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 258853 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 19-25 Link Here
19
 org.eclipse.core.filesystem;bundle-version="1.2.0"
19
 org.eclipse.core.filesystem;bundle-version="1.2.0"
20
Export-Package: org.eclipse.pde.api.tools.internal;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
20
Export-Package: org.eclipse.pde.api.tools.internal;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
21
 org.eclipse.pde.api.tools.internal.builder;x-friends:="org.eclipse.pde.api.tools.ui",
21
 org.eclipse.pde.api.tools.internal.builder;x-friends:="org.eclipse.pde.api.tools.ui",
22
 org.eclipse.pde.api.tools.internal.comparator;x-internal:=true,
22
 org.eclipse.pde.api.tools.internal.comparator;x-friends:="org.eclipse.pde.api.tools.ui",
23
 org.eclipse.pde.api.tools.internal.descriptors;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
23
 org.eclipse.pde.api.tools.internal.descriptors;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
24
 org.eclipse.pde.api.tools.internal.model;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
24
 org.eclipse.pde.api.tools.internal.model;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
25
 org.eclipse.pde.api.tools.internal.natures;x-internal:=true,
25
 org.eclipse.pde.api.tools.internal.natures;x-internal:=true,
(-)src/org/eclipse/pde/api/tools/internal/provisional/ApiPlugin.java (-1 / +12 lines)
Lines 34-39 Link Here
34
import org.eclipse.pde.api.tools.internal.ApiDescriptionManager;
34
import org.eclipse.pde.api.tools.internal.ApiDescriptionManager;
35
import org.eclipse.pde.api.tools.internal.ApiFilterStore;
35
import org.eclipse.pde.api.tools.internal.ApiFilterStore;
36
import org.eclipse.pde.api.tools.internal.JavadocTagManager;
36
import org.eclipse.pde.api.tools.internal.JavadocTagManager;
37
import org.eclipse.pde.api.tools.internal.SessionManager;
37
import org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector;
38
import org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector;
38
import org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder;
39
import org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder;
39
import org.eclipse.pde.api.tools.internal.builder.ReferenceAnalyzer;
40
import org.eclipse.pde.api.tools.internal.builder.ReferenceAnalyzer;
Lines 146-152 Link Here
146
	 * Singleton instance of the {@link JavadocTagManager}
147
	 * Singleton instance of the {@link JavadocTagManager}
147
	 */
148
	 */
148
	private static JavadocTagManager fgTagManager = null;
149
	private static JavadocTagManager fgTagManager = null;
149
150
	/**
151
	 * Singleton instance of the {@link ISessionManager}
152
	 */
153
	private static ISessionManager fgSessionManager = null;
150
	/**
154
	/**
151
	 * Private debug options
155
	 * Private debug options
152
	 */
156
	 */
Lines 518-523 Link Here
518
		}
522
		}
519
		return SEVERITY_IGNORE;
523
		return SEVERITY_IGNORE;
520
	}
524
	}
525
	
526
	public ISessionManager getSessionManager() {
527
		if(fgSessionManager == null) {
528
			fgSessionManager = new SessionManager();
529
		}
530
		return fgSessionManager;
531
	}
521
532
522
	/**
533
	/**
523
	 * Returns the enable state for the specific key from the given {@link IProject}.
534
	 * Returns the enable state for the specific key from the given {@link IProject}.
(-)src/org/eclipse/pde/api/tools/internal/util/Util.java (+5 lines)
Lines 2244-2247 Link Here
2244
			return 0;
2244
			return 0;
2245
		}
2245
		}
2246
	};
2246
	};
2247
2248
	public static void checkCanceled(IProgressMonitor monitor) {
2249
		if (monitor.isCanceled())
2250
			throw new OperationCanceledException();
2251
	}
2247
}
2252
}
(-)src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java (-6 / +38 lines)
Lines 15-21 Link Here
15
import java.util.Set;
15
import java.util.Set;
16
16
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jdt.core.Flags;
21
import org.eclipse.jdt.core.Flags;
20
import org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator;
22
import org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator;
21
import org.eclipse.pde.api.tools.internal.comparator.Delta;
23
import org.eclipse.pde.api.tools.internal.comparator.Delta;
Lines 355-363 Link Here
355
			final int visibilityModifiers) {
357
			final int visibilityModifiers) {
356
		try {
358
		try {
357
		
359
		
358
			if (referenceBaseline == null || baseline == null) {
359
				throw new IllegalArgumentException("The baselines cannot be null"); //$NON-NLS-1$
360
			}
361
			if (referenceComponent == null) {
360
			if (referenceComponent == null) {
362
				if (component2 == null) {
361
				if (component2 == null) {
363
					throw new IllegalArgumentException("Both components cannot be null"); //$NON-NLS-1$
362
					throw new IllegalArgumentException("Both components cannot be null"); //$NON-NLS-1$
Lines 381-386 Link Here
381
						referenceComponentId,
380
						referenceComponentId,
382
						Util.getComponentVersionsId(referenceComponent));
381
						Util.getComponentVersionsId(referenceComponent));
383
			}
382
			}
383
			if (referenceBaseline == null || baseline == null) {
384
				throw new IllegalArgumentException("The baselines cannot be null"); //$NON-NLS-1$
385
			}
384
			String referenceComponentId = referenceComponent.getId();
386
			String referenceComponentId = referenceComponent.getId();
385
			final Delta globalDelta = new Delta();
387
			final Delta globalDelta = new Delta();
386
	
388
	
Lines 443-449 Link Here
443
			final int visibilityModifiers) {
445
			final int visibilityModifiers) {
444
446
445
		try {
447
		try {
446
			return compare(referenceComponent, component, referenceComponent.getBaseline(), component.getBaseline(), visibilityModifiers);
448
			return compare(referenceComponent, component, referenceComponent == null ? null : referenceComponent.getBaseline(), component.getBaseline(), visibilityModifiers);
447
		} catch (CoreException e) {
449
		} catch (CoreException e) {
448
			ApiPlugin.log(e);
450
			ApiPlugin.log(e);
449
		}
451
		}
Lines 665-670 Link Here
665
	 * @param baseline the given API baseline to compare with
667
	 * @param baseline the given API baseline to compare with
666
	 * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison
668
	 * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison
667
	 * @param force a flag to force the comparison of nested API components with the same versions 
669
	 * @param force a flag to force the comparison of nested API components with the same versions 
670
	 * @param monitor the given progress monitor to report progress
668
	 *
671
	 *
669
	 * @return a delta, an empty delta if no difference is found or null if the delta detection failed
672
	 * @return a delta, an empty delta if no difference is found or null if the delta detection failed
670
	 * @throws IllegalArgumentException if one of the two baselines is null
673
	 * @throws IllegalArgumentException if one of the two baselines is null
Lines 674-685 Link Here
674
			final IApiScope scope,
677
			final IApiScope scope,
675
			final IApiBaseline baseline,
678
			final IApiBaseline baseline,
676
			final int visibilityModifiers,
679
			final int visibilityModifiers,
677
			final boolean force) throws CoreException {
680
			final boolean force,
681
			final IProgressMonitor monitor) throws CoreException {
678
		if (scope == null || baseline == null) {
682
		if (scope == null || baseline == null) {
679
			throw new IllegalArgumentException("None of the scope or the baseline must be null"); //$NON-NLS-1$
683
			throw new IllegalArgumentException("None of the scope or the baseline must be null"); //$NON-NLS-1$
680
		}
684
		}
685
		IProgressMonitor localMonitor = null;
686
		if (monitor == null) {
687
			localMonitor = new NullProgressMonitor();
688
		} else {
689
			localMonitor = monitor;
690
		}
681
		final Set deltas = new HashSet();
691
		final Set deltas = new HashSet();
682
		final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, force, visibilityModifiers);
692
		final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, force, visibilityModifiers, localMonitor);
683
		scope.accept(visitor);
693
		scope.accept(visitor);
684
		if (visitor.containsError()) {
694
		if (visitor.containsError()) {
685
			return null;
695
			return null;
Lines 711-716 Link Here
711
		}
721
		}
712
		return globalDelta.isEmpty() ? NO_DELTA : globalDelta;
722
		return globalDelta.isEmpty() ? NO_DELTA : globalDelta;
713
	}
723
	}
724
725
	/**
726
	 * Returns a delta that corresponds to the comparison of the two given API baselines. 
727
	 * Nested API components with the same versions are not compared.
728
	 * <p>Equivalent to: compare(baseline, baseline2, visibilityModifiers, force, null);</p>
729
	 * 
730
	 * @param scope the given scope for the comparison
731
	 * @param baseline the given API baseline to compare with
732
	 * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison
733
	 * @param force a flag to force the comparison of nested API components with the same versions 
734
	 *
735
	 * @return a delta, an empty delta if no difference is found or null if the delta detection failed
736
	 * @throws IllegalArgumentException if one of the two baselines is null
737
	 *         CoreException if one of the element in the scope cannot be visited
738
	 */
739
	public static IDelta compare(
740
			final IApiScope scope,
741
			final IApiBaseline baseline,
742
			final int visibilityModifiers,
743
			final boolean force) throws CoreException {
744
		return compare(scope, baseline, visibilityModifiers, force, null);
745
	}
714
	/**
746
	/**
715
	 * Returns a delta that corresponds to the comparison of the two given API baselines. 
747
	 * Returns a delta that corresponds to the comparison of the two given API baselines. 
716
	 * Nested API components with the same versions are not compared.
748
	 * Nested API components with the same versions are not compared.
(-)src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java (-44 / +79 lines)
Lines 13-18 Link Here
13
import java.util.Set;
13
import java.util.Set;
14
14
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
17
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
17
import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor;
18
import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor;
18
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
19
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
Lines 20-25 Link Here
20
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
21
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
21
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
22
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
22
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
23
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
24
import org.eclipse.pde.api.tools.internal.util.Util;
23
25
24
/**
26
/**
25
 * ApiScope visitor implementation to run the comparison on all elements of the scope.
27
 * ApiScope visitor implementation to run the comparison on all elements of the scope.
Lines 31-102 Link Here
31
	int visibilityModifiers;
33
	int visibilityModifiers;
32
	boolean force;
34
	boolean force;
33
	boolean containsErrors = false;
35
	boolean containsErrors = false;
36
	IProgressMonitor monitor;
34
37
35
	public CompareApiScopeVisitor(final Set deltas, final IApiBaseline baseline, final boolean force, final int visibilityModifiers) {
38
	public CompareApiScopeVisitor(
39
			final Set deltas,
40
			final IApiBaseline baseline,
41
			final boolean force,
42
			final int visibilityModifiers,
43
			final IProgressMonitor monitor) {
36
		this.deltas = deltas;
44
		this.deltas = deltas;
37
		this.referenceBaseline = baseline;
45
		this.referenceBaseline = baseline;
38
		this.visibilityModifiers = visibilityModifiers;
46
		this.visibilityModifiers = visibilityModifiers;
39
		this.force = force;
47
		this.force = force;
48
		this.monitor = monitor;
40
	}
49
	}
41
	
50
	
42
	public boolean visit(IApiBaseline baseline) throws CoreException {
51
	public boolean visit(IApiBaseline baseline) throws CoreException {
43
		IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers, this.force);
52
		try {
44
		if (delta != null) {
53
			Util.checkCanceled(this.monitor);
45
			delta.accept(new DeltaVisitor() {
54
			IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers, this.force);
46
				public void endVisit(IDelta localDelta) {
55
			if (delta != null) {
47
					if (localDelta.getChildren().length == 0) {
56
				delta.accept(new DeltaVisitor() {
48
						CompareApiScopeVisitor.this.deltas.add(localDelta);
57
					public void endVisit(IDelta localDelta) {
58
						if (localDelta.getChildren().length == 0) {
59
							CompareApiScopeVisitor.this.deltas.add(localDelta);
60
						}
49
					}
61
					}
50
				}
62
				});
51
			});
63
			} else {
52
		} else {
64
				this.containsErrors = true;
53
			this.containsErrors = true;
65
			}
66
			return false;
67
		} finally {
68
			this.monitor.worked(1);
54
		}
69
		}
55
		return false;
56
	}
70
	}
57
71
58
	public boolean visit(IApiTypeContainer container) throws CoreException {
72
	public boolean visit(IApiTypeContainer container) throws CoreException {
59
		container.accept(new ApiTypeContainerVisitor() {
73
		try {
60
			public void visit(String packageName, IApiTypeRoot typeroot) {
74
			Util.checkCanceled(this.monitor);
61
				try {
75
			container.accept(new ApiTypeContainerVisitor() {
62
					CompareApiScopeVisitor.this.visit(typeroot);
76
				public void visit(String packageName, IApiTypeRoot typeroot) {
63
				} catch (CoreException e) {
77
					try {
64
					ApiPlugin.log(e);
78
						Util.checkCanceled(CompareApiScopeVisitor.this.monitor);
79
						compareApiTypeRoot(typeroot);
80
					} catch (CoreException e) {
81
						ApiPlugin.log(e);
82
					}
65
				}
83
				}
66
			}
84
			});
67
		});
85
			return false;
68
		return false;
86
		} finally {
87
			this.monitor.worked(1);
88
		}
69
	}
89
	}
70
90
71
	public boolean visit(IApiComponent component) throws CoreException {
91
	public boolean visit(IApiComponent component) throws CoreException {
72
		if (component.getErrors() != null) {
92
		try {
73
			this.containsErrors = true;
93
			Util.checkCanceled(this.monitor);
74
			return false;
94
			if (component.getErrors() != null) {
75
		}
95
				this.containsErrors = true;
76
		IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId());
96
				return false;
77
		if (referenceComponent.getErrors() != null) {
97
			}
78
			this.containsErrors = true;
98
			IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId());
79
			return false;
99
			if (referenceComponent != null && referenceComponent.getErrors() != null) {
80
		}
100
				this.containsErrors = true;
81
		if (component.isSourceComponent() || component.isSystemComponent()) {
101
				return false;
82
			return false;
102
			}
83
		}
103
			if (component.isSourceComponent() || component.isSystemComponent()) {
84
		IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers);
104
				return false;
85
		if (delta != null) {
105
			}
86
			delta.accept(new DeltaVisitor() {
106
			Util.checkCanceled(this.monitor);
87
				public void endVisit(IDelta localDelta) {
107
			IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers);
88
					if (localDelta.getChildren().length == 0) {
108
			if (delta != null) {
89
						CompareApiScopeVisitor.this.deltas.add(localDelta);
109
				delta.accept(new DeltaVisitor() {
110
					public void endVisit(IDelta localDelta) {
111
						if (localDelta.getChildren().length == 0) {
112
							CompareApiScopeVisitor.this.deltas.add(localDelta);
113
						}
90
					}
114
					}
91
				}
115
				});
92
			});
116
			} else {
93
		} else {
117
				this.containsErrors = true;
94
			this.containsErrors = true;
118
			}
119
			return false;
120
		} finally {
121
			this.monitor.worked(1);
95
		}
122
		}
96
		return false;
97
	}
123
	}
98
	
124
	
99
	public void visit(IApiTypeRoot root) throws CoreException {
125
	public void visit(IApiTypeRoot root) throws CoreException {
126
		try {
127
			Util.checkCanceled(this.monitor);
128
			compareApiTypeRoot(root);
129
		} finally {
130
			this.monitor.worked(1);
131
		}
132
	}
133
134
	void compareApiTypeRoot(IApiTypeRoot root) throws CoreException {
100
		IApiComponent apiComponent = root.getApiComponent();
135
		IApiComponent apiComponent = root.getApiComponent();
101
		if (apiComponent == null || apiComponent.isSystemComponent() || apiComponent.isSourceComponent()) {
136
		if (apiComponent == null || apiComponent.isSystemComponent() || apiComponent.isSourceComponent()) {
102
			return;
137
			return;
(-)src/org/eclipse/pde/api/tools/internal/SessionManager.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal;
12
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.Iterator;
16
import java.util.List;
17
import java.util.Set;
18
19
import org.eclipse.pde.api.tools.internal.provisional.ISession;
20
import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
21
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
22
23
/**
24
 * Implementation of the ISessionManager.
25
 * Synchronize all accesses to prevent concurrent modifications.
26
 */
