1 11 package org.eclipse.pde.internal.ui.wizards.exports; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.HashSet ; 16 import java.util.StringTokenizer ; 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 CROSS_PLATFORM = "cross-platform"; 39 class Configuration { 40 String os; 41 String ws; 42 String arch; 43 44 public String toString() { 45 return os + " (" + ws + "/" + arch + ")"; } 47 } 48 49 class ContentProvider extends DefaultContentProvider implements 50 IStructuredContentProvider { 51 public Object [] getElements(Object parent) { 52 return getListElements(); 53 } 54 } 55 56 class PlatformPart extends WizardCheckboxTablePart { 57 public PlatformPart(String label, String [] 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 pageName, IFeatureModel model) { 82 super(pageName); 83 fPlatformPart = 84 new PlatformPart( 85 PDEUIMessages.CrossPlatformExportPage_available, 86 new String [] { 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 value = getDialogSettings().get(CROSS_PLATFORM); 112 if (value != null) { 113 HashSet set = new HashSet (); 114 StringTokenizer tok = new StringTokenizer (value, ","); while (tok.hasMoreTokens()) { 116 set.add(tok.nextToken()); 117 } 118 ArrayList selected = new ArrayList (); 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 [] objects = fPlatformPart.getSelection(); 133 StringBuffer buffer = new StringBuffer (); 134 for (int i = 0; i < objects.length; i++) { 135 if (buffer.length() > 0) 136 buffer.append(","); buffer.append(objects[i].toString()); 138 } 139 settings.put(CROSS_PLATFORM, buffer.toString()); 140 } 141 142 private Configuration[] getListElements() { 143 ArrayList list = new ArrayList (); 144 if (fModel != null) { 145 File bin = new File (fModel.getInstallLocation(), "bin"); if (bin.exists() && bin.isDirectory()) { 147 File [] 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 list, File file) { 158 File [] 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 list, File file, String ws) { 166 File [] children = file.listFiles(); 167 for (int i = 0; i < children.length; i++) { 168 if (children[i].isDirectory() && !"CVS".equalsIgnoreCase(children[i].getName())) { 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 [][] getTargets() { 183 Object [] objects = fPlatformPart.getSelection(); 184 String [][] targets = new String [objects.length][4]; 185 for (int i = 0; i < objects.length; i++) { 186 Configuration config = (Configuration)objects[i]; 187 String [] combo = new String [4]; 188 combo[0] = config.os; 189 combo[1] = config.ws; 190 combo[2] = config.arch; 191 combo[3] = ""; targets[i] = combo; 193 } 194 return targets; 195 } 196 } 197 | Popular Tags |