Skip to content

Commit

Permalink
basic visualization of argument instrumentation works
Browse files Browse the repository at this point in the history
(before, we only visualized return values)

issue #58
  • Loading branch information
miho committed Aug 13, 2015
1 parent c53ff10 commit 1b34561
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@
import eu.mihosoft.vrl.workflow.VisualizationRequest;
import eu.mihosoft.vrl.workflow.WorkflowUtil;
import eu.mihosoft.vrl.workflow.fx.FXValueSkinFactory;
import eu.mihosoft.vrl.workflow.fx.ScalableContentPane;
import eu.mihosoft.vrl.workflow.fx.ScaleBehavior;
import eu.mihosoft.vrl.workflow.fx.TranslateBehavior;
import eu.mihosoft.vrl.workflow.fx.VCanvas;
import eu.mihosoft.vrl.workflow.skin.VNodeSkin;
import groovy.lang.GroovyClassLoader;
import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -414,13 +410,15 @@ private Optional<VNode> getNodeByCodeId(VFlowModel flow, String id) {
// }
private void runCode() {

// copy cu
// TODO 10.08.2015 add copy/cloning functionality (see todos in model)
updateView();
CompilationUnitDeclaration cu
= (CompilationUnitDeclaration) UIBinding.scopes.values().
iterator().next().get(0);

// copy cu
// TODO 10.08.2015 add copy/cloning functionality (see todos in model)
updateView();

InstrumentCode instrumentCode = new InstrumentCode();
CompilationUnitDeclaration newCu = instrumentCode.transform(cu);

Expand All @@ -438,7 +436,7 @@ private void runCode() {
});

VRLInstrumentationUtil.addEventHandler(
InstrumentationEventType.POST_INVOCATION,
InstrumentationEventType.INVOCATION,
(evt) -> {
getNodeByCodeId(
flow.getModel(),
Expand Down Expand Up @@ -851,12 +849,16 @@ static void addResetViewMenu(VCanvas canvas) {

private void visualizeEvent(InstrumentationEvent evt, VNode vn) {
System.out.println("vn: " + vn.getId());

if (vn.getValueObject().getValue() instanceof CodeEntity) {
CodeEntity ce = (CodeEntity) vn.getValueObject().getValue();
ce.getMetaData().put("VRL:retVal", evt.getSource().getReturnValue().orElse(null));
if (evt.getType() == InstrumentationEventType.POST_INVOCATION) {
ce.getMetaData().put("VRL:retVal", evt.getSource().getReturnValue().orElse(null));
} else if (evt.getType() == InstrumentationEventType.PRE_INVOCATION) {
ce.getMetaData().put("VRL:args", evt.getSource().getArguments());
}
}

// List<VNodeSkin> skins = flow.getNodeSkinLookup().getById(vn.getId());
//
// skins.stream().filter(sk -> sk instanceof VariableFlowNodeSkin).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import eu.mihosoft.vrl.lang.model.CodeEntity;
import eu.mihosoft.vrl.lang.model.CodeEvent;
import eu.mihosoft.vrl.lang.model.CodeEventType;
import eu.mihosoft.vrl.lang.model.DeclarationInvocation;
import eu.mihosoft.vrl.lang.model.IArgument;
import eu.mihosoft.vrl.lang.model.Invocation;
import eu.mihosoft.vrl.lang.model.MethodDeclaration;
Expand All @@ -25,8 +26,9 @@
import eu.mihosoft.vrl.workflow.fx.ScaleBehavior;
import eu.mihosoft.vrl.workflow.fx.TranslateBehavior;
import eu.mihosoft.vrl.workflow.fx.VCanvas;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
Expand All @@ -53,6 +55,7 @@ public class VariableFlowNodeSkin extends CustomFlowNodeSkin {

private boolean updating;
private VBox outputs;
private final ObjectProperty<Object[]> args = new SimpleObjectProperty<>();

public VariableFlowNodeSkin(FXSkinFactory skinFactory, VNode model, VFlow controller) {
super(skinFactory, model, controller);
Expand All @@ -66,6 +69,14 @@ public void configureCanvas(VCanvas canvas) {
canvas.setTranslateBehavior(TranslateBehavior.ALWAYS);
}

private boolean isInvocation() {
return getModel().getValueObject().getValue() instanceof Invocation;
}

private Invocation getInvocation() {
return (Invocation)getModel().getValueObject().getValue();
}

@Override
protected Node createView() {

Expand All @@ -81,7 +92,9 @@ protected Node createView() {

}

if (value instanceof Invocation) {
if (!(value instanceof Invocation)) {
return parent;
}

// if (value instanceof ScopeInvocation) {
// ScopeInvocation inv = (ScopeInvocation) value;
Expand All @@ -92,44 +105,53 @@ protected Node createView() {
// System.exit(1);
// }
// }
Invocation invocation = (Invocation) value;
Invocation invocation = (Invocation) value;

box.setVisible(!invocation.getArguments().isEmpty());
box.setVisible(!invocation.getArguments().isEmpty());

VBox inputs = new VBox();
outputs = new VBox();
HBox hbox = new HBox(inputs, outputs);
hbox.setPadding(new Insets(0, 15, 0, 15));
VBox inputs = new VBox();
outputs = new VBox();
HBox hbox = new HBox(inputs, outputs);
hbox.setPadding(new Insets(0, 15, 0, 15));

createArgView(invocation, inputs, false);
createArgView(invocation, inputs, false);

invocation.getArguments().addListener(
(ListChangeListener.Change<? extends IArgument> c) -> {
box.setVisible(!invocation.getArguments().isEmpty());
if (!updating) {
createArgView(invocation, inputs,
invocation.getArguments().size()
== inputs.getChildren().size());
}
});
parent.getChildren().add(hbox);
}


invocation.getArguments().addListener(
(ListChangeListener.Change<? extends IArgument> c) -> {
box.setVisible(!invocation.getArguments().isEmpty());
if (!updating) {
createArgView(invocation, inputs,
invocation.getArguments().size()
== inputs.getChildren().size());
}
});
parent.getChildren().add(hbox);

if (getModel().getValueObject().getValue() instanceof CodeEntity) {
CodeEntity ce = (CodeEntity) getModel().getValueObject().getValue();
updateOutputView(ce.getMetaData().get("VRL:retVal"));


args.set((Object[]) ce.getMetaData().get("VRL:args"));
createArgView(invocation, inputs, true);

ce.getMetaData().addListener((Observable observable) -> {
updateOutputView(ce.getMetaData().get("VRL:retVal"));

args.set((Object[]) ce.getMetaData().get("VRL:args"));

createArgView(invocation, inputs, true);

});
}

getModel().getValueObject().valueProperty().addListener((ov, oldV, newV) -> {
if (newV instanceof CodeEntity) {
CodeEntity ce = (CodeEntity) newV;
ce.getMetaData().addListener((Observable observable) -> {

args.set((Object[]) ce.getMetaData().get("VRL:args"));
createArgView(invocation, inputs, true);

updateOutputView(ce.getMetaData().get("VRL:retVal"));
});
}
Expand Down Expand Up @@ -221,6 +243,18 @@ private void createArgView(Invocation invocation, VBox inputs, boolean update) {
} else {
inputs.getChildren().add(label);
}

if (args.get() != null) {
Object[] currentArgs = args.get();
if (argIndex < currentArgs.length) {
Object arg = currentArgs[argIndex];
if (arg != null) {
label.setText(arg.toString());
label.setTextFill(Color.WHITE);
}
}
}

} else if (a.getArgType() == ArgumentType.INVOCATION) {
Label label = new Label();
label.setTextFill(Color.WHITE);
Expand All @@ -230,6 +264,17 @@ private void createArgView(Invocation invocation, VBox inputs, boolean update) {
} else {
inputs.getChildren().add(label);
}

if (args.get() != null) {
Object[] currentArgs = args.get();
if (argIndex < currentArgs.length) {
Object arg = currentArgs[argIndex];
if (arg != null) {
label.setText(arg.toString());
label.setTextFill(Color.WHITE);
}
}
}
}

argIndex++;
Expand Down Expand Up @@ -290,9 +335,19 @@ void updateOutputView(Object retVal) {

outputs.getChildren().addAll(subScene);
} else if (retVal != null) {
outputs.getChildren().add(new Label(retVal.toString()));
Label l = new Label(retVal.toString());
l.setTextFill(Color.WHITE);
outputs.getChildren().add(l);
} else {
outputs.getChildren().add(new Label("null"));
Label l = new Label();
if (isInvocation()) {
Invocation invocation = getInvocation();
if(!invocation.isVoid() && !(invocation instanceof DeclarationInvocation)) {
l.setText("null");
}
}
l.setTextFill(Color.WHITE);
outputs.getChildren().add(l);
}

}
Expand Down

0 comments on commit 1b34561

Please sign in to comment.