Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 106935 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 12-16 Link Here
12
 org.eclipse.jdt.core,
12
 org.eclipse.jdt.core,
13
 org.eclipse.contribution.visualiser,
13
 org.eclipse.contribution.visualiser,
14
 org.eclipse.mylar.core,
14
 org.eclipse.mylar.core,
15
 org.eclipse.mylar.java
15
 org.eclipse.mylar.java,
16
 org.eclipse.mylar.tasklist,
17
 org.eclipse.mylar.ui
16
Eclipse-AutoStart: true
18
Eclipse-AutoStart: true
(-)src/org/eclipse/mylar/viz/seesoft/JavaContextContentProvider.java (+280 lines)
Added Link Here
1
package org.eclipse.mylar.viz.seesoft;
2
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
import java.util.List;
6
7
import org.eclipse.contribution.visualiser.VisualiserPlugin;
8
import org.eclipse.contribution.visualiser.core.ProviderManager;
9
import org.eclipse.contribution.visualiser.core.resources.VisualiserImages;
10
import org.eclipse.contribution.visualiser.interfaces.IContentProvider;
11
import org.eclipse.contribution.visualiser.interfaces.IGroup;
12
import org.eclipse.contribution.visualiser.interfaces.IMember;
13
import org.eclipse.contribution.visualiser.jdtImpl.JDTGroup;
14
import org.eclipse.contribution.visualiser.jdtImpl.JDTMember;
15
import org.eclipse.contribution.visualiser.utils.JDTUtils;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.mylar.core.IMylarContext;
20
import org.eclipse.mylar.core.IMylarContextListener;
21
import org.eclipse.mylar.core.IMylarElement;
22
import org.eclipse.mylar.core.MylarPlugin;
23
import org.eclipse.mylar.java.JavaStructureBridge;
24
25
26
/**
27
 * Provides interesting java packages and classes for display in the Visualiser view.
28
 * 
29
 * Note: This currently updates after the interest changes for any context node. 
30
 * If performance is a problem, this could be modified to only update when a 
31
 * landmark is added or removed. 
32
 * 
33
 * @author Wesley Coelho
34
 */
