Example usage for com.google.gwt.user.client.ui TextBox setVisibleLength

List of usage examples for com.google.gwt.user.client.ui TextBox setVisibleLength

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TextBox setVisibleLength.

Prototype

public void setVisibleLength(int length) 

Source Link

Document

Sets the number of visible characters in the text box.

Usage

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.DefaultLiteralEditor.java

License:Apache License

private TextBox getTextBox() {
    final TextBox box = TextBoxFactory.getTextBox(dataType);
    box.setTitle(Constants.INSTANCE.LiteralValueTip());
    box.setStyleName("constraint-value-Editor");
    if (constraint.getValue() == null) {
        box.setText("");
    } else {/*  w w w. j  a v  a 2 s  . c  om*/
        box.setText(constraint.getValue());
    }

    String v = constraint.getValue();
    if (v == null || v.length() < 7) {
        box.setVisibleLength(8);
    } else {
        box.setVisibleLength(v.length() + 1);
    }

    box.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            constraint.setValue(box.getText());
        }

    });

    box.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {

            //Alter visible size
            int length = box.getText().length();
            box.setVisibleLength(length > 0 ? length : 1);

            //Commit change if enter is pressed
            final int keyCode = event.getNativeKeyCode();
            if (keyCode == KeyCodes.KEY_ENTER) {
                valueChanged.valueChanged(box.getText());
            }
        }
    });

    return box;
}

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.factPattern.PopupCreator.java

License:Apache License

/**
 * This adds in (optionally) the editor for changing the bound variable
 * name. If its a bindable pattern, it will show the editor, if it is
 * already bound, and the name is used, it should not be editable.
 *//*from   w ww .  j av  a 2  s. c o  m*/
private void doBindingEditor(final FormStylePopup popup) {
    if (bindable || !(modeller.getModel().isBoundFactUsed(pattern.getBoundName()))) {
        HorizontalPanel varName = new HorizontalPanel();
        final TextBox varTxt = new BindingTextBox();
        if (pattern.getBoundName() == null) {
            varTxt.setText("");
        } else {
            varTxt.setText(pattern.getBoundName());
        }

        varTxt.setVisibleLength(6);
        varName.add(varTxt);

        Button bindVar = new Button(Constants.INSTANCE.Set());
        bindVar.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                String var = varTxt.getText();
                if (modeller.isVariableNameUsed(var)) {
                    Window.alert(Constants.INSTANCE.TheVariableName0IsAlreadyTaken(var));
                    return;
                }
                pattern.setBoundName(varTxt.getText());
                modeller.refreshWidget();
                popup.hide();
            }
        });

        varName.add(bindVar);
        popup.addAttribute(Constants.INSTANCE.VariableName(), varName);

    }
}

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.MethodParameterValueEditor.java

License:Apache License

private TextBox boundTextBox(final ActionFieldValue c) {
    final TextBox box = TextBoxFactory.getTextBox(methodParameter.type);
    box.setStyleName("constraint-value-Editor");
    if (c.value == null) {
        box.setText("");
    } else {//from  w w  w.j av a  2 s. c o m
        if (c.value.trim().equals("")) {
            c.value = "";
        }
        box.setText(c.value);
    }

    if (c.value == null || c.value.length() < 5) {
        box.setVisibleLength(6);
    } else {
        box.setVisibleLength(c.value.length() - 1);
    }

    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            c.value = box.getText();
            if (onValueChangeCommand != null) {
                onValueChangeCommand.execute();
            }
            makeDirty();
        }

    });

    box.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            box.setVisibleLength(box.getText().length());
        }
    });

    return box;
}

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.RuleAttributeWidget.java

License:Apache License

private TextBox textBoxEditor(final RuleAttribute at) {
    final TextBox box = new TextBox();
    box.setVisibleLength((at.value.length() < 3) ? 3 : at.value.length());
    box.setText(at.value);//from  www  . ja v a2s. c  o  m
    box.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            at.value = box.getText();
        }
    });

    if (at.attributeName.equals(DATE_EFFECTIVE_ATTR) || at.attributeName.equals(DATE_EXPIRES_ATTR)) {
        if (at.value == null || "".equals(at.value))
            box.setText("");

        box.setVisibleLength(10);
    }

    box.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            int length = box.getText().length();
            box.setVisibleLength(length > 0 ? length : 1);
        }
    });
    return box;
}

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.RuleAttributeWidget.java

