ref #6909 migrate/delete e3 name editor refs
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / NavigationUtil.java
index c4d361d0fc03430b67a80f5ab04ee8d8a5abcc74..790b0a66a3470d3c0ccb39ca3520fcd180dbd8da 100644 (file)
@@ -24,7 +24,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
@@ -39,7 +38,7 @@ import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -52,6 +51,7 @@ import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
+import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -65,7 +65,10 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
  * @version 1.0
  */
 public class NavigationUtil extends AbstractUtility{
-       private static IUndoContext defaultUndoContext;
+
+    private static final String NOT_IMPLEMENTED_YET = Messages.NavigationUtil_NOT_IMPLEMENTED;
+    private static final String ERROR_OPENING_THE_EDITOR = Messages.NavigationUtil_OPEN_ERROR;
+    private static IUndoContext defaultUndoContext;
 
        /**
         * <p>openEditor</p>
@@ -73,7 +76,7 @@ public class NavigationUtil extends AbstractUtility{
         * @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object.
         */
        public static void openEditor(UuidAndTitleCache uuidAndTitleCache){
-           Class type = uuidAndTitleCache.getType();
+           Class<?> type = uuidAndTitleCache.getType();
            ICdmBase cdmBase = null;
            if(type.equals(Classification.class)){
                cdmBase = CdmStore.getService(IClassificationService.class).load(uuidAndTitleCache.getUuid());
@@ -84,51 +87,55 @@ public class NavigationUtil extends AbstractUtility{
            else if(TaxonBase.class.isAssignableFrom(type)){
                cdmBase = CdmStore.getService(ITaxonService.class).load(uuidAndTitleCache.getUuid());
            }
-           else if(type.equals(TaxonNameBase.class)){
+           else if(type.equals(TaxonName.class)){
                cdmBase = CdmStore.getService(INameService.class).load(uuidAndTitleCache.getUuid());
            }
            else{
-               MessagingUtils.warningDialog("Unknown type", NavigationUtil.class, "There is no editor available to open this object.");
+               MessagingUtils.warningDialog(Messages.NavigationUtil_UNKNOWN_TYPE, NavigationUtil.class, Messages.NavigationUtil_UNKNOWN_TYPE_MESSAGE);
            }
            if(cdmBase!=null){
                openEditor(cdmBase);
            }
            else{
-               MessagingUtils.warningDialog("Cdm entity not found", NavigationUtil.class, "CDM entity could not be found in the database.");
+               MessagingUtils.warningDialog(Messages.NavigationUtil_NOT_FOUND, NavigationUtil.class, Messages.NavigationUtil_NOT_FOUND_MESSAGE);
            }
        }
 
        public static void openEditor(ICdmBase selectedObject){
                UUID entityUuid = selectedObject.getUuid();
                try {
-                       if(selectedObject instanceof Classification){
-                       NewClassificationWizard classificationWizard = new NewClassificationWizard();
-                       classificationWizard.init(null, null);
-                       classificationWizard.setEntity((Classification) selectedObject);
-                       WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
-                       dialog.open();
-                       }
-                       else if(selectedObject instanceof TaxonNode){
-                               EditorUtil.openTaxonNode(entityUuid);
+                       if(selectedObject instanceof TaxonNode){
+                           TaxonNode taxonNode = (TaxonNode)selectedObject;
+                           Classification classification = taxonNode.getClassification();
+                           if(classification!=null && classification.getRootNode().equals(taxonNode)){
+                               NewClassificationWizard classificationWizard = new NewClassificationWizard();
+                               classificationWizard.init(null, null);
+                               classificationWizard.setEntity(classification);
+                               WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), classificationWizard);
+                               dialog.open();
+                           }
+                           else{
+                               EditorUtil.openTaxonNodeE4(entityUuid);
+                           }
                        }else if(selectedObject instanceof TaxonBase){
                                TaxonBase taxonBase = (TaxonBase)selectedObject;
                                if(taxonBase.isOrphaned()){
                                        openInBulkEditor(taxonBase);
                                }
                                else{
-                                       EditorUtil.openTaxonBase(entityUuid);
+                                       EditorUtil.openTaxonBaseE4(entityUuid);
                                }
-                       }else if(selectedObject instanceof TaxonNameBase){
+                       }else if(selectedObject instanceof TaxonName){
                                openInBulkEditor(selectedObject);
                        }else if(selectedObject instanceof PolytomousKey){
                                EditorUtil.openPolytomousKey(entityUuid);
                        }else{
-                               MessagingUtils.warningDialog("Unsupported Type", NavigationUtil.class, "No editor exists for the current selection: " + selectedObject);
+                               MessagingUtils.warningDialog(Messages.NavigationUtil_UNSUPPORTED_TYPE, NavigationUtil.class, Messages.NavigationUtil_UNSUPPORTED_TYPE_MESSAGE + selectedObject);
                        }
                } catch (PartInitException e) {
-                       MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e);
+                       MessagingUtils.error(NavigationUtil.class, ERROR_OPENING_THE_EDITOR, e);
                } catch (Exception e) {
-                   MessagingUtils.errorDialog("Could not create Taxon",
+                   MessagingUtils.errorDialog(Messages.NavigationUtil_CREATE_FAILED,
                            NavigationUtil.class,
                            e.getMessage(), TaxeditorStorePlugin.PLUGIN_ID,
                            e,
@@ -138,13 +145,13 @@ public class NavigationUtil extends AbstractUtility{
        }
 
        private static void openInBulkEditor(ICdmBase selectedObject) {
-               ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
-               IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
-               String openInBulkEditorCommand = "eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity";
+               ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
+               IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
+               String openInBulkEditorCommand = "eu.etaxonomy.taxeditor.bulkeditor.openBulkEditorForIdentifiableEntity"; //$NON-NLS-1$
                Command command = commandService.getCommand(openInBulkEditorCommand);
                if(command.isDefined()){
                        Map<String, UUID> params = new HashMap<String, UUID>();
-                       params.put(openInBulkEditorCommand+".uuid", ((ICdmBase) selectedObject).getUuid()); //$NON-NLS-1$
+                       params.put(openInBulkEditorCommand+".uuid", selectedObject.getUuid()); //$NON-NLS-1$
                        ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, params);
                        try {
                                if(parameterizedCommand!=null){
@@ -170,9 +177,9 @@ public class NavigationUtil extends AbstractUtility{
         */
        public static void openEmpty(UUID parentNodeUuid) {
                try {
-                       EditorUtil.openEmpty(parentNodeUuid);
+                       EditorUtil.openEmptyE4(parentNodeUuid);
                } catch (PartInitException e) {
-                       MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e);
+                       MessagingUtils.error(NavigationUtil.class, ERROR_OPENING_THE_EDITOR, e);
                }
        }
 
@@ -297,7 +304,7 @@ public class NavigationUtil extends AbstractUtility{
                        handleOpeningOfMultipleTaxa(accTaxa);
 
                }else{
-                       MessagingUtils.warningDialog("Not implemented yet", NavigationUtil.class, "You chose to open a name that has no connection to a taxon. The Editor does not support editing of such a content type at the moment.");
+                       MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, Messages.NavigationUtil_ORPHAN_NAME_MESSAGE);
                }
 
        }
@@ -307,11 +314,10 @@ public class NavigationUtil extends AbstractUtility{
                        openEditor(acceptedTaxa.iterator().next());
                }else if(acceptedTaxa.size() > 1){
                        // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
-                       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.");
+                       MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, Messages.NavigationUtil_MULTI_TREE);
                }else if(acceptedTaxa.size() == 0){
                        // this is an undesired state
-                       MessagingUtils.warningDialog("Not implemented yet", NavigationUtil.class, "This taxon is not connected to a classification. Currently editing of such taxa is not supported yet.");
+                       MessagingUtils.warningDialog(NOT_IMPLEMENTED_YET, NavigationUtil.class, Messages.NavigationUtil_ORPHAN_TAXON);
                }
        }
 
@@ -325,11 +331,10 @@ public class NavigationUtil extends AbstractUtility{
                        openEditor(taxonNodes.iterator().next());
                }else if(taxonNodes.size() > 1){
                        // FIXME implement a dialog that shows all possible taxa and let the user choose which he wants to open.
-                       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.");
+                       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.");
                }else if(taxonNodes.size() == 0){
                        // this is an undesired state
-                       MessagingUtils.warningDialog("Incorrect state", NavigationUtil.class, "The accepted taxon is not in a taxonomic view. This should not have happened.");
+                       MessagingUtils.warningDialog(Messages.NavigationUtil_INCORRECT_STATE, NavigationUtil.class, Messages.NavigationUtil_INCORRECT_STATE_MESSAGE);
                }
        }
 
@@ -352,15 +357,6 @@ public class NavigationUtil extends AbstractUtility{
                return (TaxonNavigator) getView(TaxonNavigator.ID, restore);
        }
 
-       /**
-        * <p>getOpenEditors</p>
-        *
-        * @return a {@link java.util.Set} object.
-        */
-       public static Set<IEditorPart> getOpenEditors() {
-               return EditorUtil.getOpenEditors();
-       }
-
        /**
         * <p>getPluginId</p>
         *