Test fixes

This commit is contained in:
dragonmacher 2023-05-11 17:10:45 -04:00
parent f546c8828c
commit 2f2a07c671
5 changed files with 35 additions and 8 deletions

View file

@ -111,6 +111,11 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
// do nothing, actions are not supported by this display
}
@Override
public Collection<DockingActionIf> getActions() {
return Collections.emptyList();
}
@Override
public AttributedVertex getFocusedVertex() {
return null;

View file

@ -601,7 +601,7 @@ public class DefaultGraphDisplay implements GraphDisplay {
display.setGraph(createSubGraph(), graphRenderer.getGraphDisplayOptions(),
title + " - Sub-graph", false, TaskMonitor.DUMMY);
display.setGraphDisplayListener(listener.cloneWith(display));
copyActionsToNewGraph((DefaultGraphDisplay) display);
copyActionsToNewGraph(display);
}
catch (CancelledException e) {
// using Dummy, so can't happen
@ -1277,10 +1277,11 @@ public class DefaultGraphDisplay implements GraphDisplay {
return vv;
}
private void copyActionsToNewGraph(DefaultGraphDisplay display) {
private void copyActionsToNewGraph(GraphDisplay display) {
Collection<DockingActionIf> defaultActions = display.getActions();
for (DockingActionIf action : addedActions) {
if (display.containsAction(action)) {
if (defaultActions.contains(action)) {
// ignore actions added by the graph itself and any actions that the end user may
// accidentally add more than once
continue;
@ -1288,7 +1289,6 @@ public class DefaultGraphDisplay implements GraphDisplay {
display.addAction(new DockingActionProxy(action));
}
}
private boolean containsAction(DockingActionIf action) {
@ -1314,6 +1314,11 @@ public class DefaultGraphDisplay implements GraphDisplay {
componentProvider.addLocalAction(action);
}
@Override
public Collection<DockingActionIf> getActions() {
return new ArrayList<>(addedActions);
}
@Override
public AttributedVertex getFocusedVertex() {
return focusedVertex;

View file

@ -15,6 +15,7 @@
*/
package ghidra.graph.visualization;
import java.util.Collection;
import java.util.Set;
import docking.action.DockingActionIf;
@ -108,6 +109,11 @@ public class DefaultGraphDisplayWrapper
Swing.runNow(() -> delegate.addAction(action));
}
@Override
public Collection<DockingActionIf> getActions() {
return Swing.runNow(() -> delegate.getActions());
}
@Override
public int compareTo(DefaultGraphDisplayWrapper other) {
// note: no need for call to Swing, assuming ID is immutable

View file

@ -15,6 +15,7 @@
*/
package ghidra.service.graph;
import java.util.Collection;
import java.util.Set;
import docking.action.DockingActionIf;
@ -147,4 +148,11 @@ public interface GraphDisplay {
* @param action the action to add
*/
public void addAction(DockingActionIf action);
/**
* Gets all actions that have been added to this graph display. If this display does not
* support actions, then an empty collection will be returned.
* @return the actions
*/
public Collection<DockingActionIf> getActions();
}

View file

@ -15,8 +15,7 @@
*/
package ghidra.graph;
import java.util.Map;
import java.util.Set;
import java.util.*;
import docking.action.DockingActionIf;
import docking.widgets.EventTrigger;
@ -62,8 +61,7 @@ public class TestGraphDisplay implements GraphDisplay {
}
@Override
public void setGraph(AttributedGraph graph, String title, boolean append,
TaskMonitor monitor)
public void setGraph(AttributedGraph graph, String title, boolean append, TaskMonitor monitor)
throws CancelledException {
if (append) {
this.graph = mergeGraphs(graph, this.graph);
@ -113,6 +111,11 @@ public class TestGraphDisplay implements GraphDisplay {
// do nothing, actions are not supported by this display
}
@Override
public Collection<DockingActionIf> getActions() {
return Collections.emptyList();
}
private AttributedGraph mergeGraphs(AttributedGraph newGraph, AttributedGraph oldGraph) {
for (AttributedVertex vertex : oldGraph.vertexSet()) {
newGraph.addVertex(vertex);