KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > CrossPlatformExportPage


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.exports;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17
18 import org.eclipse.jface.dialogs.IDialogSettings;
19 import org.eclipse.jface.viewers.IStructuredContentProvider;
20 import org.eclipse.jface.viewers.LabelProvider;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.pde.internal.core.PDECore;
23 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
24 import org.eclipse.pde.internal.ui.IHelpContextIds;
25 import org.eclipse.pde.internal.ui.PDEUIMessages;
26 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
27 import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
28 import org.eclipse.swt.SWT;
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.TableItem;
33 import org.eclipse.ui.PlatformUI;
34
35 public class CrossPlatformExportPage extends AbstractExportWizardPage {
36     
37     private static String JavaDoc CROSS_PLATFORM = "cross-platform"; //$NON-NLS-1$
38

39     class Configuration {
40         String JavaDoc os;
41         String JavaDoc ws;
42         String JavaDoc arch;
43         
44         public String JavaDoc toString() {
45             return os + " (" + ws + "/" + arch + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
46
}
47     }
48     
49     class ContentProvider extends DefaultContentProvider implements
50             IStructuredContentProvider {
51         public Object JavaDoc[] getElements(Object JavaDoc parent) {
52             return getListElements();
53         }
54     }
55     
56     class PlatformPart extends WizardCheckboxTablePart {
57         public PlatformPart(String JavaDoc label, String JavaDoc[] buttonLabels) {
58             super(label, buttonLabels);
59         }
60
61         public void updateCounter(int count) {
62             super.updateCounter(count);
63             pageChanged();
64         }
65
66         protected void buttonSelected(Button button, int index) {
67             switch (index) {
68             case 0:
69                 handleSelectAll(true);
70                 break;
71             case 1:
72                 handleSelectAll(false);
73                 break;
74             }
75         }
76     }
77         
78     private PlatformPart fPlatformPart;
79     private IFeatureModel fModel;
80     
81     public CrossPlatformExportPage(String JavaDoc pageName, IFeatureModel model) {
82         super(pageName);
83         fPlatformPart =
84             new PlatformPart(
85                 PDEUIMessages.CrossPlatformExportPage_available,
86                 new String JavaDoc[] {
87                     PDEUIMessages.WizardCheckboxTablePart_selectAll,
88                     PDEUIMessages.WizardCheckboxTablePart_deselectAll});
89         setTitle(PDEUIMessages.CrossPlatformExportPage_title);
90         setDescription(PDEUIMessages.CrossPlatformExportPage_desc);
91         fModel = model;
92     }
93
94     public void createControl(Composite parent) {
95         Composite container = new Composite(parent, SWT.NULL);
96         container.setLayout(new GridLayout(2, false));
97         
98         fPlatformPart.createControl(container);
99         TableViewer viewer = fPlatformPart.getTableViewer();
100         viewer.setContentProvider(new ContentProvider());
101         viewer.setLabelProvider(new LabelProvider());
102         fPlatformPart.getTableViewer().setInput(PDECore.getDefault().getFeatureModelManager());
103         
104         initialize();
105         setControl(container);
106         
107         PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.CROSS_PLATFORM_EXPORT);
108     }
109     
110     private void initialize() {
111         String JavaDoc value = getDialogSettings().get(CROSS_PLATFORM);
112         if (value != null) {
113             HashSet JavaDoc set = new HashSet JavaDoc();
114             StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(value, ","); //$NON-NLS-1$
115
while (tok.hasMoreTokens()) {
116                 set.add(tok.nextToken());
117             }
118             ArrayList JavaDoc selected = new ArrayList JavaDoc();
119             TableItem[] items = fPlatformPart.getTableViewer().getTable().getItems();
120             for (int i = 0; i < items.length; i++) {
121                 Configuration config = (Configuration)items[i].getData();
122                 if (set.contains(config.toString())) {
123                     selected.add(config);
124                 }
125             }
126             fPlatformPart.setSelection(selected.toArray());
127         }
128         pageChanged();
129     }
130     
131     public void saveSettings(IDialogSettings settings) {
132         Object JavaDoc[] objects = fPlatformPart.getSelection();
133         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
134         for (int i = 0; i < objects.length; i++) {
135             if (buffer.length() > 0)
136                 buffer.append(","); //$NON-NLS-1$
137
buffer.append(objects[i].toString());
138         }
139         settings.put(CROSS_PLATFORM, buffer.toString());
140     }
141     
142     private Configuration[] getListElements() {
143         ArrayList JavaDoc list = new ArrayList JavaDoc();
144         if (fModel != null) {
145             File JavaDoc bin = new File JavaDoc(fModel.getInstallLocation(), "bin"); //$NON-NLS-1$
146
if (bin.exists() && bin.isDirectory()) {
147                 File JavaDoc[] children = bin.listFiles();
148                 for (int i = 0; i < children.length; i++) {
149                     if (children[i].isDirectory())
150                         getWS(list, children[i]);
151                 }
152             }
153         }
154         return (Configuration[])list.toArray(new Configuration[list.size()]);
155     }
156     
157     private void getWS(ArrayList JavaDoc list, File JavaDoc file) {
158         File JavaDoc[] children = file.listFiles();
159         for (int i = 0; i < children.length; i++) {
160             if (children[i].isDirectory())
161                 getOS(list, children[i], file.getName());
162         }
163     }
164     
165     private void getOS(ArrayList JavaDoc list, File JavaDoc file, String JavaDoc ws) {
166         File JavaDoc[] children = file.listFiles();
167         for (int i = 0; i < children.length; i++) {
168             if (children[i].isDirectory() && !"CVS".equalsIgnoreCase(children[i].getName())) { //$NON-NLS-1$
169
Configuration config = new Configuration();
170                 config.ws = ws;
171                 config.os = file.getName();
172                 config.arch = children[i].getName();
173                 list.add(config);
174             }
175         }
176     }
177     
178     protected void pageChanged() {
179         setPageComplete(fPlatformPart.getSelectionCount() > 0);
180     }
181     
182     public String JavaDoc[][] getTargets() {
183         Object JavaDoc[] objects = fPlatformPart.getSelection();
184         String JavaDoc[][] targets = new String JavaDoc[objects.length][4];
185         for (int i = 0; i < objects.length; i++) {
186             Configuration config = (Configuration)objects[i];
187             String JavaDoc[] combo = new String JavaDoc[4];
188             combo[0] = config.os;
189             combo[1] = config.ws;
190             combo[2] = config.arch;
191             combo[3] = ""; //$NON-NLS-1$
192
targets[i] = combo;
193         }
194         return targets;
195     }
196 }
197
Popular Tags