35
public class JavaContextContentProvider implements IContentProvider, IMylarContextListener {
36
37
	/** IGroups representing packages with interesting elements in them */
38
	protected List<JDTGroup> groups = new ArrayList<JDTGroup>();	
39
	
40
	/** True if there is currently an active context */
41
	protected boolean contextActive = false;
42
43
	/** True if the visualiser has set this provider active*/
44
	protected boolean viewActive = false;
45
	
46
	public void initialise(){
47
		MylarPlugin.getContextManager().addListener(this);
48
	}
49
50
	/**
51
	 * Returns all registered groups
52
	 * @see org.eclipse.contribution.visualiser.interfaces.IContentProvider#getAllGroups()
53
	 * @return List of IGroups
54
	 */
55
	public List getAllGroups() {
56
		buildModel();
57
		return groups;
58
	}
59
	
60
	public List getAllMembers(IGroup group) {
61
		return group.getMembers();
62
	}
63
64
	/**
65
	 * Returns the List of all IMembers in all registered groups
66
	 * Adapted from org.eclipse.contribution.visualiser.SimpleContentProvider
67
	 */
68
	public List getAllMembers() {
69
		List grps = getAllGroups();
70
		List<IMember> members = new ArrayList<IMember>();
71
		if (grps == null) return members;
72
		Iterator iter = grps.iterator();
73
		while (iter.hasNext()) {
74
			IGroup grp = (IGroup)iter.next();
75
			List membersInGroup = getAllMembers(grp);
76
			Iterator iter2 = membersInGroup.iterator();
77
			while (iter2.hasNext()) {
78
				IMember im = (IMember)iter2.next();
79
				members.add(im);
80
			}
81
		}
82
		return members;
83
	}
84
	
85
	/** 
86
	 * Constructs the model to be displayed in the visualiser by requesting
87
	 * the active context's interesting elements and converting them to the
88
	 * groups and members structure
89
	 */
90
	protected void buildModel(){
91
		try {
92
			if(!(ProviderManager.getContentProvider().equals(this))){
93
				return;
94
			}
95
96
			groups.clear();
97
		
98
			if (!contextActive || !viewActive){
99
				return;
100
			}
101
			
102
			List<IMylarElement> interestingNodes = MylarPlugin.getContextManager().getActiveContext().getInteresting();
103
			JavaStructureBridge jBridge = new JavaStructureBridge();
104
	
105
			for (int i = 0; i < interestingNodes.size(); i++){
106
				IMylarElement node = interestingNodes.get(i);
107
				
108
				if (node.getContentType().equals(JavaStructureBridge.CONTENT_TYPE)){
109
					String handleID = node.getHandleIdentifier();
110
111
					IJavaElement jElement = (IJavaElement) jBridge.getObjectForHandle(handleID);
112
					
113
					if (jElement.getElementType() == IJavaElement.TYPE){
114
115
						String typeName = jBridge.getName(jElement);
116
						if (typeName.equals("")){
117
							continue;
118
						}
119
						
120
						JDTMember javaType = new JDTMember(typeName, jElement);
121
						addTypeToGroups(javaType);
122
					}
123
				}
124
			}
125
			
126
		} catch (RuntimeException e) {
127
			MylarPlugin.fail(e, "Could not provide data for the visualiser", false);
128
		}
129
	}
130
	
131
	/**
132
	 * Adds the specified visualiser member to the group representing its package
133
	 * in the groups list. The package group is created as required.
134
	 */
135
	protected void addTypeToGroups(JDTMember javaType){
136
		
137
		IJavaElement packageElt = javaType.getResource().getParent();
138
		while (packageElt.getParent() != null){
139
			if (packageElt.getElementType() == IJavaElement.PACKAGE_FRAGMENT){
140
				break;
141
			}
142
			packageElt = packageElt.getParent();
143
		}
144
		
145
		if (packageElt.getElementType() != IJavaElement.PACKAGE_FRAGMENT){
146
			MylarPlugin.fail(new Exception("Could not find package for java element"), "Could not find package for java element", false);
147
			return;
148
		}
149
		
150
		ICompilationUnit compilationUnit = Util.getCompilationUnit(javaType.getResource());
151
		if (compilationUnit == null || !compilationUnit.exists()){
152
			return;
153
		}
154
		
155
		javaType.setSize(Util.getLength(compilationUnit));
156
		
157
		JDTGroup parentGroup = new JDTGroup(packageElt.getElementName());
158
		
159
		//Check for an existing group for this package
160
		for (int i = 0; i < groups.size(); i++){
161
			JDTGroup currGroup = groups.get(i);
162
			
163
			if (currGroup.getFullname().equals(parentGroup.getFullname())){
164
				parentGroup = currGroup;
165
				break;
166
			}
167
		}
168
		
169
		List<IMember> memberList = new ArrayList<IMember>();
170
		memberList.add(javaType);
171
		parentGroup.addMembers(memberList);
172
		
173
		if (!groups.contains(parentGroup)){
174
			groups.add(parentGroup);
175
		}
176
	}
177
	
178
	/**
179
	 * @see org.eclipse.contribution.visualiser.interfaces.IContentProvider#getMemberViewIcon()
180
	 */
181
	public ImageDescriptor getMemberViewIcon() {
182
		return VisualiserImages.CLASS_VIEW;
183
	}
184
185
186
	/**
187
	 * @see org.eclipse.contribution.visualiser.interfaces.IContentProvider#getGroupViewIcon()
188
	 */
189
	public ImageDescriptor getGroupViewIcon() {
190
		return VisualiserImages.PACKAGE_VIEW;
191
	}
192
193
194
	/**
195
	 * Process a mouse click on a member
196
	 * @see org.eclipse.contribution.visualiser.interfaces.IContentProvider#processMouseclick(IMember, boolean, int)
197
	 * Copied from JDTContentProvider
198
	 */
199
	public boolean processMouseclick(
200
		IMember member,
201
		boolean markupWasClicked,
202
		int buttonClicked) {
203
		
204
		if(buttonClicked != 1){
205
			return true;	
206
		}
207
		if(markupWasClicked) {
208
			return false;
209
		}
210
		if(member instanceof JDTMember) {
211
			IJavaElement jEl = ((JDTMember)member).getResource();
212
			if(jEl != null) {
213
				JDTUtils.openInEditor(jEl.getResource(), JDTUtils.getClassDeclLineNum(jEl));
214
			}
215
		}
216
		
217
		return false;
218
	}
219
220
221
	public String getEmptyMessage() {
222
		return "No active context to display.";
223
	}
224
225
	
226
	//Begin implementation of IMylarContextListener
227
	
228
	public void contextActivated(IMylarContext context) {
229
		contextActive = true;
230
		VisualiserPlugin.refresh();
231
	}
232
233
	public void contextDeactivated(IMylarContext context) {
234
		contextActive = false;
235
		VisualiserPlugin.refresh();
236
	}
237
238
	public void presentationSettingsChanging(UpdateKind kind) {
239
240
	}
241
242
	public void presentationSettingsChanged(UpdateKind kind) {
243
		if (kind == UpdateKind.HIGHLIGHTER){
244
			VisualiserPlugin.refresh();
245
		}
246
	}
247
248
	public void interestChanged(IMylarElement node) {
249
250
	}
251
252
	public void interestChanged(List<IMylarElement> nodes) {
253
		VisualiserPlugin.refresh();
254
	}
255
256
	public void nodeDeleted(IMylarElement node) {
257
		VisualiserPlugin.refresh();
258
	}
259
260
	public void landmarkAdded(IMylarElement node) {
261
		VisualiserPlugin.refresh();
262
	}
263
264
	public void landmarkRemoved(IMylarElement node) {
265
		VisualiserPlugin.refresh();
266
	}
267
268
	public void edgesChanged(IMylarElement node) {
269
270
	}
271
272
	public void activate() {
273
		viewActive = true;
274
	}
275
276
	public void deactivate() {
277
		viewActive = false;
278
	}
279
	
280
}
(-)src/org/eclipse/mylar/viz/seesoft/JavaContextMarkupProvider.java (+225 lines)
Added Link Here
1
package org.eclipse.mylar.viz.seesoft;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.SortedSet;
9
import java.util.TreeSet;
10
11
import org.eclipse.contribution.visualiser.core.Stripe;
12
import org.eclipse.contribution.visualiser.interfaces.IGroup;
13
import org.eclipse.contribution.visualiser.interfaces.IMarkupKind;
14
import org.eclipse.contribution.visualiser.interfaces.IMarkupProvider;
15
import org.eclipse.contribution.visualiser.interfaces.IMember;
16
import org.eclipse.contribution.visualiser.jdtImpl.JDTMember;
17
import org.eclipse.contribution.visualiser.simpleImpl.SimpleMarkupKind;
18
import org.eclipse.contribution.visualiser.utils.JDTUtils;
19
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IMethod;
21
import org.eclipse.jdt.core.ISourceReference;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.JavaModelException;
24
import org.eclipse.mylar.core.IDegreeOfInterest;
25
import org.eclipse.mylar.core.IMylarElement;
26
import org.eclipse.mylar.core.MylarPlugin;
27
import org.eclipse.mylar.tasklist.ITask;
28
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
29
import org.eclipse.mylar.ui.internal.UiUtil;
30
import org.eclipse.swt.graphics.Color;
31
import org.eclipse.swt.graphics.RGB;
32
33
/**
34
 * Provides horizontal stripes that represent interesting members
35
 * of a class in the visualiser view
36
 * 
37
 * @author Wesley Coelho
38
 */
