X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/46294101df429560406d98729427215ecaaca8bb..1bf80c0c5daafa3cf40d34be966146731c669fb9:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java index 8d1f9ad9d..67a0bae27 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java @@ -3,8 +3,11 @@ */ package eu.etaxonomy.taxeditor.view; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; import eu.etaxonomy.taxeditor.editor.ISecuredEditor; import eu.etaxonomy.taxeditor.model.AbstractUtility; @@ -21,39 +24,103 @@ import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider; */ public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart { - /* - * (non-Javadoc) - * - * @see - * eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org - * .eclipse.swt.widgets.Composite) - */ - /** {@inheritDoc} */ - @Override - public void createPartControl(Composite parent) { - super.createPartControl(parent); - } - - /** - *
- * getEditor - *
- * - * @return the currently active editor - */ - public IEditorPart getEditor() { - return AbstractUtility.getActiveEditor(); - } - - /** {@inheritDoc} */ - @Override - public void setFocus() { - super.setFocus(); - - if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){ - boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied(); - setEnabled(doEnable); - } + private DelaySelection delaySelection = null; + /** + * This is the monitor for the DelaySelection runnable. + * If it istrue
then it is currently delaying a selection.
+ */
+ private boolean isInDelay = false;
+
+
+ /**
+ * This class invokes internal_selectionChanged() in a separate thread.
+ * This allows an asynchronous and/or delayed handling of selection changes
+ */
+ private class DelaySelection implements Runnable{
+ private IWorkbenchPart part;
+ private ISelection selection;
+
+ public DelaySelection(IWorkbenchPart part, ISelection selection) {
+ super();
+ this.part = part;
+ this.selection = selection;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+ internal_selectionChanged(part, selection);
+ isInDelay = false;
+ }
+
+ public synchronized void setSelection(ISelection selection) {
+ this.selection = selection;
+ }
+
+ public synchronized void setPart(IWorkbenchPart part) {
+ this.part = part;
+ }
+
+ }
+
+ /**
+ * Handle selection change events here and not in
+ * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
+ * if you want asynchronous selection handling.
+ * @param part The workbench part that has issued the selection change
+ * @param selection the new selection
+ */
+ protected abstract void internal_selectionChanged(IWorkbenchPart part, ISelection selection);
+
+ /** {@inheritDoc} */
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if(delaySelection==null){
+ delaySelection = new DelaySelection(part, selection);
+ }
+ delaySelection.setPart(part);
+ delaySelection.setSelection(selection);
+ if(!isInDelay){
+ isInDelay = true;
+ Display.getCurrent().asyncExec(delaySelection);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org
+ * .eclipse.swt.widgets.Composite)
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ }
+
+ /**
+ * + * getEditor + *
+ * + * @return the currently active editor + */ + public IEditorPart getEditor() { + return AbstractUtility.getActiveEditor(); + } + + /** {@inheritDoc} */ + @Override + public void setFocus() { + super.setFocus(); + + if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){ + boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied(); + setEnabled(doEnable); + } } /** {@inheritDoc} */