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();
}
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;
}
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);
}
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);
}
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;
}
Aggregations