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 (-2 / +34 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 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.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
}
(-)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 / +26 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 DeltaDetails;
45
21
	static {
46
	static {
22
		// initialize resource bundle
47
		// initialize resource bundle
23
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
48
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties (-1 / +27 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
DeltaDetails=Delta Information
(-)src/org/eclipse/pde/api/tools/ui/internal/ApiUIPlugin.java (-5 / +8 lines)
Lines 62-72 Link Here
62
	/**
62
	/**
63
	 * Relative path to object model icons.
63
	 * Relative path to object model icons.
64
	 */
64
	 */
65
	private final static String OBJECT= ICONS_PATH + "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
65
	private final static String OBJECT = ICONS_PATH + "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
66
	private final static String OVR= ICONS_PATH + "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
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$
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$
68
	private static final String ELCL = ICONS_PATH + "elcl16/"; 	//basic colors - size 16x16 //$NON-NLS-1$
69
	
69
	private static final String DLCL = ICONS_PATH + "dlcl16/"; 	//basic colors - size 16x16 disabled//$NON-NLS-1$
70
	/**
70
	/**
71
	 * Maps Image descriptors to images for composite images
71
	 * Maps Image descriptors to images for composite images
72
	 */
72
	 */
Lines 124-129 Link Here
124
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_FRAGMENT, OBJECT + "frgmt_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$
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$
126
		declareRegistryImage(reg, IApiToolsConstants.IMG_OBJ_BUNDLE_VERSION, OBJECT + "bundleversion.gif"); //$NON-NLS-1$
127
127
		// overlays
128
		// overlays
128
		declareRegistryImage(reg, IApiToolsConstants.IMG_OVR_ERROR, OVR + "error_ovr.gif"); //$NON-NLS-1$
129
		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_WARNING, OVR + "warning_ovr.gif"); //$NON-NLS-1$
Lines 134-139 Link Here
134
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_FILTER, ELCL + "filter_ps.gif"); //$NON-NLS-1$
135
		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_REMOVE, ELCL + "remove_exc.gif"); //$NON-NLS-1$
136
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_OPEN_PAGE, ELCL + "open_page.gif"); //$NON-NLS-1$
137
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_OPEN_PAGE, ELCL + "open_page.gif"); //$NON-NLS-1$
138
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_COMPARE_APIS, ELCL + "compare_apis.gif"); //$NON-NLS-1$
139
		declareRegistryImage(reg, IApiToolsConstants.IMG_ELCL_COMPARE_APIS_DISABLED, DLCL + "compare_apis.gif"); //$NON-NLS-1$
137
	}
140
	}
138
141
139
	/**
142
	/**
(-)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 (-1 / +4 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=Compare With...
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
(-)plugin.xml (+39 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="org.eclipse.pde.ui.project.tools/group1">
127
         </action>
128
         <menu
129
               id="org.eclipse.pde.ui.project.tools"
130
               label="%PdeTools.name">
131
            <separator
132
                  name="group1">
133
            </separator>
134
         </menu>
135
      </objectContribution>
117
   </extension>
136
   </extension>
118
   <extension
137
   <extension
119
         point="org.eclipse.ui.propertyPages">
138
         point="org.eclipse.ui.propertyPages">
Lines 271-276 Link Here
271
      </markerResolutionGenerator>
290
      </markerResolutionGenerator>
272
   </extension>
291
   </extension>
273
   <extension
292
   <extension
293
         point="org.eclipse.ui.views">
294
      <category
295
            id="org.eclipse.pde.api.tools.ui.views.apitooling.view.category"
296
            name="%Apitoolingview.category.name">
297
      </category>
298
      <view
299
            category="org.eclipse.pde.api.tools.ui.views.apitooling.view.category"
300
            class="org.eclipse.pde.api.tools.ui.internal.views.APIToolingView"
301
            icon="icons/full/obj16/api_tools.gif"
302
            id="org.eclipse.pde.api.tools.ui.views.apitooling.views.apitoolingview"
303
            name="%Apitoolingview.name">
304
      </view>
305
   </extension>
306
   <extension
307
         point="org.eclipse.help.contexts">
308
      <contexts
309
            file="contexts.xml">
310
      </contexts>
311
   </extension>
312
   <extension
274
         point="org.eclipse.ltk.core.refactoring.renameParticipants">
313
         point="org.eclipse.ltk.core.refactoring.renameParticipants">
275
      <renameParticipant
314
      <renameParticipant
276
            class="org.eclipse.pde.api.tools.ui.internal.refactoring.FilterRenameParticipant"
315
            class="org.eclipse.pde.api.tools.ui.internal.refactoring.FilterRenameParticipant"
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/RemoveAllSessionsAction.java (+27 lines)
Added Link Here
1
package org.eclipse.pde.api.tools.ui.internal.actions;
2
import org.eclipse.jface.action.Action;
3
import org.eclipse.jface.resource.ImageDescriptor;
4
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
5
import org.eclipse.ui.ISharedImages;
6
import org.eclipse.ui.PlatformUI;
7
8
/**
9
 * This action removes the active session.
10
 */
11
public class RemoveAllSessionsAction extends Action {
12
13
	public RemoveAllSessionsAction() {
14
		setText(ActionMessages.RemoveAllSessionsAction_label);
15
		setToolTipText(ActionMessages.RemoveAllSessionsAction_tooltip);
16
		ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVEALL);
17
		//ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE);
18
		setImageDescriptor(enabledImageDescriptor);
19
		ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVEALL_DISABLED);
20
		//ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED);
21
		setDisabledImageDescriptor(disabledImageDescriptor);
22
	}
23
24
	public void run() {
25
		ApiPlugin.getDefault().getSessionManager().removeAllSessions();
26
	}
