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 182506
Collapse All | Expand All

(-)src/org/eclipse/mylar/java/tests/xml/XmlSearchPluginTest.java (-1 / +1 lines)
Lines 25-33 Link Here
25
import org.eclipse.mylar.internal.context.core.CompositeContext;
25
import org.eclipse.mylar.internal.context.core.CompositeContext;
26
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
26
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
27
import org.eclipse.mylar.internal.context.core.MylarContext;
27
import org.eclipse.mylar.internal.context.core.MylarContext;
28
import org.eclipse.mylar.internal.ide.xml.pde.PdeStructureBridge;
29
import org.eclipse.mylar.internal.java.JavaStructureBridge;
28
import org.eclipse.mylar.internal.java.JavaStructureBridge;
30
import org.eclipse.mylar.internal.java.search.XmlJavaRelationProvider;
29
import org.eclipse.mylar.internal.java.search.XmlJavaRelationProvider;
30
import org.eclipse.mylar.internal.pde.PdeStructureBridge;
31
import org.eclipse.mylar.internal.resources.ResourceStructureBridge;
31
import org.eclipse.mylar.internal.resources.ResourceStructureBridge;
32
import org.eclipse.mylar.java.tests.search.ActiveSearchNotifier;
32
import org.eclipse.mylar.java.tests.search.ActiveSearchNotifier;
33
import org.eclipse.mylar.java.tests.search.SearchPluginTestHelper;
33
import org.eclipse.mylar.java.tests.search.SearchPluginTestHelper;
(-)src/org/eclipse/mylar/java/tests/xml/XmlTestActiveSearchListener.java (-1 / +1 lines)
Lines 14-22 Link Here
14
import java.util.List;
14
import java.util.List;
15
15
16
import org.eclipse.core.internal.resources.File;
16
import org.eclipse.core.internal.resources.File;
17
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
17
import org.eclipse.mylar.context.core.AbstractRelationProvider;
18
import org.eclipse.mylar.context.core.AbstractRelationProvider;
18
import org.eclipse.mylar.context.core.ContextCorePlugin;
19
import org.eclipse.mylar.context.core.ContextCorePlugin;
19
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
20
import org.eclipse.mylar.context.tests.support.search.TestActiveSearchListener;
20
import org.eclipse.mylar.context.tests.support.search.TestActiveSearchListener;
21
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
21
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
22
import org.eclipse.search.internal.ui.text.FileSearchResult;
22
import org.eclipse.search.internal.ui.text.FileSearchResult;
(-)src/org/eclipse/mylar/java/tests/xml/XmlResultUpdaterSearchListener.java (-2 / +2 lines)
Lines 16-29 Link Here
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.core.internal.resources.File;
18
import org.eclipse.core.internal.resources.File;
19
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
19
import org.eclipse.mylar.context.core.AbstractRelationProvider;
20
import org.eclipse.mylar.context.core.AbstractRelationProvider;
20
import org.eclipse.mylar.context.core.ContextCorePlugin;
21
import org.eclipse.mylar.context.core.ContextCorePlugin;
21
import org.eclipse.mylar.context.core.IMylarElement;
22
import org.eclipse.mylar.context.core.IMylarElement;
22
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
23
import org.eclipse.mylar.context.tests.support.search.TestActiveSearchListener;
23
import org.eclipse.mylar.context.tests.support.search.TestActiveSearchListener;
24
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
24
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
25
import org.eclipse.mylar.internal.ide.xml.pde.PdeStructureBridge;
26
import org.eclipse.mylar.internal.java.search.XmlJavaRelationProvider;
25
import org.eclipse.mylar.internal.java.search.XmlJavaRelationProvider;
26
import org.eclipse.mylar.internal.pde.PdeStructureBridge;
27
import org.eclipse.mylar.monitor.core.InteractionEvent;
27
import org.eclipse.mylar.monitor.core.InteractionEvent;
28
import org.eclipse.search.internal.ui.text.FileSearchResult;
28
import org.eclipse.search.internal.ui.text.FileSearchResult;
29
import org.eclipse.search.ui.text.Match;
29
import org.eclipse.search.ui.text.Match;
(-)src/org/eclipse/mylar/java/tests/search/JavaReferencesSearchTest.java (-1 / +1 lines)
Lines 27-35 Link Here
27
import org.eclipse.mylar.internal.context.core.CompositeContext;
27
import org.eclipse.mylar.internal.context.core.CompositeContext;
28
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
28
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
29
import org.eclipse.mylar.internal.context.core.MylarContext;
29
import org.eclipse.mylar.internal.context.core.MylarContext;
30
import org.eclipse.mylar.internal.ide.xml.pde.PdeStructureBridge;
31
import org.eclipse.mylar.internal.java.JavaStructureBridge;
30
import org.eclipse.mylar.internal.java.JavaStructureBridge;
32
import org.eclipse.mylar.internal.java.search.JavaReferencesProvider;
31
import org.eclipse.mylar.internal.java.search.JavaReferencesProvider;
32
import org.eclipse.mylar.internal.pde.PdeStructureBridge;
33
33
34
/**
34
/**
35
 * @author Shawn Minto
35
 * @author Shawn Minto
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 34-40 Link Here
34
 org.eclipse.mylar.monitor.ui,
34
 org.eclipse.mylar.monitor.ui,
35
 org.eclipse.search,
35
 org.eclipse.search,
36
 org.eclipse.mylar.resources.tests,
36
 org.eclipse.mylar.resources.tests,
37
 org.eclipse.mylar.monitor.core
37
 org.eclipse.mylar.monitor.core,
38
 org.eclipse.mylar.pde,
39
 org.eclipse.mylar.ant
38
Eclipse-AutoStart: true
40
Eclipse-AutoStart: true
39
Bundle-ClassPath: mylar-java-tests.jar
41
Bundle-ClassPath: mylar-java-tests.jar
40
Export-Package: org.eclipse.mylar.java.tests,
42
Export-Package: org.eclipse.mylar.java.tests,
(-)src/org/eclipse/mylar/internal/ide/xml/pde/PdeStructureBridge.java (-340 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.ide.xml.pde;
13
14
import java.util.Collections;
15
import java.util.List;
16
17
import org.eclipse.core.internal.resources.File;
18
import org.eclipse.core.internal.resources.Workspace;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.jface.text.Document;
25
import org.eclipse.jface.text.IDocument;
26
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
27
import org.eclipse.mylar.context.core.ContextCorePlugin;
28
import org.eclipse.mylar.context.core.IMylarElement;
29
import org.eclipse.mylar.core.MylarStatusHandler;
30
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
31
import org.eclipse.pde.internal.core.text.build.BuildEntry;
32
import org.eclipse.pde.internal.core.text.plugin.PluginNode;
33
import org.eclipse.pde.internal.core.text.plugin.PluginObjectNode;
34
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
35
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
36
import org.eclipse.ui.IEditorPart;
37
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.views.markers.internal.ProblemMarker;
39
40
/**
41
 * @author Mik Kersten
42
 * 
43
 */