27
public class SessionManager implements ISessionManager {
28
29
	// use a list so that we can preserve the order
30
	private List sessions = new ArrayList();
31
	private Set listeners = new HashSet();
32
	private ISession activeSession;
33
34
	public synchronized void addSession(ISession session, boolean activate) {
35
		if (session == null) {
36
			throw new IllegalArgumentException("The given session cannot be null"); //$NON-NLS-1$
37
		}
38
		if (!this.sessions.contains(session)) {
39
			this.sessions.add(session);
40
			fireSessionAdded(session);
41
		}
42
		if (activate) {
43
			this.activeSession = session;
44
			fireSessionActivated(session);
45
		}
46
	}
47
48
	public synchronized void removeSession(ISession session) {
49
		if (sessions.remove(session)) {
50
			if (session.equals(this.activeSession)) {
51
				this.activeSession = null;
52
				fireSessionActivated(null);
53
			}
54
			fireSessionRemoved(session);
55
		}
56
	}
57
58
	public synchronized void removeAllSessions() {
59
		ISession[] allSessions = (ISession[]) this.sessions.toArray(new ISession[this.sessions.size()]);
60
		this.sessions.clear();
61
		this.activeSession = null;
62
		fireSessionActivated(null);
63
		for (int i = 0; i < allSessions.length; i++) {
64
			ISession session = allSessions[i];
65
			fireSessionRemoved(session);
66
		}
67
	}
68
69
	public synchronized ISession[] getSessions() {
70
		return (ISession[]) sessions.toArray(new ISession[sessions.size()]);
71
	}
72
73
	public synchronized void addSessionListener(ISessionListener listener) {
74
		if (listener == null) throw new IllegalArgumentException("The given listener cannot be null"); //$NON-NLS-1$
75
		listeners.add(listener);
76
	}
77
78
	public synchronized void removeSessionListener(ISessionListener listener) {
79
		listeners.remove(listener);
80
	}
81
82
	protected synchronized void fireSessionAdded(ISession session) {
83
		Iterator i = listeners.iterator();
84
		while (i.hasNext()) {
85
			((ISessionListener) i.next()).sessionAdded(session);
86
		}
87
	}
88
89
	protected synchronized void fireSessionRemoved(ISession session) {
90
		Iterator i = listeners.iterator();
91
		while (i.hasNext()) {
92
			((ISessionListener) i.next()).sessionRemoved(session);
93
		}
94
	}
95
96
	public ISession getActiveSession() {
97
		return this.activeSession;
98
	}
99
100
	protected synchronized void fireSessionActivated(ISession session) {
101
		Iterator i = listeners.iterator();
102
		while (i.hasNext()) {
103
			((ISessionListener) i.next()).sessionActivated(session);
104
		}
105
	}
106
107
	public void activateSession(ISession session) {
108
		if (this.sessions.contains(session) && !session.equals(this.activeSession)) {
109
			this.activeSession = session;
110
			fireSessionActivated(session);
111
		}
112
	}
113
}
(-)src/org/eclipse/pde/api/tools/internal/provisional/ITreeNode.java (+24 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal.provisional;
12
13
public interface ITreeNode {
14
	public static final int CLASS = 1;
15
	public static final int INTERFACE = 2;
16
	public static final int ANNOTATION = 3;
17
	public static final int ENUM = 4;
18
	public static final int PACKAGE = 5;
19
20
	Object[] getChildren();
21
	boolean hasChildren();
22
	int getId();
23
	Object getData();
24
}
(-)src/org/eclipse/pde/api/tools/internal/provisional/ITreeModel.java (+15 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal.provisional;
12
13
public interface ITreeModel {
14
	public ITreeNode getRoot();
15
}
(-)src/org/eclipse/pde/api/tools/internal/provisional/ISession.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal.provisional;
12
13
/**
14
 * Provide information about the API Tooling session.
15
 */
16
public interface ISession {
17
	
18
	public ITreeModel getModel();
19
	
20
	public String getTimestamp();
21
}
(-)xslt/compare.xsl (+141 lines)
Added Link Here
1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!--
3
	Copyright (c) IBM Corporation and others 2009. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page.
4
	
5
	All Platform Debug contexts, those for org.eclipse.debug.ui, are located in this file
6
	All contexts are grouped by their relation, with all relations grouped alphabetically.
7
-->
8
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
9
<xsl:output
10
               xmlns="http://www.w3.org/1999/xhtml"
11
               method="xml"
12
               encoding="ISO-8859-1"
13
               media-type="text/html"
14
               doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
15
               doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
16
               indent="yes"/>
17
<xsl:template match="/">
18
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
19
	<head>
20
	<title>Compare Details</title>
21
		<style type="text/css">
22
			table {
23
				border-style: solid;
24
				border-width: 1px;
25
				border-color: #666666;
26
				border-collapse: collapse;
27
			}
28
			tbody {
29
				display:block
30
			}
31
			td {
32
				border-style: solid;
33
				border-width: 1px;
34
				border-color: #666666;
35
			}
36
			a {
37
				text-decoration: none;
38
				font-weight: bold;
39
			}
40
			.link {
41
				color:black;
42
			}
43
			.vis {
44
				display:block;
45
			}
46
			.vis tr {
47
					border-style: solid;
48
					border-width: 1px;
49
					border-color: #666666;
50
			}
51
			.vis th {
52
					border-style: solid;
53
					border-width: 1px;
54
					border-color: #666666;
55
					background-color:#CC9933
56
			}
57
		</style>
58
		<script type="text/javascript">
59
		<xsl:text disable-output-escaping="yes">&lt;</xsl:text>!-- Begin
60
			var element=false;
61
			function hideall() {
62
				var tBodyElements = document.getElementsByTagName('tbody');
63
				for (i=0;i <xsl:text disable-output-escaping="yes">&lt;</xsl:text> tBodyElements.length;i++) {
64
					tBodyElements[i].style.display='none';
65
				}
66
			}
67
68
			function showHide(tBodyID,link) {
69
				element=document.getElementById(tBodyID);
70
				if (element.style.display=='none') {
71
					document.getElementById(link).innerHTML=' - ';
72
					element.style.display='block';
73
				} else {
74
					document.getElementById(link).innerHTML=' + ';
75
					element.style.display='none';
76
				}
77
			}
78
			onload=hideall;
79
		// End --<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
80
		</script>
81
	</head>
82
	<body>
83
		<div align="left">
84
			<xsl:apply-templates select="deltas"/>
85
		</div>
86
		<p>
87
			<a href="http://validator.w3.org/check?uri=referer">
88
				<img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Strict" height="31" width="88"/>
89
			</a>
90
		</p>
91
	</body>
92
</html>
93
</xsl:template>
94
<xsl:template match="deltas">
95
	<table>
96
		<thead>
97
			<tr class="vis">
98
				<th class="vis">
99
					<span onclick="showHide('breaking', 'breakingspan')">
100
						<span id="breakingspan" class="link" > + </span> List of breaking changes
101
					</span>
102
				</th>
103
			</tr>
104
		</thead>
105
		<tbody id="breaking">
106
			<xsl:for-each select="delta">
107
				<xsl:if test="(@compatible='false')">
108
					<tr>
109
						<td>
110
							<xsl:value-of disable-output-escaping="yes" select="@message"/>
111
						</td>
112
					</tr>
113
				</xsl:if>
114
			</xsl:for-each>
115
		</tbody>
116
	</table>
117
	<p></p>
118
	<table>
119
		<thead>
120
			<tr class="vis">
121
				<th class="vis">
122
					<span onclick="showHide('compatible', 'compatiblespan')">
123
						<span id="compatiblespan" class="link"> + </span> List of compatible changes
124
					</span>
125
				</th>
126
			</tr>
127
		</thead>
128
		<tbody id="compatible">
129
			<xsl:for-each select="delta">
130
				<xsl:if test="(@compatible='true')">
131
					<tr>
132
						<td>
133
							<xsl:value-of disable-output-escaping="yes" select="@message"/>
134
						</td>
135
					</tr>
136
				</xsl:if>
137
			</xsl:for-each>
138
		</tbody>
139
	</table>
140
</xsl:template>
141
</xsl:stylesheet>
(-)src/org/eclipse/pde/api/tools/internal/provisional/ISessionListener.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal.provisional;
12
13
14
15
/**
16
 * Listener interface for changes of the session manager.
17
 * 
18
 * @see ISessionManager#addSessionListener(ISessionListener)
19
 * @see ISessionManager#removeSessionListener(ISessionListener)
20
 */
21
public interface ISessionListener {
22
23
	/**
24
	 * Called when a session has been added.
25
	 * 
26
	 * @param addedSession the given added session
27
	 */  
28
	public void sessionAdded(ISession addedSession);
29
30
	/**
31
	 * Called when a session has been removed.
32
	 * 
33
	 * @param removedSession the given removed session
34
	 */
35
	public void sessionRemoved(ISession removedSession);
36
	
37
	/**
38
	 * Called when a new session has been activated or the last session has been
39
	 * removed. In this case <code>null</code> is passed as a parameter.
40
	 * 
41
	 * @param session the given activated session or <code>null</code>
42
	 */
43
	public void sessionActivated(ISession session);
44
}
(-)src/org/eclipse/pde/api/tools/internal/provisional/ISessionManager.java (+80 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.internal.provisional;
12
13
/**
14
 * The session manager holds a list of currently available sessions.
15
 *
16
 * @noimplement This interface is not intended to be implemented by clients.
17
 * @noextend This interface is not intended to be extended by clients.
18
 */
19
public interface ISessionManager {
20
21
	/**
22
	 * Adds the given session to this session manager. If the session is already
23
	 * part of this session manager, the method has no effect.
24
	 * 
25
	 * @param session the new session
26
	 * @param activate if <code>true</code> the session will also be activated, <code>false</code> otherwise
27
	 * @throws IllegalArgumentException if the given session is null
28
	 */
29
	public void addSession(ISession session, boolean activate);
30
31
	/**
32
	 * Removes the given session. If the session is not in included in this
33
	 * session manager, this method has no effect.
34
	 * 
35
	 * @param session the given session to remove
36
	 */
37
	public void removeSession(ISession session);
38
39
	/**
40
	 * Removes all available sessions.
41
	 */
42
	public void removeAllSessions();
43
44
	/**
45
	 * Returns all available sessions registered with this session manager.
46
	 * 
47
	 * @return list of available sessions
48
	 */
49
	public ISession[] getSessions();
50
51
	/**
52
	 * Adds the given session listener unless it has been added before.
53
	 * 
54
	 * @param listener the given session listener to add
55
	 * @throws IllegalArgumentException if the given listener is null
56
	 */
57
	public void addSessionListener(ISessionListener listener);
58
59
	/**
60
	 * Removes the given session listener. If the listener has not been added
61
	 * before this method has no effect.
62
	 * 
63
	 * @param listener the given session listener to remove
64
	 */
65
	public void removeSessionListener(ISessionListener listener);
66
67
	/**
68
	 * Returns the active session or <code>null</code> if there is no session.
69
	 * 
70
	 * @return active session or <code>null</null>
71
	 */
72
	public ISession getActiveSession();
73
	/**
74
	 * Activates the given session. If the session is not in included in this
75
	 * session manager this method has no effect.
76
	 * 
77
	 * @param session the given session or <code>null</code> to remove the active session.
78
	 */
79
	public void activateSession(ISession session);
80
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java (-1 / +40 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
public class ActionMessages extends NLS {
18
public class ActionMessages extends NLS {
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.actions.actionmessages"; //$NON-NLS-1$
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.actions.actionmessages"; //$NON-NLS-1$
20
	public static String ApiToolingSetupObjectContribution_0;
20
	public static String ApiToolingSetupObjectContribution_0;
21
	public static String SelectABaseline;
22
	public static String SetAsDefault;
23
	public static String EnterFileName;
24
	public static String SelectFileName;
25
	public static String Browse;
26
	public static String ConvertToHtml;
27
	public static String CompareDialogTitle;
28
	public static String CompareDialogCollectingElementTaskName;
29
	public static String CompareDialogComputeDeltasTaskName;
30
	public static String CompareWithAction_comparing_apis;
31
	public static String CompareTaskNoChanges;
32
	public static String RemoveActiveSessionAction_label;
33
	public static String RemoveActiveSessionAction_tooltip;
34
	public static String RemoveAllSessionsAction_label;
35
	public static String RemoveAllSessionsAction_tooltip;
36
	public static String SelectSessionAction_label;
37
	public static String SelectSessionAction_tooltip;
38
	public static String SelectSessionActionEntry_label;
39
	public static String DeltaDetailsDialogTitle;
40
	public static String ExportSessionAction_label;
41
	public static String ExportSessionAction_tooltip;
42
	public static String EnterFileNameForExport;
43
	public static String ExportActionTitle;
44
	public static String PropertyPackageVisibility;
45
46
	public static String PropertyMessageKey;
47
	public static String PropertyComponentKey;
48
	public static String PropertyElementTypeKey;
49
	public static String PropertyFlagsKey;
50
	public static String PropertyKeyKey;
51
	public static String PropertyKindKey;
52
	public static String PropertyNewModifiersKey;
53
	public static String PropertyOldModifiersKey;
54
	public static String PropertyRestrictionsKey;
55
	public static String PropertyTypeNameKey;
56
57
	public static String MessageCategory;
58
	public static String InfoCategory;
59
21
	static {
60
	static {
22
		// initialize resource bundle
61
		// initialize resource bundle
23
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
62
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties (-1 / +41 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2008 IBM Corporation and others.
2
# Copyright (c) 2008, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 9-11 Link Here
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
ApiToolingSetupObjectContribution_0=Set up API tooling
11
ApiToolingSetupObjectContribution_0=Set up API tooling
12
SelectABaseline=Select a &baseline:
13
SetAsDefault={0} (default)
14
EnterFileName=Report &location:
15
SelectFileName=Select a report location
16
Browse=Bro&wse...
17
ConvertToHtml=Con&vert to html
18
CompareDialogTitle=Compare With Baseline
19
CompareDialogCollectingElementTaskName=Collecting elements to compare
20
CompareDialogComputeDeltasTaskName=Computing deltas...
21
CompareWithAction_comparing_apis=Comparing APIs...
22
CompareTaskNoChanges=No changes have been found
23
RemoveActiveSessionAction_label=Remove Active Session
24
RemoveActiveSessionAction_tooltip=Remove Active Session
25
RemoveAllSessionsAction_label=Remove All Sessions
26
RemoveAllSessionsAction_tooltip=Remove All Sessions
27
SelectSessionAction_label=Select Session
28
SelectSessionAction_tooltip=Select Session
29
# {0} int value
30
# {1} timestamp
31
SelectSessionActionEntry_label=Session {0} ({1})
32
DeltaDetailsDialogTitle=Delta Details
33
ExportSessionAction_label=Export Session
34
ExportSessionAction_tooltip=Export Session
35
EnterFileNameForExport=Enter a file name for export:
36
ExportActionTitle=Export Active Session
37
38
PropertyMessageKey=localized message
39
PropertyComponentKey=component
40
PropertyPackageVisibility=<package visibility>
41
PropertyElementTypeKey=element type
42
PropertyFlagsKey=flags
43
PropertyKeyKey=key
44
PropertyKindKey=kind
45
PropertyNewModifiersKey=new modifiers
46
PropertyOldModifiersKey=old modifiers
47
PropertyRestrictionsKey=restrictions
48
PropertyTypeNameKey=type name
49
50
MessageCategory=Message
51
InfoCategory=Info
(-)src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java (-145 / +183 lines)
Lines 23-31 Link Here
23
import org.eclipse.jface.dialogs.IDialogSettings;
23
import org.eclipse.jface.dialogs.IDialogSettings;
24
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.resource.ImageRegistry;
25
import org.eclipse.jface.resource.ImageRegistry;
26
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
27
import org.eclipse.pde.api.tools.internal.provisional.ISession;
28
import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
29
import org.eclipse.pde.api.tools.ui.internal.views.APIToolingView;
26
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.IViewPart;
33
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchWindow;
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.PartInitException;
29
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.PlatformUI;
30
import org.eclipse.ui.plugin.AbstractUIPlugin;
37
import org.eclipse.ui.plugin.AbstractUIPlugin;
31
import org.osgi.framework.Bundle;
38
import org.osgi.framework.Bundle;
Lines 38-87 Link Here
38
 * @since 1.0.0
45
 * @since 1.0.0
39
 */
46
 */
40
public class ApiUIPlugin extends AbstractUIPlugin {
47
public class ApiUIPlugin extends AbstractUIPlugin {
41
42
	/**
48
	/**
43
	 * Singleton plug-in
49
	 * Maps Image descriptors to images for composite images
44
	 */
45
	private static ApiUIPlugin fgDefault = null;
46
	
47
	/**
48
	 * The id of the plugin
49
	 */
50
	 */
50
	public static final String PLUGIN_ID = "org.eclipse.pde.api.tools.ui"; //$NON-NLS-1$
51
	private static Map fCompositeImages = new HashMap();
51
	
52
	
52
	/**
53
	/**
53
	 * Status code indicating an unexpected internal error.
54
	 * Singleton plug-in
54
	 */
55
	 */
55
	public static final int INTERNAL_ERROR = 120;
56
	private static ApiUIPlugin fgDefault = null;
56
	
57
	
57
	/**
58
	/**
58
	 * Root path to icon directories.
59
	 * Root path to icon directories.
59
	 */
60
	 */
60
	private static final String ICONS_PATH = "$nl$/icons/full/"; //$NON-NLS-1$
61
	private static final String ICONS_PATH = "$nl$/icons/full/"; //$NON-NLS-1$
62
63
	private static final String DLCL = ICONS_PATH + "dlcl16/"; //basic colors - size 16x16 disabled//$NON-NLS-1$
64
	
65
	private static final String ELCL = ICONS_PATH + "elcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
61
	
66
	
62
	/**
67
	/**
63
	 * Relative path to object model icons.
68
	 * Status code indicating an unexpected internal error.
64
	 */
69
	 */
65
	private final static String OBJECT= ICONS_PATH + "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
70
	public static final int INTERNAL_ERROR = 120;
66
	private final static String OVR= ICONS_PATH + "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
67
	private final static String WIZBAN= ICONS_PATH + "wizban/"; //basic colors - size 16x16 //$NON-NLS-1$
68
	private static final String ELCL= ICONS_PATH + "elcl16/"; 	//basic colors - size 16x16 //$NON-NLS-1$
69
	
70
	/**
71
	/**
71
	 * Maps Image descriptors to images for composite images
72
	 * Relative path to object model icons.
72
	 */
73
	 */
73
	private static Map fCompositeImages = new HashMap();
74
	private final static String OBJECT = ICONS_PATH + "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
74
	
75
	private final static String OVR = ICONS_PATH + "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
75
	/**
76
	/**
76
	 * This bundle's OSGi context
77
	 * The id of the plugin
77
	 */
78
	 */
78
	private BundleContext fBundleContext = null;
79
	public static final String PLUGIN_ID = "org.eclipse.pde.api.tools.ui"; //$NON-NLS-1$
80
	private final static String WIZBAN = ICONS_PATH + "wizban/"; //basic colors - size 16x16 //$NON-NLS-1$
79
	
81
	
80
	/**
82
	/**
81
	 * Constructor
83
	 * Declare an Image in the registry table.
84
	 * @param reg	image registry
85
	 * @param key 	The key to use when registering the image
86
	 * @param path	The path where the image can be found. This path is relative to where
87
	 *				this plug-in class is found (i.e. typically the packages directory)
82
	 */
88
	 */
83
	public ApiUIPlugin() {
89
	private final static void declareRegistryImage(ImageRegistry reg, String key, String path) {
84
		fgDefault = this;
90
		ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
91
		Bundle bundle = Platform.getBundle(IApiToolsConstants.ID_API_TOOLS_UI_PLUGIN);
92
		URL url = null;
93
		if (bundle != null){
94
			url = FileLocator.find(bundle, new Path(path), null);
95
			desc = ImageDescriptor.createFromURL(url);
96
		}
97
		reg.put(key, desc);
85
	}
98
	}
86
	
99
	
87
	/**
100
	/**
Lines 97-142 Link Here
97
	}
110
	}
98
	
111
	
99
	/**
112
	/**
100
	 * Returns dialog settings with the given name, creating a new section
113
	 * Returns the image associated with the given image descriptor.
101
	 * if one does not exist.
102
	 * 
114
	 * 
103
	 * @param name section name
115
	 * @param descriptor the image descriptor for which there is a managed image
104
	 * @return dialog settings
116
	 * @return the image associated with the image descriptor or <code>null</code>
117
	 *  if the image descriptor can't create the requested image.
105
	 */
118
	 */
106
	public IDialogSettings getDialogSettingsSection(String name) {
119
	public static Image getImage(ImageDescriptor descriptor) {
107
		IDialogSettings dialogSettings= getDialogSettings();
120
		if (descriptor == null)
108
		IDialogSettings section= dialogSettings.getSection(name);
121
			descriptor= ImageDescriptor.getMissingImageDescriptor();
109
		if (section == null) {
122
			
110
			section= dialogSettings.addNewSection(name);
123
		Image result= (Image)fCompositeImages.get(descriptor);
111
		}
124
		if (result != null)
112
		return section;
125
			return result;
126
	 
127
		result= descriptor.createImage();
128
		if (result != null)
129
			fCompositeImages.put(descriptor, result);
130
		return result;
131
	}
132
	
133
	/**
134
	 * Returns an image descriptor from the registry with the given key or <code>null</code> if none.
135
	 * 
136
	 * @param key image key
137
	 * @return image descriptor or <code>null</code>
138
	 */
139
	public static ImageDescriptor getImageDescriptor(String key) {
140
		return getDefault().getImageRegistry().getDescriptor(key);
113
	}	
141
	}	
114
142
115
	/* (non-Javadoc)
143
	/**
116
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
144
	 * @return the id of this plugin.
145
	 * Value is <code><org.eclipse.pde.api.tools.ui></code>
117
	 */
146
	 */
118
	protected void initializeImageRegistry(ImageRegistry reg) {
147
	public static String getPluginIdentifier() {
119
		// model objects
148
		return PLUGIN_ID;
120
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_COMPONENT, OBJECT + "api_tools.gif"); //$NON-NLS-1$
121
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_SYSTEM_LIBRARY, OBJECT + "library_obj.gif"); //$NON-NLS-1$
122
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_SEARCH, OBJECT + "extract_references.gif"); //$NON-NLS-1$
123
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_BUNDLE, OBJECT + "plugin_obj.gif"); //$NON-NLS-1$
124
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_FRAGMENT, OBJECT + "frgmt_obj.gif"); //$NON-NLS-1$
125
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_ECLIPSE_PROFILE, OBJECT + "eclipse_profile.gif"); //$NON-NLS-1$
126
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_BUNDLE_VERSION, OBJECT + "bundleversion.gif"); //$NON-NLS-1$
127
		// overlays
128
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_ERROR, OVR + "error_ovr.gif"); //$NON-NLS-1$
129
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_WARNING, OVR + "warning_ovr.gif"); //$NON-NLS-1$
130
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_SUCCESS, OVR + "success_ovr.gif"); //$NON-NLS-1$
131
		// wizards
132
		declareRegistryImage(reg, IApiToolsConstants.IMG_WIZBAN_PROFILE, WIZBAN + "profile_wiz.png"); //$NON-NLS-1$
133
		// enabled images
134
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_FILTER, ELCL + "filter_ps.gif"); //$NON-NLS-1$
135
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_REMOVE, ELCL + "remove_exc.gif"); //$NON-NLS-1$
136
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_OPEN_PAGE, ELCL + "open_page.gif"); //$NON-NLS-1$
137
	}
