blob: 26d436721b4b7c7c3529d632ccfb360d2b950e9f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.internal;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
/**
* The job listener called after the restoring job is done,
* to set the expanded states of the tree viewer in
* a safe UI thread.
*/
public class RestoreDone extends JobChangeAdapter {
// The tree viewer whose expanding state is going to be restored.
private TreeViewer viewer;
/**
* Create a job listener with the specified tree viewer.
*
* @param viewer The tree viewer whose state is going to be restored.
*/
public RestoreDone(TreeViewer viewer) {
this.viewer = viewer;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
@Override
public void done(IJobChangeEvent event) {
IStatus result = event.getResult();
if(result.isOK() && result instanceof RestoreStatus) {
final RestoreStatus status = (RestoreStatus) result;
Tree tree = viewer.getTree();
if(!tree.isDisposed()) {
Display display = tree.getDisplay();
if(!display.isDisposed()) {
display.asyncExec(new Runnable(){
@Override
public void run() {
expandTreeViewer(status);
}});
}
}
}
}
/**
* Expand the tree viewer using the restoring status where the expanded paths are retrieved.
*
* @param status The status that keeps the expanded paths.
*/
void expandTreeViewer(RestoreStatus status) {
IElementComparer comparer = viewer.getComparer();
if(comparer instanceof ViewViewerComparer) {
((ViewViewerComparer)comparer).setByDefault(false);
}
viewer.setExpandedTreePaths(status.getExpandedPaths());
if(comparer instanceof ViewViewerComparer) {
((ViewViewerComparer)comparer).setByDefault(true);
}
}
}
|