1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

First commit of an example visualizer, which displays a count of problem markers.

This commit is contained in:
Marc Khouzam 2012-02-26 22:28:50 -05:00
parent 45fd24540c
commit bcce66726a
11 changed files with 461 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.visualizer.examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,70 @@
#Tue Jun 24 11:04:56 PDT 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
org.eclipse.jdt.core.compiler.problem.nullReference=error
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=error
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6

View file

@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.cdt.visualizer.examples;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.visualizer.examples.VisualizerExamplesPlugin
Bundle-Vendor: %provider.name
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.cdt.visualizer.ui,
org.eclipse.core.resources
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

View file

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,18 @@
# =============================================================================
# Copyright (c) 2012 Ericsson Corporation and others.
# 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:
# Marc Khouzam (Ericsson) - initial API and implementation
# =============================================================================
# -----------------------------------------------------------------------------
# Plugin string resources
# -----------------------------------------------------------------------------
plugin.name=CDT Visualizer Examples
provider.name=Eclipse CDT

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.cdt.visualizer.ui.visualizer">
<visualizer
class="org.eclipse.cdt.visualizer.examples.ProblemVisualizer"
id="org.eclipse.cdt.visualizer.examples.counterVisualizer">
</visualizer>
</extension>
</plugin>

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2009, 2011 Ericsson and others.
* 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:
* Ericsson - initial API and implementation
* Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
*******************************************************************************/
package org.eclipse.cdt.visualizer.examples;
import org.eclipse.osgi.util.NLS;
/**
* Preference strings.
*/
class Messages extends NLS {
public static String CounterVisualizer_Name;
public static String CounterVisualizer_DisplayName;
public static String CounterVisualizer_Description;
static {
// initialize resource bundle
NLS.initializeMessages(Messages.class.getName(), Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,14 @@
###############################################################################
# Copyright (c) 2012 Ericsson and others.
# 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:
# Marc Khouzam (Ericsson) - initial API and implementation
###############################################################################
CounterVisualizer_Name=counter
CounterVisualizer_DisplayName=Counter Visualizer
CounterVisualizer_Description=Visualizer displaying the count of errors/warnings/info

View file

@ -0,0 +1,212 @@
/*******************************************************************************
* Copyright (c) 2012 Tilera Corporation and others.
* 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:
* Marc Khouzam (Ericsson) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.visualizer.examples;
import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvas;
import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvasVisualizer;
import org.eclipse.cdt.visualizer.ui.canvas.GraphicObject;
import org.eclipse.cdt.visualizer.ui.util.Colors;
import org.eclipse.cdt.visualizer.ui.util.SelectionManager;
import org.eclipse.cdt.visualizer.ui.util.SelectionUtils;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
public class ProblemVisualizer extends GraphicCanvasVisualizer {
private static final int MARGIN_WIDTH = 10;
private static final int MARGIN_HEIGHT = 10;
private static final int SPACING_HEIGHT = 40;
private static final int NUM_SEVERITY = 3;
private class BarGraphicObject extends GraphicObject {
public BarGraphicObject(int severity, int x, int y, int w, int h) {
super(x, y, w, h);
Color color = Colors.BLACK;
switch (severity) {
case IMarker.SEVERITY_ERROR:
color = Colors.DARK_RED;
break;
case IMarker.SEVERITY_WARNING:
color = Colors.DARK_YELLOW;
break;
case IMarker.SEVERITY_INFO:
color = Colors.DARK_BLUE;
break;
}
setBackground(color);
setForeground(color);
}
@Override
public void paintContent(GC gc) {
gc.fillRectangle(m_bounds);
}
}
private GraphicCanvas m_canvas;
private int[] m_markerCount = new int[NUM_SEVERITY];
public ProblemVisualizer() {
super();
}
@Override
public String getName() {
return Messages.CounterVisualizer_Name;
}
@Override
public String getDisplayName() {
return Messages.CounterVisualizer_DisplayName;
}
@Override
public String getDescription() {
return Messages.CounterVisualizer_Description;
}
@Override
public GraphicCanvas createCanvas(Composite parent) {
m_canvas = new GraphicCanvas(parent);
return m_canvas;
}
@Override
protected void initializeCanvas(GraphicCanvas canvas) {
// TODO Auto-generated method stub
super.initializeCanvas(canvas);
}
@Override
public int handlesSelection(ISelection selection) {
Object sel = SelectionUtils.getSelectedObject(selection);
if (sel instanceof IResource) {
return 2;
}
return 0;
}
@Override
public void visualizerDeselected() {
// TODO Auto-generated method stub
super.visualizerDeselected();
}
@Override
public void visualizerSelected() {
// TODO Auto-generated method stub
super.visualizerSelected();
}
private BarGraphicObject[] getBars() {
BarGraphicObject[] bars = new BarGraphicObject[3];
Rectangle bounds = m_canvas.getBounds();
int x = bounds.x + MARGIN_WIDTH;
int y = bounds.y + MARGIN_HEIGHT;
int spacing = SPACING_HEIGHT;
int height = (bounds.height - 2 * MARGIN_HEIGHT - 2 * SPACING_HEIGHT) / 3;
if (height <= 0) {
spacing = 0;
y = bounds.y;
height = bounds.height / 3;
}
// Find the maximum marker count to dictate the width
int maxCount = Math.max(m_markerCount[0], m_markerCount[1]);
maxCount = Math.max(maxCount, m_markerCount[2]);
int maxWidth = bounds.width - 2 * MARGIN_WIDTH;
if (maxCount == 0) maxCount = maxWidth;
int count = m_markerCount[IMarker.SEVERITY_ERROR];
if (count == 0) count = 1;
int width = maxWidth * count / maxCount;
bars[0] = new BarGraphicObject(IMarker.SEVERITY_ERROR, x, y, width, height);
y = y + height + spacing;
count = m_markerCount[IMarker.SEVERITY_WARNING];
if (count == 0) count = 1;
width = maxWidth * count / maxCount;
bars[1] = new BarGraphicObject(IMarker.SEVERITY_WARNING, x, y, width, height);
y = y + height + spacing;
count = m_markerCount[IMarker.SEVERITY_INFO];
if (count == 0) count = 1;
width = maxWidth * count / maxCount;
bars[2] = new BarGraphicObject(IMarker.SEVERITY_INFO, x, y, width, height);
return bars;
}
private void setMarkerCount(IResource resource) {
m_markerCount[IMarker.SEVERITY_ERROR] = 0;
m_markerCount[IMarker.SEVERITY_WARNING] = 0;
m_markerCount[IMarker.SEVERITY_INFO] = 0;
IMarker[] problems = null;
try {
problems = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
return;
}
for (IMarker problem : problems) {
try {
Object attrValue = problem.getAttribute(IMarker.SEVERITY);
if (attrValue != null && attrValue instanceof Integer) {
int severity = (Integer)attrValue;
m_markerCount[severity]++;
}
} catch (CoreException e) {
}
}
}
@Override
public void workbenchSelectionChanged(ISelection selection) {
m_canvas.clear();
Object sel = SelectionUtils.getSelectedObject(selection);
if (sel instanceof IResource) {
m_canvas.setBackground(Colors.WHITE);
setMarkerCount((IResource)sel);
BarGraphicObject[] bars = getBars();
for (BarGraphicObject bar : bars) {
m_canvas.add(bar);
}
}
m_canvas.redraw();
}
public SelectionManager getSelectionManager() {
return m_selectionManager;
}
}

View file

@ -0,0 +1,50 @@
package org.eclipse.cdt.visualizer.examples;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class VisualizerExamplesPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.cdt.visualizer.examples"; //$NON-NLS-1$
// The shared instance
private static VisualizerExamplesPlugin plugin;
/**
* The constructor
*/
public VisualizerExamplesPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static VisualizerExamplesPlugin getDefault() {
return plugin;
}
}