44
public class PdeStructureBridge extends AbstractContextStructureBridge {
45
46
	public final static String CONTENT_TYPE = "plugin.xml";
47
48
	@Override
49
	public String getContentType() {
50
		return CONTENT_TYPE;
51
	}
52
53
	@Override
54
	public String getContentType(String elementHandle) {
55
		if (elementHandle.endsWith(".xml")) {
56
			return parentContentType;
57
//			return parentBridge.getContentType();
58
		} else {
59
			return CONTENT_TYPE;
60
		}
61
	}
62
63
	@Override
64
	public List<String> getChildHandles(String handle) {
65
		return Collections.emptyList();
66
	}
67
68
	@Override
69
	public String getParentHandle(String handle) {
70
		// we can only get the parent if we have a PluginObjectNode
71
72
		Object object = getObjectForHandle(handle);
73
		if (object instanceof PluginObjectNode) {
74
			PluginObjectNode parent = (PluginObjectNode) ((PluginObjectNode) object).getParentNode();
75
			if (parent != null) {
76
				return getHandleIdentifier(parent);
77
			} else {
78
				// the parent is the plugin.xml file, so return that handle
79
				int delimeterIndex = handle.indexOf(";");
80
				if (delimeterIndex != -1) {
81
					String parentHandle = handle.substring(0, delimeterIndex);
82
					return parentHandle;
83
				} else {
84
					return null;
85
				}
86
			}
87
		} else if (object instanceof PluginNode) {
88
			PluginNode parent = (PluginNode) ((PluginNode) object).getParentNode();
89
			if (parent != null) {
90
				return getHandleIdentifier(parent);
91
			} else {
92
				// the parent is the plugin.xml file, so return that handle
93
				int delimeterIndex = handle.indexOf(";");
94
				if (delimeterIndex != -1) {
95
					String parentHandle = handle.substring(0, delimeterIndex);
96
					return parentHandle;
97
				} else {
98
					return null;
99
				}
100
			}
101
		} else if (object instanceof IFile) {
102
			// String fileHandle = parentBridge.getParentHandle(handle);
103
			AbstractContextStructureBridge parentBridge = ContextCorePlugin.getDefault().getStructureBridge(parentContentType);
104
			return parentBridge.getParentHandle(handle);
105
		} else {
106
			return null;
107
		}
108
	}
109
110
	/**
111
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getObjectForHandle(java.lang.String)
112
	 */
113
	@Override
114
	public Object getObjectForHandle(String handle) {
115
		if (handle == null)
116
			return null;
117
		int first = handle.indexOf(";");
118
		String filename = "";
119
		if (first == -1) {
120
			AbstractContextStructureBridge parentBridge = ContextCorePlugin.getDefault().getStructureBridge(parentContentType);
121
			return parentBridge.getObjectForHandle(handle);
122
		} else {
123
			// extract the filename from the handle since it represents a node
124
			filename = handle.substring(0, first);
125
		}
126
127
		try {
128
			// get the file and create a FileEditorInput
129
			IPath path = new Path(filename);
130
			IFile f = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
131
132
			// get the start line for the element
133
			int start = Integer.parseInt(handle.substring(first + 1));
134
135
			// // get the content and the document so that we can get the offset
136
			// String content = XmlNodeHelper.getContents(f.getContents());
137
			// IDocument d = new Document(content);
138
139
			// get the offsets for the element
140
			// make sure that we are on a character and not whitespace
141
			// int offset = d.getLineOffset(start);
142
			// while(d.getChar(offset) == ' ')
143
			// offset++;
144
145
			// get the current editor which should be the ManifestEditor so that
146
			// we can get the element that we want
147
			IEditorPart editorPart = null;
148
			try {
149
				editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
150
			} catch (NullPointerException e) {
151
				// do nothing, this just means that there is no active page
152
			}
153
			if (editorPart != null && editorPart instanceof ManifestEditor) {
154
				PluginObjectNode node = PdeEditingMonitor.getNode((ManifestEditor) editorPart, start, true);
155
				// get the element based on the offset
156
				return node;
157
			} else {
158
				String content = XmlNodeHelper.getContents(f.getContents());
159
				IDocument d = new Document(content);
160
				PluginObjectNode node = PdeEditingMonitor.getNode(d, f, start, true);
161
				return node;
162
			}
163
		} catch (Exception e) {
164
			// ignore, means file doesn't exist
165
			// ContextCorePlugin.log(e, "handle failed");
166
		}
167
		return null;
168
	}
169
170
	/**
171
	 * Handle is filename;hashcodeOfElementAndAttributes
172
	 * 
173
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getHandleIdentifier(java.lang.Object)
174
	 */
175
	@Override
176
	public String getHandleIdentifier(Object object) {
177
		// we can only create handles for PluginObjectNodes and plugin.xml files
178
		if (object instanceof XmlNodeHelper) {
179
			return ((XmlNodeHelper) object).getHandle();
180
		} else if (object instanceof PluginObjectNode) {
181
			PluginObjectNode node = (PluginObjectNode) object;
182
			try {
183
				// get the handle for the PluginObjectNode
184
				if (node.getModel() == null || node.getModel().getUnderlyingResource() == null
185
						|| node.getModel().getUnderlyingResource().getFullPath() == null) {
186
					// ContextCorePlugin.log("PDE xml node's resource or model is
187
					// null: " + node.getName(), this);
188
					return null;
189
				}
190
				IPath path = new Path(node.getModel().getUnderlyingResource().getFullPath().toString());
191
				IFile file = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
192
				String handle = new XmlNodeHelper(file.getFullPath().toString(), PdeEditingMonitor
193
						.getStringOfNode(node).hashCode()).getHandle();
194
				return handle;
195
			} catch (Exception e) {
196
				MylarStatusHandler.log(e, "pde handle failed");
197
			}
198
		} else if (object instanceof PluginNode) {
199
			PluginNode node = (PluginNode) object;
200
			try {
201
				if (node.getModel() == null || node.getModel().getUnderlyingResource() == null
202
						|| node.getModel().getUnderlyingResource().getFullPath() == null) {
203
					// ContextCorePlugin.log("PDE xml node's resource or model is
204
					// null: " + node.getName(), this);
205
					return null;
206
				}
207
				IPath path = new Path(node.getModel().getUnderlyingResource().getFullPath().toString());
208
				IFile file = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
209
				String handle = new XmlNodeHelper(file.getFullPath().toString(), PdeEditingMonitor
210
						.getStringOfNode(node).hashCode()).getHandle();
211
				return handle;
212
			} catch (Exception e) {
213
				MylarStatusHandler.log(e, "pde handle failed");
214
			}
215
216
		} else if (object instanceof File) {
217
			// get the handle for the file if it is plugin.xml
218
			File file = (File) object;
219
			if (file.getFullPath().toString().endsWith("plugin.xml"))
220
				return file.getFullPath().toString();
221
		}
222
		return null;
223
	}
224
225
	@Override
226
	public String getName(Object object) {
227
		if (object instanceof PluginObjectNode) {
228
			PluginObjectNode node = (PluginObjectNode) object;
229
			String name = node.getXMLAttributeValue("name");
230
			if (name == null)
231
				name = node.getXMLTagName();
232
			name = node.getModel().getUnderlyingResource().getName() + ": " + name;
233
			return name;
234
		} else if (object instanceof File) {
235
			File file = (File) object;
236
			if (file.getFullPath().toString().endsWith("plugin.xml"))
237
				return "plugin.xml";
238
		}
239
		return "";
240
	}
241
242
	/**
243
	 * TODO: make a non-handle based test
244
	 */
245
	@Override
246
	public boolean canBeLandmark(String handle) {
247
		if (handle == null) {
248
			return false;
249
		} else {
250
			return handle.indexOf(';') == -1;
251
		}
252
	}
253
254
	@Override
255
	public boolean acceptsObject(Object object) {
256
		// we only accept PluginObjectNodes and plugin.xml Files
257
		if (object instanceof PluginNode || object instanceof PluginObjectNode || object instanceof BuildEntry || object instanceof PDEFormPage) {
258
			return true;
259
		} else if (object instanceof XmlNodeHelper) {
260
			if (((XmlNodeHelper) object).getFilename().endsWith("plugin.xml"))
261
				return true;
262
		} else if (object instanceof File) {
263
			File file = (File) object;
264
			if (file.getFullPath().toString().endsWith("plugin.xml"))
265
				return true;
266
		}
267
		return false;
268
	}
269
270
	@Override
271
	public boolean canFilter(Object element) {
272
		return true;
273
	}
274
275
	@Override
276
	public boolean isDocument(String handle) {
277
		return handle.indexOf(';') == -1;
278
	}
279
280
	@Override
281
	public String getHandleForOffsetInObject(Object resource, int offset) {
282
		if (resource == null)
283
			return null;
284
		if (resource instanceof ProblemMarker) {
285
			ProblemMarker marker = (ProblemMarker) resource;
286
287
			// we can only get a handle for a marker with the resource
288
			// plugin.xml
289
			try {
290
				IResource res = marker.getResource();
291
292
				if (res instanceof IFile) {
293
					IFile file = (IFile) res;
294
					if (file.getFullPath().toString().endsWith("plugin.xml")) {
295
						return file.getFullPath().toString();
296
					} else {
297
						return null;
298
					}
299
				}
300
				return null;
301
			} catch (Throwable t) {
302
				MylarStatusHandler.log(t, "Could not find element for: " + marker);
303
				return null;
304
			}
305
		} else if (resource instanceof IFile) {
306
			try {
307
				IFile file = (IFile) resource;
308
				if (file.getFullPath().toString().endsWith("plugin.xml")) {
309
					String content = XmlNodeHelper.getContents(file.getContents());
310
					IDocument d = new Document(content);
311
					PluginObjectNode node = PdeEditingMonitor.getNode(d, file, offset, false);
312
					String handle = new XmlNodeHelper(file.getFullPath().toString(), PdeEditingMonitor.getStringOfNode(
313
							node).hashCode()).getHandle();
314
					return handle;
315
				}
316
			} catch (Exception e) {
317
				MylarStatusHandler.log(e, "Unable to get handle for offset in object");
318
			}
319
		}
320
		return null;
321
	}
322
323
//	public IProject getProjectForObject(Object object) {
324
//		while (!(object instanceof IFile)) {
325
//			String handle = getParentHandle(getHandleIdentifier(object));
326
//			if (handle == null)
327
//				break;
328
//			object = getObjectForHandle(handle);
329
//		}
330
//		if (object instanceof IFile && acceptsObject(object)) {
331
//			return ((IFile) object).getProject();
332
//		}
333
//		return null;
334
//	}
335
336
	public boolean containsProblem(IMylarElement node) {
337
		// TODO Auto-generated method stub
338
		return false;
339
	}
340
}
(-)src/org/eclipse/mylar/internal/ide/xml/pde/PdeContextLabelProvider.java (-61 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.ide.xml.pde;
13
14
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
15
import org.eclipse.mylar.context.core.ContextCorePlugin;
16
import org.eclipse.mylar.context.core.IMylarElement;
17
import org.eclipse.mylar.context.core.IMylarRelation;
18
import org.eclipse.mylar.internal.context.ui.AbstractContextLabelProvider;
19
import org.eclipse.mylar.internal.context.ui.ContextUiImages;
20
import org.eclipse.mylar.internal.ide.MylarIdePlugin;
21
import org.eclipse.swt.graphics.Image;
22
23
/**
24
 * @author Mik Kersten
25
 */
26
public class PdeContextLabelProvider extends AbstractContextLabelProvider {
27
28
	public static final String LABEL_RELATION = "referenced by";
29
	
30
	@Override
31
	protected Image getImage(IMylarElement node) {
32
		return ContextUiImages.getImage(ContextUiImages.FILE_XML);
33
	}
34
35
	@Override
36
	protected Image getImage(IMylarRelation edge) {
37
		return ContextUiImages.getImage(MylarIdePlugin.EDGE_REF_XML);
38
	}
39
40
	@Override
41
	protected String getText(IMylarElement node) {
42
		AbstractContextStructureBridge bridge = ContextCorePlugin.getDefault().getStructureBridge(PdeStructureBridge.CONTENT_TYPE);
43
		return bridge.getName(bridge.getObjectForHandle(node.getHandleIdentifier()));
44
	}
45
46
	@Override
47
	protected String getText(IMylarRelation edge) {
48
		return LABEL_RELATION;
49
	}
50
51
	@Override
52
	protected Image getImageForObject(Object object) {
53
		return ContextUiImages.getImage(ContextUiImages.FILE_XML);
54
	}
55
56
	@Override
57
	protected String getTextForObject(Object object) {
58
		AbstractContextStructureBridge bridge = ContextCorePlugin.getDefault().getStructureBridge(PdeStructureBridge.CONTENT_TYPE);
59
		return bridge.getName(object);
60
	}
61
}
(-)src/org/eclipse/mylar/internal/ide/xml/pde/PdeEditingMonitor.java (-267 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Apr 1, 2005
13
 */
14
package org.eclipse.mylar.internal.ide.xml.pde;
15
16
import java.util.Locale;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.jface.text.IDocument;
21
import org.eclipse.jface.text.TextSelection;
22
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.StructuredSelection;
24
import org.eclipse.mylar.core.MylarStatusHandler;
25
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
26
import org.eclipse.mylar.monitor.ui.AbstractUserInteractionMonitor;
27
import org.eclipse.pde.core.plugin.IPluginModelBase;
28
import org.eclipse.pde.core.plugin.IPluginObject;
29
import org.eclipse.pde.internal.core.plugin.ImportObject;
30
import org.eclipse.pde.internal.core.text.IDocumentAttribute;
31
import org.eclipse.pde.internal.core.text.IDocumentNode;
32
import org.eclipse.pde.internal.core.text.plugin.PluginModel;
33
import org.eclipse.pde.internal.core.text.plugin.PluginObjectNode;
34
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
35
import org.eclipse.pde.internal.ui.editor.plugin.ManifestSourcePage;
36
import org.eclipse.ui.IEditorInput;
37
import org.eclipse.ui.IWorkbenchPart;
38
import org.eclipse.ui.part.FileEditorInput;
39
40
public class PdeEditingMonitor extends AbstractUserInteractionMonitor {
41
42
	public PdeEditingMonitor() {
43
		super();
44
	}
45
46
	@Override
47
	protected void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) {
48
		if (part instanceof ManifestEditor) {
49
			TextSelection textSelection = null;
50
			IEditorInput in = null;
51
52
			// assume that we are editing an xml file due to the editor used
53
			// this is the plugin.xml editor
54
55
			ManifestEditor editor = (ManifestEditor) part;
56
57
			// fix bug when user is looking in the cvs repository since the
58
			// input
59
			// is not a FileEditorInput
60
			if (!(editor.getEditorInput() instanceof FileEditorInput))
61
				return;
62
63
			// make sure that the selection is a text selection
64
			if (!(editor.getSelection() instanceof TextSelection || editor.getSelection() instanceof StructuredSelection)) {
65
				return;
66
			} else if (editor.getSelection() instanceof StructuredSelection) {
67
				StructuredSelection s = (StructuredSelection) editor.getSelection();
68
				if (s.getFirstElement() instanceof PluginObjectNode) {
69
					PluginObjectNode n = (PluginObjectNode) s.getFirstElement();
70
					textSelection = new TextSelection(n.getOffset(), n.getLength());
71
				} else if (s.getFirstElement() instanceof ImportObject) {
72
					ImportObject io = (ImportObject) s.getFirstElement();
73
					if (io.getImport() instanceof PluginObjectNode) {
74
						PluginObjectNode n = (PluginObjectNode) io.getImport();
75
						textSelection = new TextSelection(n.getOffset(), n.getLength());
76
					}
77
				} else {
78
					return;
79
				}
80
			} else {
81
				// get the selection and the editor input
82
				textSelection = (TextSelection) editor.getSelection();
83
			}
84
			in = editor.getEditorInput();
85
86
			// check if we have a text selection
87
			if (textSelection != null) {
88
				try {
89
90
					// get the node for the selection
91
					int offset = textSelection.getOffset();
92
					PluginObjectNode node = getNode(editor, offset, false);
93
94
					if (node != null) {
95
						FileEditorInput fei = (FileEditorInput) in;
96
97
						// fix a bug when there is a selection and the editor
98
						// input is the manifest.mf file
99
						// not the plugin.xml
100
						if (fei.getFile().getFullPath().toString().toLowerCase(Locale.ENGLISH).endsWith("/manifest.mf")) {
101
							return;
102
						}
103
104
						String nodeString = getStringOfNode(node);
105
						if (nodeString == null)
106
							return;
107
108
						// create the helper to get the handle for the node
109
						XmlNodeHelper xnode = new XmlNodeHelper(fei.getFile().getFullPath().toString(), nodeString
110
								.hashCode());
111
112
						// get the name for the node
113
//						String name = node.getXMLAttributeValue("name");
114
//						if (name == null)
115
//							name = node.getXMLTagName();
116
						super.handleElementSelection(part, xnode, contributeToContext);
117
					}
118
				} catch (Exception e) {
119
					MylarStatusHandler.log(e, "couldn't resolve selection");
120
				}
121
			}
122
		}
123
	}
124
125
	public static String getStringOfNode(IDocumentNode node) {
126
		if (node == null)
127
			return null;
128
		String s = node.getXMLTagName();
129
		for (IDocumentAttribute a : node.getNodeAttributes()) {
130
			s += a.getAttributeName() + "=" + a.getAttributeValue();
131
		}
132
		return s;
133
	}
134
135
	/**
136
	 * COPIED FROM ManifestSourcePage - from a getRangeElement body
137
	 */
138
	public static PluginObjectNode getNode(ManifestEditor editor, int offset, boolean hashCode) {
139
		ManifestSourcePage page = (ManifestSourcePage) editor.findPage("plugin-context");
140
		if (page != null) {
141
			IPluginModelBase model = (IPluginModelBase) page.getInputContext().getModel();
142
			PluginObjectNode node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getLibraries(),
143
					offset, hashCode);
144
			if (node == null)
145
				node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getImports(), offset,
146
						hashCode);
147
			if (node == null)
148
				node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getExtensionPoints(),
149
						offset, hashCode);
150
			if (node == null)
151
				node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getExtensions(), offset,
152
						hashCode);