149
	}
138
150
139
	/**
151
	/**
152
	 * Returns an image from the registry with the given key or <code>null</code> if none.
153
	 * 
154
	 * @param key image key
155
	 * @return image or <code>null</code>
156
	 */
157
	public static Image getSharedImage(String key) {
158
		return getDefault().getImageRegistry().get(key);
159
	}
160
	
161
	/**
162
	 * Returns the currently active workbench window shell or <code>null</code>
163
	 * if none.
164
	 * 
165
	 * @return the currently active workbench window shell or <code>null</code>
166
	 */
167
	public static Shell getShell() {
168
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
169
		if (window == null) {
170
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
171
			if (windows.length > 0) {
172
				return windows[0].getShell();
173
			}
174
		} 
175
		else {
176
			return window.getShell();
177
		}
178
		return null;
179
	}
180
	
181
	/**
140
	 * Logs the specified status with this plug-in's log.
182
	 * Logs the specified status with this plug-in's log.
141
	 * 
183
	 * 
142
	 * @param status status to log
184
	 * @param status status to log
Lines 183-306 Link Here
183
	}
225
	}
184
	
226
	
185
	/**
227
	/**
186
	 * Returns the currently active workbench window shell or <code>null</code>
228
	 * This bundle's OSGi context
187
	 * if none.
188
	 * 
189
	 * @return the currently active workbench window shell or <code>null</code>
190
	 */
191
	public static Shell getShell() {
192
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
193
		if (window == null) {
194
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
195
			if (windows.length > 0) {
196
				return windows[0].getShell();
197
			}
198
		} 
199
		else {
200
			return window.getShell();
201
		}
202
		return null;
203
	}
204
	
205
	/**
206
	 * @return the id of this plugin.
207
	 * Value is <code><org.eclipse.pde.api.tools.ui></code>
208
	 */
229
	 */
209
	public static String getPluginIdentifier() {
230
	private BundleContext fBundleContext = null;
210
		return PLUGIN_ID;
211
	}
212
	
231
	
213
	/**
232
	private ISessionListener sessionListener = new ISessionListener() {
214
	 * Declare an Image in the registry table.
233
		public void sessionAdded(ISession addedSession) {
215
	 * @param reg	image registry
234
			getWorkbench().getDisplay().asyncExec(new Runnable() {
216
	 * @param key 	The key to use when registering the image
235
				public void run() {
217
	 * @param path	The path where the image can be found. This path is relative to where
236
					showAPIToolingView();
218
	 *				this plug-in class is found (i.e. typically the packages directory)
237
				}
219
	 */
238
			});
220
	private final static void declareRegistryImage(ImageRegistry reg, String key, String path) {
221
		ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
222
		Bundle bundle = Platform.getBundle(IApiToolsConstants.ID_API_TOOLS_UI_PLUGIN);
223
		URL url = null;
224
		if (bundle != null){
225
			url = FileLocator.find(bundle, new Path(path), null);
226
			desc = ImageDescriptor.createFromURL(url);
227
		}
239
		}
228
		reg.put(key, desc);
240
		public void sessionRemoved(ISession removedSession) {
229
	}	
241
		}
230
	
242
		public void sessionActivated(ISession session) {
243
		}
244
	};
245
231
	/**
246
	/**
232
	 * Returns an image from the registry with the given key or <code>null</code> if none.
247
	 * Constructor
233
	 * 
234
	 * @param key image key
235
	 * @return image or <code>null</code>
236
	 */
248
	 */
237
	public static Image getSharedImage(String key) {
249
	public ApiUIPlugin() {
238
		return getDefault().getImageRegistry().get(key);
250
		fgDefault = this;
239
	}
251
	}
240
	
252
	
241
	/**
253
	/**
242
	 * Returns the image associated with the given image descriptor.
254
	 * Returns a service with the specified name or <code>null</code> if none.
243
	 * 
255
	 * 
244
	 * @param descriptor the image descriptor for which there is a managed image
256
	 * @param serviceName name of service
245
	 * @return the image associated with the image descriptor or <code>null</code>
257
	 * @return service object or <code>null</code> if none
246
	 *  if the image descriptor can't create the requested image.
247
	 */
258
	 */
248
	public static Image getImage(ImageDescriptor descriptor) {
259
	public Object acquireService(String serviceName) {
249
		if (descriptor == null)
260
		ServiceReference reference = fBundleContext.getServiceReference(serviceName);
250
			descriptor= ImageDescriptor.getMissingImageDescriptor();
261
		if (reference == null)
251
			
262
			return null;
252
		Image result= (Image)fCompositeImages.get(descriptor);
263
		return fBundleContext.getService(reference);
253
		if (result != null)
254
			return result;
255
	 
256
		result= descriptor.createImage();
257
		if (result != null)
258
			fCompositeImages.put(descriptor, result);
259
		return result;
260
	}
264
	}
261
	
265
	
262
	/**
266
	/**
263
	 * Returns an image descriptor from the registry with the given key or <code>null</code> if none.
267
	 * Returns dialog settings with the given name, creating a new section
268
	 * if one does not exist.
264
	 * 
269
	 * 
265
	 * @param key image key
270
	 * @param name section name
266
	 * @return image descriptor or <code>null</code>
271
	 * @return dialog settings
267
	 */
272
	 */
268
	public static ImageDescriptor getImageDescriptor(String key) {
273
	public IDialogSettings getDialogSettingsSection(String name) {
269
		return getDefault().getImageRegistry().getDescriptor(key);
274
		IDialogSettings dialogSettings= getDialogSettings();
275
		IDialogSettings section= dialogSettings.getSection(name);
276
		if (section == null) {
277
			section= dialogSettings.addNewSection(name);
278
		}
279
		return section;
270
	}
280
	}
271
281
272
	/* (non-Javadoc)
282
	/* (non-Javadoc)
273
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
283
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
274
	 */
284
	 */
275
	public void stop(BundleContext context) throws Exception {
285
	protected void initializeImageRegistry(ImageRegistry reg) {
276
		// dispose composite images
286
		// model objects
277
		for (Iterator iter= fCompositeImages.values().iterator(); iter.hasNext(); ) {
287
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_COMPONENT, OBJECT + "api_tools.gif"); //$NON-NLS-1$
278
			Image image= (Image)iter.next();
288
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_SYSTEM_LIBRARY, OBJECT + "library_obj.gif"); //$NON-NLS-1$
279
			image.dispose();
289
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_API_SEARCH, OBJECT + "extract_references.gif"); //$NON-NLS-1$
290
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_BUNDLE, OBJECT + "plugin_obj.gif"); //$NON-NLS-1$
291
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_FRAGMENT, OBJECT + "frgmt_obj.gif"); //$NON-NLS-1$
292
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_ECLIPSE_PROFILE, OBJECT + "eclipse_profile.gif"); //$NON-NLS-1$
293
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_BUNDLE_VERSION, OBJECT + "bundleversion.gif"); //$NON-NLS-1$
294
295
		// overlays
296
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_ERROR, OVR + "error_ovr.gif"); //$NON-NLS-1$
297
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_WARNING, OVR + "warning_ovr.gif"); //$NON-NLS-1$
298
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_SUCCESS, OVR + "success_ovr.gif"); //$NON-NLS-1$
299
		// wizards
300
		declareRegistryImage(reg, IApiToolsConstants.IMG_WIZBAN_PROFILE, WIZBAN + "profile_wiz.png"); //$NON-NLS-1$
301
		// enabled images
302
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_FILTER, ELCL + "filter_ps.gif"); //$NON-NLS-1$
303
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_REMOVE, ELCL + "remove_exc.gif"); //$NON-NLS-1$
304
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_OPEN_PAGE, ELCL + "open_page.gif"); //$NON-NLS-1$
305
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_COMPARE_APIS, ELCL + "compare_apis.gif"); //$NON-NLS-1$
306
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_COMPARE_APIS_DISABLED, DLCL + "compare_apis.gif"); //$NON-NLS-1$
307
	}