License:Apache License

private TextBox textBoxEditor(final RuleMetadata rm) {
    final TextBox box = new TextBox();
    box.setVisibleLength((rm.value.length() < 3) ? 3 : rm.value.length());
    box.setText(rm.value);/* ww  w  .j ava  2s.  c  o m*/
    box.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            rm.value = box.getText();
        }
    });

    box.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            box.setVisibleLength(box.getText().length());
        }
    });
    return box;
}

From source file:org.drools.guvnor.client.decisiontable.GuidedDecisionTableWidget.java

License:Apache License

private Widget newColumn() {
    AddButton addButton = new AddButton();
    addButton.setText(Constants.INSTANCE.NewColumn());
    addButton.setTitle(Constants.INSTANCE.AddNewColumn());

    addButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            final FormStylePopup pop = new FormStylePopup();
            pop.setModal(false);//from w  ww  . j ava 2 s.c o m

            //List of basic column types
            final ListBox choice = new ListBox();
            choice.setVisibleItemCount(NewColumnTypes.values().length);

            choice.addItem(Constants.INSTANCE.AddNewMetadataOrAttributeColumn(),
                    NewColumnTypes.METADATA_ATTRIBUTE.name());
            choice.addItem(SECTION_SEPARATOR);
            choice.addItem(Constants.INSTANCE.AddNewConditionSimpleColumn(),
                    NewColumnTypes.CONDITION_SIMPLE.name());
            choice.addItem(SECTION_SEPARATOR);
            choice.addItem(Constants.INSTANCE.SetTheValueOfAField(),
                    NewColumnTypes.ACTION_UPDATE_FACT_FIELD.name());
            choice.addItem(Constants.INSTANCE.SetTheValueOfAFieldOnANewFact(),
                    NewColumnTypes.ACTION_INSERT_FACT_FIELD.name());
            choice.addItem(Constants.INSTANCE.RetractAnExistingFact(),
                    NewColumnTypes.ACTION_RETRACT_FACT.name());

            //Checkbox to include Advanced Action types
            final CheckBox chkIncludeAdvancedOptions = new CheckBox(
                    SafeHtmlUtils.fromString(Constants.INSTANCE.IncludeAdvancedOptions()));
            chkIncludeAdvancedOptions.setValue(false);
            chkIncludeAdvancedOptions.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    if (chkIncludeAdvancedOptions.getValue()) {
                        addItem(3, Constants.INSTANCE.AddNewConditionBRLFragment(),
                                NewColumnTypes.CONDITION_BRL_FRAGMENT.name());
                        addItem(Constants.INSTANCE.WorkItemAction(), NewColumnTypes.ACTION_WORKITEM.name());
                        addItem(Constants.INSTANCE.WorkItemActionSetField(),
                                NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name());
                        addItem(Constants.INSTANCE.WorkItemActionInsertFact(),
                                NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name());
                        addItem(Constants.INSTANCE.AddNewActionBRLFragment(),
                                NewColumnTypes.ACTION_BRL_FRAGMENT.name());
                    } else {
                        removeItem(NewColumnTypes.CONDITION_BRL_FRAGMENT.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name());
                        removeItem(NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name());
                        removeItem(NewColumnTypes.ACTION_BRL_FRAGMENT.name());
                    }
                    pop.center();
                }

                private void addItem(int index, String item, String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            return;
                        }
                    }
                    choice.insertItem(item, value, index);
                }

                private void addItem(String item, String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            return;
                        }
                    }
                    choice.addItem(item, value);
                }

                private void removeItem(String value) {
                    for (int itemIndex = 0; itemIndex < choice.getItemCount(); itemIndex++) {
                        if (choice.getValue(itemIndex).equals(value)) {
                            choice.removeItem(itemIndex);
                            break;
                        }
                    }
                }

            });

            //OK button to create column
            final Button ok = new Button(Constants.INSTANCE.OK());
            ok.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent w) {
                    String s = choice.getValue(choice.getSelectedIndex());
                    if (s.equals(NewColumnTypes.METADATA_ATTRIBUTE.name())) {
                        showMetaDataAndAttribute();
                    } else if (s.equals(NewColumnTypes.CONDITION_SIMPLE.name())) {
                        showConditionSimple();
                    } else if (s.equals(NewColumnTypes.CONDITION_BRL_FRAGMENT.name())) {
                        showConditionBRLFragment();
                    } else if (s.equals(NewColumnTypes.ACTION_UPDATE_FACT_FIELD.name())) {
                        showActionSet();
                    } else if (s.equals(NewColumnTypes.ACTION_INSERT_FACT_FIELD.name())) {
                        showActionInsert();
                    } else if (s.equals(NewColumnTypes.ACTION_RETRACT_FACT.name())) {
                        showActionRetract();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM.name())) {
                        showActionWorkItemAction();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM_UPDATE_FACT_FIELD.name())) {
                        showActionWorkItemActionSet();
                    } else if (s.equals(NewColumnTypes.ACTION_WORKITEM_INSERT_FACT_FIELD.name())) {
                        showActionWorkItemActionInsert();
                    } else if (s.equals(NewColumnTypes.ACTION_BRL_FRAGMENT.name())) {
                        showActionBRLFragment();
                    }
                    pop.hide();
                }

                private void showMetaDataAndAttribute() {
                    // show choice of attributes
                    Image image = new Image(DroolsGuvnorImageResources.INSTANCE.config());
                    image.setAltText(Constants.INSTANCE.Config());
                    final FormStylePopup pop = new FormStylePopup(image,
                            Constants.INSTANCE.AddAnOptionToTheRule());
                    final ListBox list = RuleAttributeWidget.getAttributeList();

                    //This attribute is only used for Decision Tables
                    list.addItem(GuidedDecisionTable52.NEGATE_RULE_ATTR);

                    // Remove any attributes already added
                    for (AttributeCol52 col : guidedDecisionTable.getAttributeCols()) {
                        for (int iItem = 0; iItem < list.getItemCount(); iItem++) {
                            if (list.getItemText(iItem).equals(col.getAttribute())) {
                                list.removeItem(iItem);
                                break;
                            }
                        }
                    }

                    final Image addbutton = DroolsGuvnorImages.INSTANCE.NewItem();
                    final TextBox box = new TextBox();
                    box.setVisibleLength(15);

                    list.setSelectedIndex(0);

                    list.addChangeHandler(new ChangeHandler() {
                        public void onChange(ChangeEvent event) {
                            AttributeCol52 attr = new AttributeCol52();
                            attr.setAttribute(list.getItemText(list.getSelectedIndex()));
                            dtable.addColumn(attr);
                            refreshAttributeWidget();
                            pop.hide();
                        }
                    });

                    addbutton.setTitle(Constants.INSTANCE.AddMetadataToTheRule());

                    addbutton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent w) {

                            String metadata = box.getText();
                            if (!isUnique(metadata)) {
                                Window.alert(
                                        Constants.INSTANCE.ThatColumnNameIsAlreadyInUsePleasePickAnother());
                                return;
                            }
                            MetadataCol52 met = new MetadataCol52();
                            met.setHideColumn(true);
                            met.setMetadata(metadata);
                            dtable.addColumn(met);
                            refreshAttributeWidget();
                            pop.hide();
                        }

                        private boolean isUnique(String metadata) {
                            for (MetadataCol52 mc : guidedDecisionTable.getMetadataCols()) {
                                if (metadata.equals(mc.getMetadata())) {
                                    return false;
                                }
                            }
                            return true;
                        }

                    });
                    DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
                    horiz.add(box);
                    horiz.add(addbutton);

                    pop.addAttribute(Constants.INSTANCE.Metadata1(), horiz);
                    pop.addAttribute(Constants.INSTANCE.Attribute(), list);
                    pop.show();
                }

                private void showConditionSimple() {
                    final ConditionCol52 column = makeNewConditionColumn();
                    ConditionPopup dialog = new ConditionPopup(getSCE(), guidedDecisionTable,
                            new ConditionColumnCommand() {
                                public void execute(Pattern52 pattern, ConditionCol52 column) {

                                    //Update UI
                                    dtable.addColumn(pattern, column);
                                    refreshConditionsWidget();
                                }
                            }, column, true, isReadOnly);
                    dialog.show();
                }

                private void showConditionBRLFragment() {
                    final BRLConditionColumn column = makeNewConditionBRLFragment();
                    switch (guidedDecisionTable.getTableFormat()) {
                    case EXTENDED_ENTRY:
                        BRLConditionColumnViewImpl popup = new BRLConditionColumnViewImpl(sce,
                                guidedDecisionTable, true, asset, column, clientFactory, eventBus);
                        popup.setPresenter(BRL_CONDITION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLConditionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLConditionColumnViewImpl(
                                sce, guidedDecisionTable, true, asset, (LimitedEntryBRLConditionColumn) column,
                                clientFactory, eventBus);
                        limtedEntryPopup.setPresenter(LIMITED_ENTRY_BRL_CONDITION_PRESENTER);
                        limtedEntryPopup.show();
                        break;
                    }
                }

                private void showActionInsert() {
                    final ActionInsertFactCol52 afc = makeNewActionInsertColumn();
                    ActionInsertFactPopup ins = new ActionInsertFactPopup(getSCE(), guidedDecisionTable,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, afc, true, isReadOnly);
                    ins.show();
                }

                private void showActionSet() {
                    final ActionSetFieldCol52 afc = makeNewActionSetColumn();
                    ActionSetFieldPopup set = new ActionSetFieldPopup(getSCE(), guidedDecisionTable,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, afc, true, isReadOnly);
                    set.show();
                }

                private void showActionRetract() {
                    final ActionRetractFactCol52 arf = makeNewActionRetractFact();
                    ActionRetractFactPopup popup = new ActionRetractFactPopup(guidedDecisionTable,
                            new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, arf, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemAction() {
                    final ActionWorkItemCol52 awi = makeNewActionWorkItem();
                    ActionWorkItemPopup popup = new ActionWorkItemPopup(clientFactory, packageUUID,
                            guidedDecisionTable, GuidedDecisionTableWidget.this, new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awi, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemActionSet() {
                    final ActionWorkItemSetFieldCol52 awisf = makeNewActionWorkItemSetField();
                    ActionWorkItemSetFieldPopup popup = new ActionWorkItemSetFieldPopup(getSCE(),
                            guidedDecisionTable, new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awisf, true, isReadOnly);
                    popup.show();
                }

                private void showActionWorkItemActionInsert() {
                    final ActionWorkItemInsertFactCol52 awiif = makeNewActionWorkItemInsertFact();
                    ActionWorkItemInsertFactPopup popup = new ActionWorkItemInsertFactPopup(getSCE(),
                            guidedDecisionTable, new GenericColumnCommand() {
                                public void execute(DTColumnConfig52 column) {
                                    newActionAdded((ActionCol52) column);
                                }
                            }, awiif, true, isReadOnly);
                    popup.show();
                }

                private void showActionBRLFragment() {
                    final BRLActionColumn column = makeNewActionBRLFragment();
                    switch (guidedDecisionTable.getTableFormat()) {
                    case EXTENDED_ENTRY:
                        BRLActionColumnViewImpl popup = new BRLActionColumnViewImpl(sce, guidedDecisionTable,
                                true, asset, column, clientFactory, eventBus);
                        popup.setPresenter(BRL_ACTION_PRESENTER);
                        popup.show();
                        break;
                    case LIMITED_ENTRY:
                        LimitedEntryBRLActionColumnViewImpl limtedEntryPopup = new LimitedEntryBRLActionColumnViewImpl(
                                sce, guidedDecisionTable, true, asset, (LimitedEntryBRLActionColumn) column,
                                clientFactory, eventBus);
                        limtedEntryPopup.setPresenter(LIMITED_ENTRY_BRL_ACTION_PRESENTER);
                        limtedEntryPopup.show();
                        break;
                    }

                }

                private void newActionAdded(ActionCol52 column) {
                    dtable.addColumn(column);
                    refreshActionsWidget();
                }
            });

            //If a separator is clicked disable OK button
            choice.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    int itemIndex = choice.getSelectedIndex();
                    if (itemIndex < 0) {
                        return;
                    }
                    ok.setEnabled(!choice.getValue(itemIndex).equals(SECTION_SEPARATOR));
                }

            });

            pop.setTitle(Constants.INSTANCE.AddNewColumn());
            pop.addAttribute(Constants.INSTANCE.TypeOfColumn(), choice);
            pop.addAttribute("", chkIncludeAdvancedOptions);
            pop.addAttribute("", ok);
            pop.show();
        }

        private ConditionCol52 makeNewConditionColumn() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryConditionCol52();
            default:
                return new ConditionCol52();
            }
        }

        private ActionInsertFactCol52 makeNewActionInsertColumn() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryActionInsertFactCol52();
            default:
                return new ActionInsertFactCol52();
            }
        }

        private ActionSetFieldCol52 makeNewActionSetColumn() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryActionSetFieldCol52();
            default:
                return new ActionSetFieldCol52();
            }
        }

        private ActionRetractFactCol52 makeNewActionRetractFact() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                LimitedEntryActionRetractFactCol52 ler = new LimitedEntryActionRetractFactCol52();
                ler.setValue(new DTCellValue52(""));
                return ler;
            default:
                return new ActionRetractFactCol52();
            }
        }

        private ActionWorkItemCol52 makeNewActionWorkItem() {
            //WorkItems are defined within the column and always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemCol52();
        }

        private ActionWorkItemSetFieldCol52 makeNewActionWorkItemSetField() {
            //Actions setting Field Values from Work Item Result Parameters are always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemSetFieldCol52();
        }

        private ActionWorkItemInsertFactCol52 makeNewActionWorkItemInsertFact() {
            //Actions setting Field Values from Work Item Result Parameters are always boolean (i.e. Limited Entry) in the table
            return new ActionWorkItemInsertFactCol52();
        }

        private BRLActionColumn makeNewActionBRLFragment() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryBRLActionColumn();
            default:
                return new BRLActionColumn();
            }
        }

        private BRLConditionColumn makeNewConditionBRLFragment() {
            switch (guidedDecisionTable.getTableFormat()) {
            case LIMITED_ENTRY:
                return new LimitedEntryBRLConditionColumn();
            default:
                return new BRLConditionColumn();
            }
        }

    });

    return addButton;
}

