--- /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 java.util.Iterator;
+
+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.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Event;
+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.common.Language;
+import eu.etaxonomy.cdm.model.description.CommonTaxonName;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.Page;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.description.DescriptionLabelComposite;
+import eu.etaxonomy.taxeditor.editor.description.DistributionDialog;
+import eu.etaxonomy.taxeditor.editor.description.LanguageDialog;
+import eu.etaxonomy.taxeditor.editor.description.TaxonDescriptionEditor;
+import eu.etaxonomy.taxeditor.editor.descriptiontree.TaxonDescriptionFeature;
+import eu.etaxonomy.taxeditor.operations.CreateDescriptionElementOperation;
+import eu.etaxonomy.taxeditor.operations.CreateImageOperation;
+import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
+
+/**
+ * @author n.hoffmann
+ * @created 16.04.2009
+ * @version 1.0
+ */
+public class CreateDescriptionElementHandler extends AbstractHandler {
+ private static final Logger logger = Logger
+ .getLogger(CreateDescriptionElementHandler.class);
+
+ private DescriptionElementBase element;
+
+ /* (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);
+ if (selection instanceof TreeSelection) {
+ TreePath[] paths = ((TreeSelection) selection).getPaths();
+ TaxonDescription description = (TaxonDescription) (paths[0]).getFirstSegment();
+
+ Feature feature = (Feature) ((Event)event.getTrigger()).data;
+
+ IUndoableOperation operation = null;
+ try {
+ // TODO use undo context specific to editor
+// if (feature.equals(Feature.IMAGE())) {
+// operation = new CreateImageOperation(event.getCommand().getName(),
+// EditorUtil.getUndoContext(), taxon, description, (IPostOperationEnabled) editor);
+// } else {
+ operation = new CreateDescriptionElementOperation(event.getCommand().getName(),
+ EditorUtil.getUndoContext(), taxon, description, feature, (IPostOperationEnabled) editor);
+// }
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ logger.warn("Command name not set");
+ }
+ }
+ }
+
+// TaxonDescriptionEditor editor = (TaxonDescriptionEditor) EditorUtil.getActiveEditorPage(
+// Page.DESCRIPTIVE);
+//
+// Feature feature = (Feature) ((Event)event.getTrigger()).data;
+//
+// // FIXME right now we have only one description per taxon
+// // this will change in the future and then attaching the feature to
+// // the firstGroupedComposite will not work anymore
+// TaxonDescription description = ((DescriptionLabelComposite)editor.getFirstGroupedComposite()).getDescription();
+
+// if (getElementUserInput(feature).equals(Status.OK_STATUS)) {
+// IUndoableOperation operation;
+// try {
+// operation = new CreateDescriptionElementOperation(event.getCommand().getName(),
+// editor.getUndoContext(), editor.getTaxon(), description, feature, element, editor);
+// EditorUtil.executeOperation(operation);
+// } catch (NotDefinedException e) {
+// logger.warn("Command name not set");
+// }
+// }
+ return null;
+ }
+
+ /**
+ * Some element types require input via the UI - initialize these here
+ *
+ * @param feature
+ * @return
+ * @deprecated
+ */
+ private IStatus getElementUserInput(Feature feature) {
+
+ // Remove object from last execution from element
+ element = null;
+
+ // -------------- Common name -------------- //
+ if (feature.supportsCommonTaxonName()) {
+ Language language = LanguageDialog.getLanguage
+ ("Select language", "Select the common name's language:");
+ if (language == null) {
+ return Status.CANCEL_STATUS;
+ }
+ element = CommonTaxonName.NewInstance("", language);
+ // Feature must be explicitly set to sync w term in persistence layer
+ element.setFeature(feature);
+ }
+
+ // -------------- Distribution -------------- //
+ if (feature.supportsDistribution()) {
+ element = DistributionDialog.getDistribution
+ ("Create distribution", null);
+ if (element == null) {
+ return Status.CANCEL_STATUS;
+ }
+ // Feature must be explicitly set to sync w term in persistence layer
+ element.setFeature(feature);
+ }
+
+ return Status.OK_STATUS;
+ }
+}
\ No newline at end of file
--- /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.IHandler;
+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.IPostOperationEnabled;
+
+/**
+ * @author n.hoffmann
+ * @created 20.04.2009
+ * @version 1.0
+ */
+public class DeleteDescriptionElementHandler extends AbstractHandler implements
+ IHandler {
+ private static final Logger logger = Logger
+ .getLogger(DeleteDescriptionElementHandler.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);
+ }
+ 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);
+ }
+ EditorUtil.executeOperation(operation);
+ } catch (NotDefinedException e) {
+ logger.warn("Command name not set");
+ }
+ }
+ return null;
+ }
+}