9 |
9 |
*/
|
10 |
10 |
package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
|
11 |
11 |
|
12 |
|
import java.util.ArrayList;
|
13 |
12 |
import java.util.Collection;
|
14 |
13 |
import java.util.Set;
|
15 |
|
import java.util.UUID;
|
16 |
14 |
|
17 |
|
import org.eclipse.core.commands.Command;
|
18 |
|
import org.eclipse.core.commands.ExecutionException;
|
19 |
|
import org.eclipse.core.commands.IParameter;
|
20 |
|
import org.eclipse.core.commands.NotEnabledException;
|
21 |
|
import org.eclipse.core.commands.NotHandledException;
|
22 |
|
import org.eclipse.core.commands.Parameterization;
|
23 |
|
import org.eclipse.core.commands.ParameterizedCommand;
|
24 |
|
import org.eclipse.core.commands.common.NotDefinedException;
|
25 |
15 |
import org.eclipse.jface.viewers.ArrayContentProvider;
|
26 |
16 |
import org.eclipse.jface.viewers.DoubleClickEvent;
|
27 |
17 |
import org.eclipse.jface.viewers.IDoubleClickListener;
|
28 |
18 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
29 |
19 |
import org.eclipse.jface.viewers.LabelProvider;
|
30 |
|
import org.eclipse.jface.viewers.TableViewer;
|
|
20 |
import org.eclipse.jface.viewers.ListViewer;
|
31 |
21 |
import org.eclipse.swt.SWT;
|
32 |
22 |
import org.eclipse.swt.widgets.Label;
|
33 |
|
import org.eclipse.ui.IWorkbenchWindow;
|
34 |
|
import org.eclipse.ui.PlatformUI;
|
35 |
|
import org.eclipse.ui.commands.ICommandService;
|
36 |
|
import org.eclipse.ui.handlers.IHandlerService;
|
37 |
23 |
|
38 |
24 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
39 |
25 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
... | ... | |
47 |
33 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
48 |
34 |
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
49 |
35 |
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
|
36 |
import eu.etaxonomy.taxeditor.view.CdmViewerChooser;
|
50 |
37 |
|
51 |
38 |
/**
|
52 |
39 |
* @author pplitzner
|
... | ... | |
75 |
62 |
return;
|
76 |
63 |
}
|
77 |
64 |
if(!associatedTaxa.isEmpty()){
|
78 |
|
TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
79 |
|
viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
|
65 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
|
66 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
80 |
67 |
viewer.setContentProvider(new ArrayContentProvider());
|
81 |
68 |
viewer.setLabelProvider(new LabelProvider(){
|
82 |
69 |
@Override
|
... | ... | |
88 |
75 |
viewer.addDoubleClickListener(this);
|
89 |
76 |
}
|
90 |
77 |
if(!typeDesignations.isEmpty()){
|
91 |
|
TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
92 |
|
viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
|
78 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
|
79 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
93 |
80 |
viewer.setContentProvider(new ArrayContentProvider());
|
94 |
81 |
viewer.setLabelProvider(new LabelProvider(){
|
95 |
82 |
@Override
|
... | ... | |
110 |
97 |
viewer.addDoubleClickListener(this);
|
111 |
98 |
}
|
112 |
99 |
if(!determinationEvents.isEmpty()){
|
113 |
|
TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
114 |
|
viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
|
100 |
ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.FULL_SELECTION);
|
|
101 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
115 |
102 |
viewer.setContentProvider(new ArrayContentProvider());
|
116 |
103 |
viewer.setLabelProvider(new LabelProvider(){
|
117 |
104 |
@Override
|
... | ... | |
141 |
128 |
public void doubleClick(DoubleClickEvent event) {
|
142 |
129 |
if(event.getSelection() instanceof IStructuredSelection){
|
143 |
130 |
Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
|
144 |
|
UUID taxonToOpenUuid = null;
|
145 |
|
if(firstElement instanceof TaxonBase<?>){
|
146 |
|
taxonToOpenUuid = ((TaxonBase<?>)firstElement).getUuid();
|
147 |
|
}
|
148 |
|
else if(firstElement instanceof SpecimenTypeDesignation){
|
149 |
|
//TODO how to open an editor for all typed names?
|
|
131 |
if(firstElement instanceof SpecimenTypeDesignation){
|
|
132 |
SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)firstElement;
|
|
133 |
Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames();
|
|
134 |
if(typifiedNames.size()==1){
|
|
135 |
firstElement = typifiedNames.iterator().next();
|
|
136 |
}
|
|
137 |
if(typifiedNames.size()==0 || typifiedNames.size()>=2){
|
|
138 |
MessagingUtils.informationDialog("Could not open name", "Type designation has either 0 or more than 1 names associated");
|
|
139 |
}
|
150 |
140 |
}
|
151 |
141 |
else if(firstElement instanceof DeterminationEvent){
|
152 |
142 |
if(((DeterminationEvent) firstElement).getTaxon()!=null){
|
153 |
|
taxonToOpenUuid = ((DeterminationEvent) firstElement).getTaxon().getUuid();
|
|
143 |
firstElement = ((DeterminationEvent) firstElement).getTaxon();
|
154 |
144 |
}
|
155 |
145 |
else if(((DeterminationEvent) firstElement).getTaxonName()!=null){
|
156 |
|
//TODO how to open editor for taxon name
|
157 |
|
}
|
158 |
|
}
|
159 |
|
if(taxonToOpenUuid!=null){
|
160 |
|
String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
|
161 |
|
|
162 |
|
|
163 |
|
ArrayList parameters = new ArrayList();
|
164 |
|
IParameter iparam = null;
|
165 |
|
|
166 |
|
//get the command from plugin.xml
|
167 |
|
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
168 |
|
ICommandService cmdService = (ICommandService)window.getService(ICommandService.class);
|
169 |
|
Command cmd = cmdService.getCommand(commandId);
|
170 |
|
|
171 |
|
//get the parameter
|
172 |
|
try {
|
173 |
|
iparam = cmd.getParameter("eu.etaxonomy.taxeditor.editor.taxonParameter");
|
174 |
|
} catch (NotDefinedException e1) {
|
175 |
|
MessagingUtils.error(this.getClass(), "Command not defined", e1);
|
176 |
|
}
|
177 |
|
Parameterization params = new Parameterization(iparam, taxonToOpenUuid.toString());
|
178 |
|
parameters.add(params);
|
179 |
|
|
180 |
|
//build the parameterized command
|
181 |
|
ParameterizedCommand pc = new ParameterizedCommand(cmd, (Parameterization[]) parameters.toArray(new Parameterization[parameters.size()]));
|
182 |
|
|
183 |
|
//execute the command
|
184 |
|
IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
|
185 |
|
try {
|
186 |
|
handlerService.executeCommand(pc, null);
|
187 |
|
} catch (ExecutionException e) {
|
188 |
|
MessagingUtils.error(TaxonAssociationDetailElement.class, e);
|
189 |
|
} catch (NotDefinedException e) {
|
190 |
|
MessagingUtils.error(TaxonAssociationDetailElement.class, e);
|
191 |
|
} catch (NotEnabledException e) {
|
192 |
|
MessagingUtils.error(TaxonAssociationDetailElement.class, e);
|
193 |
|
} catch (NotHandledException e) {
|
194 |
|
MessagingUtils.error(TaxonAssociationDetailElement.class, e);
|
|
146 |
firstElement = ((DeterminationEvent) firstElement).getTaxonName();
|
195 |
147 |
}
|
196 |
148 |
}
|
|
149 |
new CdmViewerChooser(event.getViewer().getControl().getShell()).chooseViewer(firstElement);
|
197 |
150 |
}
|
198 |
151 |
}
|
199 |
152 |
}
|
ref #5348 Reduce space of taxon associations