// $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.
-*/
+ * 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.newWizard;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.model.media.Media;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitDetailsWizardPage;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailsWizardPage;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationGeneralWizardPage;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailsWizardPage;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenDetailsWizardPage;
-import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenGeneralWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
+import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchCompositeController;
/**
- * <p>NewDerivedUnitBaseWizard class.</p>
- *
* @author n.hoffmann
* @created Jun 16, 2010
* @version 1.0
*/
-public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOrObservationBase<?>> {
- private SpecimenOrObservationType specOrObsType = null;
+public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOrObservationBase> implements IDerivedUnitFacadePart{
+ private SpecimenOrObservationType specOrObsType = null;
- public NewDerivedUnitBaseWizard() {
- super();
- }
+ public NewDerivedUnitBaseWizard() {
+ super();
+ }
- public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) {
- super();
- this.specOrObsType = specOrObsType;
- }
- /** {@inheritDoc} */
- @Override
+ public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) {
+ super();
+ this.specOrObsType = specOrObsType;
+ }
+ /** {@inheritDoc} */
+ @Override
public void addPages() {
- DerivedUnitFacade derivedUnitFacade = null;
+ DerivedUnitFacade facade = null;
try {
- if (getEntity() != null) {
- if(getEntity() instanceof FieldUnit){
- derivedUnitFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity());
-
- addPage(new FieldObservationGeneralWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- addPage(new GatheringEventDetailsWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- addPage(new FieldObservationDetailsWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- }
- else if(getEntity() instanceof DerivedUnit){
- derivedUnitFacade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
-
- addPage(new SpecimenGeneralWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- addPage(new SpecimenDetailsWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- addPage(new DerivedUnitDetailsWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
- }
+ if(getEntity() instanceof DerivedUnit) {
+ facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
+ addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
+ addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
+ addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
+ addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), facade));
+ }
+ else if(getEntity() instanceof FieldUnit){
+ facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
+ addPage(new FieldUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
+ addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
+ addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
}
} catch (DerivedUnitFacadeNotSupportedException e) {
// we should never get here
throw new IllegalStateException();
}
+ }
+ /** {@inheritDoc} */
+ @Override
+ protected SpecimenOrObservationBase createNewEntity() {
+ if (specOrObsType == null) {
+ return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
+ } else {
+ if (SpecimenOrObservationType.Media.equals(specOrObsType)
+ || ((specOrObsType.getKindOf() != null) && specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
+ MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specOrObsType);
+ //a MediaSpecimen with no media attached does not make sense. Hence, we add one
+ mediaSpecimen.setMediaSpecimen(Media.NewInstance());
+ return mediaSpecimen;
+ } else if (specOrObsType.equals(SpecimenOrObservationType.FieldUnit)) {
+ return FieldUnit.NewInstance();
+ } else {
+ return DerivedUnit.NewInstance(specOrObsType);
+ }
+ }
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#createNewEntity()
- */
- /** {@inheritDoc} */
- @Override
- protected SpecimenOrObservationBase<?> createNewEntity() {
- if(specOrObsType == null) {
- return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
- } else {
- if(SpecimenOrObservationType.Media.equals(specOrObsType) ||
- ((specOrObsType.getKindOf() != null) &&
- specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
- return MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
- } else if(specOrObsType == SpecimenOrObservationType.FieldUnit){
- return FieldUnit.NewInstance();
- } else {
- return DerivedUnit.NewInstance(specOrObsType);
- }
- }
- }
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
- */
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IOccurrenceService.class).saveOrUpdate(getEntity());
+ CdmStore.getService(IOccurrenceService.class).merge(getEntity());
}
- @Override
- protected String getEntityName() {
- return "Specimen";
- }
+
+ @Override
+ protected String getEntityName() {
+ return "Specimen";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean performFinish() {
+ boolean performFinish = super.performFinish();
+ int returnCode = IDialogConstants.NO_ID;
+ if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR)){
+ MessageDialogWithToggle messageDialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
+ "Choose opening option", "Do you want to open the specimen in the specimen editor?",
+ "Remember my decision?", false, PreferencesUtil.getPreferenceStore(),
+ IPreferenceKeys.ALWAYS_OPEN_SPECIMEN_IN_EDITOR);
+ returnCode = messageDialog.getReturnCode();
+ PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.PROMPT_FOR_OPEN_SPECIMEN_IN_EDITOR, messageDialog.getToggleState());
+ if (returnCode != IDialogConstants.YES_ID) {
+ return performFinish;
+ }
+ }
+ if (returnCode==IDialogConstants.YES_ID ||
+ PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.ALWAYS_OPEN_SPECIMEN_IN_EDITOR)
+ .equals(MessageDialogWithToggle.ALWAYS)) {
+ IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
+
+ // get the command from plugin.xml
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ICommandService cmdService = (ICommandService) window.getService(ICommandService.class);
+ Command command = cmdService.getCommand("eu.etaxonomy.taxeditor.editor.openSpecimenEditor");
+ Map<String, UUID> parameters = new HashMap<String, UUID>();
+ parameters.put("eu.etaxonomy.taxeditor.specimenUuidParameter", getEntity().getUuid());
+ ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, parameters);
+
+
+ // execute the command
+ try {
+ handlerService.executeCommand(parameterizedCommand, null);
+ } catch (ExecutionException e) {
+ MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ } catch (NotDefinedException e) {
+ MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ } catch (NotEnabledException e) {
+ MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ } catch (NotHandledException e) {
+ MessagingUtils.error(DerivateSearchCompositeController.class, e);
+ }
+ }
+ return performFinish;
+ }
}