/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.
*/
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
+import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
+import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.BioCaseEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportEditor;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.GbifImportEditor;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.GbifImportEditorInput;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportEditor;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* Utility for the editor package
- *
+ *
* @author n.hoffmann
* @created 20.01.2009
* @version 1.0
/**
* Opens a new editor window with the given input
- *
+ *
* @param input
* @param editorId
* @return
/**
* Opens a new editor window with the given TaxonEditorInput
- *
+ *
* @param input
* a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput}
* object.
open(input, KeyEditor.ID);
}
+ public static void open(CdmAuthorityEditorInput input)
+ throws PartInitException {
+ open(input, CdmAuthorityEditor.ID);
+ }
+
+ /**
+ * Opens a new DerivateView for the given input
+ * @param input a {@link DerivateViewEditorInput} representing the selected derivate
+ * @throws PartInitException
+ */
+ public static void open(DerivateViewEditorInput input)
+ throws PartInitException {
+ open(input, DerivateView.ID);
+ }
+
+
+ /**
+ * Opens a new ChecklistView for the given input
+ * @param input a {@link ChecklistEditorInput} representing the selected checklist
+ * @throws PartInitException
+ */
+ public static void open(ChecklistEditorInput input)
+ throws PartInitException {
+ open(input, ChecklistEditor.ID);
+ }
+
+ /**
+ * Opens a new {@link DataImportEditor} for the given input
+ * @param input a {@link DataImportEditorInput}
+ * @throws PartInitException
+ */
+ public static void open(DataImportEditorInput<?> input)
+ throws PartInitException {
+ if(input instanceof BioCaseEditorInput){
+ open(input, SpecimenImportEditor.ID);
+ }
+ else if(input instanceof GbifImportEditorInput){
+ open(input, GbifImportEditor.ID);
+ }
+ }
+
/**
* Taxon Editors may be opened by supplying a taxon node uuid. Session gets
* initialised here and is passed to the editor
- *
+ *
* @param taxonNodeUuid
* a {@link java.util.UUID} object.
* @throws java.lang.Exception
* <p>
* openTaxonBase
* </p>
- *
+ *
* @param taxonBaseUuid
* a {@link java.util.UUID} object.
* @throws org.eclipse.ui.PartInitException
*/
public static void openTaxonBase(UUID taxonBaseUuid)
throws PartInitException {
+ TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
+ if (taxonBase != null && taxonBase.isOrphaned()) {
+ MessagingUtils.warningDialog("Orphaned Taxon", TaxonEditorInput.class, "This is an orphaned taxon i.e. a taxon that is not connected to a classification and not having any taxonomic relationships. Editing of orphaned taxon is currently not supported.");
+ return;
+ }
TaxonEditorInput input = TaxonEditorInput
.NewInstanceFromTaxonBase(taxonBaseUuid);
- open(input);
+ if(input!=null){
+ open(input);
+ }
}
/**
* <p>
* findEditorByTaxonNodeUuid
* </p>
- *
+ *
* @param taxonNodeUuid
* a {@link java.util.UUID} object.
* @return a {@link org.eclipse.ui.IEditorPart} object.
* An uninitialized taxon is one that hasn't been saved yet. As such, it
* should appear in neither the list of recent names nor in the taxonomic
* tree when opened.
- *
+ *
* @throws org.eclipse.ui.PartInitException
* if any.
* @param parentNodeUuid
* <p>
* setSaving
* </p>
- *
+ *
* @param isSaving
* a boolean.
*/
* <p>
* isSaving
* </p>
- *
+ *
* @return a boolean.
*/
public static boolean isSaving() {
/**
* Returns a set of all currently open <code>MultiPageTaxonEditor</code>s.
- *
+ *
* @return a {@link java.util.Set} object.
*/
public static Set<IEditorPart> getOpenEditors() {
/**
* Returns the currently active taxon editor
- *
+ *
* @return the taxon editor that has focus
*/
public static MultiPageTaxonEditor getActiveMultiPageTaxonEditor() {
* <p>
* getActiveEditorPage
* </p>
- *
+ *
* @param page
* a {@link eu.etaxonomy.taxeditor.editor.Page} object.
* @return a {@link org.eclipse.ui.IEditorPart} object.
/**
* Returns the selection of the currently active taxon editor
- *
+ *
* @return a {@link org.eclipse.jface.viewers.ISelection} object.
*/
public static ISelection getCurrentSelection() {
* <p>
* getUndoContext
* </p>
- *
+ *
* @param editor
* a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor}
* object.
* <p>
* getUndoContext
* </p>
- *
+ *
* @return a {@link org.eclipse.core.commands.operations.IUndoContext}
* object.
*/
* <p>
* forceUserSave
* </p>
- *
+ *
* @param editor
* a {@link org.eclipse.ui.IEditorPart} object.
* @param shell
return false;
}
- editor.doSave(EditorUtil.getMonitor());
+ editor.doSave(AbstractUtility.getMonitor());
}
return true;
}
* <p>
* getSelection
* </p>
- *
+ *
* @param event
* a {@link org.eclipse.core.commands.ExecutionEvent} object.
* @return a {@link org.eclipse.jface.viewers.IStructuredSelection} object.
* <p>
* getPluginId
* </p>
- *
+ *
* @return a {@link java.lang.String} object.
*/
public static String getPluginId() {
.NewInstance(polytomousKeyUuid);
open(input);
}
+
+ public static void openCdmAuthorities(UUID groupUuid)
+ throws Exception {
+ CdmAuthorityEditorInput input = CdmAuthorityEditorInput.NewInstance(groupUuid);
+ open(input);
+ }
+
+ /**
+ * Iterates recursively over all originals having the given specimen as a derivate.
+ * The first {@link DerivedUnit} with no more originals or the first {@link FieldUnit} is returned
+ * @param specimen the start element for which the originals are iterated recursively
+ * @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
+ */
+ public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
+ if(specimen.isInstanceOf(FieldUnit.class)){
+ return specimen;
+ }
+ else if(specimen instanceof DerivedUnit
+ && ((DerivedUnit) specimen).getOriginals()!=null
+ && !((DerivedUnit) specimen).getOriginals().isEmpty()){
+ for(SpecimenOrObservationBase<?> original:((DerivedUnit) specimen).getOriginals()){
+ return getTopMostDerivate(original);
+ }
+ //needed to add this for compilation although this is unreachable
+ return specimen;
+ }
+ else{
+ return specimen;
+ }
+ }
+
+ /**
+ * Iterates recursively over all originals having the given specimen as a derivate.
+ * If a {@link FieldUnit} is found it is returned
+ * @param specimen the start element for which the originals are iterated recursively
+ * @return the FieldUnit if found, <code>null</code> otherwise
+ */
+ public static FieldUnit getFieldUnit(SpecimenOrObservationBase<?> specimen){
+ SpecimenOrObservationBase<?> topMostDerivate = getTopMostDerivate(specimen);
+ if(topMostDerivate instanceof FieldUnit) {
+ return (FieldUnit) topMostDerivate;
+ }
+ return null;
+ }
+
+ /**
+ * If the current selection is a single {@link TreeNode} it will be returned.
+ * @param selection the selection to check
+ * @return the selected TreeNode or <code>null</code> if no TreeNode selected
+ */
+ public static TreeNode getTreeNodeOfSelection(ISelection selection){
+ if(selection instanceof IStructuredSelection
+ && ((IStructuredSelection) selection).size()==1
+ && ((IStructuredSelection) selection).getFirstElement() instanceof TreeNode){
+ return (TreeNode) ((IStructuredSelection) selection).getFirstElement();
+
+ }
+ return null;
+ }
+
+ /**
+ * Opens a taxon editor for the given object if the given object is a valid input.
+ * @param object the object for which the editor will be opened
+ * @throws PartInitException
+ */
+ public static void openTaxonEditor(Object object) throws PartInitException {
+ if(object instanceof TaxonBase<?>){
+ openTaxonBase(((TaxonBase<?>) object).getUuid());
+ }
+ }
}