KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > wizards > ConfigureProjectWizardMainPage


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  * Brock Janiczak (brockj@tpg.com.au) - Bug 144067 Repository types not sorted in the share project wizard
11  *******************************************************************************/

12 package org.eclipse.team.internal.ui.wizards;
13
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Arrays JavaDoc;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.viewers.*;
23 import org.eclipse.jface.wizard.IWizardPage;
24 import org.eclipse.jface.wizard.WizardPage;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.*;
31 import org.eclipse.team.internal.ui.*;
32 import org.eclipse.team.ui.IConfigurationWizard;
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.PlatformUI;
35 import org.eclipse.ui.activities.ITriggerPoint;
36 import org.eclipse.ui.activities.WorkbenchActivityHelper;
37 import org.eclipse.ui.model.*;
38
39 /**
40  * The main page of the configure project wizard. It contains a table
41  * which lists possible team providers with which to configure the project.
42  * The user may select one and press "Next", which will display a provider-
43  * specific wizard page.
44  */

45 public class ConfigureProjectWizardMainPage extends WizardPage {
46     private Table table;
47     private Button showAllToggle;
48     private TableViewer viewer;
49     private AdaptableList wizards;
50     private AdaptableList disabledWizards;
51     private IWorkbench workbench;
52     private IProject project;
53     private String JavaDoc description;
54     
55     private IConfigurationWizard selectedWizard;
56     
57     /**
58      * Create a new ConfigureProjectWizardMainPage
59      *
60      * @param pageName the name of the page
61      * @param title the title of the page
62      * @param titleImage the image for the page title
63      * @param wizards the wizards to populate the table with
64      * @param disabledWizards the list of wizards that are disabled via capabilities
65      */

66     public ConfigureProjectWizardMainPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage, AdaptableList wizards, AdaptableList disabledWizards) {
67         this(pageName,title,titleImage,wizards,disabledWizards, TeamUIMessages.ConfigureProjectWizardMainPage_selectRepository);
68     }
69     
70     /**
71      * Create a new ConfigureProjectWizardMainPage
72      *
73      * @param pageName the name of the page
74      * @param title the title of the page
75      * @param titleImage the image for the page title
76      * @param wizards the wizards to populate the table with
77      * @param disabledWizards the list of wizards that are disabled via capabilities
78      * @param description The string to use as a description label
79      */

80     public ConfigureProjectWizardMainPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage, AdaptableList wizards, AdaptableList disabledWizards, String JavaDoc description) {
81         super(pageName, title, titleImage);
82         this.wizards = wizards;
83         this.disabledWizards = disabledWizards;
84         this.description = description;
85     }
86     
87     public IConfigurationWizard getSelectedWizard() {
88         return selectedWizard;
89     }
90     /*
91      * @see WizardPage#canFlipToNextPage
92      */

93     public boolean canFlipToNextPage() {
94         return selectedWizard != null && selectedWizard.getPageCount() > 0;
95     }
96     /*
97      * @see WizardPage#createControl
98      */

