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
/*******************************************************************************
 *  Copyright (c) 2000, 2008 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.pde.internal.ui.wizards;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ClasspathComputer;
import org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer;
import org.eclipse.pde.internal.ui.*;
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

public class RequiredPluginsContainerPage extends WizardPage implements IClasspathContainerPage, IClasspathContainerPageExtension {
    private IClasspathEntry entry;
    private TableViewer viewer;
    private Image projectImage;
    private Image libraryImage;
    private Image slibraryImage;
    private IClasspathEntry[] realEntries;
    private IJavaProject javaProject;

    class EntryContentProvider extends DefaultContentProvider implements IStructuredContentProvider {
        public Object[] getElements(Object parent) {
            if (realEntries != null)
                return realEntries;
            return new Object[0];
        }
    }

//  class EntrySorter extends ViewerSorter {
//      public int category(Object obj) {
//          IClasspathEntry entry = (IClasspathEntry) obj;
//          return entry.getEntryKind() == IClasspathEntry.CPE_PROJECT
//              ? -10
//              : 0;
//      }
//  }

    class EntryLabelProvider extends LabelProvider implements ITableLabelProvider {
        public String getText(Object obj) {
            IClasspathEntry entry = (IClasspathEntry) obj;
            int kind = entry.getEntryKind();
            if (kind == IClasspathEntry.CPE_PROJECT)
                return entry.getPath().segment(0);
            IPath path = entry.getPath();
            String name = path.lastSegment();
            return name + " - " //$NON-NLS-1$
                    + path.uptoSegment(path.segmentCount() - 1).toOSString();
        }

        public Image getImage(Object obj) {
            IClasspathEntry entry = (IClasspathEntry) obj;
            int kind = entry.getEntryKind();
            if (kind == IClasspathEntry.CPE_PROJECT)
                return projectImage;
            else if (kind == IClasspathEntry.CPE_LIBRARY) {
                IPath sourceAtt = entry.getSourceAttachmentPath();
                return sourceAtt != null ? slibraryImage : libraryImage;
            }
            return null;
        }

        public String getColumnText(Object obj, int col) {
            return getText(obj);
        }

        public Image getColumnImage(Object obj, int col) {
            return getImage(obj);
        }
    }

    /**
     * The constructor.
     */
    public RequiredPluginsContainerPage() {
        super("requiredPluginsContainerPage"); //$NON-NLS-1$
        setTitle(PDEUIMessages.RequiredPluginsContainerPage_title);
        setDescription(PDEUIMessages.RequiredPluginsContainerPage_desc);
        projectImage = PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
        //libraryImage = PDEPluginImages.DESC_BUILD_VAR_OBJ.createImage();
        libraryImage = JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE);
        slibraryImage = JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE);
        setImageDescriptor(PDEPluginImages.DESC_CONVJPPRJ_WIZ);
    }

    /**
     * Insert the method's description here.
     * @see WizardPage#createControl
     */
    public void createControl(Composite parent) {
        Composite container = new Composite(parent, SWT.NULL);
        container.setLayout(new GridLayout());
        Label label = new Label(container, SWT.NULL);
        label.setText(PDEUIMessages.RequiredPluginsContainerPage_label);
        viewer = new TableViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        viewer.setContentProvider(new EntryContentProvider());
        viewer.setLabelProvider(new EntryLabelProvider());
        viewer.setComparator(new ViewerComparator());

        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 400;
        gd.heightHint = 300;
        viewer.getTable().setLayoutData(gd);

        PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.PLUGINS_CONTAINER_PAGE);
        setControl(container);
        Dialog.applyDialogFont(container);
        if (realEntries != null)
            initializeView();

        PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.REQUIRED_PLUINGS_CONTAINER);
    }

    /**
     * Insert the method's description here.
     * @see WizardPage#finish
     */
    public boolean finish() {
        return true;
    }

    /**
     * Insert the method's description here.
     * @see WizardPage#getSelection
     */
    public IClasspathEntry getSelection() {
        return entry;
    }

    public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) {
        javaProject = project;
    }

    /**
     * Insert the method's description here.
     * @see WizardPage#setSelection
     */
    public void setSelection(IClasspathEntry containerEntry) {
        this.entry = containerEntry;
        createRealEntries();
        if (viewer != null)
            initializeView();
    }

    private void createRealEntries() {
        IJavaProject javaProject = getJavaProject();
        if (javaProject == null) {
            realEntries = new IClasspathEntry[0];
            return;
        }

        if (entry == null) {
            entry = ClasspathComputer.createContainerEntry();
            IPluginModelBase model = PluginRegistry.findModel(javaProject.getProject());
            if (model != null) {
                IClasspathContainer container = new RequiredPluginsClasspathContainer(model);
                if (container != null)
                    realEntries = container.getClasspathEntries();
            }
        } else {
            try {
                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
                if (container != null)
                    realEntries = container.getClasspathEntries();
            } catch (JavaModelException e) {
            }
        }
        if (realEntries == null)
            realEntries = new IClasspathEntry[0];
    }

    private IJavaProject getJavaProject() {
        return javaProject;
    }

    private void initializeView() {
        viewer.setInput(entry);
    }
}
			
			

Browsed Source: [clear]