Skip to content

Instantly share code, notes, and snippets.

@romartin
Created November 7, 2019 23:54
Show Gist options
  • Save romartin/919e3f07da726fbce717d8ffdbe20577 to your computer and use it in GitHub Desktop.
Save romartin/919e3f07da726fbce717d8ffdbe20577 to your computer and use it in GitHub Desktop.
package org.kie.workbench.common.stunner.client.lienzo.components.views;
import javax.enterprise.context.Dependent;
import com.ait.lienzo.client.core.shape.Group;
import com.ait.lienzo.client.core.shape.Layer;
import org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas;
import org.kie.workbench.common.stunner.core.client.canvas.Canvas;
import org.kie.workbench.common.stunner.core.client.components.views.EmptyScreen;
@Dependent
public class LienzoEmptyScreen implements EmptyScreen {
// This class contains the pure lienzo "empty screen" implementation object as a field
// so it can be showed against some Canvas or hidden.
private WiresCanvas canvas;
private Group theLienzoEmptyScreenGroupInstance;
@Override
public void configure(Canvas canvas, String text) {
// It allows to configure the lienzo "empty screen" to show different texts, on any Stunner's editor (Canvas)
// This way, either BPMN, CM and DMN can reuse this component and just use different text literals
this.canvas = (WiresCanvas) canvas;
this.theLienzoEmptyScreenGroupInstance = /*create a new lienzo instance here*/;
// etc
}
@Override
public void show() {
// It shows the "empty screen" into the right "Canvas"
// The lienzo object for the "empty screen" will be attached to the "top" canvas layer, instead of the main one, for performance reasons
getTargetLayer().add(theLienzoEmptyScreenGroupInstance);
batch();
}
@Override
public void hide() {
theLienzoEmptyScreenGroupInstance.removeFromParent();
batch();
}
@Override
public void destroy() {
theLienzoEmptyScreenGroupInstance.removeFromParent();
theLienzoEmptyScreenGroupInstance = null;
canvas = null;
// etc
}
private void batch() {
getTargetLayer().batch();
}
private Layer getTargetLayer() {
return canvas.getView().getLayer().getTopLayer();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment