1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

- simplified API for problem details extensions

This commit is contained in:
Alena Laskavaia 2010-04-29 16:34:18 +00:00
parent 4fd94ed31f
commit 8ece4ead1a
6 changed files with 134 additions and 137 deletions

View file

@ -1,7 +1,5 @@
package org.eclipse.cdt.codan.examples.uicontrib; package org.eclipse.cdt.codan.examples.uicontrib;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -28,12 +26,11 @@ public class FlexlintHelpLink extends AbstractCodanProblemDetailsProvider {
} }
@Override @Override
public URL getHelpURL() { public String getStyledProblemDescription() {
String helpId = parseHelpId(getProblemMessage()); String helpId = parseHelpId(getProblemMessage());
try { String url = "http://www.gimpel-online.com/MsgRef.html#" + helpId;
return new URL("http://www.gimpel-online.com/MsgRef.html#" + helpId); //$NON-NLS-1$ return "<a href=\"" + url + "\">" + url + "</a>";
} catch (MalformedURLException e) {
return null;
}
} }
} }

View file

@ -91,4 +91,14 @@
</key> </key>
</extension> </extension>
--> -->
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.cdt.ui.CPerspective">
<showInPart id="org.eclipse.cdt.codan.internal.ui.views.ProblemDetails"/>
<viewShortcut id="org.eclipse.cdt.codan.internal.ui.views.ProblemDetails"/>
</perspectiveExtension>
</extension>
</plugin> </plugin>

View file

@ -94,7 +94,13 @@ If ommitted provider would be called for all problem kinds.
<meta.section type="examples"/> <meta.section type="examples"/>
</appinfo> </appinfo>
<documentation> <documentation>
[Enter extension point usage example here.] &lt;extension
point=&quot;org.eclipse.cdt.codan.ui.codanProblemDetails&quot;&gt;
&lt;problemDetails
class=&quot;org.eclipse.cdt.codan.examples.uicontrib.FlexlintHelpLink&quot;
&gt;
&lt;/problemDetails&gt;
&lt;/extension&gt;
</documentation> </documentation>
</annotation> </annotation>
@ -112,7 +118,8 @@ If ommitted provider would be called for all problem kinds.
<meta.section type="implementation"/> <meta.section type="implementation"/>
</appinfo> </appinfo>
<documentation> <documentation>
[Enter information about supplied implementation of this extension point.] See
org.eclipse.cdt.codan.examples.uicontrib.FlexlintHelpLink
</documentation> </documentation>
</annotation> </annotation>

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* $QNXLicenseC:
* Copyright 2008, QNX Software Systems. All Rights Reserved.
*
* You must obtain a written license from and pay applicable license fees to QNX
* Software Systems before you may reproduce, modify or distribute this software,
* or any work that includes all or part of this software. Free development
* licenses are available for evaluation and non-commercial purposes. For more
* information visit http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others. Please review this entire
* file for other proprietary rights or license notices, as well as the QNX
* Development Suite License Guide at http://licensing.qnx.com/license-guide/
* for other information.
* $
*******************************************************************************/
/*
* Created by: Elena Laskavaia
* Created on: 2010-04-29
* Last modified by: $Author$
*/
package org.eclipse.cdt.codan.internal.ui.views;
import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
/**
* This provides details for errors that do not have own details provider
*/
public class GenericCodanProblemDetailsProvider extends AbstractCodanProblemDetailsProvider {
@Override
public boolean isApplicable(String id) {
return true;
}
}

View file

