package eu.etaxonomy.taxeditor.editor;
+import java.util.Collection;
import java.util.HashSet;
-import java.util.Set;
import java.util.UUID;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
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.IEditorReference;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
-import eu.etaxonomy.cdm.api.service.ITaxonService;
-import eu.etaxonomy.cdm.model.common.ITreeNode;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.Synonym;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditor;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
+import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
+import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
+import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
+import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
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.store.view.dataimport.BioCaseEditorInput;
-//import eu.etaxonomy.taxeditor.view.dataimport.DataImportEditor;
-//import eu.etaxonomy.taxeditor.view.dataimport.DataImportEditorInput;
-//import eu.etaxonomy.taxeditor.view.dataimport.GbifImportEditor;
-//import eu.etaxonomy.taxeditor.view.dataimport.GbifImportEditorInput;
-//import eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportEditor;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
+import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
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;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
/**
* Utility for the editor package
*/
public class EditorUtil extends AbstractUtility {
- private static boolean isSaving = false;
+ private static final String NAME_EDITOR_ID = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
- /**
- * Opens a new editor window with the given input
- *
- * @param input
- * @param editorId
- * @return
- * @return
- * @throws PartInitException
- */
- private static IEditorPart open(final IEditorInput input,
- final String editorId) throws PartInitException {
- IEditorPart editor = getActivePage().openEditor(input, editorId);
- if(input != null &&
- editor.getEditorInput() != null &&
- input != editor.getEditorInput() &&
- input instanceof CdmEntitySessionInput) {
- ((CdmEntitySessionInput)input).dispose();
- }
- return editor;
- }
+ public static void openDescriptiveDataSetEditor(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ if(part.getObject() instanceof DescriptiveDataSetEditor
+ && ((DescriptiveDataSetEditor) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
+ partService.showPart(part, PartState.ACTIVATE);
+ return;
+ }
+ }
+ String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVEDATASET_DESCRIPTIVEDATASETEDITOR;
+ MPart part = showPart(partId, modelService, partService, application);
+ DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor) part.getObject();
+ editor.init(descriptiveDataSetUuid);
+ }
- /**
- * Opens a new editor window with the given TaxonEditorInput
- *
- * @param input
- * a {@link eu.etaxonomy.taxeditor.editor.TaxonEditorInput}
- * object.
- * @throws org.eclipse.ui.PartInitException
- * if any.
- */
- public static void open(TaxonEditorInput input) throws PartInitException {
- open(input, MultiPageTaxonEditor.ID);
- }
+ public static void openCharacterMatrix(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ if(part.getObject() instanceof CharacterMatrixPart
+ && ((CharacterMatrixPart) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
+ partService.showPart(part, PartState.ACTIVATE);
+ return;
+ }
+ }
+ String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DESCRIPTIVEDATASET_MATRIX_CHARACTERMATRIXPART;
+ MPart part = showPart(partId, modelService, partService, application);
+ CharacterMatrixPart editor = (CharacterMatrixPart) part.getObject();
+ editor.init(descriptiveDataSetUuid, true);
+ }
- public static void open(PolytomousKeyEditorInput input)
- throws PartInitException {
- open(input, KeyEditor.ID);
- }
+ public static void openDistributionEditor(UUID parentTaxonUuid, EModelService modelService, EPartService partService, MApplication application){
+ Collection<MPart> parts = partService.getParts();
+ String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
+ String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
+ String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
+ closePart(partIdMedia, partService);
+ closePart(partIdFactualData, partService);
+ MPart part = showPart(partId, modelService, partService, application);
+ DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
+ editor.init(parentTaxonUuid);
+ }
- 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);
- }
+ public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
+ String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
+ MPart part = showPart(partId, modelService, partService, application);
+ DerivateView derivateView = (DerivateView) part.getObject();
+ derivateView.init(input);
+ }
+ public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ if(part.getObject() instanceof CdmAuthorityEditorE4
+ && ((CdmAuthorityEditorE4) part.getObject()).getInput().getGroup().equals(input.getGroup())){
+ partService.showPart(part, PartState.ACTIVATE);
+ return;
+ }
+ }
+ String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
+ MPart part = showPart(partId, modelService, partService, application);
+ CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
+ authorityView.init(input);
+ }
- /**
- * 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);
- }
+ public static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
+ MPart part = partService.findPart(partId);
+ if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
+ part = partService.createPart(partId);
+ }
+ MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
+ if(editorAreaPartStack!=null){
+ editorAreaPartStack.getChildren().add(part);
+ }
+ return partService.showPart(part, PartState.ACTIVATE);
+ }
- /**
- * 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);
-// }
-// }
+ public static MPart showPart(String partId, EModelService modelService, EPartService partService){
+ MPart part = partService.findPart(partId);
+ if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
+ part = partService.createPart(partId);
+ partService.activate(part);
+ }else{
+ partService.activate(part);
+ }
- /**
- * 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
- * if any.
- */
- public static void openTaxonNode(UUID taxonNodeUuid) throws Exception {
- TaxonEditorInput input = TaxonEditorInput.NewInstance(taxonNodeUuid);
- open(input);
+ return part;
+ }
+
+ public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(taxonNodeUuid);
+ openNameEditor_internal(input, modelService, partService, application);
}
- /**
- * <p>
- * openTaxonBase
- * </p>
- *
- * @param taxonBaseUuid
- * a {@link java.util.UUID} object.
- * @throws org.eclipse.ui.PartInitException
- * if any.
- */
- public static void openTaxonBase(UUID taxonBaseUuid)
- throws PartInitException {
- TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
- if (taxonBase != null && taxonBase.isOrphaned()) {
+ public static void openTaxonBaseE4(UUID taxonBaseUuid, EModelService modelService, EPartService partService, MApplication application) {
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
+ openNameEditor_internal(input, modelService, partService, application);
+ }
+
+ public static void openTaxonBaseE4(UUID taxonBaseUuid) {
+ //FIXME E4 this can probably be removed when fully migrated
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
+
+ EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
+ EModelService modelService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService.class);
+ openNameEditor_internal(input, modelService, partService, null);
+ }
+
+ private static void openNameEditor_internal(TaxonEditorInputE4 input, EModelService modelService, EPartService partService, MApplication application) {
+ TaxonBase taxonBase = input.getTaxon();
+ if(taxonBase==null){
+ return;
+ }
+ if (taxonBase.isOrphaned()) {
if(taxonBase.isInstanceOf(Synonym.class)){
- MessagingUtils.warningDialog("Orphaned accepted taxon", TaxonEditorInput.class, "The accepted "
- + "taxon of this synonym is not part of any classification. Editing with the "
- + "name editor is currently not implemented. Try to edit the taxon with the bulk editor.");
+ MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
return;
}
else{
- 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 taxa in the name editor is currently not supported. "
- + "Try editing with the bulk editor");
+ MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
return;
}
}
- TaxonEditorInput input = TaxonEditorInput
- .NewInstanceFromTaxonBase(taxonBaseUuid);
- if(input!=null){
- open(input);
- }
- }
- /**
- * <p>
- * findEditorByTaxonNodeUuid
- * </p>
- *
- * @param taxonNodeUuid
- * a {@link java.util.UUID} object.
- * @return a {@link org.eclipse.ui.IEditorPart} object.
- * @throws java.lang.Exception
- * if any.
- */
- public static IEditorPart findEditorByTaxonNodeUuid(UUID taxonNodeUuid)
- throws Exception {
- IEditorInput input = TaxonEditorInput.NewInstance(taxonNodeUuid);
- return getActivePage().findEditor(input);
- }
+ Collection<MPart> parts = partService.getParts();
+ //check if part is already opened
+ for (MPart part : parts) {
+ if(part.getObject() instanceof TaxonNameEditorE4
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
+ if (part.isDirty()){
+ forceUserSaveE4Editor(((TaxonNameEditorE4) part.getObject()), getShell());
+ }
+ partService.hidePart(part);
+ break;
+ }
+ }
+ MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
+
+ TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+ editor.init(input);
+ String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
+ String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
+ showPart(partIdMedia, modelService, partService);
+ showPart(partIdFactualData, modelService, partService);
+ editor.setFocus();
+ }
+
+ public static Collection<MPart> checkForChanges(UUID taxonUUID, EPartService partService ){
+ Collection<MPart> parts = partService.getParts();
+ Collection<MPart> dirtyParts = new HashSet();
+ //check if part is already opened
+ boolean isDirty = false;
+ for (MPart part : parts) {
+ if(part.getObject() instanceof TaxonNameEditorE4
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
+ if (part.isDirty()){
+ dirtyParts.add(part);
+ }
+
+ break;
+ }else if (taxonUUID == null){
+ if (part.isDirty()){
+ dirtyParts.add(part);
+ }
+ }
+ }
+ return dirtyParts;
+ }
+
+ public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
+ Collection<MPart> parts = partService.getParts();
+ Collection<IE4SavablePart> dirtyParts = new HashSet<>();
+ //check if part is already opened
+ for (MPart part : parts) {
+ if(part.getObject() instanceof TaxonNameEditorE4
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
+ && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
+ if (part.isDirty()){
+ dirtyParts.add((IE4SavablePart) part);
+ }
+
+ break;
+ }else if (taxonUUID == null){
+ if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
+ dirtyParts.add((IE4SavablePart) part);
+ }
+ }
+ }
+ return dirtyParts;
+ }
/**
* 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
* a {@link java.util.UUID} object.
*/
- public static void openEmpty(UUID parentNodeUuid) throws PartInitException {
- TaxonEditorInput input = TaxonEditorInput
+ public static void openEmptyE4(UUID parentNodeUuid) {
+ TaxonEditorInputE4 input = TaxonEditorInputE4
.NewEmptyInstance(parentNodeUuid);
- open(input, MultiPageTaxonEditor.ID);
-
- getActiveMultiPageTaxonEditor().changed(null);
-
- }
-
- /**
- * <p>
- * setSaving
- * </p>
- *
- * @param isSaving
- * a boolean.
- */
- public static void setSaving(boolean isSaving) {
- EditorUtil.isSaving = isSaving;
- }
-
- /**
- * <p>
- * isSaving
- * </p>
- *
- * @return a boolean.
- */
- public static boolean isSaving() {
- return isSaving;
- }
-
- /**
- * Returns a set of all currently open <code>MultiPageTaxonEditor</code>s.
- *
- * @return a {@link java.util.Set} object.
- */
- public static Set<IEditorPart> getOpenEditors() {
- Set<IEditorPart> taxonEditors = new HashSet<IEditorPart>();
-
- if (getActivePage() != null) {
- for (IEditorReference reference : getActivePage()
- .getEditorReferences()) {
- IEditorPart editor = reference.getEditor(false);
- if (editor instanceof MultiPageTaxonEditor) {
- taxonEditors.add(editor);
- }
- }
- }
-
- return taxonEditors;
- }
-
- /**
- * Returns the currently active taxon editor
- *
- * @return the taxon editor that has focus
- */
- public static MultiPageTaxonEditor getActiveMultiPageTaxonEditor() {
- IEditorPart editorPart = getActiveEditor();
- if (editorPart != null && editorPart instanceof MultiPageTaxonEditor) {
- MultiPageTaxonEditor editor = (MultiPageTaxonEditor) editorPart;
- editor.getConversationHolder().bind();
- return editor;
- }
- return null;
- }
-
- /**
- * <p>
- * getActiveEditorPage
- * </p>
- *
- * @param page
- * a {@link eu.etaxonomy.taxeditor.editor.Page} object.
- * @return a {@link org.eclipse.ui.IEditorPart} object.
- */
- public static IEditorPart getActiveEditorPage(Page page) {
- MultiPageTaxonEditor editor = getActiveMultiPageTaxonEditor();
-
- return editor != null ? editor.getPage(page) : null;
- }
-
- /**
- * Returns the selection of the currently active taxon editor
- *
- * @return a {@link org.eclipse.jface.viewers.ISelection} object.
- */
- public static ISelection getCurrentSelection() {
- if (getActiveMultiPageTaxonEditor() == null) {
- return null;
- } else {
- return getActiveMultiPageTaxonEditor().getSite()
- .getSelectionProvider().getSelection();
- }
- }
-
- /**
- * <p>
- * getUndoContext
- * </p>
- *
- * @param editor
- * a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor}
- * object.
- * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
- * object.
- */
- public static IUndoContext getUndoContext(MultiPageTaxonEditor editor) {
- return editor.getUndoContext();
+ EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
+ MPart part = partService.createPart(NAME_EDITOR_ID);
+ part = partService.showPart(part, PartState.ACTIVATE);
+ TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+ editor.init(input);
}
/**
if (editor.isDirty()) {
boolean doSave = MessageDialog
- .openConfirm(shell, "Confirm save",
- "Warning - this operation will save the editor. This will also save all other unsaved changes " +
- "in your working editor to the database. Please 'Cancel' if you are not ready to do this.");
+ .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
+ Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
if (!doSave) {
return false;
return true;
}
+ public static boolean forceUserSaveE4Editor(TaxonNameEditorE4 editor, Shell shell) {
+ if (editor.isDirty()) {
+
+ boolean doSave = MessageDialog
+ .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
+ Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
+
+ if (!doSave) {
+ return false;
+ }
+
+ editor.save(AbstractUtility.getMonitor());
+ }
+ return true;
+ }
+
/**
* <p>
* getSelection
return TaxeditorEditorPlugin.PLUGIN_ID;
}
- public static void openPolytomousKey(UUID polytomousKeyUuid)
- throws Exception {
- PolytomousKeyEditorInput input = PolytomousKeyEditorInput
- .NewInstance(polytomousKeyUuid);
- open(input);
- }
-
-// public static void openPolytomousKeyEditor(UUID polytomousKeyUuid, String name)
-// throws Exception {
-// PolytomousKeyEditorInput input = new PolytomousKeyEditorInput(polytomousKeyUuid, name);
-// 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
* @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
*/
public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
+ if(specimen==null){
+ return null;
+ }
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);
+ else if(specimen.isInstanceOf(DerivedUnit.class)){
+ DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
+ if(derivedUnit.getOriginals()!=null
+ && !(derivedUnit.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;
}
+ return specimen;
}
/**
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());
+ public static void closeObsoleteEditor(TaxonNodeDto taxonNode, EPartService partService){
+ String treeIndex = taxonNode.getTreeIndex();
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ Object object = part.getObject();
+ if(object instanceof TaxonNameEditorE4){
+ TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
+ TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
+ if (node.treeIndex()!= null){
+ if(node.treeIndex().startsWith(treeIndex)){
+ if (part.isDirty()){
+ forceUserSaveE4Editor(taxonEditor, getShell());
+ }
+ partService.hidePart(part);
+ }
+ }else{
+ logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
+ }
+ }
}
}
- public static boolean closeObsoleteEditor(TaxonNode taxonNode, IWorkbenchPage activePage){
- boolean result = true;
- for (IEditorReference ref : activePage.getEditorReferences()) {
- try {
- String treeIndex = ((ITreeNode)taxonNode).treeIndex();
-
- IEditorInput input = ref.getEditorInput();
- if (input instanceof TaxonEditorInput) {
- TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
- //if node is a child of taxonNode then close the editor
- if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
- //if (taxonNode.equals(node)) {
- result &= activePage.closeEditor(ref.getEditor(false), true);
+ public static void closePart(String partID, EPartService partService){
- }
- }
- } catch (PartInitException e) {
- continue;
+ Collection<MPart> parts = partService.getParts();
+ for (MPart part : parts) {
+ String elementId = part.getElementId();
+ if (elementId.equals(partID)){
+ partService.hidePart(part);
}
}
- return result;
}
+
+ public static void updateEditor(TaxonNode taxonNode, TaxonNameEditorE4 editor){
+ String treeIndex = taxonNode.treeIndex();
+ TaxonNode node = editor.getEditorInput().getTaxonNode();
+ if(node.treeIndex().equals(treeIndex)){
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(node.getUuid());
+ editor.init(input);
+
+
+ }
+ }
+
}