Commit b293fac9 authored by Snejana Bisa's avatar Snejana Bisa Committed by Balazs Grill
Browse files

Bug 572591 - Make MarkerResolutionDialog extensible



Enabled providing a custom MarkerResolutionDialog implementation,
exposed several method in MarkerResolutionDialog

Change-Id: Ib199feb441176191a75919f84bc2398f30f21561
Signed-off-by: default avatarSnejana Bisa <snejana_b@yahoo.com>
parent 62d552b0
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
 *               org.eclipse.ui.views.markers.internal for that purpose because
 *               many of the relevant classes, methods, and fields are private or
 *               package private.
 *		Elektrobit - [572591]  Make MarkerResolutionDialog extensible
 *******************************************************************************/
package org.eclipse.sphinx.emf.validation.ui.views;

@@ -100,12 +101,28 @@ public class ActionResolveMarker extends MarkerSelectionProviderAction {
			MessageDialog.openInformation(view.getSite().getShell(), MarkerMessages.MarkerResolutionDialog_CannotFixTitle,
					NLS.bind(MarkerMessages.MarkerResolutionDialog_CannotFixMessage, getMarkerDescription()));
		} else {
			Dialog dialog = new MarkerResolutionDialog(view.getSite().getShell(), getSelectedMarker(), foundResolutions, view);
			Dialog dialog = createMarkerResolutionDialog(foundResolutions, getSelectedMarker());
			dialog.open();
		}

	}

	/**
	 * @param resolutions
	 * @param selectedMarker
	 * @return the marker resolution dialog
	 */
	protected Dialog createMarkerResolutionDialog(IMarkerResolution[] resolutions, IMarker selectedMarker) {
		return new MarkerResolutionDialog(view.getSite().getShell(), selectedMarker, resolutions, view);
	}

	/**
	 * @return the marker view
	 */
	protected MarkerView getMarkerView() {
		return view;
	}

	/**
	 * Handle the exception.
	 * 
+52 −29
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 *               many of the relevant classes, methods, and fields are private or
 *               package private.
 *     Elektrobit - [345672]  MarkerResolutionDialog should display images associated with resolutions
 *     Elektrobit - [572591]  Make MarkerResolutionDialog extensible
 ******************************************************************************************************/
package org.eclipse.sphinx.emf.validation.ui.views;

@@ -21,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -31,6 +33,7 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelection;
@@ -67,7 +70,6 @@ import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;

