4 package eu
.etaxonomy
.taxeditor
.view
;
6 import org
.eclipse
.jface
.viewers
.ISelection
;
7 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
8 import org
.eclipse
.swt
.widgets
.Composite
;
9 import org
.eclipse
.swt
.widgets
.Display
;
10 import org
.eclipse
.ui
.IWorkbenchPart
;
12 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
13 import eu
.etaxonomy
.taxeditor
.workbench
.part
.ISelectionElementEditingPart
;
17 * Abstract AbstractCdmEditorViewPart class.
21 * @created Sep 21, 2010
24 public abstract class AbstractCdmEditorViewPart
extends AbstractCdmViewPart
implements ISelectionElementEditingPart
{
26 private DelaySelection delaySelection
= null;
28 * This is the monitor for the DelaySelection runnable.
29 * If it is <code>true</code> then it is currently delaying a selection.
31 private boolean isInDelay
;
33 protected Object selectionProvidingPart
;
37 * This class invokes internal_selectionChanged() in a separate thread.
38 * This allows an asynchronous and/or delayed handling of selection changes
40 private class DelaySelection
implements Runnable
{
41 private IWorkbenchPart part
;
42 private ISelection selection
;
44 public DelaySelection(IWorkbenchPart part
, ISelection selection
) {
47 this.selection
= selection
;
53 selectionChanged_internal(part
, selection
);
60 public synchronized void setSelection(ISelection selection
) {
61 this.selection
= selection
;
64 public synchronized void setPart(IWorkbenchPart part
) {
71 * Handle selection change events here and <b>not</b> in
72 * {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
73 * if you want asynchronous selection handling.
74 * @param part The workbench part that has issued the selection change
75 * @param selection the new selection
77 protected abstract void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
);
81 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
82 /*to avoid widget is disposed exceptions
83 if(getViewer().getControl().isDisposed()){
86 if(delaySelection
==null){
87 delaySelection
= new DelaySelection(part
, selection
);
89 delaySelection
.setPart(part
);
90 delaySelection
.setSelection(selection
);
93 Display
.getCurrent().asyncExec(delaySelection
);
101 public void showViewer(Object part
, IStructuredSelection selection
) {
102 super.showViewer(part
, selection
);
103 selectionProvidingPart
= part
;
107 public Object
getSelectionProvidingPart() {
108 return selectionProvidingPart
;
115 public void createPartControl(Composite parent
) {
116 super.createPartControl(parent
);
125 // * @return the currently active editor
127 // public IEditorPart getEditor() {
128 //// return AbstractUtility.getActiveEditor();
135 public void showEmptyPage() {
136 selectionProvidingPart
= null;
137 super.showEmptyPage();
142 public void setFocus() {
145 // if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){
146 // boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied();
147 // setEnabled(doEnable);
155 public void dispose() {
156 selectionProvidingPart
= null;
162 public void changed(Object object
) {
163 if(part
instanceof IDirtyMarkable
){
164 ((IDirtyMarkable
) part
).changed(object
);
167 // IEditorPart editor = getEditor();
168 // if (editor != null && editor instanceof IDirtyMarkable) {
169 // ((IDirtyMarkable) editor).changed(object);