X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/48f674499660b930ee7bb5d7b3a7e4249d96fa0b..57aa2fdbaf73be3ee04b26025177cf9e146a513e:/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
index 74e264dc5..6887838dd 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
@@ -23,6 +23,9 @@ import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.FormEditor;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -54,72 +57,79 @@ import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
* @version 1.0
*/
public class MultiPageTaxonEditor extends FormEditor implements
- IPartContentHasFactualData, IConversationEnabled, IPostOperationEnabled,
- IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia {
-
- /** Constant ID="eu.etaxonomy.taxeditor.editor.taxon"{trunked}
*/
- public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon";
-
- private boolean dirty;
-
- private ConversationHolder conversation;
- private IDataChangeBehavior dataChangeBehavior;
- private IUndoContext undoContext;
-
- private TaxonEditorInput input;
-
- /**
- *
- * Constructor for MultiPageTaxonEditor. - *
- */ - public MultiPageTaxonEditor() { - super(); - undoContext = new UndoContext(); - } - - /** {@inheritDoc} */ - @Override - public void dispose() { - conversation.unregisterForDataStoreChanges(this); - conversation.close(); - super.dispose(); - } - - /** {@inheritDoc} */ - @Override - protected void addPages() { - input = (TaxonEditorInput) getEditorInput(); - conversation = input.getConversationHolder(); - conversation.registerForDataStoreChanges(this); - - try { - addPage(Page.NAME.getIndex(), new TaxonNameEditor(this), - getEditorInput()); - // setPageText(Page.NAME.getIndex(), Page.NAME.getTitle()); - - // TODO lazy create - // addPage(Page.DESCRIPTIVE.getIndex(), new - // TaxonDescriptionTreeEditor(this), getEditorInput()); - // setPageText(Page.DESCRIPTIVE.getIndex(), - // Page.DESCRIPTIVE.getTitle()); - - // EditorUtil.showPropertySheet(); - - } catch (PartInitException e) { - MessagingUtils.error(getClass(), e); - } - } - - /** {@inheritDoc} */ - @Override - public void doSave(IProgressMonitor monitor) { - monitor.beginTask("Saving Editor", 4); - try { - if (!conversation.isBound()) { - conversation.bind(); - } - monitor.worked(1); +IPartContentHasFactualData, IConversationEnabled, IPostOperationEnabled, +IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia { + + /** ConstantID="eu.etaxonomy.taxeditor.editor.taxon"{trunked}
*/
+ public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon";
+
+ private boolean dirty;
+
+ private ConversationHolder conversation;
+ private IDataChangeBehavior dataChangeBehavior;
+ private IUndoContext undoContext;
+
+ private TaxonEditorInput input;
+
+ /**
+ * + * Constructor for MultiPageTaxonEditor. + *
+ */ + public MultiPageTaxonEditor() { + super(); + undoContext = new UndoContext(); + + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + input.dispose(); + conversation.unregisterForDataStoreChanges(this); + conversation.close(); + super.dispose(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.forms.editor.FormEditor#addPages() + */ + /** {@inheritDoc} */ + @Override + protected void addPages() { + input = (TaxonEditorInput) getEditorInput(); + conversation = input.getConversationHolder(); + conversation.registerForDataStoreChanges(this); + + try { + addPage(Page.NAME.getIndex(), new TaxonNameEditor(this), + getEditorInput()); + // setPageText(Page.NAME.getIndex(), Page.NAME.getTitle()); + + // TODO lazy create + // addPage(Page.DESCRIPTIVE.getIndex(), new + // TaxonDescriptionTreeEditor(this), getEditorInput()); + // setPageText(Page.DESCRIPTIVE.getIndex(), + // Page.DESCRIPTIVE.getTitle()); + + // EditorUtil.showPropertySheet(); + + } catch (PartInitException e) { + MessagingUtils.error(getClass(), e); + } + } + + /** {@inheritDoc} */ + @Override + public void doSave(IProgressMonitor monitor) { + monitor.beginTask("Saving Editor", 4); + try { + if (!conversation.isBound()) { + conversation.bind(); + } + monitor.worked(1); for (IEditorPart editorPage : getPages()) { if (editorPage instanceof TaxonNameEditor) { @@ -135,9 +145,14 @@ public class MultiPageTaxonEditor extends FormEditor implements monitor.worked(1); } - // commit the conversation and start a new transaction immediately - conversation.commit(true); - monitor.worked(1); + // commit the conversation and start a new transaction immediately + + input.merge(); + + conversation.commit(true); + CdmApplicationState.getCurrentDataChangeService() + .fireChangeEvent(new CdmChangeEvent(Action.Update, input.getTaxonNode() , MultiPageTaxonEditor.class), true); + monitor.worked(1); this.setDirty(false); monitor.worked(1); @@ -148,119 +163,143 @@ public class MultiPageTaxonEditor extends FormEditor implements } finally { monitor.done(); } - } - - private void disableEditor(boolean isOnError) { - for (IMultiPageTaxonEditorPage editorPage : getPages()) { - if(isOnError){ - editorPage.setOnError(); - }else { - editorPage.setDisabled(); - } - } - conversation.unregisterForDataStoreChanges(this); - conversation.close(); - setDirty(false); - } - - private void setDirty(boolean dirty) { - this.dirty = dirty; - firePropertyChange(PROP_DIRTY); - } - - @Override + } + + private void disableEditor(boolean isOnError) { + for (IMultiPageTaxonEditorPage editorPage : getPages()) { + if(isOnError){ + editorPage.setOnError(); + }else { + editorPage.setDisabled(); + } + } + + conversation.unregisterForDataStoreChanges(this); + conversation.close(); + setDirty(false); + } + + private void setDirty(boolean dirty) { + this.dirty = dirty; + firePropertyChange(PROP_DIRTY); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty() + */ + /** + *+ * isDirty + *
+ * + * @return a boolean. + */ + @Override public boolean isDirty() { - return dirty; - } - - /** {@inheritDoc} */ - @Override - public void editorDirtyStateChanged() { - dirty = true; - super.editorDirtyStateChanged(); - } - - /** - * {@inheritDoc} - * - * Checks whether nested editors are calling - *firePropertyChange(PROP_DIRTY)
to signal an edit has taken
- * place before passing property change along to
- * super.handlePropertyChange(int propertyId)
.
- */
- @Override
+ return dirty;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void editorDirtyStateChanged() {
+ dirty = true;
+ super.editorDirtyStateChanged();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Checks whether nested editors are calling
+ * firePropertyChange(PROP_DIRTY)
to signal an edit has taken
+ * place before passing property change along to
+ * super.handlePropertyChange(int propertyId)
.
+ */
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
+ */
+ @Override
protected void handlePropertyChange(int propertyId) {
- if (propertyId == PROP_DIRTY) {
- setDirty(true);
- }
- super.handlePropertyChange(propertyId);
- }
-
- /** {@inheritDoc} */
- @Override
- public void doSaveAs() {
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
-
- if (!(input instanceof TaxonEditorInput)) {
+ if (propertyId == PROP_DIRTY) {
+ setDirty(true);
+ }
+ super.handlePropertyChange(propertyId);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void doSaveAs() {
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+
+ if (!(input instanceof TaxonEditorInput)) {
throw new PartInitException(
- "Invalid Input: Must be TaxonEditorInput");
+ "Invalid Input: Must be TaxonEditorInput");
+ }
+
+ this.input = (TaxonEditorInput) input;
+
+
+ // try {
+ // // Listen for name changes,
+ // // change tab for this taxon editor accordingly
+ // getTaxon().addPropertyChangeListener("name",
+ // new PropertyChangeListener() {
+ // public void propertyChange(PropertyChangeEvent e) {
+ // setPartName();
+ // }
+ // });
+ // } catch (NullPointerException e) {
+ // EditorUtil.warn(getClass(),
+ // "Caught an NPE while initing an editor. This is most " +
+ // "likely due to the unsuccesful attempt to restore the former " +
+ // "state of the application. We ignore this because the workbench " +
+ // "will simply be reset.");
+ // }
+ setPartName();
+
+ super.init(site, input);
+ }
+
+ /**
+ * Calls MultiPageEditorPart.setPartName(String partName)
with
+ * text appropriate to the state of the taxon: any taxon that has been saved
+ * will by necessity have a name to display; a new taxon should display
+ * "New taxon" in the editor tab.
+ */
+ protected void setPartName() {
+
+ String partName = null;
+ TaxonNameBase, ?> name = getTaxon().getName();
+
+ if (name != null) {
+ partName = name.getTitleCache();
+ }
+
+ if (partName == null || partName.equals("")) {
+ partName = ("New taxon");
}
- this.input = (TaxonEditorInput) input;
-
- // try {
- // // Listen for name changes,
- // // change tab for this taxon editor accordingly
- // getTaxon().addPropertyChangeListener("name",
- // new PropertyChangeListener() {
- // public void propertyChange(PropertyChangeEvent e) {
- // setPartName();
- // }
- // });
- // } catch (NullPointerException e) {
- // EditorUtil.warn(getClass(),
- // "Caught an NPE while initing an editor. This is most " +
- // "likely due to the unsuccesful attempt to restore the former " +
- // "state of the application. We ignore this because the workbench " +
- // "will simply be reset.");
- // }
- setPartName();
-
- super.init(site, input);
- }
-
- /**
- * Calls MultiPageEditorPart.setPartName(String partName)
with
- * text appropriate to the state of the taxon: any taxon that has been saved
- * will by necessity have a name to display; a new taxon should display
- * "New taxon" in the editor tab.
- */
- protected void setPartName() {
-
- String partName = null;
- TaxonNameBase, ?> name = getTaxon().getName();
-
- if (name != null) {
- partName = name.getTitleCache();
- }
-
- if (partName == null || partName.equals("")) {
- partName = ("New taxon");
- }
-
- setPartName(partName);
- }
+ setPartName(partName);
+ }
/**
* {@inheritDoc}
@@ -271,8 +310,12 @@ public class MultiPageTaxonEditor extends FormEditor implements
@Override
public void changed(Object element) {
// setDirty(true);
- dirty = true;
- super.editorDirtyStateChanged();
+ // if the attribute is null then do not set the dirty flag -> hotfix for the problem that for tasks done in service methods the changes are saved automatically
+ if (element != null){
+ dirty = true;
+ super.editorDirtyStateChanged();
+ }
+
if (element instanceof TaxonBase) {
TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
AbstractGroupedContainer container = page.getContainer((TaxonBase) element);
@@ -285,48 +328,100 @@ public class MultiPageTaxonEditor extends FormEditor implements
setPartName();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
+ */
@Override
public void forceDirty() {
changed(null);
}
- /**
- * The accepted taxon that is the input for this editor
- *
- * @return the accepted taxon
- */
- public Taxon getTaxon() {
- return input.getTaxon();
- }
+ /**
+ * The accepted taxon that is the input for this editor
+ *
+ * @return the accepted taxon
+ */
+ public Taxon getTaxon() {
+ return input.getTaxon();
+ }
- @Override
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
+ * ()
+ */
+ /**
+ * + * getConversationHolder + *
+ * + * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} + * object. + */ + @Override public ConversationHolder getConversationHolder() { - return conversation; - } - - public void setConversationHolder(ConversationHolder conversation) { - this.conversation = conversation; - } - - public IUndoContext getUndoContext() { - return undoContext; - } - - public void setUndoContext(IUndoContext undoContext) { - this.undoContext = undoContext; - } - - /** {@inheritDoc} */ - @Override - public void setFocus() { - // logger.warn("Setting focus to editor"); - // bind the conversation - getConversationHolder().bind(); - // pass focus to the active editor page - getActiveEditor().setFocus(); - } - - /** {@inheritDoc} */ + return conversation; + } + + /** + *+ * setConversationHolder + *
+ * + * @param conversation + * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} + * object. + */ + public void setConversationHolder(ConversationHolder conversation) { + this.conversation = conversation; + } + + /** + *
+ * Getter for the field undoContext
.
+ *
+ * Setter for the field undoContext
.
+ *
IEditorPart
implementation by type
- *
- * @param page
- * the page type
- * @return a {@link eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage}
- * object.
- */
- public IMultiPageTaxonEditorPage getPage(Page page) {
- for (IEditorPart editor : this.getPages()) {
- if (editor.getClass().equals(page.getClazz())) {
- return (IMultiPageTaxonEditorPage) editor;
- }
- }
- return null;
- }
-
- /**
- * Return a list of AbstractTaxonEditor
s registered with this
- * MultiPageTaxonEditor
.
- *
- * @return a {@link java.util.List} object.
- */
- public ListIEditorPart
implementation by type
+ *
+ * @param page
+ * the page type
+ * @return a {@link eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage}
+ * object.
+ */
+ public IMultiPageTaxonEditorPage getPage(Page page) {
+ for (IEditorPart editor : this.getPages()) {
+ if (editor.getClass().equals(page.getClazz())) {
+ return (IMultiPageTaxonEditorPage) editor;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return a list of AbstractTaxonEditor
s registered with this
+ * MultiPageTaxonEditor
.
+ *
+ * @return a {@link java.util.List} object.
+ */
+ public List+ * onComplete + *
+ * + * @return a boolean. + */ + @Override public boolean onComplete() { - return false; - } + return false; + } /** * Reloads the data for this @@ -444,22 +553,26 @@ public class MultiPageTaxonEditor extends FormEditor implements } } - @Override - public String toString() { - return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput()); - } - - @Override - public boolean permissionsSatisfied() { - IEditorPart activeEditor = getActiveEditor(); - if(activeEditor != null && ISecuredEditor.class.isAssignableFrom(activeEditor.getClass())){ - return ((ISecuredEditor)activeEditor).permissionsSatisfied(); - } - return true; - } - - @Override - public boolean canAttachMedia() { - return true; - } + @Override + public String toString() { + return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput()); + } + + @Override + public boolean permissionsSatisfied() { + IEditorPart activeEditor = getActiveEditor(); + if(activeEditor != null && ISecuredEditor.class.isAssignableFrom(activeEditor.getClass())){ + return ((ISecuredEditor)activeEditor).permissionsSatisfied(); + } + return true; + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.model.IPartContentHasMedia#canAttachMedia() + */ + @Override + public boolean canAttachMedia() { + return true; + } + }