mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Support for multiple selections. Factored into a ProblemVisualizer package.
This commit is contained in:
parent
b00e6396b8
commit
57ef7fb851
4 changed files with 39 additions and 24 deletions
|
@ -4,8 +4,8 @@
|
|||
<extension
|
||||
point="org.eclipse.cdt.visualizer.ui.visualizer">
|
||||
<visualizer
|
||||
class="org.eclipse.cdt.visualizer.examples.ProblemVisualizer"
|
||||
id="org.eclipse.cdt.visualizer.examples.counterVisualizer">
|
||||
class="org.eclipse.cdt.visualizer.examples.ProblemVisualizer.ProblemVisualizer"
|
||||
id="org.eclipse.cdt.visualizer.examples.ProblemVisualizer">
|
||||
</visualizer>
|
||||
</extension>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Marc Khouzam (Ericsson) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.visualizer.examples;
|
||||
package org.eclipse.cdt.visualizer.examples.ProblemVisualizer;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
#
|
||||
# Contributors:
|
||||
# Marc Khouzam (Ericsson) - initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
ProblemCountVisualizer_Name=ProblemCounter
|
||||
ProblemCountVisualizer_DisplayName=Problem Count
|
|
@ -8,7 +8,9 @@
|
|||
* Contributors:
|
||||
* Marc Khouzam (Ericsson) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.visualizer.examples;
|
||||
package org.eclipse.cdt.visualizer.examples.ProblemVisualizer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvas;
|
||||
import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvasVisualizer;
|
||||
|
@ -177,17 +179,6 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handlesSelection(ISelection selection) {
|
||||
Object sel = SelectionUtils.getSelectedObject(selection);
|
||||
|
||||
if (sel instanceof IResource) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visualizerDeselected() {
|
||||
}
|
||||
|
@ -257,14 +248,19 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the count of problem markers for each severity for the
|
||||
* specified resource.
|
||||
* Clear the marker count array.
|
||||
*/
|
||||
private void setMarkerCount(IResource resource) {
|
||||
private void clearMarkerCount() {
|
||||
m_markerCount[IMarker.SEVERITY_ERROR] = 0;
|
||||
m_markerCount[IMarker.SEVERITY_WARNING] = 0;
|
||||
m_markerCount[IMarker.SEVERITY_INFO] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the count of problem markers for each severity for the
|
||||
* specified resource.
|
||||
*/
|
||||
private void addToMarkerCount(IResource resource) {
|
||||
IMarker[] problems = null;
|
||||
try {
|
||||
problems = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
|
||||
|
@ -305,12 +301,32 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
m_canvas.redraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handlesSelection(ISelection selection) {
|
||||
List<Object> selections = SelectionUtils.getSelectedObjects(selection);
|
||||
|
||||
// As long as we support at least one element of the selection
|
||||
// that is good enough
|
||||
for (Object sel : selections) {
|
||||
if (sel instanceof IResource) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void workbenchSelectionChanged(ISelection selection) {
|
||||
Object sel = SelectionUtils.getSelectedObject(selection);
|
||||
clearMarkerCount();
|
||||
|
||||
List<Object> selections = SelectionUtils.getSelectedObjects(selection);
|
||||
|
||||
for (Object sel : selections) {
|
||||
if (sel instanceof IResource) {
|
||||
// Update the data
|
||||
setMarkerCount((IResource)sel);
|
||||
addToMarkerCount((IResource)sel);
|
||||
}
|
||||
}
|
||||
|
||||
refresh();
|
Loading…
Add table
Reference in a new issue