@ -1,18 +1,10 @@
package org.eclipse.cdt.codan.internal.ui.views; package org.eclipse.cdt.codan.internal.ui.views;
import java.net.URL;
import java.util.Collection; import java.util.Collection;
import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider; import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -21,29 +13,31 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService; import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.ViewPart;
/**
* Problems Details view show details for selected problem marker.
* Other plugins can contribute to override default behavior using codanProblemDetails extension point.
*/
public class ProblemDetails extends ViewPart { public class ProblemDetails extends ViewPart {
/** /**
* The ID of the view as specified by the extension. * The ID of the view as specified by the extension.
*/ */
public static final String ID = "org.eclipse.cdt.codan.internal.ui.views.ProblemDetails"; public static final String ID = "org.eclipse.cdt.codan.internal.ui.views.ProblemDetails";
private Composite area; private Composite area;
private Action action1; /**
* Control for problem message, which can include location
private Label description; */
private Label location; private Link message;
private Link helpLabel; /**
* Control for problem description which can include links to help or web-sites with extra info
*/
private Link description;
private GenericCodanProblemDetailsProvider genProvider = new GenericCodanProblemDetailsProvider();
/** /**
* The constructor. * The constructor.
@ -56,37 +50,43 @@ public class ProblemDetails extends ViewPart {
* to create the area and initialize it. * to create the area and initialize it.
*/ */
public void createPartControl(Composite parent) { public void createPartControl(Composite parent) {
final String processViewId = "org.eclipse.ui.views.ProblemView"; final String problemsViewId = "org.eclipse.ui.views.ProblemView";
area = new Composite(parent, SWT.NONE); area = new Composite(parent, SWT.NONE);
area.setLayout(new GridLayout()); area.setLayout(new GridLayout());
description = new Label(area, SWT.WRAP); SelectionAdapter linkSelAdapter = new SelectionAdapter() {
description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
location = new Label(area, SWT.WRAP);
helpLabel = new Link(area, SWT.WRAP);
helpLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
helpLabel.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
String link = e.text; String link = e.text;
if (link != null && link.startsWith("http")) { if (link==null) return;
if (link.startsWith("http")) {
org.eclipse.swt.program.Program.launch(e.text); org.eclipse.swt.program.Program.launch(e.text);
return;
}
if (link.startsWith("file:")) {
// open in eclipse editor TODO
return;
}
if (link.startsWith("help:")) {
// open in eclipse help TODO
return;
} }
} }
}); };
// Create the help context id for the area's control message = new Link(area, SWT.WRAP);
//PlatformUI.getWorkbench().getHelpSystem().setHelp(area, "org.eclipse.cdt.codan.ui.viewer"); message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
makeActions(); message.addSelectionListener(linkSelAdapter);
hookContextMenu(); description = new Link(area, SWT.WRAP);
contributeToActionBars(); description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
description.addSelectionListener(linkSelAdapter);
ISelectionService ser = (ISelectionService) getSite().getService(ISelectionService.class); ISelectionService ser = (ISelectionService) getSite().getService(ISelectionService.class);
ser.addSelectionListener(new ISelectionListener() { ser.addSelectionListener(new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) { public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part.getSite().getId().equals(processViewId)) { if (part.getSite().getId().equals(problemsViewId)) {
processSelection(selection); processSelection(selection);
} }
} }
}); });
ISelection selection = ser.getSelection(processViewId); ISelection selection = ser.getSelection(problemsViewId);
processSelection(selection); processSelection(selection);
} }
@ -102,11 +102,6 @@ public class ProblemDetails extends ViewPart {
marker = (IMarker) firstElement; marker = (IMarker) firstElement;
} }
if (marker != null) { if (marker != null) {
String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
description.setText(message);
String loc = marker.getResource().getFullPath().toOSString(); //$NON-NLS-1$
int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
location.setText(loc + ":" + line); //$NON-NLS-1$
queryProviders(marker); queryProviders(marker);
area.layout(); area.layout();
} }
@ -114,7 +109,6 @@ public class ProblemDetails extends ViewPart {
} }
private void queryProviders(IMarker marker) { private void queryProviders(IMarker marker) {
cleanProversControl();
String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$ String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$
Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions.getProviders(id); Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions.getProviders(id);
for (AbstractCodanProblemDetailsProvider provider : providers) { for (AbstractCodanProblemDetailsProvider provider : providers) {
@ -122,76 +116,26 @@ public class ProblemDetails extends ViewPart {
provider.setMarker(marker); provider.setMarker(marker);
if (provider.isApplicable(id)) { if (provider.isApplicable(id)) {
applyProvider(provider); applyProvider(provider);
break; return;
} }
} }
} }
} genProvider.setMarker(marker);
applyProvider(genProvider);
public void cleanProversControl() {
helpLabel.setText("");
} }
private void applyProvider(AbstractCodanProblemDetailsProvider provider) { private void applyProvider(AbstractCodanProblemDetailsProvider provider) {
String label = provider.getHelpLabel(); setTextSafe(message, provider, provider.getStyledProblemMessage());
final URL url = provider.getHelpURL(); setTextSafe(description, provider, provider.getStyledProblemDescription());
if (label != null) {
helpLabel.setText(label);
}
if (url != null) {
if (label == null) {
label = url.toString();
}
helpLabel.setText("<a href=\"" + url + "\">" + label + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
} }
private void hookContextMenu() { protected void setTextSafe(Link control, AbstractCodanProblemDetailsProvider provider, String text) {
MenuManager menuMgr = new MenuManager("#PopupMenu"); try {
menuMgr.setRemoveAllWhenShown(true); control.setText(text);
menuMgr.addMenuListener(new IMenuListener() { } catch (Exception e) {
public void menuAboutToShow(IMenuManager manager) { // this is more debug message
ProblemDetails.this.fillContextMenu(manager); control.setText("failed to set text: " + provider.getClass() + " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
} }
});
Menu menu = menuMgr.createContextMenu(area);
area.setMenu(menu);
//getSite().registerContextMenu(menuMgr, area);
}
private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();
fillLocalPullDown(bars.getMenuManager());
fillLocalToolBar(bars.getToolBarManager());
}
private void fillLocalPullDown(IMenuManager manager) {
}
private void fillContextMenu(IMenuManager manager) {
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private void fillLocalToolBar(IToolBarManager manager) {
}
private void makeActions() {
action1 = new Action() {
public void run() {
showMessage("Action 1 executed");
}
};
action1.setText("Action 1");
action1.setToolTipText("Action 1 tooltip");
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
}
private void showMessage(String message) {
MessageDialog.openInformation(area.getShell(), "Problem Details", message);
} }
/** /**

View file

@ -17,12 +17,12 @@
/* /*
* Created by: Elena Laskavaia * Created by: Elena Laskavaia
* Created on: 2010-04-28 * Created on: 2010-04-28
* Last modified by: $Author$ * Last modified by: $Author: elaskavaia $
*/ */
package org.eclipse.cdt.codan.ui; package org.eclipse.cdt.codan.ui;
import java.net.URL; import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
/** /**
@ -49,7 +49,10 @@ public abstract class AbstractCodanProblemDetailsProvider {
String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
return message; return message;
} }
protected String getProblemId(){
String id = marker.getAttribute(IMarker.PROBLEM, (String)null); //$NON-NLS-1$
return id;
}
/** /**
* return true if provider can provide details for given marker (previously set by setMarker) * return true if provider can provide details for given marker (previously set by setMarker)
* @param id - id of the problem * @param id - id of the problem
@ -58,26 +61,26 @@ public abstract class AbstractCodanProblemDetailsProvider {
public abstract boolean isApplicable(String id); public abstract boolean isApplicable(String id);
/** /**
* URL to external help for the problem, would be displayed as label, and as action * Return styled problem message. String can include <a> tags to which would be
* will go to given URL is not null. If label is null (getHelpLabel) URL would be used as label. * visible as hyperlinks and newline characters (\n). Default message if
* marker message plus location.
*/ */
public URL getHelpURL() { public String getStyledProblemMessage(){
return null; String message = getProblemMessage();
String loc = marker.getResource().getFullPath().toOSString();
int line = marker.getAttribute(IMarker.LINE_NUMBER, 0);
return message + "\n"+loc+":"+line; //$NON-NLS-1$//$NON-NLS-2$
} }
/** /**
* Label text to use to navigate to a help. Would be shown as hyperlink. If helpURL is not * Return styled problem description. String can include <a> tags to which would be
* null would open a browser with given URL. * visible as hyperlinks and newline characters (\n)
*/ */
public String getHelpLabel() { public String getStyledProblemDescription(){
return null; String id = getProblemId();
if (id==null) return ""; //$NON-NLS-1$
IProblem problem = CodanRuntime.getInstance().getChechersRegistry().getDefaultProfile().findProblem(id);
return problem.getDescription();
} }
/**
* Return help context id. Only one getHelpURL or getHelpContextId can be used.
* In case if help context id is not null hyperlink would open context help page.
*/
public String getHelpContextId() {
return null;
}
} }