27
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/SelectSessionAction.java (+66 lines)
Added Link Here
1
package org.eclipse.pde.api.tools.ui.internal.actions;
2
3
import org.eclipse.jface.action.Action;
4
import org.eclipse.jface.action.IMenuCreator;
5
import org.eclipse.osgi.util.NLS;
6
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
7
import org.eclipse.pde.api.tools.internal.provisional.ISession;
8
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
9
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
10
import org.eclipse.pde.api.tools.ui.internal.IApiToolsConstants;
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.widgets.Control;
15
import org.eclipse.swt.widgets.Menu;
16
import org.eclipse.swt.widgets.MenuItem;
17
18
/**
19
 * Drop-down action to select the active session.
20
 */
21
public class SelectSessionAction extends Action implements IMenuCreator {
22
23
	private Menu menu;
24
25
	public SelectSessionAction() {
26
		setText(ActionMessages.SelectSessionAction_label);
27
		setToolTipText(ActionMessages.SelectSessionAction_tooltip);
28
		setImageDescriptor(ApiUIPlugin.getImageDescriptor(IApiToolsConstants.IMG_ELCL_COMPARE_APIS));
29
		setDisabledImageDescriptor(ApiUIPlugin.getImageDescriptor(IApiToolsConstants.IMG_ELCL_COMPARE_APIS_DISABLED));
30
		setMenuCreator(this);
31
		setEnabled(false);
32
	}
33
34
	public Menu getMenu(Control parent) {
35
		if (menu != null) {
36
			menu.dispose();
37
		}
38
		menu = new Menu(parent);
39
40
		final ISessionManager manager = ApiPlugin.getDefault().getSessionManager();
41
		ISession[] sessions = manager.getSessions();
42
		ISession active = manager.getActiveSession();
43
		for (int i = 0; i < sessions.length; i++) {
44
			final ISession session = sessions[i];
45
			MenuItem item = new MenuItem(menu, SWT.RADIO);
46
			Object[] labelparams = new Object[] { new Integer(i + 1), session.getTimestamp()};
47
			item.setText(NLS.bind(ActionMessages.SelectSessionActionEntry_label,
48
					labelparams));
49
			item.setSelection(session == active);
50
			item.addSelectionListener(new SelectionAdapter() {
51
				public void widgetSelected(SelectionEvent e) {
52
					manager.activateSession(session);
53
				}
54
			});
55
		}
56
		return menu;
57
	}
58
59
	public Menu getMenu(Menu parent) {
60
		return null;
61
	}
62
63
	public void dispose() {
64
	}
65
66
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/RemoveActiveSessionAction.java (+40 lines)
Added Link Here
1
package org.eclipse.pde.api.tools.ui.internal.actions;
2
import org.eclipse.jface.action.Action;
3
import org.eclipse.jface.resource.ImageDescriptor;
4
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
5
import org.eclipse.pde.api.tools.internal.provisional.ISession;
6
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
7
import org.eclipse.ui.ISharedImages;
8
import org.eclipse.ui.PlatformUI;
9
import org.eclipse.ui.actions.ActionFactory;
10
11
/**
12
 * This action removes the active session.
13
 */
14
public class RemoveActiveSessionAction extends Action {
15
16
	public RemoveActiveSessionAction() {
17
		setText(ActionMessages.RemoveActiveSessionAction_label);
18
		setToolTipText(ActionMessages.RemoveActiveSessionAction_tooltip);
19
		ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE);
20
		//ImageDescriptor enabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE);
21
		setImageDescriptor(enabledImageDescriptor);
22
		ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE_DISABLED);
23
		//ImageDescriptor disabledImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED);
24
		setDisabledImageDescriptor(disabledImageDescriptor);
25
		setActionDefinitionId(ActionFactory.DELETE.getCommandId());
26
	}
27
28
	public void run() {
29
		ISessionManager manager = ApiPlugin.getDefault().getSessionManager();
30
		ISession session = manager.getActiveSession();
31
		if (session != null) {
32
			manager.removeSession(session);
33
		}
34
		ISession[] sessions = manager.getSessions();
35
		int length = sessions.length;
36
		if (length > 0) {
37
			manager.activateSession(sessions[length - 1]);
38
		}
39
	}
40
}
(-)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 (+385 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.IStructuredContentProvider;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.viewers.ITreeContentProvider;
28
import org.eclipse.jface.viewers.LabelProvider;
29
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
32
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
33
import org.eclipse.pde.api.tools.internal.provisional.ISession;
34
import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
35
import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
36
import org.eclipse.pde.api.tools.internal.provisional.ITreeModel;
37
import org.eclipse.pde.api.tools.internal.provisional.ITreeNode;
38
import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaProcessor;
39
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
40
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
41
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
42
import org.eclipse.pde.api.tools.ui.internal.ApiImageDescriptor;
43
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
44
import org.eclipse.pde.api.tools.ui.internal.IApiToolsConstants;
45
import org.eclipse.pde.api.tools.ui.internal.actions.ActionMessages;
46
import org.eclipse.pde.api.tools.ui.internal.actions.DeltaPropertyDialog;
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.PlatformUI;
56
import org.eclipse.ui.actions.ActionFactory;
57
import org.eclipse.ui.part.ViewPart;
58
59
/**
60
 * The class is used to show api tooling task results in a tree view.
61
 */
62
63
public class APIToolingView extends ViewPart implements ISessionListener {
64
65
	/**
66
	 * The ID of the view as specified by the extension.
67
	 */
68
	public static final String ID = "org.eclipse.pde.api.tools.ui.views.apitooling.views.apitoolingview"; //$NON-NLS-1$
69
70
	public TreeViewer viewer;
71
	private IAction removeActiveSessionAction;
72
	private IAction removeAllSessionsAction;
73
	private IAction selectSessionAction;
74
	private Action doubleClickAction;
75
	private ExportSessionAction exportSessionAction;
76
77
	class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {
78
		ITreeModel model;
79
		
80
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
81
			this.model = null;
82
		}
83
		public void dispose() {
84
		}
85
		public Object[] getElements(Object parent) {
86
			if (parent instanceof ISession) {
87
				ISession session = (ISession) parent;
88
				if (this.model == null) {
89
					this.model = session.getModel();
90
				}
91
				return getChildren(this.model.getRoot());
92
			}
93
			return getChildren(parent);
94
		}
95
		public Object getParent(Object child) {
96
			return null;
97
		}
98
		public Object [] getChildren(Object parent) {
99
			if (parent instanceof ITreeNode) {
100
				return ((ITreeNode) parent).getChildren();
101
			}
102
			return new Object[0];
103
		}
104
		public boolean hasChildren(Object parent) {
105
			if (parent instanceof ITreeNode) {
106
				return ((ITreeNode) parent).hasChildren();
107
			}
108
			return false;
109
		}
110
	}
111
	class ViewLabelProvider extends LabelProvider {
112
		public String getText(Object obj) {
113
			return obj.toString();
114
		}
115
116
		public Image getImage(Object obj) {
117
			if (obj instanceof ITreeNode) {
118
				ITreeNode treeNode = (ITreeNode) obj;
119
				switch(treeNode.getId()) {
120
					case ITreeNode.CLASS :
121
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS);
122
					case ITreeNode.INTERFACE :
123
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_INTERFACE);
124
					case ITreeNode.ANNOTATION :
125
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ANNOTATION);
126
					case ITreeNode.ENUM :
127
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ENUM);
128
					case ITreeNode.PACKAGE :
129
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PACKAGE);
130
				}
