Search in sources :

Example 16 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project perun by CESNET.

the class SuggestBox method addEventsToTextBox.

private void addEventsToTextBox() {
    class TextBoxEvents extends HandlesAllKeyEvents implements ValueChangeHandler<String> {

        public void onKeyDown(KeyDownEvent event) {
            switch(event.getNativeKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    display.moveSelectionDown();
                    break;
                case KeyCodes.KEY_UP:
                    display.moveSelectionUp();
                    break;
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_TAB:
                    Suggestion suggestion = display.getCurrentSelection();
                    if (suggestion == null) {
                        display.hideSuggestions();
                    } else {
                        setNewSelection(suggestion);
                    }
                    break;
            }
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyPress(KeyPressEvent event) {
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyUp(KeyUpEvent event) {
            // After every user key input, refresh the popup's suggestions.
            refreshSuggestions();
            delegateEvent(SuggestBox.this, event);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            delegateEvent(SuggestBox.this, event);
        }
    }
    TextBoxEvents events = new TextBoxEvents();
    events.addKeyHandlersTo(box);
    box.addValueChangeHandler(events);
}
Also used : Suggestion(com.google.gwt.user.client.ui.SuggestOracle.Suggestion) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) HandlesAllKeyEvents(com.google.gwt.event.dom.client.HandlesAllKeyEvents) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)

Example 17 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project perun by CESNET.

