Search in sources :

Example 1 with IMarkerResolution2

use of org.eclipse.ui.IMarkerResolution2 in project eclipse.platform.text by eclipse.

the class MarkerInformationControl method setInput.

@SuppressWarnings("unchecked")
@Override
public void setInput(Object input) {
    this.composites.values().forEach(Composite::dispose);
    this.markers = (List<IMarker>) input;
    for (IMarker marker : this.markers) {
        Composite markerComposite = new Composite(parent, SWT.NONE);
        this.composites.put(marker, markerComposite);
        GridLayout gridLayout = new GridLayout(1, false);
        gridLayout.verticalSpacing = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        markerComposite.setLayout(gridLayout);
        Composite markerLine = new Composite(markerComposite, SWT.NONE);
        RowLayout rowLayout = new RowLayout();
        rowLayout.marginTop = 0;
        rowLayout.marginBottom = 0;
        rowLayout.marginLeft = 0;
        rowLayout.marginRight = 0;
        markerLine.setLayout(rowLayout);
        IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(marker);
        if (resolutions.length > 0) {
            Label markerImage = new Label(markerLine, SWT.NONE);
            markerImage.setImage(getImage(marker));
        }
        Label markerLabel = new Label(markerLine, SWT.NONE);
        // $NON-NLS-1$
        markerLabel.setText(marker.getAttribute(IMarker.MESSAGE, "missing message"));
        for (IMarkerResolution resolution : resolutions) {
            Composite resolutionComposite = new Composite(markerComposite, SWT.NONE);
            GridData layoutData = new GridData();
            layoutData.horizontalIndent = 10;
            resolutionComposite.setLayoutData(layoutData);
            RowLayout resolutionRowLayout = new RowLayout();
            resolutionRowLayout.marginBottom = 0;
            resolutionComposite.setLayout(resolutionRowLayout);
            Label resolutionImage = new Label(resolutionComposite, SWT.NONE);
            // TODO: try to retrieve icon from QuickFix command
            Image resolutionPic = null;
            if (resolution instanceof IMarkerResolution2) {
                resolutionPic = ((IMarkerResolution2) resolution).getImage();
            }
            if (resolutionPic == null) {
                resolutionPic = PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OPEN_MARKER);
            }
            resolutionImage.setImage(resolutionPic);
            Link resolutionLink = new Link(resolutionComposite, SWT.NONE);
            // $NON-NLS-1$ //$NON-NLS-2$
            resolutionLink.setText("<A>" + resolution.getLabel() + "</a>");
            resolutionLink.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Job resolutionJob = new // $NON-NLS-1$
                    Job(// $NON-NLS-1$
                    "apply resolution - " + resolution.getLabel()) {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            resolution.run(marker);
                            return Status.OK_STATUS;
                        }
                    };
                    resolutionJob.setUser(true);
                    resolutionJob.setSystem(true);
                    resolutionJob.setPriority(Job.INTERACTIVE);
                    resolutionJob.schedule();
                    getShell().dispose();
                }
            });
        }
    }
    parent.layout(true);
}
Also used : IMarkerResolution2(org.eclipse.ui.IMarkerResolution2) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IMarkerResolution(org.eclipse.ui.IMarkerResolution) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMarker(org.eclipse.core.resources.IMarker) Job(org.eclipse.core.runtime.jobs.Job) Link(org.eclipse.swt.widgets.Link)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 IMarkerResolution (org.eclipse.ui.IMarkerResolution)1 IMarkerResolution2 (org.eclipse.ui.IMarkerResolution2)1