1 package eu
.etaxonomy
.taxeditor
.prototype2
.view
;
3 import java
.beans
.PropertyChangeEvent
;
4 import java
.beans
.PropertyChangeListener
;
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
;
57 //import org.eclipse.ui.texteditor.AbstractTextEditor;
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
;
68 //public class NameEditorView extends EditorPart implements ICdmEventListener {
69 public class NameEditorView
extends EditorPart
{
71 private Table table_1
;
73 private StyledText styledText
;
74 private TaxonName taxonname
;
75 private Text clickHereToText
;
77 public boolean dirtyBoy
= false;
80 public static final String ID
= "eu.etaxonomy.taxeditor.prototype2.view.nameeditorview"; //$NON-NLS-1$
83 * Create contents of the editor part
87 public void createPartControl(Composite parent
) {
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() {
98 //// public void verifyText(VerifyEvent e) {
99 //// e.doit = Character.isDigit(e.character);
102 // txtPlay.addSelectionListener(new SelectionListener() {
105 // public void widgetDefaultSelected(SelectionEvent e) {
106 // // TODO Auto-generated method stub
111 // public void widgetSelected(SelectionEvent e) {
112 // System.out.println(e.toString());
119 // txtPlay.addKeyListener(new KeyListener() {
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);
128 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
130 // // Add the items to the list
131 // String[] OPTIONS = { "Create homo. syn.",
132 // "Create hetero. syn.",
133 // "Create mis. name",
134 // "Create homonym"};
136 // list.setItems(OPTIONS);
138 // // Open the list and get the selected item
139 // String selected = list.open(txtPlay.getBounds());
141 // // Print the item to the console
142 // System.out.println(selected);
147 // public void keyReleased(KeyEvent e) {
148 // // TODO Auto-generated method stub
152 parent
.setLayout(new GridLayout());
153 Document doc
= new Document("");
155 final Label taxonomicallyIncludedInLabel
= new Label(parent
, SWT
.NONE
);
156 taxonomicallyIncludedInLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
157 taxonomicallyIncludedInLabel
.setText(" ");
159 final ToolBar toolBar
= new ToolBar(parent
, SWT
.NONE
);
160 // toolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
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
) {
168 // taxonname.setGenus(txtGenus.getText());
169 // taxonname.setSpecificEpithet(txtSpEpi.getText());
171 new SaveNameAction(taxonname
).run();
174 public void widgetDefaultSelected(SelectionEvent e
) {
175 new SaveNameAction(taxonname
).run();
178 public void widgetSelected(SelectionEvent e
) {
179 new SaveNameAction(taxonname
).run();
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
) {
190 final Menu menuMove
= new Menu(toolBar
);
191 addDropDown(itemMove
, menuMove
);
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");
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");
202 // newItemToolItem.setText("New item");
203 itemMove
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/move_no_bg.gif"));
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"));
209 final ToolItem separator1
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
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"));
215 final Menu menuAddRel
= new Menu(toolBar
);
216 menuAddRel
.setData("x", null);
217 addDropDown(itemAddRelationship
, menuAddRel
);
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)");
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");
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");
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");
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");
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");
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");
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");
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");
255 final Menu menu
= new Menu(addConceptRelationMenuItem_1
);
256 addConceptRelationMenuItem_1
.setMenu(menu
);
258 final MenuItem checkboxMenuItem
= new MenuItem(menu
, SWT
.CHECK
);
259 checkboxMenuItem
.setText("congruent");
261 final MenuItem checkboxMenuItem_1
= new MenuItem(menu
, SWT
.CHECK
);
262 checkboxMenuItem_1
.setSelection(true);
263 checkboxMenuItem_1
.setText("included in");
265 final MenuItem checkboxMenuItem_2
= new MenuItem(menu
, SWT
.CHECK
);
266 checkboxMenuItem_2
.setText("includes");
268 final MenuItem checkboxMenuItem_3
= new MenuItem(menu
, SWT
.CHECK
);
269 checkboxMenuItem_3
.setText("overlaps");
271 final MenuItem checkboxMenuItem_4
= new MenuItem(menu
, SWT
.CHECK
);
272 checkboxMenuItem_4
.setText("excludes");
274 final MenuItem checkboxMenuItem_5
= new MenuItem(menu
, SWT
.CHECK
);
275 checkboxMenuItem_5
.setSelection(true);
276 checkboxMenuItem_5
.setText("doubtful");
278 final ToolItem separator2
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
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");
284 final Menu menuAdd
= new Menu(toolBar
);
285 menuAdd
.setData("x", null);
286 addDropDown(itemAddTaxon
, menuAdd
);
288 final MenuItem addTaxonToMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
289 addTaxonToMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
291 final MenuItem addNewTaxonMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
292 addNewTaxonMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra coll.\"");
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
);
302 clickText
= "Click here to start entering accepted name or enter its individual fields in the property sheet to the right";
304 clickHereToText
= new Text(composite
, SWT
.WRAP
);
305 clickHereToText
.addKeyListener(new KeyAdapter() {
306 public void keyPressed(final KeyEvent e
) {
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() {
317 public void focusGained(FocusEvent e
) {
318 // clickHereToText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
320 clickHereToText
.setText("");
321 clickHereToText
.setFont(SWTResourceManager
.getFont("Georgia", 12, SWT
.NONE
));
322 clickHereToText
.setForeground(SWTResourceManager
.getColor(0, 0, 0));
324 firePropertyChange(PROP_DIRTY
);
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
));
341 // clickHereToText.addKeyListener(new KeyListener() {
343 // public void keyPressed(KeyEvent e) {
349 // public void keyReleased(KeyEvent e) {
350 // // TODO Auto-generated method stub
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));
360 final TableColumn newColumnTableColumn
= new TableColumn(table_1
, SWT
.NONE
);
361 newColumnTableColumn
.setWidth(100);
362 newColumnTableColumn
.setText("New column");
364 final TableColumn newColumnTableColumn_1
= new TableColumn(table_1
, SWT
.NONE
);
365 newColumnTableColumn_1
.setWidth(100);
366 newColumnTableColumn_1
.setText("New column");
368 final TableItem newItemTableItem
= new TableItem(table_1
, SWT
.BORDER
);
369 newItemTableItem
.setText(0, "Rank");
370 newItemTableItem
.setText("Rank");
372 final TableItem newItemTableItem_1
= new TableItem(table_1
, SWT
.BORDER
);
373 newItemTableItem_1
.setText(0, "Genus");
375 final TableItem newItemTableItem_2
= new TableItem(table_1
, SWT
.BORDER
);
376 newItemTableItem_2
.setText(0, "Species epithet");
378 final TableItem newItemTableItem_3
= new TableItem(table_1
, SWT
.BORDER
);
379 newItemTableItem_3
.setText(0, "Author team");
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));
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);
398 // final Menu menu = new Menu(toolBar);
399 // addDropDown(newItemToolItem, menu);
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);
410 // private void populateForm() {
412 // String fulltext = "";
414 // if (taxonname.getGenus() != null) {
415 // fulltext = taxonname.getGenus();
418 // if (taxonname.getSpecificEpithet() != null) {
419 // fulltext += " " + taxonname.getSpecificEpithet();
422 // if (taxonname.getAuthorship() != null) {
423 // fulltext += " " + taxonname.getAuthorship();
426 //// txtPlay.setText(fulltext);
427 //// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");
429 // this.setPartName(taxonname.getName());
432 private void populateForm() {
433 this.setPartName("Pilosella fuscoatra (Nägeli & Peter) Soják");
437 public void setFocus() {
442 public void doSave(IProgressMonitor monitor
) {
443 // Do the Save operation
447 public void doSaveAs() {
448 // Do the Save As operation
452 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
454 if (!(input
instanceof IEditorInput
))
455 throw new PartInitException(
456 "Invalid Input: Must be IFileEditorInput");
458 if (input
.getAdapter(TaxonName
.class) != null) {
459 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
460 // taxonname.addCdmEventListener(this);
471 public boolean isDirty() {
476 public boolean isSaveAsAllowed() {
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());
486 // for individual fields, do something like:
487 // if (evt.getPropertyName().equalsIgnoreCase("genus"))
488 // txtGenus.setText ...
491 // public void onDelete(ICdmEventListenerRegistration arg0) {
492 // // TODO Auto-generated method stub
496 public void onInsert(Object arg0
) {
497 // TODO Auto-generated method stub
501 public void onLoad(Object arg0
) {
502 // TODO Auto-generated method stub
506 // public void onUpdate(ICdmEventListenerRegistration arg0) {
507 // // TODO Auto-generated method stub
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);