KickJava   Java API By Example, From Geeks To Geeks.

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


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  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.sourcelookup.browsers;
12
13 import org.eclipse.core.resources.IFolder;
14 import org.eclipse.core.resources.ResourcesPlugin;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
19 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIMessages;
20 import org.eclipse.jface.viewers.ILabelProvider;
21 import org.eclipse.jface.viewers.ITreeContentProvider;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
29 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
30 import org.eclipse.ui.views.navigator.ResourceComparator;
31
32 /**
33  * The dialog for selecting the folder for which a source container will be created.
34  *
35  * @since 3.0
36  */

37 public class FolderSourceContainerDialog extends ElementTreeSelectionDialog {
38     
39     /**
40      * Constant to persist the state of the search subfolders button
41      *
42      * @since 3.2
43      */

44     private static final String JavaDoc LAST_SUBDIR_SETTING = "EXT_FOLDER_SOURCE_LAST_SUBDIR_SETTING"; //$NON-NLS-1$
45

46     /**
47      * Lets us control searching subfolders
48      *
49      * @since 3.2
50      */

51     private Button fSubfoldersButton;
52     
53     /**
54      * stored value whether to search subfolders or not
55      *
56      * @since 3.2
57      */

58     private boolean fSearchSubfolders = false;
59     
60     /**
61      * We need to add in the new control for indicating whether to search sub folders or not
62      *
63      * @since 3.2
64      */

65     protected Control createDialogArea(Composite parent) {
66         Composite parentc = (Composite)super.createDialogArea(parent);
67         fSubfoldersButton = new Button(parentc, SWT.CHECK);
68         fSubfoldersButton.setText(SourceLookupUIMessages.DirectorySourceContainerDialog_6);
69         fSubfoldersButton.setSelection(fSearchSubfolders);
70         return parentc;
71     }
72
73     /**
74      * Sets the dialog values for its construction
75      * @param parent the parent of the dialog
76      * @param labelProvider the label provider for the content of the tree in the dialog
77      * @param contentProvider the provider of the tree content for the dialog
78      */

79     public FolderSourceContainerDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
80         super(parent, labelProvider, contentProvider);
81         setTitle(SourceLookupUIMessages.folderSelection_title); //
82
setInput(ResourcesPlugin.getWorkspace().getRoot());
83         setComparator(new ResourceComparator(ResourceComparator.NAME));
84         ISelectionStatusValidator validator= new ISelectionStatusValidator() {
85             public IStatus validate(Object JavaDoc[] selection) {
86                 for (int i= 0; i < selection.length; i++) {
87                     if (!(selection[i] instanceof IFolder)) {
88                         return new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), -1, SourceLookupUIMessages.sourceSearch_folderSelectionError, null); //
89
}
90                 }
91                 return new Status(IStatus.OK, DebugUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
92
}
93         };
94         setValidator(validator);
95         setDoubleClickSelects(true);
96         setAllowMultiple(true);
97         setMessage(SourceLookupUIMessages.folderSelection_label);
98         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugHelpContextIds.ADD_FOLDER_CONTAINER_DIALOG);
99         setSearchSubfolders(DebugUIPlugin.getDefault().getDialogSettings().getBoolean(LAST_SUBDIR_SETTING));
100     }
101     
102     /**
103      * Returns whether the 'search subfolders' option is selected.
104      *
105      * @since 3.2
106      * @return true if the search subfolders button is selected, false otherwise.
107      */

108     public boolean isSearchSubfolders() {
109         return fSearchSubfolders;
110     }
111     
112     /**
113      * Sets whether the 'search subfolders' option is selected.
114      *
115      * @param subfolders
116      * @since 3.2
117      */

118     public void setSearchSubfolders(boolean subfolders) {
119         fSearchSubfolders = subfolders;
120     }
121     
122     /* (non-Javadoc)
123      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
124      */

125     protected void okPressed() {
126         fSearchSubfolders = fSubfoldersButton.getSelection();
127         DebugUIPlugin.getDefault().getDialogSettings().put(LAST_SUBDIR_SETTING, fSearchSubfolders);
128         super.okPressed();
129     }
130     
131 }
132
Popular Tags