99     public void createControl(Composite parent) {
100         Composite composite = new Composite(parent, SWT.NULL);
101         composite.setLayout(new GridLayout());
102         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
103         
104         setControl(composite);
105
106         // set F1 help
107
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARE_PROJECT_PAGE);
108                 
109         Label label = new Label(composite, SWT.LEFT);
110         label.setText(description);
111         GridData data = new GridData();
112         data.horizontalAlignment = GridData.FILL;
113         label.setLayoutData(data);
114     
115         table = new Table(composite, SWT.SINGLE | SWT.BORDER);
116         data = new GridData(GridData.FILL_BOTH);
117         data.heightHint = table.getItemHeight() * 7;
118         table.setLayoutData(data);
119         viewer = new TableViewer(table);
120         viewer.setContentProvider(new WorkbenchContentProvider());
121         viewer.setLabelProvider(new WorkbenchLabelProvider());
122         viewer.addSelectionChangedListener(new ISelectionChangedListener() {
123             public void selectionChanged(SelectionChangedEvent event) {
124                 // Initialize the wizard so we can tell whether to enable the Next button
125
ISelection selection = event.getSelection();
126                 if (selection == null || !(selection instanceof IStructuredSelection)) {
127                     selectedWizard = null;
128                     setPageComplete(false);
129                     return;
130                 }
131                 IStructuredSelection ss = (IStructuredSelection)selection;
132                 if (ss.size() != 1) {
133                     selectedWizard = null;
134                     setPageComplete(false);
135                     return;
136                 }
137                 ConfigurationWizardElement selectedElement = (ConfigurationWizardElement)ss.getFirstElement();
138                 try {
139                     selectedWizard = (IConfigurationWizard)selectedElement.createExecutableExtension();
140                     selectedWizard.init(workbench, project);
141                 } catch (CoreException e) {
142                     return;
143                 }
144                 selectedWizard.addPages();
145                 
146                 // Ask the container to update button enablement
147
setPageComplete(true);
148             }
149         });
150         viewer.addDoubleClickListener(new IDoubleClickListener() {
151             public void doubleClick(DoubleClickEvent event) {
152                 getWizard().getContainer().showPage(getNextPage());
153             }
154         });
155         viewer.setComparator(new ViewerComparator() {
156             public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
157                 if (e1 instanceof ConfigurationWizardElement && e2 instanceof ConfigurationWizardElement) {
158                     ConfigurationWizardElement wizard1 = (ConfigurationWizardElement) e1;
159                     ConfigurationWizardElement wizard2 = (ConfigurationWizardElement) e2;
160                     return wizard1.getLabel(wizard1).compareToIgnoreCase(wizard2.getLabel(wizard2));
161                 }
162                 return super.compare(viewer, e1, e2);
163             }
164         });
165         
166         if(disabledWizards.size() > 0) {
167             showAllToggle = new Button(composite, SWT.CHECK);
168             showAllToggle.setText(TeamUIMessages.ConfigureProjectWizard_showAll);
169             showAllToggle.addSelectionListener(new SelectionAdapter() {
170                 public void widgetSelected(SelectionEvent e) {
171                     ArrayList JavaDoc all = new ArrayList JavaDoc(Arrays.asList(wizards.getChildren()));
172                     if(showAllToggle.getSelection()) {
173                         all.addAll(Arrays.asList(disabledWizards.getChildren()));
174                     }
175                     viewer.setInput(new AdaptableList(all));
176                 }
177             });
178         }
179         
180         if(wizards.size() == 0 && showAllToggle != null) {
181             showAllToggle.setSelection(true);
182             ArrayList JavaDoc all = new ArrayList JavaDoc(Arrays.asList(wizards.getChildren()));
183             all.addAll(Arrays.asList(disabledWizards.getChildren()));
184             viewer.setInput(new AdaptableList(all));
185         } else {
186             viewer.setInput(wizards);
187         }
188         Dialog.applyDialogFont(parent);
189     }
190     /**
191      * The <code>WizardSelectionPage</code> implementation of
192      * this <code>IWizardPage</code> method returns the first page
193      * of the currently selected wizard if there is one.
194      *
195      * @see WizardPage#getNextPage
196      */

197     public IWizardPage getNextPage() {
198         if (selectedWizard == null) return null;
199         if(! WorkbenchActivityHelper.allowUseOf(getTriggerPoint(), ((IStructuredSelection)viewer.getSelection()).getFirstElement())) return null;
200         return selectedWizard.getStartingPage();
201     }
202     
203     private ITriggerPoint getTriggerPoint() {
204         return PlatformUI.getWorkbench()
205             .getActivitySupport().getTriggerPointManager()
206             .getTriggerPoint(TeamUIPlugin.TRIGGER_POINT_ID);
207     }
208
209     /**
210      * Set the workbench to the argument
211      *
212      * @param workbench the workbench to set
213      */

214     public void setWorkbench(IWorkbench workbench) {
215         this.workbench = workbench;
216     }
217     /**
218      * Set the project to the argument
219      *
220      * @param project the project to set
221      */

222     public void setProject(IProject project) {
223         this.project = project;
224     }
225     public void setVisible(boolean visible) {
226         super.setVisible(visible);
227         if (visible) {
228             table.setFocus();
229         }
230     }
231 }
232
Popular Tags