001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards;
011:
012: import org.eclipse.core.runtime.IPath;
013: import org.eclipse.jdt.core.IClasspathContainer;
014: import org.eclipse.jdt.core.IClasspathEntry;
015: import org.eclipse.jdt.core.IJavaProject;
016: import org.eclipse.jdt.core.JavaCore;
017: import org.eclipse.jdt.core.JavaModelException;
018: import org.eclipse.jdt.ui.JavaUI;
019: import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
020: import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension;
021: import org.eclipse.jface.dialogs.Dialog;
022: import org.eclipse.jface.viewers.IStructuredContentProvider;
023: import org.eclipse.jface.viewers.ITableLabelProvider;
024: import org.eclipse.jface.viewers.LabelProvider;
025: import org.eclipse.jface.viewers.TableViewer;
026: import org.eclipse.jface.viewers.ViewerComparator;
027: import org.eclipse.jface.wizard.WizardPage;
028: import org.eclipse.pde.core.plugin.IPluginModelBase;
029: import org.eclipse.pde.core.plugin.PluginRegistry;
030: import org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer;
031: import org.eclipse.pde.internal.ui.IHelpContextIds;
032: import org.eclipse.pde.internal.ui.PDEPluginImages;
033: import org.eclipse.pde.internal.ui.PDEUIMessages;
034: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
035: import org.eclipse.pde.internal.ui.wizards.plugin.ClasspathComputer;
036: import org.eclipse.swt.SWT;
037: import org.eclipse.swt.graphics.Image;
038: import org.eclipse.swt.layout.GridData;
039: import org.eclipse.swt.layout.GridLayout;
040: import org.eclipse.swt.widgets.Composite;
041: import org.eclipse.swt.widgets.Label;
042: import org.eclipse.ui.PlatformUI;
043: import org.eclipse.ui.ide.IDE;
044:
045: public class RequiredPluginsContainerPage extends WizardPage implements
046: IClasspathContainerPage, IClasspathContainerPageExtension {
047: private IClasspathEntry entry;
048: private TableViewer viewer;
049: private Image projectImage;
050: private Image libraryImage;
051: private Image slibraryImage;
052: private IClasspathEntry[] realEntries;
053: private IJavaProject javaProject;
054:
055: class EntryContentProvider extends DefaultContentProvider implements
056: IStructuredContentProvider {
057: public Object[] getElements(Object parent) {
058: if (realEntries != null)
059: return realEntries;
060: return new Object[0];
061: }
062: }
063:
064: // class EntrySorter extends ViewerSorter {
065: // public int category(Object obj) {
066: // IClasspathEntry entry = (IClasspathEntry) obj;
067: // return entry.getEntryKind() == IClasspathEntry.CPE_PROJECT
068: // ? -10
069: // : 0;
070: // }
071: // }
072:
073: class EntryLabelProvider extends LabelProvider implements
074: ITableLabelProvider {
075: public String getText(Object obj) {
076: IClasspathEntry entry = (IClasspathEntry) obj;
077: int kind = entry.getEntryKind();
078: if (kind == IClasspathEntry.CPE_PROJECT)
079: return entry.getPath().segment(0);
080: IPath path = entry.getPath();
081: String name = path.lastSegment();
082: return name
083: + " - " //$NON-NLS-1$
084: + path.uptoSegment(path.segmentCount() - 1)
085: .toOSString();
086: }
087:
088: public Image getImage(Object obj) {
089: IClasspathEntry entry = (IClasspathEntry) obj;
090: int kind = entry.getEntryKind();
091: if (kind == IClasspathEntry.CPE_PROJECT)
092: return projectImage;
093: else if (kind == IClasspathEntry.CPE_LIBRARY) {
094: IPath sourceAtt = entry.getSourceAttachmentPath();
095: return sourceAtt != null ? slibraryImage : libraryImage;
096: }
097: return null;
098: }
099:
100: public String getColumnText(Object obj, int col) {
101: return getText(obj);
102: }
103:
104: public Image getColumnImage(Object obj, int col) {
105: return getImage(obj);
106: }
107: }
108:
109: /**
110: * The constructor.
111: */
112: public RequiredPluginsContainerPage() {
113: super ("requiredPluginsContainerPage"); //$NON-NLS-1$
114: setTitle(PDEUIMessages.RequiredPluginsContainerPage_title);
115: setDescription(PDEUIMessages.RequiredPluginsContainerPage_desc);
116: projectImage = PlatformUI.getWorkbench().getSharedImages()
117: .getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
118: //libraryImage = PDEPluginImages.DESC_BUILD_VAR_OBJ.createImage();
119: libraryImage = JavaUI
120: .getSharedImages()
121: .getImage(
122: org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE);
123: slibraryImage = JavaUI
124: .getSharedImages()
125: .getImage(
126: org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE);
127: setImageDescriptor(PDEPluginImages.DESC_CONVJPPRJ_WIZ);
128: }
129:
130: /**
131: * Insert the method's description here.
132: * @see WizardPage#createControl
133: */
134: public void createControl(Composite parent) {
135: Composite container = new Composite(parent, SWT.NULL);
136: container.setLayout(new GridLayout());
137: Label label = new Label(container, SWT.NULL);
138: label.setText(PDEUIMessages.RequiredPluginsContainerPage_label);
139: viewer = new TableViewer(container, SWT.BORDER | SWT.V_SCROLL
140: | SWT.H_SCROLL);
141: viewer.setContentProvider(new EntryContentProvider());
142: viewer.setLabelProvider(new EntryLabelProvider());
143: viewer.setComparator(new ViewerComparator());
144:
145: GridData gd = new GridData(GridData.FILL_BOTH);
146: gd.widthHint = 400;
147: gd.heightHint = 300;
148: viewer.getTable().setLayoutData(gd);
149:
150: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
151: IHelpContextIds.PLUGINS_CONTAINER_PAGE);
152: setControl(container);
153: Dialog.applyDialogFont(container);
154: if (realEntries != null)
155: initializeView();
156:
157: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
158: IHelpContextIds.REQUIRED_PLUINGS_CONTAINER);
159: }
160:
161: /**
162: * Insert the method's description here.
163: * @see WizardPage#finish
164: */
165: public boolean finish() {
166: return true;
167: }
168:
169: /**
170: * Insert the method's description here.
171: * @see WizardPage#getSelection
172: */
173: public IClasspathEntry getSelection() {
174: return entry;
175: }
176:
177: public void initialize(IJavaProject project,
178: IClasspathEntry[] currentEntries) {
179: javaProject = project;
180: }
181:
182: /**
183: * Insert the method's description here.
184: * @see WizardPage#setSelection
185: */
186: public void setSelection(IClasspathEntry containerEntry) {
187: this .entry = containerEntry;
188: createRealEntries();
189: if (viewer != null)
190: initializeView();
191: }
192:
193: private void createRealEntries() {
194: IJavaProject javaProject = getJavaProject();
195: if (javaProject == null) {
196: realEntries = new IClasspathEntry[0];
197: return;
198: }
199:
200: if (entry == null) {
201: entry = ClasspathComputer.createContainerEntry();
202: IPluginModelBase model = PluginRegistry
203: .findModel(javaProject.getProject());
204: if (model != null) {
205: IClasspathContainer container = new RequiredPluginsClasspathContainer(
206: model);
207: if (container != null)
208: realEntries = container.getClasspathEntries();
209: }
210: } else {
211: try {
212: IClasspathContainer container = JavaCore
213: .getClasspathContainer(entry.getPath(),
214: javaProject);
215: if (container != null)
216: realEntries = container.getClasspathEntries();
217: } catch (JavaModelException e) {
218: }
219: }
220: if (realEntries == null)
221: realEntries = new IClasspathEntry[0];
222: }
223:
224: private IJavaProject getJavaProject() {
225: return javaProject;
226: }
227:
228: private void initializeView() {
229: viewer.setInput(entry);
230: }
231: }
|