Search in sources :

Example 1 with IMarkerResolution

use of org.eclipse.ui.IMarkerResolution in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    List<IMarker> markers;
    try {
        markers = getMarkersFor(invocationContext.getSourceViewer(), invocationContext.getOffset());
    } catch (BadLocationException e) {
        errorMessage = e.getMessage();
        return new ICompletionProposal[0];
    }
    List<ICompletionProposal> result = Lists.newArrayList();
    for (IMarker marker : markers) {
        for (IMarkerResolution markerResolution : quickFixer.getResolutions(marker)) {
            result.add(new MarkerResolutionProposal(marker, markerResolution, invocationContext.getSourceViewer()));
        }
    }
    return result.toArray(new ICompletionProposal[0]);
}
Also used : IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IMarker(org.eclipse.core.resources.IMarker) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with IMarkerResolution

use of org.eclipse.ui.IMarkerResolution in project bndtools by bndtools.

the class MissingWorkspaceMarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    return new IMarkerResolution[] { new IMarkerResolution() {

        @Override
        public void run(IMarker marker) {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
            wizard.init(workbench, StructuredSelection.EMPTY);
            WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
            dialog.open();
        }

        @Override
        public String getLabel() {
            return "Open 'New Bnd OSGi Workspace' Wizard";
        }
    } };
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IMarkerResolution(org.eclipse.ui.IMarkerResolution) IMarker(org.eclipse.core.resources.IMarker) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with IMarkerResolution

use of org.eclipse.ui.IMarkerResolution in project bndtools by bndtools.

the class ProjectBuildPage method generateFixes.

// look for available quick-fixes from the bnd build error details
private void generateFixes(String message, final IMarker marker) {
    boolean fixable = marker.getAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, false);
    if (!fixable)
        return;
    ITextEditor sourcePage = editor.getSourcePage();
    if (sourcePage == null)
        return;
    String type = marker.getAttribute("$bndType", (String) null);
    if (type == null)
        return;
    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
    if (handler == null)
        return;
    List<IAction> fixes = new LinkedList<>();
    List<ICompletionProposal> proposals = handler.getProposals(marker);
    if (proposals != null) {
        for (ICompletionProposal proposal : proposals) {
            fixes.add(new ApplyCompletionProposalAction(proposal, editor.getSourcePage(), editor, BndEditor.SOURCE_PAGE));
        }
    }
    // If no source completion fixes were found, add the marker resolution actions.
    if (fixes.isEmpty()) {
        List<IMarkerResolution> resolutions = handler.getResolutions(marker);
        for (final IMarkerResolution resolution : resolutions) {
            Action action = new Action(resolution.getLabel()) {

                @Override
                public void run() {
                    resolution.run(marker);
                }
            };
            fixes.add(action);
        }
    }
    messageFixesMap.put(message, fixes.toArray(new IAction[0]));
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAction(org.eclipse.jface.action.IAction) LinkedList(java.util.LinkedList) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 4 with IMarkerResolution

use of org.eclipse.ui.IMarkerResolution in project bndtools by bndtools.

the class BndtoolsMarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    String type = marker.getAttribute("$bndType", (String) null);
    if (type == null)
        return new IMarkerResolution[0];
    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
    if (handler == null)
        return new IMarkerResolution[0];
    List<IMarkerResolution> resolutions = handler.getResolutions(marker);
    return resolutions != null ? resolutions.toArray(new IMarkerResolution[0]) : new IMarkerResolution[0];
}
Also used : BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IMarkerResolution(org.eclipse.ui.IMarkerResolution)

Example 5 with IMarkerResolution

use of org.eclipse.ui.IMarkerResolution in project bndtools by bndtools.

the class BaselineErrorHandler method getResolutions.

@Override
public List<IMarkerResolution> getResolutions(IMarker marker) {
    List<IMarkerResolution> result = new LinkedList<IMarkerResolution>();
    final String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    if (suggestedVersion != null) {
        result.add(new IMarkerResolution() {

            @Override
            public void run(IMarker marker) {
                final IFile file = (IFile) marker.getResource();
                final IWorkspace workspace = file.getWorkspace();
                try {
                    workspace.run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            String input = "version " + suggestedVersion;
                            ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
                            file.setContents(stream, false, true, monitor);
                        }
                    }, null);
                } catch (CoreException e) {
                    logger.logError("Error applying baseline version quickfix.", e);
                }
            }

            @Override
            public String getLabel() {
                return "Change package version to " + suggestedVersion;
            }
        });
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) IMarker(org.eclipse.core.resources.IMarker) LinkedList(java.util.LinkedList)

Aggregations

IMarkerResolution (org.eclipse.ui.IMarkerResolution)5 IMarker (org.eclipse.core.resources.IMarker)3 LinkedList (java.util.LinkedList)2 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1