3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.association
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
15 import org
.eclipse
.core
.commands
.Command
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.IParameter
;
18 import org
.eclipse
.core
.commands
.NotEnabledException
;
19 import org
.eclipse
.core
.commands
.NotHandledException
;
20 import org
.eclipse
.core
.commands
.Parameterization
;
21 import org
.eclipse
.core
.commands
.ParameterizedCommand
;
22 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
23 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
24 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
25 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
26 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
27 import org
.eclipse
.jface
.viewers
.TableViewer
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.widgets
.Label
;
30 import org
.eclipse
.ui
.IWorkbenchWindow
;
31 import org
.eclipse
.ui
.PlatformUI
;
32 import org
.eclipse
.ui
.commands
.ICommandService
;
33 import org
.eclipse
.ui
.handlers
.IHandlerService
;
35 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
38 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
41 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
42 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
43 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
50 public class TaxonAssociationDetailElement
extends AbstractCdmDetailElement
<DerivedUnitFacade
> implements IDoubleClickListener
{
53 private TableViewer associationsViewer
;
54 private TableViewer typeDesignationViewer
;
56 public TaxonAssociationDetailElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
57 super(formFactory
, formElement
);
62 protected void createControls(ICdmFormElement formElement
, DerivedUnitFacade entity
, int style
) {
64 //TODO add context menu for deleting associations
66 Label associationsLabel
= formFactory
.createLabel(getLayoutComposite(), "Individuals Associations");
67 associationsLabel
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
69 associationsViewer
= new TableViewer(getLayoutComposite(), SWT
.FULL_SELECTION
);
70 associationsViewer
.getTable().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
71 associationsViewer
.setContentProvider(new ArrayContentProvider());
72 Collection
<TaxonBase
<?
>> associatedTaxa
= CdmStore
.getService(IOccurrenceService
.class).listAssociatedTaxa(entity
.innerDerivedUnit(), null, null, null, null);
73 associationsViewer
.setInput(associatedTaxa
);
74 associationsViewer
.addDoubleClickListener(this);
76 Label typeLabel
= formFactory
.createLabel(getLayoutComposite(), "Type Designations");
77 typeLabel
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
79 typeDesignationViewer
= new TableViewer(getLayoutComposite(), SWT
.FULL_SELECTION
);
80 typeDesignationViewer
.getTable().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
81 typeDesignationViewer
.setContentProvider(new ArrayContentProvider());
82 Collection
<TaxonBase
<?
>> typedTaxa
= CdmStore
.getService(IOccurrenceService
.class).listTypedTaxa(entity
.innerDerivedUnit(), null, null, null, null);
83 typeDesignationViewer
.setInput(typedTaxa
);
84 typeDesignationViewer
.addDoubleClickListener(this);
89 public void handleEvent(Object eventSource
) {
94 * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
97 public void doubleClick(DoubleClickEvent event
) {
98 if(associationsViewer
.getSelection() instanceof IStructuredSelection
){
99 Object firstElement
= ((IStructuredSelection
) associationsViewer
.getSelection()).getFirstElement();
100 if(firstElement
instanceof TaxonBase
<?
>){
101 TaxonBase
<?
> taxonBase
= (TaxonBase
<?
>)firstElement
;
102 String commandId
= "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
105 ArrayList parameters
= new ArrayList();
106 IParameter iparam
= null;
108 //get the command from plugin.xml
109 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
110 ICommandService cmdService
= (ICommandService
)window
.getService(ICommandService
.class);
111 Command cmd
= cmdService
.getCommand(commandId
);
115 iparam
= cmd
.getParameter("eu.etaxonomy.taxeditor.editor.taxonParameter");
116 } catch (NotDefinedException e1
) {
117 MessagingUtils
.error(this.getClass(), "Command not defined", e1
);
119 Parameterization params
= new Parameterization(iparam
, (taxonBase
).getUuid().toString());
120 parameters
.add(params
);
122 //build the parameterized command
123 ParameterizedCommand pc
= new ParameterizedCommand(cmd
, (Parameterization
[]) parameters
.toArray(new Parameterization
[parameters
.size()]));
125 //execute the command
126 IHandlerService handlerService
= (IHandlerService
)window
.getService(IHandlerService
.class);
128 handlerService
.executeCommand(pc
, null);
129 } catch (ExecutionException e
) {
130 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
131 } catch (NotDefinedException e
) {
132 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
133 } catch (NotEnabledException e
) {
134 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
135 } catch (NotHandledException e
) {
136 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);