153
			if (node == null) {
154
				node = (PluginObjectNode) PdeEditingMonitor.findNode(new IPluginObject[] { model.getPluginBase() },
155
						offset, hashCode);
156
			}
157
			return node;
158
		}
159
		return null;
160
	}
161
162
	public static PluginObjectNode getNode(IDocument d, IFile f, int num, boolean hashCode) throws CoreException {
163
		PluginModel model = new PluginModel(d, true);
164
		model.setUnderlyingResource(f);
165
		if (!model.isLoaded()) {
166
			model.load();
167
			model.setEnabled(true);
168
		}
169
170
		PluginObjectNode node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getLibraries(),
171
				num, hashCode);
172
		if (node == null)
173
			node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getImports(), num, hashCode);
174
		if (node == null)
175
			node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getExtensionPoints(), num,
176
					hashCode);
177
		if (node == null)
178
			node = (PluginObjectNode) PdeEditingMonitor.findNode(model.getPluginBase().getExtensions(), num, hashCode);
179
		if (node == null) {
180
			node = (PluginObjectNode) PdeEditingMonitor.findNode(new IPluginObject[] { model.getPluginBase() }, num,
181
					hashCode);
182
		}
183
		return node;
184
	}
185
186
	/**
187
	 * COPIED FROM ManifestSourcePage
188
	 */
189
	private static IDocumentNode findNode(IPluginObject[] nodes, int offset, boolean hashCode) {
190
		for (int i = 0; i < nodes.length; i++) {
191
			IDocumentNode node = (IDocumentNode) nodes[i];
192
			IDocumentNode[] children = node.getChildNodes();
193
194
			// changed region - added to check the children to make it work
195
			// properly
196
			IDocumentNode node2 = null;
197
			if (children.length > 0)
198
				node2 = PdeEditingMonitor.findNode(children, offset, hashCode);
199
			// end changed region
200
201
			if (node2 != null && node2 instanceof IPluginObject)
202
				return node2;
203
204
			if (!hashCode) {
205
				if (offset >= node.getOffset() && offset < node.getOffset() + node.getLength()) {
206
					return node;
207
				}
208
			} else {
209
				if (getStringOfNode(node).hashCode() == offset)
210
					return node;
211
			}
212
		}
213
		return null;
214
	}
215
216
	/**
217
	 * Copy of previous, taking different arguments
218
	 */
219
	private static IDocumentNode findNode(IDocumentNode[] nodes, int offset, boolean hashCode) {
220
		for (int i = 0; i < nodes.length; i++) {
221
			IDocumentNode node = nodes[i];
222
			IDocumentNode[] children = node.getChildNodes();
223
			IDocumentNode node2 = null;
224
			if (children.length > 0)
225
				node2 = PdeEditingMonitor.findNode(children, offset, hashCode);
226
			if (node2 != null)
227
				return node2;
228
229
			if (!hashCode) {
230
				if (offset >= node.getOffset() && offset < node.getOffset() + node.getLength()) {
231
					return node;
232
				}
233
			} else {
234
				if (getStringOfNode(node).hashCode() == offset)
235
					return node;
236
			}
237
		}
238
		return null;
239
	}
