61bd4a0bc6d44dbbafe8e2b1a0051ae5a97f23a4
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.designproposal1 / src / eu / etaxonomy / taxeditor / designproposal1 / view / NameEditorView.java
1 package eu.etaxonomy.taxeditor.designproposal1.view;
2
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.jface.action.Action;
8 import org.eclipse.jface.text.Document;
9 import org.eclipse.jface.text.TextViewer;
10 import org.eclipse.jface.text.source.SourceViewer;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.custom.PopupList;
13 import org.eclipse.swt.custom.StyledText;
14 import org.eclipse.swt.events.ControlAdapter;
15 import org.eclipse.swt.events.ControlEvent;
16 import org.eclipse.swt.events.FocusEvent;
17 import org.eclipse.swt.events.FocusListener;
18 import org.eclipse.swt.events.KeyAdapter;
19 import org.eclipse.swt.events.KeyEvent;
20 import org.eclipse.swt.events.KeyListener;
21 import org.eclipse.swt.events.MouseAdapter;
22 import org.eclipse.swt.events.MouseEvent;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.events.SelectionListener;
26 import org.eclipse.swt.graphics.Point;
27 import org.eclipse.swt.graphics.Rectangle;
28 import org.eclipse.swt.layout.FillLayout;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.CoolBar;
34 import org.eclipse.swt.widgets.CoolItem;
35 import org.eclipse.swt.widgets.Display;
36 import org.eclipse.swt.widgets.Event;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Listener;
39 import org.eclipse.swt.widgets.Menu;
40 import org.eclipse.swt.widgets.MenuItem;
41 import org.eclipse.swt.widgets.Shell;
42 import org.eclipse.swt.widgets.Table;
43 import org.eclipse.swt.widgets.TableColumn;
44 import org.eclipse.swt.widgets.TableItem;
45 import org.eclipse.swt.widgets.Text;
46 import org.eclipse.swt.widgets.ToolBar;
47 import org.eclipse.swt.widgets.ToolItem;
48 import org.eclipse.ui.IEditorInput;
49 import org.eclipse.ui.IEditorSite;
50 import org.eclipse.ui.PartInitException;
51 import org.eclipse.ui.part.EditorPart;
52 import com.swtdesigner.ResourceManager;
53 import com.swtdesigner.SWTResourceManager;
54
55 //import org.eclipse.ui.texteditor.AbstractTextEditor;
56
57 import eu.etaxonomy.cdm.event.ICdmEventListener;
58 import eu.etaxonomy.cdm.event.ICdmEventListenerRegistration;
59 import eu.etaxonomy.cdm.model.name.TaxonName;
60 import eu.etaxonomy.taxeditor.designproposal1.Activator;
61 import eu.etaxonomy.taxeditor.designproposal1.controller.OpenNameEditorAction;
62 import eu.etaxonomy.taxeditor.designproposal1.controller.SaveNameAction;
63
64 public class NameEditorView extends EditorPart implements ICdmEventListener {
65
66 private Table table_1;
67 private Text text_3;
68 private StyledText styledText;
69 private TaxonName taxonname;
70 private Text clickHereToText;
71
72 public boolean dirtyBoy = false;
73 String clickText;
74
75 public static final String ID = "eu.etaxonomy.taxeditor.designproposal1.view.nameeditorview"; //$NON-NLS-1$
76
77 /**
78 * Create contents of the editor part
79 * @param parent
80 */
81 @Override
82 public void createPartControl(Composite parent) {
83 //
84
85
86 // txtPlay = new Text(container, SWT.BORDER);
87 // txtPlay.setCapture(true);
88 // final GridData gd_txtPlay = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
89 // gd_txtPlay.heightHint = 96;
90 // txtPlay.setLayoutData(gd_txtPlay);
91 //// txtPlay.addVerifyListener(new VerifyListener() {
92 //// @Override
93 //// public void verifyText(VerifyEvent e) {
94 //// e.doit = Character.isDigit(e.character);
95 //// }
96 //// });
97 // txtPlay.addSelectionListener(new SelectionListener() {
98 //
99 // @Override
100 // public void widgetDefaultSelected(SelectionEvent e) {
101 // // TODO Auto-generated method stub
102 //
103 // }
104 //
105 // @Override
106 // public void widgetSelected(SelectionEvent e) {
107 // System.out.println(e.toString());
108 // }
109 //
110 //
111 // });
112 //
113 //
114 // txtPlay.addKeyListener(new KeyListener() {
115 //
116 // public void keyPressed(KeyEvent e) {
117 // System.out.println(e.character);
118 // if (e.character == '=') {
119 // Shell shell = Activator.getDefault().getWorkbench().
120 // getActiveWorkbenchWindow().getShell();
121 // PopupList list = new PopupList(shell, SWT.H_SCROLL | SWT.V_SCROLL);
122 //
123 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
124 //
125 // // Add the items to the list
126 // String[] OPTIONS = { "Create homo. syn.",
127 // "Create hetero. syn.",
128 // "Create mis. name",
129 // "Create homonym"};
130 //
131 // list.setItems(OPTIONS);
132 //
133 // // Open the list and get the selected item
134 // String selected = list.open(txtPlay.getBounds());
135 //
136 // // Print the item to the console
137 // System.out.println(selected);
138 // }
139 //
140 // }
141 //
142 // public void keyReleased(KeyEvent e) {
143 // // TODO Auto-generated method stub
144 //
145 // }
146 // });
147 parent.setLayout(new GridLayout());
148 Document doc = new Document("");
149
150 final Label taxonomicallyIncludedInLabel = new Label(parent, SWT.NONE);
151 taxonomicallyIncludedInLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
152 taxonomicallyIncludedInLabel.setText(" ");
153
154 final ToolBar toolBar = new ToolBar(parent, SWT.NONE);
155 // toolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
156
157 final ToolItem itemSave = new ToolItem(toolBar, SWT.PUSH);
158 itemSave.setToolTipText("Save taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
159 itemSave.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/save.gif"));
160 itemSave.addSelectionListener(new SelectionListener() {
161 public void mouseDown(final MouseEvent e) {
162
163 // taxonname.setGenus(txtGenus.getText());
164 // taxonname.setSpecificEpithet(txtSpEpi.getText());
165
166 new SaveNameAction(taxonname).run();
167 }
168
169 public void widgetDefaultSelected(SelectionEvent e) {
170 new SaveNameAction(taxonname).run();
171 }
172
173 public void widgetSelected(SelectionEvent e) {
174 new SaveNameAction(taxonname).run();
175 }
176 });
177
178 final ToolItem itemMove = new ToolItem(toolBar, SWT.DROP_DOWN);
179 itemMove.setToolTipText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
180 itemMove.addSelectionListener(new SelectionAdapter() {
181 public void widgetSelected(final SelectionEvent e) {
182 }
183 });
184
185 final Menu menuMove = new Menu(toolBar);
186 menuMove.setData("x", null);
187 addDropDown(itemMove, menuMove);
188
189 final MenuItem moveTaxonpilosellaMenuItem = new MenuItem(menuMove, SWT.NONE);
190 moveTaxonpilosellaMenuItem.setText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" to another higher taxon");
191
192 final MenuItem turnTaxonpilosellaMenuItem = new MenuItem(menuMove, SWT.NONE);
193 turnTaxonpilosellaMenuItem.setText("Turn taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" into a synonym");
194
195 // });
196 // newItemToolItem.setText("New item");
197 itemMove.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/move_no_bg.gif"));
198
199 final ToolItem itemDelete = new ToolItem(toolBar, SWT.NONE);
200 itemDelete.setToolTipText("Delete taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
201 itemDelete.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/delete.gif"));
202
203 final ToolItem separator1 = new ToolItem(toolBar, SWT.SEPARATOR);
204
205 final ToolItem itemAddRelationship = new ToolItem(toolBar, SWT.DROP_DOWN);
206 itemAddRelationship.setToolTipText("Add nom. or tax. relation to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
207 itemAddRelationship.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/rel_no_bg.gif"));
208
209 final Menu menuAddRel = new Menu(toolBar);
210 menuAddRel.setData("x", null);
211 addDropDown(itemAddRelationship, menuAddRel);
212
213 final MenuItem testMenuItem = new MenuItem(menuAddRel, SWT.NONE);
214 testMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/unknown_no_bg.gif"));
215 testMenuItem.setText("Add synonymy (type unknown)");
216
217 final MenuItem addHomotypicSynonymMenuItem = new MenuItem(menuAddRel, SWT.NONE);
218 addHomotypicSynonymMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/homosyn_no_bg.gif"));
219 addHomotypicSynonymMenuItem.setText("Add homotypic synonym");
220
221 final MenuItem addHeterotypicSynoynmMenuItem = new MenuItem(menuAddRel, SWT.NONE);
222 addHeterotypicSynoynmMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/heterosyn_no_bg.gif"));
223 addHeterotypicSynoynmMenuItem.setText("Add heterotypic synoynm");
224
225 final MenuItem addBasionymMenuItem = new MenuItem(menuAddRel, SWT.NONE);
226 addBasionymMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/basionym_no_bg.gif"));
227 addBasionymMenuItem.setText("Add basionym");
228
229 final MenuItem addReplacedSynonymMenuItem = new MenuItem(menuAddRel, SWT.NONE);
230 addReplacedSynonymMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/repsyn_no_bg.gif"));
231 addReplacedSynonymMenuItem.setText("Add replaced synonym");
232
233 final MenuItem addHomonymMenuItem = new MenuItem(menuAddRel, SWT.NONE);
234 addHomonymMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/homonym_no_bg.gif"));
235 addHomonymMenuItem.setText("Add homonym");
236
237 final MenuItem addOrthographicVariantMenuItem = new MenuItem(menuAddRel, SWT.NONE);
238 addOrthographicVariantMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/orthovariant_no_bg.gif"));
239 addOrthographicVariantMenuItem.setText("Add orthographic variant");
240
241 final MenuItem addMisappliedNameMenuItem = new MenuItem(menuAddRel, SWT.NONE);
242 addMisappliedNameMenuItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/misapplied_no_bg.gif"));
243 addMisappliedNameMenuItem.setText("Add misapplied name");
244
245 final MenuItem addConceptRelationMenuItem_1 = new MenuItem(menuAddRel, SWT.CASCADE);
246 addConceptRelationMenuItem_1.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/concept_no_bg.gif"));
247 addConceptRelationMenuItem_1.setText("Add concept relation");
248
249 final Menu menu = new Menu(addConceptRelationMenuItem_1);
250 addConceptRelationMenuItem_1.setMenu(menu);
251
252 final MenuItem checkboxMenuItem = new MenuItem(menu, SWT.CHECK);
253 checkboxMenuItem.setText("congruent");
254
255 final MenuItem checkboxMenuItem_1 = new MenuItem(menu, SWT.CHECK);
256 checkboxMenuItem_1.setSelection(true);
257 checkboxMenuItem_1.setText("included in");
258
259 final MenuItem checkboxMenuItem_2 = new MenuItem(menu, SWT.CHECK);
260 checkboxMenuItem_2.setText("includes");
261
262 final MenuItem checkboxMenuItem_3 = new MenuItem(menu, SWT.CHECK);
263 checkboxMenuItem_3.setText("overlaps");
264
265 final MenuItem checkboxMenuItem_4 = new MenuItem(menu, SWT.CHECK);
266 checkboxMenuItem_4.setText("excludes");
267
268 final MenuItem checkboxMenuItem_5 = new MenuItem(menu, SWT.CHECK);
269 checkboxMenuItem_5.setSelection(true);
270 checkboxMenuItem_5.setText("doubtful");
271
272 final ToolItem separator2 = new ToolItem(toolBar, SWT.SEPARATOR);
273
274 final ToolItem itemAddTaxon = new ToolItem(toolBar, SWT.DROP_DOWN);
275 itemAddTaxon.setImage(ResourceManager.getPluginImage(Activator.getDefault(), "icons/add_no_bg2.gif"));
276 itemAddTaxon.setToolTipText("Add new taxon");
277
278 final Menu menuAdd = new Menu(toolBar);
279 menuAdd.setData("x", null);
280 addDropDown(itemAddTaxon, menuAdd);
281
282 final MenuItem addTaxonToMenuItem = new MenuItem(menuAdd, SWT.NONE);
283 addTaxonToMenuItem.setText("Add new taxon to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
284
285 final MenuItem addNewTaxonMenuItem = new MenuItem(menuAdd, SWT.NONE);
286 addNewTaxonMenuItem.setText("Add new taxon to \"Pilosella fuscoatra coll.\"");
287
288 final Composite composite = new Composite(parent, SWT.NONE);
289 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
290 composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
291 final GridLayout gridLayout_2 = new GridLayout();
292 gridLayout_2.horizontalSpacing = 3;
293 gridLayout_2.numColumns = 2;
294 composite.setLayout(gridLayout_2);
295
296 clickText = "Click here to start entering accepted name or enter its individual fields in the property sheet to the right";
297
298 clickHereToText = new Text(composite, SWT.WRAP);
299 clickHereToText.addKeyListener(new KeyAdapter() {
300 public void keyPressed(final KeyEvent e) {
301 }
302 });
303 clickHereToText.setForeground(SWTResourceManager.getColor(192, 192, 192));
304 clickHereToText.setText(clickText);
305 clickHereToText.setFont(SWTResourceManager.getFont("Georgia", 12, SWT.ITALIC));
306 final GridData gd_clickHereToText = new GridData(SWT.FILL, SWT.CENTER, true, false);
307 gd_clickHereToText.widthHint = 426;
308 clickHereToText.setLayoutData(gd_clickHereToText);
309 clickHereToText.addFocusListener(new FocusListener() {
310
311 public void focusGained(FocusEvent e) {
312 // clickHereToText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
313 if (!dirtyBoy) {
314 clickHereToText.setText("");
315 clickHereToText.setFont(SWTResourceManager.getFont("Georgia", 12, SWT.NONE));
316 clickHereToText.setForeground(SWTResourceManager.getColor(0, 0, 0));
317 dirtyBoy = true;
318 firePropertyChange(PROP_DIRTY);
319 }
320 }
321
322 public void focusLost(FocusEvent e) {
323 // clickHereToText.setBackground(null);
324 if (clickHereToText.getText() == "") {
325 clickHereToText.setForeground(SWTResourceManager.getColor(192, 192, 192));
326 clickHereToText.setText(clickText);
327 clickHereToText.setFont(SWTResourceManager.getFont("Georgia", 12, SWT.ITALIC));
328 dirtyBoy = false;
329 } else {
330 dirtyBoy = true;
331 }
332 }
333
334 });
335 // clickHereToText.addKeyListener(new KeyListener() {
336 //
337 // public void keyPressed(KeyEvent e) {
338 // dirtyBoy = true;
339 // isDirty();
340 //
341 // }
342 //
343 // public void keyReleased(KeyEvent e) {
344 // // TODO Auto-generated method stub
345 //
346 // }
347 //
348 // });
349
350 table_1 = new Table(composite, SWT.BORDER);
351 table_1.setLinesVisible(true);
352 table_1.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 2));
353
354 final TableColumn newColumnTableColumn = new TableColumn(table_1, SWT.NONE);
355 newColumnTableColumn.setWidth(100);
356 newColumnTableColumn.setText("New column");
357
358 final TableColumn newColumnTableColumn_1 = new TableColumn(table_1, SWT.NONE);
359 newColumnTableColumn_1.setWidth(100);
360 newColumnTableColumn_1.setText("New column");
361
362 final TableItem newItemTableItem = new TableItem(table_1, SWT.BORDER);
363 newItemTableItem.setText(0, "Rank");
364 newItemTableItem.setText("Rank");
365
366 final TableItem newItemTableItem_1 = new TableItem(table_1, SWT.BORDER);
367 newItemTableItem_1.setText(0, "Genus");
368
369 final TableItem newItemTableItem_2 = new TableItem(table_1, SWT.BORDER);
370 newItemTableItem_2.setText(0, "Species epithet");
371
372 final TableItem newItemTableItem_3 = new TableItem(table_1, SWT.BORDER);
373 newItemTableItem_3.setText(0, "Author team");
374
375 final TableItem newItemTableItem_4 = new TableItem(table_1, SWT.BORDER);
376 newItemTableItem_4.setText("...");
377 // newItemTableItem_1.setText("Genus");
378 //container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
379
380 SourceViewer sourceviewer = new SourceViewer(composite, null, SWT.WRAP | SWT.FULL_SELECTION);
381 sourceviewer.setAnnotationHover(null);
382 styledText = sourceviewer.getTextWidget();
383 final GridData gd_styledText = new GridData(SWT.FILL, SWT.TOP, true, false);
384 gd_styledText.heightHint = 41;
385 gd_styledText.widthHint = 450;
386 styledText.setLayoutData(gd_styledText);
387 sourceviewer.setDocument(doc);
388 sourceviewer.configure(new MySourceViewerConfig());
389 sourceviewer.setTabsToSpacesConverter(null);
390
391
392 // final Menu menu = new Menu(toolBar);
393 // addDropDown(newItemToolItem, menu);
394 // );
395
396 // Action testAction = new OpenNameEditorAction();
397 // testAction.setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.getDefault(), "icons/edit_16x16.gif"));
398 // testAction.setToolTipText("Add relation");
399 // toolBar.add(testAction);
400
401 populateForm();
402 }
403
404 // private void populateForm() {
405 //
406 // String fulltext = "";
407 //
408 // if (taxonname.getGenus() != null) {
409 // fulltext = taxonname.getGenus();
410 // }
411 //
412 // if (taxonname.getSpecificEpithet() != null) {
413 // fulltext += " " + taxonname.getSpecificEpithet();
414 // }
415 //
416 // if (taxonname.getAuthorship() != null) {
417 // fulltext += " " + taxonname.getAuthorship();
418 // }
419 //
420 //// txtPlay.setText(fulltext);
421 //// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");
422 //
423 // this.setPartName(taxonname.getName());
424 // }
425
426 private void populateForm() {
427 this.setPartName("Pilosella fuscoatra (Nägeli & Peter) Soják");
428 }
429
430 @Override
431 public void setFocus() {
432 // Set the focus
433 }
434
435 @Override
436 public void doSave(IProgressMonitor monitor) {
437 // Do the Save operation
438 }
439
440 @Override
441 public void doSaveAs() {
442 // Do the Save As operation
443 }
444
445 @Override
446 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
447
448 if (!(input instanceof IEditorInput))
449 throw new PartInitException(
450 "Invalid Input: Must be IFileEditorInput");
451
452 if (input.getAdapter(TaxonName.class) != null) {
453 taxonname = (TaxonName) input.getAdapter(TaxonName.class);
454 taxonname.addCdmEventListener(this);
455 } else {
456
457 taxonname = null;
458 }
459
460 setSite(site);
461 setInput(input);
462 }
463
464 @Override
465 public boolean isDirty() {
466 return dirtyBoy;
467 }
468
469 @Override
470 public boolean isSaveAsAllowed() {
471 return false;
472 }
473
474 public void propertyChange(PropertyChangeEvent evt) {
475 // TaxonName taxonname = (TaxonName)evt.getNewValue();
476 this.taxonname = (TaxonName)evt.getNewValue();
477 System.out.println(((TaxonName)evt.getNewValue()).getName());
478 populateForm();
479
480 // for individual fields, do something like:
481 // if (evt.getPropertyName().equalsIgnoreCase("genus"))
482 // txtGenus.setText ...
483 }
484
485 public void onDelete(ICdmEventListenerRegistration arg0) {
486 // TODO Auto-generated method stub
487
488 }
489
490 public void onInsert(Object arg0) {
491 // TODO Auto-generated method stub
492
493 }
494
495 public void onLoad(Object arg0) {
496 // TODO Auto-generated method stub
497
498 }
499
500 public void onUpdate(ICdmEventListenerRegistration arg0) {
501 // TODO Auto-generated method stub
502
503 }
504
505 private static void addDropDown(final ToolItem item, final Menu menu) {
506 item.addListener(SWT.Selection, new Listener() {
507 public void handleEvent(Event event) {
508 if (event.detail == SWT.ARROW) {
509 Rectangle rect = item.getBounds();
510 Point pt = new Point(rect.x, rect.y + rect.height);
511 pt = item.getParent().toDisplay(pt);
512 menu.setLocation(pt.x, pt.y);
513 menu.setVisible(true);
514 }
515 }
516 });
517 }
518 }