1 package eu
.etaxonomy
.taxeditor
.prototype1
.view
;
3 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.custom
.PopupList
;
6 import org
.eclipse
.swt
.events
.KeyEvent
;
7 import org
.eclipse
.swt
.events
.KeyListener
;
8 import org
.eclipse
.swt
.events
.MouseAdapter
;
9 import org
.eclipse
.swt
.events
.MouseEvent
;
10 import org
.eclipse
.swt
.layout
.GridData
;
11 import org
.eclipse
.swt
.layout
.GridLayout
;
12 import org
.eclipse
.swt
.widgets
.Button
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Label
;
15 import org
.eclipse
.swt
.widgets
.Shell
;
16 import org
.eclipse
.swt
.widgets
.Text
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IEditorSite
;
19 import org
.eclipse
.ui
.PartInitException
;
20 import org
.eclipse
.ui
.part
.EditorPart
;
22 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
23 import eu
.etaxonomy
.taxeditor
.prototype1
.Activator
;
25 public class NameEditorView
extends EditorPart
{
27 private TaxonName taxonname
;
29 private Text txtGenus
;
30 private Text txtSpEpi
;
31 private Text txtAuthor
;
33 public static final String ID
= "eu.etaxonomy.taxeditor.prototype1.view.NameEditorView"; //$NON-NLS-1$
36 * Create contents of the editor part
40 public void createPartControl(Composite parent
) {
41 Composite container
= new Composite(parent
, SWT
.NONE
);
42 final GridLayout gridLayout
= new GridLayout();
43 gridLayout
.numColumns
= 2;
44 container
.setLayout(gridLayout
);
46 final Label lblGenus
= new Label(container
, SWT
.NONE
);
47 lblGenus
.setText("Genus:");
49 txtGenus
= new Text(container
, SWT
.BORDER
);
50 final GridData gd_txtGenus
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
51 txtGenus
.setLayoutData(gd_txtGenus
);
53 final Label lblSpEpi
= new Label(container
, SWT
.NONE
);
54 lblSpEpi
.setText("Sp. Epithet:");
56 txtSpEpi
= new Text(container
, SWT
.BORDER
);
57 final GridData gd_txtSpEpi
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
58 txtSpEpi
.setLayoutData(gd_txtSpEpi
);
60 final Label lblAuthor
= new Label(container
, SWT
.NONE
);
61 lblAuthor
.setText("Authorship:");
63 txtAuthor
= new Text(container
, SWT
.BORDER
);
64 final GridData gd_txtAuthor
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
65 txtAuthor
.setLayoutData(gd_txtAuthor
);
66 new Label(container
, SWT
.NONE
);
68 final Button btnSaveName
= new Button(container
, SWT
.NONE
);
69 btnSaveName
.addMouseListener(new MouseAdapter() {
70 public void mouseDown(final MouseEvent e
) {
71 System
.out
.println(NameEditorView
.ID
);
74 final GridData gd_btnSaveName
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false);
75 btnSaveName
.setLayoutData(gd_btnSaveName
);
76 btnSaveName
.setText("Save Name");
80 txtPlay
= new Text(container
, SWT
.BORDER
);
81 txtPlay
.setCapture(true);
82 final GridData gd_txtPlay
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1);
83 gd_txtPlay
.heightHint
= 96;
84 txtPlay
.setLayoutData(gd_txtPlay
);
85 // txtPlay.addVerifyListener(new VerifyListener() {
87 // public void verifyText(VerifyEvent e) {
88 // e.doit = Character.isDigit(e.character);
91 txtPlay
.addKeyListener(new KeyListener() {
94 public void keyPressed(KeyEvent e
) {
95 System
.out
.println(e
.character
);
96 if (e
.character
== '=') {
97 Shell shell
= Activator
.getDefault().getWorkbench().
98 getActiveWorkbenchWindow().getShell();
99 PopupList list
= new PopupList(shell
, SWT
.H_SCROLL
| SWT
.V_SCROLL
);
101 // Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
103 // Add the items to the list
104 String
[] OPTIONS
= { "Create homo. syn.",
105 "Create hetero. syn.",
109 list
.setItems(OPTIONS
);
111 // Open the list and get the selected item
112 String selected
= list
.open(txtPlay
.getBounds());
114 // Print the item to the console
115 System
.out
.println(selected
);
121 public void keyReleased(KeyEvent e
) {
122 // TODO Auto-generated method stub
130 private void populateForm() {
132 String fulltext
= "";
134 if (taxonname
.getGenus() != null) {
135 txtGenus
.setText(taxonname
.getGenus());
136 fulltext
= taxonname
.getGenus();
139 if (taxonname
.getSpecificEpithet() != null) {
140 txtSpEpi
.setText(taxonname
.getSpecificEpithet());
141 fulltext
+= " " + taxonname
.getSpecificEpithet();
144 if (taxonname
.getAuthorship() != null) {
145 txtAuthor
.setText(taxonname
.getAuthorship());
146 fulltext
+= " " + taxonname
.getAuthorship();
149 txtPlay
.setText(fulltext
);
151 this.setPartName(taxonname
.getName());
155 public void setFocus() {
160 public void doSave(IProgressMonitor monitor
) {
161 // Do the Save operation
165 public void doSaveAs() {
166 // Do the Save As operation
170 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
172 if (!(input
instanceof IEditorInput
))
173 throw new PartInitException(
174 "Invalid Input: Must be IFileEditorInput");
176 if (input
.getAdapter(TaxonName
.class) != null) {
177 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
187 public boolean isDirty() {
192 public boolean isSaveAsAllowed() {