the class AddFacilityDestinationTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add destination");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    layout.setWidth("350px");
    final ExtendedSuggestBox destination = new ExtendedSuggestBox();
    final ListBox type = new ListBox();
    type.addItem("HOST", "host");
    type.addItem("USER@HOST", "user@host");
    type.addItem("USER@HOST:PORT", "user@host:port");
    type.addItem("URL", "url");
    type.addItem("MAIL", "email");
    type.addItem("SIGNED MAIL", "semail");
    type.addItem("SERVICE SPECIFIC", "service-specific");
    final ListBoxWithObjects<Service> services = new ListBoxWithObjects<Service>();
    final CheckBox useHosts = new CheckBox(WidgetTranslation.INSTANCE.useFacilityHostnames(), false);
    useHosts.setTitle(WidgetTranslation.INSTANCE.useFacilityHostnamesTitle());
    final CheckBox onlyAssignedServices = new CheckBox("Show only services on facility", false);
    onlyAssignedServices.setTitle("Click to show all possible services");
    onlyAssignedServices.setValue(true);
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDestination());
    // fill oracle with hosts of facility
    GetHosts getHosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Host> ho = JsonUtils.jsoAsList(jso);
            for (Host h : ho) {
                hosts.addAll(ho);
                destination.getSuggestOracle().add(h.getName());
            }
        }
    });
    getHosts.retrieveData();
    JsonCallbackEvents fillAssignedServices = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            services.removeAllOption();
            services.clear();
            ArrayList<Service> ses = JsonUtils.jsoAsList(jso);
            if (ses != null && !ses.isEmpty()) {
                ses = new TableSorter<Service>().sortByName(ses);
                services.addAllItems(ses);
                services.addAllOption();
                services.setSelectedIndex(0);
            } else {
                services.addItem("No service available");
            }
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            services.removeAllOption();
            services.clear();
            services.addItem("Error while loading");
            addButton.setEnabled(true);
            type.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            services.removeAllOption();
            services.clear();
            services.addItem("Loading...");
            addButton.setEnabled(false);
            type.setEnabled(false);
        }
    };
    final GetFacilityAssignedServices getAssignedServices = new GetFacilityAssignedServices(facility.getId(), fillAssignedServices);
    getAssignedServices.retrieveData();
    final GetServices getAllServices = new GetServices(fillAssignedServices);
    onlyAssignedServices.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (onlyAssignedServices.getValue() == false) {
                onlyAssignedServices.setTitle("Click to show only services on facility");
                getAllServices.retrieveData();
            } else {
                onlyAssignedServices.setTitle("Click to show all possible services");
                getAssignedServices.retrieveData();
            }
        }
    });
    final Label destinationLabel = new Label();
    destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
    final ExtendedSuggestBox.SuggestBoxValidator validator = new ExtendedSuggestBox.SuggestBoxValidator() {

        @Override
        public boolean validateSuggestBox() {
            if (destination.getSuggestBox().getText().trim().isEmpty() && useHosts.getValue() == false) {
                destination.setError("Destination value can't be empty.");
                return false;
            }
            // check as email
            if (type.getSelectedIndex() > 3 && type.getSelectedIndex() < 6) {
                if (!JsonUtils.isValidEmail(destination.getSuggestBox().getText().trim())) {
                    destination.setError("Not valid email address.");
                    return false;
                } else {
                    destination.setOk();
                    return true;
                }
            }
            destination.setOk();
            return true;
        }
    };
    destination.setValidator(validator);
    type.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // if hosts - checkbox visible
            if (type.getSelectedIndex() == 0) {
                useHosts.setVisible(true);
            } else {
                useHosts.setVisible(false);
                useHosts.setValue(false);
                destination.getSuggestBox().setEnabled(true);
            }
            if (type.getSelectedIndex() < 3) {
                destination.getSuggestOracle().clear();
                for (Host h : hosts) {
                    destination.getSuggestOracle().add(h.getName());
                }
            } else {
                destination.getSuggestOracle().clear();
            }
            // set label
            if (type.getSelectedIndex() == 0) {
                destinationLabel.getElement().setInnerHTML("<strong>Host:</strong>");
            } else if (type.getSelectedIndex() == 1) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:</strong>");
            } else if (type.getSelectedIndex() == 2) {
                destinationLabel.getElement().setInnerHTML("<strong>User@host:port:</strong>");
            } else if (type.getSelectedIndex() == 3) {
                destinationLabel.getElement().setInnerHTML("<strong>URL:</strong>");
            } else if (type.getSelectedIndex() == 4) {
                destinationLabel.getElement().setInnerHTML("<strong>Mail:</strong>");
            } else if (type.getSelectedIndex() == 5) {
                destinationLabel.getElement().setInnerHTML("<strong>Signed mail:</strong>");
            } else if (type.getSelectedIndex() == 6) {
                destinationLabel.getElement().setInnerHTML("<strong>Service specific:</strong>");
            }
            // run validation
            validator.validateSuggestBox();
        }
    });
    useHosts.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (useHosts.getValue() == true) {
                destination.getSuggestBox().setEnabled(false);
                destination.setOk();
            } else {
                destination.getSuggestBox().setEnabled(true);
            }
        }
    });
    cellFormatter.setColSpan(0, 0, 2);
    HTML text = new HTML("Please add destinations for service configuration delivery. New service configuration can be performed directly on facility (dest. type HOST) or sent to URL or by an email.");
    text.setStyleName("inputFormInlineComment");
    layout.setWidget(0, 0, text);
    layout.setHTML(1, 0, "Service:");
    layout.setWidget(1, 1, services);
    layout.setWidget(2, 1, onlyAssignedServices);
    layout.setHTML(3, 0, "Type:");
    layout.setWidget(3, 1, type);
    layout.setWidget(4, 0, destinationLabel);
    layout.setWidget(4, 1, destination);
    layout.setWidget(5, 1, useHosts);
    for (int i = 1; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    menu.addWidget(addButton);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (services.isEmpty()) {
                // no services available
                addButton.setEnabled(false);
            }
            if (validator.validateSuggestBox()) {
                if (services.getSelectedIndex() == 0) {
                    // selected all
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestinationByHosts(services.getAllObjects());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getAllObjects());
                    }
                } else {
                    // selected one
                    if (useHosts.getValue() == true) {
                        // auto by hosts
                        AddDestinationsByHostsOnFacility request = new AddDestinationsByHostsOnFacility(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestinationByHosts(services.getSelectedObject());
                    } else {
                        // default
                        AddDestination request = new AddDestination(facility, JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                        request.addDestination(destination.getSuggestBox().getText().trim(), type.getValue(type.getSelectedIndex()), services.getSelectedObject());
                    }
                }
            }
        }
    });
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TableSorter(cz.metacentrum.perun.webgui.client.resources.TableSorter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Service(cz.metacentrum.perun.webgui.model.Service) Host(cz.metacentrum.perun.webgui.model.Host) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 18 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class AuditLogViewImpl method makeEventTypeCheckBox.

private Widget makeEventTypeCheckBox(final String eventType, final Boolean isEnabled) {
    final CheckBox chkEventType = new CheckBox(AuditLogEntryCellHelper.getEventTypeDisplayText(eventType));
    chkEventType.setValue(Boolean.TRUE.equals(isEnabled));
    chkEventType.addValueChangeHandler((ValueChangeEvent<Boolean> event) -> {
        auditLog.getAuditLogFilter().getAcceptedTypes().put(eventType, event.getValue());
    });
    // BZ-996942: Use one column layout.
    chkEventType.setWordWrap(false);
    return new Column(ColumnSize.MD_2) {

        {
            add(chkEventType);
        }
    };
}
Also used : ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Column(org.gwtbootstrap3.client.ui.Column) CheckBox(org.gwtbootstrap3.client.ui.CheckBox)

Example 19 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class ConstraintValueEditor method returnValueEditor.

/**
 * An editor for the retval "formula" (expression).
 */
private Widget returnValueEditor() {
    TextBox box = new BoundTextBox(constraint);
    if (this.readOnly) {
        return new SmallLabel(box.getText());
    }
    String msg = GuidedRuleEditorResources.CONSTANTS.FormulaEvaluateToAValue();
    Image img = new Image(GuidedRuleEditorResources.INSTANCE.images().functionAssets());
    img.setTitle(msg);
    box.setTitle(msg);
    box.addValueChangeHandler(new ValueChangeHandler<String>() {

        public void onValueChange(final ValueChangeEvent event) {
            executeOnValueChangeCommand();
        }
    });
    Widget ed = widgets(img, box);
    return ed;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) IsWidget(com.google.gwt.user.client.ui.IsWidget) Widget(com.google.gwt.user.client.ui.Widget) TextBox(org.gwtbootstrap3.client.ui.TextBox) Image(com.google.gwt.user.client.ui.Image)

Example 20 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class Connectives method connectiveOperatorDropDown.

private void connectiveOperatorDropDown(final ConnectiveConstraint cc, final Callback<Widget> callback) {
    if (!isReadOnly) {
        final String factType = cc.getFactType();
        final String fieldName = cc.getFieldName();
        this.getDataModelOracle().getConnectiveOperatorCompletions(factType, fieldName, new Callback<String[]>() {

            @Override
            public void callback(final String[] operators) {
                final CEPOperatorsDropdown dropdown = getDropdown(operators, cc);
                dropdown.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), "");
                dropdown.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {

                    public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
                        OperatorSelection selection = event.getValue();
                        String selected = selection.getValue();
                        cc.setOperator(selected);
                    }
                });
                callback.callback(dropdown);
            }
        });
    } else {
        final SmallLabel w = new SmallLabel("<b>" + (cc.getOperator() == null ? GuidedRuleEditorResources.CONSTANTS.pleaseChoose() : HumanReadable.getOperatorDisplayName(cc.getOperator())) + "</b>");
        callback.callback(w);
    }
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) OperatorSelection(org.drools.workbench.screens.guided.rule.client.editor.OperatorSelection) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)

Aggregations

ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)20 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)18 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)10 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 TextBox (org.gwtbootstrap3.client.ui.TextBox)5 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)4 Widget (com.google.gwt.user.client.ui.Widget)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 DatePicker (org.uberfire.ext.widgets.common.client.common.DatePicker)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)2 Image (com.google.gwt.user.client.ui.Image)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)2 Label (com.google.gwt.user.client.ui.Label)2