131
				Object data = treeNode.getData();
132
				if (data instanceof IDelta) {
133
					IDelta delta = (IDelta) data;
134
					Image image = getDeltaElementImage(delta);
135
					if (image != null) {
136
						int flags = (DeltaProcessor.isCompatible(delta) ? ApiImageDescriptor.SUCCESS : ApiImageDescriptor.ERROR);
137
						ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
138
						ApiImageDescriptor desc = new ApiImageDescriptor(descriptor, flags);
139
						return ApiUIPlugin.getImage(desc);
140
					}
141
				}
142
			}
143
			return null;
144
		}
145
146
		private Image getDeltaElementImage(IDelta delta) {
147
			switch(delta.getFlags()) {
148
				case IDelta.API_FIELD :
149
				case IDelta.FIELD : {
150
					int modifiers = delta.getNewModifiers();
151
					switch(delta.getKind()) {
152
						case IDelta.REMOVED : {
153
							modifiers = delta.getOldModifiers();
154
						}
155
					}
156
					if (Flags.isPublic(modifiers)) {
157
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PUBLIC);
158
					} else if (Flags.isProtected(modifiers)) {
159
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PROTECTED);
160
					} else if (Flags.isPrivate(modifiers)){
161
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PRIVATE);
162
					} else {
163
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_DEFAULT);
164
					}
165
				}
166
				case IDelta.METHOD :
167
				case IDelta.METHOD_MOVED_DOWN :
168
				case IDelta.METHOD_MOVED_UP :
169
				case IDelta.METHOD_WITH_DEFAULT_VALUE :
170
				case IDelta.METHOD_WITHOUT_DEFAULT_VALUE :
171
				case IDelta.CONSTRUCTOR :
172
				case IDelta.CLINIT : {
173
					int modifiers = delta.getNewModifiers();
174
					switch(delta.getKind()) {
175
						case IDelta.REMOVED : {
176
							modifiers = delta.getOldModifiers();
177
						}
178
					}
179
					if (Flags.isPublic(modifiers)) {
180
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
181
					} else if (Flags.isProtected(modifiers)) {
182
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PROTECTED);
183
					} else if (Flags.isPrivate(modifiers)){
184
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PRIVATE);
185
					} else {
186
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS_DEFAULT);
187
					}
188
				}
189
			}
190
			switch(delta.getElementType()) {
191
				case IDelta.ANNOTATION_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ANNOTATION);
192
				case IDelta.ENUM_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_ENUM);
193
				case IDelta.CLASS_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS);
194
				case IDelta.INTERFACE_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_INTERFACE);
195
				case IDelta.FIELD_ELEMENT_TYPE : {
196
					int modifiers = delta.getNewModifiers();
197
					switch(delta.getKind()) {
198
						case IDelta.REMOVED : {
199
							modifiers = delta.getOldModifiers();
200
						}
201
					}
202
					if (Flags.isPublic(modifiers)) {
203
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PUBLIC);
204
					} else if (Flags.isProtected(modifiers)) {
205
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PROTECTED);
206
					} else if (Flags.isPrivate(modifiers)){
207
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_PRIVATE);
208
					} else {
209
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_FIELD_DEFAULT);
210
					}
211
				}
212
				case IDelta.METHOD_ELEMENT_TYPE :
213
				case IDelta.CONSTRUCTOR_ELEMENT_TYPE : {
214
					int modifiers = delta.getNewModifiers();
215
					switch(delta.getKind()) {
216
						case IDelta.REMOVED : {
217
							modifiers = delta.getOldModifiers();
218
						}
219
					}
220
					if (Flags.isPublic(modifiers)) {
221
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
222
					} else if (Flags.isProtected(modifiers)) {
223
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PROTECTED);
224
					} else if (Flags.isPrivate(modifiers)){
225
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PRIVATE);
226
					} else {
227
						return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CLASS_DEFAULT);
228
					}
229
				}
230
				case IDelta.TYPE_PARAMETER_ELEMENT_TYPE : return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_PUBLIC);
231
				case IDelta.API_PROFILE_ELEMENT_TYPE : return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_ECLIPSE_PROFILE);