308
	void showAPIToolingView() {
309
		IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
310
		if (window == null) return;
311
		IWorkbenchPage page = window.getActivePage();
312
		if (page != null) {
313
			try {
314
				IViewPart view = page.showView(APIToolingView.ID, null, IWorkbenchPage.VIEW_CREATE);
315
				page.bringToTop(view);
316
			} catch (PartInitException e) {
317
				log(e);
318
			}
280
		}
319
		}
281
		fCompositeImages.clear();
282
		fBundleContext = null;
283
		super.stop(context);
284
	}
320
	}
285
	
286
	/* (non-Javadoc)
321
	/* (non-Javadoc)
287
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
322
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
288
	 */
323
	 */
289
	public void start(BundleContext context) throws Exception {
324
	public void start(BundleContext context) throws Exception {
290
		fBundleContext = context;
325
		fBundleContext = context;
326
		ApiPlugin.getDefault().getSessionManager().addSessionListener(this.sessionListener);
291
		super.start(context);
327
		super.start(context);
292
	}
328
	}
293
	
329
	
294
	/**
330
	/* (non-Javadoc)
295
	 * Returns a service with the specified name or <code>null</code> if none.
331
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
296
	 * 
297
	 * @param serviceName name of service
298
	 * @return service object or <code>null</code> if none
299
	 */
332
	 */
300
	public Object acquireService(String serviceName) {
333
	public void stop(BundleContext context) throws Exception {
301
		ServiceReference reference = fBundleContext.getServiceReference(serviceName);
334
		// dispose composite images
302
		if (reference == null)
335
		for (Iterator iter= fCompositeImages.values().iterator(); iter.hasNext(); ) {
303
			return null;
336
			Image image= (Image)iter.next();
304
		return fBundleContext.getService(reference);
337
			image.dispose();
338
		}
339
		fCompositeImages.clear();
340
		fBundleContext = null;
341
		ApiPlugin.getDefault().getSessionManager().removeSessionListener(this.sessionListener);
342
		super.stop(context);
305
	}
343
	}
306
}
344
}
(-)src/org/eclipse/pde/api/tools/ui/internal/IApiToolsConstants.java (-50 / +56 lines)
Lines 14-118 Link Here
14
 * @since 1.0.0
14
 * @since 1.0.0
15
 */
15
 */
