KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > MarkerResolutionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.ui.views.markers.internal;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.Hashtable JavaDoc;
17
18 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.core.runtime.SubProgressMonitor;
20 import org.eclipse.jface.dialogs.Dialog;
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.jface.viewers.CheckStateChangedEvent;
25 import org.eclipse.jface.viewers.CheckboxTableViewer;
26 import org.eclipse.jface.viewers.ColumnWeightData;
27 import org.eclipse.jface.viewers.ICheckStateListener;
28 import org.eclipse.jface.viewers.ILabelProviderListener;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.ISelectionChangedListener;
31 import org.eclipse.jface.viewers.IStructuredContentProvider;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.jface.viewers.ITableLabelProvider;
34 import org.eclipse.jface.viewers.LabelProvider;
35 import org.eclipse.jface.viewers.ListViewer;
36 import org.eclipse.jface.viewers.SelectionChangedEvent;
37 import org.eclipse.jface.viewers.TableLayout;
38 import org.eclipse.jface.viewers.Viewer;
39 import org.eclipse.jface.viewers.ViewerComparator;
40 import org.eclipse.jface.wizard.ProgressMonitorPart;
41 import org.eclipse.osgi.util.NLS;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.custom.BusyIndicator;
44 import org.eclipse.swt.events.SelectionAdapter;
45 import org.eclipse.swt.events.SelectionEvent;
46 import org.eclipse.swt.graphics.Image;
47 import org.eclipse.swt.layout.FormAttachment;
48 import org.eclipse.swt.layout.FormData;
49 import org.eclipse.swt.layout.FormLayout;
50 import org.eclipse.swt.layout.GridData;
51 import org.eclipse.swt.layout.GridLayout;
52 import org.eclipse.swt.widgets.Button;
53 import org.eclipse.swt.widgets.Composite;
54 import org.eclipse.swt.widgets.Control;
55 import org.eclipse.swt.widgets.Label;
56 import org.eclipse.swt.widgets.Shell;
57 import org.eclipse.swt.widgets.Table;
58 import org.eclipse.swt.widgets.TableColumn;
59 import org.eclipse.ui.IMarkerResolution;
60 import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
61 import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
62
63 /**
64  * The MarkerResolutionDialog is the dialog used to select a marker resolution.
65  *
66  * @since 3.2
67  *
68  */

