1 11 12 package org.eclipse.debug.internal.ui.importexport.breakpoints; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import com.ibm.icu.text.MessageFormat; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.Path; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.model.IBreakpoint; 23 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 24 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 25 import org.eclipse.debug.internal.ui.SWTFactory; 26 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsViewer; 27 import org.eclipse.debug.ui.DebugUITools; 28 import org.eclipse.debug.ui.actions.ExportBreakpointsOperation; 29 import org.eclipse.jface.dialogs.Dialog; 30 import org.eclipse.jface.dialogs.IDialogSettings; 31 import org.eclipse.jface.dialogs.IMessageProvider; 32 import org.eclipse.jface.dialogs.MessageDialog; 33 import org.eclipse.jface.viewers.CheckStateChangedEvent; 34 import org.eclipse.jface.viewers.ICheckStateListener; 35 import org.eclipse.jface.viewers.IStructuredSelection; 36 import org.eclipse.jface.wizard.WizardPage; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.graphics.Font; 39 import org.eclipse.swt.graphics.Image; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.layout.GridLayout; 42 import org.eclipse.swt.widgets.Button; 43 import org.eclipse.swt.widgets.Composite; 44 import org.eclipse.swt.widgets.Event; 45 import org.eclipse.swt.widgets.FileDialog; 46 import org.eclipse.swt.widgets.Group; 47 import org.eclipse.swt.widgets.Label; 48 import org.eclipse.swt.widgets.Listener; 49 import org.eclipse.swt.widgets.Text; 50 import org.eclipse.swt.widgets.Widget; 51 import org.eclipse.ui.PlatformUI; 52 53 73 public class WizardExportBreakpointsPage extends WizardPage implements Listener { 74 75 private Button fOverwriteExistingFilesCheckbox = null; 77 private Text fDestinationNameField = null; 78 private Button fDestinationBrowseButton = null; 79 private IPath fPath = null; 80 private EmbeddedBreakpointsViewer fTView = null; 81 private IStructuredSelection fSelection = null; 82 private Button fSelectAll = null; 83 private Button fDeselectAll = null; 84 85 private static final String OVERWRITE_ALL_STATE = "overwrite"; private static final String DESTINATION_FILE_NAME = "filename"; 89 95 public WizardExportBreakpointsPage(String pageName, IStructuredSelection selection) { 96 super(pageName, ImportExportMessages.WizardExportBreakpoints_0, null); 97 fSelection = selection; 98 } 99 100 103 public void handleEvent(Event event) { 104 Widget source = event.widget; 105 if (source == fDestinationBrowseButton) { 106 handleDestinationBrowseButtonPressed(); 107 } 108 else if (source == fDestinationNameField) { 109 handlePathTextModifiedEvent(); 110 } 111 else if(source == fSelectAll) { 112 handleSelectAllPressed(); 113 } 114 else if(source == fDeselectAll) { 115 handleDeselectAllPressed(); 116 } 117 } 118 119 123 private void handleSelectAllPressed() { 124 BreakpointsViewer viewer = fTView.getViewer(); 125 viewer.getTree().selectAll(); 126 viewer.setCheckedElements(((IStructuredSelection)viewer.getSelection()).toArray()); 127 viewer.setGrayedElements(new Object [] {}); 128 viewer.getTree().deselectAll(); 129 setPageComplete(detectPageComplete()); 130 } 131 132 136 private void handleDeselectAllPressed() { 137 BreakpointsViewer viewer = fTView.getViewer(); 138 viewer.setCheckedElements(new Object [] {}); 139 viewer.setGrayedElements(new Object [] {}); 140 setPageComplete(detectPageComplete()); 141 } 142 143 146 protected void handlePathTextModifiedEvent() { 147 setPageComplete(detectPageComplete()); 148 } 149 150 153 protected void handleDestinationBrowseButtonPressed() { 154 FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE); 155 dialog.setFilterExtensions(new String []{"*."+IImportExportConstants.EXTENSION}); dialog.setText(ImportExportMessages.WizardExportBreakpoints_0); 157 String file = dialog.open(); 158 if(file != null) { 159 fPath = new Path(file); 160 if (fPath != null) { 161 setErrorMessage(null); 162 if(fPath.getFileExtension() == null) { 163 fPath = fPath.addFileExtension(IImportExportConstants.EXTENSION); 164 } 165 else if(!fPath.getFileExtension().equals(IImportExportConstants.EXTENSION)) { 166 fPath = fPath.addFileExtension(IImportExportConstants.EXTENSION); 167 } 168 fDestinationNameField.setText(fPath.toString()); 169 } 170 } 171 } 172 173 176 public void createControl(Composite parent) { 177 initializeDialogUnits(parent); 178 Composite composite = new Composite(parent, SWT.NULL); 179 composite.setLayout(new GridLayout()); 180 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 181 182 fTView = new EmbeddedBreakpointsViewer(composite, DebugPlugin.getDefault().getBreakpointManager(), fSelection); 183 fTView.getViewer().addCheckStateListener(new ICheckStateListener() { 184 public void checkStateChanged(CheckStateChangedEvent event) { 185 setPageComplete(detectPageComplete()); 186 } 187 }); 188 fTView.getViewer().setSelection(fSelection); 189 fTView.getViewer().getTree().getHorizontalBar().setSelection(0); 193 createButtonsGroup(composite); 194 createDestinationGroup(composite); 195 createOptionsGroup(composite); 196 setControl(composite); 197 setPageComplete(detectPageComplete()); 198 restoreWidgetState(); 199 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.EXPORT_BREAKPOINTS_WIZARD_PAGE); 200 201 Dialog.applyDialogFont(parent); 202 } 203 204 207 public Image getImage() { 208 return DebugUITools.getImage(IInternalDebugUIConstants.IMG_WIZBAN_EXPORT_BREAKPOINTS); 209 } 210 211 216 private void createButtonsGroup(Composite parent) { 217 Composite composite = new Composite(parent, SWT.NONE); 218 composite.setFont(parent.getFont()); 219 GridLayout layout = new GridLayout(); 220 layout.numColumns = 3; 221 layout.makeColumnsEqualWidth = true; 222 composite.setLayout(layout); 223 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 224 fSelectAll = SWTFactory.createPushButton(composite, ImportExportMessages.WizardBreakpointsPage_1, null); 225 fSelectAll.addListener(SWT.Selection, this); 226 fDeselectAll = SWTFactory.createPushButton(composite, ImportExportMessages.WizardBreakpointsPage_2, null); 227 fDeselectAll.addListener(SWT.Selection, this); 228 } 229 230 238 private boolean detectPageComplete() { 239 boolean emptyFile = fDestinationNameField.getText().trim().equals(""); if (emptyFile) { 241 setMessage(ImportExportMessages.WizardExportBreakpointsPage_0, IMessageProvider.NONE); 242 return false; 243 } 244 int size = fTView.getCheckedElements().size(); 245 if (size == 0) { 246 setMessage(ImportExportMessages.WizardExportBreakpointsPage_1, IMessageProvider.ERROR); 247 return false; 248 } 249 setMessage(ImportExportMessages.WizardBreakpointsPage_4); 250 return true; 251 } 252 253 258 protected void createOptionsGroup(Composite parent) { 259 Font font = parent.getFont(); 260 Group OptionsGroup = new Group(parent, SWT.NONE); 262 GridLayout layout = new GridLayout(); 263 OptionsGroup.setLayout(layout); 264 OptionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); 265 OptionsGroup.setText(ImportExportMessages.WizardBreakpointsPage_5); 266 OptionsGroup.setFont(parent.getFont()); 267 fOverwriteExistingFilesCheckbox = new Button(OptionsGroup, SWT.CHECK | SWT.LEFT); 268 fOverwriteExistingFilesCheckbox.setText(ImportExportMessages.WizardBreakpointsPage_6); 269 fOverwriteExistingFilesCheckbox.setFont(font); 270 } 271 272 277 protected void createDestinationGroup(Composite parent) { 278 Font font = parent.getFont(); 279 Composite destinationSelectionGroup = new Composite(parent, SWT.NONE); 281 GridLayout layout = new GridLayout(); 282 layout.numColumns = 3; 283 destinationSelectionGroup.setLayout(layout); 284 destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); 285 destinationSelectionGroup.setFont(font); 286 Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE); 287 destinationLabel.setText(ImportExportMessages.WizardBreakpointsPage_7); 288 destinationLabel.setFont(font); 289 fDestinationNameField = new Text(destinationSelectionGroup, SWT.BORDER); 290 fDestinationNameField.addListener(SWT.Modify, this); 291 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); 292 fDestinationNameField.setLayoutData(data); 293 fDestinationNameField.setFont(font); 294 fDestinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH); 295 fDestinationBrowseButton.setText(ImportExportMessages.WizardBreakpointsPage_8); 296 fDestinationBrowseButton.addListener(SWT.Selection, this); 297 fDestinationBrowseButton.setFont(font); 298 setButtonLayoutData(fDestinationBrowseButton); 299 } 300 301 304 private void saveWidgetState() { 305 IDialogSettings settings = getDialogSettings(); 306 if(settings != null) { 307 settings.put(OVERWRITE_ALL_STATE, fOverwriteExistingFilesCheckbox.getSelection()); 308 settings.put(DESTINATION_FILE_NAME, fDestinationNameField.getText().trim()); 309 } 310 } 311 312 315 private void restoreWidgetState() { 316 IDialogSettings settings = getDialogSettings(); 317 if(settings != null) { 318 fOverwriteExistingFilesCheckbox.setSelection(Boolean.valueOf(settings.get(OVERWRITE_ALL_STATE)).booleanValue()); 319 String filename = settings.get(DESTINATION_FILE_NAME); 320 if (filename != null) { 321 fDestinationNameField.setText(filename); 322 } 323 } 324 } 325 326 333 public boolean finish() { 334 try { 335 if(fPath == null) { 337 fPath = new Path(fDestinationNameField.getText().trim()); 338 if(fPath.getFileExtension() == null) { 339 fPath = fPath.addFileExtension(IImportExportConstants.EXTENSION); 340 } 341 else if(!fPath.getFileExtension().equals(IImportExportConstants.EXTENSION)) { 342 fPath = fPath.addFileExtension(IImportExportConstants.EXTENSION); 343 } 344 } 345 saveWidgetState(); 346 if(fPath.toFile().exists() && !fOverwriteExistingFilesCheckbox.getSelection()) { 347 if (!MessageDialog.openQuestion(null, ImportExportMessages.WizardBreakpointsPage_12, MessageFormat.format(ImportExportMessages.ImportExportOperations_0, new String [] {fPath.toPortableString()}))) { 348 return false; 349 } 350 } 351 Object [] elements = fTView.getCheckedElements().toArray(); 353 List breakpoints = new ArrayList (); 354 for (int i = 0; i < elements.length; i++) { 355 Object object = elements[i]; 356 if (object instanceof IBreakpoint) { 357 breakpoints.add(object); 358 } 359 } 360 getContainer().run(true, true, new ExportBreakpointsOperation((IBreakpoint[]) breakpoints.toArray(new IBreakpoint[breakpoints.size()]), fPath.toOSString())); 361 } 362 catch (InterruptedException e) { 363 DebugPlugin.log(e); 364 return false; 365 } 366 catch (InvocationTargetException e) { 367 DebugPlugin.log(e); 368 return false; 369 } 370 return true; 371 } 372 } 373 | Popular Tags |