KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > browsers > DirectorySourceContainerDialog


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 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  * QNX Software Systems - Mikhail Khodjaiants - Bug 114664
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.sourcelookup.browsers;
13
14 import java.io.File JavaDoc;
15
16 import org.eclipse.debug.internal.ui.DebugPluginImages;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.dialogs.TitleAreaDialog;
23 import org.eclipse.jface.resource.JFaceResources;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.ModifyEvent;
26 import org.eclipse.swt.events.ModifyListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.graphics.Font;
30 import org.eclipse.swt.graphics.Image;
31 import org.eclipse.swt.graphics.Point;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.widgets.Button;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Control;
37 import org.eclipse.swt.widgets.DirectoryDialog;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.swt.widgets.Shell;
40 import org.eclipse.swt.widgets.Text;
41 import org.eclipse.ui.PlatformUI;
42
43 /**
44  * The dialog for selecting the external folder for which a source container will be created.
45  *
46  * @since 3.0
47  */

48 public class DirectorySourceContainerDialog extends TitleAreaDialog {
49
50     private static final String JavaDoc LAST_PATH_SETTING = "EXT_FOLDER_LAST_PATH_SETTING"; //$NON-NLS-1$
51
private static final String JavaDoc LAST_SUBDIR_SETTING = "EXT_FOLDER_LAST_SUBDIR_SETTING"; //$NON-NLS-1$
52

53     private String JavaDoc fDirectory;
54     private boolean fSearchSubfolders = true;
55     
56     private Text fDirText;
57     private Button fSubfoldersButton;
58     
59     private boolean fNewContainer = true;
60
61     /**
62      * Creates a dialog to select a new file system folder.
63      *
64      * @param shell shell
65      */

66     public DirectorySourceContainerDialog(Shell shell) {
67         this(shell, "", DebugUIPlugin.getDefault().getDialogSettings().getBoolean(LAST_SUBDIR_SETTING)); //$NON-NLS-1$
68
fNewContainer = true;
69     }
70
71     /**
72      * Creates a dialog to edit file system folder.
73      *
74      * @param shell shell
75      * @param directory directory to edit or empty string
76      * @param searchSubfolders whether the search subfolders button should be checked
77      * @param newContainer
78      */

79     public DirectorySourceContainerDialog(Shell shell, String JavaDoc directory, boolean searchSubfolders) {
80         super(shell);
81         setShellStyle(getShellStyle() | SWT.RESIZE );
82         fDirectory = directory;
83         fSearchSubfolders = searchSubfolders;
84         fNewContainer = false;
85     }
86     
87     /**
88      * Returns the result of the dialog.open() operation
89      * @return the dialog.open() result
90      */

91     public String JavaDoc getDirectory() {
92         return fDirectory;
93     }
94
95     /**
96      * Returns whether the 'search subfolders' option is selected.
97      *
98      * @return whether the 'search subfolders' option is selected
99      */

100     public boolean isSearchSubfolders() {
101         return fSearchSubfolders;
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
106      */

107     protected Control createDialogArea(Composite parent) {
108         Image image = (fNewContainer) ? DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_ADD_SRC_DIR_WIZ) :
109             DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_EDIT_SRC_DIR_WIZ);
110         setTitle(SourceLookupUIMessages.DirectorySourceContainerDialog_2);
111         setMessage(SourceLookupUIMessages.DirectorySourceContainerDialog_3);
112         setTitleImage(image);
113         Composite parentComposite = (Composite)super.createDialogArea(parent);
114         Font font = parentComposite.getFont();
115         Composite composite = new Composite(parentComposite, SWT.NONE);
116         GridLayout layout = new GridLayout();
117         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
118         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
119         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
120         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
121         composite.setLayout(layout);
122         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
123         composite.setFont(font);
124
125         Composite dirComposite = new Composite(composite, SWT.NONE);
126         layout = new GridLayout(2, false);
127         dirComposite.setLayout(layout);
128         dirComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
129         dirComposite.setFont(font);
130
131         Label label = new Label(dirComposite, SWT.NONE);
132         label.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_4);
133         GridData data = new GridData(GridData.FILL_HORIZONTAL);
134         data.horizontalSpan = 2;
135         label.setLayoutData(data);
136         label.setFont(font);
137         
138         fDirText = new Text(dirComposite, SWT.BORDER);
139         data = new GridData(GridData.FILL_HORIZONTAL);
140         data.horizontalSpan = 1;
141         fDirText.setLayoutData(data);
142         fDirText.setFont(font);
143         fDirText.addModifyListener(new ModifyListener() {
144             public void modifyText( ModifyEvent e ) {
145                 validate();
146             }
147         });
148
149         Button button = new Button(dirComposite, SWT.PUSH);
150         button.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_5);
151         data = new GridData();
152         int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
153         Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
154         data.widthHint = Math.max(widthHint, minSize.x);
155         button.setLayoutData(data);
156         button.setFont(JFaceResources.getDialogFont());
157         button.addSelectionListener(new SelectionAdapter() {
158             public void widgetSelected(SelectionEvent event) {
159                 browse();
160             }
161         });
162
163         fSubfoldersButton = new Button(composite, SWT.CHECK);
164         fSubfoldersButton.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_6);
165
166         return parentComposite;
167     }
168
169     /* (non-Javadoc)
170      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
171      */

172     protected void configureShell(Shell newShell) {
173         String JavaDoc title = null;
174         if (fNewContainer) {
175             title = SourceLookupUIMessages.DirectorySourceContainerDialog_7;
176         } else {
177             title = SourceLookupUIMessages.DirectorySourceContainerDialog_8;
178         }
179         newShell.setText(title);
180         super.configureShell( newShell );
181     }
182
183     /* (non-Javadoc)
184      * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite)
185      */

186     protected Control createContents(Composite parent) {
187         Control c = super.createContents(parent);
188         fDirText.setText(fDirectory);
189         fSubfoldersButton.setSelection(fSearchSubfolders);
190         validate();
191         PlatformUI.getWorkbench().getHelpSystem().setHelp(c, IDebugHelpContextIds.SELECT_DIRECTORY_SOURCE_CONTAINER_DIALOG);
192         return c;
193     }
194
195     /* (non-Javadoc)
196      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
197      */

198     protected void okPressed() {
199         fDirectory = fDirText.getText().trim();
200         fSearchSubfolders = fSubfoldersButton.getSelection();
201         DebugUIPlugin.getDefault().getDialogSettings().put(LAST_PATH_SETTING, fDirectory);
202         DebugUIPlugin.getDefault().getDialogSettings().put(LAST_SUBDIR_SETTING, fSearchSubfolders);
203         super.okPressed();
204     }
205
206     private void browse() {
207         String JavaDoc last = fDirText.getText().trim();
208         if (last.length() == 0) {
209             last = DebugUIPlugin.getDefault().getDialogSettings().get(LAST_PATH_SETTING);
210         }
211         if (last == null) {
212             last = ""; //$NON-NLS-1$
213
}
214         DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SINGLE);
215         dialog.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_0);
216         dialog.setMessage(SourceLookupUIMessages.DirectorySourceContainerDialog_1);
217         dialog.setFilterPath(last);
218         String JavaDoc result = dialog.open();
219         if (result == null) {
220             return;
221         }
222         fDirText.setText(result);
223     }
224
225     private void validate() {
226         File JavaDoc file = new File JavaDoc(fDirText.getText().trim());
227         getButton(IDialogConstants.OK_ID).setEnabled(file.isDirectory() && file.exists());
228     }
229 }
230
Popular Tags