1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-14 20:45: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;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -28,12 +26,11 @@ public class FlexlintHelpLink extends AbstractCodanProblemDetailsProvider {
}
@Override
public URL getHelpURL() {
public String getStyledProblemDescription() {
String helpId = parseHelpId(getProblemMessage());
try {
return new URL("http://www.gimpel-online.com/MsgRef.html#" + helpId); //$NON-NLS-1$
} catch (MalformedURLException e) {
return null;
}
String url = "http://www.gimpel-online.com/MsgRef.html#" + helpId;
return "<a href=\"" + url + "\">" + url + "</a>";
}
}

View file

@ -91,4 +91,14 @@
</key>
</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>

View file

@ -94,7 +94,13 @@ If ommitted provider would be called for all problem kinds.
<meta.section type="examples"/>
</appinfo>
<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>
</annotation>
@ -112,7 +118,8 @@ If ommitted provider would be called for all problem kinds.
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
See
org.eclipse.cdt.codan.examples.uicontrib.FlexlintHelpLink
</documentation>
</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;
import java.net.URL;
import java.util.Collection;
import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
import org.eclipse.core.resources.IMarker;
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.IStructuredSelection;
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.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
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.ISelectionService;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
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 {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "org.eclipse.cdt.codan.internal.ui.views.ProblemDetails";
private Composite area;
private Action action1;
private Label description;
private Label location;
private Link helpLabel;
/**
* Control for problem message, which can include location
*/
private Link message;
/**
* 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.
@ -56,37 +50,43 @@ public class ProblemDetails extends ViewPart {
* to create the area and initialize it.
*/
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.setLayout(new GridLayout());
description = new Label(area, SWT.WRAP);
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() {
SelectionAdapter linkSelAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
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);
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
//PlatformUI.getWorkbench().getHelpSystem().setHelp(area, "org.eclipse.cdt.codan.ui.viewer");
makeActions();
hookContextMenu();
contributeToActionBars();
};
message = new Link(area, SWT.WRAP);
message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
message.addSelectionListener(linkSelAdapter);
description = new Link(area, SWT.WRAP);
description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
description.addSelectionListener(linkSelAdapter);
ISelectionService ser = (ISelectionService) getSite().getService(ISelectionService.class);
ser.addSelectionListener(new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part.getSite().getId().equals(processViewId)) {
if (part.getSite().getId().equals(problemsViewId)) {
processSelection(selection);
}
}
});
ISelection selection = ser.getSelection(processViewId);
ISelection selection = ser.getSelection(problemsViewId);
processSelection(selection);
}
@ -102,11 +102,6 @@ public class ProblemDetails extends ViewPart {
marker = (IMarker) firstElement;
}
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);
area.layout();
}
@ -114,7 +109,6 @@ public class ProblemDetails extends ViewPart {
}
private void queryProviders(IMarker marker) {
cleanProversControl();
String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$
Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions.getProviders(id);
for (AbstractCodanProblemDetailsProvider provider : providers) {
@ -122,76 +116,26 @@ public class ProblemDetails extends ViewPart {
provider.setMarker(marker);
if (provider.isApplicable(id)) {
applyProvider(provider);
break;
return;
}
}
}
}
public void cleanProversControl() {
helpLabel.setText("");
genProvider.setMarker(marker);
applyProvider(genProvider);
}
private void applyProvider(AbstractCodanProblemDetailsProvider provider) {
String label = provider.getHelpLabel();
final URL url = provider.getHelpURL();
if (label != null) {
helpLabel.setText(label);
setTextSafe(message, provider, provider.getStyledProblemMessage());
setTextSafe(description, provider, provider.getStyledProblemDescription());
}
protected void setTextSafe(Link control, AbstractCodanProblemDetailsProvider provider, String text) {
try {
control.setText(text);
} catch (Exception e) {
// this is more debug message
control.setText("failed to set text: " + provider.getClass() + " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
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() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
ProblemDetails.this.fillContextMenu(manager);
}
});
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 on: 2010-04-28
* Last modified by: $Author$
* Last modified by: $Author: elaskavaia $
*/
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;
/**
@ -49,7 +49,10 @@ public abstract class AbstractCodanProblemDetailsProvider {
String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
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)
* @param id - id of the problem
@ -58,26 +61,26 @@ public abstract class AbstractCodanProblemDetailsProvider {
public abstract boolean isApplicable(String id);
/**
* URL to external help for the problem, would be displayed as label, and as action
* will go to given URL is not null. If label is null (getHelpLabel) URL would be used as label.
* Return styled problem message. String can include <a> tags to which would be
* visible as hyperlinks and newline characters (\n). Default message if
* marker message plus location.
*/
public URL getHelpURL() {
return null;
public String getStyledProblemMessage(){
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$
}
/**
* Return styled problem description. String can include <a> tags to which would be
* visible as hyperlinks and newline characters (\n)
*/
public String getStyledProblemDescription(){
String id = getProblemId();
if (id==null) return ""; //$NON-NLS-1$
IProblem problem = CodanRuntime.getInstance().getChechersRegistry().getDefaultProfile().findProblem(id);
return problem.getDescription();
}
/**
* Label text to use to navigate to a help. Would be shown as hyperlink. If helpURL is not
* null would open a browser with given URL.
*/
public String getHelpLabel() {
return null;
}
/**
* 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;
}
}