Search in sources :

Example 1 with BoundNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode 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 2 with BoundNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode 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)

Aggregations

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 TreeMap (java.util.TreeMap)2 BoundNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode)2 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)2 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)1 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)1