1 12 package org.eclipse.debug.internal.ui.sourcelookup.browsers; 13 14 import java.io.File ; 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 48 public class DirectorySourceContainerDialog extends TitleAreaDialog { 49 50 private static final String LAST_PATH_SETTING = "EXT_FOLDER_LAST_PATH_SETTING"; private static final String LAST_SUBDIR_SETTING = "EXT_FOLDER_LAST_SUBDIR_SETTING"; 53 private String fDirectory; 54 private boolean fSearchSubfolders = true; 55 56 private Text fDirText; 57 private Button fSubfoldersButton; 58 59 private boolean fNewContainer = true; 60 61 66 public DirectorySourceContainerDialog(Shell shell) { 67 this(shell, "", DebugUIPlugin.getDefault().getDialogSettings().getBoolean(LAST_SUBDIR_SETTING)); fNewContainer = true; 69 } 70 71 79 public DirectorySourceContainerDialog(Shell shell, String directory, boolean searchSubfolders) { 80 super(shell); 81 setShellStyle(getShellStyle() | SWT.RESIZE ); 82 fDirectory = directory; 83 fSearchSubfolders = searchSubfolders; 84 fNewContainer = false; 85 } 86 87 91 public String getDirectory() { 92 return fDirectory; 93 } 94 95 100 public boolean isSearchSubfolders() { 101 return fSearchSubfolders; 102 } 103 104 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 172 protected void configureShell(Shell newShell) { 173 String 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 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 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 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 = ""; } 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 result = dialog.open(); 219 if (result == null) { 220 return; 221 } 222 fDirText.setText(result); 223 } 224 225 private void validate() { 226 File file = new File (fDirText.getText().trim()); 227 getButton(IDialogConstants.OK_ID).setEnabled(file.isDirectory() && file.exists()); 228 } 229 } 230 | Popular Tags |