16
public interface IApiToolsConstants {
16
public interface IApiToolsConstants {
17
17
	/**
18
	 * Empty String constant
19
	 */
20
	public static final String EMPTY_STRING = ""; //$NON-NLS-1$
18
	/**
21
	/**
19
	 * Plug-in identifier
22
	 * Plug-in identifier
20
	 */
23
	 */
21
	public static final String ID_API_TOOLS_UI_PLUGIN = "org.eclipse.pde.api.tools.ui"; //$NON-NLS-1$
24
	public static final String ID_API_TOOLS_UI_PLUGIN = "org.eclipse.pde.api.tools.ui"; //$NON-NLS-1$
22
	/**
25
	/**
23
	 * Empty String constant
26
	 * Id for the Api baselines preference page.
27
	 * <br>
28
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apiprofiles.prefpage</code>
24
	 */
29
	 */
25
	public static final String EMPTY_STRING = ""; //$NON-NLS-1$
30
	public static final String ID_BASELINES_PREF_PAGE = "org.eclipse.pde.api.tools.ui.apiprofiles.prefpage"; //$NON-NLS-1$
26
	/**
31
	/**
27
	 * Key for API component image.
32
	 * Id for the API errors / warnings preference page
33
	 * <br>
34
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.errorwarnings.prefpage</code> 
28
	 */
35
	 */
29
	public static final String IMG_OBJ_API_COMPONENT = "IMG_OBJ_API_COMPONENT"; //$NON-NLS-1$
36
	public static final String ID_ERRORS_WARNINGS_PREF_PAGE = "org.eclipse.pde.api.tools.ui.apitools.errorwarnings.prefpage"; //$NON-NLS-1$
37
	
30
	/**
38
	/**
31
	 * Key for API system component image
39
	 * The id for the API errors / warnings property page
40
	 * <br>
41
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.warningspage</code>
32
	 */
42
	 */
33
	public static final String IMG_OBJ_API_SYSTEM_LIBRARY = "IMG_OBJ_API_SYSTEM_LIBRARY"; //$NON-NLS-1$
43
	public static final String ID_ERRORS_WARNINGS_PROP_PAGE = "org.eclipse.pde.api.tools.ui.apitools.warningspage"; //$NON-NLS-1$
34
	
44
	
35
	/**
45
	/**
36
	 * Key for API search image
46
	 * The id for the API problem filters property page
47
	 * <br>
48
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.filterspage</code>
37
	 */
49
	 */
38
	public static final String IMG_OBJ_API_SEARCH = "IMG_OBJ_API_SEARCH"; //$NON-NLS-1$
50
	public static final String ID_FILTERS_PROP_PAGE = "org.eclipse.pde.api.tools.ui.apitools.filterspage"; //$NON-NLS-1$
39
	
51
	
40
	/**
52
	/**
41
	 * Key for bundle image
53
	 * Key for a compare api image
42
	 */
54
	 */
43
	public static final String IMG_OBJ_BUNDLE = "IMG_OBJ_BUNDLE"; //$NON-NLS-1$
55
	public static final String IMG_ELCL_COMPARE_APIS = "IMG_ELCL_COMPARE_APIS"; //$NON-NLS-1$
44
	
45
	/**
56
	/**
46
	 * Key for fragment image
57
	 * Key for a compare api disabled image
47
	 */
58
	 */
48
	public static final String IMG_OBJ_FRAGMENT = "IMG_OBJ_FRAGMENT"; //$NON-NLS-1$		
59
	public static final String IMG_ELCL_COMPARE_APIS_DISABLED = "IMG_ELCL_COMPARE_APIS_DISABLED"; //$NON-NLS-1$
49
	
50
	/**
60
	/**
51
	 * Key for Eclipse SDK/API profile image
61
	 * Key for filter resolution image
52
	 */
62
	 */
53
	public static final String IMG_OBJ_ECLIPSE_PROFILE = "IMG_OBJ_ECLIPSE_PROFILE"; //$NON-NLS-1$
63
	public static final String IMG_ELCL_FILTER = "IMG_ELCL_FILTER"; //$NON-NLS-1$
54
	
64
	
55
	/**
65
	/**
56
	 * Key for a bundle version image
66
	 * Key for the open page image
57
	 */
67
	 */
58
	public static final String IMG_OBJ_BUNDLE_VERSION = "IMG_OBJ_BUNDLE_VERSION"; //$NON-NLS-1$
68
	public static final String IMG_ELCL_OPEN_PAGE = "IMG_ELCL_OPEN_PAGE"; //$NON-NLS-1$
59
	
69
60
	/**
70
	/**
61
	 * Error overlay.
71
	 * Key for enabled remove image
62
	 */
72
	 */
63
	public static final String IMG_OVR_ERROR = "IMG_OVR_ERROR"; //$NON-NLS-1$
73
	public static final String IMG_ELCL_REMOVE = "IMG_ELCL_REMOVE"; //$NON-NLS-1$
64
	
74
	
65
	/**
75
	/**
66
	 * Warning overlay
76
	 * Key for API component image.
67
	 */
77
	 */
68
	public static final String IMG_OVR_WARNING = "IMG_OVR_WARNING"; //$NON-NLS-1$
78
	public static final String IMG_OBJ_API_COMPONENT = "IMG_OBJ_API_COMPONENT"; //$NON-NLS-1$
69
	
79
	
70
	/**
80
	/**
71
	 * Success overlay
81
	 * Key for API search image
72
	 */
82
	 */
73
	public static final String IMG_OVR_SUCCESS = "IMG_OVR_SUCCESS"; //$NON-NLS-1$
83
	public static final String IMG_OBJ_API_SEARCH = "IMG_OBJ_API_SEARCH"; //$NON-NLS-1$
74
	
84
	
75
	/**
85
	/**
76
	 * Wizard banner for editing an API profile
86
	 * Key for API system component image
77
	 */
87
	 */
78
	public static final String IMG_WIZBAN_PROFILE = "IMG_WIZBAN_PROFILE"; //$NON-NLS-1$
88
	public static final String IMG_OBJ_API_SYSTEM_LIBRARY = "IMG_OBJ_API_SYSTEM_LIBRARY"; //$NON-NLS-1$
79
	
89
	
80
	/**
90
	/**
81
	 * Id for the Api baselines preference page.
91
	 * Key for bundle image
82
	 * <br>
83
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apiprofiles.prefpage</code>
84
	 */
92
	 */
85
	public static final String ID_BASELINES_PREF_PAGE = "org.eclipse.pde.api.tools.ui.apiprofiles.prefpage"; //$NON-NLS-1$
93
	public static final String IMG_OBJ_BUNDLE = "IMG_OBJ_BUNDLE"; //$NON-NLS-1$
86
	/**
94
	/**
87
	 * Id for the API errors / warnings preference page
95
	 * Key for a bundle version image
88
	 * <br>
89
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.errorwarnings.prefpage</code> 
90
	 */
96
	 */
91
	public static final String ID_ERRORS_WARNINGS_PREF_PAGE = "org.eclipse.pde.api.tools.ui.apitools.errorwarnings.prefpage"; //$NON-NLS-1$
97
	public static final String IMG_OBJ_BUNDLE_VERSION = "IMG_OBJ_BUNDLE_VERSION"; //$NON-NLS-1$
92
	/**
98
	/**
93
	 * The id for the API problem filters property page
99
	 * Key for Eclipse SDK/API profile image
94
	 * <br>
95
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.filterspage</code>
96
	 */
100
	 */
97
	public static final String ID_FILTERS_PROP_PAGE = "org.eclipse.pde.api.tools.ui.apitools.filterspage"; //$NON-NLS-1$
101
	public static final String IMG_OBJ_ECLIPSE_PROFILE = "IMG_OBJ_ECLIPSE_PROFILE"; //$NON-NLS-1$
98
	/**
102
	/**
99
	 * The id for the API errors / warnings property page
103
	 * Key for fragment image
100
	 * <br>
101
	 * Value is: <code>org.eclipse.pde.api.tools.ui.apitools.warningspage</code>
102
	 */
104
	 */
103
	public static final String ID_ERRORS_WARNINGS_PROP_PAGE = "org.eclipse.pde.api.tools.ui.apitools.warningspage"; //$NON-NLS-1$
105
	public static final String IMG_OBJ_FRAGMENT = "IMG_OBJ_FRAGMENT"; //$NON-NLS-1$		
104
	/**
106
	/**
105
	 * Key for filter resolution image
107
	 * Error overlay.
106
	 */
108
	 */
107
	public static final String IMG_ELCL_FILTER = "IMG_ELCL_FILTER"; //$NON-NLS-1$
109
	public static final String IMG_OVR_ERROR = "IMG_OVR_ERROR"; //$NON-NLS-1$
108
	
110
	
109
	/**
111
	/**
110
	 * Key for enabled remove image
112
	 * Success overlay
111
	 */
113
	 */
112
	public static final String IMG_ELCL_REMOVE = "IMG_ELCL_REMOVE"; //$NON-NLS-1$
114
	public static final String IMG_OVR_SUCCESS = "IMG_OVR_SUCCESS"; //$NON-NLS-1$
113
	
115
	
114
	/**
116
	/**
115
	 * Key for the open page image
117
	 * Warning overlay
116
	 */
118
	 */
117
	public static final String IMG_ELCL_OPEN_PAGE = "IMG_ELCL_OPEN_PAGE"; //$NON-NLS-1$
119
	public static final String IMG_OVR_WARNING = "IMG_OVR_WARNING"; //$NON-NLS-1$
120
	/**
121
	 * Wizard banner for editing an API profile
122
	 */
123
	public static final String IMG_WIZBAN_PROFILE = "IMG_WIZBAN_PROFILE"; //$NON-NLS-1$
118
}
124
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 33-37 Link Here
33
 org.eclipse.pde.api.tools.ui.internal.preferences;x-friends:="org.eclipse.pde.api.tools.tests",
33
 org.eclipse.pde.api.tools.ui.internal.preferences;x-friends:="org.eclipse.pde.api.tools.tests",
34
 org.eclipse.pde.api.tools.ui.internal.properties;x-friends:="org.eclipse.pde.api.tools.tests",
34
 org.eclipse.pde.api.tools.ui.internal.properties;x-friends:="org.eclipse.pde.api.tools.tests",
35
 org.eclipse.pde.api.tools.ui.internal.refactoring;x-internal:=true,
35
 org.eclipse.pde.api.tools.ui.internal.refactoring;x-internal:=true,
36
 org.eclipse.pde.api.tools.ui.internal.views;x-internal:=true,
36
 org.eclipse.pde.api.tools.ui.internal.wizards;x-friends:="org.eclipse.pde.api.tools.tests"
37
 org.eclipse.pde.api.tools.ui.internal.wizards;x-friends:="org.eclipse.pde.api.tools.tests"
37
Import-Package: com.ibm.icu.text;version="3.6.1"
38
Import-Package: com.ibm.icu.text;version="3.6.1"
(-)plugin.properties (-2 / +6 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2007, 2008 IBM Corporation and others.
2
# Copyright (c) 2007, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 43-48 Link Here
43
ApiToolsJavadocProposals.name = API Tools Javadoc Proposals
43
ApiToolsJavadocProposals.name = API Tools Javadoc Proposals
44
MarkerGroupingEntryLabel=API Usage and Compatibility
44
MarkerGroupingEntryLabel=API Usage and Compatibility
45
ApiToolsProposalCategory.name = PDE API Tools Proposals
45
ApiToolsProposalCategory.name = PDE API Tools Proposals
46
APICompare.name=API Baseline...
47
Apitoolingview.name=API Tooling
48
Apitoolingview.category.name=API Tooling
46
FilterDeleteParticipant.name = API Problem Filter Delete Participant
49
FilterDeleteParticipant.name = API Problem Filter Delete Participant
47
FilterRenameParticipant.name = API Problem Filter Rename Participant
50
FilterRenameParticipant.name = API Problem Filter Rename Participant
48
FilterMoveParticipant.name = API Problem Filter Move Participant
51
FilterMoveParticipant.name = API Problem Filter Move Participant
52
CompareWithMenu.label=Compare With
(-)plugin.xml (+34 lines)
Lines 114-119 Link Here
114
               value="org.eclipse.pde.api.tools.apiAnalysisNature">
114
               value="org.eclipse.pde.api.tools.apiAnalysisNature">
115
         </filter>
115
         </filter>
116
      </objectContribution>
116
      </objectContribution>
117
      <objectContribution
118
            adaptable="false"
119
            id="org.eclipse.pde.api.tools.ui.compare"
120
            objectClass="org.eclipse.jdt.core.IJavaElement">
121
         <action
122
               class="org.eclipse.pde.api.tools.ui.internal.actions.CompareWithAction"
123
               enablesFor="+"
124
               id="org.eclipse.pde.api.tools.ui.action.compare"
125
               label="%APICompare.name"
126
               menubarPath="compareWithMenu/compareWithGroup">
127
         </action>
128
         <menu
129
               label="%CompareWithMenu.label"
130
               path="additions"
131
               id="compareWithMenu">
132
            <separator
133
                  name="compareWithGroup">
134
            </separator>
135
         </menu>
136
      </objectContribution>
117
   </extension>
137
   </extension>
118
   <extension
138
   <extension
119
         point="org.eclipse.ui.propertyPages">
139
         point="org.eclipse.ui.propertyPages">
Lines 271-276 Link Here
271
      </markerResolutionGenerator>
291
      </markerResolutionGenerator>
272
   </extension>
292
   </extension>
273
   <extension
293
   <extension
294
         point="org.eclipse.ui.views">
295
      <category
296
            id="org.eclipse.pde.api.tools.ui.views.apitooling.view.category"
297
            name="%Apitoolingview.category.name">
298
      </category>
299
      <view
300
            category="org.eclipse.pde.api.tools.ui.views.apitooling.view.category"
301
            class="org.eclipse.pde.api.tools.ui.internal.views.APIToolingView"
302
            icon="icons/full/obj16/api_tools.gif"
303
            id="org.eclipse.pde.api.tools.ui.views.apitooling.views.apitoolingview"
304
            name="%Apitoolingview.name">
305
      </view>
306
   </extension>
307
   <extension
274
         point="org.eclipse.ltk.core.refactoring.renameParticipants">
308
         point="org.eclipse.ltk.core.refactoring.renameParticipants">
275
      <renameParticipant
309
      <renameParticipant
276
            class="org.eclipse.pde.api.tools.ui.internal.refactoring.FilterRenameParticipant"
310
            class="org.eclipse.pde.api.tools.ui.internal.refactoring.FilterRenameParticipant"
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/RemoveAllSessionsAction.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
import org.eclipse.jface.action.Action;
13
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
15
import org.eclipse.ui.ISharedImages;
16
import org.eclipse.ui.PlatformUI;
17
18
/**
19
 * This action removes the active session.
20
 */
21
public class RemoveAllSessionsAction extends Action {
22
23
	public RemoveAllSessionsAction() {
24
		setText(ActionMessages.RemoveAllSessionsAction_label);
25
		setToolTipText(ActionMessages.RemoveAllSessionsAction_tooltip);
26
		ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVEALL);
27
		//ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE);
28
		setImageDescriptor(enabledImageDescriptor);
29
		ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVEALL_DISABLED);
30
		//ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED);
31
		setDisabledImageDescriptor(disabledImageDescriptor);
32
	}
33
34
	public void run() {
35
		ApiPlugin.getDefault().getSessionManager().removeAllSessions();
36
	}
37
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/SelectSessionAction.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.IMenuCreator;
15
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
17
import org.eclipse.pde.api.tools.internal.provisional.ISession;
18
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
19
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
20
import org.eclipse.pde.api.tools.ui.internal.IApiToolsConstants;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Menu;
26
import org.eclipse.swt.widgets.MenuItem;
27
28
/**
29
 * Drop-down action to select the active session.
30
 */
31
public class SelectSessionAction extends Action implements IMenuCreator {
32
33
	private Menu menu;
34
35
	public SelectSessionAction() {
36
		setText(ActionMessages.SelectSessionAction_label);
37
		setToolTipText(ActionMessages.SelectSessionAction_tooltip);
38
		setImageDescriptor(ApiUIPlugin.getImageDescriptor(IApiToolsConstants.IMG_ELCL_COMPARE_APIS));
39
		setDisabledImageDescriptor(ApiUIPlugin.getImageDescriptor(IApiToolsConstants.IMG_ELCL_COMPARE_APIS_DISABLED));
40
		setMenuCreator(this);
41
		setEnabled(false);
42
	}
43
44
	public Menu getMenu(Control parent) {
45
		if (menu != null) {
46
			menu.dispose();
47
		}
48
		menu = new Menu(parent);
49
50
		final ISessionManager manager = ApiPlugin.getDefault().getSessionManager();
51
		ISession[] sessions = manager.getSessions();
52
		ISession active = manager.getActiveSession();
53
		for (int i = 0; i < sessions.length; i++) {
54
			final ISession session = sessions[i];
55
			MenuItem item = new MenuItem(menu, SWT.RADIO);
56
			Object[] labelparams = new Object[] { new Integer(i + 1), session.getTimestamp()};
57
			item.setText(NLS.bind(ActionMessages.SelectSessionActionEntry_label,
58
					labelparams));
59
			item.setSelection(session == active);
60
			item.addSelectionListener(new SelectionAdapter() {
61
				public void widgetSelected(SelectionEvent e) {
62
					manager.activateSession(session);
63
				}
64
			});
65
		}
66
		return menu;
67
	}
68
69
	public Menu getMenu(Menu parent) {
70
		return null;
71
	}
72
73
	public void dispose() {
74
	}
75
76
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/RemoveActiveSessionAction.java (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
import org.eclipse.jface.action.Action;
13
import org.eclipse.jface.resource.ImageDescriptor;
14
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
15
import org.eclipse.pde.api.tools.internal.provisional.ISession;
16
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
17
import org.eclipse.ui.ISharedImages;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.actions.ActionFactory;
20
21
/**
22
 * This action removes the active session.
23
 */
24
public class RemoveActiveSessionAction extends Action {
25
26
	public RemoveActiveSessionAction() {
27
		setText(ActionMessages.RemoveActiveSessionAction_label);
28
		setToolTipText(ActionMessages.RemoveActiveSessionAction_tooltip);
29
		ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE);
30
		//ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE);
31
		setImageDescriptor(enabledImageDescriptor);
32
		ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE_DISABLED);
33
		//ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED);
34
		setDisabledImageDescriptor(disabledImageDescriptor);
35
		setActionDefinitionId(ActionFactory.DELETE.getCommandId());
36
	}
37
38
	public void run() {
39
		ISessionManager manager = ApiPlugin.getDefault().getSessionManager();
40
		ISession session = manager.getActiveSession();
41
		if (session != null) {
42
			manager.removeSession(session);
43
		}
44
		ISession[] sessions = manager.getSessions();
45
		int length = sessions.length;
46
		if (length > 0) {
47
			manager.activateSession(sessions[length - 1]);
48
		}
49
	}
50
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
13
import java.util.Arrays;
14
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.dialogs.IDialogSettings;
17
import org.eclipse.jface.window.IShellProvider;
18
import org.eclipse.osgi.util.NLS;
19
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
20
import org.eclipse.pde.api.tools.internal.provisional.IApiBaselineManager;
21
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
22
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
23
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Control;
31
import org.eclipse.swt.widgets.Shell;
32
33
/**
34
 * Compares {@link org.eclipse.pde.api.tools.internal.provisional.model.IApiElement}s
35
 * to a given {@link IApiBaseline} to get a delta
36
 * 
37
 * @since 1.0.1
38
 */
39
public class CompareDialog extends Dialog {
40
41
	//widget state ids 
42
	static final String SETTINGS_SECTION = ApiUIPlugin.PLUGIN_ID + ".api.compare"; //$NON-NLS-1$
43
	static final String BASELINE_STATE = SETTINGS_SECTION + ".baseline"; //$NON-NLS-1$
44
	
45
	public String baseline = null;
46
	String title = null;;
47
	Combo baselinecombo = null;
48
49
	/**
50
	 * Constructor
51
	 * @param provider
52
	 * @param title
53
	 */
54
	public CompareDialog(IShellProvider provider, String title) {
55
		super(provider);
56
		this.title = title;
57
	}
58
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
61
	 */
62
	protected void configureShell(Shell newShell) {
63
		super.configureShell(newShell);
64
		newShell.setText(this.title);
65
	}
66
	
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
69
	 */
70
	protected boolean isResizable() {
71
		return true;
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
76
	 */
77
	protected Control createDialogArea(Composite parent) {
78
		Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_HORIZONTAL);
79
		GridData gd = (GridData) comp.getLayoutData();
80
		gd.widthHint = 310;
81
		
82
		SWTFactory.createWrapLabel(comp, ActionMessages.SelectABaseline, 2);
83
		this.baselinecombo = SWTFactory.createCombo(comp, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY, 2, GridData.FILL_HORIZONTAL, null);
84
		this.baselinecombo.addSelectionListener(new SelectionAdapter(){
85
			public void widgetSelected(SelectionEvent e) {
86
				Combo combo = (Combo) e.widget;
87
				String[] baselineNames = (String[]) combo.getData();
88
				String selectedBaselineName = baselineNames[combo.getSelectionIndex()];
89
				CompareDialog.this.baseline = selectedBaselineName;
90
			}
91
		});
92
		initialize();
93
		return comp;
94
	}
95
	
96
	/**
97
	 * Initializes the controls
98
	 */
99
	void initialize() {
100
		IApiBaselineManager apiBaselineManager = ApiPlugin.getDefault().getApiBaselineManager();
101
		IApiBaseline defaultBaseline = apiBaselineManager.getDefaultApiBaseline();
102
		String defaultBaselineName = defaultBaseline != null ? defaultBaseline.getName() : null;
103
		IApiBaseline[] baselines = apiBaselineManager.getApiBaselines();
104
		int length = baselines.length;
105
		String[] baselinesItems = new String[length];
106
		String[] baselinesNames = new String[length];
107
		// set the names
108
		for (int i = 0; i < length; i++) {
109
			String currentBaselineName = baselines[i].getName();
110
			baselinesNames[i] = currentBaselineName;
111
		}
112
		Arrays.sort(baselinesNames);
113
		// set the labels
114
		int index = 0;
115
		for (int i = 0; i < length; i++) {
116
			String currentBaselineName = baselinesNames[i];
117
			if (defaultBaselineName != null && defaultBaselineName.equals(currentBaselineName)) {
118
				baselinesItems[i] = NLS.bind(ActionMessages.SetAsDefault, currentBaselineName);
119
				this.baseline = currentBaselineName;
120
				index = i;
121
			} else {
122
				baselinesItems[i] = currentBaselineName;
123
			}
124
		}
125
		this.baselinecombo.setItems(baselinesItems);
126
		this.baselinecombo.setData(baselinesNames);
127
		this.baselinecombo.select(index);
128
		
129
		IDialogSettings settings = ApiUIPlugin.getDefault().getDialogSettings().getSection(SETTINGS_SECTION);
130
		if(settings != null) {
131
			restoreComboSelection(this.baselinecombo, BASELINE_STATE, settings, baselinesNames);
132
		}
133
	}
134
	
135
	/* (non-Javadoc)
136
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
137
	 */
138
	protected void okPressed() {
139
		saveWidgetState();
140
		super.okPressed();
141
	}
142
	/**
143
	 * Restores the selected item for the given combo based on the stored value from the 
144
	 * dialog settings
145
	 * 
146
	 * @param combo
147
	 * @param id
148
	 * @param settings
149
	 */
150
	private void restoreComboSelection(Combo combo, String id, IDialogSettings settings, String[] baselinesNames) {
151
		String value = settings.get(id);
152
		if(value != null) {
153
			CompareDialog.this.baseline = value;
154
			// retrieve the right index in the combo
155
			int index = 0;
156
			int length = baselinesNames.length;
157
			for (int i = 0; i < length; i++) {
158
				String currentBaselineName = baselinesNames[i];
159
				if (value.equals(currentBaselineName)) {
160
					index = i;
161
					break;
162
				}
163
			}
164
			combo.select(index);
165
		}
166
	}
167
	
168
	/**
169
	 * Saves the state of the widgets on the page
170
	 */
171
	void saveWidgetState() {
172
		IDialogSettings rootsettings = ApiUIPlugin.getDefault().getDialogSettings();
173
		IDialogSettings settings = rootsettings.getSection(SETTINGS_SECTION);
174
		if(settings == null) {
175
			settings = rootsettings.addNewSection(SETTINGS_SECTION);
176
		}
177
		settings.put(BASELINE_STATE, this.baseline);
178
	}
179
}
(-)src/org/eclipse/pde/api/tools/ui/internal/views/APIToolingView.java (+406 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.views;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jdt.core.Flags;
15
import org.eclipse.jdt.ui.JavaUI;
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IMenuManager;
19
import org.eclipse.jface.action.IToolBarManager;
20
import org.eclipse.jface.action.Separator;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.viewers.DoubleClickEvent;
23
import org.eclipse.jface.viewers.IDoubleClickListener;
24
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.viewers.ISelectionChangedListener;
26
import org.eclipse.jface.viewers.IStructuredContentProvider;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.ITreeContentProvider;
29
import org.eclipse.jface.viewers.LabelProvider;
30
import org.eclipse.jface.viewers.SelectionChangedEvent;
31
import org.eclipse.jface.viewers.TreeViewer;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
34
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
35
import org.eclipse.pde.api.tools.internal.provisional.ISession;
36
import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
37
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
38
import org.eclipse.pde.api.tools.internal.provisional.ITreeModel;
39
import org.eclipse.pde.api.tools.internal.provisional.ITreeNode;
40
import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaProcessor;
41
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
42
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
43
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
44
import org.eclipse.pde.api.tools.ui.internal.ApiImageDescriptor;
45
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
46
import org.eclipse.pde.api.tools.ui.internal.IApiToolsConstants;
47
import org.eclipse.pde.api.tools.ui.internal.actions.ExportSessionAction;
48
import org.eclipse.pde.api.tools.ui.internal.actions.RemoveActiveSessionAction;
49
import org.eclipse.pde.api.tools.ui.internal.actions.RemoveAllSessionsAction;
50
import org.eclipse.pde.api.tools.ui.internal.actions.SelectSessionAction;
51
import org.eclipse.swt.SWT;
52
import org.eclipse.swt.graphics.Image;
53
import org.eclipse.swt.widgets.Composite;
54
import org.eclipse.ui.IActionBars;
55
import org.eclipse.ui.actions.ActionFactory;
56
import org.eclipse.ui.part.ViewPart;
57
import org.eclipse.ui.views.properties.IPropertySheetPage;
58
import org.eclipse.ui.views.properties.PropertySheetPage;
59
60
/**
61
 * The class is used to show api tooling task results in a tree view.
62
 */
63
64
public class APIToolingView extends ViewPart implements ISessionListener {
65
66
	/**
67
	 * The ID of the view as specified by the extension.
68
	 */
69
	public static final String ID = "org.eclipse.pde.api.tools.ui.views.apitooling.views.apitoolingview"; //$NON-NLS-1$
70
71
	public TreeViewer viewer;
72
	private IAction removeActiveSessionAction;
73
	private IAction removeAllSessionsAction;
74
	private IAction selectSessionAction;
75
	private Action doubleClickAction;
76
	private ExportSessionAction exportSessionAction;
77
78
	class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {
79
		ITreeModel model;
80
		
81
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
82
			this.model = null;
83
		}
84
		public void dispose() {
85
		}
86
		public Object[] getElements(Object parent) {
87
			if (parent instanceof ISession) {
88
				ISession session = (ISession) parent;
89
				if (this.model == null) {
90
					this.model = session.getModel();
91
				}
92
				return getChildren(this.model.getRoot());
93
			}
94
			return getChildren(parent);
95
		}
96
		public Object getParent(Object child) {
97
			return null;
98
		}
99
		public Object [] getChildren(Object parent) {
100
			if (parent instanceof ITreeNode) {
101
				return ((ITreeNode) parent).getChildren();
102
			}
103
			return new Object[0];
104
		}
105
		public boolean hasChildren(Object parent) {
106
			if (parent instanceof ITreeNode) {
107
				return ((ITreeNode) parent).hasChildren();
108
			}
109
			return false;
110
		}
111
	}
112
	class ViewLabelProvider extends LabelProvider {
113
		public String getText(Object obj) {
114
			return obj.toString();
115
		}
116
117
		public Image getImage(Object obj) {
118
			if (obj instanceof ITreeNode) {
119
				ITreeNode treeNode = (ITreeNode) obj;
120
				switch(treeNode.getId()) {
121
					case ITreeNode.CLASS :
122
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS);
123
					case ITreeNode.INTERFACE :
124
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_INTERFACE);
125
					case ITreeNode.ANNOTATION :
126
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ANNOTATION);
127
					case ITreeNode.ENUM :
128
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ENUM);
129
					case ITreeNode.PACKAGE :
130
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PACKAGE);
131
				}
132
				Object data = treeNode.getData();
133
				if (data instanceof IDelta) {
134
					IDelta delta = (IDelta) data;
135
					Image image = getDeltaElementImage(delta);
136
					if (image != null) {
137
						int flags = (DeltaProcessor.isCompatible(delta) ? ApiImageDescriptor.SUCCESS : ApiImageDescriptor.ERROR);
138
						ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
139
						ApiImageDescriptor desc = new ApiImageDescriptor(descriptor, flags);
140
						return ApiUIPlugin.getImage(desc);
141
					}
142
				}
143
			}
