KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > tools > UpdateBuildpathWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.internal.ui.wizards.tools;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.viewers.CheckboxTableViewer;
15 import org.eclipse.jface.viewers.IStructuredContentProvider;
16 import org.eclipse.jface.viewers.StructuredViewer;
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.pde.core.plugin.IPluginModelBase;
19 import org.eclipse.pde.internal.ui.IHelpContextIds;
20 import org.eclipse.pde.internal.ui.PDEPlugin;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
23 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
24 import org.eclipse.pde.internal.ui.wizards.ListUtil;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.forms.widgets.FormToolkit;
31
32 public class UpdateBuildpathWizardPage extends WizardPage {
33     private IPluginModelBase[] fSelected;
34     private IPluginModelBase[] fUnmigrated;
35     private CheckboxTableViewer pluginListViewer;
36     private TablePart tablePart;
37
38     public class BuildpathContentProvider
39         extends DefaultContentProvider
40         implements IStructuredContentProvider {
41         public Object JavaDoc[] getElements(Object JavaDoc parent) {
42             if (fUnmigrated != null)
43                 return fUnmigrated;
44             return new Object JavaDoc[0];
45         }
46     }
47
48     class TablePart extends WizardCheckboxTablePart {
49         public TablePart(String JavaDoc mainLabel) {
50             super(mainLabel);
51         }
52
53         public void updateCounter(int count) {
54             super.updateCounter(count);
55             dialogChanged();
56         }
57         protected StructuredViewer createStructuredViewer(
58             Composite parent,
59             int style,
60             FormToolkit toolkit) {
61             StructuredViewer viewer =
62                 super.createStructuredViewer(parent, style, toolkit);
63             viewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
64             return viewer;
65         }
66     }
67
68     public UpdateBuildpathWizardPage(IPluginModelBase[] models, IPluginModelBase[] selected) {
69         super("UpdateBuildpathWizardPage"); //$NON-NLS-1$
70
setTitle(PDEUIMessages.UpdateBuildpathWizard_title);
71         setDescription(PDEUIMessages.UpdateBuildpathWizard_desc);
72         this.fUnmigrated = models;
73         this.fSelected = selected;
74         tablePart = new TablePart(PDEUIMessages.UpdateBuildpathWizard_availablePlugins);
75         PDEPlugin.getDefault().getLabelProvider().connect(this);
76     }
77     
78     public void dispose() {
79         super.dispose();
80         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
81     }
82
83     public void createControl(Composite parent) {
84         Composite container = new Composite(parent, SWT.NONE);
85         GridLayout layout = new GridLayout();
86         layout.numColumns = 2;
87         layout.marginHeight = 0;
88         layout.marginWidth = 5;
89         container.setLayout(layout);
90
91         tablePart.createControl(container);
92
93         pluginListViewer = tablePart.getTableViewer();
94         pluginListViewer.setContentProvider(new BuildpathContentProvider());
95         pluginListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
96
97         GridData gd = (GridData)tablePart.getControl().getLayoutData();
98         gd.heightHint = 300;
99         gd.widthHint = 300;
100         
101         pluginListViewer.setInput(PDEPlugin.getDefault());
102         tablePart.setSelection(fSelected);
103
104         setControl(container);
105         Dialog.applyDialogFont(container);
106         PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.UPDATE_CLASSPATH);
107     }
108
109     public void storeSettings() {
110     }
111
112     public Object JavaDoc[] getSelected() {
113         return tablePart.getSelection();
114     }
115     
116     private void dialogChanged() {
117         setPageComplete(tablePart.getSelectionCount() > 0);
118     }
119     
120     /* (non-Javadoc)
121      * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
122      */

123     public boolean isPageComplete() {
124         return tablePart.getSelectionCount() > 0;
125     }
126 }
127
Popular Tags