26 |
26 |
import org.eclipse.ui.internal.Workbench;
|
27 |
27 |
import org.springframework.remoting.RemoteAccessException;
|
28 |
28 |
|
|
29 |
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
29 |
30 |
import eu.etaxonomy.taxeditor.model.IContextListener;
|
30 |
31 |
import eu.etaxonomy.taxeditor.model.MementoHelper;
|
31 |
32 |
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
... | ... | |
36 |
37 |
*
|
37 |
38 |
* @author n.hoffmann
|
38 |
39 |
* @created Sep 30, 2010
|
39 |
|
* @version 1.0
|
40 |
40 |
*/
|
41 |
41 |
public class ContextManager implements IWorkbenchListener{
|
42 |
42 |
|
43 |
|
private final ListenerList contextListeners = new ListenerList();
|
|
43 |
private final ListenerList<IContextListener> contextListeners = new ListenerList<>();
|
44 |
44 |
|
45 |
45 |
private IMemento memento;
|
46 |
46 |
|
... | ... | |
53 |
53 |
}
|
54 |
54 |
}
|
55 |
55 |
|
56 |
|
/**
|
57 |
|
* <p>addContextListener</p>
|
58 |
|
*
|
59 |
|
* @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
|
60 |
|
*/
|
61 |
56 |
public void addContextListener(IContextListener listener){
|
62 |
57 |
contextListeners.add(listener);
|
63 |
58 |
}
|
64 |
59 |
|
65 |
|
/**
|
66 |
|
* <p>removeContextListener</p>
|
67 |
|
*
|
68 |
|
* @param listener a {@link eu.etaxonomy.taxeditor.model.IContextListener} object.
|
69 |
|
*/
|
70 |
60 |
public void removeContextListener(IContextListener listener) {
|
71 |
61 |
contextListeners.remove(listener);
|
72 |
62 |
}
|
... | ... | |
80 |
70 |
((IContextListener) listener).contextStart(memento, monitor);
|
81 |
71 |
}
|
82 |
72 |
}
|
83 |
|
/**
|
84 |
|
* <p>notifyContextStart</p>
|
85 |
|
* @throws Throwable
|
86 |
|
*/
|
|
73 |
|
87 |
74 |
public void notifyContextStart() throws RemoteAccessException {
|
88 |
75 |
MessagingUtils.info("Notifying context listeners, that the context has started.");
|
89 |
|
ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
|
|
76 |
ProgressMonitorDialog dialog = new ProgressMonitorDialog(AbstractUtility.getShell());
|
90 |
77 |
|
91 |
78 |
try {
|
92 |
79 |
dialog.run(false, false, new IRunnableWithProgress() {
|
93 |
|
/* (non-Javadoc)
|
94 |
|
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
|
95 |
|
*/
|
|
80 |
|
96 |
81 |
@Override
|
97 |
82 |
public void run(IProgressMonitor monitor)
|
98 |
83 |
throws InvocationTargetException, InterruptedException {
|
... | ... | |
124 |
109 |
}
|
125 |
110 |
}
|
126 |
111 |
|
127 |
|
|
128 |
|
/**
|
129 |
|
*
|
130 |
|
*/
|
131 |
112 |
public void notifyContextRefresh() {
|
132 |
113 |
MessagingUtils.info("Notifying context listeners, that the context needs to be refreshed.");
|
133 |
|
ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
|
|
114 |
ProgressMonitorDialog dialog = new ProgressMonitorDialog(AbstractUtility.getShell());
|
134 |
115 |
|
135 |
116 |
try {
|
136 |
117 |
dialog.run(false, false, new IRunnableWithProgress() {
|
137 |
|
/* (non-Javadoc)
|
138 |
|
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
|
139 |
|
*/
|
|
118 |
|
140 |
119 |
@Override
|
141 |
120 |
public void run(IProgressMonitor monitor)
|
142 |
121 |
throws InvocationTargetException, InterruptedException {
|
... | ... | |
164 |
143 |
}
|
165 |
144 |
}
|
166 |
145 |
|
167 |
|
/**
|
168 |
|
* <p>notifyContextAboutToStop</p>
|
169 |
|
*
|
170 |
|
* @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
|
171 |
|
*/
|
172 |
146 |
public void notifyContextAboutToStop(final IProgressMonitor monitor){
|
173 |
147 |
|
174 |
|
IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
|
|
148 |
IProgressMonitor subMonitor = AbstractUtility.getSubProgressMonitor(monitor, 1);
|
175 |
149 |
|
176 |
150 |
subMonitor.beginTask("Stoping context", contextListeners.size());
|
177 |
151 |
// we are creating the memento here; even if the context is not stopped
|
... | ... | |
185 |
159 |
subMonitor.done();
|
186 |
160 |
}
|
187 |
161 |
|
188 |
|
/**
|
189 |
|
* <p>notifyContextStop</p>
|
190 |
|
*
|
191 |
|
* @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object.
|
192 |
|
*/
|
193 |
162 |
public void notifyContextStop(IProgressMonitor monitor) {
|
194 |
163 |
|
195 |
|
IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, 1);
|
|
164 |
IProgressMonitor subMonitor = AbstractUtility.getSubProgressMonitor(monitor, 1);
|
196 |
165 |
|
197 |
166 |
subMonitor.beginTask("Stoping context", contextListeners.size());
|
198 |
167 |
MessagingUtils.info("Notifying context listeners, that the context has stopped.");
|
... | ... | |
206 |
175 |
subMonitor.done();
|
207 |
176 |
}
|
208 |
177 |
|
209 |
|
/* (non-Javadoc)
|
210 |
|
* @see org.eclipse.ui.IWorkbenchListener#preShutdown(org.eclipse.ui.IWorkbench, boolean)
|
211 |
|
*/
|
212 |
|
/** {@inheritDoc} */
|
213 |
178 |
@Override
|
214 |
179 |
public boolean preShutdown(IWorkbench workbench, boolean forced) {
|
215 |
180 |
|
... | ... | |
227 |
192 |
return true;
|
228 |
193 |
}
|
229 |
194 |
|
230 |
|
/* (non-Javadoc)
|
231 |
|
* @see org.eclipse.ui.IWorkbenchListener#postShutdown(org.eclipse.ui.IWorkbench)
|
232 |
|
*/
|
233 |
|
/** {@inheritDoc} */
|
234 |
195 |
@Override
|
235 |
196 |
public void postShutdown(IWorkbench workbench) {
|
236 |
|
|
237 |
|
|
238 |
197 |
}
|
239 |
198 |
|
240 |
|
|
241 |
199 |
private void readMemento(){
|
242 |
200 |
try {
|
243 |
201 |
memento = MementoHelper.readMementoFromFile(getStateFileForCurrentDatabase());
|
... | ... | |
265 |
223 |
} else {
|
266 |
224 |
MessagingUtils.info("Not storing state data, because no DataSource present.");
|
267 |
225 |
}
|
268 |
|
|
269 |
226 |
}
|
270 |
227 |
|
271 |
228 |
private boolean saveMemento(){
|
272 |
229 |
return MementoHelper.saveMementoToFile(memento, getStateFileForCurrentDatabase()) != null;
|
273 |
230 |
}
|
274 |
231 |
|
275 |
|
/**
|
276 |
|
* <p>getStateFileForCurrentDatabase</p>
|
277 |
|
*
|
278 |
|
* @return a {@link java.io.File} object.
|
279 |
|
*/
|
280 |
232 |
protected File getStateFileForCurrentDatabase() {
|
281 |
233 |
if(CdmStore.getActiveCdmSource() == null){
|
282 |
234 |
return null;
|
... | ... | |
289 |
241 |
path = path.append("editor_state_" + CdmStore.getActiveCdmSource().getName() + ".xml");
|
290 |
242 |
return path.toFile();
|
291 |
243 |
}
|
292 |
|
|
293 |
244 |
}
|
cleanup