240
}
241
242
// XXX used if we support the xmen editor
243
// if (part instanceof XMLTextEditor) {
244
// XMLTextEditor editor = (XMLTextEditor)part;
245
// TextSelection textSelection =
246
// (TextSelection)editor.getSelectionProvider().getSelection();
247
// if (textSelection != null) {
248
//
249
// try{
250
// // get the model for the xml elements
251
// XMLReconciler rec = editor.getModel();
252
//                    
253
// int start = textSelection.getStartLine();
254
// int end = textSelection.getEndLine();
255
//                    
256
// // get the node that was selected
257
// XMLNode node = rec.getNodeFromLine(start);
258
//                    
259
// ContextCorePlugin.getTaskscapeManager().handleElementSelected(
260
// node.getHandle(), node.getCanName(),
261
// IDegreeOfInterest.Value.Selections,
262
// ITaskscapeNode.Kind.XML);
263
//                              
264
// }catch(Exception e){
265
// //handle properly
266
// }
267
// }
(-)src/org/eclipse/mylar/internal/ide/xml/pde/PdeUiBridge.java (-328 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Apr 6, 2005
13
 */
14
package org.eclipse.mylar.internal.ide.xml.pde;
15
16
import java.lang.reflect.Field;
17
import java.util.ArrayList;
18
import java.util.Collections;
19
import java.util.List;
20
21
import org.eclipse.core.internal.resources.Workspace;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.jface.text.TextSelection;
28
import org.eclipse.jface.viewers.ISelectionChangedListener;
29
import org.eclipse.jface.viewers.ITreeViewerListener;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
31
import org.eclipse.jface.viewers.TreeExpansionEvent;
32
import org.eclipse.jface.viewers.TreeViewer;
33
import org.eclipse.mylar.context.core.IMylarElement;
34
import org.eclipse.mylar.context.ui.AbstractContextUiBridge;
35
import org.eclipse.mylar.core.MylarStatusHandler;
36
import org.eclipse.mylar.resources.MylarResourcesPlugin;
37
import org.eclipse.pde.internal.core.text.plugin.PluginObjectNode;
38
import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
39
import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
40
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
41
import org.eclipse.pde.internal.ui.editor.PDESourcePage;
42
import org.eclipse.pde.internal.ui.editor.SourceOutlinePage;
43
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
44
import org.eclipse.pde.internal.ui.editor.plugin.PluginInputContext;
45
import org.eclipse.ui.IEditorInput;
46
import org.eclipse.ui.IEditorPart;
47
import org.eclipse.ui.IEditorReference;
48
import org.eclipse.ui.IWorkbenchPage;
49
import org.eclipse.ui.PartInitException;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.forms.editor.FormEditor;
52
import org.eclipse.ui.ide.IDE;
53
import org.eclipse.ui.texteditor.AbstractTextEditor;
54
55
/**
56
 * @author Mik Kersten
57
 * @author Shawn Minto
58
 */
59
public class PdeUiBridge extends AbstractContextUiBridge {
60
	
61
	private TreeViewerListener treeSelectionChangedListener;
62
63
	public PdeUiBridge() {
64
		treeSelectionChangedListener = new TreeViewerListener();
65
	}
66
67
	/**
68
	 * @see org.eclipse.mylar.context.ui.AbstractContextUiBridge#open(org.eclipse.mylar.context.core.IMylarElement)
69
	 */
70
	@Override
71
	public void open(IMylarElement node) {
72
		// get the handle of the node
73
		String handle = node.getHandleIdentifier();
74
75
		int first = handle.indexOf(";");
76
		String filename = "";
77
		if (first == -1)
78
			filename = handle;
79
		else
80
			filename = handle.substring(0, first);
81
82
		try {
83
			// get the file
84
			IPath path = new Path(filename);
85
			IFile f = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
86
87
			// open the xml file looking at the proper line
88
			IEditorPart editor = openInEditor(f, true);
89
90
			// if the editor is null, we had a problem and should return
91
			if (editor == null) {
92
				MylarStatusHandler.log("Unable to open editor for file: " + filename, this);
93
				return;
94
			}
95
96
			// get the contents and create a new document so that we can get
97
			// the offsets to highlight
98
			// String content = XmlNodeHelper.getContents(f.getContents());
99
			//            
100
			// IDocument d = new Document(content);
101
102
			// if(first != -1){
103
			// int start = Integer.parseInt(handle.substring(first + 1));
104
			//                
105
			// // get the offsets for the element
106
			// int startOffset = d.getLineOffset(start);
107
			// int length = 0;
108
			//                
109
			// // set the selection if the selection provider is not null
110
			// ISelectionProvider selectionProvider =
111
			// editor.getEditorSite().getSelectionProvider();
112
			// if(selectionProvider != null)
113
			// selectionProvider.setSelection(new TextSelection(startOffset,
114
			// length));
115
			// }
116
117
		} catch (Exception e) {
118
			// ContextCorePlugin.log(e, "ERROR OPENING XML EDITOR\n" +
119
			// e.getMessage());
120
		}
121
	}
122
123
	/**
124
	 * Open a file in the appropriate editor
125
	 * 
126
	 * @param file
127
	 *            The IFile to open
128
	 * @param activate
129
	 *            Whether to activate the editor or not
130
	 * @return The IEditorPart that the file opened in
131
	 * @throws PartInitException
132
	 */
133
	private IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {
134
		if (file != null) {
135
			IWorkbenchPage p = MylarResourcesPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
136
			if (p != null && file.exists()) {
137
				IEditorPart editorPart = IDE.openEditor(p, file, activate);
138
				// initializeHighlightRange(editorPart);
139
				return editorPart;
140
			}
141
		}
142
		return null;
143
	}
144
145
	@Override
146
	public void close(IMylarElement node) {
147
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
148
		if (page != null) {
149
			IEditorReference[] references = page.getEditorReferences();
150
			for (int i = 0; i < references.length; i++) {
151
				IEditorPart part = references[i].getEditor(false);
152
				if (part != null) {
153
					// HACK find better way to get the filename other than the
154
					// tooltip
155
					if (("/" + part.getTitleToolTip()).equals(node.getHandleIdentifier())) {
156
						if (part instanceof FormEditor) {
157
							((FormEditor) part).close(true);
158
						} else if (part instanceof AbstractTextEditor) {
159
							((AbstractTextEditor) part).close(true);
160
						}
161
					}
162
					// if (part.getEditorInput() instanceof IFileEditorInput) {
163
					// IFileEditorInput input =
164
					// (IFileEditorInput)part.getEditorInput();
165
					// if (input.getFile().getName().endsWith(".xml")) {
166
					// if (part instanceof FormEditor) {
167
					// ((FormEditor)part).close(true);
168
					// } else if (part instanceof AbstractTextEditor) {
169
					// ((AbstractTextEditor)part).close(true);
170
					// }
171
					// }
172
					// }
173
				}
174
			}
175
		}
176
	}
177
178
	@Override
179
	public boolean acceptsEditor(IEditorPart editorPart) {
180
		return editorPart instanceof ManifestEditor;
181
	}
182
183
	/**
184
	 * HACK: use a lot of reflection to get the TreeViewer
185
	 */
186
	@Override
187
	public List<TreeViewer> getContentOutlineViewers(IEditorPart editor) {
188
		if (editor instanceof PDEFormEditor) {
189
			PDESourcePage sp = null;
190
			List<TreeViewer> viewers = new ArrayList<TreeViewer>(2);
191
			if ((sp = (PDESourcePage) ((PDEFormEditor) editor).findPage(PluginInputContext.CONTEXT_ID)) != null) {
192
				ISortableContentOutlinePage p = sp.getContentOutline();
193
				if (p != null && p.getControl() != null) {
194
					try {
195
						if (p != null && p instanceof SourceOutlinePage) {
196
							// get the tree viewer for the outline
197
							Class<?> clazz2 = p.getClass();
198
							Field field2 = clazz2.getDeclaredField("viewer");
199
							field2.setAccessible(true);
200
							Object f2 = field2.get(p);
201
							if (f2 != null && f2 instanceof TreeViewer) {
202
								viewers.add((TreeViewer) f2);
203
							}
204
						}
205
					} catch (Exception e) {
206
						MylarStatusHandler.log(e, "failed to get tree viewers");
207
						return null;
208
					}
209
				}
210
			}
211
212
			try {
213
				// get the current page of the outline
214
				Class<?> clazz = PDEFormEditor.class;
215
				Field field = null;
216
				try {
217
					field = clazz.getDeclaredField("formOutline");
218
				} catch (NoSuchFieldException e) {
219
					field = clazz.getDeclaredField("fFormOutline");
220
				}
221
				field.setAccessible(true);
222
				Object f = field.get(editor);
223
				if (f != null && f instanceof FormOutlinePage) {
224
					// get the tree viewer for the outline
225
					Class<?> clazz2 = FormOutlinePage.class;
226
					Field field2 = null;
227
					try {
228
						field2 = clazz2.getDeclaredField("treeViewer");
229
					} catch (NoSuchFieldException e) {
230
						field2 = clazz2.getDeclaredField("fTreeViewer");
231
					}
232
					field2.setAccessible(true);
233
					Object f2 = field2.get(f);
234
					if (f2 != null && f2 instanceof TreeViewer) {
235
						TreeViewer treeViewer = (TreeViewer) f2;
236
						viewers.add(treeViewer);
237
					}
238
				}
239
			} catch (Exception e) {
240
				MylarStatusHandler.fail(e, "could not get PDE outline", false);
241
				return Collections.emptyList();
242
			}
243
244
			// add a listener so that when the selection changes, the view is
245
			// refreshed to attempt to keep the ui model the same as the
246
			// taskscape one
247
			for (TreeViewer viewer : viewers) {
248
				viewer.addSelectionChangedListener(treeSelectionChangedListener);
249
				viewer.addTreeListener(treeSelectionChangedListener);
250
			}
251
252
			return viewers;
253
		}
254
		return Collections.emptyList();
255
	}
256
257
	public void refreshOutline(Object element, boolean updateLabels, boolean setSelection) {
258
		IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
259
		List<TreeViewer> treeViewers = getContentOutlineViewers(editorPart);
260
		for (TreeViewer treeViewer : treeViewers) {
261
			if (treeViewer != null) {
262
				if (element == null) {
263
					treeViewer.getControl().setRedraw(false);
264
					treeViewer.refresh(true);
265
					treeViewer.getControl().setRedraw(true);
266
					treeViewer.expandAll();
267
				} else if (element instanceof PluginObjectNode) {
268
					treeViewer.getControl().setRedraw(false);
269
					treeViewer.refresh(element, true);
270
					treeViewer.getControl().setRedraw(true);
271
					treeViewer.expandAll();
272
				}
273
			}
274
		}
275
276
	}
277
278
	/**
279
	 * Class to listen to the tree views to attempt to refresh them more
280
	 * frequently to keep the ui model consistant with the user selections
281
	 * 
282
	 * @author Shawn Minto
283
	 */
284
	private class TreeViewerListener implements ISelectionChangedListener, ITreeViewerListener {
285
		public void selectionChanged(SelectionChangedEvent event) {
286
			Object o = event.getSource();
287
			if (o instanceof TreeViewer) {
288
				((TreeViewer) o).refresh();
289
				((TreeViewer) o).expandAll();
290
			}
291
		}
292
293
		public void treeCollapsed(TreeExpansionEvent event) {
294
			Object o = event.getSource();
295
			if (o instanceof TreeViewer) {
296
				((TreeViewer) o).refresh();
297
			}
298
299
		}
300
301
		public void treeExpanded(TreeExpansionEvent event) {
302
			Object o = event.getSource();
303
			if (o instanceof TreeViewer) {
304
				((TreeViewer) o).refresh();
305
			}
306
		}
307
	}
308
309
	@Override
310
	public Object getObjectForTextSelection(TextSelection selection, IEditorPart editor) {
311
		return null;
312
	}
313
314
	@Override
315
	public void restoreEditor(IMylarElement document) {
316
		open(document);
317
	}
318
	
319
	@Override
320
	public IMylarElement getElement(IEditorInput input) {
321
		return null;
322
	}
323
324
	@Override
325
	public String getContentType() {
326
		return PdeStructureBridge.CONTENT_TYPE;
327
	}
328
}
(-)META-INF/MANIFEST.MF (-3 / +1 lines)
Lines 30-36 Link Here
30
Export-Package: org.eclipse.mylar.internal.ide,
30
Export-Package: org.eclipse.mylar.internal.ide,
31
 org.eclipse.mylar.internal.ide.ui,
31
 org.eclipse.mylar.internal.ide.ui,
32
 org.eclipse.mylar.internal.ide.ui.actions,
32
 org.eclipse.mylar.internal.ide.ui.actions,
33
 org.eclipse.mylar.internal.ide.xml,
33
 org.eclipse.mylar.internal.ide.xml
34
 org.eclipse.mylar.internal.ide.xml.ant,
35
 org.eclipse.mylar.internal.ide.xml.pde
36
Bundle-RequiredExecutionEnvironment: J2SE-1.5
34
Bundle-RequiredExecutionEnvironment: J2SE-1.5
(-)src/org/eclipse/mylar/internal/ide/xml/ant/AntEditingMonitor.java (-130 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Apr 1, 2005
13
 */
14
package org.eclipse.mylar.internal.ide.xml.ant;
15
16
//import java.lang.reflect.InvocationTargetException;
17
//import java.lang.reflect.Method;
18
19
import org.eclipse.ant.internal.ui.editor.AntEditor;
20
import org.eclipse.ant.internal.ui.model.AntElementNode;
21
import org.eclipse.ant.internal.ui.model.AntModel;
22
import org.eclipse.ant.internal.ui.model.AntProjectNode;
23
import org.eclipse.jface.text.TextSelection;
24
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.mylar.core.MylarStatusHandler;
26
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
27
import org.eclipse.mylar.monitor.ui.AbstractUserInteractionMonitor;
28
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IWorkbenchPart;
30
import org.eclipse.ui.part.FileEditorInput;
31
32
/**
33
 * @author Mik Kersten
34
 */
35
public class AntEditingMonitor extends AbstractUserInteractionMonitor {
36
37
	public AntEditingMonitor() {
38
		super();
39
	}
40
41
	@Override
42
	protected void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) {
43
		if (part instanceof AntEditor) {
44
45
			TextSelection textSelection = null;
46
			IEditorInput in = null;
47
48
			// assume that we are editing an xml file due to the editor used
49
			// this is the build.xml and other ant file editor
50
			AntEditor editor = (AntEditor) part;
51
52
			if (!(editor.getSelectionProvider().getSelection() instanceof TextSelection))
53
				return;
54
55
			textSelection = (TextSelection) editor.getSelectionProvider().getSelection();
56
			in = editor.getEditorInput();
57
58
			// check if we have a text selection
59
			if (textSelection != null && editor != null && editor.getAntModel() != null) {
60
				try {
61
					AntElementNode node = editor.getAntModel().getNode(textSelection.getOffset(), false);
62
					if (node == null) {
63
						return;
64
					}
65
66
					FileEditorInput fei = (FileEditorInput) in;
67
//					Method method = AntElementNode.class.getDeclaredMethod("getElementPath", new Class[] {});
68
//					method.setAccessible(true);
69
//					String path = (String) method.invoke(node, new Object[] {});
70
					String path = node.getElementPath();
71
					if (path == null) {
72
						return;
73
					}
74
					XmlNodeHelper xnode = new XmlNodeHelper(fei.getFile().getFullPath().toString(), path);
75
					super.handleElementSelection(part, xnode, contributeToContext);
76
				} catch (Exception e) {
77
					MylarStatusHandler.log(e, "selection resolve failed");
78
				}
79
			}
80
		}
81
		return;
82
	}
83
84
	public static AntElementNode getNode(AntModel antModel, String elementPath) throws SecurityException,
85
			NoSuchMethodException {
86
		AntProjectNode topNode;
87
		try {
88
			topNode = antModel.getProjectNode();
89
			return getNode(topNode, elementPath);
90
		} catch (Exception e) {
91
			return null;
92
		}
93
	}
94
95
	/**
96
	 * HACK: using reflection to gain accessibility
97
	 */
98
	private static AntElementNode getNode(AntElementNode topNode, String elementPath) throws NoSuchMethodException,
99
			IllegalAccessException {
100
		if (topNode == null)
101
			return null;
102
103
//		Method method = AntElementNode.class.getDeclaredMethod("getElementPath", new Class[] {});
104
//		method.setAccessible(true);
105
//		String path = (String) method.invoke(topNode, new Object[] {});
106
		String path = topNode.getElementPath();
107
		if (path.compareTo(elementPath) == 0) {
108
			return topNode;
109
		}
110
111
		if (topNode.getChildNodes() == null)
112
			return null;
113
114
		for (Object obj : topNode.getChildNodes()) {
115
			if (obj instanceof AntElementNode) {
116
				AntElementNode node = (AntElementNode) obj;
117
//				path = (String) method.invoke(node, new Object[] {});
118
				path = node.getElementPath();
119
				if (path.compareTo(elementPath) == 0) {
120
					return node;
121
				} else {
122
					AntElementNode node2 = getNode(node, elementPath);
123
					if (node2 != null)
124
						return node2;
125
				}
126
			}
127
		}
128
		return null;
129
	}
130
}
(-)src/org/eclipse/mylar/internal/ide/xml/ant/AntUiBridge.java (-202 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Apr 6, 2005
13
 */
14
package org.eclipse.mylar.internal.ide.xml.ant;
15
16
import java.lang.reflect.Method;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.eclipse.ant.internal.ui.editor.AntEditor;
21
import org.eclipse.ant.internal.ui.editor.outline.AntEditorContentOutlinePage;
22
import org.eclipse.core.internal.resources.Workspace;
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.jface.text.TextSelection;
29
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.mylar.context.core.IMylarElement;
31
import org.eclipse.mylar.context.ui.AbstractContextUiBridge;
32
import org.eclipse.mylar.core.MylarStatusHandler;
33
import org.eclipse.mylar.internal.ide.MylarIdePlugin;
34
import org.eclipse.ui.IEditorInput;
35
import org.eclipse.ui.IEditorPart;
36
import org.eclipse.ui.IEditorReference;
37
import org.eclipse.ui.IFileEditorInput;
38
import org.eclipse.ui.IWorkbenchPage;
39
import org.eclipse.ui.PartInitException;
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.forms.editor.FormEditor;
42
import org.eclipse.ui.ide.IDE;
43
import org.eclipse.ui.texteditor.AbstractTextEditor;
44
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
45
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
46
47
/**
48
 * @author Mik Kersten
49
 */
50
public class AntUiBridge extends AbstractContextUiBridge {
51
52
	/**
53
	 * @see org.eclipse.mylar.context.ui.AbstractContextUiBridge#open(org.eclipse.mylar.context.core.IMylarElement)
54
	 */
55
	@Override
56
	public void open(IMylarElement node) {
57
		// get the handle of the node
58
		String handle = node.getHandleIdentifier();
59
60
		int first = handle.indexOf(";");
61
		String filename = "";
62
		if (first == -1)
63
			filename = handle;
64
		else
65
			filename = handle.substring(0, first);
66
67
		try {
68
			// get the file
69
			IPath path = new Path(filename);
70
			IFile f = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
71
72
			// open the xml file looking at the proper line
73
			IEditorPart editor = openInEditor(f, true);
74
75
			// if the editor is null, we had a problem and should return
76
			if (editor == null) {
77
				MylarStatusHandler.log("Unable to open editor for file: " + filename, this);
78
				return;
79
			}
80
81
			// get the contents and create a new document so that we can get
82
			// the offsets to highlight
83
			// String content = XmlNodeHelper.getContents(f.getContents());
84
85
			// IDocument d = new Document(content);
86
87
			// if(first != -1){
88
			// int start = Integer.parseInt(handle.substring(first + 1));
89
			//
90
			// // get the offsets for the element
91
			// int startOffset = d.getLineOffset(start);
92
			// int length = 0;
93
			//                
94
			// // set the selection if the selection provider is not null
95
			// ISelectionProvider selectionProvider =
96
			// editor.getEditorSite().getSelectionProvider();
97
			// if(selectionProvider != null)
98
			// selectionProvider.setSelection(new TextSelection(startOffset,
99
			// length));
100
			// }
101
102
		} catch (Exception e) {
103
			MylarStatusHandler.fail(e, "ERROR OPENING XML EDITOR\n" + e.getMessage(), false);
104
		}
105
	}
106
107
	/**
108
	 * Open a file in the appropriate editor
109
	 * 
110
	 * @param file
111
	 *            The IFile to open
112
	 * @param activate
113
	 *            Whether to activate the editor or not
114
	 * @return The IEditorPart that the file opened in
115
	 * @throws PartInitException
116
	 */
117
	private IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {
118
		if (file != null) {
119
			IWorkbenchPage p = MylarIdePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
120
			if (p != null && file.exists()) {
121
				try {
122
					IEditorPart editorPart = IDE.openEditor(p, file, activate);
123
					return editorPart;
124
				} catch (Exception e) {
125
					// ignore this
126
				}
127
				// initializeHighlightRange(editorPart);
128
			}
129
		}
130
		return null;
131
	}
132
133
	@Override
134
	public void close(IMylarElement node) {
135
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
136
		if (page != null) {
137
			IEditorReference[] references = page.getEditorReferences();
138
			for (int i = 0; i < references.length; i++) {
139
				IEditorPart part = references[i].getEditor(false);
140
				if (part != null) {
141
					if (part.getEditorInput() instanceof IFileEditorInput) {
142
						IFileEditorInput input = (IFileEditorInput) part.getEditorInput();
143
						if ((input.getFile().getFullPath().toString()).equals(node.getHandleIdentifier())) {
144
							if (part instanceof FormEditor) {
145
								((FormEditor) part).close(true);
146
							} else if (part instanceof AbstractTextEditor) {
147
								((AbstractTextEditor) part).close(true);
148
							}
149
						}
150
					}
151
				}
152
			}
153
		}
154
	}
155
156
	@Override
157
	public boolean acceptsEditor(IEditorPart editorPart) {
158
		return editorPart instanceof AntEditor;
159
	}
160
161
	/**
162
	 * HACK: use reflection to get the TreeViewer
163
	 */
164
	@Override
165
	public List<TreeViewer> getContentOutlineViewers(IEditorPart editor) {
166
		List<TreeViewer> viewers = new ArrayList<TreeViewer>();
167
		if (editor instanceof AntEditor) {
168
			try {
169
				AntEditor ae = (AntEditor) editor;
170
				AntEditorContentOutlinePage outline = (AntEditorContentOutlinePage) ae
171
						.getAdapter(IContentOutlinePage.class);
172
				Class<?> clazz = ContentOutlinePage.class;
173
				Method method = clazz.getDeclaredMethod("getTreeViewer", new Class[] {});
174
				method.setAccessible(true);
175
				viewers.add((TreeViewer) method.invoke(outline, new Object[] {}));
176
			} catch (Exception e) {
177
				MylarStatusHandler.log(e, "couldn't get outline");
178
			}
179
		}
180
		return viewers;
181
	}
182
183
	@Override
184
	public Object getObjectForTextSelection(TextSelection selection, IEditorPart editor) {
185
		return null;
186
	}
187
188
	@Override
189
	public void restoreEditor(IMylarElement document) {
190
		open(document);
191
	}
192
	
193
	@Override
194
	public IMylarElement getElement(IEditorInput input) {
195
		return null;
196
	}
197
198
	@Override
199
	public String getContentType() {
200
		return AntStructureBridge.CONTENT_TYPE;
201
	}
202
}
(-)src/org/eclipse/mylar/internal/ide/xml/ant/AntContextLabelProvider.java (-62 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.ide.xml.ant;
13
14
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
15
import org.eclipse.mylar.context.core.ContextCorePlugin;
16
import org.eclipse.mylar.context.core.IMylarElement;
17
import org.eclipse.mylar.context.core.IMylarRelation;
18
import org.eclipse.mylar.internal.context.ui.AbstractContextLabelProvider;
19
import org.eclipse.mylar.internal.context.ui.ContextUiImages;
20
import org.eclipse.mylar.internal.ide.MylarIdePlugin;
21
import org.eclipse.swt.graphics.Image;
22
23
/**
24
 * @author Mik Kersten
25
 */
26
public class AntContextLabelProvider extends AbstractContextLabelProvider {
27
28
	public static final String LABEL_RELATION = "referenced by";
29
	
30
	@Override
31
	protected Image getImage(IMylarElement node) {
32
		return ContextUiImages.getImage(ContextUiImages.FILE_XML);
33
	}
34
35
	@Override
36
	protected Image getImage(IMylarRelation edge) {
37
		return ContextUiImages.getImage(MylarIdePlugin.EDGE_REF_XML);
38
	}
39
40
	@Override
41
	protected String getText(IMylarElement node) {
42
		AbstractContextStructureBridge bridge = ContextCorePlugin.getDefault().getStructureBridge(AntStructureBridge.CONTENT_TYPE);
43
		return bridge.getName(bridge.getObjectForHandle(node.getHandleIdentifier()));
44
	}
45
46
	@Override
47
	protected String getText(IMylarRelation edge) {
48
		return LABEL_RELATION;
49
	}
50
51
	@Override
52
	protected Image getImageForObject(Object object) {
53
		return ContextUiImages.getImage(ContextUiImages.FILE_XML);
54
	}
55
56
	@Override
57
	protected String getTextForObject(Object object) {
58
		AbstractContextStructureBridge bridge = ContextCorePlugin.getDefault().getStructureBridge(AntStructureBridge.CONTENT_TYPE);
59
		return bridge.getName(object);
60
	}
61
62
}
(-)src/org/eclipse/mylar/internal/ide/xml/ant/AntStructureBridge.java (-334 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
/*
12
 * Created on Apr 20, 2005
13
 */
14
package org.eclipse.mylar.internal.ide.xml.ant;
15
16
//import java.lang.reflect.Method;
17
import java.util.Collections;
18
import java.util.List;
19
20
import org.eclipse.ant.internal.ui.editor.AntEditor;
21
import org.eclipse.ant.internal.ui.editor.text.AntAnnotationModel;
22
import org.eclipse.ant.internal.ui.model.AntElementNode;
23
import org.eclipse.ant.internal.ui.model.AntModel;
24
import org.eclipse.ant.internal.ui.model.IProblemRequestor;
25
import org.eclipse.ant.internal.ui.model.LocationProvider;
26
import org.eclipse.core.internal.resources.File;
27
import org.eclipse.core.internal.resources.Workspace;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.runtime.IPath;
32
import org.eclipse.core.runtime.Path;
33
import org.eclipse.jface.text.Document;
34
import org.eclipse.jface.text.IDocument;
35
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
36
import org.eclipse.mylar.context.core.ContextCorePlugin;
37
import org.eclipse.mylar.core.MylarStatusHandler;
38
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
39
import org.eclipse.ui.IEditorPart;
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.part.FileEditorInput;
42
import org.eclipse.ui.views.markers.internal.ProblemMarker;
43
44
/**
45
 * @author Mik Kersten
46
 */
47
public class AntStructureBridge extends AbstractContextStructureBridge {
48
49
	public final static String CONTENT_TYPE = "build.xml";
50
51
	private static final char HANDLE_PATH_SEPARATOR = ';';
52
53
	/**
54
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getContentType()
55
	 */
56
	@Override
57
	public String getContentType() {
58
		return CONTENT_TYPE;
59
	}
60
61
	@Override
62
	public String getContentType(String elementHandle) {
63
		if (elementHandle.endsWith(".xml")) {
64
			return parentContentType;
65
		} else {
66
			return CONTENT_TYPE;
67
		}
68
	}
69
70
	@Override
71
	public List<String> getChildHandles(String handle) {
72
		return Collections.emptyList();
73
	}
74
75
	/**
76
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getParentHandle(java.lang.String)
77
	 */
78
	@Override
79
	public String getParentHandle(String handle) {
80
		Object o = getObjectForHandle(handle);
81
82
		// we can only get the parent if the element is an AntElementNode
83
		if (o instanceof AntElementNode) {
84
85
			// try to get the parent node
86
			AntElementNode parent = ((AntElementNode) o).getParentNode();
87
88
			if (parent != null) {
89
				// get the handle for the parent node
90
				return getHandleIdentifier(parent);
91
			} else {
92
				// if the parent is null, we just need to return the handle for
93
				// the file
94
				int delimeterIndex = handle.indexOf(";");
95
				if (delimeterIndex != -1) {
96
					String parentHandle = handle.substring(0, delimeterIndex);
97
					return parentHandle;
98
				} else {
99
					return null;
100
				}
101
			}
102
		} else if (o instanceof IFile) {
103
			AbstractContextStructureBridge parentBridge = ContextCorePlugin.getDefault().getStructureBridge(parentContentType);
104
			return parentBridge.getParentHandle(handle);
105
		} else {
106
			// return null if we can't get a parents
107
			return null;
108
		}
109
	}
110
111
	/**
112
	 * TODO: performance issue?
113
	 */
114
	@Override
115
	public Object getObjectForHandle(String handle) {
116
		try {
117
			if (handle == null)
118
				return null;
119
			int first = handle.indexOf(HANDLE_PATH_SEPARATOR);
120
			String filename = "";
121
			if (first == -1) {
122
				// we have just the filename, so return the IFile for this
123
				// filename
124
				filename = handle;
125
				IPath path = new Path(filename);
126
				IFile f = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
127
				return f;
128
			} else {
129
				// we have an element since there is a line number
130
				// get the filename from the handle
131
				filename = handle.substring(0, first);
132
			}
133
134
			// get the file and create a new FileEditorInput
135
			IPath path = new Path(filename);
136
			IFile file = (IFile) ((Workspace) ResourcesPlugin.getWorkspace()).newResource(path, IResource.FILE);
137
			FileEditorInput fei = new FileEditorInput(file);
138
139
			// get the line number that the element is on
140
			String elementPath = handle.substring(first + 1);
141
			if (elementPath.equals("")) {
142
				return file;
143
			} else {
144
				// XXX needed if the editor is the only way to get the model
145
				// get the active editor, which should be the ant editor so we
146
				// can get the AntModel
147
				IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
148
						.getActiveEditor();
149
				if (editorPart instanceof AntEditor) {
150
					AntModel antModel = ((AntEditor) editorPart).getAntModel();
151
					if (antModel != null)
152
						return AntEditingMonitor.getNode(antModel, elementPath);
153
				} else {
154
					String content = XmlNodeHelper.getContents(file.getContents());
155
					IDocument d = new Document(content);
156
					// create the ant model and get the element from it
157
					IProblemRequestor p = new AntAnnotationModel(file);
158
					AntModel am = new AntModel(d, p, new LocationProvider(fei));
159
					am.reconcile();
160
					return AntEditingMonitor.getNode(am, elementPath);
161
				}
162
			}
163
		} catch (Throwable t) {
164
			// ignore this, means that the file or node doesn't exist
165
		}
166
		return null;
167
	}
168
169
	/**
170
	 * Handle is filename;XPath
171
	 * 
172
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getHandleIdentifier(java.lang.Object)
173
	 */
174
	@Override
175
	public String getHandleIdentifier(Object object) {
176
		// we can only create handles for AntElementNodes and build.xml Files
177
		if (object instanceof XmlNodeHelper) {
178
			return ((XmlNodeHelper) object).getHandle();
179
		} else if (object instanceof AntElementNode) {
180
			AntElementNode node = (AntElementNode) object;
181
				String path = node.getElementPath();
182
				if (path == null || node == null || node.getIFile() == null) {
183
					return null;
184
				}
185
				XmlNodeHelper helper = new XmlNodeHelper(node.getIFile().getFullPath().toString(), path);
186
				if (helper != null) {
187
					return helper.getHandle();
188
				}
189
		} else if (object instanceof File) {
190
			File file = (File) object;
191
			// get the handle for the build.xml file
192
			if (file.getFullPath().toString().endsWith("build.xml"))
193
				return file.getFullPath().toString();
194
		}
195
		return null;
196
	}
197
198
	/**
199
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getName(java.lang.Object)
200
	 */
201
	@Override
202
	public String getName(Object object) {
203
		if (object instanceof AntElementNode) {
204
			AntElementNode n = (AntElementNode) object;
205
			String name = n.getIFile().getName() + ": " + n.getName();
206
			return name;
207
		} else if (object instanceof File) {
208
			File file = (File) object;
209
			if (file.getFullPath().toString().endsWith("build.xml"))
210
				return "build.xml";
211
		}
212
		return "";
213
	}
214
215
	/**
216
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#canBeLandmark(Object)
217
	 * 
218
	 * TODO: make a non-handle based test
219
	 */
220
	@Override
221
	public boolean canBeLandmark(String handle) {
222
		if (handle != null) {
223
			return handle.indexOf(';') == -1;
224
		} else {
225
			return false;
226
		}
227
	}
228
229
	/**
230
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#acceptsObject(java.lang.Object)
231
	 */
232
	@Override
233
	public boolean acceptsObject(Object object) {
234
		// we accept AntElementNode and build.xml File objects
235
		if (object instanceof AntElementNode) {
236
			return true;
237
		} else if (object instanceof XmlNodeHelper) {
238
			if (((XmlNodeHelper) object).getFilename().endsWith("build.xml"))
239
				return true;
240
		} else if (object instanceof File) {
241
			File file = (File) object;
242
			if (file.getFullPath().toString().endsWith("build.xml"))
243
				return true;
244
		}
245
		return false;
246
	}
247
248
	/**
249
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#canFilter(java.lang.Object)
250
	 */
251
	@Override
252
	public boolean canFilter(Object element) {
253
		return true;
254
	}
255
256
	/**
257
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#isDocument(java.lang.String)
258
	 */
259
	@Override
260
	public boolean isDocument(String handle) {
261
		return handle.indexOf(';') == -1;
262
	}
263
264
	/**
265
	 * @see org.eclipse.mylar.context.core.AbstractContextStructureBridge#getHandleForOffsetInObject(Object,
266
	 *      int)
267
	 */
268
	@Override
269
	public String getHandleForOffsetInObject(Object resource, int offset) {
270
		if (resource == null)
271
			return null;
272
		if (resource instanceof ProblemMarker) {
273
			ProblemMarker marker = (ProblemMarker) resource;
274
275
			// we can only return a handle if the resource is build.xml
276
			try {
277
				IResource res = marker.getResource();
278
279
				if (res instanceof IFile) {
280
					IFile file = (IFile) res;
281
					if (file.getFullPath().toString().endsWith("build.xml")) {
282
						return file.getFullPath().toString();
283
					} else {
284
						return null;
285
					}
286
				}
287
				return null;
288
			} catch (Throwable t) {
289
				MylarStatusHandler.fail(t, "Could not find element for: " + marker, false);
290
				return null;
291
			}
292
		} else if (resource instanceof IFile) {
293
			try {
294
				IFile file = (IFile) resource;
295
				if (file.getFullPath().toString().endsWith("build.xml")) {
296
					FileEditorInput fei = new FileEditorInput(file);
297
					String content = XmlNodeHelper.getContents(file.getContents());
298
					IDocument d = new Document(content);
299
					// create the ant model and get the element from it
300
					IProblemRequestor p = new AntAnnotationModel(file);
301
					AntModel am = new AntModel(d, p, new LocationProvider(fei));
302
					am.reconcile();
303
304
					AntElementNode node = am.getNode(offset, false);
305
//					Method method = AntElementNode.class.getDeclaredMethod("getElementPath", new Class[] {});
306
//					method.setAccessible(true);
307
//					String path = (String) method.invoke(node, new Object[] {});
308
					String path = node.getElementPath();
309
					if (path == null) {
310
						return null;
311
					}
312
					String handle = new XmlNodeHelper(file.getFullPath().toString(), path).getHandle();
313
					return handle;
314
				}
315
			} catch (Exception e) {
316
				MylarStatusHandler.log(e, "Unable to get handle for offset in object");
317
			}
318
		}
319
		return null;
320
	}
321
322
//	public IProject getProjectForObject(Object object) {
323
//		while (!(object instanceof IFile)) {
324
//			String handle = getParentHandle(getHandleIdentifier(object));
325
//			if (handle == null)
326
//				break;
327
//			object = getObjectForHandle(handle);
328
//		}
329
//		if (object instanceof IFile && acceptsObject(object)) {
330
//			return ((IFile) object).getProject();
331
//		}
332
//		return null;
333
//	}
334
}
(-)src/org/eclipse/mylar/internal/ide/MylarIdePlugin.java (-31 / +17 lines)
Lines 12-19 Link Here
12
12
13
import org.eclipse.jface.resource.ImageDescriptor;
13
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.mylar.core.MylarStatusHandler;
14
import org.eclipse.mylar.core.MylarStatusHandler;
15
import org.eclipse.mylar.internal.ide.xml.ant.AntEditingMonitor;
16
import org.eclipse.mylar.internal.ide.xml.pde.PdeEditingMonitor;
17
import org.eclipse.mylar.monitor.ui.MylarMonitorUiPlugin;
15
import org.eclipse.mylar.monitor.ui.MylarMonitorUiPlugin;
18
import org.eclipse.ui.plugin.AbstractUIPlugin;
16
import org.eclipse.ui.plugin.AbstractUIPlugin;
19
import org.osgi.framework.BundleContext;
17
import org.osgi.framework.BundleContext;
Lines 22-38 Link Here
22
 * @author Mik Kersten
20
 * @author Mik Kersten
23
 */
21
 */
24
public class MylarIdePlugin extends AbstractUIPlugin {
22
public class MylarIdePlugin extends AbstractUIPlugin {
25
	
23
26
	public static final String PLUGIN_ID = "org.eclipse.mylar.ide";
24
	public static final String PLUGIN_ID = "org.eclipse.mylar.ide";
27
	
25
28
	private static MylarIdePlugin INSTANCE;
26
	private static MylarIdePlugin INSTANCE;
29
27
30
	public static final ImageDescriptor EDGE_REF_XML = getImageDescriptor("icons/elcl16/edge-ref-xml.gif");
28
	public static final ImageDescriptor EDGE_REF_XML = getImageDescriptor("icons/elcl16/edge-ref-xml.gif");
31
29
32
	private PdeEditingMonitor pdeEditingMonitor;
33
34
	private AntEditingMonitor antEditingMonitor;
35
		
36
	public MylarIdePlugin() {
30
	public MylarIdePlugin() {
37
		INSTANCE = this;
31
		INSTANCE = this;
38
	}
32
	}
Lines 40-66 Link Here
40
	@Override
34
	@Override
41
	public void start(BundleContext context) throws Exception {
35
	public void start(BundleContext context) throws Exception {
42
		super.start(context);
36
		super.start(context);
43
		
37
44
		pdeEditingMonitor = new PdeEditingMonitor();
38
		// final IWorkbench workbench = PlatformUI.getWorkbench();
45
		MylarMonitorUiPlugin.getDefault().getSelectionMonitors().add(pdeEditingMonitor);
39
		// workbench.getDisplay().asyncExec(new Runnable() {
46
40
		// public void run() {
47
		antEditingMonitor = new AntEditingMonitor();
41
		// try {
48
		MylarMonitorUiPlugin.getDefault().getSelectionMonitors().add(antEditingMonitor);
42
		// pdeEditingMonitor = new PdeEditingMonitor();
49
		
43
		// MylarMonitorPlugin.getDefault().getSelectionMonitors().add(pdeEditingMonitor);
50
//		final IWorkbench workbench = PlatformUI.getWorkbench();
44
		//
51
//		workbench.getDisplay().asyncExec(new Runnable() {
45
		// antEditingMonitor = new AntEditingMonitor();
52
//			public void run() {
46
		// MylarMonitorPlugin.getDefault().getSelectionMonitors().add(antEditingMonitor);
53
//				try {
47
		// } catch (Exception e) {
54
//					pdeEditingMonitor = new PdeEditingMonitor();
48
		// MylarStatusHandler.fail(e, "Mylar IDE initialization failed", false);
55
//					MylarMonitorPlugin.getDefault().getSelectionMonitors().add(pdeEditingMonitor);
49
		// }
56
//
50
		// }
57
//					antEditingMonitor = new AntEditingMonitor();
51
		// });
58
//					MylarMonitorPlugin.getDefault().getSelectionMonitors().add(antEditingMonitor);
59
//				} catch (Exception e) {
60
//					MylarStatusHandler.fail(e, "Mylar IDE initialization failed", false);
61
//				}
62
//			}
63
//		});
64
	}
52
	}
65
53
66
	@Override
54
	@Override
Lines 68-75 Link Here
68
		try {
56
		try {
69
			super.stop(context);
57
			super.stop(context);
70
			INSTANCE = null;
58
			INSTANCE = null;
71
			MylarMonitorUiPlugin.getDefault().getSelectionMonitors().remove(pdeEditingMonitor);
72
			MylarMonitorUiPlugin.getDefault().getSelectionMonitors().remove(antEditingMonitor);
73
		} catch (Exception e) {
59
		} catch (Exception e) {
74
			MylarStatusHandler.fail(e,
60
			MylarStatusHandler.fail(e,
75
					"Mylar IDE stop failed, Mylar may not have started properly (ensure correct Eclipse version)",
61
					"Mylar IDE stop failed, Mylar may not have started properly (ensure correct Eclipse version)",
(-)plugin.xml (-29 lines)
Lines 1-37 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<?eclipse version="3.0"?>
4
<plugin> 
3
<plugin> 
5
   
4
   
6
   	<extension point="org.eclipse.mylar.context.core.bridges">
7
		<structureBridge
8
	        class="org.eclipse.mylar.internal.ide.xml.ant.AntStructureBridge"
9
	        name="Ant Structure Bridge"
10
	        parentContentType="*"/>
11
		<structureBridge
12
	        class="org.eclipse.mylar.internal.ide.xml.pde.PdeStructureBridge"
13
	        name="PDE Structure Bridge"
14
	        parentContentType="*"/>
15
	</extension>
16
5
17
   <extension point="org.eclipse.mylar.context.ui.bridges">
18
    <uiBridge
19
          class="org.eclipse.mylar.internal.ide.xml.pde.PdeUiBridge"
20
          contentType="plugin.xml"
21
          activeSearchIcon="icons/elcl16/edge-ref-xml.gif"
22
	      activeSearchLabel="XML Search"/>
23
    <labelProvider
24
          class="org.eclipse.mylar.internal.ide.xml.pde.PdeContextLabelProvider"
25
          contentType="plugin.xml"/>
26
    <uiBridge
27
          class="org.eclipse.mylar.internal.ide.xml.ant.AntUiBridge"
28
          contentType="build.xml"
29
          activeSearchIcon="icons/elcl16/edge-ref-xml.gif"
30
	      activeSearchLabel="XML Search"/>
31
    <labelProvider
32
          class="org.eclipse.mylar.internal.ide.xml.ant.AntContextLabelProvider"
33
          contentType="build.xml"/>
34
  </extension>
35
  
6
  
36
 	<extension point="org.eclipse.ui.preferencePages">
7
 	<extension point="org.eclipse.ui.preferencePages">
37
      <page 
8
      <page 
(-).refactorings/2007/4/16/refactorings.index (+2 lines)
Added Link Here
1
1176782571643	Delete element
2
1176783488221	Delete element
(-).refactorings/2007/4/16/refactorings.history (+5 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<session version="1.0">
3
<refactoring accessors="true" comment="Delete 1 element(s) from project 'org.eclipse.mylar.ide'&#13;&#10;- Original project: 'org.eclipse.mylar.ide'&#13;&#10;- Original element: 'org.eclipse.mylar.ide/src/org.eclipse.mylar.internal.ide.xml.ant'" description="Delete element" element1="/src&lt;org.eclipse.mylar.internal.ide.xml.ant" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1176782571643" subPackages="false" version="1.0"/>
4
<refactoring accessors="true" comment="Delete 1 element(s) from project 'org.eclipse.mylar.ide'&#13;&#10;- Original project: 'org.eclipse.mylar.ide'&#13;&#10;- Original element: 'org.eclipse.mylar.ide/src/org.eclipse.mylar.internal.ide.xml.pde'" description="Delete element" element1="/src&lt;org.eclipse.mylar.internal.ide.xml.pde" elements="1" flags="589830" id="org.eclipse.jdt.ui.delete" resources="0" stamp="1176783488221" subPackages="false" version="1.0"/>
5
</session>
(-)src/org/eclipse/mylar/internal/java/search/XmlJavaRelationProvider.java (-9 / +11 lines)
Lines 37-53 Link Here
37
import org.eclipse.jdt.core.IMember;
37
import org.eclipse.jdt.core.IMember;
38
import org.eclipse.jdt.core.IType;
38
import org.eclipse.jdt.core.IType;
39
import org.eclipse.jdt.core.JavaCore;
39
import org.eclipse.jdt.core.JavaCore;
40
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
40
import org.eclipse.mylar.context.core.AbstractRelationProvider;
41
import org.eclipse.mylar.context.core.AbstractRelationProvider;
41
import org.eclipse.mylar.context.core.ContextCorePlugin;
42
import org.eclipse.mylar.context.core.ContextCorePlugin;
42
import org.eclipse.mylar.context.core.IDegreeOfSeparation;
43
import org.eclipse.mylar.context.core.IDegreeOfSeparation;
43
import org.eclipse.mylar.context.core.IMylarElement;
44
import org.eclipse.mylar.context.core.IMylarElement;
44
import org.eclipse.mylar.context.core.AbstractContextStructureBridge;
45
import org.eclipse.mylar.core.MylarStatusHandler;
45
import org.eclipse.mylar.core.MylarStatusHandler;
46
import org.eclipse.mylar.internal.context.core.DegreeOfSeparation;
46
import org.eclipse.mylar.internal.context.core.DegreeOfSeparation;
47
import org.eclipse.mylar.internal.context.core.IActiveSearchListener;
47
import org.eclipse.mylar.internal.context.core.IActiveSearchListener;
48
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
48
import org.eclipse.mylar.internal.context.core.IMylarSearchOperation;
49
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
49
import org.eclipse.mylar.internal.ide.xml.XmlNodeHelper;
50
import org.eclipse.mylar.internal.ide.xml.pde.PdeStructureBridge;
51
import org.eclipse.mylar.resources.MylarResourcesPlugin;
50
import org.eclipse.mylar.resources.MylarResourcesPlugin;
52
import org.eclipse.search.core.text.TextSearchScope;
51
import org.eclipse.search.core.text.TextSearchScope;
53
import org.eclipse.search.internal.ui.text.FileSearchQuery;
52
import org.eclipse.search.internal.ui.text.FileSearchQuery;
Lines 72-80 Link Here
72
71
73
	public static final Map<Match, XmlNodeHelper> nodeMap = new HashMap<Match, XmlNodeHelper>();
72
	public static final Map<Match, XmlNodeHelper> nodeMap = new HashMap<Match, XmlNodeHelper>();
74
73
74
	//TODO: copied from PdeStructure bridge: Pde has a dep on Java but Java should not have a dep on PDE
75
	protected static final String PDE_CONTENT_TYPE = "plugin.xml";
76
75
	public XmlJavaRelationProvider() {
77
	public XmlJavaRelationProvider() {
76
		// TODO: should this be a generic XML extension?
78
		// TODO: should this be a generic XML extension?
77
		super(PdeStructureBridge.CONTENT_TYPE, SOURCE_ID);
79
		super(PDE_CONTENT_TYPE, SOURCE_ID);
78
	}
80
	}
79
81
80
	@Override
82
	@Override
Lines 113-119 Link Here
113
			// create a search scope for the projects of landmarks
115
			// create a search scope for the projects of landmarks
114
			Set<IResource> l = new HashSet<IResource>();
116
			Set<IResource> l = new HashSet<IResource>();
115
			for (IMylarElement landmark : landmarks) {
117
			for (IMylarElement landmark : landmarks) {
116
				if (landmark.getContentType().equals(PdeStructureBridge.CONTENT_TYPE)) {
118
				if (landmark.getContentType().equals(PDE_CONTENT_TYPE)) {
117
					// ||
119
					// ||
118
					// landmark.getContentType().equals(AntStructureBridge.CONTENT_TYPE))
120
					// landmark.getContentType().equals(AntStructureBridge.CONTENT_TYPE))
119
					// {
121
					// {
Lines 136-142 Link Here
136
138
137
			IResource[] res = new IResource[l.size()];
139
			IResource[] res = new IResource[l.size()];
138
			res = l.toArray(res);
140
			res = l.toArray(res);
139
			TextSearchScope doiScope = FileTextSearchScope.newSearchScope(res, new String[] {PdeStructureBridge.CONTENT_TYPE}, false);
141
			TextSearchScope doiScope = FileTextSearchScope.newSearchScope(res, new String[] {PDE_CONTENT_TYPE}, false);
140
			return l.isEmpty() ? null : doiScope;
142
			return l.isEmpty() ? null : doiScope;
141
		case 2:
143
		case 2:
142
			// create a search scope for the projects of landmarks
144
			// create a search scope for the projects of landmarks
Lines 160-174 Link Here
160
162
161
			res = new IProject[projectsToSearch.size()];
163
			res = new IProject[projectsToSearch.size()];
162
			res = projectsToSearch.toArray(res);
164
			res = projectsToSearch.toArray(res);
163
			TextSearchScope projScope = FileTextSearchScope.newSearchScope(res, new String[] {PdeStructureBridge.CONTENT_TYPE}, false);
165
			TextSearchScope projScope = FileTextSearchScope.newSearchScope(res, new String[] {PDE_CONTENT_TYPE}, false);
164
166
165
			return projectsToSearch.isEmpty() ? null : projScope;
167
			return projectsToSearch.isEmpty() ? null : projScope;
166
		case 3:
168
		case 3:
167
			// create a search scope for the workspace
169
			// create a search scope for the workspace
168
			return FileTextSearchScope.newSearchScope(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, new String[] {PdeStructureBridge.CONTENT_TYPE}, false);
170
			return FileTextSearchScope.newSearchScope(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, new String[] {PDE_CONTENT_TYPE}, false);
169
		case 4:
171
		case 4:
170
			// create a search scope for the workspace
172
			// create a search scope for the workspace
171
			return FileTextSearchScope.newSearchScope(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, new String[] {PdeStructureBridge.CONTENT_TYPE}, false);
173
			return FileTextSearchScope.newSearchScope(new IResource[] { ResourcesPlugin.getWorkspace().getRoot() }, new String[] {PDE_CONTENT_TYPE}, false);
172
		default:
174
		default:
173
			return null;
175
			return null;
174
		}
176
		}
Lines 243-249 Link Here
243
245
244
					for (String handle : nodes.keySet()) {
246
					for (String handle : nodes.keySet()) {
245
247
246
						incrementInterest(node, PdeStructureBridge.CONTENT_TYPE, handle, degreeOfSeparation);
248
						incrementInterest(node, PDE_CONTENT_TYPE, handle, degreeOfSeparation);
247
					}
249
					}
248
					gathered = true;
250
					gathered = true;
249
					XmlJavaRelationProvider.this.searchCompleted(node);
251
					XmlJavaRelationProvider.this.searchCompleted(node);

Return to bug 182506