144
			return null;
145
		}
146
147
		private Image getDeltaElementImage(IDelta delta) {
148
			switch(delta.getFlags()) {
149
				case IDelta.API_FIELD :
150
				case IDelta.FIELD : {
151
					int modifiers = delta.getNewModifiers();
152
					switch(delta.getKind()) {
153
						case IDelta.REMOVED : {
154
							modifiers = delta.getOldModifiers();
155
						}
156
					}
157
					if (Flags.isPublic(modifiers)) {
158
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PUBLIC);
159
					} else if (Flags.isProtected(modifiers)) {
160
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PROTECTED);
161
					} else if (Flags.isPrivate(modifiers)){
162
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PRIVATE);
163
					} else {
164
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_DEFAULT);
165
					}
166
				}
167
				case IDelta.METHOD :
168
				case IDelta.METHOD_MOVED_DOWN :
169
				case IDelta.METHOD_MOVED_UP :
170
				case IDelta.METHOD_WITH_DEFAULT_VALUE :
171
				case IDelta.METHOD_WITHOUT_DEFAULT_VALUE :
172
				case IDelta.CONSTRUCTOR :
173
				case IDelta.CLINIT : {
174
					int modifiers = delta.getNewModifiers();
175
					switch(delta.getKind()) {
176
						case IDelta.REMOVED : {
177
							modifiers = delta.getOldModifiers();
178
						}
179
					}
180
					if (Flags.isPublic(modifiers)) {
181
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
182
					} else if (Flags.isProtected(modifiers)) {
183
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PROTECTED);
184
					} else if (Flags.isPrivate(modifiers)){
185
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PRIVATE);
186
					} else {
187
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS_DEFAULT);
188
					}
189
				}
190
			}
191
			switch(delta.getElementType()) {
192
				case IDelta.ANNOTATION_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ANNOTATION);
193
				case IDelta.ENUM_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ENUM);
194
				case IDelta.CLASS_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS);
195
				case IDelta.INTERFACE_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_INTERFACE);
196
				case IDelta.FIELD_ELEMENT_TYPE : {
197
					int modifiers = delta.getNewModifiers();
198
					switch(delta.getKind()) {
199
						case IDelta.REMOVED : {
200
							modifiers = delta.getOldModifiers();
201
						}
202
					}
203
					if (Flags.isPublic(modifiers)) {
204
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PUBLIC);
205
					} else if (Flags.isProtected(modifiers)) {
206
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PROTECTED);
207
					} else if (Flags.isPrivate(modifiers)){
208
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PRIVATE);
209
					} else {
210
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_DEFAULT);
211
					}
212
				}
213
				case IDelta.METHOD_ELEMENT_TYPE :
214
				case IDelta.CONSTRUCTOR_ELEMENT_TYPE : {
215
					int modifiers = delta.getNewModifiers();
216
					switch(delta.getKind()) {
217
						case IDelta.REMOVED : {
218
							modifiers = delta.getOldModifiers();
219
						}
220
					}
221
					if (Flags.isPublic(modifiers)) {
222
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
223
					} else if (Flags.isProtected(modifiers)) {
224
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PROTECTED);
225
					} else if (Flags.isPrivate(modifiers)){
226
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PRIVATE);
227
					} else {
228
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS_DEFAULT);
229
					}
230
				}
231
				case IDelta.TYPE_PARAMETER_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
232
				case IDelta.API_PROFILE_ELEMENT_TYPE : return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_ECLIPSE_PROFILE);
233
				case IDelta.API_COMPONENT_ELEMENT_TYPE : {
234
					String componentVersionId = delta.getComponentVersionId();
235
					IApiComponent component = null;
236
					if (componentVersionId != null) {
237
						int indexOfOpen = componentVersionId.lastIndexOf('(');
238
						String componentID = componentVersionId.substring(0, indexOfOpen);
239
						IApiBaseline baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
240
						if (baseline != null) {
241
							IApiComponent apiComponent = baseline.getApiComponent(componentID);
242
							if (apiComponent != null) {
243
								component = apiComponent;
244
							}
245
						}
246
					}
247
					if (component != null) {
248
						if(component.isSystemComponent()) {
249
							return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_API_SYSTEM_LIBRARY);
250
						}
251
						try {
252
							if (component.isFragment()) {
253
								return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_FRAGMENT);
254
							}
255
						} catch (CoreException e) {
256
							ApiPlugin.log(e);
257
						}
258
						return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_BUNDLE);
259
					}
260
				}
261
			}
262
			return null;
263
		}
264
	}
265
266
	/**
267
	 * The constructor.
268
	 */
269
	public APIToolingView() {
270
	}
271
	/**
272
	 * This is a callback that will allow us
273
	 * to create the viewer and initialize it.
274
	 */
275
	public void createPartControl(Composite parent) {
276
		this.viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
277
		this.viewer.setContentProvider(new ViewContentProvider());
278
		this.viewer.setLabelProvider(new ViewLabelProvider());
279
		this.viewer.addSelectionChangedListener(new ISelectionChangedListener() {
280
			public void selectionChanged(SelectionChangedEvent event) {
281
				// TODO Auto-generated method stub
282
				
283
			}
284
		});
285
		ISession[] sessions = ApiPlugin.getDefault().getSessionManager().getSessions();
286
		if (sessions.length > 0) {
287
			this.viewer.setInput(sessions[0]);
288
		}
289
		createActions();
290
		updateActions();
291
		configureToolbar();
292
		hookDoubleClickAction();
293
294
		ApiPlugin.getDefault().getSessionManager().addSessionListener(this);
295
		
296
		getSite().setSelectionProvider(this.viewer);
297
	}
298
	private void hookDoubleClickAction() {
299
		this.viewer.addDoubleClickListener(new IDoubleClickListener() {
300
			public void doubleClick(DoubleClickEvent event) {
301
				APIToolingView.this.doubleClickAction.run();
302
			}
303
		});
304
	}
305
	public void dispose() {
306
		ApiPlugin.getDefault().getSessionManager().removeSessionListener(this);
307
	}
308
	protected void configureToolbar() {
309
		IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
310
		tbm.add(new Separator());
311
		tbm.add(this.removeActiveSessionAction);
312
		tbm.add(this.removeAllSessionsAction);
313
		tbm.add(this.selectSessionAction);
314
		tbm.add(new Separator());
315
//		tbm.add(new CollapseAllAction(this.viewer));
316
317
		IMenuManager mm = getViewSite().getActionBars().getMenuManager();
318
		mm.add(this.exportSessionAction);
319
	}
320
	private void createActions() {
321
		final IActionBars actionBars = getViewSite().getActionBars();
322
323
		this.removeActiveSessionAction = new RemoveActiveSessionAction();
324
		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeActiveSessionAction);
325
326
		this.removeAllSessionsAction = new RemoveAllSessionsAction();
327
		this.selectSessionAction = new SelectSessionAction();
328
		this.doubleClickAction = new Action() {
329
			public void run() {
330
				ISelection selection = viewer.getSelection();
331
				if (selection instanceof IStructuredSelection) {
332
					Object item = ((IStructuredSelection) selection).getFirstElement();
333
					if (APIToolingView.this.viewer.getExpandedState(item)) {
334
						APIToolingView.this.viewer.collapseToLevel(item, 1);
335
					} else {
336
						APIToolingView.this.viewer.expandToLevel(item, 1);
337
					}
338
					if (item instanceof ITreeNode) {
339
						ITreeNode node = (ITreeNode) item;
340
						if (node.getData() != null) {
341
							// show in Properties view
342
						}
343
					}
344
				}
345
			}
346
		};
347
		this.exportSessionAction = new ExportSessionAction(this);
348
	}
349
	private void updateActions() {
350
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
351
			public void run() {
352
				ISessionManager sessionManager = ApiPlugin.getDefault().getSessionManager();
353
				ISession active = sessionManager.getActiveSession();
354
				setContentDescription(active == null ? "" : active.getTimestamp()); //$NON-NLS-1$
355
				ISession[] sessions =  sessionManager.getSessions();
356
				boolean atLeastOne = sessions.length >= 1;
357
				APIToolingView.this.removeActiveSessionAction.setEnabled(atLeastOne);
358
				APIToolingView.this.removeAllSessionsAction.setEnabled(atLeastOne);
359
				APIToolingView.this.selectSessionAction.setEnabled(atLeastOne);
360
				APIToolingView.this.exportSessionAction.setEnabled(active != null);
361
			}
362
		});
363
	}
364
	/**
365
	 * Passing the focus request to the viewer's control.
366
	 */
367
	public void setFocus() {
368
		this.viewer.getControl().setFocus();
369
	}
370
	public void sessionAdded(final ISession session) {
371
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
372
			public void run() {
373
				APIToolingView.this.viewer.setInput(session);
374
			}
375
		});
376
		updateActions();
377
	}
378
	public void sessionRemoved(ISession session) {
379
		this.viewer.setInput(null);
380
		updateActions();
381
	}
382
	
383
	public void sessionActivated(final ISession session) {
384
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
385
			public void run() {
386
				APIToolingView.this.viewer.setInput(session);
387
			}
388
		});
389
		updateActions();
390
	}
391
	/**
392
	 * Returns the property sheet.
393
	 */
394
	protected IPropertySheetPage getPropertySheet() {
395
		return new PropertySheetPage();
396
	}
397
	/* (non-Javadoc)
398
	 * Method declared on IAdaptable
399
	 */
400
	public Object getAdapter(Class adapter) {
401
		if (adapter.equals(IPropertySheetPage.class)) {
402
			return getPropertySheet();
403
		}
404
		return super.getAdapter(adapter);
405
	}
406
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ExportSessionAction.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
13
import java.io.BufferedWriter;
14
import java.io.File;
15
import java.io.FileWriter;
16
import java.io.IOException;
17
import java.io.InputStream;
18
19
import javax.xml.transform.Result;
20
import javax.xml.transform.Source;
21
import javax.xml.transform.Transformer;
22
import javax.xml.transform.TransformerConfigurationException;
23
import javax.xml.transform.TransformerException;
24
import javax.xml.transform.TransformerFactory;
25
import javax.xml.transform.stream.StreamResult;
26
import javax.xml.transform.stream.StreamSource;
27
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.OperationCanceledException;
32
import org.eclipse.core.runtime.Status;
33
import org.eclipse.core.runtime.SubMonitor;
34
import org.eclipse.core.runtime.jobs.Job;
35
import org.eclipse.jface.action.Action;
36
import org.eclipse.jface.window.Window;
37
import org.eclipse.pde.api.tools.internal.comparator.DeltaXmlVisitor;
38
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
39
import org.eclipse.pde.api.tools.internal.provisional.ISession;
40
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
41
import org.eclipse.pde.api.tools.internal.util.Util;
42
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
43
import org.eclipse.pde.api.tools.ui.internal.views.APIToolingView;
44
45
/**
46
 * Drop-down action to select the active session.
47
 */
48
public class ExportSessionAction extends Action {
49
	private static final String DELTAS_XSLT_TRANSFORM_PATH = "/xslt/compare.xsl"; //$NON-NLS-1$
50
	private static final String XML_FILE_EXTENSION = ".xml"; //$NON-NLS-1$
51
	private static final String HTML_FILE_EXTENSION = ".html"; //$NON-NLS-1$
52
	APIToolingView view;
53
	public ExportSessionAction(APIToolingView view) {
54
		setText(ActionMessages.ExportSessionAction_label);
55
		setToolTipText(ActionMessages.ExportSessionAction_tooltip);
56
		setEnabled(false);
57
		this.view = view;
58
	}
59
60
	public void run() {
61
		final ISession activeSession = ApiPlugin.getDefault().getSessionManager().getActiveSession();
62
		if (activeSession == null) {
63
			return;
64
		}
65
		ExportDialog dialog = new ExportDialog(view.getSite(), ActionMessages.ExportActionTitle);
66
		int returnCode = dialog.open();
67
		if (returnCode == Window.CANCEL) {
68
			return;
69
		}
70
		final String reportFileName = dialog.reportPath;
71
		if (reportFileName == null) {
72
			return;
73
		}
74
		final String lowerCase = reportFileName.toLowerCase();
75
		if (!lowerCase.endsWith(HTML_FILE_EXTENSION) && !lowerCase.endsWith(XML_FILE_EXTENSION)) {
76
			return;
77
		}
78
		
79
		Job job = new Job(ActionMessages.CompareWithAction_comparing_apis){
80
			protected IStatus run(IProgressMonitor monitor) {
81
				SubMonitor progress = SubMonitor.convert(monitor, 100);
82
				progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName);
83
				boolean isHtmlFile = lowerCase.endsWith(HTML_FILE_EXTENSION);
84
				File xmlOutputFile = null;
85
				try {
86
					progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
87
					File reportFile = new File(reportFileName);
88
					try {
89
						progress.worked(25);
90
						Util.checkCanceled(progress);
91
						BufferedWriter writer = null;
92
						try {
93
							if (isHtmlFile) {
94
								xmlOutputFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), XML_FILE_EXTENSION);
95
							} else {
96
								xmlOutputFile = reportFile;
97
							}
98
							if (xmlOutputFile.exists()) {
99
								xmlOutputFile.delete();
100
							}
101
							writer = new BufferedWriter(new FileWriter(xmlOutputFile));
102
							DeltaXmlVisitor visitor = new DeltaXmlVisitor();
103
							Object data = activeSession.getModel().getRoot().getData();
104
							if (data instanceof IDelta) {
105
								IDelta delta = (IDelta) data;
106
								progress.worked(25);
107
								Util.checkCanceled(progress);
108
								delta.accept(visitor);
109
								writer.write(visitor.getXML());
110
								writer.flush();
111
								progress.worked(25);
112
							}
113
						} catch (IOException e) {
114
							ApiPlugin.log(e);
115
						} catch (CoreException e) {
116
							ApiPlugin.log(e);
117
						} finally {
118
							if (writer != null) {
119
								try {
120
									writer.close();
121
								} catch(IOException e) {
122
									// ignore
123
								}
124
							}
125
						}
126
						if(isHtmlFile) {
127
							// remaining part is to convert the xml file to html using XSLT
128
							Util.checkCanceled(progress);
129
							Source xmlSource = new StreamSource(xmlOutputFile);
130
							InputStream stream = ApiPlugin.class.getResourceAsStream(DELTAS_XSLT_TRANSFORM_PATH);
131
							Source xsltSource = new StreamSource(stream);
132
							try {
133
								writer = new BufferedWriter(new FileWriter(reportFile));
134
								Result result = new StreamResult(writer);
135
								// create an instance of TransformerFactory
136
								TransformerFactory transFact = TransformerFactory.newInstance();
137
								Transformer trans = transFact.newTransformer(xsltSource);
138
								trans.transform(xmlSource, result);
139
							} catch (TransformerConfigurationException e) {
140
								ApiUIPlugin.log(e);
141
							} catch (TransformerException e) {
142
								ApiUIPlugin.log(e);
143
							} catch(IOException e) {
144
								ApiUIPlugin.log(e);
145
							} finally {
146
								if (writer != null) {
147
									try {
148
										writer.close();
149
									} catch(IOException e) {
150
										// ignore
151
									}
152
								}
153
							}
154
						}
155
						progress.worked(25);
156
						return Status.OK_STATUS;
157
					} catch(OperationCanceledException e) {
158
						// ignore
159
						if (xmlOutputFile != null && xmlOutputFile.exists()) {
160
							xmlOutputFile.delete();
161
						}
162
						if (reportFile.exists()) {
163
							reportFile.delete();
164
						}
165
					}
166
				} finally {
167
					monitor.done();
168
				}
169
				return Status.CANCEL_STATUS;
170
			}
