summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views')
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries3
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag1
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java23
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java169
-rw-r--r--org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java138
7 files changed, 336 insertions, 0 deletions
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries
new file mode 100644
index 0000000..58fdd77
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Entries
@@ -0,0 +1,3 @@
+/GenericCodanProblemDetailsProvider.java/1.2/Sat May 1 00:41:55 2010//TCDT_7_0_0
+/ProblemDetails.java/1.5/Wed May 5 20:48:28 2010//TCDT_7_0_0
+/ProblemDetailsExtensions.java/1.2/Sat May 1 00:41:55 2010//TCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository
new file mode 100644
index 0000000..b01fe09
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Repository
@@ -0,0 +1 @@
+org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root
new file mode 100644
index 0000000..04efa23
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@dev.eclipse.org:/cvsroot/tools
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag
new file mode 100644
index 0000000..49a449a
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/CVS/Tag
@@ -0,0 +1 @@
+NCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java
new file mode 100644
index 0000000..0afb53c
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/GenericCodanProblemDetailsProvider.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+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;
+ }
+}
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java
new file mode 100644
index 0000000..3f164af
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetails.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.ui.views;
+
+import java.util.Collection;
+
+import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
+import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
+import org.eclipse.cdt.codan.ui.CodanEditorUtility;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+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.Link;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * Problems Details view show details for selected problem marker.
+ * Other plugins can contribute to override default behaviour 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"; //$NON-NLS-1$
+ private Composite area;
+ /**
+ * 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();
+ private AbstractCodanProblemDetailsProvider curProvider = genProvider;
+
+ /**
+ * The constructor.
+ */
+ public ProblemDetails() {
+ }
+
+ /**
+ * This is a callback that will allow us
+ * to create the area and initialize it.
+ */
+ public void createPartControl(Composite parent) {
+ final String problemsViewId = "org.eclipse.ui.views.ProblemView"; //$NON-NLS-1$
+ area = new Composite(parent, SWT.NONE);
+ area.setLayout(new GridLayout());
+ SelectionAdapter linkSelAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String link = e.text;
+ if (link == null)
+ return;
+ if (link.startsWith("http")) { //$NON-NLS-1$
+ org.eclipse.swt.program.Program.launch(e.text);
+ return;
+ }
+ // link file format example "file:/tmp/file.c#42", 42 is the line number
+ if (link.startsWith("file:")) { //$NON-NLS-1$
+ try {
+ CodanEditorUtility.openInEditor(link, curProvider.getMarker().getResource());
+ } catch (PartInitException e1) {
+ CodanUIActivator.log(e1);
+ }
+ return;
+ }
+ if (link.startsWith("help:")) { //$NON-NLS-1$
+ // open in eclipse help TODO
+ return;
+ }
+ }
+ };
+ 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(problemsViewId)) {
+ processSelection(selection);
+ }
+ }
+ });
+ ISelection selection = ser.getSelection(problemsViewId);
+ processSelection(selection);
+ }
+
+ protected void processSelection(ISelection selection) {
+ if (selection == null || selection.isEmpty())
+ return;
+ if (selection instanceof IStructuredSelection) {
+ Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+ IMarker marker = null;
+ if (firstElement instanceof IAdaptable) {
+ marker = (IMarker) ((IAdaptable) firstElement).getAdapter(IMarker.class);
+ } else if (firstElement instanceof IMarker) {
+ marker = (IMarker) firstElement;
+ }
+ if (marker != null) {
+ queryProviders(marker);
+ area.layout();
+ }
+ }
+ }
+
+ private void queryProviders(IMarker marker) {
+ String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$
+ Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions.getProviders(id);
+ for (AbstractCodanProblemDetailsProvider provider : providers) {
+ synchronized (provider) {
+ provider.setMarker(marker);
+ if (provider.isApplicable(id)) {
+ applyProvider(provider);
+ return;
+ }
+ }
+ }
+ genProvider.setMarker(marker);
+ applyProvider(genProvider);
+ }
+
+ private void applyProvider(AbstractCodanProblemDetailsProvider provider) {
+ curProvider = provider;
+ 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 debug message
+ control.setText("failed to set text: " + provider.getClass() + " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ /**
+ * Passing the focus request to the area's control.
+ */
+ public void setFocus() {
+ message.setFocus();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java
new file mode 100644
index 0000000..689d9d8
--- /dev/null
+++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/views/ProblemDetailsExtensions.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.ui.views;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
+import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * Class that can load extension for problemDetails
+ */
+public class ProblemDetailsExtensions {
+ public static final String ALL = "*";//$NON-NLS-1$
+ private static final String EXTENSION_POINT_NAME = "codanProblemDetails"; //$NON-NLS-1$
+ private static boolean extensionsLoaded;
+ private static HashMap<String, Collection<?>> map = new HashMap<String, Collection<?>>();
+
+ private static synchronized void readExtensions() {
+ if (extensionsLoaded) return;
+ IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME);
+ if (ep == null)
+ return;
+ try {
+ IConfigurationElement[] elements = ep.getConfigurationElements();
+ // process categories
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement configurationElement = elements[i];
+ processDetails(configurationElement);
+ }
+ } finally {
+ extensionsLoaded = true;
+ }
+ }
+
+ /**
+ * @param configurationElement
+ */
+ private static void processDetails(IConfigurationElement configurationElement) {
+ if (configurationElement.getName().equals("problemDetails")) { //$NON-NLS-1$
+ String id = configurationElement.getAttribute("problemId"); //$NON-NLS-1$
+ if (id == null) {
+ id = ALL;
+ }
+ addExtension(id, configurationElement);
+ }
+ }
+
+ public static AbstractCodanProblemDetailsProvider resolveClass(IConfigurationElement configurationElement) {
+ AbstractCodanProblemDetailsProvider res;
+ try {
+ res = (AbstractCodanProblemDetailsProvider) configurationElement.createExecutableExtension("class");//$NON-NLS-1$
+ } catch (CoreException e) {
+ CodanUIActivator.log(e);
+ return null;
+ }
+ return res;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private static void addExtension(String id, IConfigurationElement configurationElement) {
+ Collection collection = getCollection(id);
+ collection.add(configurationElement);
+ }
+
+ /**
+ * Remove provider from the list
+ * @param id - codan problem id or ALL
+ * @param el - details provider (class extending AbstractCodanProblemDetailsProvider) or ElementConfiguration (user internally)
+ */
+ @SuppressWarnings("rawtypes")
+ public static void removeExtension(String id, Object el) {
+ Collection collection = getCollection(id);
+ collection.remove(el);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static Collection getCollection(String id) {
+ Collection collection = map.get(id);
+ if (collection == null) {
+ collection = new ArrayList();
+ map.put(id, collection);
+ }
+ return collection;
+ }
+
+ public static Collection<AbstractCodanProblemDetailsProvider> getProviders(String id) {
+ readExtensions();
+ Collection<AbstractCodanProblemDetailsProvider> providers = new ArrayList<AbstractCodanProblemDetailsProvider>();
+ Collection<?> collection1 = getCollection(id);
+ Collection<?> collection2 = getCollection(ALL);
+ providers.addAll(resolveProviders(collection1));
+ providers.addAll(resolveProviders(collection2));
+ return providers;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static Collection<AbstractCodanProblemDetailsProvider> resolveProviders(Collection collection) {
+ Collection res = new ArrayList(collection);
+ for (Iterator iterator = res.iterator(); iterator.hasNext();) {
+ Object object = iterator.next();
+ if (object instanceof IConfigurationElement) {
+ // resolve
+ collection.remove(object);
+ AbstractCodanProblemDetailsProvider provider = resolveClass((IConfigurationElement) object);
+ if (provider!=null)
+ collection.add(provider);
+ }
+ }
+ return collection;
+ }
+
+ /**
+ * Add extension (details provider) using API
+ * @param id - codan problem id or ALL
+ * @param provider - class extending AbstractCodanProblemDetailsProvider
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static void addExtension(String id, AbstractCodanProblemDetailsProvider provider) {
+ Collection collection = getCollection(id);
+ collection.add(provider);
+ }
+}