2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
.handler
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.IHandler
;
17 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.jface
.dialogs
.InputDialog
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.window
.Window
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
29 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
30 import eu
.etaxonomy
.taxeditor
.store
.operations
.CreateChildTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.store
.operations
.IPostOperationEnabled
;
32 import eu
.etaxonomy
.taxeditor
.store
.parser
.CdmParserUtil
;
39 public class QuickCreateChildTaxonHandler
extends AbstractHandler
implements
41 private static final Logger logger
= Logger
42 .getLogger(QuickCreateChildTaxonHandler
.class);
45 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 IPostOperationEnabled postOperationEnabled
= HandlerUtil
.getActivePart(event
) instanceof IPostOperationEnabled ?
(IPostOperationEnabled
) HandlerUtil
.getActivePart(event
) : null;
50 Shell shell
= HandlerUtil
.getActiveShell(event
);
51 Taxon parentTaxon
= NavigationUtil
.getCurrentSelection(event
);
53 if(NavigationUtil
.isDirty(parentTaxon
)){
54 MessageDialog
.openWarning(shell
, "Unsaved Parent Taxon", "There are unsaved " +
55 "changes in the parent taxon. Pleas save first.");
59 InputDialog dialog
= new InputDialog(shell
, "Quick create child taxon",
60 "Enter child taxon's name to create a new taxon", null, null);
61 if (dialog
.open() == Window
.OK
) {
63 //TaxonUtil.addChildTaxonBaseIsolated(parentTaxon.getUuid(), dialog.getValue());
65 TaxonNameBase name
= CdmParserUtil
.parseFullReference(dialog
.getValue(), null, null);
67 CreateChildTaxonOperation operation
;
69 operation
= new CreateChildTaxonOperation(event
.getCommand().getName(),
70 NavigationUtil
.getUndoContext(), parentTaxon
, name
, postOperationEnabled
);
71 IStatus status
= EditorUtil
.executeOperation(operation
);
72 if(status
.getCode() == TaxeditorStorePlugin
.ERROR_SAVING_ZERO_NAME
){
73 MessageDialog
.openWarning(shell
, "No Name Specified", "An attempt was made to save a taxon with" +
74 " an empty name. Operation was cancelled");
77 NavigationUtil
.selectInNavigator(operation
.getChildTaxon(), parentTaxon
);
79 } catch (NotDefinedException e
) {
80 logger
.warn("Command name not set");
84 logger
.info("Taxon created");