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
.KeyEvent
;
19 import org
.eclipse
.swt
.events
.KeyListener
;
20 import org
.eclipse
.swt
.events
.MouseAdapter
;
21 import org
.eclipse
.swt
.events
.MouseEvent
;
22 import org
.eclipse
.swt
.events
.SelectionAdapter
;
23 import org
.eclipse
.swt
.events
.SelectionEvent
;
24 import org
.eclipse
.swt
.events
.SelectionListener
;
25 import org
.eclipse
.swt
.graphics
.Point
;
26 import org
.eclipse
.swt
.graphics
.Rectangle
;
27 import org
.eclipse
.swt
.layout
.FillLayout
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Button
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.CoolBar
;
33 import org
.eclipse
.swt
.widgets
.CoolItem
;
34 import org
.eclipse
.swt
.widgets
.Display
;
35 import org
.eclipse
.swt
.widgets
.Event
;
36 import org
.eclipse
.swt
.widgets
.Label
;
37 import org
.eclipse
.swt
.widgets
.Listener
;
38 import org
.eclipse
.swt
.widgets
.Menu
;
39 import org
.eclipse
.swt
.widgets
.MenuItem
;
40 import org
.eclipse
.swt
.widgets
.Shell
;
41 import org
.eclipse
.swt
.widgets
.Table
;
42 import org
.eclipse
.swt
.widgets
.TableColumn
;
43 import org
.eclipse
.swt
.widgets
.TableItem
;
44 import org
.eclipse
.swt
.widgets
.Text
;
45 import org
.eclipse
.swt
.widgets
.ToolBar
;
46 import org
.eclipse
.swt
.widgets
.ToolItem
;
47 import org
.eclipse
.ui
.IEditorInput
;
48 import org
.eclipse
.ui
.IEditorSite
;
49 import org
.eclipse
.ui
.PartInitException
;
50 import org
.eclipse
.ui
.part
.EditorPart
;
51 import com
.swtdesigner
.ResourceManager
;
52 import com
.swtdesigner
.SWTResourceManager
;
54 //import org.eclipse.ui.texteditor.AbstractTextEditor;
56 //import eu.etaxonomy.cdm.event.ICdmEventListener;
57 //import eu.etaxonomy.cdm.event.ICdmEventListenerRegistration;
58 //import eu.etaxonomy.cdm.model.name.TaxonName;
59 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
60 import eu
.etaxonomy
.taxeditor
.prototype2
.view
.MySourceViewerConfig
;
61 import eu
.etaxonomy
.taxeditor
.prototype2
.controller
.SaveNameAction
;
62 import eu
.etaxonomy
.taxeditor
.prototype2
.Activator
;
63 import eu
.etaxonomy
.taxeditor
.prototype2
.controller
.OpenNameEditorAction
;
65 //public class CarduusEditorView extends EditorPart implements ICdmEventListener {
66 public class CarduusEditorView
extends EditorPart
{
68 private Table table_1
;
69 private Text carduusLSpText
;
70 private StyledText styledText
;
71 private TaxonName taxonname
;
73 public static final String ID
= "eu.etaxonomy.taxeditor.prototype2.view.carduuseditorview"; //$NON-NLS-1$
76 * Create contents of the editor part
80 public void createPartControl(Composite parent
) {
84 // txtPlay = new Text(container, SWT.BORDER);
85 // txtPlay.setCapture(true);
86 // final GridData gd_txtPlay = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
87 // gd_txtPlay.heightHint = 96;
88 // txtPlay.setLayoutData(gd_txtPlay);
89 //// txtPlay.addVerifyListener(new VerifyListener() {
91 //// public void verifyText(VerifyEvent e) {
92 //// e.doit = Character.isDigit(e.character);
95 // txtPlay.addSelectionListener(new SelectionListener() {
98 // public void widgetDefaultSelected(SelectionEvent e) {
99 // // TODO Auto-generated method stub
104 // public void widgetSelected(SelectionEvent e) {
105 // System.out.println(e.toString());
112 // txtPlay.addKeyListener(new KeyListener() {
114 // public void keyPressed(KeyEvent e) {
115 // System.out.println(e.character);
116 // if (e.character == '=') {
117 // Shell shell = Activator.getDefault().getWorkbench().
118 // getActiveWorkbenchWindow().getShell();
119 // PopupList list = new PopupList(shell, SWT.H_SCROLL | SWT.V_SCROLL);
121 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
123 // // Add the items to the list
124 // String[] OPTIONS = { "Create homo. syn.",
125 // "Create hetero. syn.",
126 // "Create mis. name",
127 // "Create homonym"};
129 // list.setItems(OPTIONS);
131 // // Open the list and get the selected item
132 // String selected = list.open(txtPlay.getBounds());
134 // // Print the item to the console
135 // System.out.println(selected);
140 // public void keyReleased(KeyEvent e) {
141 // // TODO Auto-generated method stub
145 parent
.setLayout(new GridLayout());
146 Document doc
= new Document("");
148 final Label taxonomicallyIncludedInLabel
= new Label(parent
, SWT
.NONE
);
149 taxonomicallyIncludedInLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
150 taxonomicallyIncludedInLabel
.setText("Higher taxon: \"Cardueae Cass.\"");
152 final ToolBar toolBar
= new ToolBar(parent
, SWT
.NONE
);
153 // toolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
155 final ToolItem itemSave
= new ToolItem(toolBar
, SWT
.PUSH
);
156 itemSave
.setToolTipText("Save taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
157 itemSave
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/save.gif"));
158 itemSave
.addSelectionListener(new SelectionListener() {
159 public void mouseDown(final MouseEvent e
) {
161 // taxonname.setGenus(txtGenus.getText());
162 // taxonname.setSpecificEpithet(txtSpEpi.getText());
164 new SaveNameAction(taxonname
).run();
167 public void widgetDefaultSelected(SelectionEvent e
) {
168 new SaveNameAction(taxonname
).run();
171 public void widgetSelected(SelectionEvent e
) {
172 new SaveNameAction(taxonname
).run();
176 final ToolItem itemMove
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
177 itemMove
.setToolTipText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
178 itemMove
.addSelectionListener(new SelectionAdapter() {
179 public void widgetSelected(final SelectionEvent e
) {
183 final Menu menuMove
= new Menu(toolBar
);
184 menuMove
.setData("x", null);
185 addDropDown(itemMove
, menuMove
);
187 final MenuItem moveTaxonpilosellaMenuItem
= new MenuItem(menuMove
, SWT
.NONE
);
188 moveTaxonpilosellaMenuItem
.setText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" to another higher taxon");
190 final MenuItem turnTaxonpilosellaMenuItem
= new MenuItem(menuMove
, SWT
.NONE
);
191 turnTaxonpilosellaMenuItem
.setText("Turn taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" into a synonym");
194 // newItemToolItem.setText("New item");
195 itemMove
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/move_no_bg.gif"));
197 final ToolItem itemDelete
= new ToolItem(toolBar
, SWT
.NONE
);
198 itemDelete
.setToolTipText("Delete taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
199 itemDelete
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/delete.gif"));
201 final ToolItem separator1
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
203 final ToolItem itemAddRelationship
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
204 itemAddRelationship
.setToolTipText("Add nom. or tax. relation to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
205 itemAddRelationship
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/rel_no_bg.gif"));
207 final Menu menuAddRel
= new Menu(toolBar
);
208 menuAddRel
.setData("x", null);
209 addDropDown(itemAddRelationship
, menuAddRel
);
211 final MenuItem testMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
212 testMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/unknown_no_bg.gif"));
213 testMenuItem
.setText("Add synonymy (type unknown)");
215 final MenuItem addHomotypicSynonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
216 addHomotypicSynonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/homosyn_no_bg.gif"));
217 addHomotypicSynonymMenuItem
.setText("Add homotypic synonym");
219 final MenuItem addHeterotypicSynoynmMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
220 addHeterotypicSynoynmMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/heterosyn_no_bg.gif"));
221 addHeterotypicSynoynmMenuItem
.setText("Add heterotypic synoynm");
223 final MenuItem addBasionymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
224 addBasionymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/basionym_no_bg.gif"));
225 addBasionymMenuItem
.setText("Add basionym");
227 final MenuItem addReplacedSynonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
228 addReplacedSynonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/repsyn_no_bg.gif"));
229 addReplacedSynonymMenuItem
.setText("Add replaced synonym");
231 final MenuItem addHomonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
232 addHomonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/homonym_no_bg.gif"));
233 addHomonymMenuItem
.setText("Add homonym");
235 final MenuItem addOrthographicVariantMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
236 addOrthographicVariantMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/orthovariant_no_bg.gif"));
237 addOrthographicVariantMenuItem
.setText("Add orthographic variant");
239 final MenuItem addMisappliedNameMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
240 addMisappliedNameMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/misapplied_no_bg.gif"));
241 addMisappliedNameMenuItem
.setText("Add misapplied name");
243 final MenuItem addConceptRelationMenuItem_1
= new MenuItem(menuAddRel
, SWT
.CASCADE
);
244 addConceptRelationMenuItem_1
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/concept_no_bg.gif"));
245 addConceptRelationMenuItem_1
.setText("Add concept relation");
247 final Menu menu
= new Menu(addConceptRelationMenuItem_1
);
248 addConceptRelationMenuItem_1
.setMenu(menu
);
250 final MenuItem checkboxMenuItem
= new MenuItem(menu
, SWT
.CHECK
);
251 checkboxMenuItem
.setText("congruent");
253 final MenuItem checkboxMenuItem_1
= new MenuItem(menu
, SWT
.CHECK
);
254 checkboxMenuItem_1
.setSelection(true);
255 checkboxMenuItem_1
.setText("included in");
257 final MenuItem checkboxMenuItem_2
= new MenuItem(menu
, SWT
.CHECK
);
258 checkboxMenuItem_2
.setText("includes");
260 final MenuItem checkboxMenuItem_3
= new MenuItem(menu
, SWT
.CHECK
);
261 checkboxMenuItem_3
.setText("overlaps");
263 final MenuItem checkboxMenuItem_4
= new MenuItem(menu
, SWT
.CHECK
);
264 checkboxMenuItem_4
.setText("excludes");
266 final MenuItem checkboxMenuItem_5
= new MenuItem(menu
, SWT
.CHECK
);
267 checkboxMenuItem_5
.setSelection(true);
268 checkboxMenuItem_5
.setText("doubtful");
270 final ToolItem separator2
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
272 final ToolItem itemAddTaxon
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
273 itemAddTaxon
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/add_no_bg2.gif"));
274 itemAddTaxon
.setToolTipText("Add new taxon");
276 final Menu menuAdd
= new Menu(toolBar
);
277 menuAdd
.setData("x", null);
278 addDropDown(itemAddTaxon
, menuAdd
);
280 final MenuItem addTaxonToMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
281 addTaxonToMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
283 final MenuItem addNewTaxonMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
284 addNewTaxonMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra coll.\"");
286 final Composite composite
= new Composite(parent
, SWT
.NONE
);
287 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
288 composite
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
289 final GridLayout gridLayout_2
= new GridLayout();
290 gridLayout_2
.horizontalSpacing
= 3;
291 gridLayout_2
.numColumns
= 2;
292 composite
.setLayout(gridLayout_2
);
294 carduusLSpText
= new Text(composite
, SWT
.WRAP
);
295 carduusLSpText
.setText("Carduus L., Sp. Pl.: 820. 1753");
296 carduusLSpText
.setFont(SWTResourceManager
.getFont("Georgia", 12, SWT
.NONE
));
297 final GridData gd_carduusLSpText
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
298 carduusLSpText
.setLayoutData(gd_carduusLSpText
);
299 carduusLSpText
.addFocusListener(new FocusListener() {
301 public void focusGained(FocusEvent e
) {
302 carduusLSpText
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_LIGHT_SHADOW
));
305 public void focusLost(FocusEvent e
) {
306 carduusLSpText
.setBackground(null);
311 table_1
= new Table(composite
, SWT
.BORDER
);
312 table_1
.setLinesVisible(true);
313 table_1
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.FILL
, true, true, 1, 2));
315 final TableColumn newColumnTableColumn
= new TableColumn(table_1
, SWT
.NONE
);
316 newColumnTableColumn
.setWidth(100);
317 newColumnTableColumn
.setText("New column");
319 final TableColumn newColumnTableColumn_1
= new TableColumn(table_1
, SWT
.NONE
);
320 newColumnTableColumn_1
.setWidth(100);
321 newColumnTableColumn_1
.setText("New column");
323 final TableItem newItemTableItem
= new TableItem(table_1
, SWT
.BORDER
);
324 newItemTableItem
.setText(0, "Rank");
325 newItemTableItem
.setText(1, "genus");
326 newItemTableItem
.setText("Rank");
328 final TableItem newItemTableItem_1
= new TableItem(table_1
, SWT
.BORDER
);
329 newItemTableItem_1
.setText(1, "Carduus");
330 newItemTableItem_1
.setText(0, "Genus");
332 final TableItem newItemTableItem_2
= new TableItem(table_1
, SWT
.BORDER
);
333 newItemTableItem_2
.setText(0, "Species epithet");
335 final TableItem newItemTableItem_3
= new TableItem(table_1
, SWT
.BORDER
);
336 newItemTableItem_3
.setText(1, "L.");
337 newItemTableItem_3
.setText(0, "Author team");
339 final TableItem newItemTableItem_4
= new TableItem(table_1
, SWT
.BORDER
);
340 newItemTableItem_4
.setText("...");
341 // newItemTableItem_2.setText("Species epithet");
342 // newItemTableItem_1.setText("Genus");
343 //container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
345 SourceViewer sourceviewer
= new SourceViewer(composite
, null, SWT
.WRAP
| SWT
.FULL_SELECTION
);
346 sourceviewer
.setAnnotationHover(null);
347 styledText
= sourceviewer
.getTextWidget();
348 final GridData gd_styledText
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
349 // gd_styledText.heightHint = 41;
350 // gd_styledText.widthHint = 450;
351 styledText
.setLayoutData(gd_styledText
);
352 sourceviewer
.setDocument(doc
);
353 sourceviewer
.configure(new MySourceViewerConfig());
354 sourceviewer
.setTabsToSpacesConverter(null);
357 // final Menu menu = new Menu(toolBar);
358 // addDropDown(newItemToolItem, menu);
361 // Action testAction = new OpenNameEditorAction();
362 // testAction.setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.getDefault(), "icons/edit_16x16.gif"));
363 // testAction.setToolTipText("Add relation");
364 // toolBar.add(testAction);
369 // private void populateForm() {
371 // String fulltext = "";
373 // if (taxonname.getGenus() != null) {
374 // fulltext = taxonname.getGenus();
377 // if (taxonname.getSpecificEpithet() != null) {
378 // fulltext += " " + taxonname.getSpecificEpithet();
381 // if (taxonname.getAuthorship() != null) {
382 // fulltext += " " + taxonname.getAuthorship();
385 //// txtPlay.setText(fulltext);
386 //// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");
388 // this.setPartName(taxonname.getName());
391 private void populateForm() {
392 this.setPartName("Pilosella fuscoatra (Nägeli & Peter) Soják");
396 public void setFocus() {
401 public void doSave(IProgressMonitor monitor
) {
402 // Do the Save operation
406 public void doSaveAs() {
407 // Do the Save As operation
411 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
413 if (!(input
instanceof IEditorInput
))
414 throw new PartInitException(
415 "Invalid Input: Must be IFileEditorInput");
417 if (input
.getAdapter(TaxonName
.class) != null) {
418 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
419 // taxonname.addCdmEventListener(this);
430 public boolean isDirty() {
435 public boolean isSaveAsAllowed() {
439 public void propertyChange(PropertyChangeEvent evt
) {
440 // TaxonName taxonname = (TaxonName)evt.getNewValue();
441 this.taxonname
= (TaxonName
)evt
.getNewValue();
442 System
.out
.println(((TaxonName
)evt
.getNewValue()).getName());
445 // for individual fields, do something like:
446 // if (evt.getPropertyName().equalsIgnoreCase("genus"))
447 // txtGenus.setText ...
450 // public void onDelete(ICdmEventListenerRegistration arg0) {
451 // // TODO Auto-generated method stub
455 public void onInsert(Object arg0
) {
456 // TODO Auto-generated method stub
460 public void onLoad(Object arg0
) {
461 // TODO Auto-generated method stub
465 // public void onUpdate(ICdmEventListenerRegistration arg0) {
466 // // TODO Auto-generated method stub
470 private static void addDropDown(final ToolItem item
, final Menu menu
) {
471 item
.addListener(SWT
.Selection
, new Listener() {
472 public void handleEvent(Event event
) {
473 if (event
.detail
== SWT
.ARROW
) {
474 Rectangle rect
= item
.getBounds();
475 Point pt
= new Point(rect
.x
, rect
.y
+ rect
.height
);
476 pt
= item
.getParent().toDisplay(pt
);
477 menu
.setLocation(pt
.x
, pt
.y
);
478 menu
.setVisible(true);