1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.view;
|
5
|
|
6
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
7
|
import org.eclipse.jface.viewers.ISelection;
|
8
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
9
|
import org.eclipse.swt.widgets.Composite;
|
10
|
import org.eclipse.swt.widgets.Display;
|
11
|
import org.eclipse.ui.IWorkbenchPart;
|
12
|
|
13
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
14
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
15
|
|
16
|
/**
|
17
|
* <p>
|
18
|
* Abstract AbstractCdmEditorViewPart class.
|
19
|
* </p>
|
20
|
*
|
21
|
* @author n.hoffmann
|
22
|
* @created Sep 21, 2010
|
23
|
* @version 1.0
|
24
|
*/
|
25
|
public abstract class AbstractCdmEditorViewPart extends AbstractCdmViewPart implements ISelectionElementEditingPart {
|
26
|
|
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;
|
33
|
|
34
|
protected Object selectionProvidingPart;
|
35
|
|
36
|
|
37
|
/**
|
38
|
* This class invokes internal_selectionChanged() in a separate thread.
|
39
|
* This allows an asynchronous and/or delayed handling of selection changes
|
40
|
*/
|
41
|
private class DelaySelection implements Runnable{
|
42
|
private IWorkbenchPart part;
|
43
|
private ISelection selection;
|
44
|
|
45
|
public DelaySelection(IWorkbenchPart part, ISelection selection) {
|
46
|
super();
|
47
|
this.part = part;
|
48
|
this.selection = selection;
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public void run() {
|
53
|
try{
|
54
|
selectionChanged_internal(part, selection);
|
55
|
}
|
56
|
finally{
|
57
|
isInDelay = false;
|
58
|
}
|
59
|
}
|
60
|
|
61
|
public synchronized void setSelection(ISelection selection) {
|
62
|
this.selection = selection;
|
63
|
}
|
64
|
|
65
|
public synchronized void setPart(IWorkbenchPart part) {
|
66
|
this.part = part;
|
67
|
}
|
68
|
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Handle selection change events here and <b>not</b> in
|
73
|
* {@link AbstractCdmEditorViewPart#selectionChanged(IWorkbenchPart, ISelection)}
|
74
|
* if you want asynchronous selection handling.
|
75
|
* @param part The workbench part that has issued the selection change
|
76
|
* @param selection the new selection
|
77
|
*/
|
78
|
protected abstract void selectionChanged_internal(IWorkbenchPart part, ISelection selection);
|
79
|
|
80
|
/** {@inheritDoc} */
|
81
|
@Override
|
82
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
83
|
/*to avoid widget is disposed exceptions
|
84
|
if(getViewer().getControl().isDisposed()){
|
85
|
return;
|
86
|
}*/
|
87
|
if(delaySelection==null){
|
88
|
delaySelection = new DelaySelection(part, selection);
|
89
|
}
|
90
|
delaySelection.setPart(part);
|
91
|
delaySelection.setSelection(selection);
|
92
|
if(!isInDelay){
|
93
|
isInDelay = true;
|
94
|
Display.getCurrent().asyncExec(delaySelection);
|
95
|
}
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* {@inheritDoc}
|
100
|
*/
|
101
|
@Override
|
102
|
public void showViewer(Object part, IStructuredSelection selection) {
|
103
|
super.showViewer(part, selection);
|
104
|
selectionProvidingPart = part;
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public MPart getSelectionProvidingPart() {
|
109
|
return (MPart) selectionProvidingPart;
|
110
|
}
|
111
|
|
112
|
|
113
|
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
public void createPartControl(Composite parent) {
|
117
|
super.createPartControl(parent);
|
118
|
isInDelay = false;
|
119
|
}
|
120
|
|
121
|
// /**
|
122
|
// * <p>
|
123
|
// * getEditor
|
124
|
// * </p>
|
125
|
// *
|
126
|
// * @return the currently active editor
|
127
|
// */
|
128
|
// public IEditorPart getEditor() {
|
129
|
//// return AbstractUtility.getActiveEditor();
|
130
|
// }
|
131
|
|
132
|
/**
|
133
|
* {@inheritDoc}
|
134
|
*/
|
135
|
@Override
|
136
|
public void showEmptyPage() {
|
137
|
selectionProvidingPart = null;
|
138
|
super.showEmptyPage();
|
139
|
}
|
140
|
|
141
|
/** {@inheritDoc} */
|
142
|
@Override
|
143
|
public void setFocus() {
|
144
|
super.setFocus();
|
145
|
|
146
|
// if(getEditor() != null && ISecuredEditor.class.isAssignableFrom(getEditor().getClass())){
|
147
|
// boolean doEnable = ((ISecuredEditor)getEditor()).permissionsSatisfied();
|
148
|
// setEnabled(doEnable);
|
149
|
// }
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* {@inheritDoc}
|
154
|
*/
|
155
|
@Override
|
156
|
public void dispose() {
|
157
|
selectionProvidingPart = null;
|
158
|
super.dispose();
|
159
|
}
|
160
|
|
161
|
/** {@inheritDoc} */
|
162
|
@Override
|
163
|
public void changed(Object object) {
|
164
|
if(part instanceof IDirtyMarkable){
|
165
|
((IDirtyMarkable) part).changed(object);
|
166
|
}
|
167
|
else {
|
168
|
// IEditorPart editor = getEditor();
|
169
|
// if (editor != null && editor instanceof IDirtyMarkable) {
|
170
|
// ((IDirtyMarkable) editor).changed(object);
|
171
|
// }
|
172
|
}
|
173
|
}
|
174
|
|
175
|
}
|