KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > EngineTypeWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2004, 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  *******************************************************************************/

11 package org.eclipse.help.ui.internal.views;
12
13 import org.eclipse.help.ui.internal.Messages;
14 import org.eclipse.jface.viewers.*;
15 import org.eclipse.jface.wizard.WizardPage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.graphics.Font;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.layout.*;
20 import org.eclipse.swt.widgets.*;
21
22 public class EngineTypeWizardPage extends WizardPage {
23     private TableViewer tableViewer;
24     private EngineTypeDescriptor [] engineTypes;
25     private EngineTypeDescriptor selection;
26     
27     class EngineContentProvider implements IStructuredContentProvider {
28
29         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
30             return engineTypes;
31         }
32
33         public void dispose() {
34         }
35
36         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
37         }
38     }
39     
40     class EngineLabelProvider extends LabelProvider implements ITableLabelProvider {
41         public String JavaDoc getText(Object JavaDoc obj) {
42             EngineTypeDescriptor desc = (EngineTypeDescriptor)obj;
43             return desc.getLabel();
44         }
45         public Image getImage(Object JavaDoc obj) {
46             EngineTypeDescriptor desc = (EngineTypeDescriptor)obj;
47             return desc.getIconImage();
48         }
49         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
50             return getImage(element);
51         }
52         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
53             return getText(element);
54         }
55     }
56
57     public EngineTypeWizardPage(EngineTypeDescriptor[] engineTypes) {
58         super("engineType"); //$NON-NLS-1$
59
setTitle(Messages.EngineTypeWizardPage_title);
60         setDescription(Messages.EngineTypeWizardPage_desc);
61         this.engineTypes = engineTypes;
62     }
63
64     public void createControl(Composite parent) {
65         Font font = parent.getFont();
66         Composite container = new Composite(parent, SWT.NULL);
67         GridLayout layout = new GridLayout();
68         container.setLayout(layout);
69         Label label = new Label(container, SWT.NULL);
70         label.setText(Messages.EngineTypeWizardPage_label);
71         label.setFont(font);
72         tableViewer = new TableViewer(container);
73         tableViewer.setContentProvider(new EngineContentProvider());
74         tableViewer.setLabelProvider(new EngineLabelProvider());
75         tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
76             public void selectionChanged(SelectionChangedEvent event) {
77                 setPageComplete(!event.getSelection().isEmpty());
78                 selection = (EngineTypeDescriptor)((IStructuredSelection)event.getSelection()).getFirstElement();
79             }
80         });
81         tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
82         tableViewer.setInput(engineTypes);
83         tableViewer.getTable().setFont(font);
84         setControl(container);
85         setPageComplete(false);
86     }
87     public EngineTypeDescriptor getSelectedEngineType() {
88         return selection;
89     }
90 }
91
Popular Tags