001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.samples;
011:
012: import org.eclipse.core.runtime.IConfigurationElement;
013: import org.eclipse.jface.viewers.IStructuredContentProvider;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.jface.viewers.LabelProvider;
016: import org.eclipse.jface.wizard.WizardPage;
017: import org.eclipse.pde.internal.ui.IHelpContextIds;
018: import org.eclipse.pde.internal.ui.PDEPlugin;
019: import org.eclipse.pde.internal.ui.PDEPluginImages;
020: import org.eclipse.pde.internal.ui.PDEUIMessages;
021: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
022: import org.eclipse.pde.internal.ui.parts.TablePart;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.graphics.Image;
025: import org.eclipse.swt.layout.GridData;
026: import org.eclipse.swt.layout.GridLayout;
027: import org.eclipse.swt.widgets.Button;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Text;
030: import org.eclipse.ui.PlatformUI;
031:
032: public class SelectionPage extends WizardPage {
033: private TablePart part;
034: private Text desc;
035: private SampleWizard wizard;
036:
037: class SelectionPart extends TablePart {
038: public SelectionPart() {
039: super (new String[] { "More Info" }); //$NON-NLS-1$
040: }
041:
042: protected void buttonSelected(Button button, int index) {
043: if (index == 0)
044: doMoreInfo();
045: }
046:
047: protected void selectionChanged(IStructuredSelection selection) {
048: updateSelection(selection);
049: }
050:
051: protected void handleDoubleClick(IStructuredSelection selection) {
052: }
053: }
054:
055: class SampleProvider extends DefaultContentProvider implements
056: IStructuredContentProvider {
057: public Object[] getElements(Object input) {
058: return wizard.getSamples();
059: }
060: }
061:
062: class SampleLabelProvider extends LabelProvider {
063: private Image image;
064:
065: public SampleLabelProvider() {
066: image = PDEPlugin.getDefault().getLabelProvider().get(
067: PDEPluginImages.DESC_NEWEXP_TOOL);
068: }
069:
070: public String getText(Object obj) {
071: IConfigurationElement sample = (IConfigurationElement) obj;
072: return sample.getAttribute("name"); //$NON-NLS-1$
073: }
074:
075: public Image getImage(Object obj) {
076: return image;
077: }
078: }
079:
080: /**
081: * @param pageName
082: */
083: public SelectionPage(SampleWizard wizard) {
084: super ("selection"); //$NON-NLS-1$
085: this .wizard = wizard;
086: setTitle(PDEUIMessages.SelectionPage_title);
087: setDescription(PDEUIMessages.SelectionPage_desc);
088: part = new SelectionPart();
089: }
090:
091: public void createControl(Composite parent) {
092: Composite container = new Composite(parent, SWT.NULL);
093: GridLayout layout = new GridLayout();
094: container.setLayout(layout);
095: layout.numColumns = 2;
096: part.setMinimumSize(300, 300);
097: part.createControl(container, SWT.H_SCROLL | SWT.V_SCROLL
098: | SWT.BORDER, 2, null);
099: part.getTableViewer().setContentProvider(new SampleProvider());
100: part.getTableViewer().setLabelProvider(
101: new SampleLabelProvider());
102: desc = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP
103: | SWT.V_SCROLL);
104: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
105: gd.heightHint = 64;
106: desc.setLayoutData(gd);
107: part.getTableViewer().setInput(this );
108: updateSelection(null);
109: setControl(container);
110:
111: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
112: IHelpContextIds.SELECTION);
113: }
114:
115: private void doMoreInfo() {
116: if (wizard.getSelection() != null) {
117: IConfigurationElement desc[] = wizard.getSelection()
118: .getChildren("description"); //$NON-NLS-1$
119: String helpHref = desc[0].getAttribute("helpHref"); //$NON-NLS-1$
120: PlatformUI.getWorkbench().getHelpSystem()
121: .displayHelpResource(helpHref);
122: }
123: }
124:
125: private void updateSelection(IStructuredSelection selection) {
126: if (selection == null) {
127: desc.setText(""); //$NON-NLS-1$
128: part.setButtonEnabled(0, false);
129: setPageComplete(false);
130: } else {
131: IConfigurationElement sample = (IConfigurationElement) selection
132: .getFirstElement();
133: String text = ""; //$NON-NLS-1$
134: String helpHref = null;
135: IConfigurationElement[] sampleDesc = sample
136: .getChildren("description"); //$NON-NLS-1$
137: if (sampleDesc.length == 1) {
138: text = sampleDesc[0].getValue();
139: helpHref = sampleDesc[0].getAttribute("helpHref"); //$NON-NLS-1$
140: }
141: desc.setText(text);
142: part.setButtonEnabled(0, helpHref != null);
143: wizard.setSelection(sample);
144: setPageComplete(true);
145: }
146: }
147: }
|