232
				case IDelta.API_COMPONENT_ELEMENT_TYPE : {
233
					String componentVersionId = delta.getComponentVersionId();
234
					IApiComponent component = null;
235
					if (componentVersionId != null) {
236
						int indexOfOpen = componentVersionId.lastIndexOf('(');
237
						String componentID = componentVersionId.substring(0, indexOfOpen);
238
						IApiBaseline baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
239
						if (baseline != null) {
240
							IApiComponent apiComponent = baseline.getApiComponent(componentID);
241
							if (apiComponent != null) {
242
								component = apiComponent;
243
							}
244
						}
245
					}
246
					if (component != null) {
247
						if(component.isSystemComponent()) {
248
							return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_API_SYSTEM_LIBRARY);
249
						}
250
						try {
251
							if (component.isFragment()) {
252
								return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_FRAGMENT);
253
							}
254
						} catch (CoreException e) {
255
							ApiPlugin.log(e);
256
						}
257
						return ApiUIPlugin.getSharedImage(IApiToolsConstants.IMG_OBJ_BUNDLE);
258
					}
259
				}
260
			}
261
			return null;
262
		}
263
	}
264
265
	/**
266
	 * The constructor.
267
	 */
268
	public APIToolingView() {
269
	}
270
	/**
271
	 * This is a callback that will allow us
272
	 * to create the viewer and initialize it.
273
	 */
274
	public void createPartControl(Composite parent) {
275
		this.viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
276
		this.viewer.setContentProvider(new ViewContentProvider());
277
		this.viewer.setLabelProvider(new ViewLabelProvider());
278
		ISession[] sessions = ApiPlugin.getDefault().getSessionManager().getSessions();
279
		if (sessions.length > 0) {
280
			this.viewer.setInput(sessions[0]);
281
		}
282
		// Create the help context id for the viewer's control
283
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this.viewer.getControl(), APIToolingView.ID);
284
		createActions();
285
		updateActions();
286
		configureToolbar();
287
		hookDoubleClickAction();
288
289
		ApiPlugin.getDefault().getSessionManager().addSessionListener(this);
290
	}
291
	private void hookDoubleClickAction() {
292
		this.viewer.addDoubleClickListener(new IDoubleClickListener() {
293
			public void doubleClick(DoubleClickEvent event) {
294
				APIToolingView.this.doubleClickAction.run();
295
			}
296
		});
297
	}
298
	public void dispose() {
299
		ApiPlugin.getDefault().getSessionManager().removeSessionListener(this);
300
	}
301
	protected void configureToolbar() {
302
		IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
303
		tbm.add(new Separator());
304
		tbm.add(this.removeActiveSessionAction);
305
		tbm.add(this.removeAllSessionsAction);
306
		tbm.add(this.selectSessionAction);
307
		tbm.add(new Separator());
308
//		tbm.add(new CollapseAllAction(this.viewer));
309
310
		IMenuManager mm = getViewSite().getActionBars().getMenuManager();
311
		mm.add(this.exportSessionAction);
312
	}
313
	private void createActions() {
314
		final IActionBars actionBars = getViewSite().getActionBars();
315
316
		this.removeActiveSessionAction = new RemoveActiveSessionAction();
317
		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), removeActiveSessionAction);
318
319
		this.removeAllSessionsAction = new RemoveAllSessionsAction();
320
		this.selectSessionAction = new SelectSessionAction();
321
		this.doubleClickAction = new Action() {
322
			public void run() {
323
				ISelection selection = viewer.getSelection();
324
				if (selection instanceof IStructuredSelection) {
325
					Object item = ((IStructuredSelection) selection).getFirstElement();
326
					if (APIToolingView.this.viewer.getExpandedState(item)) {
327
						APIToolingView.this.viewer.collapseToLevel(item, 1);
328
					} else {
329
						APIToolingView.this.viewer.expandToLevel(item, 1);
330
					}
331
					if (item instanceof ITreeNode) {
332
						ITreeNode node = (ITreeNode) item;
333
						if (node.getData() != null) {
334
							DeltaPropertyDialog dialog = new DeltaPropertyDialog(APIToolingView.this.getSite(), ActionMessages.DeltaDetails, (IDelta) node.getData());
335
							dialog.open();
336
						}
337
					}
338
				}
339
			}
340
		};
341
		this.exportSessionAction = new ExportSessionAction(this);
342
	}
343
	private void updateActions() {
344
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
345
			public void run() {
346
				ISessionManager sessionManager = ApiPlugin.getDefault().getSessionManager();
347
				ISession active = sessionManager.getActiveSession();
348
				setContentDescription(active == null ? "" : active.getTimestamp()); //$NON-NLS-1$
349
				ISession[] sessions =  sessionManager.getSessions();
350
				boolean atLeastOne = sessions.length >= 1;
351
				APIToolingView.this.removeActiveSessionAction.setEnabled(atLeastOne);
352
				APIToolingView.this.removeAllSessionsAction.setEnabled(atLeastOne);
353
				APIToolingView.this.selectSessionAction.setEnabled(atLeastOne);
354
				APIToolingView.this.exportSessionAction.setEnabled(active != null);
355
			}
356
		});
357
	}
358
	/**
359
	 * Passing the focus request to the viewer's control.
360
	 */
361
	public void setFocus() {
362
		this.viewer.getControl().setFocus();
363
	}
364
	public void sessionAdded(final ISession session) {
365
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
366
			public void run() {
367
				APIToolingView.this.viewer.setInput(session);
368
			}
369
		});
370
		updateActions();
371
	}
372
	public void sessionRemoved(ISession session) {
373
		this.viewer.setInput(null);
374
		updateActions();
375
	}
376
	
377
	public void sessionActivated(final ISession session) {
378
		this.viewer.getControl().getDisplay().asyncExec(new Runnable() {
379
			public void run() {
380
				APIToolingView.this.viewer.setInput(session);
381
			}
382
		});
383
		updateActions();
384
	}
385
}
(-)contexts.xml (+12 lines)
Added Link Here
1
<contexts>
2
	<context id="viewer" title="Sample View">
3
		<description>This is the context help for the sample view with a tree viewer. It was generated by a PDE template.</description>
4
		<topic href="/PLUGINS_ROOT/org.eclipse.platform.doc.isv/guide/ua_help_context.htm" label="Context-sensitive help">
5
			<enablement>
