KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > macbundler > BundleWizardPage2


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.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); //$NON-NLS-1$
30
}
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); //$NON-NLS-1$
36
fWorkingDir= createText(c, WORKINGDIR, 1);
37
38         fClassPath= createTableGroup(parent, Util.getString("page2.addToClasspath.group.label"), true); //$NON-NLS-1$
39
fResources= createTableGroup(parent, Util.getString("page2.addToBundle.group.label"), false); //$NON-NLS-1$
40
}
41     
42     Table createTableGroup(Composite parent, String JavaDoc 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")); //$NON-NLS-1$
48
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")); //$NON-NLS-1$
52
String JavaDoc 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")); //$NON-NLS-1$
61
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")); //$NON-NLS-1$
65
String JavaDoc 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")); //$NON-NLS-1$
74
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, "")); //$NON-NLS-1$
111

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