1 package eu
.etaxonomy
.taxeditor
.designproposal1
.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
.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
;
55 //import org.eclipse.ui.texteditor.AbstractTextEditor;
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
;
64 public class NameEditorView
extends EditorPart
implements ICdmEventListener
{
66 private Table table_1
;
68 private StyledText styledText
;
69 private TaxonName taxonname
;
70 private Text clickHereToText
;
72 public boolean dirtyBoy
= false;
75 public static final String ID
= "eu.etaxonomy.taxeditor.designproposal1.view.nameeditorview"; //$NON-NLS-1$
78 * Create contents of the editor part
82 public void createPartControl(Composite parent
) {
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() {
93 //// public void verifyText(VerifyEvent e) {
94 //// e.doit = Character.isDigit(e.character);
97 // txtPlay.addSelectionListener(new SelectionListener() {
100 // public void widgetDefaultSelected(SelectionEvent e) {
101 // // TODO Auto-generated method stub
106 // public void widgetSelected(SelectionEvent e) {
107 // System.out.println(e.toString());
114 // txtPlay.addKeyListener(new KeyListener() {
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);
123 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
125 // // Add the items to the list
126 // String[] OPTIONS = { "Create homo. syn.",
127 // "Create hetero. syn.",
128 // "Create mis. name",
129 // "Create homonym"};
131 // list.setItems(OPTIONS);
133 // // Open the list and get the selected item
134 // String selected = list.open(txtPlay.getBounds());
136 // // Print the item to the console
137 // System.out.println(selected);
142 // public void keyReleased(KeyEvent e) {
143 // // TODO Auto-generated method stub
147 parent
.setLayout(new GridLayout());
148 Document doc
= new Document("");
150 final Label taxonomicallyIncludedInLabel
= new Label(parent
, SWT
.NONE
);
151 taxonomicallyIncludedInLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
152 taxonomicallyIncludedInLabel
.setText(" ");
154 final ToolBar toolBar
= new ToolBar(parent
, SWT
.NONE
);
155 // toolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
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
) {
163 // taxonname.setGenus(txtGenus.getText());
164 // taxonname.setSpecificEpithet(txtSpEpi.getText());
166 new SaveNameAction(taxonname
).run();
169 public void widgetDefaultSelected(SelectionEvent e
) {
170 new SaveNameAction(taxonname
).run();
173 public void widgetSelected(SelectionEvent e
) {
174 new SaveNameAction(taxonname
).run();
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
) {
185 final Menu menuMove
= new Menu(toolBar
);
186 menuMove
.setData("x", null);
187 addDropDown(itemMove
, menuMove
);
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");
192 final MenuItem turnTaxonpilosellaMenuItem
= new MenuItem(menuMove
, SWT
.NONE
);
193 turnTaxonpilosellaMenuItem
.setText("Turn taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" into a synonym");
196 // newItemToolItem.setText("New item");
197 itemMove
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/move_no_bg.gif"));
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"));
203 final ToolItem separator1
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
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"));
209 final Menu menuAddRel
= new Menu(toolBar
);
210 menuAddRel
.setData("x", null);
211 addDropDown(itemAddRelationship
, menuAddRel
);
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)");
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");
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");
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");
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");
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");
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");
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");
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");
249 final Menu menu
= new Menu(addConceptRelationMenuItem_1
);
250 addConceptRelationMenuItem_1
.setMenu(menu
);
252 final MenuItem checkboxMenuItem
= new MenuItem(menu
, SWT
.CHECK
);
253 checkboxMenuItem
.setText("congruent");
255 final MenuItem checkboxMenuItem_1
= new MenuItem(menu
, SWT
.CHECK
);
256 checkboxMenuItem_1
.setSelection(true);
257 checkboxMenuItem_1
.setText("included in");
259 final MenuItem checkboxMenuItem_2
= new MenuItem(menu
, SWT
.CHECK
);
260 checkboxMenuItem_2
.setText("includes");
262 final MenuItem checkboxMenuItem_3
= new MenuItem(menu
, SWT
.CHECK
);
263 checkboxMenuItem_3
.setText("overlaps");
265 final MenuItem checkboxMenuItem_4
= new MenuItem(menu
, SWT
.CHECK
);
266 checkboxMenuItem_4
.setText("excludes");
268 final MenuItem checkboxMenuItem_5
= new MenuItem(menu
, SWT
.CHECK
);
269 checkboxMenuItem_5
.setSelection(true);
270 checkboxMenuItem_5
.setText("doubtful");
272 final ToolItem separator2
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
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");
278 final Menu menuAdd
= new Menu(toolBar
);
279 menuAdd
.setData("x", null);
280 addDropDown(itemAddTaxon
, menuAdd
);
282 final MenuItem addTaxonToMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
283 addTaxonToMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
285 final MenuItem addNewTaxonMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
286 addNewTaxonMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra coll.\"");
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
);
296 clickText
= "Click here to start entering accepted name or enter its individual fields in the property sheet to the right";
298 clickHereToText
= new Text(composite
, SWT
.WRAP
);
299 clickHereToText
.addKeyListener(new KeyAdapter() {
300 public void keyPressed(final KeyEvent e
) {
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() {
311 public void focusGained(FocusEvent e
) {
312 // clickHereToText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
314 clickHereToText
.setText("");
315 clickHereToText
.setFont(SWTResourceManager
.getFont("Georgia", 12, SWT
.NONE
));
316 clickHereToText
.setForeground(SWTResourceManager
.getColor(0, 0, 0));
318 firePropertyChange(PROP_DIRTY
);
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
));
335 // clickHereToText.addKeyListener(new KeyListener() {
337 // public void keyPressed(KeyEvent e) {
343 // public void keyReleased(KeyEvent e) {
344 // // TODO Auto-generated method stub
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));
354 final TableColumn newColumnTableColumn
= new TableColumn(table_1
, SWT
.NONE
);
355 newColumnTableColumn
.setWidth(100);
356 newColumnTableColumn
.setText("New column");
358 final TableColumn newColumnTableColumn_1
= new TableColumn(table_1
, SWT
.NONE
);
359 newColumnTableColumn_1
.setWidth(100);
360 newColumnTableColumn_1
.setText("New column");
362 final TableItem newItemTableItem
= new TableItem(table_1
, SWT
.BORDER
);
363 newItemTableItem
.setText(0, "Rank");
364 newItemTableItem
.setText("Rank");
366 final TableItem newItemTableItem_1
= new TableItem(table_1
, SWT
.BORDER
);
367 newItemTableItem_1
.setText(0, "Genus");
369 final TableItem newItemTableItem_2
= new TableItem(table_1
, SWT
.BORDER
);
370 newItemTableItem_2
.setText(0, "Species epithet");
372 final TableItem newItemTableItem_3
= new TableItem(table_1
, SWT
.BORDER
);
373 newItemTableItem_3
.setText(0, "Author team");
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));
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);
392 // final Menu menu = new Menu(toolBar);
393 // addDropDown(newItemToolItem, menu);
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);
404 // private void populateForm() {
406 // String fulltext = "";
408 // if (taxonname.getGenus() != null) {
409 // fulltext = taxonname.getGenus();
412 // if (taxonname.getSpecificEpithet() != null) {
413 // fulltext += " " + taxonname.getSpecificEpithet();
416 // if (taxonname.getAuthorship() != null) {
417 // fulltext += " " + taxonname.getAuthorship();
420 //// txtPlay.setText(fulltext);
421 //// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");
423 // this.setPartName(taxonname.getName());
426 private void populateForm() {
427 this.setPartName("Pilosella fuscoatra (Nägeli & Peter) Soják");
431 public void setFocus() {
436 public void doSave(IProgressMonitor monitor
) {
437 // Do the Save operation
441 public void doSaveAs() {
442 // Do the Save As operation
446 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
448 if (!(input
instanceof IEditorInput
))
449 throw new PartInitException(
450 "Invalid Input: Must be IFileEditorInput");
452 if (input
.getAdapter(TaxonName
.class) != null) {
453 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
454 taxonname
.addCdmEventListener(this);
465 public boolean isDirty() {
470 public boolean isSaveAsAllowed() {
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());
480 // for individual fields, do something like:
481 // if (evt.getPropertyName().equalsIgnoreCase("genus"))
482 // txtGenus.setText ...
485 public void onDelete(ICdmEventListenerRegistration arg0
) {
486 // TODO Auto-generated method stub
490 public void onInsert(Object arg0
) {
491 // TODO Auto-generated method stub
495 public void onLoad(Object arg0
) {
496 // TODO Auto-generated method stub
500 public void onUpdate(ICdmEventListenerRegistration arg0
) {
501 // TODO Auto-generated method stub
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);