6
				<with variable="platform">
7
	            	<test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.platform.doc.isv"/>
8
	     		</with>
9
			</enablement>
10
		</topic>
11
	</context>
12
</contexts>
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ExportSessionAction.java (+160 lines)
Added Link Here
1
package org.eclipse.pde.api.tools.ui.internal.actions;
2
3
import java.io.BufferedWriter;
4
import java.io.File;
5
import java.io.FileWriter;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.Writer;
9
10
import javax.xml.transform.Result;
11
import javax.xml.transform.Source;
12
import javax.xml.transform.Transformer;
13
import javax.xml.transform.TransformerConfigurationException;
14
import javax.xml.transform.TransformerException;
15
import javax.xml.transform.TransformerFactory;
16
import javax.xml.transform.stream.StreamResult;
17
import javax.xml.transform.stream.StreamSource;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.SubMonitor;
25
import org.eclipse.core.runtime.jobs.Job;
26
import org.eclipse.jface.action.Action;
27
import org.eclipse.jface.window.Window;
28
import org.eclipse.pde.api.tools.internal.comparator.DeltaXmlVisitor;
29
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
30
import org.eclipse.pde.api.tools.internal.provisional.ISession;
31
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
32
import org.eclipse.pde.api.tools.internal.util.Util;
33
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
34
import org.eclipse.pde.api.tools.ui.internal.views.APIToolingView;
35
36
/**
37
 * Drop-down action to select the active session.
38
 */
39
public class ExportSessionAction extends Action {
40
	private static final String DELTAS_XSLT_TRANSFORM_PATH = "/xslt/deltas.xsl"; //$NON-NLS-1$
41
	private static final String XML_FILE_EXTENSION = ".xml"; //$NON-NLS-1$
42
	private static final String HTML_FILE_EXTENSION = ".html"; //$NON-NLS-1$
43
	APIToolingView view;
44
	public ExportSessionAction(APIToolingView view) {
45
		setText(ActionMessages.ExportSessionAction_label);
46
		setToolTipText(ActionMessages.ExportSessionAction_tooltip);
47
		setEnabled(false);
48
		this.view = view;
49
	}
50
51
	public void run() {
52
		final ISession activeSession = ApiPlugin.getDefault().getSessionManager().getActiveSession();
53
		if (activeSession == null) {
54
			return;
55
		}
56
		ExportDialog dialog = new ExportDialog(view.getSite(), ActionMessages.ExportActionTitle);
57
		int returnCode = dialog.open();
58
		if (returnCode == Window.CANCEL) {
59
			return;
60
		}
61
		final String reportFileName = dialog.reportPath;
62
		if (reportFileName == null) {
63
			return;
64
		}
65
		final String lowerCase = reportFileName.toLowerCase();
66
		if (!lowerCase.endsWith(HTML_FILE_EXTENSION) && !lowerCase.endsWith(XML_FILE_EXTENSION)) {
67
			return;
68
		}
69
		
70
		Job job = new Job(ActionMessages.CompareWithAction_comparing_apis){
71
			protected IStatus run(IProgressMonitor monitor) {
72
				SubMonitor progress = SubMonitor.convert(monitor, 100);
73
				progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName);
74
				boolean isHtmlFile = lowerCase.endsWith(HTML_FILE_EXTENSION);
75
				File xmlOutputFile = null;
76
				try {
77
					progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
78
					BufferedWriter writer = null;
79
					try {
80
						progress.worked(50);
81
						Util.checkCanceled(progress);
82
						if (isHtmlFile) {
83
							xmlOutputFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), XML_FILE_EXTENSION);
84
						} else {
85
							xmlOutputFile = new File(reportFileName);
86
						}
87
						if (xmlOutputFile.exists()) {
88
							xmlOutputFile.delete();
89
						}
90
						writer = new BufferedWriter(new FileWriter(xmlOutputFile));
91
						DeltaXmlVisitor visitor = new DeltaXmlVisitor();
92
						Object data = activeSession.getModel().getRoot().getData();
93
						if (data instanceof IDelta) {
94
							IDelta delta = (IDelta) data;
95
							progress.worked(25);
96
							delta.accept(visitor);
97
							writer.write(visitor.getXML());
98
							writer.flush();
99
							progress.worked(25);
100
						}
101
						return Status.OK_STATUS;
102
					} catch (IOException e) {
103
						ApiPlugin.log(e);
104
					} catch (CoreException e) {
105
						ApiPlugin.log(e);
106
					} catch(OperationCanceledException e) {
107
						// ignore
108
					} finally {
109
						try {
110
							if (writer != null) {
111
								writer.close();
112
							}
113
						} catch(IOException e) {}
114
					}
115
					progress.worked(1);
116
				} finally {
117
					monitor.done();
118
				}
119
				if(isHtmlFile) {
120
					// remaining part is to convert the xml file to html using XSLT
121
					Source xmlSource = new StreamSource(xmlOutputFile);
122
					InputStream stream = ApiPlugin.class.getResourceAsStream(DELTAS_XSLT_TRANSFORM_PATH);
123
					Source xsltSource = new StreamSource(stream);
124
					Writer writer = null;
125
					try {
126
						writer = new BufferedWriter(new FileWriter(reportFileName));
127
						Result result = new StreamResult(writer);
128
129
						// create an instance of TransformerFactory
130
						TransformerFactory transFact = TransformerFactory.newInstance();
131
132
						Transformer trans = transFact.newTransformer(xsltSource);
133
						trans.transform(xmlSource, result);
134
					} catch (TransformerConfigurationException e) {
135
						ApiUIPlugin.log(e);
136
					} catch (TransformerException e) {
137
						ApiUIPlugin.log(e);
138
					} catch(IOException e) {
139
						ApiUIPlugin.log(e);
140
					} finally {
141
						if (writer != null) {
142
							try {
143
								writer.close();
144
							} catch(IOException e) {
145
								// ignore
146
							}
147
						}
148
					}
149
				}
150
				return Status.CANCEL_STATUS;
151
			}