171
		};
172
		job.setSystem(false);
173
		job.setPriority(Job.LONG);
174
		job.schedule();
175
	}
176
	public void dispose() {
177
	}
178
179
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ExportDialog.java (+160 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
13
import java.io.File;
14
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.IDialogSettings;
18
import org.eclipse.jface.window.IShellProvider;
19
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
20
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.FileDialog;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Text;
31
32
/**
33
 * Compares {@link org.eclipse.pde.api.tools.internal.provisional.model.IApiElement}s
34
 * to a given {@link IApiBaseline} to get a delta
35
 * 
36
 * @since 1.0.1
37
 */
38
public class ExportDialog extends Dialog {
39
40
	//widget state ids 
41
	static final String SETTINGS_SECTION = ApiUIPlugin.PLUGIN_ID + ".api.exportsession"; //$NON-NLS-1$
42
	static final String REPORT_PATH_STATE = SETTINGS_SECTION + ".reportpath"; //$NON-NLS-1$
43
	
44
	private String title = null;;
45
	private Text reportPathText;
46
	public String reportPath;
47
48
	/**
49
	 * Constructor
50
	 * @param provider
51
	 * @param title
52
	 */
53
	public ExportDialog(IShellProvider provider, String title) {
54
		super(provider);
55
		this.title = title;
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
60
	 */
61
	protected void configureShell(Shell newShell) {
62
		super.configureShell(newShell);
63
		newShell.setText(this.title);
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
68
	 */
69
	protected boolean isResizable() {
70
		return true;
71
	}
72
	
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75
	 */
76
	protected Control createDialogArea(Composite parent) {
77
		Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_HORIZONTAL);
78
		GridData gd = (GridData) comp.getLayoutData();
79
		gd.widthHint = 310;
80
81
		SWTFactory.createWrapLabel(comp, ActionMessages.EnterFileNameForExport, 2);
82
		this.reportPathText = SWTFactory.createText(comp, SWT.SINGLE | SWT.BORDER | SWT.FLAT, 1, GridData.BEGINNING | GridData.FILL_HORIZONTAL);
83
		gd = (GridData) this.reportPathText.getLayoutData();
84
		gd.grabExcessHorizontalSpace = true;
85
86
		Button browseButton = SWTFactory.createPushButton(comp, ActionMessages.Browse, null);
87
		browseButton.addSelectionListener(new SelectionAdapter() {
88
			public void widgetSelected(SelectionEvent e) {
89
				FileDialog dialog = new FileDialog(getShell());
90
				dialog.setText(ActionMessages.SelectFileName);
91
				String loctext = ExportDialog.this.reportPathText.getText().trim();
92
				if (loctext.length() > 0) {
93
					File file = new File(loctext).getParentFile();
94
					if (file != null && file.exists()) {
95
						dialog.setFilterPath(file.getAbsolutePath());
96
					}
97
				}
98
				String newPath = dialog.open();
99
				if (newPath != null && !new Path(loctext).equals(new Path(newPath))) {
100
					ExportDialog.this.reportPathText.setText(newPath);
101
					ExportDialog.this.reportPath = newPath;
102
				}
103
			}
104
		});
105
106
		initialize();
107
		return comp;
108
	}
109
	
110
	/**
111
	 * Initializes the controls
112
	 */
113
	void initialize() {
114
		IDialogSettings settings = ApiUIPlugin.getDefault().getDialogSettings().getSection(SETTINGS_SECTION);
115
		if(settings != null) {
116
			restoreTextSelection(this.reportPathText, REPORT_PATH_STATE, settings);
117
		}
118
	}
119
120
	/* (non-Javadoc)
121
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
122
	 */
123
	protected void okPressed() {
124
		String oldPath = this.reportPath;
125
		String newPath = this.reportPathText.getText().trim();
126
		if (newPath != null && !new Path(oldPath).equals(new Path(newPath))) {
127
			this.reportPathText.setText(newPath);
128
			this.reportPath = newPath;
129
		}
130
		saveWidgetState();
131
		super.okPressed();
132
	}
133
	/**
134
	 * Restores the selected item for the given combo based on the stored value from the 
135
	 * dialog settings
136
	 * 
137
	 * @param combo
138
	 * @param id
139
	 * @param settings
140
	 */
141
	private void restoreTextSelection(Text text, String id, IDialogSettings settings) {
142
		String value = settings.get(id);
143
		if(value != null) {
144
			ExportDialog.this.reportPath = value;
145
			text.setText(value);
146
		}
147
	}
148
	
149
	/**
150
	 * Saves the state of the widgets on the page
151
	 */
152
	void saveWidgetState() {
153
		IDialogSettings rootsettings = ApiUIPlugin.getDefault().getDialogSettings();
154
		IDialogSettings settings = rootsettings.getSection(SETTINGS_SECTION);
155
		if(settings == null) {
156
			settings = rootsettings.addNewSection(SETTINGS_SECTION);
157
		}
158
		settings.put(REPORT_PATH_STATE, this.reportPath);
159
	}
160
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java (+692 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.api.tools.ui.internal.actions;
12
13
import java.util.ArrayList;
14
import java.util.Date;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.OperationCanceledException;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.SubMonitor;
26
import org.eclipse.core.runtime.jobs.Job;
27
import org.eclipse.jdt.core.Flags;
28
import org.eclipse.jdt.core.IClassFile;
29
import org.eclipse.jdt.core.ICompilationUnit;
30
import org.eclipse.jdt.core.IJavaElement;
31
import org.eclipse.jdt.core.IJavaProject;
32
import org.eclipse.jdt.core.IPackageFragment;
33
import org.eclipse.jdt.core.IPackageFragmentRoot;
34
import org.eclipse.jdt.core.IType;
35
import org.eclipse.jdt.core.JavaModelException;
36
import org.eclipse.jface.action.IAction;
37
import org.eclipse.jface.viewers.ISelection;
38
import org.eclipse.jface.viewers.IStructuredSelection;
39
import org.eclipse.jface.window.Window;
40
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
41
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
42
import org.eclipse.pde.api.tools.internal.provisional.Factory;
43
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
44
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
45
import org.eclipse.pde.api.tools.internal.provisional.ISession;
46
import org.eclipse.pde.api.tools.internal.provisional.ITreeModel;
47
import org.eclipse.pde.api.tools.internal.provisional.ITreeNode;
48
import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers;
49
import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
50
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator;
51
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope;
52
import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaVisitor;
53
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
54
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
55
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
56
import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
57
import org.eclipse.pde.api.tools.internal.provisional.model.IApiType;
58
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
59
import org.eclipse.pde.api.tools.internal.util.Util;
60
import org.eclipse.ui.IObjectActionDelegate;
61
import org.eclipse.ui.IWorkbenchPart;
62
import org.eclipse.ui.IWorkbenchPartSite;
63
import org.eclipse.ui.views.properties.IPropertyDescriptor;
64
import org.eclipse.ui.views.properties.IPropertySheetEntry;
65
import org.eclipse.ui.views.properties.IPropertySource;
66
import org.eclipse.ui.views.properties.PropertyDescriptor;
67
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
68
69
import com.ibm.icu.text.DateFormat;
70
71
public class CompareWithAction implements IObjectActionDelegate {
72
73
	public static class DeltaSession implements ISession {
74
		static Object[] NO_CHILDREN = new Object[0];
75
76
		static class TreeNode implements ITreeNode, IPropertySource, IAdaptable {
77
			private static final IPropertyDescriptor[] NO_PROPERTY_DESCRIPTORS = new IPropertyDescriptor[0];
78
			// Property id keys
79
			public static final String ID_MESSAGE = "IDelta.Message"; //$NON-NLS-1$
80
			public static final String ID_COMPONENT = "IDelta.Component"; //$NON-NLS-1$
81
			public static final String ID_ELEMENT_TYPE = "IDelta.ElementType"; //$NON-NLS-1$
82
			public static final String ID_FLAGS = "IDelta.Flags"; //$NON-NLS-1$
83
			private static final Object ID_KEY = "IDelta.Key"; //$NON-NLS-1$
84
			private static final Object ID_KIND = "IDelta.Kind"; //$NON-NLS-1$
85
			private static final Object ID_NEW_MODIFIERS = "IDelta.NewModifiers"; //$NON-NLS-1$
86
			private static final Object ID_OLD_MODIFIERS = "IDelta.OldModifiers"; //$NON-NLS-1$
87
			private static final Object ID_RESTRICTIONS = "IDelta.Restrictions"; //$NON-NLS-1$
88
			private static final Object ID_TYPENAME = "IDelta.TypeName"; //$NON-NLS-1$
89
90
			// categories
91
			public static final String P_MESSAGE_CATEGORY = ActionMessages.MessageCategory;
92
			public static final String P_INFO_CATEGORY = ActionMessages.InfoCategory;
93
94
			public static final String P_MESSAGE = ActionMessages.PropertyMessageKey;
95
			public static final String P_COMPONENT = ActionMessages.PropertyComponentKey;
96
			public static final String P_ELEMENT_TYPE = ActionMessages.PropertyElementTypeKey;
97
			public static final String P_FLAGS = ActionMessages.PropertyFlagsKey;
98
			public static final String P_KEY = ActionMessages.PropertyKeyKey;
99
			public static final String P_KIND = ActionMessages.PropertyKindKey;
100
			public static final String P_NEW_MODIFIERS = ActionMessages.PropertyNewModifiersKey;
101
			public static final String P_OLD_MODIFIERS = ActionMessages.PropertyOldModifiersKey;
102
			public static final String P_RESTRICTIONS = ActionMessages.PropertyRestrictionsKey;
103
			public static final String P_TYPENAME = ActionMessages.PropertyTypeNameKey;
104
105
			private static List Descriptors;
106
			static {
107
				Descriptors = new ArrayList();
108
109
				PropertyDescriptor propertyDescriptor = new TextPropertyDescriptor(ID_MESSAGE, P_MESSAGE);
110
				propertyDescriptor.setCategory(P_MESSAGE_CATEGORY);
111
				Descriptors.add(propertyDescriptor);
112
113
				propertyDescriptor = new TextPropertyDescriptor(ID_COMPONENT, P_COMPONENT);
114
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
115
				Descriptors.add(propertyDescriptor);
116
117
				propertyDescriptor = new TextPropertyDescriptor(ID_KEY, P_KEY);
118
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
119
				propertyDescriptor.setFilterFlags(new String[] { IPropertySheetEntry.FILTER_ID_EXPERT });
120
				Descriptors.add(propertyDescriptor);
121
122
				propertyDescriptor = new TextPropertyDescriptor(ID_KIND, P_KIND);
123
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
124
				Descriptors.add(propertyDescriptor);
125
126
				propertyDescriptor = new TextPropertyDescriptor(ID_NEW_MODIFIERS, P_NEW_MODIFIERS);
127
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
128
				Descriptors.add(propertyDescriptor);
129
130
				propertyDescriptor = new TextPropertyDescriptor(ID_OLD_MODIFIERS, P_OLD_MODIFIERS);
131
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
132
				Descriptors.add(propertyDescriptor);
133
134
				propertyDescriptor = new TextPropertyDescriptor(ID_RESTRICTIONS, P_RESTRICTIONS);
135
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
136
				Descriptors.add(propertyDescriptor);
137
138
				propertyDescriptor = new TextPropertyDescriptor(ID_TYPENAME, P_TYPENAME);
139
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
140
				Descriptors.add(propertyDescriptor);
141
142
				propertyDescriptor = new TextPropertyDescriptor(ID_FLAGS, P_FLAGS);
143
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
144
				Descriptors.add(propertyDescriptor);
145
				
146
				propertyDescriptor = new TextPropertyDescriptor(ID_ELEMENT_TYPE, P_ELEMENT_TYPE);
147
				propertyDescriptor.setCategory(P_INFO_CATEGORY);
148
				Descriptors.add(propertyDescriptor);
149
			}
150
			/**
151
			 * Returns the descriptors
152
			 */
153
			static List getDescriptors() {
154
				return Descriptors;
155
			}
156
			Map children;
157
			String name;
158
			TreeNode parent;
159
			Object data;
160
			int id;
161
162
			public TreeNode(int id, String name, Object data) {
163
				this.name = name;
164
				this.id = id;
165
				this.data = data;
166
			}
167
			public Object[] getChildren() {
168
				if (this.children == null) {
169
					return NO_CHILDREN;
170
				}
171
				return this.children.values().toArray(new Object[this.children.size()]);
172
			}
173
			public TreeNode getNode(String name) {
174
				if (this.children == null) {
175
					return null;
176
				}
177
				return (TreeNode) this.children.get(name);
178
			}
179
			public int getId() {
180
				return this.id;
181
			}
182
			public void add(TreeNode node) {
183
				if (this.children == null) {
184
					this.children = new HashMap();
185
				}
186
				this.children.put(node.name, node);
187
			}
188
			public boolean hasChildren() {
189
				return this.children != null && !this.children.isEmpty();
190
			}
191
			public String toString() {
192
				return String.valueOf(this.name);
193
			}
194
			public Object getData() {
195
				return this.data;
196
			}
197
			public Object getEditableValue() {
198
				return null;
199
			}
200
			public IPropertyDescriptor[] getPropertyDescriptors() {
201
				if (this.data != null) {
202
					return (IPropertyDescriptor[]) getDescriptors().toArray(
203
							new IPropertyDescriptor[getDescriptors().size()]);
204
				}
205
				return NO_PROPERTY_DESCRIPTORS;
206
			}
207
			public Object getPropertyValue(Object propKey) {
208
				if (this.data == null) return null;
209
				IDelta delta = (IDelta) this.data;
210
				if (ID_MESSAGE.equals(propKey)) {
211
					return delta.getMessage();
212
				}
213
				if (ID_COMPONENT.equals(propKey)) {
214
					return delta.getComponentVersionId();
215
				}
216
				if (ID_ELEMENT_TYPE.equals(propKey)) {
217
					int elementType = delta.getElementType();
218
					StringBuffer buffer = new StringBuffer(Util.getDeltaElementType(elementType));
219
					buffer.append(" (").append(elementType).append(')'); //$NON-NLS-1$
220
					return String.valueOf(buffer);
221
				}
222
				if (ID_FLAGS.equals(propKey)) {
223
					int flags = delta.getFlags();
224
					StringBuffer buffer = new StringBuffer(Util.getDeltaFlagsName(flags));
225
					buffer.append(" (").append(flags).append(')'); //$NON-NLS-1$
226
					return String.valueOf(buffer);
227
				}
228
				if (ID_KEY.equals(propKey)) {
229
					return delta.getKey();
230
				}
231
				if (ID_KIND.equals(propKey)) {
232
					int kind = delta.getKind();
233
					StringBuffer buffer = new StringBuffer(Util.getDeltaKindName(kind));
234
					buffer.append(" (").append(kind).append(')'); //$NON-NLS-1$
235
					return String.valueOf(buffer);
236
				}
237
				if (ID_NEW_MODIFIERS.equals(propKey)) {
238
					return getDisplayedModifiers(delta.getNewModifiers());
239
				}
240
				if (ID_OLD_MODIFIERS.equals(propKey)) {
241
					return getDisplayedModifiers(delta.getOldModifiers());
242
					}
243
				if (ID_RESTRICTIONS.equals(propKey)) {
244
					int restrictions = delta.getRestrictions();
245
					StringBuffer buffer = new StringBuffer(RestrictionModifiers.getRestrictionText(restrictions));
246
					buffer.append(" (0x").append(Integer.toHexString(restrictions)).append(')'); //$NON-NLS-1$
247
					return String.valueOf(buffer);
248
				}
249
				if (ID_TYPENAME.equals(propKey)) {
250
					return delta.getTypeName();
251
				}
252
				return null;
253
			}
254
			public boolean isPropertySet(Object id) {
255
				return false;
256
			}
257
			public void resetPropertyValue(Object id) {
258
				// nothing to do
259
			}
260
			public void setPropertyValue(Object id, Object value) {
261
				// nothing to do
262
			}
263
			/* (non-Javadoc)
264
			 * Method declared on IAdaptable
265
			 */
266
			public Object getAdapter(Class adapter) {
267
				if (adapter == IPropertySource.class) {
268
					return this;
269
				}
270
				return null;
271
			}
272
			private static String getDisplayedModifiers(int newModifiers) {
273
				StringBuffer buffer = new StringBuffer();
274
				if(newModifiers == 0) {
275
					buffer.append(ActionMessages.PropertyPackageVisibility);
276
				} else {
277
					if (Flags.isAbstract(newModifiers)) {
278
						buffer.append("abstract"); //$NON-NLS-1$
279
					}
280
					String separator = " | "; //$NON-NLS-1$
281
					if(Flags.isFinal(newModifiers)) {
282
						if(buffer.length() > 0) {
283
							buffer.append(separator);
284
						}
285
						buffer.append("final"); //$NON-NLS-1$
286
					}
287
					if(Flags.isNative(newModifiers)) {
288
						if(buffer.length() > 0) {
289
							buffer.append(separator);
290
						}
291
						buffer.append("native"); //$NON-NLS-1$
292
					}
293
					if(Flags.isPrivate(newModifiers)) {
294
						if(buffer.length() > 0) {
295
							buffer.append(separator);
296
						}
297
						buffer.append("private"); //$NON-NLS-1$
298
					}
299
					if(Flags.isProtected(newModifiers)) {
300
						if(buffer.length() > 0) {
301
							buffer.append(separator);
302
						}
303
						buffer.append("protected"); //$NON-NLS-1$
304
					}
305
					if(Flags.isPublic(newModifiers)) {
306
						if(buffer.length() > 0) {
307
							buffer.append(separator);
308
						}
309
						buffer.append("public"); //$NON-NLS-1$
310
					}
311
					if(Flags.isStatic(newModifiers)) {
312
						if(buffer.length() > 0) {
313
							buffer.append(separator);
314
						}
315
						buffer.append("static"); //$NON-NLS-1$
316
					}
317
					if(Flags.isStrictfp(newModifiers)) {
318
						if(buffer.length() > 0) {
319
							buffer.append(separator);
320
						}
321
						buffer.append("strictfp"); //$NON-NLS-1$
322
					}
323
					if(Flags.isSynchronized(newModifiers)) {
324
						if(buffer.length() > 0) {
325
							buffer.append(separator);
326
						}
327
						buffer.append("synchronized"); //$NON-NLS-1$
328
					}
329
					if(Flags.isTransient(newModifiers)) {
330
						if(buffer.length() > 0) {
331
							buffer.append(separator);
332
						}
333
						buffer.append("transient"); //$NON-NLS-1$
334
					}
335
					if(Flags.isVolatile(newModifiers)) {
336
						if(buffer.length() > 0) {
337
							buffer.append(separator);
338
						}
339
						buffer.append("volatile"); //$NON-NLS-1$
340
					}
341
					if(Flags.isVarargs(newModifiers)) {
342
						if(buffer.length() > 0) {
343
							buffer.append(separator);
344
						}
345
						buffer.append("vargars"); //$NON-NLS-1$
346
					}
347
				}
348
				buffer.append(" (0x").append(Integer.toHexString(newModifiers)).append(')'); //$NON-NLS-1$
349
				return buffer.toString();
350
			}
351
		}
352
353
		static class TreeModel implements ITreeModel, IAdaptable {
354
			TreeNode root;
355
356
			TreeModel(TreeNode root) {
357
				this.root = root;
358
			}
359
			public ITreeNode getRoot() {
360
				return this.root;
361
			}
362
			public Object getAdapter(Class adapter) {
363
				// TODO Auto-generated method stub
364
				return null;
365
			}
366
		}
367
368
		IDelta delta;
369
		String baselineName;
370
		String timestamp;
371
		
372
		public DeltaSession(IDelta delta, String baselineName) {
373
			this.delta = delta;
374
			this.baselineName = baselineName;
375
			this.timestamp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
376
		}
377
		public ITreeModel getModel() {
378
			TreeNode root = new TreeNode(0, null, this.delta);
379
			TreeModel model = new TreeModel(root);
380
			class TreeBuilder extends DeltaVisitor {
381
				TreeNode node;
382
				
383
				public TreeBuilder(TreeNode node) {
384
					this.node = node;
385
				}
386
				public void endVisit(IDelta delta) {
387
					if (delta.getChildren().length == 0) {
388
						String typeName = delta.getTypeName();
389
						if (typeName == null) {
390
							this.node.add(new TreeNode(0, delta.getKey(), delta));
391
						} else if (typeName.length() == 0) {
392
							this.node.add(new TreeNode(0, delta.getMessage(), delta));
393
						} else {
394
							// split the type name (package - type)
395
							int index = typeName.lastIndexOf('.');
396
							String packageName = "<default package>"; //$NON-NLS-1$
397
							String actualTypeName = null;
398
							if (index != -1) {
399
								packageName = typeName.substring(0, index);
400
								actualTypeName = typeName.substring(index + 1);
401
							} else {
402
								actualTypeName = typeName;
403
							}
404
							TreeNode node2 = this.node.getNode(packageName);
405
							if (node2 == null) {
406
								node2 = new TreeNode(ITreeNode.PACKAGE, packageName, null);
407
								this.node.add(node2);
408
							}
409
							TreeNode node3 = node2.getNode(actualTypeName);
410
							if (node3 == null) {
411
								int id = 0;
412
								switch(delta.getElementType()) {
413
									case IDelta.ANNOTATION_ELEMENT_TYPE :
414
										id = ITreeNode.ANNOTATION;
415
										break;
416
									case IDelta.INTERFACE_ELEMENT_TYPE :
417
										id = ITreeNode.INTERFACE;
418
										break;
419
									case IDelta.CLASS_ELEMENT_TYPE :
420
										id = ITreeNode.CLASS;
421
										break;
422
									case IDelta.ENUM_ELEMENT_TYPE :
423
										id = ITreeNode.ENUM;
424
									default :
425
										// we need to retrieve the type kind
426
										try {
427
											String componentVersionId = delta.getComponentVersionId();
428
											if (componentVersionId != null) {
429
												int indexOfOpen = componentVersionId.lastIndexOf('(');
430
												String componentID = componentVersionId.substring(0, indexOfOpen);
431
												String version = componentVersionId.substring(indexOfOpen + 1, componentVersionId.length() - 1);
432
												IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(DeltaSession.this.baselineName);
433
												int modifiers = 0;
434
												if (baseline != null) {
435
													IApiComponent apiComponent = baseline.getApiComponent(componentID);
436
													if (apiComponent != null && version.equals(apiComponent.getVersion())) {
437
														IApiTypeRoot typeRoot = apiComponent.findTypeRoot(typeName);
438
														if (typeRoot != null) {
439
															IApiType structure = typeRoot.getStructure();
440
															modifiers = structure.getModifiers();
441
														}
442
													}
443
												}
444
												if (modifiers == 0) {
445
													// try the workspace baseline
446
													baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
447
													if (baseline != null) {
448
														IApiComponent apiComponent = baseline.getApiComponent(componentID);
449
														if (apiComponent != null && version.equals(apiComponent.getVersion())) {
450
															IApiTypeRoot typeRoot = apiComponent.findTypeRoot(typeName);
451
															if (typeRoot != null) {
452
																IApiType structure = typeRoot.getStructure();
453
																modifiers = structure.getModifiers();
454
															}
455
														}
456
													}
457
												}
458
												if (Flags.isEnum(modifiers)) {
459
													id = ITreeNode.ENUM;
460
												} else if (Flags.isAnnotation(modifiers)) {
461
													id = ITreeNode.ANNOTATION;
462
												} else if (Flags.isInterface(modifiers)) {
463
													id = ITreeNode.INTERFACE;
464
												} else {
465
													id = ITreeNode.CLASS;
466
												}
467
											}
468
										} catch (CoreException e) {
469
											// ignore
470
										}
471
								}
472
								node3 = new TreeNode(id, actualTypeName, null);
473
								node2.add(node3);
474
							}
475
							node3.add(new TreeNode(0, delta.getMessage(), delta));
476
						}
477
					}
478
				}
479
			}
480
			if (this.delta == ApiComparator.NO_DELTA) {
481
				root.add(new TreeNode(0, ActionMessages.CompareTaskNoChanges, null));
482
			} else {
483
				this.delta.accept(new TreeBuilder(root));
484
			}
485
			return model;
486
		}
487
		
488
		public String getTimestamp() {
489
			return this.timestamp;
490
		}
491
	}
492
493
	private IWorkbenchPartSite workbenchPartSite;
494
	private ISelection selection = null;
495
	
496
	/**
497
	 * Constructor for Action1.
498
	 */
499
	public CompareWithAction() {
500
		super();
501
	}
502
503
	/**
504
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
505
	 */
506
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
507
		workbenchPartSite = targetPart.getSite();
508
	}
509
	/**
510
	 * @see IActionDelegate#run(IAction)
511
	 */
512
	public void run(IAction action) {
513
		if (this.selection instanceof IStructuredSelection) {
514
			final IStructuredSelection structuredSelection=(IStructuredSelection) this.selection;
515
			CompareDialog dialog = new CompareDialog(workbenchPartSite, ActionMessages.CompareDialogTitle);
516
			int returnCode = dialog.open();
517
			if (returnCode == Window.CANCEL) return;
518
			final String baselineName = dialog.baseline;
519
			if (baselineName == null) return;
520
			final IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(baselineName);
521
			if (baseline == null) {
522
				return;
523
			}
524
			Job job = new Job(ActionMessages.CompareWithAction_comparing_apis){
525
				protected IStatus run(IProgressMonitor monitor) {
526
					SubMonitor progress = SubMonitor.convert(monitor, 100);
527
					progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName);
528
					SubMonitor loopProgress = progress.newChild(10).setWorkRemaining(structuredSelection.size());
529
					final IApiScope scope = walkStructureSelection(structuredSelection, loopProgress);
530
					try {
531
						progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
532
						SubMonitor compareProgress = progress.newChild(98).setWorkRemaining(scope.getApiElements().length);
533
						try {
534
							IDelta delta = ApiComparator.compare(scope, baseline, VisibilityModifiers.API, false, compareProgress);
535
							ApiPlugin.getDefault().getSessionManager().addSession(new DeltaSession(delta, baselineName), true);
536
							progress.worked(1);
537
							return Status.OK_STATUS;
538
						} catch (CoreException e) {
539
							ApiPlugin.log(e);
540
						} catch(OperationCanceledException e) {
541
							// ignore
542
						}
543
					} finally {
544
						monitor.done();
545
					}
546
					return Status.CANCEL_STATUS;
547
				}
548
			};
549
			job.setSystem(false);
550
			job.setPriority(Job.LONG);
551
			job.schedule();
552
			return;
553
		}
554
	}
555
556
	public static ApiScope walkStructureSelection(
557
			IStructuredSelection structuredSelection,
558
			IProgressMonitor monitor) {
559
		Object[] selected=structuredSelection.toArray();
560
		ApiScope scope = new ApiScope();
561
		IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
562
		if (workspaceBaseline == null) {
563
			return scope;
564
		}
565
		for (int i=0, max = selected.length; i < max; i++) {
566
			Object currentSelection = selected[i];
567
			if (currentSelection instanceof IJavaElement) {
568
				monitor.worked(1);
569
				IJavaElement element =(IJavaElement) currentSelection;
570
				IJavaProject javaProject = element.getJavaProject();
571
				try {
572
					switch (element.getElementType()) {
573
						case IJavaElement.COMPILATION_UNIT: {
574
							ICompilationUnit compilationUnit = (ICompilationUnit) element;
575
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
576
							if (apiComponent != null) {
577
								addElementFor(compilationUnit, apiComponent, scope);
578
							}
579
							break;
580
						}
581
						case IJavaElement.PACKAGE_FRAGMENT: {
582
							IPackageFragment fragment = (IPackageFragment) element;
583
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
584
							IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
585
							boolean isArchive = false;
586
							if (packageFragmentRoot != null) {
587
								isArchive = packageFragmentRoot.isArchive();
588
							}
589
							if (apiComponent != null) {
590
								addElementFor(fragment, isArchive, apiComponent, scope);
591
							}
592
							break;
593
						}
594
						case IJavaElement.PACKAGE_FRAGMENT_ROOT: {
595
							IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) element;
596
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
597
							if (apiComponent != null) {
598
								addElementFor(fragmentRoot, apiComponent, scope);
599
							}
600
							break;
601
						}
602
						case IJavaElement.JAVA_PROJECT:
603
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
604
							if (apiComponent != null) {
605
								scope.add(apiComponent);
606
//								IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
607
//								for (int j = 0, max2 = roots.length; j < max2; j++) {
608
//									addElementFor(roots[j], apiComponent, scope);
609
//								}
610
							}
611
							break;
612
					}
613
				} catch (JavaModelException e) {
614
					ApiPlugin.log(e);
615
				} catch (CoreException e) {
616
					ApiPlugin.log(e);
617
				}
618
			}
619
		}
620
		return scope;
621
	}
622
623
	private static void addElementFor(
624
			IPackageFragmentRoot fragmentRoot, IApiComponent apiComponent,
625
			ApiScope scope) throws JavaModelException, CoreException {
626
		boolean isArchive = fragmentRoot.isArchive();
627
		IJavaElement[] packageFragments = fragmentRoot.getChildren();
628
		for (int j = 0, max2 = packageFragments.length; j < max2; j++) {
629
			IPackageFragment packageFragment = (IPackageFragment) packageFragments[j];
630
			addElementFor(packageFragment, isArchive, apiComponent, scope);
631
		}
632
	}
633
634
	private static void addElementFor(
635
			IPackageFragment packageFragment,
636
			boolean isArchive,
637
			IApiComponent apiComponent,
638
			ApiScope scope)
639
		throws JavaModelException, CoreException {
640
641
		// add package fragment elements only if this is an API package
642
		IApiDescription apiDescription = apiComponent.getApiDescription();
643
		IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName()));
644
		if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) {
645
			return;
646
		}
