KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dolphin > dialogs > DialogWorkspace


1 /*
2 * Copyright (C) 2005 Bourgeon Jérôme, Macherel Bruno
3 *
4 * This file is part of Dolphin
5 *
6 * Dolphin : An open source J2EE Deployment Tool JSR-88 compliant
7 * Contact: ishmael-dev@objectweb.org
8 *
9 * Dolphin is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or any later version.
13 *
14 * Dolphin is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with Dolphin; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */

24 package org.objectweb.dolphin.dialogs;
25
26 import org.eclipse.jface.dialogs.Dialog;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.DirectoryDialog;
36 import org.eclipse.swt.widgets.Label;
37 import org.eclipse.swt.widgets.Shell;
38 import org.eclipse.swt.widgets.Text;
39 import org.objectweb.dolphin.resources.DolphinResourcesManagment;
40
41 /**
42  * Class who implements the UI of the Change Workspace Dialog
43  * @author Bourgeon Jérôme, Macherel Bruno
44  */

45 public class DialogWorkspace extends Dialog{
46     private String JavaDoc text ="";
47
48     /**
49      * Creates a dialog instance. Note that the window will have no visual
50      * representation (no widgets) until it is told to open. By default,
51      * <code>open</code> blocks for dialogs.
52      *
53      * @param parentShell
54      * the parent shell, or <code>null</code> to create a top-level
55      * shell
56      */

57     public DialogWorkspace(Shell parentShell) {
58         super(parentShell);
59     }
60
61     /**
62      * Method who open a Directory Dialog
63      * @return the path of the directory
64      */

65     private String JavaDoc queryFile() {
66         DirectoryDialog dialog= new DirectoryDialog(new Shell(), SWT.OPEN);
67         dialog.setText("Switch Workspace"); //$NON-NLS-1$
68
String JavaDoc path= dialog.open();
69         if (path != null && path.length() > 0)
70             return path;
71         return null;
72     }
73
74     /**
75      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
76      */

77     public Control createDialogArea(Composite parent){
78         Composite composite = (Composite) super.createDialogArea(parent);
79         GridLayout grid = new GridLayout(2,true);
80         composite.setLayout(grid);
81         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
82
83         Label old = new Label(composite, SWT.BOLD);
84         old.setText("Old workspace : "+DolphinResourcesManagment.getWorkspace());
85         gd.horizontalSpan=2;
86         old.setLayoutData(gd);
87         gd = new GridData(GridData.FILL_HORIZONTAL);
88
89         //The Label
90
Label label = new Label(composite, SWT.BOLD);
91         label.setText("Select the new workspace :");
92         gd.horizontalSpan=2;
93         label.setLayoutData(gd);
94
95         //The File Browser
96
gd = new GridData(GridData.FILL_HORIZONTAL);
97         final Text textField = new Text(composite,SWT.BORDER);
98         textField.setBounds(10,10,300,20);
99         textField.setLayoutData(gd);
100         gd = new GridData(GridData.FILL_HORIZONTAL);
101         Button button = new Button(composite,SWT.PUSH);
102         button.setText("Browse");
103         button.addSelectionListener(new SelectionAdapter() {
104             public void widgetSelected(SelectionEvent e) {
105                 text = queryFile();
106                 textField.setText(text);
107             }
108         });
109         button.setLayoutData(gd);
110
111
112         return composite;
113     }
114
115     /**
116      * Set the new workspace in the application
117      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
118      */

119     protected void okPressed() {
120         DolphinResourcesManagment.setWorkspace(text);
121         super.okPressed();
122     }
123
124
125
126
127 }
128
Popular Tags