/**
 * The MarkerResolutionDialog is the dialog used to select a marker resolution.
 * 
@@ -95,7 +97,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {

	private Button addMatching;

	private Hashtable markerMap = new Hashtable(0);
	private Map<WorkbenchMarkerResolution, Collection<IMarker>> markerMap = new Hashtable<WorkbenchMarkerResolution, Collection<IMarker>>(0);

	/**
	 * Create a new instance of the receiver with the given resolutions.
@@ -184,17 +186,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
			}
		});

		resolutionsList.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				return ((IMarkerResolution) element).getLabel();
			}

			@Override
			public Image getImage(Object element) {
				return element instanceof IMarkerResolution2 ? ((IMarkerResolution2) element).getImage() : null;
			}
		});
		resolutionsList.setLabelProvider(createResolutionsListLabelProvider());

		resolutionsList.addSelectionChangedListener(new ISelectionChangedListener() {
			/*
@@ -205,13 +197,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {

				WorkbenchMarkerResolution resolution = getSelectedWorkbenchResolution();
				if (resolution == null || markerMap.containsKey(resolution)) {
					addMatching.setEnabled(false);
				} else {
					addMatching.setEnabled(true);
				}
				markersTable.refresh();
				handleResolutionSelectionChanged(event);
			}
		});

@@ -277,6 +263,36 @@ public class MarkerResolutionDialog extends TitleAreaDialog {

	}

	/**
	 * @param event
	 */
	protected void handleResolutionSelectionChanged(SelectionChangedEvent event) {
		WorkbenchMarkerResolution resolution = getSelectedWorkbenchResolution();
		if (resolution == null || markerMap.containsKey(resolution)) {
			addMatching.setEnabled(false);
		} else {
			addMatching.setEnabled(true);
		}
		markersTable.refresh();
	}

	/**
	 * @return {@link IBaseLabelProvider}
	 */
	protected IBaseLabelProvider createResolutionsListLabelProvider() {
		return new LabelProvider() {
			@Override
			public String getText(Object element) {
				return ((IMarkerResolution) element).getLabel();
			}

			@Override
			public Image getImage(Object element) {
				return element instanceof IMarkerResolution2 ? ((IMarkerResolution2) element).getImage() : null;
			}
		};
	}

	/**
	 * Choose a good whitespace position for a page break. Start in the middle of the message.
	 * 
@@ -390,7 +406,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
	 * @return WorkbenchMarkerResolution or <code>null</code> if there is no selection or the selection is not a
	 *         WorkbenchMarkerResolution.
	 */
	private WorkbenchMarkerResolution getSelectedWorkbenchResolution() {
	protected WorkbenchMarkerResolution getSelectedWorkbenchResolution() {
		Object selection = getSelectedResolution();
		if (selection == null || !(selection instanceof WorkbenchMarkerResolution)) {
			return null;
@@ -404,7 +420,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
	 * 
	 * @return IMarkerResolution or <code>null</code> if there is no selection.
	 */
	private IMarkerResolution getSelectedResolution() {
	protected IMarkerResolution getSelectedResolution() {
		ISelection selection = resolutionsList.getSelection();
		if (!(selection instanceof IStructuredSelection)) {
			return null;
@@ -416,6 +432,13 @@ public class MarkerResolutionDialog extends TitleAreaDialog {

	}

	/**
	 * @return the original marker displayed in the dialog
	 */
	protected IMarker getOriginalMarker() {
		return originalMarker;
	}

	/**
	 * Add all of the markers that have resolutions compatible with the receiver.
	 * 
@@ -443,10 +466,10 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
			public void run() {
				IMarker[] others = resolution.findOtherMarkers(markerView.getCurrentMarkers().getIMarkers());

				Collection currentMarkers = new ArrayList();
				Collection<IMarker> currentMarkers = new ArrayList<IMarker>();
				currentMarkers.add(originalMarker);

				Collection done = new HashSet(currentMarkers);
				Collection<IMarker> done = new HashSet<IMarker>(currentMarkers);
				for (IMarker element : others) {
					if (done.add(element)) {
						currentMarkers.add(element);
@@ -516,7 +539,7 @@ public class MarkerResolutionDialog extends TitleAreaDialog {
				}

				if (markerMap.containsKey(selected)) {
					return ((Collection) markerMap.get(selected)).toArray();
					return markerMap.get(selected).toArray();
				}
				return new IMarker[] { originalMarker };
			}
+12 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
 *     See4sys - copied from org.eclipse.ui.views.markers.internal.ProblemView to
 *               add support for problem markers on model objects (rather than
 *               only on workspace resources)
 *	   Elektrobit - [572591]  Make MarkerResolutionDialog extensible
 *******************************************************************************/
package org.eclipse.sphinx.emf.validation.ui.views;

@@ -31,6 +32,7 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.ViewerComparator;
@@ -257,7 +259,16 @@ public class ValidationView extends MarkerView {
	protected void createActions() {
		super.createActions();
		propertiesAction = new ActionProblemProperties(this, getViewer());
		resolveMarkerAction = new ActionResolveMarker(this, getViewer());
		resolveMarkerAction = createActionResolveMarker(this, getViewer());
	}

	/**
	 * @param markerView
	 * @param provider
	 * @return the resolve marker action
	 */
	protected ActionResolveMarker createActionResolveMarker(MarkerView markerView, ISelectionProvider provider) {
		return new ActionResolveMarker(markerView, provider);
	}

	/*