Revision 2832a925
Added by Patrick Plitzner over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmEditorViewPart.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.view; |
5 | 5 |
|
6 |
import org.eclipse.jface.viewers.ISelection; |
|
6 | 7 |
import org.eclipse.swt.widgets.Composite; |
8 |
import org.eclipse.swt.widgets.Display; |
|
7 | 9 |
import org.eclipse.ui.IEditorPart; |
10 |
import org.eclipse.ui.IWorkbenchPart; |
|
8 | 11 |
|
9 | 12 |
import eu.etaxonomy.taxeditor.editor.ISecuredEditor; |
10 | 13 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
... | ... | |
21 | 24 |
*/ |
22 | 25 |
public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart { |
23 | 26 |
|
24 |
/* |
|
25 |
* (non-Javadoc) |
|
26 |
* |
|
27 |
* @see |
|
28 |
* eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org |
|
29 |
* .eclipse.swt.widgets.Composite) |
|
30 |
*/ |
|
31 |
/** {@inheritDoc} */ |
|
32 |
@Override |
|
33 |
public void createPartControl(Composite parent) { |
|
34 |
super.createPartControl(parent); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* <p> |
|
39 |
* getEditor |
|
40 |
* </p> |
|
41 |
* |
|
42 |
* @return the currently active editor |
|
43 |
*/ |
|
44 |
public IEditorPart getEditor() { |
|
45 |
return AbstractUtility.getActiveEditor(); |
|
46 |
} |
|
47 |
|
|
48 |
/** {@inheritDoc} */ |
|
49 |
@Override |
|
50 |
public void setFocus() { |
|
51 |
super.setFocus(); |
|
52 |
|
|
53 |
if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){ |
|
54 |
boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied(); |
|
55 |
setEnabled(doEnable); |
|
56 |
} |
|
27 |
private DelaySelection delaySelection = null; |
|
28 |
/** |
|
29 |
* This is the monitor for the DelaySelection runnable. |
|
30 |
* If it is <code>true</code> then it is currently delaying a selection. |
|
31 |
*/ |
|
32 |
private boolean isInDelay = false; |
|
33 |
|
|
34 |
|
|
35 |
/** |
|
36 |
* This class invokes internal_selectionChanged() in a separate thread. |
|
37 |
* This allows an asynchronous and/or delayed handling of selection changes |
|
38 |
*/ |
|
39 |
private class DelaySelection implements Runnable{ |
|
40 |
private IWorkbenchPart part; |
|
41 |
private ISelection selection; |
|
42 |
|
|
43 |
public DelaySelection(IWorkbenchPart part, ISelection selection) { |
|
44 |
super(); |
|
45 |
this.part = part; |
|
46 |
this.selection = selection; |
|
47 |
} |
|
48 |
|
|
49 |
/* (non-Javadoc) |
|
50 |
* @see java.lang.Runnable#run() |
|
51 |
*/ |
|
52 |
@Override |
|
53 |
public void run() { |
|
54 |
internal_selectionChanged(part, selection); |
|
55 |
isInDelay = false; |
|
56 |
} |
|
57 |
|
|
58 |
public synchronized void setSelection(ISelection selection) { |
|
59 |
this.selection = selection; |
|
60 |
} |
|
61 |
|
|
62 |
public synchronized void setPart(IWorkbenchPart part) { |
|
63 |
this.part = part; |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
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 |
|
74 |
*/ |
|
75 |
protected abstract void internal_selectionChanged(IWorkbenchPart part, ISelection selection); |
|
76 |
|
|
77 |
/** {@inheritDoc} */ |
|
78 |
@Override |
|
79 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
80 |
if(delaySelection==null){ |
|
81 |
delaySelection = new DelaySelection(part, selection); |
|
82 |
} |
|
83 |
delaySelection.setPart(part); |
|
84 |
delaySelection.setSelection(selection); |
|
85 |
if(!isInDelay){ |
|
86 |
isInDelay = true; |
|
87 |
Display.getCurrent().asyncExec(delaySelection); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
/* |
|
92 |
* (non-Javadoc) |
|
93 |
* |
|
94 |
* @see |
|
95 |
* eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createPartControl(org |
|
96 |
* .eclipse.swt.widgets.Composite) |
|
97 |
*/ |
|
98 |
/** {@inheritDoc} */ |
|
99 |
@Override |
|
100 |
public void createPartControl(Composite parent) { |
|
101 |
super.createPartControl(parent); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* <p> |
|
106 |
* getEditor |
|
107 |
* </p> |
|
108 |
* |
|
109 |
* @return the currently active editor |
|
110 |
*/ |
|
111 |
public IEditorPart getEditor() { |
|
112 |
return AbstractUtility.getActiveEditor(); |
|
113 |
} |
|
114 |
|
|
115 |
/** {@inheritDoc} */ |
|
116 |
@Override |
|
117 |
public void setFocus() { |
|
118 |
super.setFocus(); |
|
119 |
|
|
120 |
if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){ |
|
121 |
boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied(); |
|
122 |
setEnabled(doEnable); |
|
123 |
} |
|
57 | 124 |
} |
58 | 125 |
|
59 | 126 |
/** {@inheritDoc} */ |
Also available in: Unified diff
fix for #2754