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