/
EReferencesView.java
136 lines (114 loc) · 3.92 KB
/
EReferencesView.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/***********************************************************************
* Copyright (c) 2007 Anyware Technologies
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Anyware Technologies - initial API and implementation
*
* $Id: EReferencesView.java,v 1.6 2008/05/19 09:26:31 jlescot Exp $
**********************************************************************/
package org.eclipse.emf.ecoretools.ui.views;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecoretools.ui.Messages;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.progress.WorkbenchJob;
/**
* This class displays all the references to an EClass
*
* @author <a href="david.sciamma@anyware-tech.com">David Sciamma</a>
*/
public class EReferencesView extends AnalysisView {
/**
* The ID of the view
*/
public static final String VIEW_ID = "org.eclipse.emf.ecoretools.internal.views.EReferencesView"; //$NON-NLS-1$
private TreeViewer referencesTree;
/**
* The job used to refresh the tree.
*/
private Job refreshJob;
/**
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
referencesTree = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
referencesTree.setContentProvider(new EReferencesContentProvider());
referencesTree.setLabelProvider(new EReferencesLabelProvider());
referencesTree.getControl().addDisposeListener(new DisposeListener() {
/**
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
*/
public void widgetDisposed(DisposeEvent e) {
if (refreshJob != null) {
refreshJob.cancel();
}
}
});
prepareViewerForDragToSirius(referencesTree);
}
/**
* @see org.eclipse.emf.ecoretools.ui.views.AnalysisView#refresh(org.eclipse.emf.ecore.EObject)
*/
@Override
protected void refresh(EObject object) {
// cancel currently running job first, to prevent unnecessary redraw
if (refreshJob != null) {
refreshJob.cancel();
}
if (object instanceof DSemanticDecorator) {
object = ((DSemanticDecorator)object).getTarget();
}
if (object instanceof EClass) {
EClass selectedEClass = (EClass) object;
if (selectedEClass != null) {
refreshJob = createRefreshJob(selectedEClass);
refreshJob.schedule(200);
}
}
}
private Job createRefreshJob(final EClass selection) {
Job job = new WorkbenchJob(Messages.EReferencesView_RefreshReferences) {
/**
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (referencesTree.getControl().isDisposed()) {
return Status.CANCEL_STATUS;
}
try {
referencesTree.getControl().setRedraw(false);
// TODO Calling setInput() and then refresh() causes a
// refreshment of the view twice : setInput() should be
// performed elsewhere.
referencesTree.setInput(selection);
referencesTree.refresh();
referencesTree.expandAll();
} finally {
// done updating the tree - set redraw back to true
referencesTree.getControl().setRedraw(true);
}
return Status.OK_STATUS;
}
};
job.setSystem(true);
return job;
}
}