KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > internal > samples > SelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ui.internal.samples;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.jface.viewers.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.jface.viewers.LabelProvider;
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.pde.internal.ui.IHelpContextIds;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.PDEPluginImages;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
23 import org.eclipse.pde.internal.ui.parts.TablePart;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Text;
31 import org.eclipse.ui.PlatformUI;
32
33 public class SelectionPage extends WizardPage {
34     private TablePart part;
35     private Text desc;
36     private SampleWizard wizard;
37     
38     class SelectionPart extends TablePart {
39         public SelectionPart() {
40             super(new String JavaDoc [] { "More Info" }); //$NON-NLS-1$
41
}
42         protected void buttonSelected(Button button, int index) {
43             if (index == 0)
44                 doMoreInfo();
45         }
46         
47         protected void selectionChanged(IStructuredSelection selection) {
48             updateSelection(selection);
49         }
50         protected void handleDoubleClick(IStructuredSelection selection) {
51         }
52     }
53     
54     class SampleProvider extends DefaultContentProvider implements IStructuredContentProvider {
55         public Object JavaDoc [] getElements(Object JavaDoc input) {
56             return wizard.getSamples();
57         }
58     }
59     
60     class SampleLabelProvider extends LabelProvider {
61         private Image image;
62         public SampleLabelProvider() {
63             image = PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_NEWEXP_TOOL);
64         }
65         public String JavaDoc getText(Object JavaDoc obj) {
66             IConfigurationElement sample = (IConfigurationElement)obj;
67             return sample.getAttribute("name"); //$NON-NLS-1$
68
}
69         public Image getImage(Object JavaDoc obj) {
70             return image;
71         }
72     }
73     /**
74      * @param pageName
75      */

76     public SelectionPage(SampleWizard wizard) {
77         super("selection"); //$NON-NLS-1$
78
this.wizard = wizard;
79         setTitle(PDEUIMessages.SelectionPage_title); //$NON-NLS-1$
80
setDescription(PDEUIMessages.SelectionPage_desc); //$NON-NLS-1$
81
part = new SelectionPart();
82     }
83
84     public void createControl(Composite parent) {
85         Composite container = new Composite(parent, SWT.NULL);
86         GridLayout layout = new GridLayout();
87         container.setLayout(layout);
88         layout.numColumns = 2;
89         part.setMinimumSize(300, 300);
90         part.createControl(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, 2, null);
91         part.getTableViewer().setContentProvider(new SampleProvider());
92         part.getTableViewer().setLabelProvider(new SampleLabelProvider());
93         desc = new Text(container, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);
94         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
95         gd.heightHint = 64;
96         desc.setLayoutData(gd);
97         part.getTableViewer().setInput(this);
98         updateSelection(null);
99         setControl(container);
100         
101         PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.SELECTION);
102     }
103     private void doMoreInfo() {
104         if (wizard.getSelection()!=null) {
105             IConfigurationElement desc[] = wizard.getSelection().getChildren("description"); //$NON-NLS-1$
106
String JavaDoc helpHref = desc[0].getAttribute("helpHref"); //$NON-NLS-1$
107
PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpHref);
108         }
109     }
110     private void updateSelection(IStructuredSelection selection) {
111         if (selection==null) {
112             desc.setText(""); //$NON-NLS-1$
113
part.setButtonEnabled(0, false);
114             setPageComplete(false);
115         }
116         else {
117             IConfigurationElement sample = (IConfigurationElement)selection.getFirstElement();
118             String JavaDoc text = ""; //$NON-NLS-1$
119
String JavaDoc helpHref=null;
120             IConfigurationElement [] sampleDesc = sample.getChildren("description"); //$NON-NLS-1$
121
if (sampleDesc.length==1) {
122                 text = sampleDesc[0].getValue();
123                 helpHref = sampleDesc[0].getAttribute("helpHref"); //$NON-NLS-1$
124
}
125             desc.setText(text);
126             part.setButtonEnabled(0, helpHref!=null);
127             wizard.setSelection(sample);
128             setPageComplete(true);
129         }
130     }
131 }
132
Popular Tags