KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > feature > PatchPluginListPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.wizards.feature;
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.resource.*;
16 import org.eclipse.jface.viewers.*;
17 import org.eclipse.pde.internal.core.*;
18 import org.eclipse.pde.internal.core.ifeature.*;
19 import org.eclipse.pde.internal.ui.*;
20 import org.eclipse.pde.internal.ui.elements.*;
21 import org.eclipse.pde.internal.ui.wizards.*;
22 import org.eclipse.pde.internal.ui.wizards.feature.NewFeaturePatchWizard.*;
23 import org.eclipse.swt.*;
24 import org.eclipse.swt.layout.*;
25 import org.eclipse.swt.widgets.*;
26 import org.eclipse.ui.help.*;
27
28 /**
29  * @author cgwong
30  */

31 public class PatchPluginListPage extends BasePluginListPage {
32
33     public static final String JavaDoc PAGE_TITLE = "PatchPlugins.title"; //$NON-NLS-1$
34
public static final String JavaDoc PAGE_DESC = "PatchPlugins.desc"; //$NON-NLS-1$
35
private IProjectProvider provider;
36     private CheckboxTableViewer pluginViewer;
37
38     /**
39      * @param pageName
40      */

41     public PatchPluginListPage(String JavaDoc pageName) {
42         super(pageName);
43         setTitle(PDEPlugin.getResourceString(PAGE_TITLE));
44         setDescription(PDEPlugin.getResourceString(PAGE_DESC));
45     }
46
47     /**
48      * @param provider
49      */

50     public PatchPluginListPage(IProjectProvider provider) {
51         super("patchPluginList"); //$NON-NLS-1$
52
this.provider = provider;
53         setTitle(PDEPlugin.getResourceString(PAGE_TITLE));
54         setDescription(PDEPlugin.getResourceString(PAGE_DESC));
55     }
56
57     /**
58      * @param pageName
59      * @param title
60      * @param titleImage
61      */

62     public PatchPluginListPage(String JavaDoc pageName, String JavaDoc title,
63             ImageDescriptor titleImage) {
64         super(pageName, title, titleImage);
65     }
66
67     class PluginContentProvider extends DefaultContentProvider
68             implements
69                 IStructuredContentProvider {
70
71         public Object JavaDoc[] getElements(Object JavaDoc parent) {
72             return getPluginModels();
73         }
74     }
75
76     public PatchPluginListPage() {
77         super("patchPluginListPage"); //$NON-NLS-1$
78
setTitle(PDEPlugin.getResourceString(PAGE_TITLE));
79         setDescription(PDEPlugin.getResourceString(PAGE_DESC));
80     }
81
82     public void createControl(Composite parent) {
83         Composite container = new Composite(parent, SWT.NULL);
84         GridLayout layout = new GridLayout();
85         layout.numColumns = 2;
86         layout.verticalSpacing = 9;
87         container.setLayout(layout);
88
89         tablePart.createControl(container);
90         pluginViewer = tablePart.getTableViewer();
91         pluginViewer.setContentProvider(new PluginContentProvider());
92         pluginViewer
93                 .setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
94         pluginViewer.setSorter(ListUtil.PLUGIN_SORTER);
95         GridData gd = (GridData) tablePart.getControl().getLayoutData();
96         gd.heightHint = 250;
97         pluginViewer.setInput(PDECore.getDefault().getWorkspaceModelManager());
98         tablePart.setSelection(new Object JavaDoc[0]);
99         setControl(container);
100         Dialog.applyDialogFont(container);
101         WorkbenchHelp.setHelp(container,
102                 IHelpContextIds.NEW_FEATURE_REFERENCED_PLUGINS);
103     }
104
105     private Object JavaDoc[] getPluginModels() {
106         IFeatureModel featureModel = ((FeaturePatchProvider)provider).getFeatureToPatch();
107         if (featureModel== null)
108             return new Object JavaDoc[0];
109         return featureModel.getFeature().getPlugins();
110     }
111
112     public IFeaturePlugin[] getSelectedPlugins(){
113         IFeatureModel featureModel = ((FeaturePatchProvider)provider).getFeatureToPatch();
114         if (featureModel== null)
115             return new IFeaturePlugin[0];
116         Object JavaDoc[] result = tablePart.getSelection();
117         IFeaturePlugin[] plugins = new IFeaturePlugin[result.length];
118         for (int i = 0 ;i<plugins.length; i++){
119             plugins[i] = (IFeaturePlugin)result[i];
120         }
121         return plugins;
122     }
123     
124     /* (non-Javadoc)
125      * @see org.eclipse.pde.internal.ui.wizards.feature.BasePluginListPage#setVisible(boolean)
126      */

127     public void setVisible(boolean visible) {
128         if (visible = true){
129             pluginViewer.refresh();
130         }
131         super.setVisible(visible);
132     }
133 }
134
Popular Tags