1 11 package org.eclipse.jdt.internal.ui.macbundler; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.events.*; 15 import org.eclipse.swt.layout.*; 16 import org.eclipse.swt.widgets.*; 17 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 20 21 public class BundleWizardPage2 extends BundleWizardBasePage { 22 23 Text fWorkingDir; 24 Table fClassPath; 25 Table fResources; 26 27 28 protected BundleWizardPage2(BundleDescription bd) { 29 super("page2", bd); } 31 32 public void createContents(Composite parent) { 33 34 Composite c= createComposite(parent, 2); 35 createLabel(c, Util.getString("page2.workingDirectory.label"), GridData.VERTICAL_ALIGN_CENTER); fWorkingDir= createText(c, WORKINGDIR, 1); 37 38 fClassPath= createTableGroup(parent, Util.getString("page2.addToClasspath.group.label"), true); fResources= createTableGroup(parent, Util.getString("page2.addToBundle.group.label"), false); } 41 42 Table createTableGroup(Composite parent, String groupName, final boolean onClasspath) { 43 Group g1= createGroup(parent, groupName, 1); 44 final Table table= new Table(g1, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); 45 setHeightHint(table, 80); 46 Composite c1= createComposite(g1, 3); 47 final Button addButton1= createButton(c1, SWT.NONE, Util.getString("page2.addFile.button.label")); addButton1.addSelectionListener(new SelectionAdapter() { 49 public void widgetSelected(SelectionEvent e) { 50 FileDialog fd= new FileDialog(addButton1.getShell(), SWT.OPEN); 51 fd.setText(Util.getString("page2.chooseFileDialog.title")); String path= fd.open(); 53 if (path != null) { 54 ResourceInfo ri= new ResourceInfo(path); 55 fBundleDescription.addResource(ri, onClasspath); 56 add(table, ri); 57 } 58 } 59 }); 60 final Button addButton2= createButton(c1, SWT.NONE, Util.getString("page2.addFolder.button.label")); addButton2.addSelectionListener(new SelectionAdapter() { 62 public void widgetSelected(SelectionEvent e) { 63 DirectoryDialog fd= new DirectoryDialog(addButton2.getShell(), SWT.OPEN); 64 fd.setText(Util.getString("page2.chooseFolder.dialog.title")); String path= fd.open(); 66 if (path != null) { 67 ResourceInfo ri= new ResourceInfo(path); 68 fBundleDescription.addResource(ri, onClasspath); 69 add(table, ri); 70 } 71 } 72 }); 73 final Button removeButton= createButton(c1, SWT.NONE, Util.getString("page2.remove.button.label")); removeButton.setEnabled(false); 75 removeButton.addSelectionListener(new SelectionAdapter() { 76 public void widgetSelected(SelectionEvent e) { 77 remove(table, onClasspath, removeButton); 78 } 79 }); 80 table.addSelectionListener(new SelectionAdapter() { 81 public void widgetSelected(SelectionEvent e) { 82 removeButton.setEnabled(table.getSelectionCount() > 0); 83 } 84 }); 85 return table; 86 } 87 88 private void add(Table t, ResourceInfo ri) { 89 TableItem ti= new TableItem(t, SWT.NONE); 90 ti.setData(ri); 91 ti.setText(ri.fPath); 92 } 93 94 private void remove(Table table, boolean b, Button removeButton) { 95 TableItem[] selection= table.getSelection(); 96 for (int i= 0; i < selection.length; i++) { 97 TableItem ti= selection[i]; 98 ResourceInfo ri= (ResourceInfo) ti.getData(); 99 if (fBundleDescription.removeResource(ri, b)) { 100 int ix= table.indexOf(ti); 101 if (ix >= 0) 102 table.remove(ix); 103 } 104 } 105 removeButton.setEnabled(table.getSelectionCount() > 0); 106 } 107 108 public void propertyChange(PropertyChangeEvent event) { 109 if (fWorkingDir != null) 110 fWorkingDir.setText(fBundleDescription.get(WORKINGDIR, "")); 112 if (fClassPath != null) { 113 fClassPath.removeAll(); 114 ResourceInfo[] ris= fBundleDescription.getResources(true); 115 for (int i= 0; i < ris.length; i++) 116 add(fClassPath, ris[i]); 117 } 118 119 if (fResources != null) { 120 fResources.removeAll(); 121 ResourceInfo[] ris= fBundleDescription.getResources(false); 122 for (int i= 0; i < ris.length; i++) 123 add(fResources, ris[i]); 124 } 125 } 126 127 public boolean isPageComplete() { 128 return true; 129 } 130 } 131 | Popular Tags |