.
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.prototype1 / src / eu / etaxonomy / taxeditor / prototype1 / view / NameEditorView.java
1 package eu.etaxonomy.taxeditor.prototype1.view;
2
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;
21
22 import eu.etaxonomy.cdm.model.name.TaxonName;
23 import eu.etaxonomy.taxeditor.prototype1.Activator;
24
25 public class NameEditorView extends EditorPart {
26
27 private TaxonName taxonname;
28
29 private Text txtGenus;
30 private Text txtSpEpi;
31 private Text txtAuthor;
32 private Text txtPlay;
33 public static final String ID = "eu.etaxonomy.taxeditor.prototype1.view.NameEditorView"; //$NON-NLS-1$
34
35 /**
36 * Create contents of the editor part
37 * @param parent
38 */
39 @Override
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);
45
46 final Label lblGenus = new Label(container, SWT.NONE);
47 lblGenus.setText("Genus:");
48
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);
52
53 final Label lblSpEpi = new Label(container, SWT.NONE);
54 lblSpEpi.setText("Sp. Epithet:");
55
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);
59
60 final Label lblAuthor = new Label(container, SWT.NONE);
61 lblAuthor.setText("Authorship:");
62
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);
67
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);
72 }
73 });
74 final GridData gd_btnSaveName = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
75 btnSaveName.setLayoutData(gd_btnSaveName);
76 btnSaveName.setText("Save Name");
77 //
78
79
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() {
86 // @Override
87 // public void verifyText(VerifyEvent e) {
88 // e.doit = Character.isDigit(e.character);
89 // }
90 // });
91 txtPlay.addKeyListener(new KeyListener() {
92
93 @Override
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);
100
101 // Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
102
103 // Add the items to the list
104 String[] OPTIONS = { "Create homo. syn.",
105 "Create hetero. syn.",
106 "Create mis. name",
107 "Create homonym"};
108
109 list.setItems(OPTIONS);
110
111 // Open the list and get the selected item
112 String selected = list.open(txtPlay.getBounds());
113
114 // Print the item to the console
115 System.out.println(selected);
116 }
117
118 }
119
120 @Override
121 public void keyReleased(KeyEvent e) {
122 // TODO Auto-generated method stub
123
124 }
125 });
126
127 populateForm();
128 }
129
130 private void populateForm() {
131
132 String fulltext = "";
133
134 if (taxonname.getGenus() != null) {
135 txtGenus.setText(taxonname.getGenus());
136 fulltext = taxonname.getGenus();
137 }
138
139 if (taxonname.getSpecificEpithet() != null) {
140 txtSpEpi.setText(taxonname.getSpecificEpithet());
141 fulltext += " " + taxonname.getSpecificEpithet();
142 }
143
144 if (taxonname.getAuthorship() != null) {
145 txtAuthor.setText(taxonname.getAuthorship());
146 fulltext += " " + taxonname.getAuthorship();
147 }
148
149 txtPlay.setText(fulltext);
150
151 this.setPartName(taxonname.getName());
152 }
153
154 @Override
155 public void setFocus() {
156 // Set the focus
157 }
158
159 @Override
160 public void doSave(IProgressMonitor monitor) {
161 // Do the Save operation
162 }
163
164 @Override
165 public void doSaveAs() {
166 // Do the Save As operation
167 }
168
169 @Override
170 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
171
172 if (!(input instanceof IEditorInput))
173 throw new PartInitException(
174 "Invalid Input: Must be IFileEditorInput");
175
176 if (input.getAdapter(TaxonName.class) != null) {
177 taxonname = (TaxonName) input.getAdapter(TaxonName.class);
178 } else {
179 taxonname = null;
180 }
181
182 setSite(site);
183 setInput(input);
184 }
185
186 @Override
187 public boolean isDirty() {
188 return false;
189 }
190
191 @Override
192 public boolean isSaveAsAllowed() {
193 return false;
194 }
195 }