package eu.etaxonomy.taxeditor.editor;
-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.ui.basic.MPart;
+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.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.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.e4.TaxonEditorInputE4;
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.molecular.AlignmentEditor;
-import eu.etaxonomy.taxeditor.editor.molecular.AlignmentEditorInput;
-import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
-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.editor.view.checklist.ChecklistEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* Utility for the editor package
*/
private static IEditorPart open(final IEditorInput input,
final String editorId) throws PartInitException {
- return getActivePage().openEditor(input, editorId);
- }
-
- /**
- * 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);
+ 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 open(PolytomousKeyEditorInput input)
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
open(input, ChecklistEditor.ID);
}
- /**
- * Opens a new AlignmentEditor for the given input
- * @param input
- * @throws PartInitException
- */
- public static void open(AlignmentEditorInput input)
- throws PartInitException {
- open(input, AlignmentEditor.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);
- }
- }
+// 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
* @throws java.lang.Exception
* if any.
*/
- public static void openTaxonNode(UUID taxonNodeUuid) throws Exception {
- TaxonEditorInput input = TaxonEditorInput.NewInstance(taxonNodeUuid);
- open(input);
+ public static void openTaxonNodeE4(UUID taxonNodeUuid) throws Exception {
+ //FIXME E4 this can probably be removed when fully migrated
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(taxonNodeUuid);
+ EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
+ MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4");
+ partService.showPart(part, PartState.ACTIVATE);
+ TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+ editor.init(input);
}
- /**
- * <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 {
- TaxonEditorInput input = TaxonEditorInput
- .NewInstanceFromTaxonBase(taxonBaseUuid);
- open(input);
+ public static void openTaxonBaseE4(UUID taxonBaseUuid) throws PartInitException{
+ //FIXME E4 this can probably be removed when fully migrated
+ TaxonBase taxonBase = CdmStore.getService(ITaxonService.class).find(taxonBaseUuid);
+
+ if (taxonBase != null && taxonBase.isOrphaned()) {
+ if(taxonBase.isInstanceOf(Synonym.class)){
+ MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
+ return;
+ }
+ else{
+ MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
+ return;
+ }
+ }
+
+ TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
+ EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
+ MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4");
+ partService.showPart(part, PartState.ACTIVATE);
+ TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+ editor.init(input);
}
/**
* @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) throws PartInitException {
+ TaxonEditorInputE4 input = TaxonEditorInputE4
.NewEmptyInstance(parentNodeUuid);
- open(input, MultiPageTaxonEditor.ID);
-
- getActiveMultiPageTaxonEditor().changed(null);
-
+ EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
+ MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4");
+ partService.showPart(part, PartState.ACTIVATE);
+ TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
+ editor.init(input);
}
/**
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();
- }
-
/**
* <p>
* getUndoContext
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
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);
}
}
- /**
- * 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 null;
}
+
+ 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);
+
+ }
+ }
+ } catch (PartInitException e) {
+ continue;
+ }
+ }
+ return result;
+ }
}