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
.IDirtyMarkable
;
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
;
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
;
52 selectionChanged_internal(part
, selection
);
59 public synchronized void setSelection(ISelection selection
) {
60 this.selection
= selection
;
63 public synchronized void setPart(IWorkbenchPart part
) {
70 * Handle selection change events here and <b>not</b> in
71 * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
72 * if you want asynchronous selection handling.
73 * @param part The workbench part that has issued the selection change
74 * @param selection the new selection
76 protected abstract void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
);
80 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
81 if(delaySelection
==null){
82 delaySelection
= new DelaySelection(part
, selection
);
84 delaySelection
.setPart(part
);
85 delaySelection
.setSelection(selection
);
88 Display
.getCurrent().asyncExec(delaySelection
);
94 public void createPartControl(Composite parent
) {
95 super.createPartControl(parent
);
104 * @return the currently active editor
106 public IEditorPart
getEditor() {
107 return AbstractUtility
.getActiveEditor();
112 public void setFocus() {
115 if(getEditor() != null && ISecuredEditor
.class.isAssignableFrom(getEditor().getClass())){
116 boolean doEnable
= ((ISecuredEditor
)getEditor()).permissionsSatisfied();
117 setEnabled(doEnable
);
123 public void changed(Object object
) {
124 if (part
instanceof AbstractCdmViewPart
) {
125 ((AbstractCdmViewPart
) part
).changed(object
);
127 IEditorPart editor
= getEditor();
128 if (editor
!= null && editor
instanceof IDirtyMarkable
) {
129 ((IDirtyMarkable
) editor
).changed(object
);