taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/CreateImageListHandler.java -text
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteDescriptionElementHandler.java -text
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteDescriptionHandler.java -text
+taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteHandler.java -text
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DeleteImageHandler.java -text
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/DescriptionsMenuPropertyTester.java -text
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiontree/handler/MoveImageDownInListHandler.java -text
visible="true">
</separator>
<command
- xcommandId="eu.etaxonomy.taxeditor.editor.name.deleteTaxonBase"
commandId="org.eclipse.ui.edit.delete"
label="Delete"
style="push">
visible="true">
</separator>
<command
- commandId="eu.etaxonomy.taxeditor.description.commands.deletedescription"
- label="Delete Description"
- style="push">
- <visibleWhen>
- <reference
- definitionId="isInDescription">
- </reference>
- </visibleWhen>
- </command>
- <command
- commandId="taxeditor-editor.command.deleteImageGallery"
- label="Delete Image Gallery"
- style="push">
- <visibleWhen>
- <reference
- definitionId="isInImageGallery">
- </reference>
- </visibleWhen>
- </command>
- <command
- commandId="taxeditor-editor.command.deleteImage"
- label="Delete Image"
- style="push">
- <visibleWhen>
- <reference
- definitionId="isImage">
- </reference>
- </visibleWhen>
- </command>
- <command
- commandId="eu.etaxonomy.taxeditor.editor.name.deleteDescriptionElement"
+ commandId="org.eclipse.ui.edit.delete"
label="Delete"
style="push">
<visibleWhen>
<reference
- definitionId="isNonImageElement">
+ definitionId="isDeletable">
</reference>
</visibleWhen>
</command>
</test>
</with>
</definition>
+ <definition
+ id="isDeletable">
+ <with
+ variable="activeMenuSelection">
+ <or>
+ <iterate>
+ <instanceof
+ value="eu.etaxonomy.cdm.model.description.DescriptionBase">
+ </instanceof>
+ </iterate>
+ <iterate>
+ <instanceof
+ value="eu.etaxonomy.cdm.model.description.DescriptionElementBase">
+ </instanceof>
+ </iterate>
+ <iterate>
+ <instanceof
+ value="eu.etaxonomy.cdm.model.media.ImageFile">
+ </instanceof>
+ </iterate>
+ </or>
+ </with>
+ </definition>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
class="eu.etaxonomy.taxeditor.editor.descriptiontree.handler.DescriptionsMenuPropertyTester"
id="taxeditor-editor.descriptions.PropertyTester"
namespace="taxeditor-editor.descriptions.propertyTester"
- properties="isInImageGallery,isInImageList,isImage,isInDescription,isNonImageElement"
+ properties="isInImageGallery,isInImageList,isImage,isInDescription,isNonImageElement,isDescription"
type="org.eclipse.jface.viewers.TreeSelection">
</propertyTester>
</extension>
name="New Editor">
</command>
</extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="eu.etaxonomy.taxeditor.editor.descriptiontree.handler.DeleteHandler"
+ commandId="org.eclipse.ui.edit.delete">
+ <activeWhen>
+ <reference
+ definitionId="isDeletable">
+ </reference></activeWhen>
+ </handler>
+ </extension>
</plugin>
* @created 20.04.2009
* @version 1.0
*/
+@Deprecated
public class DeleteDescriptionElementHandler extends AbstractHandler implements
IHandler {
private static final Logger logger = Logger
* @author p.ciardelli\r
*\r
*/\r
+@Deprecated\r
public class DeleteDescriptionHandler extends AbstractHandler {\r
private static final Logger logger = Logger\r
.getLogger(DeleteDescriptionHandler.class);\r
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.editor.descriptiontree.handler;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+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 org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.media.ImageFile;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.operations.DeleteDescriptionElementOperation;
+import eu.etaxonomy.taxeditor.operations.DeleteImageOperation;
+import eu.etaxonomy.taxeditor.operations.DeleteTaxonDescriptionOperation;
+import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
+
+/**
+ * @author n.hoffmann
+ * @created Jan 19, 2010
+ * @version 1.0
+ */
+public class DeleteHandler extends AbstractHandler {
+ private static final Logger logger = Logger.getLogger(DeleteHandler.class);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+ if (editor instanceof FormEditor) {
+ editor = ((FormEditor) editor).getActiveEditor();
+ }
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof TaxonEditorInput) {
+ Taxon taxon = ((TaxonEditorInput) input).getTaxon();
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ Object deleteElement = ((TreeSelection) selection).getFirstElement();
+
+ IUndoableOperation operation = null;
+ try {
+
+ if (deleteElement instanceof DescriptionElementBase) {
+ DescriptionElementBase descriptionElement = (DescriptionElementBase) deleteElement;
+ // TODO use undo context specific to editor
+ operation = new DeleteDescriptionElementOperation(event.getCommand().getName(),
+ EditorUtil.getUndoContext(), taxon, descriptionElement, (IPostOperationEnabled) editor);
+ }else if (deleteElement instanceof ImageFile) {
+ ImageFile imageFile = (ImageFile) deleteElement;
+ TreePath[] paths = ((TreeSelection) selection).getPaths();
+ TaxonDescription description = (TaxonDescription) (paths[0]).getFirstSegment();
+ operation = new DeleteImageOperation(event.getCommand().getName(),
+ EditorUtil.getUndoContext(), taxon, description, imageFile, (IPostOperationEnabled) editor);
+ }else if(deleteElement instanceof TaxonDescription){
+
+ TaxonDescription description = (TaxonDescription) deleteElement;
+ // TODO use undo context specific to editor
+ operation = new DeleteTaxonDescriptionOperation(event.getCommand().getName(),
+ EditorUtil.getUndoContext(), taxon, description, (IPostOperationEnabled) editor);
+ EditorUtil.executeOperation(operation);
+ }
+
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ logger.warn("Command name not set");
+ }
+ }
+ return null;
+ }
+}
import org.eclipse.core.expressions.PropertyTester;\r
import org.eclipse.jface.viewers.TreePath;\r
import org.eclipse.jface.viewers.TreeSelection;\r
+\r
+import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
import eu.etaxonomy.cdm.model.media.ImageFile;\r
if ("isNonImageElement".equals(property)) {\r
return isInDescription() && isInDescriptionElement();\r
}\r
+ if("isDescription".equals(property)){\r
+ return isDescription(); \r
+ }\r
\r
return false;\r
}\r
\r
+ /**\r
+ * @return\r
+ */\r
+ private boolean isDescription() {\r
+ for (Object o : segments) {\r
+ if(!(o instanceof DescriptionBase))\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
/**\r
* @param receiver\r
* @return\r
return list;\r
}\r
\r
+ \r
+ \r
/**\r
* @return\r
*/\r
/**\r
* @param taxon\r
* @param imageFile\r
- * @deprecated\r
+ * @deprecated // move this to library\r
*/\r
public static void removeTaxonImage(Taxon taxon, DescriptionBase<?> imageGallery, ImageFile imageFile) {\r
- Set<DescriptionElementBase> elementsToRemove = new HashSet<DescriptionElementBase>();\r
+ Set<DescriptionElementBase> descriptionElementsToRemove = new HashSet<DescriptionElementBase>();\r
+ Set<MediaRepresentationPart> representationPartsToRemove = new HashSet<MediaRepresentationPart>();\r
\r
Set<DescriptionElementBase> images = imageGallery.getElements();\r
\r
+ // overmodelling of media in cdmlib makes this a little bit complicated\r
for(DescriptionElementBase descriptionElement : images){\r
for(Media media : descriptionElement.getMedia()){\r
for(MediaRepresentation representation : media.getRepresentations()){\r
for(MediaRepresentationPart part : representation.getParts()){\r
if(part.equals(imageFile)){\r
- elementsToRemove.add(descriptionElement);\r
+ // because of concurrent modification, we just collect the parts to remove \r
+ representationPartsToRemove.add(part);\r
}\r
}\r
+\r
+ // and then remove the representation parts here\r
+ for (MediaRepresentationPart part : representationPartsToRemove){\r
+ representation.removeRepresentationPart(part);\r
+ }\r
+ // clear set for next run\r
+ representationPartsToRemove.clear();\r
+ \r
+ // description elements with empty representations should be deleted as well\r
+ if(representation.getParts().size() == 0){\r
+ descriptionElementsToRemove.add(descriptionElement);\r
+ }\r
}\r
}\r
} \r
\r
- for(DescriptionElementBase descriptionElement : elementsToRemove){\r
+ // remove the empty description elements\r
+ for(DescriptionElementBase descriptionElement : descriptionElementsToRemove){\r
imageGallery.removeElement(descriptionElement);\r
} \r
}\r