69 public class MarkerResolutionDialog extends TitleAreaDialog {
70
71     private IMarker originalMarker;
72
73     private IMarkerResolution[] resolutions;
74
75     private CheckboxTableViewer markersTable;
76
77     private ListViewer resolutionsList;
78
79     private ProgressMonitorPart progressPart;
80
81     private MarkerView markerView;
82
83     private ViewerComparator resolutionsComparator;
84
85     private boolean calculatingResolutions;
86
87     private boolean progressCancelled = false;
88
89     private Button addMatching;
90
91     private Hashtable JavaDoc markerMap = new Hashtable JavaDoc(0);
92
93     /**
94      * Create a new instance of the receiver with the given resolutions.
95      *
96      * @param shell
97      * @param marker
98      * the marker to show
99      * @param newResolutions
100      * @param view
101      * the viewer that is showing these errors
102      */

103     public MarkerResolutionDialog(Shell shell, IMarker marker,
104             IMarkerResolution[] newResolutions, MarkerView view) {
105         super(shell);
106         setShellStyle(getShellStyle() | SWT.RESIZE);
107         initializeResolutionsSorter();
108         resolutionsComparator.sort(view.getViewer(), newResolutions);
109         resolutions = newResolutions;
110         originalMarker = marker;
111         markerView = view;
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
118      */

119     protected void configureShell(Shell newShell) {
120         super.configureShell(newShell);
121         newShell.setText(MarkerMessages.resolveMarkerAction_dialogTitle);
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
128      */

129     protected Control createDialogArea(Composite parent) {
130
131         initializeDialogUnits(parent);
132
133         setTitleImage(JFaceResources
134                 .getResources()
135                 .createImageWithDefault(
136                         IDEInternalWorkbenchImages
137                                 .getImageDescriptor(IDEInternalWorkbenchImages.IMG_DLGBAN_QUICKFIX_DLG)));
138
139         Composite mainArea = (Composite) super.createDialogArea(parent);
140
141         // Create a new composite as there is the title bar seperator
142
// to deal with
143
Composite control = new Composite(mainArea, SWT.NONE);
144         control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
145
146         FormLayout layout = new FormLayout();
147         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
148         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
149         layout.spacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
150         control.setLayout(layout);
151
152         Label resolutionsLabel = new Label(control, SWT.NONE);
153         resolutionsLabel
154                 .setText(MarkerMessages.MarkerResolutionDialog_Resolutions_List_Title);
155
156         resolutionsLabel.setLayoutData(new FormData());
157
158         resolutionsList = new ListViewer(control, SWT.BORDER | SWT.SINGLE
159                 | SWT.V_SCROLL);
160         resolutionsList.setContentProvider(new IStructuredContentProvider() {
161             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
162                 return resolutions;
163             }
164
165             /*
166              * (non-Javadoc)
167              *
168              * @see org.eclipse.jface.viewers.IContentProvider#dispose()
169              */

170             public void dispose() {
171
172             }
173
174             /*
175              * (non-Javadoc)
176              *
177              * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
178              * java.lang.Object, java.lang.Object)
179              */

180             public void inputChanged(Viewer viewer, Object JavaDoc oldInput,
181                     Object JavaDoc newInput) {
182
183             }
184         });
185
186         resolutionsList.setLabelProvider(new LabelProvider() {
187             public String JavaDoc getText(Object JavaDoc element) {
188                 return ((IMarkerResolution) element).getLabel();
189             }
190         });
191
192         resolutionsList
193                 .addSelectionChangedListener(new ISelectionChangedListener() {
194                     /*
195                      * (non-Javadoc)
196                      *
197                      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
198                      */

199                     public void selectionChanged(SelectionChangedEvent event) {
200
201                         WorkbenchMarkerResolution resolution = getSelectedWorkbenchResolution();
202                         if (resolution == null
203                                 || markerMap.containsKey(resolution))
204                             addMatching.setEnabled(false);
205                         else
206                             addMatching.setEnabled(true);
207                         markersTable.refresh();
208                     }
209                 });
210
211         resolutionsList.setInput(this);
212
213         resolutionsList.setComparator(resolutionsComparator);
214
215         FormData listData = new FormData();
216         listData.top = new FormAttachment(resolutionsLabel, 0);
217         listData.left = new FormAttachment(0);
218         listData.right = new FormAttachment(100, 0);
219         listData.height = convertHeightInCharsToPixels(10);
220         resolutionsList.getControl().setLayoutData(listData);
221
222         Label title = new Label(control, SWT.NONE);
223         title
224                 .setText(MarkerMessages.MarkerResolutionDialog_Problems_List_Title);
225         FormData labelData = new FormData();
226         labelData.top = new FormAttachment(resolutionsList.getControl(), 0);
227         labelData.left = new FormAttachment(0);
228         title.setLayoutData(labelData);
229
230         Composite buttons = createTableButtons(control);
231         FormData buttonData = new FormData();
232         buttonData.top = new FormAttachment(title, 0);
233         buttonData.right = new FormAttachment(100);
234         buttonData.height = convertHeightInCharsToPixels(10);
235         buttons.setLayoutData(buttonData);
236
237         createMarkerTable(control);
238
239         FormData tableData = new FormData();
240         tableData.top = new FormAttachment(buttons, 0, SWT.TOP);
241         tableData.left = new FormAttachment(0);
242         tableData.right = new FormAttachment(buttons, 0);
243         tableData.height = convertHeightInCharsToPixels(10);
244         markersTable.getControl().setLayoutData(tableData);
245
246         progressPart = new ProgressMonitorPart(control, new GridLayout());
247
248         FormData progressData = new FormData();
249         progressData.top = new FormAttachment(markersTable.getControl(), 0);
250         progressData.left = new FormAttachment(0);
251         progressData.right = new FormAttachment(100, 0);
252         progressPart.setLayoutData(progressData);
253
254         Dialog.applyDialogFont(control);
255
256         String JavaDoc message = NLS.bind(
257                 MarkerMessages.MarkerResolutionDialog_Description, Util
258                         .getProperty(IMarker.MESSAGE, originalMarker));
259         if (message.length() > 50) {
260             // Add a carriage return in the middle if we can
261
int insertionIndex = chooseWhitespace(message);
262             if (insertionIndex > 0) {
263                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
264                 buffer.append(message.substring(0, insertionIndex));
265                 buffer.append("\n"); //$NON-NLS-1$
266
buffer.append(message.substring(insertionIndex, message
267                         .length()));
268                 message = buffer.toString();
269             }
270         }
271
272         setMessage(message);
273         return mainArea;
274
275     }
276
277     /**
278      * Choose a good whitespace position for a page break. Start in the middle
279      * of the message.
280      *
281      * @param message
282      * @return int -1 if there is no whitespace to choose.
283      */

284     private int chooseWhitespace(String JavaDoc message) {
285
286         for (int i = message.length() / 2; i < message.length(); i++) {
287             if (Character.isWhitespace(message.charAt(i)))
288                 return i;
289         }
290         return -1;
291     }
292
293     /**
294      * Create the resolutions sorter.
295      */

296     private void initializeResolutionsSorter() {
297         resolutionsComparator = new ViewerComparator() {
298             /*
299              * (non-Javadoc)
300              *
301              * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
302              * java.lang.Object, java.lang.Object)
303              */

304             public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
305                 return ((IMarkerResolution) e1).getLabel().compareTo(
306                         ((IMarkerResolution) e1).getLabel());
307             }
308         };
309     }
310
311     /**
312      * Create the buttons for the table.
313      *
314      * @param control
315      * @return Composite
316      */

317     private Composite createTableButtons(Composite control) {
318
319         Composite buttonComposite = new Composite(control, SWT.NONE);
320         GridLayout layout = new GridLayout();
321         layout.marginWidth = 0;
322         layout.marginHeight = 0;
323         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
324         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
325         buttonComposite.setLayout(layout);
326
327         Button selectAll = new Button(buttonComposite, SWT.PUSH);
328         selectAll.setText(MarkerMessages.selectAllAction_title);
329         selectAll.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
330
331         selectAll.addSelectionListener(new SelectionAdapter() {
332             /*
333              * (non-Javadoc)
334              *
335              * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
336              */

337             public void widgetSelected(SelectionEvent arg0) {
338                 markersTable.setAllChecked(true);
339                 setComplete(!resolutionsList.getSelection().isEmpty());
340             }
341         });
342
343         Button deselectAll = new Button(buttonComposite, SWT.PUSH);
344         deselectAll.setText(MarkerMessages.filtersDialog_deselectAll);
345         deselectAll
346                 .setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
347
348         deselectAll.addSelectionListener(new SelectionAdapter() {
349             /*
350              * (non-Javadoc)
351              *
352              * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
353              */

354             public void widgetSelected(SelectionEvent arg0) {
355                 markersTable.setAllChecked(false);
356                 setComplete(false);
357             }
358         });
359
360         addMatching = new Button(buttonComposite, SWT.PUSH);
361         addMatching.setText(MarkerMessages.MarkerResolutionDialog_AddOthers);
362         addMatching
363                 .setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
364         addMatching.setEnabled(true);
365         addMatching.addSelectionListener(new SelectionAdapter() {
366             /*
367              * (non-Javadoc)
368              *
369              * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
370              */

371             public void widgetSelected(SelectionEvent arg0) {
372
373                 WorkbenchMarkerResolution selected = getSelectedWorkbenchResolution();
374                 if (selected == null) {
375                     return;
376                 }
377
378                 if (addMatchingMarkers(selected)) {
379                     addMatching.setEnabled(false);
380                 }
381             }
382         });
383
384         return buttonComposite;
385     }
386
387     /**
388      * Return the single selected WorkbenchMarkerResolution if there is one.
389      *
390      * @return WorkbenchMarkerResolution or <code>null</code> if there is no
391      * selection or the selection is not a WorkbenchMarkerResolution.
392      */

393     private WorkbenchMarkerResolution getSelectedWorkbenchResolution() {
394         Object JavaDoc selection = getSelectedResolution();
395         if (selection == null
396                 || !(selection instanceof WorkbenchMarkerResolution)) {
397             return null;
398         }
399         return (WorkbenchMarkerResolution) selection;
400
401     }
402
403     /**
404      * Return the marker resolution that is currenly selected/
405      *
406      * @return IMarkerResolution or <code>null</code> if there is no
407      * selection.
408      */

409     private IMarkerResolution getSelectedResolution() {
410         ISelection selection = resolutionsList.getSelection();
411         if (!(selection instanceof IStructuredSelection)) {
412             return null;
413         }
414
415         Object JavaDoc first = ((IStructuredSelection) selection).getFirstElement();
416
417         return (IMarkerResolution) first;
418
419     }
420
421     /**
422      * Add all of the markers that have resolutions compatible with the
423      * receiver.
424      *
425      * @return boolean <code>true</code> if the operation completed.
426      */

427     protected boolean addMatchingMarkers(
428             final WorkbenchMarkerResolution resolution) {
429
430         calculatingResolutions = true;
431         progressPart.beginTask(
432                 MarkerMessages.MarkerResolutionDialog_CalculatingTask, 100);
433
434         progressPart.worked(10);
435         if (progressCancelled()) {
436             calculatingResolutions = false;
437             return false;
438         }
439
440         progressPart.subTask(NLS.bind(
441                 MarkerMessages.MarkerResolutionDialog_WorkingSubTask,
442                 resolution.getLabel()));
443
444         BusyIndicator.showWhile(getShell().getDisplay(), new Runnable JavaDoc() {
445             /*
446              * (non-Javadoc)
447              *
448              * @see java.lang.Runnable#run()
449              */

450             public void run() {
451                 IMarker[] others = resolution.findOtherMarkers(markerView
452                         .getCurrentMarkers().getIMarkers());
453
454                 Collection JavaDoc currentMarkers = new ArrayList JavaDoc();
455                 currentMarkers.add(originalMarker);
456
457                 for (int i = 0; i < others.length; i++) {
458                     currentMarkers.add(others[i]);
459                 }
460
461                 markerMap.put(resolution, currentMarkers);
462
463                 progressPart.worked(90);
464                 progressPart.done();
465                 progressCancelled = false;
466                 calculatingResolutions = false;
467                 markersTable.refresh();
468
469             }
470         });
471
472         return true;
473     }
474
475     /**
476      * Spin the event loop and see if the cancel button was pressed. If it was
477      * then clear the flags and return <code>true</code>.
478      *
479      * @return boolean
480      */

481     private boolean progressCancelled() {
482         getShell().getDisplay().readAndDispatch();
483         if (progressCancelled) {
484             progressCancelled = false;
485             calculatingResolutions = false;
486             progressPart.done();
487             return true;
488         }
489         return false;
490     }
491
492     /**
493      * Create the table for the markers/
494      *
495      * @param control
496      */

497     private void createMarkerTable(Composite control) {
498         markersTable = CheckboxTableViewer.newCheckList(control, SWT.BORDER
499                 | SWT.V_SCROLL);
500
501         createTableColumns();
502
503         markersTable.setContentProvider(new IStructuredContentProvider() {
504             /*
505              * (non-Javadoc)
506              *
507              * @see org.eclipse.jface.viewers.IContentProvider#dispose()
508              */

509             public void dispose() {
510
511             }
512
513             /*
514              * (non-Javadoc)
515              *
516              * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
517              */

518             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
519                 IMarkerResolution selected = getSelectedResolution();
520                 if (selected == null) {
521                     return new Object JavaDoc[0];
522                 }
523
524                 if (markerMap.containsKey(selected)) {
525                     return ((Collection JavaDoc) markerMap.get(selected)).toArray();
526                 }
527                 return new IMarker[] { originalMarker };
528             }
529
530             /*
531              * (non-Javadoc)
532              *
533              * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
534              * java.lang.Object, java.lang.Object)
535              */

536             public void inputChanged(Viewer viewer, Object JavaDoc oldInput,
537                     Object JavaDoc newInput) {
538
539             }
540         });
541
542         markersTable.setLabelProvider(new ITableLabelProvider() {
543
544             /*
545              * (non-Javadoc)
546              *
547              * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object,
548              * int)
549              */

550             public Image getColumnImage(Object JavaDoc element, int columnIndex) {
551                 if (columnIndex == 0)
552                     return Util.getImage(((IMarker) element).getAttribute(
553                             IMarker.SEVERITY, -1));
554                 return null;
555             }
556
557             /*
558              * (non-Javadoc)
559              *
560              * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
561              * int)
562              */

563             public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
564                 if (columnIndex == 0)
565                     return Util.getResourceName((IMarker) element);
566                 int line = ((IMarker) element).getAttribute(
567                         IMarker.LINE_NUMBER, -1);
568                 if (line < 0) {
569                     return MarkerMessages.Unknown;
570                 }
571                 return NLS.bind(MarkerMessages.label_lineNumber, Integer
572                         .toString(line));
573             }
574
575             /*
576              * (non-Javadoc)
577              *
578              * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
579              */

580             public void addListener(ILabelProviderListener listener) {
581                 // do nothing
582

583             }
584
585             /*
586              * (non-Javadoc)
587              *
588              * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
589              */

590             public void dispose() {
591                 // do nothing
592

593             }
594
595             /*
596              * (non-Javadoc)
597              *
598              * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
599              * java.lang.String)
600              */

601             public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
602                 return false;
603             }
604
605             /*
606              * (non-Javadoc)
607              *
608              * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
609              */

610             public void removeListener(ILabelProviderListener listener) {
611                 // do nothing
612

613             }
614         });
615
616         markersTable.addCheckStateListener(new ICheckStateListener() {
617             /*
618              * (non-Javadoc)
619              *
620              * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
621              */

622             public void checkStateChanged(CheckStateChangedEvent event) {
623                 if (event.getChecked() == true) {
624                     setComplete(true);
625                 } else {
626                     setComplete(markersTable.getCheckedElements().length > 0);
627                 }
628
629             }
630         });
631
632         markersTable.setInput(this);
633         markersTable.setAllChecked(true);
634     }
635
636     /**
637      * Create the table columns for the receiver.
638      */

