1 11 12 package org.eclipse.debug.internal.ui.importexport.breakpoints; 13 14 import java.io.File ; 15 import java.lang.reflect.InvocationTargetException ; 16 import com.ibm.icu.text.MessageFormat; 17 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 21 import org.eclipse.debug.internal.ui.SWTFactory; 22 import org.eclipse.debug.ui.DebugUITools; 23 import org.eclipse.debug.ui.actions.ImportBreakpointsOperation; 24 import org.eclipse.jface.dialogs.IDialogSettings; 25 import org.eclipse.jface.wizard.WizardPage; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.graphics.Font; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Event; 34 import org.eclipse.swt.widgets.FileDialog; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Listener; 38 import org.eclipse.swt.widgets.Text; 39 import org.eclipse.swt.widgets.Widget; 40 import org.eclipse.ui.PlatformUI; 41 42 49 public class WizardImportBreakpointsPage extends WizardPage implements Listener { 50 51 private Button fAutoRemoveDuplicates = null; 53 private Button fAutoCreateWorkingSets = null; 54 private Text fFileNameField = null; 55 private Button fBrowseForFileButton = null; 56 57 private static final String REMOVE_DUPS = "overwrite"; private static final String CREATE_WORKING_SETS = "createws"; private static final String SOURCE_FILE_NAME = "filename"; 62 68 public WizardImportBreakpointsPage(String pageName) { 69 super(pageName, ImportExportMessages.WizardImportBreakpointsPage_0, null); 70 } 71 72 75 public void handleEvent(Event event) { 76 Widget source = event.widget; 77 if(source == fBrowseForFileButton) { 78 handleBrowseForFileButtonPressed(); 79 } 80 setPageComplete(detectPageComplete()); 81 } 82 83 86 protected void handleBrowseForFileButtonPressed() { 87 FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.OPEN); 88 dialog.setFilterExtensions(new String []{"*."+IImportExportConstants.EXTENSION}); String file = dialog.open(); 90 if(file != null) { 91 fFileNameField.setText(file); 92 } 93 } 94 95 98 public void createControl(Composite parent) { 99 initializeDialogUnits(parent); 100 Composite composite = new Composite(parent, SWT.NULL); 101 composite.setLayout(new GridLayout()); 102 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 103 composite.setFont(parent.getFont()); 104 createDestinationGroup(composite); 105 createOptionsGroup(composite); 106 setControl(composite); 107 restoreWidgetState(); 108 setPageComplete(detectPageComplete()); 109 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.IMPORT_BREAKPOINTS_WIZARD_PAGE); 110 } 111 112 115 public Image getImage() { 116 return DebugUITools.getImage(IInternalDebugUIConstants.IMG_WIZBAN_IMPORT_BREAKPOINTS); 117 } 118 119 125 private boolean detectPageComplete() { 126 String fileName = fFileNameField.getText().trim(); 127 if (fileName.equals("")) { setMessage(ImportExportMessages.WizardImportBreakpointsPage_6); 129 return false; 130 } 131 File file = new File (fileName); 132 if (!file.exists() || file.isDirectory()) { 133 setMessage(MessageFormat.format(ImportExportMessages.WizardImportBreakpointsPage_1, new String []{fileName}), ERROR); 134 return false; 135 } 136 137 setMessage(ImportExportMessages.WizardImportBreakpointsPage_2); 138 return true; 139 } 140 141 146 protected void createOptionsGroup(Composite parent) { 147 Font font = parent.getFont(); 148 Group optionsGroup = new Group(parent, SWT.NONE); 150 GridLayout layout = new GridLayout(); 151 optionsGroup.setLayout(layout); 152 optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); 153 optionsGroup.setText(ImportExportMessages.WizardBreakpointsPage_5); 154 optionsGroup.setFont(parent.getFont()); 155 fAutoRemoveDuplicates = new Button(optionsGroup, SWT.CHECK | SWT.LEFT); 156 fAutoRemoveDuplicates.setText(ImportExportMessages.WizardImportBreakpointsPage_3); 157 fAutoRemoveDuplicates.setFont(font); 158 fAutoCreateWorkingSets = new Button(optionsGroup, SWT.CHECK | SWT.LEFT); 159 fAutoCreateWorkingSets.setText(ImportExportMessages.WizardImportBreakpointsPage_5); 160 fAutoCreateWorkingSets.setFont(font); 161 } 162 163 168 protected void createDestinationGroup(Composite parent) { 169 Font font = parent.getFont(); 170 Composite destinationSelectionGroup = new Composite(parent, SWT.NONE); 171 GridLayout layout = new GridLayout(); 172 layout.numColumns = 3; 173 destinationSelectionGroup.setLayout(layout); 174 destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); 175 destinationSelectionGroup.setFont(font); 176 Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE); 177 destinationLabel.setText(ImportExportMessages.WizardImportBreakpointsPage_4); 178 destinationLabel.setFont(font); 179 180 fFileNameField = new Text(destinationSelectionGroup, SWT.BORDER); 182 fFileNameField.addListener(SWT.Modify, this); 183 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); 184 fFileNameField.setLayoutData(data); 185 fFileNameField.setFont(font); 186 187 fBrowseForFileButton = SWTFactory.createPushButton(destinationSelectionGroup, ImportExportMessages.WizardBreakpointsPage_8, null); 189 fBrowseForFileButton.addListener(SWT.Selection, this); 190 } 191 192 195 private void saveWidgetState() { 196 IDialogSettings settings = getDialogSettings(); 197 if(settings != null) { 198 settings.put(REMOVE_DUPS, fAutoRemoveDuplicates.getSelection()); 199 settings.put(CREATE_WORKING_SETS, fAutoCreateWorkingSets.getSelection()); 200 settings.put(SOURCE_FILE_NAME, fFileNameField.getText().trim()); 201 } 202 } 203 204 207 private void restoreWidgetState() { 208 IDialogSettings settings = getDialogSettings(); 209 if(settings != null) { 210 fAutoRemoveDuplicates.setSelection(Boolean.valueOf(settings.get(REMOVE_DUPS)).booleanValue()); 211 fAutoCreateWorkingSets.setSelection(Boolean.valueOf(settings.get(CREATE_WORKING_SETS)).booleanValue()); 212 String fileName = settings.get(SOURCE_FILE_NAME); 213 if (fileName != null) { 214 fFileNameField.setText(fileName); 215 } 216 } 217 } 218 219 227 public boolean finish() { 228 try { 229 saveWidgetState(); 230 getContainer().run(true, true, new ImportBreakpointsOperation(fFileNameField.getText().trim(), fAutoRemoveDuplicates.getSelection(), fAutoCreateWorkingSets.getSelection())); 231 } 232 catch (InterruptedException e) { 233 DebugPlugin.log(e); 234 return false; 235 } 236 catch (InvocationTargetException e) { 237 DebugPlugin.log(e); 238 return false; 239 } 240 return true; 241 } 242 243 } 244 | Popular Tags |