001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.provisioner;
011:
012: import java.util.Iterator;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.jface.dialogs.Dialog;
016: import org.eclipse.jface.viewers.ArrayContentProvider;
017: import org.eclipse.jface.viewers.ISelectionChangedListener;
018: import org.eclipse.jface.viewers.IStructuredSelection;
019: import org.eclipse.jface.viewers.SelectionChangedEvent;
020: import org.eclipse.jface.viewers.TableViewer;
021: import org.eclipse.jface.wizard.IWizard;
022: import org.eclipse.jface.wizard.IWizardNode;
023: import org.eclipse.jface.wizard.WizardSelectionPage;
024: import org.eclipse.pde.internal.ui.IHelpContextIds;
025: import org.eclipse.pde.internal.ui.PDEUIMessages;
026: import org.eclipse.pde.internal.ui.elements.ElementList;
027: import org.eclipse.pde.internal.ui.wizards.ListUtil;
028: import org.eclipse.pde.internal.ui.wizards.WizardElement;
029: import org.eclipse.pde.internal.ui.wizards.WizardNode;
030: import org.eclipse.pde.ui.IBasePluginWizard;
031: import org.eclipse.swt.SWT;
032: import org.eclipse.swt.custom.SashForm;
033: import org.eclipse.swt.layout.GridData;
034: import org.eclipse.swt.layout.GridLayout;
035: import org.eclipse.swt.widgets.Composite;
036: import org.eclipse.swt.widgets.Label;
037: import org.eclipse.swt.widgets.Text;
038: import org.eclipse.ui.PlatformUI;
039:
040: public class ProvisionerListSelectionPage extends WizardSelectionPage {
041:
042: private TableViewer fTableViewer = null;
043: private Text fTextBox = null;
044: private ElementList fElements = null;
045:
046: protected ProvisionerListSelectionPage(ElementList elements) {
047: super (PDEUIMessages.ProvisionerListSelectionPage_pageName);
048: fElements = elements;
049: setTitle(PDEUIMessages.ProvisionerListSelectionPage_title);
050: setDescription(PDEUIMessages.ProvisionerListSelectionPage_description);
051: }
052:
053: public void createControl(Composite parent) {
054: Composite container = new Composite(parent, SWT.NONE);
055: GridLayout layout = new GridLayout();
056: layout.verticalSpacing = 10;
057: container.setLayout(layout);
058: container.setLayoutData(new GridData(GridData.FILL_BOTH));
059:
060: Label label = new Label(container, SWT.None);
061: label
062: .setText(PDEUIMessages.ProvisionerListSelectionPage_tableLabel);
063: label.setLayoutData(new GridData());
064:
065: SashForm sashForm = new SashForm(container, SWT.HORIZONTAL);
066: GridData gd = new GridData(GridData.FILL_BOTH);
067: gd.widthHint = 300;
068: sashForm.setLayoutData(gd);
069:
070: fTableViewer = new TableViewer(sashForm, SWT.BORDER);
071:
072: fTableViewer.setLabelProvider(ListUtil.TABLE_LABEL_PROVIDER);
073: fTableViewer.setContentProvider(new ArrayContentProvider());
074: fTableViewer.setInput(fElements.getChildren());
075: fTableViewer
076: .addSelectionChangedListener(new ISelectionChangedListener() {
077: public void selectionChanged(
078: SelectionChangedEvent event) {
079: handleSelection();
080: }
081: });
082:
083: fTextBox = new Text(sashForm, SWT.BORDER | SWT.WRAP
084: | SWT.READ_ONLY);
085: fTextBox.setText(new String());
086: fTextBox.setBackground(fTableViewer.getControl()
087: .getBackground());
088: setControl(container);
089: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
090: IHelpContextIds.TARGET_PROVISIONERS_PREFERENCE_PAGE);
091: Dialog.applyDialogFont(container);
092:
093: }
094:
095: protected IWizardNode createWizardNode(WizardElement element) {
096: return new WizardNode(this , element) {
097: public IBasePluginWizard createWizard()
098: throws CoreException {
099: return (IBasePluginWizard) wizardElement
100: .createExecutableExtension();
101: }
102: };
103: }
104:
105: protected void setDescriptionText(String text) {
106: fTextBox.setText(text);
107: }
108:
109: protected void handleSelection() {
110: setErrorMessage(null);
111: IStructuredSelection selection = (IStructuredSelection) fTableViewer
112: .getSelection();
113: WizardElement currentWizardSelection = null;
114: Iterator iter = selection.iterator();
115: if (iter.hasNext())
116: currentWizardSelection = (WizardElement) iter.next();
117: if (currentWizardSelection == null) {
118: setDescriptionText(""); //$NON-NLS-1$
119: setSelectedNode(null);
120: setPageComplete(false);
121: return;
122: }
123: final WizardElement finalSelection = currentWizardSelection;
124: setSelectedNode(createWizardNode(finalSelection));
125: setDescriptionText(finalSelection.getDescription());
126: setPageComplete(true);
127: getContainer().updateButtons();
128: }
129:
130: public IWizard getSelectedWizard() {
131: IWizardNode node = getSelectedNode();
132: if (node != null)
133: return node.getWizard();
134: return null;
135: }
136:
137: }
|