001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.jdt.internal.ui.macbundler;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.*;
014: import org.eclipse.swt.layout.*;
015: import org.eclipse.swt.widgets.*;
016:
017: import org.eclipse.jface.util.PropertyChangeEvent;
018:
019: public class BundleWizardPage2 extends BundleWizardBasePage {
020:
021: Text fWorkingDir;
022: Table fClassPath;
023: Table fResources;
024:
025: protected BundleWizardPage2(BundleDescription bd) {
026: super ("page2", bd); //$NON-NLS-1$
027: }
028:
029: public void createContents(Composite parent) {
030:
031: Composite c = createComposite(parent, 2);
032: createLabel(
033: c,
034: Util.getString("page2.workingDirectory.label"), GridData.VERTICAL_ALIGN_CENTER); //$NON-NLS-1$
035: fWorkingDir = createText(c, WORKINGDIR, 1);
036:
037: fClassPath = createTableGroup(parent, Util
038: .getString("page2.addToClasspath.group.label"), true); //$NON-NLS-1$
039: fResources = createTableGroup(parent, Util
040: .getString("page2.addToBundle.group.label"), false); //$NON-NLS-1$
041: }
042:
043: Table createTableGroup(Composite parent, String groupName,
044: final boolean onClasspath) {
045: Group g1 = createGroup(parent, groupName, 1);
046: final Table table = new Table(g1, SWT.H_SCROLL | SWT.V_SCROLL
047: | SWT.MULTI | SWT.FULL_SELECTION);
048: setHeightHint(table, 80);
049: Composite c1 = createComposite(g1, 3);
050: final Button addButton1 = createButton(c1, SWT.NONE, Util
051: .getString("page2.addFile.button.label")); //$NON-NLS-1$
052: addButton1.addSelectionListener(new SelectionAdapter() {
053: public void widgetSelected(SelectionEvent e) {
054: FileDialog fd = new FileDialog(addButton1.getShell(),
055: SWT.OPEN);
056: fd.setText(Util
057: .getString("page2.chooseFileDialog.title")); //$NON-NLS-1$
058: String path = fd.open();
059: if (path != null) {
060: ResourceInfo ri = new ResourceInfo(path);
061: fBundleDescription.addResource(ri, onClasspath);
062: add(table, ri);
063: }
064: }
065: });
066: final Button addButton2 = createButton(c1, SWT.NONE, Util
067: .getString("page2.addFolder.button.label")); //$NON-NLS-1$
068: addButton2.addSelectionListener(new SelectionAdapter() {
069: public void widgetSelected(SelectionEvent e) {
070: DirectoryDialog fd = new DirectoryDialog(addButton2
071: .getShell(), SWT.OPEN);
072: fd.setText(Util
073: .getString("page2.chooseFolder.dialog.title")); //$NON-NLS-1$
074: String path = fd.open();
075: if (path != null) {
076: ResourceInfo ri = new ResourceInfo(path);
077: fBundleDescription.addResource(ri, onClasspath);
078: add(table, ri);
079: }
080: }
081: });
082: final Button removeButton = createButton(c1, SWT.NONE, Util
083: .getString("page2.remove.button.label")); //$NON-NLS-1$
084: removeButton.setEnabled(false);
085: removeButton.addSelectionListener(new SelectionAdapter() {
086: public void widgetSelected(SelectionEvent e) {
087: remove(table, onClasspath, removeButton);
088: }
089: });
090: table.addSelectionListener(new SelectionAdapter() {
091: public void widgetSelected(SelectionEvent e) {
092: removeButton.setEnabled(table.getSelectionCount() > 0);
093: }
094: });
095: return table;
096: }
097:
098: private void add(Table t, ResourceInfo ri) {
099: TableItem ti = new TableItem(t, SWT.NONE);
100: ti.setData(ri);
101: ti.setText(ri.fPath);
102: }
103:
104: private void remove(Table table, boolean b, Button removeButton) {
105: TableItem[] selection = table.getSelection();
106: for (int i = 0; i < selection.length; i++) {
107: TableItem ti = selection[i];
108: ResourceInfo ri = (ResourceInfo) ti.getData();
109: if (fBundleDescription.removeResource(ri, b)) {
110: int ix = table.indexOf(ti);
111: if (ix >= 0)
112: table.remove(ix);
113: }
114: }
115: removeButton.setEnabled(table.getSelectionCount() > 0);
116: }
117:
118: public void propertyChange(PropertyChangeEvent event) {
119: if (fWorkingDir != null)
120: fWorkingDir.setText(fBundleDescription.get(WORKINGDIR, "")); //$NON-NLS-1$
121:
122: if (fClassPath != null) {
123: fClassPath.removeAll();
124: ResourceInfo[] ris = fBundleDescription.getResources(true);
125: for (int i = 0; i < ris.length; i++)
126: add(fClassPath, ris[i]);
127: }
128:
129: if (fResources != null) {
130: fResources.removeAll();
131: ResourceInfo[] ris = fBundleDescription.getResources(false);
132: for (int i = 0; i < ris.length; i++)
133: add(fResources, ris[i]);
134: }
135: }
136:
137: public boolean isPageComplete() {
138: return true;
139: }
140: }
|