2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
;
12 import java
.util
.Collection
;
13 import java
.util
.HashSet
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.core
.commands
.operations
.UndoContext
;
19 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
20 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
21 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
22 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
23 import org
.eclipse
.jface
.wizard
.WizardDialog
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
30 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
38 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
39 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
40 import eu
.etaxonomy
.taxeditor
.editor
.e4
.TaxonEditorInputE4
;
41 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
42 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
43 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
44 import eu
.etaxonomy
.taxeditor
.navigation
.internal
.TaxeditorNavigationPlugin
;
45 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
46 import eu
.etaxonomy
.taxeditor
.newWizard
.NewClassificationWizard
;
47 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
48 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
56 public class NavigationUtil
extends AbstractUtility
{
58 private static final String NOT_IMPLEMENTED_YET
= Messages
.NavigationUtil_NOT_IMPLEMENTED
;
59 private static IUndoContext defaultUndoContext
;
64 * @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object.
66 public static void openEditor(UuidAndTitleCache uuidAndTitleCache
, Shell shell
, EModelService modelService
, EPartService partService
, MApplication application
){
67 Class
<?
> type
= uuidAndTitleCache
.getType();
68 ICdmBase cdmBase
= null;
69 if(uuidAndTitleCache
instanceof TaxonNodeDto
){
70 EditorUtil
.openTaxonNodeE4(uuidAndTitleCache
.getUuid(), modelService
, partService
, application
);
73 else if(type
.equals(Classification
.class)){
74 cdmBase
= CdmStore
.getService(IClassificationService
.class).load(uuidAndTitleCache
.getUuid());
76 else if(type
.equals(TaxonNode
.class)){
77 cdmBase
= CdmStore
.getService(ITaxonNodeService
.class).load(uuidAndTitleCache
.getUuid());
79 else if(TaxonBase
.class.isAssignableFrom(type
)){
80 cdmBase
= CdmStore
.getService(ITaxonService
.class).load(uuidAndTitleCache
.getUuid());
82 else if(type
.equals(TaxonName
.class)){
83 cdmBase
= CdmStore
.getService(INameService
.class).load(uuidAndTitleCache
.getUuid());
86 MessagingUtils
.warningDialog(Messages
.NavigationUtil_UNKNOWN_TYPE
, NavigationUtil
.class, Messages
.NavigationUtil_UNKNOWN_TYPE_MESSAGE
);
89 openEditor(cdmBase
, shell
, modelService
, partService
, application
);
92 MessagingUtils
.warningDialog(Messages
.NavigationUtil_NOT_FOUND
, NavigationUtil
.class, Messages
.NavigationUtil_NOT_FOUND_MESSAGE
);
96 public static void openEditor(ICdmBase selectedObject
, Shell shell
, EModelService modelService
, EPartService partService
, MApplication application
){
97 UUID entityUuid
= selectedObject
.getUuid();
99 if(selectedObject
instanceof TaxonNode
){
100 TaxonNode taxonNode
= (TaxonNode
)selectedObject
;
101 Classification classification
= taxonNode
.getClassification();
102 if(classification
!=null && classification
.getRootNode().equals(taxonNode
)){
103 NewClassificationWizard classificationWizard
= new NewClassificationWizard();
104 classificationWizard
.init(null, null);
105 classificationWizard
.setEntity(classification
);
106 WizardDialog dialog
= new WizardDialog(shell
, classificationWizard
);
110 EditorUtil
.openTaxonNodeE4(entityUuid
, modelService
, partService
, application
);
113 else if(selectedObject
instanceof TaxonBase
){
114 EditorUtil
.openTaxonBaseE4(entityUuid
, modelService
, partService
, application
);
117 MessagingUtils
.warningDialog(Messages
.NavigationUtil_UNSUPPORTED_TYPE
, NavigationUtil
.class, Messages
.NavigationUtil_UNSUPPORTED_TYPE_MESSAGE
+ selectedObject
);
119 } catch (Exception e
) {
120 MessagingUtils
.errorDialog(Messages
.NavigationUtil_CREATE_FAILED
,
121 NavigationUtil
.class,
122 e
.getMessage(), TaxeditorStorePlugin
.PLUGIN_ID
,
132 * @param parentNodeUuid a {@link java.util.UUID} object.
134 public static void openEmpty(UUID parentNodeUuid
) {
135 EditorUtil
.openEmptyE4(parentNodeUuid
);
139 * <p>getUndoContext</p>
141 * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object.
143 public static IUndoContext
getUndoContext() {
144 // FIXME this has to be more specific. Every widget has to have its own undo context
145 // return IOperationHistory.GLOBAL_UNDO_CONTEXT;
147 // Plug-ins that wish their operations to be undoable from workbench views
148 // such as the Navigator or Package Explorer should assign the workbench
149 // undo context to their operations.
150 if (defaultUndoContext
== null) {
151 defaultUndoContext
= new UndoContext();
153 return defaultUndoContext
;
157 * Whether a taxonNode has unsaved changes.
159 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
162 public static boolean isDirty(TaxonNodeDto taxonNode
, EPartService partService
){
164 Collection
<MPart
> dirtyParts
= partService
.getDirtyParts();
165 for (MPart part
: dirtyParts
) {
166 if(part
.getObject() instanceof TaxonNameEditorE4
){
167 TaxonEditorInputE4 input
= ((TaxonNameEditorE4
) part
.getObject()).getEditorInput();
168 if(input
.getTaxonNode().getUuid().equals(taxonNode
.getUuid())){
177 * Whether a taxonNode has unsaved changes.
179 * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
182 public static boolean isDirty(TaxonNode taxonNode
, EPartService partService
){
184 Collection
<MPart
> dirtyParts
= partService
.getDirtyParts();
185 for (MPart part
: dirtyParts
) {
186 if(part
.getObject() instanceof TaxonNameEditorE4
){
187 TaxonEditorInputE4 input
= ((TaxonNameEditorE4
) part
.getObject()).getEditorInput();
188 if(input
.getTaxonNode().equals(taxonNode
)){
199 * @param selection a {@link java.lang.Object} object.
201 public static void openSearch(Object selection
) {
202 if(selection
instanceof Taxon
){
203 Taxon taxon
= (Taxon
) selection
;
205 handleOpeningOfMultipleTaxonNodes(taxon
.getTaxonNodes());
207 }else if(selection
instanceof Synonym
){
208 Synonym synonym
= (Synonym
) selection
;
210 Set
<Taxon
> accTaxa
= new HashSet
<Taxon
>();
211 if (synonym
.getAcceptedTaxon() != null){
212 accTaxa
.add(synonym
.getAcceptedTaxon());
214 handleOpeningOfMultipleTaxa(accTaxa
);
217 MessagingUtils
.warningDialog(NOT_IMPLEMENTED_YET
, NavigationUtil
.class, Messages
.NavigationUtil_ORPHAN_NAME_MESSAGE
);
222 private static void handleOpeningOfMultipleTaxa(Set
<Taxon
> acceptedTaxa
) {
223 //FIXME E4 migrate/delete
224 // if(acceptedTaxa.size() == 1){
225 // openEditor(acceptedTaxa.iterator().next(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
226 // }else if(acceptedTaxa.size() > 1){
227 // // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
228 // MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, Messages.NavigationUtil_MULTI_TREE);
229 // }else if(acceptedTaxa.size() == 0){
230 // // this is an undesired state
231 // MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, Messages.NavigationUtil_ORPHAN_TAXON);
238 private static void handleOpeningOfMultipleTaxonNodes(
239 Set
<TaxonNode
> taxonNodes
) {
240 //FIXME E4 migrate/delete
242 // if(taxonNodes.size() == 1){
243 // openEditor(taxonNodes.iterator().next(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
244 // }else if(taxonNodes.size() > 1){
245 // // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
246 // MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, "The accepted taxon is in multiple taxonomic trees. We currently do not know which one you want to open. This case is not handled yet by the software.");
247 // }else if(taxonNodes.size() == 0){
248 // // this is an undesired state
249 // MessagingUtils.warningDialog(Messages.NavigationUtil_INCORRECT_STATE, NavigationUtil.class, Messages.NavigationUtil_INCORRECT_STATE_MESSAGE);
256 * @return a {@link java.lang.String} object.
258 public static String
getPluginId(){
259 return TaxeditorNavigationPlugin
.PLUGIN_ID
;