001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 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.wizards.exports;
011:
012: import java.io.File;
013: import java.util.ArrayList;
014: import java.util.HashSet;
015: import java.util.StringTokenizer;
016:
017: import org.eclipse.jface.dialogs.IDialogSettings;
018: import org.eclipse.jface.viewers.IStructuredContentProvider;
019: import org.eclipse.jface.viewers.LabelProvider;
020: import org.eclipse.jface.viewers.TableViewer;
021: import org.eclipse.pde.internal.core.PDECore;
022: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
023: import org.eclipse.pde.internal.ui.IHelpContextIds;
024: import org.eclipse.pde.internal.ui.PDEUIMessages;
025: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
026: import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart;
027: import org.eclipse.swt.SWT;
028: import org.eclipse.swt.layout.GridLayout;
029: import org.eclipse.swt.widgets.Button;
030: import org.eclipse.swt.widgets.Composite;
031: import org.eclipse.swt.widgets.TableItem;
032: import org.eclipse.ui.PlatformUI;
033:
034: public class CrossPlatformExportPage extends AbstractExportWizardPage {
035:
036: private static String CROSS_PLATFORM = "cross-platform"; //$NON-NLS-1$
037:
038: class Configuration {
039: String os;
040: String ws;
041: String arch;
042:
043: public String toString() {
044: return os + " (" + ws + "/" + arch + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
045: }
046: }
047:
048: class ContentProvider extends DefaultContentProvider implements
049: IStructuredContentProvider {
050: public Object[] getElements(Object parent) {
051: return getListElements();
052: }
053: }
054:
055: class PlatformPart extends WizardCheckboxTablePart {
056: public PlatformPart(String label, String[] buttonLabels) {
057: super (label, buttonLabels);
058: }
059:
060: public void updateCounter(int count) {
061: super .updateCounter(count);
062: pageChanged();
063: }
064:
065: protected void buttonSelected(Button button, int index) {
066: switch (index) {
067: case 0:
068: handleSelectAll(true);
069: break;
070: case 1:
071: handleSelectAll(false);
072: break;
073: }
074: }
075: }
076:
077: private PlatformPart fPlatformPart;
078: private IFeatureModel fModel;
079:
080: public CrossPlatformExportPage(String pageName, IFeatureModel model) {
081: super (pageName);
082: fPlatformPart = new PlatformPart(
083: PDEUIMessages.CrossPlatformExportPage_available,
084: new String[] {
085: PDEUIMessages.WizardCheckboxTablePart_selectAll,
086: PDEUIMessages.WizardCheckboxTablePart_deselectAll });
087: setTitle(PDEUIMessages.CrossPlatformExportPage_title);
088: setDescription(PDEUIMessages.CrossPlatformExportPage_desc);
089: fModel = model;
090: }
091:
092: public void createControl(Composite parent) {
093: Composite container = new Composite(parent, SWT.NULL);
094: container.setLayout(new GridLayout(2, false));
095:
096: fPlatformPart.createControl(container);
097: TableViewer viewer = fPlatformPart.getTableViewer();
098: viewer.setContentProvider(new ContentProvider());
099: viewer.setLabelProvider(new LabelProvider());
100: fPlatformPart.getTableViewer().setInput(
101: PDECore.getDefault().getFeatureModelManager());
102:
103: initialize();
104: setControl(container);
105:
106: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
107: IHelpContextIds.CROSS_PLATFORM_EXPORT);
108: }
109:
110: private void initialize() {
111: String value = getDialogSettings().get(CROSS_PLATFORM);
112: if (value != null) {
113: HashSet set = new HashSet();
114: StringTokenizer tok = new StringTokenizer(value, ","); //$NON-NLS-1$
115: while (tok.hasMoreTokens()) {
116: set.add(tok.nextToken());
117: }
118: ArrayList selected = new ArrayList();
119: TableItem[] items = fPlatformPart.getTableViewer()
120: .getTable().getItems();
121: for (int i = 0; i < items.length; i++) {
122: Configuration config = (Configuration) items[i]
123: .getData();
124: if (set.contains(config.toString())) {
125: selected.add(config);
126: }
127: }
128: fPlatformPart.setSelection(selected.toArray());
129: }
130: pageChanged();
131: }
132:
133: public void saveSettings(IDialogSettings settings) {
134: Object[] objects = fPlatformPart.getSelection();
135: StringBuffer buffer = new StringBuffer();
136: for (int i = 0; i < objects.length; i++) {
137: if (buffer.length() > 0)
138: buffer.append(","); //$NON-NLS-1$
139: buffer.append(objects[i].toString());
140: }
141: settings.put(CROSS_PLATFORM, buffer.toString());
142: }
143:
144: private Configuration[] getListElements() {
145: ArrayList list = new ArrayList();
146: if (fModel != null) {
147: File bin = new File(fModel.getInstallLocation(), "bin"); //$NON-NLS-1$
148: if (bin.exists() && bin.isDirectory()) {
149: File[] children = bin.listFiles();
150: for (int i = 0; i < children.length; i++) {
151: if (children[i].isDirectory())
152: getWS(list, children[i]);
153: }
154: }
155: }
156: return (Configuration[]) list.toArray(new Configuration[list
157: .size()]);
158: }
159:
160: private void getWS(ArrayList list, File file) {
161: File[] children = file.listFiles();
162: for (int i = 0; i < children.length; i++) {
163: if (children[i].isDirectory())
164: getOS(list, children[i], file.getName());
165: }
166: }
167:
168: private void getOS(ArrayList list, File file, String ws) {
169: File[] children = file.listFiles();
170: for (int i = 0; i < children.length; i++) {
171: if (children[i].isDirectory()
172: && !"CVS".equalsIgnoreCase(children[i].getName())) { //$NON-NLS-1$
173: Configuration config = new Configuration();
174: config.ws = ws;
175: config.os = file.getName();
176: config.arch = children[i].getName();
177: list.add(config);
178: }
179: }
180: }
181:
182: protected void pageChanged() {
183: setPageComplete(fPlatformPart.getSelectionCount() > 0);
184: }
185:
186: public String[][] getTargets() {
187: Object[] objects = fPlatformPart.getSelection();
188: String[][] targets = new String[objects.length][4];
189: for (int i = 0; i < objects.length; i++) {
190: Configuration config = (Configuration) objects[i];
191: String[] combo = new String[4];
192: combo[0] = config.os;
193: combo[1] = config.ws;
194: combo[2] = config.arch;
195: combo[3] = ""; //$NON-NLS-1$
196: targets[i] = combo;
197: }
198: return targets;
199: }
200: }
|