From source file:org.drools.guvnor.client.explorer.navigation.qa.testscenarios.MethodParameterCallValueEditor.java

License:Apache License

private TextBox boundTextBox(final CallFieldValue c) {

    final TextBox box = TextBoxFactory.getTextBox(methodParameter.type);
    box.setStyleName("constraint-value-Editor");
    if (c.value == null) {
        box.setText("");
    } else {// www .  ja v a 2  s .  c om
        if (c.value.trim().equals("")) {
            c.value = "";
        }
        box.setText(c.value);
    }

    if (c.value == null || c.value.length() < 5) {
        box.setVisibleLength(6);
    } else {
        box.setVisibleLength(c.value.length() - 1);
    }

    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            c.value = box.getText();
            if (onValueChangeCommand != null) {
                onValueChangeCommand.execute();
            }
            makeDirty();
        }

    });

    box.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            box.setVisibleLength(box.getText().length());
        }
    });

    return box;
}

From source file:org.drools.guvnor.client.explorer.navigation.qa.VerifyRulesFiredWidget.java

License:Apache License

private FlexTable render(final FixtureList rfl, final Scenario sc) {
    FlexTable data = new DirtyableFlexTable();

    for (int i = 0; i < rfl.size(); i++) {
        final VerifyRuleFired v = (VerifyRuleFired) rfl.get(i);

        if (showResults && v.getSuccessResult() != null) {
            if (!v.getSuccessResult().booleanValue()) {
                data.setWidget(i, 0, new Image(DroolsGuvnorImageResources.INSTANCE.warning()));
                data.setWidget(i, 4, new HTML(Constants.INSTANCE.ActualResult(v.getActualResult().toString())));

                data.getCellFormatter().addStyleName(i, 4, "testErrorValue"); //NON-NLS

            } else {
                data.setWidget(i, 0, new Image(DroolsGuvnorImageResources.INSTANCE.testPassed()));
            }//from   w  w  w. java2 s  . co m

        }
        data.setWidget(i, 1, new SmallLabel(v.getRuleName() + ":"));
        data.getFlexCellFormatter().setAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT,
                HasVerticalAlignment.ALIGN_MIDDLE);

        final ListBox b = new ListBox();
        b.addItem(Constants.INSTANCE.firedAtLeastOnce(), "y");
        b.addItem(Constants.INSTANCE.didNotFire(), "n");
        b.addItem(Constants.INSTANCE.firedThisManyTimes(), "e");
        final TextBox num = new TextBox();
        num.setVisibleLength(5);

        if (v.getExpectedFire() != null) {
            b.setSelectedIndex((v.getExpectedFire().booleanValue()) ? 0 : 1);
            num.setVisible(false);
        } else {
            b.setSelectedIndex(2);
            String xc = (v.getExpectedCount() != null) ? "" + v.getExpectedCount().intValue() : "0";
            num.setText(xc);
        }

        b.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                String s = b.getValue(b.getSelectedIndex());
                if (s.equals("y") || s.equals("n")) {
                    num.setVisible(false);
                    v.setExpectedFire((s.equals("y")) ? Boolean.TRUE : Boolean.FALSE);
                    v.setExpectedCount(null);
                } else {
                    num.setVisible(true);
                    v.setExpectedFire(null);
                    num.setText("1");
                    v.setExpectedCount(new Integer(1));
                }
            }
        });

        b.addItem(Constants.INSTANCE.ChooseDotDotDot());

        num.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                v.setExpectedCount(new Integer(num.getText()));
            }
        });

        HorizontalPanel h = new HorizontalPanel();
        h.add(b);
        h.add(num);
        data.setWidget(i, 2, h);

        Image del = DroolsGuvnorImages.INSTANCE.DeleteItemSmall();
        del.setAltText(Constants.INSTANCE.RemoveThisRuleExpectation());
        del.setTitle(Constants.INSTANCE.RemoveThisRuleExpectation());
        del.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent w) {
                if (Window.confirm(Constants.INSTANCE.AreYouSureYouWantToRemoveThisRuleExpectation())) {
                    rfl.remove(v);
                    sc.removeFixture(v);
                    outer.setWidget(1, 0, render(rfl, sc));
                }
            }
        });

        data.setWidget(i, 3, del);

        //we only want numbers here...
        num.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if (Character.isLetter(event.getCharCode())) {
                    ((TextBox) event.getSource()).cancelKey();
                }
            }
        });
    }
    return data;
}

