KickJava   Java API By Example, From Geeks To Geeks.

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


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.dialogs.IDialogSettings;
15 import org.eclipse.jface.viewers.CheckboxTableViewer;
16 import org.eclipse.jface.viewers.IStructuredContentProvider;
17 import org.eclipse.jface.viewers.StructuredViewer;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20 import org.eclipse.pde.internal.ui.IHelpContextIds;
21 import org.eclipse.pde.internal.ui.PDEPlugin;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
24 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
25 import org.eclipse.pde.internal.ui.wizards.ListUtil;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.forms.widgets.FormToolkit;
33
34 public class MigratePluginWizardPage extends WizardPage {
35     private IPluginModelBase[] fSelected;
36     private IPluginModelBase[] fUnmigrated;
37     private CheckboxTableViewer fPluginListViewer;
38     private TablePart fTablePart;
39     private Button fUpdateClasspathButton;
40     private String JavaDoc S_UPDATE_CLASSATH = "updateClasspath"; //$NON-NLS-1$
41
private String JavaDoc S_CLEAN_PROJECTS = "cleanProjects"; //$NON-NLS-1$
42
private Button fCleanProjectsButton;
43
44     public class ContentProvider
45         extends DefaultContentProvider
46         implements IStructuredContentProvider {
47         public Object JavaDoc[] getElements(Object JavaDoc parent) {
48             if (fUnmigrated != null)
49                 return fUnmigrated;
50             return new Object JavaDoc[0];
51         }
52     }
53
54     class TablePart extends WizardCheckboxTablePart {
55         public TablePart(String JavaDoc mainLabel) {
56             super(mainLabel);
57         }
58
59         public void updateCounter(int count) {
60             super.updateCounter(count);
61             dialogChanged();
62         }
63         protected StructuredViewer createStructuredViewer(
64             Composite parent,
65             int style,
66             FormToolkit toolkit) {
67             StructuredViewer viewer =
68                 super.createStructuredViewer(parent, style, toolkit);
69             viewer.setSorter(ListUtil.PLUGIN_SORTER);
70             return viewer;
71         }
72     }
73
74     public MigratePluginWizardPage(IPluginModelBase[] models, IPluginModelBase[] selected) {
75         super("MigrateWizardPage"); //$NON-NLS-1$
76
setTitle(PDEUIMessages.MigrationWizard_title);
77         setDescription(PDEUIMessages.MigrationWizardPage_desc);
78         this.fUnmigrated = models;
79         this.fSelected = selected;
80         fTablePart = new TablePart(PDEUIMessages.MigrationWizardPage_label);
81         PDEPlugin.getDefault().getLabelProvider().connect(this);
82     }
83     
84     public void dispose() {
85         super.dispose();
86         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
87     }
88
89     public void createControl(Composite parent) {
90         Composite container = new Composite(parent, SWT.NONE);
91         GridLayout layout = new GridLayout();
92         layout.numColumns = 2;
93         layout.marginHeight = 0;
94         layout.marginWidth = 5;
95         layout.verticalSpacing = 10;
96         container.setLayout(layout);
97
98         fTablePart.createControl(container);
99
100         fPluginListViewer = fTablePart.getTableViewer();
101         fPluginListViewer.setContentProvider(new ContentProvider());
102         fPluginListViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
103
104         GridData gd = (GridData)fTablePart.getControl().getLayoutData();
105         gd.heightHint = 300;
106         gd.widthHint = 300;
107         
108         fPluginListViewer.setInput(PDEPlugin.getDefault());
109         fTablePart.setSelection(fSelected);
110         
111         fUpdateClasspathButton = new Button(container, SWT.CHECK);
112         fUpdateClasspathButton.setText(PDEUIMessages.MigrationWizard_update);
113         gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
114         gd.horizontalSpan = 2;
115         fUpdateClasspathButton.setLayoutData(gd);
116         String JavaDoc update = getDialogSettings().get(S_UPDATE_CLASSATH);
117         boolean doUpdate = update == null ? true : getDialogSettings().getBoolean(S_UPDATE_CLASSATH);
118         fUpdateClasspathButton.setSelection(doUpdate);
119         
120         fCleanProjectsButton = new Button(container, SWT.CHECK);
121         fCleanProjectsButton.setText(PDEUIMessages.MigratePluginWizard_cleanProjects);
122         gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
123         gd.horizontalSpan = 2;
124         fCleanProjectsButton.setLayoutData(gd);
125         String JavaDoc clean = getDialogSettings().get(S_CLEAN_PROJECTS);
126         boolean doClean = clean == null ? true : getDialogSettings().getBoolean(S_CLEAN_PROJECTS);
127         fCleanProjectsButton.setSelection(doClean);
128
129         setControl(container);
130         Dialog.applyDialogFont(container);
131         PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.MIGRATE_3_0);
132     }
133
134     public IPluginModelBase[] getSelected() {
135         Object JavaDoc[] objects = fTablePart.getSelection();
136         IPluginModelBase [] models = new IPluginModelBase[objects.length];
137         System.arraycopy(objects, 0, models, 0, objects.length);
138         return models;
139     }
140
141     private void dialogChanged() {
142         setPageComplete(fTablePart.getSelectionCount() > 0);
143     }
144     
145     /* (non-Javadoc)
146      * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
147      */

148     public boolean isPageComplete() {
149         return fTablePart.getSelectionCount() > 0;
150     }
151
152     public void storeSettings() {
153         IDialogSettings settings = getDialogSettings();
154         settings.put(S_UPDATE_CLASSATH, fUpdateClasspathButton.getSelection());
155         settings.put(S_CLEAN_PROJECTS, fCleanProjectsButton.getSelection());
156     }
157     
158     public boolean isUpdateClasspathRequested() {
159         return fUpdateClasspathButton.getSelection();
160     }
161     
162     public boolean isCleanProjectsRequested() {
163         return fCleanProjectsButton.getSelection();
164     }
165
166 }
167
Popular Tags