001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.provisional.views.markers;
011:
012: import java.lang.reflect.InvocationTargetException;
013: import java.util.Iterator;
014: import java.util.Map;
015:
016: import org.eclipse.core.resources.IMarker;
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.core.runtime.IStatus;
019: import org.eclipse.core.runtime.SubProgressMonitor;
020: import org.eclipse.jface.operation.IRunnableWithProgress;
021: import org.eclipse.jface.wizard.IWizardPage;
022: import org.eclipse.jface.wizard.Wizard;
023: import org.eclipse.ui.IMarkerResolution;
024: import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
025: import org.eclipse.ui.internal.ide.StatusUtil;
026: import org.eclipse.ui.statushandlers.StatusManager;
027: import org.eclipse.ui.views.markers.internal.MarkerMessages;
028:
029: /**
030: * QuickFixWizard is the wizard for quick fixes.
031: *
032: * @since 3.4
033: *
034: */
035: class QuickFixWizard extends Wizard {
036:
037: private Map resolutionMap;
038:
039: /**
040: * Create the wizard with the map of resolutions.
041: *
042: * @param resolutions
043: * Map key {@link IMarker} value {@link IMarkerResolution} []
044: * @param page
045: * The page to display the problem in.
046: */
047: public QuickFixWizard(Map resolutions) {
048: super ();
049: this .resolutionMap = resolutions;
050: setDefaultPageImageDescriptor(IDEInternalWorkbenchImages
051: .getImageDescriptor(IDEInternalWorkbenchImages.IMG_DLGBAN_QUICKFIX_DLG));
052: setNeedsProgressMonitor(true);
053:
054: }
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see org.eclipse.jface.wizard.Wizard#addPages()
060: */
061: public void addPages() {
062: super .addPages();
063: Iterator markers = resolutionMap.keySet().iterator();
064: while (markers.hasNext()) {
065: IMarker next = (IMarker) markers.next();
066: IMarkerResolution[] resolutions = (IMarkerResolution[]) resolutionMap
067: .get(next);
068: addPage(new QuickFixPage(next, resolutions));
069: }
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see org.eclipse.jface.wizard.Wizard#performFinish()
076: */
077: public boolean performFinish() {
078: IRunnableWithProgress finishRunnable = new IRunnableWithProgress() {
079: /*
080: * (non-Javadoc)
081: *
082: * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
083: */
084: public void run(IProgressMonitor monitor) {
085: IWizardPage[] pages = getPages();
086: monitor.beginTask(
087: MarkerMessages.MarkerResolutionDialog_Fixing,
088: (10 * pages.length) + 1);
089: monitor.worked(1);
090: for (int i = 0; i < pages.length; i++) {
091: //Allow for cancel event processing
092: getShell().getDisplay().readAndDispatch();
093: if (monitor.isCanceled())
094: return;
095: QuickFixPage wizardPage = (QuickFixPage) pages[i];
096: wizardPage.performFinish(new SubProgressMonitor(
097: monitor, 10));
098: monitor.worked(1);
099: }
100: monitor.done();
101:
102: }
103: };
104:
105: try {
106: getContainer().run(false, true, finishRunnable);
107: } catch (InvocationTargetException e) {
108: StatusManager.getManager().handle(
109: StatusUtil.newStatus(IStatus.ERROR, e
110: .getLocalizedMessage(), e));
111: return false;
112: } catch (InterruptedException e) {
113: StatusManager.getManager().handle(
114: StatusUtil.newStatus(IStatus.ERROR, e
115: .getLocalizedMessage(), e));
116: return false;
117: }
118:
119: return true;
120: }
121:
122: }
|