X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/0875c8c1e298c356f80d58bc8bc93a4f6f43d592..62315c717221efb51013acd426ef3a33e8ec71ac:/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java index da31d1c5b..2d33925c2 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/NavigationUtil.java @@ -9,72 +9,68 @@ package eu.etaxonomy.taxeditor.navigation; -import java.util.HashMap; -import java.util.Map; +import java.util.Collection; +import java.util.HashSet; import java.util.Set; import java.util.UUID; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.UndoContext; -import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; 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; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.navigator.CommonViewer; import eu.etaxonomy.cdm.api.service.IClassificationService; import eu.etaxonomy.cdm.api.service.INameService; 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; import eu.etaxonomy.cdm.model.taxon.TaxonBase; import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto; import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; import eu.etaxonomy.taxeditor.editor.EditorUtil; -import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; -import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; +import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4; +import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin; -import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator; +import eu.etaxonomy.taxeditor.navigation.l10n.Messages; import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** - *
NavigationUtil class.
* * @author n.hoffmann * @created 24.03.2009 * @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 IUndoContext defaultUndoContext; /** *openEditor
* * @param selectedObject a {@link eu.etaxonomy.cdm.model.common.CdmBase} object. */ - public static void openEditor(UuidAndTitleCache uuidAndTitleCache){ - Class type = uuidAndTitleCache.getType(); + public static void openEditor(UuidAndTitleCache uuidAndTitleCache, Shell shell, EModelService modelService, EPartService partService, MApplication application){ + Class> type = uuidAndTitleCache.getType(); ICdmBase cdmBase = null; - if(type.equals(Classification.class)){ + if(uuidAndTitleCache instanceof TaxonNodeDto){ + EditorUtil.openTaxonNodeE4(uuidAndTitleCache.getUuid(), modelService, partService, application); + return; + } + else if(type.equals(Classification.class)){ cdmBase = CdmStore.getService(IClassificationService.class).load(uuidAndTitleCache.getUuid()); } else if(type.equals(TaxonNode.class)){ @@ -83,51 +79,45 @@ 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); + openEditor(cdmBase, shell, modelService, partService, application); } 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){ + public static void openEditor(ICdmBase selectedObject, Shell shell, EModelService modelService, EPartService partService, MApplication application){ 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(); + 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(shell, classificationWizard); + dialog.open(); + } + else{ + EditorUtil.openTaxonNodeE4(entityUuid, modelService, partService, application); + } + } + else if(selectedObject instanceof TaxonBase){ + EditorUtil.openTaxonBaseE4(entityUuid, modelService, partService, application); } - else if(selectedObject instanceof TaxonNode){ - EditorUtil.openTaxonNode(entityUuid); - }else if(selectedObject instanceof TaxonBase){ - TaxonBase taxonBase = (TaxonBase)selectedObject; - if(taxonBase.isOrphaned()){ - openInBulkEditor(taxonBase); - } - else{ - EditorUtil.openTaxonBase(entityUuid); - } - }else if(selectedObject instanceof TaxonNameBase){ - 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); + else{ + 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); } catch (Exception e) { - MessagingUtils.errorDialog("Could not create Taxon", + MessagingUtils.errorDialog(Messages.NavigationUtil_CREATE_FAILED, NavigationUtil.class, e.getMessage(), TaxeditorStorePlugin.PLUGIN_ID, e, @@ -136,72 +126,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"; - Command command = commandService.getCommand(openInBulkEditorCommand); - if(command.isDefined()){ - MapopenEmpty
* * @param parentNodeUuid a {@link java.util.UUID} object. */ public static void openEmpty(UUID parentNodeUuid) { - try { - EditorUtil.openEmpty(parentNodeUuid); - } catch (PartInitException e) { - MessagingUtils.error(NavigationUtil.class, "Error opening the editor", e); - } - } - - /** - *getShell
- * - * @return a {@link org.eclipse.swt.widgets.Shell} object. - */ - public static Shell getShell() { - return getActiveWindow().getShell(); - } - - /** - *getActiveWindow
- * - * @return a {@link org.eclipse.ui.IWorkbenchWindow} object. - */ - public static IWorkbenchWindow getActiveWindow() { - return TaxeditorNavigationPlugin.getDefault().getWorkbench(). - getActiveWorkbenchWindow(); - } - - /** - *getWorkbenchUndoContext
- * - * @return a {@link org.eclipse.core.commands.operations.IUndoContext} object. - */ - public static IUndoContext getWorkbenchUndoContext() { - return TaxeditorEditorPlugin.getDefault().getWorkbench(). - getOperationSupport().getUndoContext(); + EditorUtil.openEmptyE4(parentNodeUuid); } /** @@ -228,52 +159,39 @@ public class NavigationUtil extends AbstractUtility{ * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object. * @return a boolean. */ - public static boolean isDirty(TaxonNode taxonNode){ - - for (IEditorReference reference : getActivePage().getEditorReferences()) { - - try { - if (reference.getEditorInput() instanceof TaxonEditorInput) { - TaxonEditorInput editorInput = (TaxonEditorInput) reference.getEditorInput(); - if(editorInput.getTaxonNode().equals(taxonNode) && reference.isDirty()){ - return true; - } - } - } catch (PartInitException e) { - MessagingUtils.error(NavigationUtil.class, e.getMessage(), e); - throw new RuntimeException(e); - } - - } + public static boolean isDirty(TaxonNodeDto taxonNode, EPartService partService){ + + CollectionselectInNavigator
- * - * @param element a {@link java.lang.Object} object. - * @param parentElement a {@link java.lang.Object} object. - */ - public static void selectInNavigator(final Object element, final Object parentElement) { - Display.getDefault().asyncExec(new Runnable(){ - - @Override - public void run() { - TaxonNavigator navigator = showNavigator(); - - if (navigator != null) { - CommonViewer viewer = navigator.getCommonViewer(); - if (viewer != null) { - if (parentElement != null) { - viewer.setExpandedState(parentElement, true); - } - viewer.setSelection(new StructuredSelection(element)); - } - } - } - - }); - } + * Whether a taxonNode has unsaved changes. + * + * @param taxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object. + * @return a boolean. + */ + public static boolean isDirty(TaxonNode taxonNode, EPartService partService){ + + CollectionopenSearch
@@ -289,25 +207,29 @@ public class NavigationUtil extends AbstractUtility{ }else if(selection instanceof Synonym){ Synonym synonym = (Synonym) selection; - handleOpeningOfMultipleTaxa(synonym.getAcceptedTaxa()); + SetshowNavigator
- * - * @return the TaxonNavigator instance if present - */ - public static TaxonNavigator showNavigator() { - return (TaxonNavigator) showView(TaxonNavigator.ID); - } - - /** - *getNavigator
- * - * @param restore a boolean. - * @return a {@link eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator} object. - */ - public static TaxonNavigator getNavigator(boolean restore) { - return (TaxonNavigator) getView(TaxonNavigator.ID, restore); - } - - /** - *getOpenEditors
- * - * @return a {@link java.util.Set} object. - */ - public static Set