KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > provisioner > ProvisionerListSelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.provisioner;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.viewers.ArrayContentProvider;
18 import org.eclipse.jface.viewers.ISelectionChangedListener;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.jface.viewers.SelectionChangedEvent;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.jface.wizard.IWizard;
23 import org.eclipse.jface.wizard.IWizardNode;
24 import org.eclipse.jface.wizard.WizardSelectionPage;
25 import org.eclipse.pde.internal.ui.IHelpContextIds;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27 import org.eclipse.pde.internal.ui.elements.ElementList;
28 import org.eclipse.pde.internal.ui.wizards.ListUtil;
29 import org.eclipse.pde.internal.ui.wizards.WizardElement;
30 import org.eclipse.pde.internal.ui.wizards.WizardNode;
31 import org.eclipse.pde.ui.IBasePluginWizard;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.custom.SashForm;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Text;
39 import org.eclipse.ui.PlatformUI;
40
41 public class ProvisionerListSelectionPage extends WizardSelectionPage {
42     
43     private TableViewer fTableViewer = null;
44     private Text fTextBox = null;
45     private ElementList fElements = null;
46     
47     protected ProvisionerListSelectionPage(ElementList elements) {
48         super(PDEUIMessages.ProvisionerListSelectionPage_pageName);
49         fElements = elements;
50         setTitle(PDEUIMessages.ProvisionerListSelectionPage_title);
51         setDescription(PDEUIMessages.ProvisionerListSelectionPage_description);
52     }
53
54     public void createControl(Composite parent) {
55         Composite container = new Composite(parent, SWT.NONE);
56         GridLayout layout = new GridLayout();
57         layout.verticalSpacing = 10;
58         container.setLayout(layout);
59         container.setLayoutData(new GridData(GridData.FILL_BOTH));
60         
61         Label label = new Label(container, SWT.None);
62         label.setText(PDEUIMessages.ProvisionerListSelectionPage_tableLabel);
63         label.setLayoutData(new GridData());
64         
65         SashForm sashForm = new SashForm(container, SWT.HORIZONTAL);
66         GridData gd = new GridData(GridData.FILL_BOTH);
67         gd.widthHint = 300;
68         sashForm.setLayoutData(gd);
69             
70         fTableViewer = new TableViewer(sashForm, SWT.BORDER);
71         
72         fTableViewer.setLabelProvider(ListUtil.TABLE_LABEL_PROVIDER);
73         fTableViewer.setContentProvider(new ArrayContentProvider());
74         fTableViewer.setInput(fElements.getChildren());
75         fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
76             public void selectionChanged(SelectionChangedEvent event) {
77                 handleSelection();
78             }
79         });
80         
81         fTextBox = new Text(sashForm, SWT.BORDER | SWT.WRAP | SWT.READ_ONLY);
82         fTextBox.setText(new String JavaDoc());
83         fTextBox.setBackground(fTableViewer.getControl().getBackground());
84         setControl(container);
85         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.TARGET_PROVISIONERS_PREFERENCE_PAGE);
86         Dialog.applyDialogFont(container);
87
88     }
89
90     protected IWizardNode createWizardNode(WizardElement element) {
91         return new WizardNode(this, element) {
92             public IBasePluginWizard createWizard() throws CoreException {
93                 return (IBasePluginWizard) wizardElement.createExecutableExtension();
94             }
95         };
96     }
97     
98     protected void setDescriptionText(String JavaDoc text) {
99         fTextBox.setText(text);
100     }
101     
102     protected void handleSelection() {
103         setErrorMessage(null);
104         IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
105         WizardElement currentWizardSelection = null;
106         Iterator JavaDoc iter = selection.iterator();
107         if (iter.hasNext())
108             currentWizardSelection = (WizardElement) iter.next();
109         if (currentWizardSelection == null) {
110             setDescriptionText(""); //$NON-NLS-1$
111
setSelectedNode(null);
112             setPageComplete(false);
113             return;
114         }
115         final WizardElement finalSelection = currentWizardSelection;
116         setSelectedNode(createWizardNode(finalSelection));
117         setDescriptionText(finalSelection.getDescription());
118         setPageComplete(true);
119         getContainer().updateButtons();
120     }
121     
122     public IWizard getSelectedWizard() {
123         IWizardNode node = getSelectedNode();
124         if (node != null)
125             return node.getWizard();
126         return null;
127     }
128
129 }
130
Popular Tags