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
{
52 private TableViewer associationsViewer
;
54 public TaxonAssociationDetailElement(CdmFormFactory formFactory
, ICdmFormElement formElement
) {
55 super(formFactory
, formElement
);
60 protected void createControls(ICdmFormElement formElement
, DerivedUnitFacade entity
, int style
) {
62 //TODO add context menu for deleting associations
64 Collection
<TaxonBase
<?
>> associatedTaxa
= CdmStore
.getService(IOccurrenceService
.class).listAssociatedTaxa(entity
.innerDerivedUnit(), null, null, null, null);
66 if(!associatedTaxa
.isEmpty()){
67 associationsViewer
= new TableViewer(getLayoutComposite(), SWT
.FULL_SELECTION
);
68 associationsViewer
.getTable().setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
69 associationsViewer
.setContentProvider(new ArrayContentProvider());
70 associationsViewer
.setInput(associatedTaxa
);
71 associationsViewer
.addDoubleClickListener(this);
74 Label label
= formFactory
.createLabel(getLayoutComposite(), "No associations");
75 label
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
82 public void handleEvent(Object eventSource
) {
87 public void doubleClick(DoubleClickEvent event
) {
88 if(event
.getSelection() instanceof IStructuredSelection
){
89 Object firstElement
= ((IStructuredSelection
) event
.getSelection()).getFirstElement();
90 if(firstElement
instanceof TaxonBase
<?
>){
91 TaxonBase
<?
> taxonBase
= (TaxonBase
<?
>)firstElement
;
92 String commandId
= "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
95 ArrayList parameters
= new ArrayList();
96 IParameter iparam
= null;
98 //get the command from plugin.xml
99 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
100 ICommandService cmdService
= (ICommandService
)window
.getService(ICommandService
.class);
101 Command cmd
= cmdService
.getCommand(commandId
);
105 iparam
= cmd
.getParameter("eu.etaxonomy.taxeditor.editor.taxonParameter");
106 } catch (NotDefinedException e1
) {
107 MessagingUtils
.error(this.getClass(), "Command not defined", e1
);
109 Parameterization params
= new Parameterization(iparam
, (taxonBase
).getUuid().toString());
110 parameters
.add(params
);
112 //build the parameterized command
113 ParameterizedCommand pc
= new ParameterizedCommand(cmd
, (Parameterization
[]) parameters
.toArray(new Parameterization
[parameters
.size()]));
115 //execute the command
116 IHandlerService handlerService
= (IHandlerService
)window
.getService(IHandlerService
.class);
118 handlerService
.executeCommand(pc
, null);
119 } catch (ExecutionException e
) {
120 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
121 } catch (NotDefinedException e
) {
122 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
123 } catch (NotEnabledException e
) {
124 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);
125 } catch (NotHandledException e
) {
126 MessagingUtils
.error(TaxonAssociationDetailElement
.class, e
);