39
public class JavaContextMarkupProvider implements IMarkupProvider {
40
41
	/**Assigned when there is no highlight color for a task or it is too light */
42
	public Color defaultStripeColor = new Color(null, new RGB(128,128,255));
43
44
	/**Holds all IMarkupKinds (for the visualiser menu) */
45
	SortedSet<IMarkupKind> markupKindSet = new TreeSet<IMarkupKind>();
46
	
47
	/**Contains the color assigned to a markupkind for a particular task*/
48
	protected Map<IMarkupKind, Color> kindToColorMap = new HashMap<IMarkupKind, Color>();
49
	
50
	/**Records colors that have been explicitly set in the visualiser menu so they are not overridden*/
51
	protected Map<IMarkupKind, Object> colorSetByVisualiserMap = new HashMap<IMarkupKind, Object>();
52
	
53
	public void initialise() {
54
55
	}
56
57
	/**
58
	 * Returns a list of Stripes representing the interesting
59
	 * declarations in the specified IMember where the IMember
60
	 * represents a Java class.
61
	 */
62
	public List getMemberMarkups(IMember member) {
63
		try {
64
			List<Stripe> stripeList = new ArrayList<Stripe>();
65
			IJavaElement classElt = (IJavaElement)((JDTMember)member).getResource();
66
			
67
			if (classElt instanceof IType){
68
				IJavaElement[] classMembers = ((IType)classElt).getChildren();
69
				for(int i = 0; i < classMembers.length; i++){
70
					Stripe memberStripe = makeStripeForJavaMember(classMembers[i]);
71
					if (memberStripe != null){
72
						stripeList.add(memberStripe);
73
					}
74
				}
75
			}
76
			
77
			return stripeList;
78
		} catch (JavaModelException e) {
79
			MylarPlugin.fail(e, "Could not produce markups for member", false);
80
			return new ArrayList<Stripe>();
81
		}
82
	}
83
84
	/**
85
	 * Produces a stripe for the given member with the offset set to
86
	 * the line where the member appears in the file and the 
87
	 * depth set to the number of lines in a method or 1 for fields.
88
	 * Returns null if the member was not interesting or if there 
89
	 * was a problem getting all the required information.
90
	 */
91
	protected Stripe makeStripeForJavaMember(IJavaElement member){
92
		try {
93
			
94
			IMylarElement memberMylarElement = MylarPlugin.getContextManager().getNode(member.getHandleIdentifier());
95
			
96
			if (memberMylarElement != null){
97
				
98
				IDegreeOfInterest degreeOfInterest = memberMylarElement.getDegreeOfInterest();
99
				if(!degreeOfInterest.isInteresting() && !degreeOfInterest.isLandmark()){
100
					return null;
101
				}
102
103
				//Set the depth of the stripe to the number of lines in the member
104
				Stripe stripe = new Stripe();
105
				int stripeDepth = 1;
106
				if (member instanceof IMethod){
107
					stripeDepth = Util.getLength((IMethod)member);
108
				}
109
				stripe.setDepth(stripeDepth);
110
				
111
				//Set the offset to the starting line of the member in the file
112
				int offset = 0;
113
				if (member instanceof ISourceReference){
114
					try {
115
						offset = JDTUtils.getLineNumber(Util.getCompilationUnit(member),  ((ISourceReference)member).getSourceRange().getOffset());
116
					} catch (JavaModelException e) {
117
						MylarPlugin.fail(e, "could not get member line number", false);
118
					}
119
				}
120
				stripe.setOffset(offset);
121
				
122
				//Set the task description
123
				String taskHandle = MylarPlugin.getContextManager().getDominantContextHandleForElement(memberMylarElement);
124
				if (taskHandle == null){
125
					return null;
126
				}
127
				ITask task = MylarTasklistPlugin.getTaskListManager().getTaskForHandle(taskHandle, false);
128
				if (task == null){
129
					return null;
130
				}
131
				IMarkupKind kind = new SimpleMarkupKind(task.getDescription(true));
132
				markupKindSet.add(kind);
133
				
134
				//Set the color
135
				Color kindColor = UiUtil.getBackgroundForElement(memberMylarElement, true);
136
				if (kindColor == null || colorTooLight(kindColor)){
137
					kindColor = defaultStripeColor;
138
				}
139
				if (!colorSetByVisualiserMap.containsKey(kind)){
140
					kindToColorMap.put(kind, kindColor);
141
				}
142
				
143
				List<IMarkupKind> kindList = new ArrayList<IMarkupKind>();
144
				kindList.add(kind);
145
				stripe.setKinds(kindList);
146
				return stripe;
147
			}
148
			
149
			return null;
150
			
151
		} catch (RuntimeException e) {
152
			MylarPlugin.fail(e, "could not get stripe for java member", false);
153
			return null;
154
		}
155
	}
156
	
157
	/** True if the specified stripe color is too light to show up clearly in the visualiser */
158
	protected boolean colorTooLight(Color color){
159
		return (color.getRed() > 225 && color.getGreen() > 225 && color.getBlue() > 200);
160
	}
161
	
162
	
163
	/**
164
	 * Get the markups for a group. Group markups are a stacked set of member markups.
165
	 * Note: copied from org.eclipse.contribution.visualiser.SimpleMarkupProvider
166
	 */
167
	public List getGroupMarkups(IGroup group) {		
168
		List<Stripe> stripes = new ArrayList<Stripe>();
169
		List kids = group.getMembers();
170
		int accumulatedOffset = 0;
171
		
172
		// Go through all the children of the group
173
		for (Iterator iter = kids.iterator(); iter.hasNext();) {
174
			IMember element = (IMember) iter.next();
175
			List l = getMemberMarkups(element);
176
			if (l != null) {
177
				for (Iterator iterator = l.iterator(); iterator.hasNext();) {
178
					Stripe elem = (Stripe) iterator.next();
179
					stripes.add(new Stripe(elem.getKinds(), elem.getOffset() + accumulatedOffset, elem.getDepth()));
180
				}
181
			}
182
			accumulatedOffset += element.getSize().intValue();
183
		}	
184
		return stripes;
185
	}
186
187
	public SortedSet getAllMarkupKinds() {
188
		return markupKindSet;
189
	}
190
191
	public void setColorFor(IMarkupKind kind, Color color) {
192
		kindToColorMap.put(kind, color);
193
		colorSetByVisualiserMap.put(kind, null);
194
	}
195
196
	public Color getColorFor(IMarkupKind kind) {
197
		Color kindColor = kindToColorMap.get(kind);
198
		if (kindColor == null){
199
			kindColor = defaultStripeColor;
200
		}
201
		return kindColor;
202
	}
203
204
	/** Go to the member represented by the clicked stripe */
205
	public boolean processMouseclick(IMember member, Stripe stripe, int buttonClicked) {
206
		if(buttonClicked != 1){
207
			return false;	
208
		}
209
		
210
		if(member instanceof JDTMember) {
211
			IJavaElement javaElement = ((JDTMember)member).getResource();
212
			if(javaElement != null) {
213
				JDTUtils.openInEditor(javaElement.getResource(), JDTUtils.getClassDeclLineNum(javaElement) + stripe.getOffset());
214
			}
215
		}
216
		
217
		return false;
218
	}
219
220
	public void activate() {
221
	}
222
223
	public void deactivate() {
224
	}
225
}

Return to bug 106935