Revision 81893f4a
Added by Niels Hoffmann about 13 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
3 |
* Copyright (C) 2007 EDIT
|
|
4 |
* European Distributed Institute of Taxonomy
|
|
5 |
* http://www.e-taxonomy.eu
|
|
6 |
*
|
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
|
9 |
*/
|
|
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.navigation.navigator; |
12 | 12 |
|
... | ... | |
42 | 42 |
|
43 | 43 |
/** |
44 | 44 |
* Taxonomic tree implementation using Common Navigator Framework. |
45 |
* |
|
45 |
*
|
|
46 | 46 |
* @author p.ciardelli |
47 | 47 |
* @author n.hoffmann |
48 | 48 |
* @created 02.06.2009 |
49 | 49 |
* @version 1.0 |
50 | 50 |
*/ |
51 |
public class TaxonNavigator extends CommonNavigator implements IPostOperationEnabled, IConversationEnabled{ |
|
51 |
public class TaxonNavigator extends CommonNavigator implements |
|
52 |
IPostOperationEnabled, IConversationEnabled { |
|
52 | 53 |
|
53 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */ |
|
54 |
/** |
|
55 |
* Constant |
|
56 |
* <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> |
|
57 |
*/ |
|
54 | 58 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator"; //$NON-NLS-1$ |
55 | 59 |
|
56 |
/** Constant <code>OPEN_COMMAND_ID="eu.etaxonomy.taxeditor.navigation.comma"{trunked}</code> */ |
|
60 |
/** |
|
61 |
* Constant |
|
62 |
* <code>OPEN_COMMAND_ID="eu.etaxonomy.taxeditor.navigation.comma"{trunked}</code> |
|
63 |
*/ |
|
57 | 64 |
public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.command.editSelection"; |
58 |
|
|
65 |
|
|
59 | 66 |
private static final String TREE_PATH = "treepath"; |
60 | 67 |
|
61 | 68 |
private static final String TREE_PATHS = "treepaths"; |
62 | 69 |
|
63 | 70 |
private ConversationHolder conversation; |
64 |
|
|
71 |
|
|
65 | 72 |
private String partNameCache; |
66 | 73 |
|
67 | 74 |
private IDataChangeBehavior dataChangeBehavior; |
68 | 75 |
|
69 |
/* (non-Javadoc) |
|
76 |
/* |
|
77 |
* (non-Javadoc) |
|
78 |
* |
|
70 | 79 |
* @see org.eclipse.ui.navigator.CommonNavigator#getInitialInput() |
71 | 80 |
*/ |
72 | 81 |
/** {@inheritDoc} */ |
73 | 82 |
@Override |
74 | 83 |
protected IAdaptable getInitialInput() { |
75 |
if(CdmStore.isActive()){ |
|
76 |
// TODO when closing and reopening the taxon navigator |
|
77 |
// we do not preserve state. Closing the view, in contrary to closing the whole application |
|
84 |
if (CdmStore.isActive()) { |
|
85 |
// TODO when closing and reopening the taxon navigator |
|
86 |
// we do not preserve state. Closing the view, in contrary to |
|
87 |
// closing the whole application |
|
78 | 88 |
// should be handled by the state manager too |
79 |
|
|
89 |
|
|
80 | 90 |
return new Root(conversation); |
81 | 91 |
} |
82 | 92 |
return new EmptyRoot(); |
83 | 93 |
} |
84 |
|
|
94 |
|
|
85 | 95 |
/** {@inheritDoc} */ |
86 |
public void init(IViewSite site)
|
|
87 |
throws PartInitException {
|
|
96 |
@Override
|
|
97 |
public void init(IViewSite site) throws PartInitException {
|
|
88 | 98 |
super.init(site); |
89 | 99 |
init(); |
90 | 100 |
} |
91 |
|
|
101 |
|
|
92 | 102 |
/** |
93 |
* <p>init</p> |
|
103 |
* <p> |
|
104 |
* init |
|
105 |
* </p> |
|
94 | 106 |
*/ |
95 |
public void init(){ |
|
96 |
if(CdmStore.isActive() && conversation == null){
|
|
107 |
public void init() {
|
|
108 |
if (CdmStore.isActive() && conversation == null) {
|
|
97 | 109 |
conversation = CdmStore.createConversation(); |
98 | 110 |
conversation.registerForDataStoreChanges(TaxonNavigator.this); |
99 | 111 |
} |
100 | 112 |
} |
101 |
|
|
113 |
|
|
102 | 114 |
/** |
103 | 115 |
* Refresh this navigators viewer |
104 | 116 |
*/ |
105 |
public void refresh(){ |
|
117 |
public void refresh() {
|
|
106 | 118 |
getConversationHolder().bind(); |
107 | 119 |
getCommonViewer().refresh(); |
108 | 120 |
} |
... | ... | |
110 | 122 |
/** |
111 | 123 |
* Removes all content |
112 | 124 |
*/ |
113 |
public void clear(){ |
|
125 |
public void clear() {
|
|
114 | 126 |
getCommonViewer().setInput(new EmptyRoot()); |
115 | 127 |
} |
116 |
|
|
128 |
|
|
117 | 129 |
/** |
118 |
* <p>restore</p> |
|
119 |
* |
|
120 |
* @param memento a {@link org.eclipse.ui.IMemento} object. |
|
121 |
* @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
130 |
* <p> |
|
131 |
* restore |
|
132 |
* </p> |
|
133 |
* |
|
134 |
* @param memento |
|
135 |
* a {@link org.eclipse.ui.IMemento} object. |
|
136 |
* @param monitor |
|
137 |
* a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
122 | 138 |
*/ |
123 | 139 |
public void restore(IMemento memento, IProgressMonitor monitor) { |
124 | 140 |
if (memento == null) { |
... | ... | |
128 | 144 |
int mementoWork = 0; |
129 | 145 |
Set<TreePath> treePaths = new HashSet<TreePath>(); |
130 | 146 |
IMemento[] treePathMementos = null; |
131 |
|
|
147 |
|
|
132 | 148 |
IMemento treePathsMemento = memento.getChild(TREE_PATHS); |
133 |
|
|
149 |
|
|
134 | 150 |
if (treePathsMemento != null) { |
135 | 151 |
treePathMementos = treePathsMemento.getChildren(TREE_PATH); |
136 | 152 |
mementoWork = treePathMementos.length; |
137 | 153 |
} |
138 |
// begin the monitor with steps for all tree paths and steps for creating |
|
139 |
// conversation s.o., refreshing the tree and setting the paths |
|
140 |
IProgressMonitor subProgressMonitor = NavigationUtil.getSubProgressMonitor(monitor, 1); |
|
141 |
|
|
142 |
subProgressMonitor.beginTask("Restoring Taxon Navigator", 1 + mementoWork + 5); |
|
154 |
// begin the monitor with steps for all tree paths and steps for |
|
155 |
// creating |
|
156 |
// conversation s.o., refreshing the tree and setting the paths |
|
157 |
IProgressMonitor subProgressMonitor = NavigationUtil |
|
158 |
.getSubProgressMonitor(monitor, 1); |
|
159 |
|
|
160 |
subProgressMonitor.beginTask("Restoring Taxon Navigator", |
|
161 |
1 + mementoWork + 5); |
|
143 | 162 |
subProgressMonitor.subTask("Restoring Taxon Navigator"); |
144 | 163 |
subProgressMonitor.worked(1); |
145 |
|
|
164 |
|
|
146 | 165 |
conversation = CdmStore.createConversation(); |
147 | 166 |
subProgressMonitor.worked(1); |
148 | 167 |
conversation.registerForDataStoreChanges(TaxonNavigator.this); |
... | ... | |
151 | 170 |
subProgressMonitor.worked(1); |
152 | 171 |
getCommonViewer().refresh(); |
153 | 172 |
subProgressMonitor.worked(1); |
154 |
|
|
155 |
|
|
156 |
|
|
173 |
|
|
157 | 174 |
if (treePathMementos != null && treePathMementos.length > 0) { |
158 | 175 |
for (IMemento treePathMemento : treePathMementos) { |
159 |
TreePath treePath = createTreePathFromString(treePathMemento.getID()); |
|
176 |
TreePath treePath = createTreePathFromString(treePathMemento |
|
177 |
.getID()); |
|
160 | 178 |
if (!subProgressMonitor.isCanceled() && treePath != null) { |
161 | 179 |
treePaths.add(treePath); |
162 | 180 |
subProgressMonitor.worked(1); |
... | ... | |
164 | 182 |
} |
165 | 183 |
} |
166 | 184 |
if (treePaths.size() > 0) { |
167 |
TaxonNavigator.this.getCommonViewer().setExpandedTreePaths(treePaths.toArray(new TreePath[0])); |
|
185 |
TaxonNavigator.this.getCommonViewer().setExpandedTreePaths( |
|
186 |
treePaths.toArray(new TreePath[0])); |
|
168 | 187 |
subProgressMonitor.worked(1); |
169 | 188 |
} |
170 | 189 |
subProgressMonitor.done(); |
... | ... | |
177 | 196 |
private TreePath createTreePathFromString(String string) { |
178 | 197 |
|
179 | 198 |
List<CdmBase> pathList = new ArrayList<CdmBase>(); |
180 |
|
|
181 |
if(string.length() == 0) return null; |
|
182 |
|
|
199 |
|
|
200 |
if (string.length() == 0) |
|
201 |
return null; |
|
202 |
|
|
183 | 203 |
for (String uuid : string.split(" ")) { |
184 |
CdmBase cdmBaseObject = CdmStore.getService(IClassificationService.class).getTaxonNodeByUuid(UUID.fromString(uuid)); |
|
204 |
CdmBase cdmBaseObject = CdmStore.getService( |
|
205 |
IClassificationService.class).getTaxonNodeByUuid( |
|
206 |
UUID.fromString(uuid)); |
|
185 | 207 |
if (cdmBaseObject == null) { |
186 | 208 |
// is this a tree uuid? |
187 |
cdmBaseObject = CdmStore.getService(IClassificationService.class).getClassificationByUuid(UUID.fromString(uuid)); |
|
188 |
|
|
189 |
if(cdmBaseObject == null) return null; |
|
209 |
cdmBaseObject = CdmStore.getService( |
|
210 |
IClassificationService.class).load( |
|
211 |
UUID.fromString(uuid)); |
|
212 |
|
|
213 |
if (cdmBaseObject == null) |
|
214 |
return null; |
|
190 | 215 |
} |
191 | 216 |
pathList.add(cdmBaseObject); |
192 | 217 |
} |
193 | 218 |
return new TreePath(pathList.toArray()); |
194 | 219 |
} |
195 | 220 |
|
196 |
|
|
197 | 221 |
/** {@inheritDoc} */ |
198 | 222 |
@Override |
199 | 223 |
public void saveState(IMemento aMemento) { |
200 | 224 |
// |
201 | 225 |
} |
202 |
|
|
226 |
|
|
203 | 227 |
/** |
204 |
* <p>saveTreeState</p> |
|
205 |
* |
|
206 |
* @param memento a {@link org.eclipse.ui.IMemento} object. |
|
207 |
* @param progressMonitor a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
228 |
* <p> |
|
229 |
* saveTreeState |
|
230 |
* </p> |
|
231 |
* |
|
232 |
* @param memento |
|
233 |
* a {@link org.eclipse.ui.IMemento} object. |
|
234 |
* @param progressMonitor |
|
235 |
* a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
208 | 236 |
*/ |
209 | 237 |
public void saveTreeState(IMemento memento, IProgressMonitor progressMonitor) { |
210 | 238 |
if (memento == null) { |
211 | 239 |
return; |
212 | 240 |
} |
213 |
IProgressMonitor monitor = NavigationUtil.getSubProgressMonitor(progressMonitor, 1); |
|
214 |
|
|
241 |
IProgressMonitor monitor = NavigationUtil.getSubProgressMonitor( |
|
242 |
progressMonitor, 1); |
|
243 |
|
|
215 | 244 |
super.saveState(memento); |
216 |
|
|
245 |
|
|
217 | 246 |
memento = memento.createChild(TREE_PATHS); |
218 | 247 |
TreePath[] treePaths = this.getCommonViewer().getExpandedTreePaths(); |
219 |
|
|
248 |
|
|
220 | 249 |
monitor.beginTask("Saving Taxon Navigator State", treePaths.length); |
221 |
|
|
250 |
|
|
222 | 251 |
for (TreePath treePath : treePaths) { |
223 | 252 |
int pathLength = treePath.getSegmentCount(); |
224 | 253 |
String path = ""; |
... | ... | |
226 | 255 |
Object segment = treePath.getSegment(i); |
227 | 256 |
if (segment instanceof CdmBase) { |
228 | 257 |
path += ((CdmBase) segment).getUuid().toString() + " "; |
229 |
monitor.worked(1);
|
|
258 |
monitor.worked(1); |
|
230 | 259 |
} else { |
231 |
NavigationUtil.warn(getClass(), "Non-taxon tree path segment " + segment); |
|
260 |
NavigationUtil.warn(getClass(), |
|
261 |
"Non-taxon tree path segment " + segment); |
|
232 | 262 |
} |
233 | 263 |
} |
234 | 264 |
memento.createChild(TREE_PATH, path.trim()); |
235 | 265 |
} |
236 | 266 |
monitor.done(); |
237 |
}
|
|
267 |
} |
|
238 | 268 |
|
239 |
/* (non-Javadoc) |
|
240 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
269 |
/* |
|
270 |
* (non-Javadoc) |
|
271 |
* |
|
272 |
* @see |
|
273 |
* eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder |
|
274 |
* () |
|
241 | 275 |
*/ |
242 | 276 |
/** |
243 |
* <p>getConversationHolder</p> |
|
244 |
* |
|
245 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
277 |
* <p> |
|
278 |
* getConversationHolder |
|
279 |
* </p> |
|
280 |
* |
|
281 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} |
|
282 |
* object. |
|
246 | 283 |
*/ |
284 |
@Override |
|
247 | 285 |
public ConversationHolder getConversationHolder() { |
248 | 286 |
return conversation; |
249 | 287 |
} |
250 | 288 |
|
251 |
/* (non-Javadoc) |
|
252 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
289 |
/* |
|
290 |
* (non-Javadoc) |
|
291 |
* |
|
292 |
* @see |
|
293 |
* eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update |
|
294 |
* (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
253 | 295 |
*/ |
254 | 296 |
/** {@inheritDoc} */ |
297 |
@Override |
|
255 | 298 |
public void update(CdmDataChangeMap changeEvents) { |
256 |
if(dataChangeBehavior == null){
|
|
299 |
if (dataChangeBehavior == null) {
|
|
257 | 300 |
dataChangeBehavior = new TaxonNavigatorDataChangeBehavior(this); |
258 | 301 |
} |
259 |
|
|
302 |
|
|
260 | 303 |
DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior); |
261 | 304 |
} |
262 |
|
|
305 |
|
|
263 | 306 |
/** {@inheritDoc} */ |
307 |
@Override |
|
264 | 308 |
public String getFrameToolTipText(Object element) { |
265 | 309 |
if (element instanceof Root) { |
266 | 310 |
return "Taxonomic Tree"; |
267 | 311 |
} |
268 | 312 |
return super.getFrameToolTipText(element); |
269 | 313 |
} |
270 |
|
|
271 |
/* (non-Javadoc) |
|
314 |
|
|
315 |
/* |
|
316 |
* (non-Javadoc) |
|
317 |
* |
|
272 | 318 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
273 | 319 |
*/ |
274 | 320 |
/** {@inheritDoc} */ |
... | ... | |
276 | 322 |
public void dispose() { |
277 | 323 |
super.dispose(); |
278 | 324 |
dataChangeBehavior = null; |
279 |
if(conversation != null){
|
|
325 |
if (conversation != null) {
|
|
280 | 326 |
conversation.unregisterForDataStoreChanges(this); |
281 | 327 |
} |
282 | 328 |
} |
283 |
|
|
284 |
/* (non-Javadoc) |
|
329 |
|
|
330 |
/* |
|
331 |
* (non-Javadoc) |
|
332 |
* |
|
285 | 333 |
* @see org.eclipse.ui.navigator.CommonNavigator#setFocus() |
286 | 334 |
*/ |
287 | 335 |
/** {@inheritDoc} */ |
288 | 336 |
@Override |
289 | 337 |
public void setFocus() { |
290 |
//logger.warn("Setting focus to navigator"); |
|
338 |
// logger.warn("Setting focus to navigator");
|
|
291 | 339 |
super.setFocus(); |
292 |
if(getConversationHolder() != null){
|
|
340 |
if (getConversationHolder() != null) {
|
|
293 | 341 |
getConversationHolder().bind(); |
294 | 342 |
} |
295 | 343 |
} |
296 | 344 |
|
297 |
/* (non-Javadoc) |
|
298 |
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) |
|
345 |
/* |
|
346 |
* (non-Javadoc) |
|
347 |
* |
|
348 |
* @see |
|
349 |
* eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation |
|
350 |
* (eu.etaxonomy.cdm.model.common.CdmBase) |
|
299 | 351 |
*/ |
300 | 352 |
/** {@inheritDoc} */ |
353 |
@Override |
|
301 | 354 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
302 | 355 |
// nothing to do here |
303 | 356 |
return true; |
304 | 357 |
} |
305 | 358 |
|
306 | 359 |
/** |
307 |
* <p>save</p> |
|
308 |
* |
|
309 |
* @param memento a {@link org.eclipse.ui.IMemento} object. |
|
310 |
* @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
360 |
* <p> |
|
361 |
* save |
|
362 |
* </p> |
|
363 |
* |
|
364 |
* @param memento |
|
365 |
* a {@link org.eclipse.ui.IMemento} object. |
|
366 |
* @param monitor |
|
367 |
* a {@link org.eclipse.core.runtime.IProgressMonitor} object. |
|
311 | 368 |
*/ |
312 | 369 |
public void save(IMemento memento, IProgressMonitor monitor) { |
313 | 370 |
saveTreeState(memento, monitor); |
314 |
if(conversation != null){
|
|
371 |
if (conversation != null) {
|
|
315 | 372 |
conversation.unregisterForDataStoreChanges(this); |
316 | 373 |
conversation = null; |
317 | 374 |
} |
318 | 375 |
} |
319 |
|
|
376 |
|
|
320 | 377 |
/** {@inheritDoc} */ |
321 | 378 |
@Override |
322 | 379 |
protected void handleDoubleClick(DoubleClickEvent anEvent) { |
323 |
|
|
324 |
ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class); |
|
325 |
|
|
326 |
Command command = commandService.getCommand(OPEN_COMMAND_ID); |
|
327 |
if(command.isEnabled()) { |
|
328 |
IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class); |
|
380 |
|
|
381 |
ICommandService commandService = (ICommandService) getSite() |
|
382 |
.getService(ICommandService.class); |
|
383 |
|
|
384 |
Command command = commandService.getCommand(OPEN_COMMAND_ID); |
|
385 |
if (command.isEnabled()) { |
|
386 |
IHandlerService handlerService = (IHandlerService) getSite() |
|
387 |
.getService(IHandlerService.class); |
|
329 | 388 |
try { |
330 | 389 |
handlerService.executeCommand(OPEN_COMMAND_ID, null); |
331 | 390 |
} catch (NotDefinedException e) { |
332 |
throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID); |
|
391 |
throw new RuntimeException("Could not find open command: " |
|
392 |
+ OPEN_COMMAND_ID); |
|
333 | 393 |
} catch (Exception e) { |
334 |
NavigationUtil.error(getClass(), "An exception occured while trying to open a selection", e); |
|
394 |
NavigationUtil |
|
395 |
.error(getClass(), |
|
396 |
"An exception occured while trying to open a selection", |
|
397 |
e); |
|
335 | 398 |
} |
336 | 399 |
} |
337 |
// If the double click is passed up to the super-class it will expand/collapse trees. |
|
400 |
// If the double click is passed up to the super-class it will |
|
401 |
// expand/collapse trees. |
|
338 | 402 |
// We do not want that |
339 |
//super.handleDoubleClick(anEvent); |
|
403 |
// super.handleDoubleClick(anEvent);
|
|
340 | 404 |
} |
341 | 405 |
|
342 | 406 |
/** |
343 |
* <p>onComplete</p> |
|
344 |
* |
|
407 |
* <p> |
|
408 |
* onComplete |
|
409 |
* </p> |
|
410 |
* |
|
345 | 411 |
* @return a boolean. |
346 | 412 |
*/ |
413 |
@Override |
|
347 | 414 |
public boolean onComplete() { |
348 | 415 |
return true; |
349 | 416 |
} |
350 |
|
|
351 |
/* (non-Javadoc) |
|
417 |
|
|
418 |
/* |
|
419 |
* (non-Javadoc) |
|
420 |
* |
|
352 | 421 |
* @see org.eclipse.ui.part.WorkbenchPart#showBusy(boolean) |
353 | 422 |
*/ |
354 | 423 |
/** {@inheritDoc} */ |
... | ... | |
356 | 425 |
public void showBusy(boolean busy) { |
357 | 426 |
super.showBusy(busy); |
358 | 427 |
getCommonViewer().getControl().setEnabled(!busy); |
359 |
if(busy){
|
|
428 |
if (busy) {
|
|
360 | 429 |
partNameCache = getPartName(); |
361 | 430 |
setPartName("Loading datasources"); |
362 |
}else{
|
|
363 |
if(partNameCache != null){
|
|
431 |
} else {
|
|
432 |
if (partNameCache != null) {
|
|
364 | 433 |
setPartName(partNameCache); |
365 | 434 |
} |
366 | 435 |
} |
Also available in: Unified diff
Removing calls of deprecated methods