647
		if (isArchive) {
648
			IClassFile[] classFiles = packageFragment.getClassFiles();
649
			for (int i = 0, max= classFiles.length; i < max; i++) {
650
				addElementFor(classFiles[i], apiComponent, scope);
651
			}
652
		} else {
653
			ICompilationUnit[] units = packageFragment.getCompilationUnits();
654
			for (int i = 0, max= units.length; i < max; i++) {
655
				addElementFor(units[i], apiComponent, scope);
656
			}
657
		}
658
	}
659
660
	private static void addElementFor(IClassFile classFile,
661
			IApiComponent apiComponent, ApiScope scope) {
662
		try {
663
			IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName());
664
			if (typeRoot != null) {
665
				scope.add(typeRoot);
666
			}
667
		} catch (CoreException e) {
668
			ApiPlugin.log(e);
669
		}
670
	}
671
672
	private static void addElementFor(ICompilationUnit compilationUnit, IApiComponent component, ApiScope scope) throws JavaModelException {
673
		IType[] types = compilationUnit.getTypes();
674
		for (int i = 0, max = types.length; i < max; i++) {
675
			try {
676
				IApiTypeRoot typeRoot = component.findTypeRoot(types[i].getFullyQualifiedName());
677
				if (typeRoot != null) {
678
					scope.add(typeRoot);
679
				}
680
			} catch (CoreException e) {
681
				ApiPlugin.log(e);
682
			}
683
		}
684
	}
685
686
	/**
687
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
688
	 */
689
	public void selectionChanged(IAction action, ISelection selection) {
690
		this.selection = selection;
691
	}
692
}

Return to bug 258853