152
		};
153
		job.setSystem(false);
154
		job.setPriority(Job.LONG);
155
		job.schedule();
156
	}
157
	public void dispose() {
158
	}
159
160
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ExportDialog.java (+154 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
		saveWidgetState();
125
		super.okPressed();
126
	}
127
	/**
128
	 * Restores the selected item for the given combo based on the stored value from the 
129
	 * dialog settings
130
	 * 
131
	 * @param combo
132
	 * @param id
133
	 * @param settings
134
	 */
135
	private void restoreTextSelection(Text text, String id, IDialogSettings settings) {
136
		String value = settings.get(id);
137
		if(value != null) {
138
			ExportDialog.this.reportPath = value;
139
			text.setText(value);
140
		}
141
	}
142
	
143
	/**
144
	 * Saves the state of the widgets on the page
145
	 */
146
	void saveWidgetState() {
147
		IDialogSettings rootsettings = ApiUIPlugin.getDefault().getDialogSettings();
148
		IDialogSettings settings = rootsettings.getSection(SETTINGS_SECTION);
149
		if(settings == null) {
150
			settings = rootsettings.addNewSection(SETTINGS_SECTION);
151
		}
152
		settings.put(REPORT_PATH_STATE, this.reportPath);
153
	}
154
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/DeltaPropertyDialog.java (+79 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.dialogs.Dialog;
14
import org.eclipse.jface.window.IShellProvider;
15
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
16
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Shell;
21
22
/**
23
 * Compares {@link org.eclipse.pde.api.tools.internal.provisional.model.IApiElement}s
24
 * to a given {@link IApiBaseline} to get a delta
25
 * 
26
 * @since 1.0.1
27
 */
28
public class DeltaPropertyDialog extends Dialog {
29
	private String title = null;;
30
	private IDelta delta;
31
32
	/**
33
	 * Constructor
34
	 * @param provider
35
	 * @param title
36
	 */
37
	public DeltaPropertyDialog(IShellProvider provider, String title, IDelta delta) {
38
		super(provider);
39
		this.title = title;
40
	}
41
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
44
	 */
45
	protected void configureShell(Shell newShell) {
46
		super.configureShell(newShell);
47
		newShell.setText(this.title);
48
	}
49
	
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
52
	 */
53
	protected boolean isResizable() {
54
		return true;
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
59
	 */
60
	protected Control createDialogArea(Composite parent) {
61
		Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_HORIZONTAL);
62
		GridData gd = (GridData) comp.getLayoutData();
63
		gd.widthHint = 310;
64
		return comp;
65
	}
66
	
67
	/**
68
	 * Initializes the controls
69
	 */
70
	void initialize() {
71
	}
72
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
75
	 */
76
	protected void okPressed() {
77
		super.okPressed();
78
	}
79
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java (+442 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.Date;
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.SubMonitor;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.jdt.core.Flags;
25
import org.eclipse.jdt.core.IClassFile;
26
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaProject;
29
import org.eclipse.jdt.core.IPackageFragment;
30
import org.eclipse.jdt.core.IPackageFragmentRoot;
31
import org.eclipse.jdt.core.IType;
32
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jface.action.IAction;
34
import org.eclipse.jface.viewers.ISelection;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.window.Window;
37
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
38
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
39
import org.eclipse.pde.api.tools.internal.provisional.Factory;
40
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
41
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
42
import org.eclipse.pde.api.tools.internal.provisional.ISession;
43
import org.eclipse.pde.api.tools.internal.provisional.ITreeModel;
44
import org.eclipse.pde.api.tools.internal.provisional.ITreeNode;
45
import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
46
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator;
47
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope;
48
import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaVisitor;
49
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
50
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
51
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
52
import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
53
import org.eclipse.pde.api.tools.internal.provisional.model.IApiType;
54
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
55
import org.eclipse.ui.IObjectActionDelegate;
56
import org.eclipse.ui.IWorkbenchPart;
57
import org.eclipse.ui.IWorkbenchPartSite;
58
59
import com.ibm.icu.text.DateFormat;
60
61
public class CompareWithAction implements IObjectActionDelegate {
62
63
	public static class DeltaSession implements ISession {
64
		static Object[] NO_CHILDREN = new Object[0];
65
66
		static class TreeNode implements ITreeNode {
67
			Map children;
68
			String name;
69
			TreeNode parent;
70
			Object data;
71
			int id;
72
73
			public TreeNode(int id, String name, Object data) {
74
				this.name = name;
75
				this.id = id;
76
				this.data = data;
77
			}
78
			public Object[] getChildren() {
79
				if (this.children == null) {
80
					return NO_CHILDREN;
81
				}
82
				return this.children.values().toArray(new Object[this.children.size()]);
83
			}
84
			public TreeNode getNode(String name) {
85
				if (this.children == null) {
86
					return null;
87
				}
88
				return (TreeNode) this.children.get(name);
89
			}
90
			public int getId() {
91
				return this.id;
92
			}
93
			public void add(TreeNode node) {
94
				if (this.children == null) {
95
					this.children = new HashMap();
96
				}
97
				this.children.put(node.name, node);
98
			}
99
			public boolean hasChildren() {
100
				return this.children != null && !this.children.isEmpty();
101
			}
102
			public String toString() {
103
				return String.valueOf(this.name);
104
			}
105
			public Object getData() {
106
				return this.data;
107
			}
108
		}
109
110
		static class TreeModel implements ITreeModel {
111
			TreeNode root;
112
113
			TreeModel(TreeNode root) {
114
				this.root = root;
115
			}
116
			public ITreeNode getRoot() {
117
				return this.root;
118
			}
119
		}
120
121
		IDelta delta;
122
		String baselineName;
123
		String timestamp;
124
		
125
		public DeltaSession(IDelta delta, String baselineName) {
126
			this.delta = delta;
127
			this.baselineName = baselineName;
128
			this.timestamp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
129
		}
130
		public ITreeModel getModel() {
131
			TreeNode root = new TreeNode(0, null, this.delta);
132
			TreeModel model = new TreeModel(root);
133
			class TreeBuilder extends DeltaVisitor {
134
				TreeNode node;
135
				
136
				public TreeBuilder(TreeNode node) {
137
					this.node = node;
138
				}
139
				public void endVisit(IDelta delta) {
140
					if (delta.getChildren().length == 0) {
141
						String typeName = delta.getTypeName();
142
						if (typeName == null) {
143
							this.node.add(new TreeNode(0, delta.getKey(), delta));
144
						} else {
145
							// split the type name (package - type)
146
							int index = typeName.lastIndexOf('.');
147
							String packageName = "<default package>"; //$NON-NLS-1$
148
							String actualTypeName = null;
149
							if (index != -1) {
150
								packageName = typeName.substring(0, index);
151
								actualTypeName = typeName.substring(index + 1);
152
							} else {
153
								actualTypeName = typeName;
154
							}
155
							TreeNode node2 = this.node.getNode(packageName);
156
							if (node2 == null) {
157
								node2 = new TreeNode(ITreeNode.PACKAGE, packageName, null);
158
								this.node.add(node2);
159
							}
160
							TreeNode node3 = node2.getNode(actualTypeName);
161
							if (node3 == null) {
162
								int id = 0;
163
								switch(delta.getElementType()) {
164
									case IDelta.ANNOTATION_ELEMENT_TYPE :
165
										id = ITreeNode.ANNOTATION;
166
										break;
167
									case IDelta.INTERFACE_ELEMENT_TYPE :
168
										id = ITreeNode.INTERFACE;
169
										break;
170
									case IDelta.CLASS_ELEMENT_TYPE :
171
										id = ITreeNode.CLASS;
172
										break;
173
									case IDelta.ENUM_ELEMENT_TYPE :
174
										id = ITreeNode.ENUM;
175
									default :
176
										// we need to retrieve the type kind
177
										try {
178
											String componentVersionId = delta.getComponentVersionId();
179
											if (componentVersionId != null) {
180
												int indexOfOpen = componentVersionId.lastIndexOf('(');
181
												String componentID = componentVersionId.substring(0, indexOfOpen);
182
												String version = componentVersionId.substring(indexOfOpen + 1, componentVersionId.length() - 1);
183
												IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(DeltaSession.this.baselineName);
184
												int modifiers = 0;
185
												if (baseline != null) {
186
													IApiComponent apiComponent = baseline.getApiComponent(componentID);
187
													if (apiComponent != null && version.equals(apiComponent.getVersion())) {
188
														IApiTypeRoot typeRoot = apiComponent.findTypeRoot(typeName);
189
														if (typeRoot != null) {
190
															IApiType structure = typeRoot.getStructure();
191
															modifiers = structure.getModifiers();
192
														}
193
													}
194
												}
195
												if (modifiers == 0) {
196
													// try the workspace baseline
197
													baseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
198
													if (baseline != null) {
199
														IApiComponent apiComponent = baseline.getApiComponent(componentID);
200
														if (apiComponent != null && version.equals(apiComponent.getVersion())) {
201
															IApiTypeRoot typeRoot = apiComponent.findTypeRoot(typeName);
202
															if (typeRoot != null) {
203
																IApiType structure = typeRoot.getStructure();
204
																modifiers = structure.getModifiers();
205
															}
206
														}
207
													}
208
												}
209
												if (Flags.isEnum(modifiers)) {
210
													id = ITreeNode.ENUM;
211
												} else if (Flags.isAnnotation(modifiers)) {
212
													id = ITreeNode.ANNOTATION;
213
												} else if (Flags.isInterface(modifiers)) {
214
													id = ITreeNode.INTERFACE;
215
												} else {
216
													id = ITreeNode.CLASS;
217
												}
218
											}
219
										} catch (CoreException e) {
220
											// ignore
221
										}
222
								}
223
								node3 = new TreeNode(id, actualTypeName, null);
224
								node2.add(node3);
225
							}
226
							node3.add(new TreeNode(0, delta.getMessage(), delta));
227
						}
228
					}
229
				}
230
			}
231
			if (this.delta == ApiComparator.NO_DELTA) {
232
				root.add(new TreeNode(0, ActionMessages.CompareTaskNoChanges, null));
233
			} else {
234
				this.delta.accept(new TreeBuilder(root));
235
			}
236
			return model;
237
		}
238
		
239
		public String getTimestamp() {
240
			return this.timestamp;
241
		}
242
	}
243
244
	private IWorkbenchPartSite workbenchPartSite;
245
	private ISelection selection = null;
246
	
247
	/**
248
	 * Constructor for Action1.
249
	 */
250
	public CompareWithAction() {
251
		super();
252
	}
253
254
	/**
255
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
256
	 */
257
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
258
		workbenchPartSite = targetPart.getSite();
259
	}
260
	/**
261
	 * @see IActionDelegate#run(IAction)
262
	 */
263
	public void run(IAction action) {
264
		if (this.selection instanceof IStructuredSelection) {
265
			final IStructuredSelection structuredSelection=(IStructuredSelection) this.selection;
266
			CompareDialog dialog = new CompareDialog(workbenchPartSite, ActionMessages.CompareDialogTitle);
267
			int returnCode = dialog.open();
268
			if (returnCode == Window.CANCEL) return;
269
			final String baselineName = dialog.baseline;
270
			if (baselineName == null) return;
271
			final IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(baselineName);
272
			if (baseline == null) {
273
				return;
274
			}
275
			Job job = new Job(ActionMessages.CompareWithAction_comparing_apis){
276
				protected IStatus run(IProgressMonitor monitor) {
277
					SubMonitor progress = SubMonitor.convert(monitor, 100);
278
					progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName);
279
					SubMonitor loopProgress = progress.newChild(10).setWorkRemaining(structuredSelection.size());
280
					final IApiScope scope = walkStructureSelection(structuredSelection, loopProgress);
281
					try {
282
						progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
283
						SubMonitor compareProgress = progress.newChild(98).setWorkRemaining(scope.getApiElements().length);
284
						try {
285
							IDelta delta = ApiComparator.compare(scope, baseline, VisibilityModifiers.API, false, compareProgress);
286
							ApiPlugin.getDefault().getSessionManager().addSession(new DeltaSession(delta, baselineName), true);
287
							progress.worked(1);
288
							return Status.OK_STATUS;
289
						} catch (CoreException e) {
290
							ApiPlugin.log(e);
291
						} catch(OperationCanceledException e) {
292
							// ignore
293
						}
294
					} finally {
295
						monitor.done();
296
					}
297
					return Status.CANCEL_STATUS;
298
				}
299
			};
300
			job.setSystem(false);
301
			job.setPriority(Job.LONG);
302
			job.schedule();
303
			return;
304
		}
305
	}
306
307
	public static ApiScope walkStructureSelection(
308
			IStructuredSelection structuredSelection,
309
			IProgressMonitor monitor) {
310
		Object[] selected=structuredSelection.toArray();
311
		ApiScope scope = new ApiScope();
312
		IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
313
		if (workspaceBaseline == null) {
314
			return scope;
315
		}
316
		for (int i=0, max = selected.length; i < max; i++) {
317
			Object currentSelection = selected[i];
318
			if (currentSelection instanceof IJavaElement) {
319
				monitor.worked(1);
320
				IJavaElement element =(IJavaElement) currentSelection;
321
				IJavaProject javaProject = element.getJavaProject();
322
				try {
323
					switch (element.getElementType()) {
324
						case IJavaElement.COMPILATION_UNIT: {
325
							ICompilationUnit compilationUnit = (ICompilationUnit) element;
326
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
327
							if (apiComponent != null) {
328
								addElementFor(compilationUnit, apiComponent, scope);
329
							}
330
							break;
331
						}
332
						case IJavaElement.PACKAGE_FRAGMENT: {
333
							IPackageFragment fragment = (IPackageFragment) element;
334
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
335
							IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
336
							boolean isArchive = false;
337
							if (packageFragmentRoot != null) {
338
								isArchive = packageFragmentRoot.isArchive();
339
							}
340
							if (apiComponent != null) {
341
								addElementFor(fragment, isArchive, apiComponent, scope);
342
							}
343
							break;
344
						}
345
						case IJavaElement.PACKAGE_FRAGMENT_ROOT: {
346
							IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) element;
347
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
348
							if (apiComponent != null) {
349
								addElementFor(fragmentRoot, apiComponent, scope);
350
							}
351
							break;
352
						}
353
						case IJavaElement.JAVA_PROJECT:
354
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
355
							IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
356
							for (int j = 0, max2 = roots.length; j < max2; j++) {
357
								addElementFor(roots[j], apiComponent, scope);
358
							}
359
							break;
360
					}
361
				} catch (JavaModelException e) {
362
					ApiPlugin.log(e);
363
				} catch (CoreException e) {
364
					ApiPlugin.log(e);
365
				}
366
			}
367
		}
368
		return scope;
369
	}
370
371
	private static void addElementFor(
372
			IPackageFragmentRoot fragmentRoot, IApiComponent apiComponent,
373
			ApiScope scope) throws JavaModelException, CoreException {
374
		boolean isArchive = fragmentRoot.isArchive();
375
		IJavaElement[] packageFragments = fragmentRoot.getChildren();
376
		for (int j = 0, max2 = packageFragments.length; j < max2; j++) {
377
			IPackageFragment packageFragment = (IPackageFragment) packageFragments[j];
378
			addElementFor(packageFragment, isArchive, apiComponent, scope);
379
		}
380
	}
381
382
	private static void addElementFor(
383
			IPackageFragment packageFragment,
384
			boolean isArchive,
385
			IApiComponent apiComponent,
386
			ApiScope scope)
387
		throws JavaModelException, CoreException {
388
389
		// add package fragment elements only if this is an API package
390
		IApiDescription apiDescription = apiComponent.getApiDescription();
391
		IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName()));
