KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > xhtml > XHTMLConversionWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.wizards.xhtml;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.viewers.CheckStateChangedEvent;
18 import org.eclipse.jface.viewers.ICheckStateListener;
19 import org.eclipse.jface.viewers.ITreeContentProvider;
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.jface.wizard.WizardPage;
22 import org.eclipse.pde.internal.ui.IHelpContextIds;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.pde.internal.ui.wizards.xhtml.TocReplaceTable.TocReplaceEntry;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.ui.PlatformUI;
34 import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
35 import org.eclipse.ui.model.WorkbenchLabelProvider;
36
37
38 public class XHTMLConversionWizardPage extends WizardPage {
39
40     private TocReplaceTable fTable;
41     private ContainerCheckedTreeViewer fInputViewer;
42     
43     private class CP implements ITreeContentProvider {
44
45         public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
46             if (parentElement instanceof IResource)
47                 return fTable.getToBeConverted((IResource)parentElement);
48             return null;
49         }
50         public Object JavaDoc getParent(Object JavaDoc element) {
51             if (element instanceof TocReplaceEntry)
52                 return ((TocReplaceEntry)element).getTocFile();
53             return null;
54         }
55         public boolean hasChildren(Object JavaDoc element) {
56             return element instanceof IResource;
57         }
58         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
59             return fTable.getTocs();
60         }
61         public void dispose() {
62         }
63         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
64         }
65     }
66     
67     private class LP extends WorkbenchLabelProvider {
68         protected String JavaDoc decorateText(String JavaDoc input, Object JavaDoc element) {
69             if (element instanceof IResource)
70                 return ((IResource)element).getProjectRelativePath().toString();
71             return super.decorateText(input, element);
72         }
73     }
74     
75     protected XHTMLConversionWizardPage(TocReplaceTable table) {
76         super("convert"); //$NON-NLS-1$
77
setTitle(PDEUIMessages.XHTMLConversionWizardPage_title);
78         setDescription(PDEUIMessages.XHTMLConversionWizardPage_desc);
79         fTable = table;
80     }
81
82     public void createControl(Composite parent) {
83         Composite columns = createComposite(parent, false, 2, false);
84         columns.setLayoutData(new GridData(GridData.FILL_BOTH));
85         
86         Composite valid = createComposite(columns, true, 1, false);
87         Label label = new Label(valid, SWT.NONE);
88         label.setText(PDEUIMessages.XHTMLConversionWizardPage_viewerLabel);
89         fInputViewer = new ContainerCheckedTreeViewer(valid, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.BORDER);
90         fInputViewer.setContentProvider(new CP());
91         fInputViewer.setLabelProvider(new LP());
92         GridData gd = new GridData(GridData.FILL_BOTH);
93         gd.widthHint = 400;
94         gd.heightHint = 170;
95         fInputViewer.getTree().setLayoutData(gd);
96         fInputViewer.addCheckStateListener(new ICheckStateListener() {
97             public void checkStateChanged(CheckStateChangedEvent event) {
98                 setPageComplete(fInputViewer.getCheckedElements().length > 0);
99             }
100         });
101         fInputViewer.setInput(new Object JavaDoc());
102         fInputViewer.setAllChecked(true);
103         
104         Composite buttonComp = createComposite(columns, true, 1, true);
105         Label blankLabel = new Label(buttonComp, SWT.NONE);
106         blankLabel.setText(""); //$NON-NLS-1$
107
Button selectAll = new Button(buttonComp, SWT.PUSH);
108         selectAll.setText(PDEUIMessages.XHTMLConversionWizardPage_selectAll);
109         selectAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
110         selectAll.addSelectionListener(new SelectionAdapter() {
111             public void widgetSelected(SelectionEvent e) {
112                 fInputViewer.setAllChecked(true);
113                 setPageComplete(true);
114             }
115         });
116         Button deselectAll = new Button(buttonComp, SWT.PUSH);
117         deselectAll.setText(PDEUIMessages.XHTMLConversionWizardPage_deselectAll);
118         deselectAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119         deselectAll.addSelectionListener(new SelectionAdapter() {
120             public void widgetSelected(SelectionEvent e) {
121                 fInputViewer.setAllChecked(false);
122                 setPageComplete(false);
123             }
124         });
125         
126         setControl(columns);
127         Dialog.applyDialogFont(columns);
128         
129         PlatformUI.getWorkbench().getHelpSystem().setHelp(columns, IHelpContextIds.XHTML_CONVERSION_PAGE );
130     }
131     
132     protected Composite createComposite(Composite parent, boolean noMargin, int cols, boolean valignTop) {
133         Composite comp = new Composite(parent, SWT.NONE);
134         GridLayout layout = new GridLayout(cols, false);
135         if (noMargin)
136             layout.marginHeight = layout.marginWidth = 0;
137         comp.setLayout(layout);
138         if (valignTop)
139             comp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
140         else
141             comp.setLayoutData(new GridData(GridData.FILL_BOTH));
142         return comp;
143     }
144
145     protected TocReplaceEntry[] getCheckedEntries() {
146         ArrayList JavaDoc list = new ArrayList JavaDoc();
147         Object JavaDoc[] entries = fInputViewer.getCheckedElements();
148         for (int i = 0; i < entries.length; i++) {
149             if (entries[i] instanceof TocReplaceEntry)
150                 list.add(entries[i]);
151         }
152         return (TocReplaceEntry[]) list.toArray(new TocReplaceEntry[list.size()]);
153     }
154 }
155
Popular Tags