From: Patrick Plitzner Date: Fri, 3 Nov 2017 09:36:59 +0000 (+0100) Subject: ref #6906 Fix Delete and move handler for media view X-Git-Tag: 4.11.0^2~43 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/fb019605f439b05d4c6b91b9ffa8fc073adb1be4?ds=sidebyside ref #6906 Fix Delete and move handler for media view --- diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java index 013525623..1cbec16db 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java @@ -6,9 +6,11 @@ package eu.etaxonomy.taxeditor.editor.view.media.handler; import javax.inject.Named; import org.eclipse.core.runtime.IStatus; +import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.di.UISynchronize; import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -16,9 +18,6 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.forms.editor.FormEditor; import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; import eu.etaxonomy.cdm.model.description.DescriptionBase; @@ -26,16 +25,15 @@ import eu.etaxonomy.cdm.model.description.SpecimenDescription; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.cdm.model.description.TaxonNameDescription; import eu.etaxonomy.cdm.model.media.Media; -import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput; import eu.etaxonomy.taxeditor.editor.EditorUtil; import eu.etaxonomy.taxeditor.editor.l10n.Messages; -import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; +import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteSpecimenDescriptionOperation; +import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.DeleteTaxonDescriptionOperation; import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4; import eu.etaxonomy.taxeditor.editor.view.media.operation.DeleteMediaOperation; import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog; -import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; /** * @@ -47,98 +45,71 @@ public class DeleteMediaHandler { @Execute public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, - @Named(IServiceConstants.ACTIVE_SELECTION) Media media, + @Named(IServiceConstants.ACTIVE_SELECTION) Object object, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MMenuItem menuItem, UISynchronize sync) { MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); - - Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart()); - if (e4WrappedPart instanceof FormEditor) { - IEditorPart editor = null; - editor = (FormEditor) e4WrappedPart; - IEditorInput input = editor.getEditorInput(); - if (input instanceof CdmEntitySessionInput) { - ISelection selection = mediaView.getViewer().getSelection(); - if (selection instanceof TreeSelection) { - TreePath[] paths = ((TreeSelection) selection).getPaths(); - int count = paths[0].getSegmentCount(); - DescriptionBase description = null; - for (int i = 0; i < count; i++ ) { - if (paths[0].getSegment(i) instanceof DescriptionBase) { - description = (DescriptionBase) paths[0].getSegment(i); - break; - } - } - // TODO use undo context specific to editor - MediaDeletionConfigurator config = new MediaDeletionConfigurator(); - - config.setDeleteFromDescription(true); - config.setOnlyRemoveFromGallery(false); - - if (description instanceof SpecimenDescription){ - config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation()); - } else if (description instanceof TaxonDescription){ - config.setDeleteFrom(((TaxonDescription)description).getTaxon()); - }else if (description instanceof TaxonNameDescription){ - config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName()); - } - - - DeleteConfiguratorDialog dialog; - dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0); - int result_dialog= dialog.open(); - if (result_dialog != IStatus.OK){ - return; - } - AbstractPostOperation operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView); - AbstractUtility.executeOperation(operation, sync); - + ISelection selection = mediaView.getViewer().getSelection(); + if (selection instanceof TreeSelection) { + TreePath[] paths = ((TreeSelection) selection).getPaths(); + int count = paths[0].getSegmentCount(); + DescriptionBase description = null; + for (int i = 0; i < count; i++ ) { + if (paths[0].getSegment(i) instanceof DescriptionBase) { + description = (DescriptionBase) paths[0].getSegment(i); + break; + } + } + // TODO use undo context specific to editor + MediaDeletionConfigurator config = new MediaDeletionConfigurator(); + + config.setDeleteFromDescription(true); + config.setOnlyRemoveFromGallery(false); + + if (description instanceof SpecimenDescription){ + config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation()); + } else if (description instanceof TaxonDescription){ + config.setDeleteFrom(((TaxonDescription)description).getTaxon()); + }else if (description instanceof TaxonNameDescription){ + config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName()); + } + DeleteConfiguratorDialog dialog; + dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0); + int result_dialog= dialog.open(); + if (result_dialog != IStatus.OK){ + return; + } + if(object instanceof Media){ + AbstractPostOperation operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, (Media) object, config, mediaView); + AbstractUtility.executeOperation(operation, sync); + } + if(object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery()){ + if(object instanceof TaxonDescription){ + DeleteTaxonDescriptionOperation deleteTaxonDescriptionOperation = new DeleteTaxonDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (TaxonDescription)object, mediaView, null); + AbstractUtility.executeOperation(deleteTaxonDescriptionOperation, sync); + } + else if(object instanceof SpecimenDescription){ + DeleteSpecimenDescriptionOperation deleteTaxonDescriptionOperation = new DeleteSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenDescription)object, mediaView, null); + AbstractUtility.executeOperation(deleteTaxonDescriptionOperation, sync); } } - } else if (e4WrappedPart instanceof DerivateView){ - DerivateView view = (DerivateView) e4WrappedPart; - - ISelection selection = mediaView.getViewer().getSelection(); - if (selection instanceof TreeSelection) { - TreePath[] paths = ((TreeSelection) selection).getPaths(); - int count = paths[0].getSegmentCount(); - DescriptionBase description = null; - for (int i = 0; i < count; i++ ) { - if (paths[0].getSegment(i) instanceof DescriptionBase) { - description = (DescriptionBase) paths[0].getSegment(i); - break; - } - } - // TODO use undo context specific to editor - MediaDeletionConfigurator config = new MediaDeletionConfigurator(); - - config.setDeleteFromDescription(true); - config.setOnlyRemoveFromGallery(false); - - if (description instanceof SpecimenDescription){ - config.setDeleteFrom(((SpecimenDescription)description).getDescribedSpecimenOrObservation()); - } else if (description instanceof TaxonDescription){ - config.setDeleteFrom(((TaxonDescription)description).getTaxon()); - }else if (description instanceof TaxonNameDescription){ - config.setDeleteFrom(((TaxonNameDescription)description).getTaxonName()); - } - - - DeleteConfiguratorDialog dialog; - dialog = new DeleteConfiguratorDialog(config, shell, Messages.DeleteMediaHandler_CONFIRM, null, Messages.DeleteMediaHandler_CONFIRM_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteMediaHandler_DELETE, Messages.DeleteMediaHandler_SKIP }, 0); - int result_dialog= dialog.open(); - if (result_dialog != IStatus.OK){ - return; - } - AbstractPostOperation operation = new DeleteMediaOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), description, media, config, mediaView); - AbstractUtility.executeOperation(operation, sync); - } - } } + } + + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) Object object, + MHandledMenuItem menuItem){ + boolean canExecute = false; + canExecute = object instanceof Media + || (object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery()); + menuItem.setVisible(canExecute); + return canExecute; + } + } \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java index 95de13a65..f401ebf68 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.java @@ -17,15 +17,13 @@ import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.forms.editor.FormEditor; import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.media.Media; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.editor.EditorUtil; -import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; +import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4; +import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4; import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation; import eu.etaxonomy.taxeditor.model.AbstractUtility; @@ -48,33 +46,31 @@ public class MoveImageDownInListHandler { MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); - IEditorPart editor = null; + TaxonNameEditorE4 editor = null; Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart()); - if (e4WrappedPart instanceof FormEditor) { - editor = (FormEditor) e4WrappedPart; - IEditorInput input = editor.getEditorInput(); - if (input instanceof TaxonEditorInput) { - Taxon taxon = ((TaxonEditorInput) input).getTaxon(); + if (e4WrappedPart instanceof TaxonNameEditorE4) { + editor = (TaxonNameEditorE4) e4WrappedPart; + TaxonEditorInputE4 input = editor.getEditorInput(); + Taxon taxon = input.getTaxon(); - ISelection selection = mediaView.getViewer().getSelection(); - if (selection instanceof TreeSelection) { - TreePath[] paths = ((TreeSelection) selection).getPaths(); - int count = paths[0].getSegmentCount(); - DescriptionBase description = null; - for (int i = 0; i < count; i++ ) { - if (paths[0].getSegment(i) instanceof DescriptionBase) { - description = (DescriptionBase) paths[0].getSegment(i); - break; - } + ISelection selection = mediaView.getViewer().getSelection(); + if (selection instanceof TreeSelection) { + TreePath[] paths = ((TreeSelection) selection).getPaths(); + int count = paths[0].getSegmentCount(); + DescriptionBase description = null; + for (int i = 0; i < count; i++ ) { + if (paths[0].getSegment(i) instanceof DescriptionBase) { + description = (DescriptionBase) paths[0].getSegment(i); + break; } - AbstractPostOperation operation = null; - // TODO use undo context specific to editor - operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(), - EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, mediaView); - AbstractUtility.executeOperation(operation, sync); } + AbstractPostOperation operation = null; + // TODO use undo context specific to editor + operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(), + EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, mediaView); + AbstractUtility.executeOperation(operation, sync); } } - } + } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java index 2037ba4b1..a46b6e097 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java @@ -17,15 +17,13 @@ import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.forms.editor.FormEditor; import eu.etaxonomy.cdm.model.description.DescriptionBase; import eu.etaxonomy.cdm.model.media.Media; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.taxeditor.editor.EditorUtil; -import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; +import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4; +import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4; import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation; import eu.etaxonomy.taxeditor.model.AbstractUtility; @@ -48,31 +46,29 @@ public class MoveImageUpInListHandler { MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); - IEditorPart editor = null; + TaxonNameEditorE4 editor = null; Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart()); - if (e4WrappedPart instanceof FormEditor) { - editor = (FormEditor) e4WrappedPart; - IEditorInput input = editor.getEditorInput(); - if (input instanceof TaxonEditorInput) { - Taxon taxon = ((TaxonEditorInput) input).getTaxon(); + if (e4WrappedPart instanceof TaxonNameEditorE4) { + editor = (TaxonNameEditorE4) e4WrappedPart; + TaxonEditorInputE4 input = editor.getEditorInput(); + Taxon taxon =input.getTaxon(); - ISelection selection = mediaView.getViewer().getSelection(); - if (selection instanceof TreeSelection) { - TreePath[] paths = ((TreeSelection) selection).getPaths(); - int count = paths[0].getSegmentCount(); - DescriptionBase element = null; - for (int i = 0; i < count; i++ ) { - if (paths[0].getSegment(i) instanceof DescriptionBase) { - element = (DescriptionBase) paths[0].getSegment(i); - break; - } + ISelection selection = mediaView.getViewer().getSelection(); + if (selection instanceof TreeSelection) { + TreePath[] paths = ((TreeSelection) selection).getPaths(); + int count = paths[0].getSegmentCount(); + DescriptionBase element = null; + for (int i = 0; i < count; i++ ) { + if (paths[0].getSegment(i) instanceof DescriptionBase) { + element = (DescriptionBase) paths[0].getSegment(i); + break; } - AbstractPostOperation operation = null; - // TODO use undo context specific to editor - operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(), - EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, mediaView); - AbstractUtility.executeOperation(operation, sync); } + AbstractPostOperation operation = null; + // TODO use undo context specific to editor + operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(), + EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, mediaView); + AbstractUtility.executeOperation(operation, sync); } } }