From source file:org.drools.guvnor.client.modeldriven.ui.ConstraintValueEditor.java

License:Apache License

private TextBox boundTextBox(final ISingleFieldConstraint c) {
    final TextBox box = new TextBox();
    box.setStyleName("constraint-value-Editor");
    if (c.value == null) {
        box.setText("");
    } else {/*from  www . j  a  va  2  s.c  o  m*/
        box.setText(c.value);
    }

    if (c.value == null || c.value.length() < 5) {
        box.setVisibleLength(6);
    } else {
        box.setVisibleLength(c.value.length() - 1);
    }

    box.addChangeListener(new ChangeListener() {
        public void onChange(Widget w) {
            c.value = box.getText();
            makeDirty();
        }

    });

    box.addKeyboardListener(new FieldEditListener(new Command() {
        public void execute() {
            box.setVisibleLength(box.getText().length());
        }
    }));

    return box;
}

From source file:org.drools.guvnor.client.modeldriven.ui.MethodParameterValueEditor.java

License:Apache License

private TextBox boundTextBox(final ActionFieldValue c) {
    final TextBox box = new TextBox();
    box.setStyleName("constraint-value-Editor");
    if (c.value == null) {
        box.setText("");
    } else {//w  w  w . ja v  a 2  s. co m
        if (c.value.trim().equals("")) {
            c.value = "";
        }
        box.setText(c.value);
    }

    if (c.value == null || c.value.length() < 5) {
        box.setVisibleLength(6);
    } else {
        box.setVisibleLength(c.value.length() - 1);
    }

    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            c.value = box.getText();
            if (onValueChangeCommand != null) {
                onValueChangeCommand.execute();
            }
            makeDirty();
        }

    });

    box.addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            box.setVisibleLength(box.getText().length());
        }
    });

    if (methodParameter.type.equals(SuggestionCompletionEngine.TYPE_NUMERIC)) {
        box.addKeyPressHandler(new NumbericFilterKeyPressHandler(box));
    }

    return box;
}