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 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.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
return editor;
}
- /**
- * 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 open(PolytomousKeyEditorInput input)
throws PartInitException {
open(input, KeyEditor.ID);
* @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 {
+ 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, TaxonEditorInput.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
- return;
- }
- else{
- MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInput.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
- return;
- }
- }
- TaxonEditorInput input = TaxonEditorInput
- .NewInstanceFromTaxonBase(taxonBaseUuid);
- if(input!=null && input.getTaxonNode()!=null){
- open(input);
- }
+
+ 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() {
- Object editorPart = getActiveE4Editor();
- 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
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 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 boolean closeObsoleteEditor(TaxonNode taxonNode, IWorkbenchPage activePage){
boolean result = true;
for (IEditorReference ref : activePage.getEditorReferences()) {