4 package eu
.etaxonomy
.taxeditor
.view
;
6 import org
.eclipse
.jface
.viewers
.ISelection
;
7 import org
.eclipse
.swt
.widgets
.Composite
;
8 import org
.eclipse
.swt
.widgets
.Display
;
9 import org
.eclipse
.ui
.IEditorPart
;
10 import org
.eclipse
.ui
.IWorkbenchPart
;
12 import eu
.etaxonomy
.taxeditor
.editor
.ISecuredEditor
;
13 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
14 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkableSelectionProvider
;
18 * Abstract AbstractCdmEditorViewPart class.
22 * @created Sep 21, 2010
25 public abstract class AbstractCdmEditorViewPart
extends AbstractCdmViewPart
{
27 private DelaySelection delaySelection
= null;
29 * This is the monitor for the DelaySelection runnable.
30 * If it is <code>true</code> then it is currently delaying a selection.
32 private boolean isInDelay
= false;
36 * This class invokes internal_selectionChanged() in a separate thread.
37 * This allows an asynchronous and/or delayed handling of selection changes
39 private class DelaySelection
implements Runnable
{
40 private IWorkbenchPart part
;
41 private ISelection selection
;
43 public DelaySelection(IWorkbenchPart part
, ISelection selection
) {
46 this.selection
= selection
;
50 * @see java.lang.Runnable#run()
54 internal_selectionChanged(part
, selection
);
58 public synchronized void setSelection(ISelection selection
) {
59 this.selection
= selection
;
62 public synchronized void setPart(IWorkbenchPart part
) {
69 * Handle selection change events here and <b>not</b> in
70 * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
71 * if you want asynchronous selection handling.
72 * @param part The workbench part that has issued the selection change
73 * @param selection the new selection
75 protected abstract void internal_selectionChanged(IWorkbenchPart part
, ISelection selection
);
79 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
80 if(delaySelection
==null){
81 delaySelection
= new DelaySelection(part
, selection
);
83 delaySelection
.setPart(part
);
84 delaySelection
.setSelection(selection
);
87 Display
.getCurrent().asyncExec(delaySelection
);
95 * eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org
96 * .eclipse.swt.widgets.Composite)
100 public void createPartControl(Composite parent
) {
101 super.createPartControl(parent
);
109 * @return the currently active editor
111 public IEditorPart
getEditor() {
112 return AbstractUtility
.getActiveEditor();
117 public void setFocus() {
120 if(getEditor() != null && ISecuredEditor
.class.isAssignableFrom(getEditor().getClass())){
121 boolean doEnable
= ((ISecuredEditor
)getEditor()).permissionsSatisfied();
122 setEnabled(doEnable
);
128 public void changed(Object object
) {
129 if (part
instanceof AbstractCdmViewPart
) {
130 ((AbstractCdmViewPart
) part
).changed(object
);
132 IEditorPart editor
= getEditor();
133 if (editor
!= null && editor
instanceof IDirtyMarkableSelectionProvider
) {
134 ((IDirtyMarkableSelectionProvider
) editor
).changed(object
);