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
;
50 * @see java.lang.Runnable#run()
55 selectionChanged_internal(part
, selection
);
62 public synchronized void setSelection(ISelection selection
) {
63 this.selection
= selection
;
66 public synchronized void setPart(IWorkbenchPart part
) {
73 * Handle selection change events here and <b>not</b> in
74 * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
75 * if you want asynchronous selection handling.
76 * @param part The workbench part that has issued the selection change
77 * @param selection the new selection
79 protected abstract void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
);
83 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
84 if(delaySelection
==null){
85 delaySelection
= new DelaySelection(part
, selection
);
87 delaySelection
.setPart(part
);
88 delaySelection
.setSelection(selection
);
91 Display
.getCurrent().asyncExec(delaySelection
);
99 * eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org
100 * .eclipse.swt.widgets.Composite)
104 public void createPartControl(Composite parent
) {
105 super.createPartControl(parent
);
114 * @return the currently active editor
116 public IEditorPart
getEditor() {
117 return AbstractUtility
.getActiveEditor();
122 public void setFocus() {
125 if(getEditor() != null && ISecuredEditor
.class.isAssignableFrom(getEditor().getClass())){
126 boolean doEnable
= ((ISecuredEditor
)getEditor()).permissionsSatisfied();
127 setEnabled(doEnable
);
133 public void changed(Object object
) {
134 if (part
instanceof AbstractCdmViewPart
) {
135 ((AbstractCdmViewPart
) part
).changed(object
);
137 IEditorPart editor
= getEditor();
138 if (editor
!= null && editor
instanceof IDirtyMarkable
) {
139 ((IDirtyMarkable
) editor
).changed(object
);