639     private void createTableColumns() {
640         TableLayout layout = new TableLayout();
641
642         Table table = markersTable.getTable();
643         table.setLayout(layout);
644         table.setLinesVisible(true);
645         table.setHeaderVisible(true);
646
647         layout.addColumnData(new ColumnWeightData(70, true));
648         TableColumn tc = new TableColumn(table, SWT.NONE, 0);
649         tc
650                 .setText(MarkerMessages.MarkerResolutionDialog_Problems_List_Location);
651         layout.addColumnData(new ColumnWeightData(30, true));
652         tc = new TableColumn(table, SWT.NONE, 0);
653         tc
654                 .setText(MarkerMessages.MarkerResolutionDialog_Problems_List_Resource);
655
656     }
657
658     /**
659      * Set the dialog to be complete.
660      *
661      * @param complete
662      */

663     protected void setComplete(boolean complete) {
664         getButton(IDialogConstants.OK_ID).setEnabled(complete);
665
666     }
667
668     /**
669      * Return all of the resolutions to choose from in the receiver.
670      *
671      * @return IMarkerResolution[]
672      */

673     public IMarkerResolution[] getResolutions() {
674         return resolutions;
675     }
676
677     /*
678      * (non-Javadoc)
679      *
680      * @see org.eclipse.jface.dialogs.Dialog#create()
681      */

