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
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
29 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
31 import eu
.etaxonomy
.taxeditor
.operations
.CreateChildTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.parser
.CdmParserUtil
;
34 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
41 public class QuickCreateChildTaxonHandler
extends AbstractHandler
implements
42 IHandler
, IPostOperationEnabled
{
43 private static final Logger logger
= Logger
44 .getLogger(QuickCreateChildTaxonHandler
.class);
46 private TaxonNode parentTaxonNode
;
49 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 Shell shell
= HandlerUtil
.getActiveShell(event
);
54 parentTaxonNode
= NavigationUtil
.getCurrentSelection(event
);
56 if(NavigationUtil
.isDirty(parentTaxonNode
)){
57 MessageDialog
.openWarning(shell
, "Unsaved Parent Taxon", "There are unsaved " +
58 "changes in the parent taxon. Pleas save first.");
62 InputDialog dialog
= new InputDialog(shell
, "Quick create child taxon",
63 "Enter child taxon's name to create a new taxon", null, null);
64 if (dialog
.open() == Window
.OK
) {
66 //TaxonUtil.addChildTaxonBaseIsolated(parentTaxon.getUuid(), dialog.getValue());
68 TaxonNameBase name
= CdmParserUtil
.parseFullReference(dialog
.getValue(), null, null);
70 CreateChildTaxonOperation operation
;
72 operation
= new CreateChildTaxonOperation(event
.getCommand().getName(),
73 NavigationUtil
.getUndoContext(), parentTaxonNode
, name
, this);
74 IStatus status
= EditorUtil
.executeOperation(operation
);
75 if(status
.getCode() == TaxeditorStorePlugin
.ERROR_SAVING_ZERO_NAME
){
76 MessageDialog
.openWarning(shell
, "No Name Specified", "An attempt was made to save a taxon with" +
77 " an empty name. Operation was cancelled");
79 } catch (NotDefinedException e
) {
80 logger
.warn("Command name not set");
83 logger
.info("Taxon created");
90 public boolean postOperation(CdmBase objectAffectedByOperation
) {
91 NavigationUtil
.selectInNavigator(objectAffectedByOperation
, parentTaxonNode
);