392
		if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) {
393
			return;
394
		}
395
		if (isArchive) {
396
			IClassFile[] classFiles = packageFragment.getClassFiles();
397
			for (int i = 0, max= classFiles.length; i < max; i++) {
398
				addElementFor(classFiles[i], apiComponent, scope);
399
			}
400
		} else {
401
			ICompilationUnit[] units = packageFragment.getCompilationUnits();
402
			for (int i = 0, max= units.length; i < max; i++) {
403
				addElementFor(units[i], apiComponent, scope);
404
			}
405
		}
406
	}
407
408
	private static void addElementFor(IClassFile classFile,
409
			IApiComponent apiComponent, ApiScope scope) {
410
		try {
411
			IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName());
412
			if (typeRoot != null) {
413
				scope.add(typeRoot);
414
			}
415
		} catch (CoreException e) {
416
			ApiPlugin.log(e);
417
		}
418
	}
419
420
	private static void addElementFor(ICompilationUnit compilationUnit, IApiComponent component, ApiScope scope) throws JavaModelException {
421
		IType[] types = compilationUnit.getTypes();
422
		for (int i = 0, max = types.length; i < max; i++) {
423
			try {
424
				IApiTypeRoot typeRoot = component.findTypeRoot(types[i].getFullyQualifiedName());
425
				if (typeRoot != null) {
426
					scope.add(typeRoot);
427
				}
428
			} catch (CoreException e) {
429
				ApiPlugin.log(e);
430
			}
431
		}
432
	}
433
434
	/**
435
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
436
	 */
437
	public void selectionChanged(IAction action, ISelection selection) {
438
		this.selection = selection;
439
	}
440
441
	
442
}

Return to bug 258853