Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 9efe70082f1c96378f86b05e14d6dca2fdfa9d64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*******************************************************************************
 * Copyright (c) 2003, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.internal.wizard;



import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.j2ee.application.internal.operations.ClassPathSelection;
import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.common.frameworks.internal.ui.OverlayIcon;


public class AvailableJarsProvider implements org.eclipse.jface.viewers.IStructuredContentProvider, org.eclipse.jface.viewers.ITableLabelProvider {
	protected static Image utilImage;
	protected static Image invalidImage;
	protected static Image ejbImage;
	protected static Image ejbClientImage;
	protected static Image classpathImage;

	/**
	 * AvailableJarsContentProvider constructor comment.
	 */
	public AvailableJarsProvider() {
		super();
	}

	/**
	 * Adds a listener to this label provider. Has no effect if an identical listener is already
	 * registered.
	 * <p>
	 * Label provider listeners are informed about state changes that affect the rendering of the
	 * viewer that uses this label provider.
	 * </p>
	 * 
	 * @param listener
	 *            a label provider listener
	 */
	public void addListener(org.eclipse.jface.viewers.ILabelProviderListener listener) {
		//do nothing
	}

	/**
	 * Disposes of this label provider. When a label provider is attached to a viewer, the viewer
	 * will automatically call this method when the viewer is being closed. When label providers are
	 * used outside of the context of a viewer, it is the client's responsibility to ensure that
	 * this method is called when the provider is no longer needed.
	 */
	public void dispose() {
		//dispose
	}

	/**
	 * Returns the label image for the given column of the given element.
	 * 
	 * @param element
	 *            the object representing the entire row, or <code>null</code> indicating that no
	 *            input object is set in the viewer
	 * @param columnIndex
	 *            the zero-based index of the column in which the label appears
	 */
	public org.eclipse.swt.graphics.Image getColumnImage(Object element, int columnIndex) {
		if (columnIndex > 0)
			return null;
		ClasspathElement cp = (ClasspathElement) element;
		if (!cp.isValid())
			return getInvalidImage();
		
		if (cp.isClasspathEntry()) {
			return getClasspathDependencyImage();
		}
		
		switch (cp.getJarType()) {
			case ClasspathElement.EJB_JAR :
				return getEjbImage();
			case ClasspathElement.EJB_CLIENT_JAR :
				return getEjbClientImage();
			default :
				return getUtilImage();
		}
	}

	/**
	 * Returns the label text for the given column of the given element.
	 * 
	 * @param element
	 *            the object representing the entire row, or <code>null</code> indicating that no
	 *            input object is set in the viewer
	 * @param columnIndex
	 *            the zero-based index of the column in which the label appears
	 */
	public String getColumnText(Object element, int columnIndex) {
		String value = null;
		switch (columnIndex) {
			case 0 : {
				value = ((ClasspathElement) element).getText();
				break;
			}
			case 1 :
				value = ((ClasspathElement) element).getProjectName();
		}
		return value == null ? "" : value;//$NON-NLS-1$
	}

	public static Image getEjbImage() {
		if (ejbImage == null)
			ejbImage = getImageDescriptor("EJBJar").createImage();//$NON-NLS-1$
		return ejbImage;
	}

	public static Image getEjbClientImage() {
		if (ejbClientImage == null)
			ejbClientImage = getImageDescriptor("ejbclientjar_obj").createImage();//$NON-NLS-1$
		return ejbClientImage;
	}
	
	public static Image getClasspathDependencyImage() {
		if (classpathImage == null)
			classpathImage = getImageDescriptor("CPDep").createImage();//$NON-NLS-1$
		return classpathImage;
	}

	/**
	 * Returns the elements to display in the viewer when its input is set to the given element.
	 * These elements can be presented as rows in a table, items in a list, etc. The result is not
	 * modified by the viewer.
	 * 
	 * @param inputElement
	 *            the input element
	 * @return the array of elements to display in the viewer
	 */
	public java.lang.Object[] getElements(Object inputElement) {
		ClassPathSelection selection = (ClassPathSelection) inputElement;
		return filter(selection, selection.getFilterLevel()).toArray();
	}

	/**
	 * @param list
	 */
	private List filter(ClassPathSelection selection, int filterLevel) {
		List list = selection.getClasspathElements();
		List result = new ArrayList(list.size());
		for (int i = 0; i < list.size(); i++) {
			ClasspathElement element = (ClasspathElement) list.get(i);
			if (!element.isSelected()) {
				switch (filterLevel) {
					case (ClassPathSelection.FILTER_EJB_CLIENT_JARS) :
						if (element.isEJBClientJar())
							continue;
						break;
					case (ClassPathSelection.FILTER_EJB_SERVER_JARS) :
						if (element.isEJBJar() && selection.getOppositeElement(element) != null)
							continue;
				}
			}
			result.add(element);
		}
		return result;
	}

	/**
	 * This gets a .gif from the icons folder.
	 */
	protected static ImageDescriptor getImageDescriptor(String key) {
		ImageDescriptor imageDescriptor = null;

		URL gifImageURL = (URL) J2EEPlugin.getPlugin().getImage(key);
		imageDescriptor = ImageDescriptor.createFromURL(gifImageURL);
		return imageDescriptor;
	}

	public static Image getInvalidImage() {
		if (invalidImage == null) {
			ImageDescriptor base = getImageDescriptor("jar_nonexist_obj");//$NON-NLS-1$
			ImageDescriptor overlay = getImageDescriptor("warning_co");//$NON-NLS-1$
			invalidImage = new OverlayIcon(base, new ImageDescriptor[][]{{overlay}}).createImage();
		}
		return invalidImage;
	}

	public static Image getUtilImage() {
		if (utilImage == null)
			utilImage = getImageDescriptor("jar_obj").createImage();//$NON-NLS-1$
		return utilImage;
	}

	/**
	 * Notifies this content provider that the given viewer's input has been switched to a different
	 * element.
	 * <p>
	 * A typical use for this method is registering the content provider as a listener to changes on
	 * the new input (using model-specific means), and deregistering the viewer from the old input.
	 * In response to these change notifications, the content provider propagates the changes to the
	 * viewer.
	 * </p>
	 * 
	 * @param viewer
	 *            the viewer
	 * @param oldInput
	 *            the old input element, or <code>null</code> if the viewer did not previously
	 *            have an input
	 * @param newInput
	 *            the new input element, or <code>null</code> if the viewer does not have an input
	 */
	public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, Object oldInput, Object newInput) {
		//do nothing
	}

	/**
	 * Returns whether the label would be affected by a change to the given property of the given
	 * element. This can be used to optimize a non-structural viewer update. If the property
	 * mentioned in the update does not affect the label, then the viewer need not update the label.
	 * 
	 * @param element
	 *            the element
	 * @param property
	 *            the property
	 * @return <code>true</code> if the label would be affected, and <code>false</code> if it
	 *         would be unaffected
	 */
	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	/**
	 * Removes a listener to this label provider. Has no affect if an identical listener is not
	 * registered.
	 * 
	 * @param listener
	 *            a label provider listener
	 */
	public void removeListener(org.eclipse.jface.viewers.ILabelProviderListener listener) {
		//do nothing
	}
}

Back to the top