682     public void create() {
683         super.create();
684         setTitle(MarkerMessages.MarkerResolutionDialog_Title);
685         resolutionsList.getList().select(0);
686         markersTable.refresh();
687         markersTable.setAllChecked(true);
688         setComplete(true);
689     }
690
691     /*
692      * (non-Javadoc)
693      *
694      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
695      */

696     protected void okPressed() {
697         IMarkerResolution resolution = getSelectedResolution();
698         if (resolution == null) {
699             return;
700         }
701
702         Object JavaDoc[] checked = markersTable.getCheckedElements();
703
704         progressPart.beginTask(MarkerMessages.MarkerResolutionDialog_Fixing,
705                 checked.length + 1);
706         progressPart.worked(1);
707
708         calculatingResolutions = true;
709
710         if (resolution instanceof WorkbenchMarkerResolution) {
711
712             IMarker[] markers = new IMarker[checked.length];
713             System.arraycopy(checked, 0, markers, 0, checked.length);
714             ((WorkbenchMarkerResolution) resolution).run(markers,
715                     new SubProgressMonitor(progressPart, checked.length));
716         } else {
717
718             // Allow paint events and wake up the button
719
getShell().getDisplay().readAndDispatch();
720             if (!progressCancelled() && checked.length == 1) {
721
722                 // There will only be one
723
IMarker marker = (IMarker) checked[0];
724
725                 progressPart.subTask(Util.getProperty(IMarker.MESSAGE, marker));
726                 resolution.run(marker);
727                 progressPart.worked(1);
728             }
729
730         }
731
732         calculatingResolutions = false;
733         progressPart.done();
734         progressCancelled = false;
735         super.okPressed();
736     }
737
738     /*
739      * (non-Javadoc)
740      *
741      * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
742      */

743     protected void cancelPressed() {
744         if (calculatingResolutions) {
745             progressCancelled = true;
746             progressPart.setCanceled(true);
747             return;
748         }
749         super.cancelPressed();
750     }
751
752 }
753
Popular Tags