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
.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
.taxeditor
.designproposal1
.Activator
;
60 import eu
.etaxonomy
.taxeditor
.designproposal1
.controller
.OpenNameEditorAction
;
61 import eu
.etaxonomy
.taxeditor
.designproposal1
.controller
.SaveNameAction
;
62 import eu
.etaxonomy
.taxeditor
.designproposal1
.model
.TaxonName
;
64 //public class CarduusEditorView extends EditorPart implements ICdmEventListener {
65 public class CarduusEditorView
extends EditorPart
{
67 private Table table_1
;
68 private Text carduusLSpText
;
69 private StyledText styledText
;
70 private TaxonName taxonname
;
72 public static final String ID
= "eu.etaxonomy.taxeditor.designproposal1.view.carduuseditorview"; //$NON-NLS-1$
75 * Create contents of the editor part
79 public void createPartControl(Composite parent
) {
83 // txtPlay = new Text(container, SWT.BORDER);
84 // txtPlay.setCapture(true);
85 // final GridData gd_txtPlay = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
86 // gd_txtPlay.heightHint = 96;
87 // txtPlay.setLayoutData(gd_txtPlay);
88 //// txtPlay.addVerifyListener(new VerifyListener() {
90 //// public void verifyText(VerifyEvent e) {
91 //// e.doit = Character.isDigit(e.character);
94 // txtPlay.addSelectionListener(new SelectionListener() {
97 // public void widgetDefaultSelected(SelectionEvent e) {
98 // // TODO Auto-generated method stub
103 // public void widgetSelected(SelectionEvent e) {
104 // System.out.println(e.toString());
111 // txtPlay.addKeyListener(new KeyListener() {
113 // public void keyPressed(KeyEvent e) {
114 // System.out.println(e.character);
115 // if (e.character == '=') {
116 // Shell shell = Activator.getDefault().getWorkbench().
117 // getActiveWorkbenchWindow().getShell();
118 // PopupList list = new PopupList(shell, SWT.H_SCROLL | SWT.V_SCROLL);
120 //// Combo list = new Combo(shell, SWT.H_SCROLL | SWT.V_SCROLL);
122 // // Add the items to the list
123 // String[] OPTIONS = { "Create homo. syn.",
124 // "Create hetero. syn.",
125 // "Create mis. name",
126 // "Create homonym"};
128 // list.setItems(OPTIONS);
130 // // Open the list and get the selected item
131 // String selected = list.open(txtPlay.getBounds());
133 // // Print the item to the console
134 // System.out.println(selected);
139 // public void keyReleased(KeyEvent e) {
140 // // TODO Auto-generated method stub
144 parent
.setLayout(new GridLayout());
145 Document doc
= new Document("");
147 final Label taxonomicallyIncludedInLabel
= new Label(parent
, SWT
.NONE
);
148 taxonomicallyIncludedInLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
149 taxonomicallyIncludedInLabel
.setText("Higher taxon: \"Cardueae Cass.\"");
151 final ToolBar toolBar
= new ToolBar(parent
, SWT
.NONE
);
152 // toolBar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
154 final ToolItem itemSave
= new ToolItem(toolBar
, SWT
.PUSH
);
155 itemSave
.setToolTipText("Save taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
156 itemSave
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/save.gif"));
157 itemSave
.addSelectionListener(new SelectionListener() {
158 public void mouseDown(final MouseEvent e
) {
160 // taxonname.setGenus(txtGenus.getText());
161 // taxonname.setSpecificEpithet(txtSpEpi.getText());
163 new SaveNameAction(taxonname
).run();
166 public void widgetDefaultSelected(SelectionEvent e
) {
167 new SaveNameAction(taxonname
).run();
170 public void widgetSelected(SelectionEvent e
) {
171 new SaveNameAction(taxonname
).run();
175 final ToolItem itemMove
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
176 itemMove
.setToolTipText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
177 itemMove
.addSelectionListener(new SelectionAdapter() {
178 public void widgetSelected(final SelectionEvent e
) {
182 final Menu menuMove
= new Menu(toolBar
);
183 menuMove
.setData("x", null);
184 addDropDown(itemMove
, menuMove
);
186 final MenuItem moveTaxonpilosellaMenuItem
= new MenuItem(menuMove
, SWT
.NONE
);
187 moveTaxonpilosellaMenuItem
.setText("Move taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" to another higher taxon");
189 final MenuItem turnTaxonpilosellaMenuItem
= new MenuItem(menuMove
, SWT
.NONE
);
190 turnTaxonpilosellaMenuItem
.setText("Turn taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\" into a synonym");
193 // newItemToolItem.setText("New item");
194 itemMove
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/move_no_bg.gif"));
196 final ToolItem itemDelete
= new ToolItem(toolBar
, SWT
.NONE
);
197 itemDelete
.setToolTipText("Delete taxon \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
198 itemDelete
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/delete.gif"));
200 final ToolItem separator1
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
202 final ToolItem itemAddRelationship
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
203 itemAddRelationship
.setToolTipText("Add nom. or tax. relation to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
204 itemAddRelationship
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/rel_no_bg.gif"));
206 final Menu menuAddRel
= new Menu(toolBar
);
207 menuAddRel
.setData("x", null);
208 addDropDown(itemAddRelationship
, menuAddRel
);
210 final MenuItem testMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
211 testMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/unknown_no_bg.gif"));
212 testMenuItem
.setText("Add synonymy (type unknown)");
214 final MenuItem addHomotypicSynonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
215 addHomotypicSynonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/homosyn_no_bg.gif"));
216 addHomotypicSynonymMenuItem
.setText("Add homotypic synonym");
218 final MenuItem addHeterotypicSynoynmMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
219 addHeterotypicSynoynmMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/heterosyn_no_bg.gif"));
220 addHeterotypicSynoynmMenuItem
.setText("Add heterotypic synoynm");
222 final MenuItem addBasionymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
223 addBasionymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/basionym_no_bg.gif"));
224 addBasionymMenuItem
.setText("Add basionym");
226 final MenuItem addReplacedSynonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
227 addReplacedSynonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/repsyn_no_bg.gif"));
228 addReplacedSynonymMenuItem
.setText("Add replaced synonym");
230 final MenuItem addHomonymMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
231 addHomonymMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/homonym_no_bg.gif"));
232 addHomonymMenuItem
.setText("Add homonym");
234 final MenuItem addOrthographicVariantMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
235 addOrthographicVariantMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/orthovariant_no_bg.gif"));
236 addOrthographicVariantMenuItem
.setText("Add orthographic variant");
238 final MenuItem addMisappliedNameMenuItem
= new MenuItem(menuAddRel
, SWT
.NONE
);
239 addMisappliedNameMenuItem
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/misapplied_no_bg.gif"));
240 addMisappliedNameMenuItem
.setText("Add misapplied name");
242 final MenuItem addConceptRelationMenuItem_1
= new MenuItem(menuAddRel
, SWT
.CASCADE
);
243 addConceptRelationMenuItem_1
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/concept_no_bg.gif"));
244 addConceptRelationMenuItem_1
.setText("Add concept relation");
246 final Menu menu
= new Menu(addConceptRelationMenuItem_1
);
247 addConceptRelationMenuItem_1
.setMenu(menu
);
249 final MenuItem checkboxMenuItem
= new MenuItem(menu
, SWT
.CHECK
);
250 checkboxMenuItem
.setText("congruent");
252 final MenuItem checkboxMenuItem_1
= new MenuItem(menu
, SWT
.CHECK
);
253 checkboxMenuItem_1
.setSelection(true);
254 checkboxMenuItem_1
.setText("included in");
256 final MenuItem checkboxMenuItem_2
= new MenuItem(menu
, SWT
.CHECK
);
257 checkboxMenuItem_2
.setText("includes");
259 final MenuItem checkboxMenuItem_3
= new MenuItem(menu
, SWT
.CHECK
);
260 checkboxMenuItem_3
.setText("overlaps");
262 final MenuItem checkboxMenuItem_4
= new MenuItem(menu
, SWT
.CHECK
);
263 checkboxMenuItem_4
.setText("excludes");
265 final MenuItem checkboxMenuItem_5
= new MenuItem(menu
, SWT
.CHECK
);
266 checkboxMenuItem_5
.setSelection(true);
267 checkboxMenuItem_5
.setText("doubtful");
269 final ToolItem separator2
= new ToolItem(toolBar
, SWT
.SEPARATOR
);
271 final ToolItem itemAddTaxon
= new ToolItem(toolBar
, SWT
.DROP_DOWN
);
272 itemAddTaxon
.setImage(ResourceManager
.getPluginImage(Activator
.getDefault(), "icons/add_no_bg2.gif"));
273 itemAddTaxon
.setToolTipText("Add new taxon");
275 final Menu menuAdd
= new Menu(toolBar
);
276 menuAdd
.setData("x", null);
277 addDropDown(itemAddTaxon
, menuAdd
);
279 final MenuItem addTaxonToMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
280 addTaxonToMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra (Nägeli & Peter) Soják\"");
282 final MenuItem addNewTaxonMenuItem
= new MenuItem(menuAdd
, SWT
.NONE
);
283 addNewTaxonMenuItem
.setText("Add new taxon to \"Pilosella fuscoatra coll.\"");
285 final Composite composite
= new Composite(parent
, SWT
.NONE
);
286 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
287 composite
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
288 final GridLayout gridLayout_2
= new GridLayout();
289 gridLayout_2
.horizontalSpacing
= 3;
290 gridLayout_2
.numColumns
= 2;
291 composite
.setLayout(gridLayout_2
);
293 carduusLSpText
= new Text(composite
, SWT
.WRAP
);
294 carduusLSpText
.setText("Carduus L., Sp. Pl.: 820. 1753");
295 carduusLSpText
.setFont(SWTResourceManager
.getFont("Georgia", 12, SWT
.NONE
));
296 final GridData gd_carduusLSpText
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
297 carduusLSpText
.setLayoutData(gd_carduusLSpText
);
298 carduusLSpText
.addFocusListener(new FocusListener() {
300 public void focusGained(FocusEvent e
) {
301 carduusLSpText
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_LIGHT_SHADOW
));
304 public void focusLost(FocusEvent e
) {
305 carduusLSpText
.setBackground(null);
310 table_1
= new Table(composite
, SWT
.BORDER
);
311 table_1
.setLinesVisible(true);
312 table_1
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.FILL
, true, true, 1, 2));
314 final TableColumn newColumnTableColumn
= new TableColumn(table_1
, SWT
.NONE
);
315 newColumnTableColumn
.setWidth(100);
316 newColumnTableColumn
.setText("New column");
318 final TableColumn newColumnTableColumn_1
= new TableColumn(table_1
, SWT
.NONE
);
319 newColumnTableColumn_1
.setWidth(100);
320 newColumnTableColumn_1
.setText("New column");
322 final TableItem newItemTableItem
= new TableItem(table_1
, SWT
.BORDER
);
323 newItemTableItem
.setText(0, "Rank");
324 newItemTableItem
.setText(1, "genus");
325 newItemTableItem
.setText("Rank");
327 final TableItem newItemTableItem_1
= new TableItem(table_1
, SWT
.BORDER
);
328 newItemTableItem_1
.setText(1, "Carduus");
329 newItemTableItem_1
.setText(0, "Genus");
331 final TableItem newItemTableItem_2
= new TableItem(table_1
, SWT
.BORDER
);
332 newItemTableItem_2
.setText(0, "Species epithet");
334 final TableItem newItemTableItem_3
= new TableItem(table_1
, SWT
.BORDER
);
335 newItemTableItem_3
.setText(1, "L.");
336 newItemTableItem_3
.setText(0, "Author team");
338 final TableItem newItemTableItem_4
= new TableItem(table_1
, SWT
.BORDER
);
339 newItemTableItem_4
.setText("...");
340 // newItemTableItem_2.setText("Species epithet");
341 // newItemTableItem_1.setText("Genus");
342 //container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
344 SourceViewer sourceviewer
= new SourceViewer(composite
, null, SWT
.WRAP
| SWT
.FULL_SELECTION
);
345 sourceviewer
.setAnnotationHover(null);
346 styledText
= sourceviewer
.getTextWidget();
347 final GridData gd_styledText
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
348 gd_styledText
.heightHint
= 41;
349 gd_styledText
.widthHint
= 450;
350 styledText
.setLayoutData(gd_styledText
);
351 sourceviewer
.setDocument(doc
);
352 sourceviewer
.configure(new MySourceViewerConfig());
353 sourceviewer
.setTabsToSpacesConverter(null);
356 // final Menu menu = new Menu(toolBar);
357 // addDropDown(newItemToolItem, menu);
360 // Action testAction = new OpenNameEditorAction();
361 // testAction.setImageDescriptor(ResourceManager.getPluginImageDescriptor(Activator.getDefault(), "icons/edit_16x16.gif"));
362 // testAction.setToolTipText("Add relation");
363 // toolBar.add(testAction);
368 // private void populateForm() {
370 // String fulltext = "";
372 // if (taxonname.getGenus() != null) {
373 // fulltext = taxonname.getGenus();
376 // if (taxonname.getSpecificEpithet() != null) {
377 // fulltext += " " + taxonname.getSpecificEpithet();
380 // if (taxonname.getAuthorship() != null) {
381 // fulltext += " " + taxonname.getAuthorship();
384 //// txtPlay.setText(fulltext);
385 //// txtPlay.setToolTipText("Joe mama\njoe daddy\njoe gramammy");
387 // this.setPartName(taxonname.getName());
390 private void populateForm() {
391 this.setPartName("Pilosella fuscoatra (Nägeli & Peter) Soják");
395 public void setFocus() {
400 public void doSave(IProgressMonitor monitor
) {
401 // Do the Save operation
405 public void doSaveAs() {
406 // Do the Save As operation
410 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
412 if (!(input
instanceof IEditorInput
))
413 throw new PartInitException(
414 "Invalid Input: Must be IFileEditorInput");
416 if (input
.getAdapter(TaxonName
.class) != null) {
417 taxonname
= (TaxonName
) input
.getAdapter(TaxonName
.class);
418 // taxonname.addCdmEventListener(this);
429 public boolean isDirty() {
434 public boolean isSaveAsAllowed() {
438 public void propertyChange(PropertyChangeEvent evt
) {
439 // TaxonName taxonname = (TaxonName)evt.getNewValue();
440 this.taxonname
= (TaxonName
)evt
.getNewValue();
441 System
.out
.println(((TaxonName
)evt
.getNewValue()).getName());
444 // for individual fields, do something like:
445 // if (evt.getPropertyName().equalsIgnoreCase("genus"))
446 // txtGenus.setText ...
449 // public void onDelete(ICdmEventListenerRegistration arg0) {
450 // // TODO Auto-generated method stub
454 public void onInsert(Object arg0
) {
455 // TODO Auto-generated method stub
459 public void onLoad(Object arg0
) {
460 // TODO Auto-generated method stub
464 // public void onUpdate(ICdmEventListenerRegistration arg0) {
465 // // TODO Auto-generated method stub
469 private static void addDropDown(final ToolItem item
, final Menu menu
) {
470 item
.addListener(SWT
.Selection
, new Listener() {
471 public void handleEvent(Event event
) {
472 if (event
.detail
== SWT
.ARROW
) {
473 Rectangle rect
= item
.getBounds();
474 Point pt
= new Point(rect
.x
, rect
.y
+ rect
.height
);
475 pt
= item
.getParent().toDisplay(pt
);
476 menu
.setLocation(pt
.x
, pt
.y
);
477 menu
.setVisible(true);