Search in sources :

Example 56 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method setModel.

public void setModel(final GuidedDecisionTree model, final boolean isReadOnly) {
    this.uiRoot = null;
    this.model = model;
    // Clear existing state
    super.clear();
    clearEvent.fire(new ClearEvent());
    // Walk model creating UIModel
    final TypeNode root = model.getRoot();
    if (root != null) {
        final WiresBaseTreeNode uiRoot = typeNodeFactory.getShape(root, isReadOnly);
        this.uiRoot = uiRoot;
        processChildren(root, uiRoot, isReadOnly);
        final Map<WiresBaseShape, Point2D> layout = layoutManager.getLayoutInformation(uiRoot);
        final Rectangle2D canvasBounds = WiresLayoutUtilities.alignLayoutInCanvas(layout);
        for (Map.Entry<WiresBaseShape, Point2D> e : layout.entrySet()) {
            final Point2D destination = new Point2D(e.getValue().getX(), e.getValue().getY());
            e.getKey().setLocation(destination);
        }
        WiresLayoutUtilities.resizeViewPort(canvasBounds, canvasLayer.getViewport());
    }
    if (shapesInCanvas.isEmpty()) {
        showGettingStartedHint();
    }
    canvasLayer.batch();
}
Also used : WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) Rectangle2D(org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D) ClearEvent(org.uberfire.ext.wires.core.api.events.ClearEvent) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class GuidedDecisionTreePalette method makeStencils.

private Widget makeStencils(final String className, final boolean isReadOnly) {
    final GuidedDecisionTreePaletteGroup paletteGroup = new GuidedDecisionTreePaletteGroup();
    if (className == null) {
        return paletteGroup;
    }
    oracle.getFieldCompletions(className, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] mfs) {
            if (mfs == null || mfs.length == 0) {
                return;
            }
            final TypeNode tn = new TypeNodeImpl(className);
            paletteGroup.addStencil(typeNodeFactory, stencilBuilder, new TypeFactoryHelper(tn, isReadOnly), isReadOnly);
            for (ModelField mf : mfs) {
                final String fieldName = mf.getName();
                if (!fieldName.equals(DataType.TYPE_THIS)) {
                    final ConstraintNode cn = new ConstraintNodeImpl(className, fieldName, "", new StringValue(""));
                    paletteGroup.addStencil(constraintNodeFactory, stencilBuilder, new ConstraintFactoryHelper(cn, isReadOnly), isReadOnly);
                }
            }
        }
    });
    return paletteGroup;
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) TypeFactoryHelper(org.drools.workbench.screens.guided.dtree.client.widget.factories.TypeFactoryHelper) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) ConstraintFactoryHelper(org.drools.workbench.screens.guided.dtree.client.widget.factories.ConstraintFactoryHelper)

Example 58 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class EditActionRetractPopup method initialiseBoundTypes.

private void initialiseBoundTypes() {
    // Extract all bindings available on the path to the root
    final Map<String, TypeNode> bindings = new TreeMap<String, TypeNode>();
    Node parent = clone.getParent();
    while (parent != null) {
        if (parent instanceof TypeNode) {
            final TypeNode tn = (TypeNode) parent;
            if (tn.isBound()) {
                bindings.put(tn.getBinding(), tn);
            }
        }
        parent = parent.getParent();
    }
    bindingListBox.setEnabled(!bindings.isEmpty());
    if (bindings.isEmpty()) {
        bindingListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noBindings());
        return;
    }
    // Add them to the ListBox
    int selectedIndex = 0;
    final BoundNode boundNode = clone.getBoundNode();
    for (String binding : bindings.keySet()) {
        bindingListBox.addItem(binding);
        if (boundNode != null) {
            if (binding.equals(boundNode.getBinding())) {
                selectedIndex = bindingListBox.getItemCount() - 1;
            }
        }
    }
    // Attach event handler before we set the selected index in case we're selecting the first item
    bindingListBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            final String binding = bindingListBox.getItemText(bindingListBox.getSelectedIndex());
            clone.setBoundNode(bindings.get(binding));
        }
    });
    bindingListBox.setSelectedIndex(selectedIndex);
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) TreeMap(java.util.TreeMap)

Example 59 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class EditActionUpdatePopup method initialiseBoundTypes.

private void initialiseBoundTypes() {
    // Extract all bindings available on the path to the root
    final Map<String, TypeNode> bindings = new TreeMap<String, TypeNode>();
    Node parent = clone.getParent();
    while (parent != null) {
        if (parent instanceof TypeNode) {
            final TypeNode tn = (TypeNode) parent;
            if (tn.isBound()) {
                bindings.put(tn.getBinding(), tn);
            }
        }
        parent = parent.getParent();
    }
    bindingListBox.setEnabled(!bindings.isEmpty());
    if (bindings.isEmpty()) {
        bindingListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noBindings());
        return;
    }
    // Add them to the ListBox
    int selectedIndex = 0;
    final BoundNode boundNode = clone.getBoundNode();
    for (String binding : bindings.keySet()) {
        bindingListBox.addItem(binding);
        if (boundNode != null) {
            if (binding.equals(boundNode.getBinding())) {
                selectedIndex = bindingListBox.getItemCount() - 1;
            }
        }
    }
    // Attach event handler before we set the selected index in case we're selecting the first item
    bindingListBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            final String binding = bindingListBox.getItemText(bindingListBox.getSelectedIndex());
            clone.setBoundNode(bindings.get(binding));
            clone.getFieldValues().clear();
            initialiseFieldValues();
        }
    });
    bindingListBox.setSelectedIndex(selectedIndex);
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) TreeMap(java.util.TreeMap)

Example 60 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class EditTypePopup method cloneNode.

// Clone node whilst editing to preserve original node should User cancel the edit
private TypeNode cloneNode(final TypeNode node) {
    final TypeNode clone = new TypeNodeImpl(node.getClassName());
    clone.setParent(node.getParent());
    clone.setBinding(node.getBinding());
    return clone;
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Aggregations

TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)125 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)109 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)106 Test (org.junit.Test)105 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)61 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)53 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)34 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)33 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)31 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)30 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)26 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)24 BigInteger (java.math.BigInteger)23 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)17 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)16 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)11 DataTypeConversionErrorParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage)11 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)11 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)9 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)9