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