Search in sources :

Example 1 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class AddExecServiceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create exec service");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    layout.setWidth("350px");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // define objects
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createExecService());
    Label serviceLabel = new Label();
    serviceLabel.setText(service.getName() + " (" + serviceId + ")");
    final ListBox type = new ListBox();
    type.addItem("GENERATE", "GENERATE");
    type.addItem("SEND", "SEND");
    final VerticalPanel fp = new VerticalPanel();
    final RadioButton radio1 = new RadioButton("rd-type", "GENERATE + SEND");
    final RadioButton radio2 = new RadioButton("rd-type", "GENERATE");
    final RadioButton radio3 = new RadioButton("rd-type", "SEND");
    radio1.setValue(true);
    fp.add(radio1);
    fp.add(radio2);
    fp.add(radio3);
    final CheckBox enabled = new CheckBox();
    enabled.setText("Enabled / Disabled");
    enabled.setValue(true);
    final ExtendedTextBox delay = new ExtendedTextBox();
    delay.getTextBox().setText(DEFAULT_DELAY);
    final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
                delay.setError("Delay must be a number (time in minutes) !");
                return false;
            } else {
                delay.setOk();
                return true;
            }
        }
    };
    delay.setValidator(delayValidator);
    final ExtendedTextBox scriptPath = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (scriptPath.getTextBox().getText().trim().isEmpty()) {
                scriptPath.setError("Script path can't be empty !");
                return false;
            } else {
                scriptPath.setOk();
                return true;
            }
        }
    };
    scriptPath.setValidator(scriptValidator);
    // put default path
    scriptPath.getTextBox().setValue("./" + service.getName());
    // layout
    layout.setHTML(0, 0, "Service:");
    layout.setHTML(1, 0, "Type:");
    layout.setHTML(2, 0, "Status:");
    layout.setHTML(3, 0, "Delay:");
    layout.setHTML(4, 0, "Script path:");
    layout.setWidget(0, 1, serviceLabel);
    layout.setWidget(1, 1, fp);
    layout.setWidget(2, 1, enabled);
    layout.setWidget(3, 1, delay);
    layout.setWidget(4, 1, scriptPath);
    // send button
    createButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (delayValidator.validateTextBox() && scriptValidator.validateTextBox()) {
                int delayNum = Integer.parseInt(delay.getTextBox().getText().trim());
                InsertExecService request = new InsertExecService(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
                if (radio1.getValue()) {
                    request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
                    request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
                } else if (radio2.getValue()) {
                    request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
                } else if (radio3.getValue()) {
                    request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
                }
            }
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(createButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : InsertExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.InsertExecService) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 2 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class EditExecServiceTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit ExecService");
    VerticalPanel vp = new VerticalPanel();
    final CheckBox enabled = new CheckBox();
    enabled.setText("Enabled / Disabled");
    enabled.setValue(execService.isEnabled());
    final ExtendedTextBox delay = new ExtendedTextBox();
    delay.getTextBox().setText("" + execService.getDefaultDelay());
    final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
                delay.setError("Delay must be a number (time in minutes) !");
                return false;
            } else {
                delay.setOk();
                return true;
            }
        }
    };
    delay.setValidator(delayValidator);
    final ExtendedTextBox scriptPath = new ExtendedTextBox();
    scriptPath.getTextBox().setValue(execService.getScriptPath());
    final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (scriptPath.getTextBox().getText().trim().isEmpty()) {
                scriptPath.setError("Script path can't be empty !");
                return false;
            } else {
                scriptPath.setOk();
                return true;
            }
        }
    };
    scriptPath.setValidator(scriptValidator);
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes of ExecService");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!scriptValidator.validateTextBox() && !delayValidator.validateTextBox())
                return;
            ExecService es = JsonUtils.clone(execService).cast();
            es.setEnabled(enabled.getValue());
            es.setDefaultDelay(Integer.parseInt(delay.getTextBox().getValue().trim()));
            es.setScriptPath(scriptPath.getTextBox().getValue().trim());
            UpdateExecService request = new UpdateExecService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
            request.updateExecService(es);
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    // Add some standard form options
    layout.setHTML(0, 0, "Enabled:");
    layout.setWidget(0, 1, enabled);
    layout.setHTML(1, 0, "Script path:");
    layout.setWidget(1, 1, scriptPath);
    layout.setHTML(2, 0, "Delay:");
    layout.setWidget(2, 1, delay);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(saveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) ExecService(cz.metacentrum.perun.webgui.model.ExecService) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) UpdateExecService(cz.metacentrum.perun.webgui.json.generalServiceManager.UpdateExecService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 3 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class CreateAttributeDefinitionTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // creates HTML elements
    final ExtendedTextBox attributeDisplayName = new ExtendedTextBox();
    final ExtendedTextBox attributeName = new ExtendedTextBox();
    final ExtendedTextBox attributeDescription = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (attributeName.getTextBox().getText().trim().isEmpty()) {
                attributeName.setError("Name of attribute can't be empty.");
            } else if (!attributeName.getTextBox().getText().trim().matches(Utils.ATTRIBUTE_FRIENDLY_NAME_MATCHER)) {
                attributeName.setError("Name of attribute can contain only letters, numbers, dash and colon.");
            } else {
                attributeName.setOk();
                return true;
            }
            return false;
        }
    };
    final ExtendedTextBox.TextBoxValidator descriptionValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDescription.getTextBox().getText().trim().isEmpty()) {
                attributeDescription.setOk();
                return true;
            } else {
                attributeDescription.setError("Description of attribute can't be empty.");
                return false;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator displayNameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDisplayName.getTextBox().getText().trim().isEmpty()) {
                attributeDisplayName.setOk();
                return true;
            } else {
                attributeDisplayName.setError("Display name of attribute can't be empty.");
                return false;
            }
        }
    };
    attributeName.setValidator(nameValidator);
    attributeDisplayName.setValidator(displayNameValidator);
    attributeDescription.setValidator(descriptionValidator);
    final ListBox entityListBox = new ListBox();
    final ListBox definitionListBox = new ListBox();
    final ListBox typeListBox = new ListBox();
    // fill listboxs with pre-defined values
    entityListBox.addItem("facility", "urn:perun:facility:");
    entityListBox.addItem("resource", "urn:perun:resource:");
    entityListBox.addItem("group", "urn:perun:group:");
    entityListBox.addItem("group_resource", "urn:perun:group_resource:");
    entityListBox.addItem("host", "urn:perun:host:");
    entityListBox.addItem("member", "urn:perun:member:");
    entityListBox.addItem("member_group", "urn:perun:member_group:");
    entityListBox.addItem("member_resource", "urn:perun:member_resource:");
    entityListBox.addItem("user", "urn:perun:user:");
    entityListBox.addItem("user_ext_source", "urn:perun:ues:");
    entityListBox.addItem("user_facility", "urn:perun:user_facility:");
    entityListBox.addItem("vo", "urn:perun:vo:");
    entityListBox.addItem("entityless", "urn:perun:entityless:");
    definitionListBox.addItem("def", "attribute-def:def");
    definitionListBox.addItem("opt", "attribute-def:opt");
    definitionListBox.addItem("virt", "attribute-def:virt");
    definitionListBox.addItem("core", "attribute-def:core");
    typeListBox.addItem("String", "java.lang.String");
    typeListBox.addItem("Integer", "java.lang.Integer");
    typeListBox.addItem("Boolean", "java.lang.Boolean");
    typeListBox.addItem("Array", "java.util.ArrayList");
    typeListBox.addItem("LinkedHashMap", "java.util.LinkedHashMap");
    // prepare layout for this tab
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    TabMenu menu = new TabMenu();
    // BUTTONS
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createAttributeDefinition());
    menu.addWidget(createButton);
    // close tab events & enable, disable buttons
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(createButton, this, true);
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (nameValidator.validateTextBox() && descriptionValidator.validateTextBox() && displayNameValidator.validateTextBox()) {
                String displayName = attributeDisplayName.getTextBox().getText().trim();
                String friendlyName = attributeName.getTextBox().getText().trim();
                String description = attributeDescription.getTextBox().getText().trim();
                String namespace = entityListBox.getValue(entityListBox.getSelectedIndex()) + definitionListBox.getValue(definitionListBox.getSelectedIndex());
                String type = typeListBox.getValue(typeListBox.getSelectedIndex());
                boolean isUnique = unique.getValue();
                CreateAttribute request = new CreateAttribute(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        AttributeDefinition a = jso.cast();
                        ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
                        AttributeRights right = AttributeRights.create(a.getId(), "SELF");
                        list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, right));
                        AttributeRights right2 = AttributeRights.create(a.getId(), "VOADMIN");
                        list.add(getRightsFromWidgets(voRead, voWrite, right2));
                        AttributeRights right3 = AttributeRights.create(a.getId(), "GROUPADMIN");
                        list.add(getRightsFromWidgets(groupRead, groupWrite, right3));
                        AttributeRights right4 = AttributeRights.create(a.getId(), "FACILITYADMIN");
                        list.add(getRightsFromWidgets(facilityRead, facilityWrite, right4));
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                                closeTabEvents.onFinished(jso);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.createAttributeDefinition(displayName, friendlyName, description, namespace, type, isUnique);
            }
        }
    });
    // insert layout
    layout.setHTML(0, 0, "Friendly name:");
    layout.setWidget(0, 1, attributeName);
    layout.setHTML(1, 0, "Display name:");
    layout.setWidget(1, 1, attributeDisplayName);
    layout.setHTML(2, 0, "Description:");
    layout.setWidget(2, 1, attributeDescription);
    layout.setHTML(3, 0, "Entity:");
    layout.setWidget(3, 1, entityListBox);
    layout.setHTML(4, 0, "Definition type:");
    layout.setWidget(4, 1, definitionListBox);
    layout.setHTML(5, 0, "Value type:");
    layout.setWidget(5, 1, typeListBox);
    layout.setHTML(6, 0, "Unique:");
    layout.setWidget(6, 1, unique);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    vp.add(layout);
    vp.add(rightsTable);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) CreateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.CreateAttribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)

Example 4 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class EditServiceDetailsTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit service");
    VerticalPanel vp = new VerticalPanel();
    final ExtendedTextBox serviceName = new ExtendedTextBox();
    final ExtendedTextBox serviceDescription = new ExtendedTextBox();
    final ExtendedTextBox scriptPath = new ExtendedTextBox();
    final CheckBox enabled = new CheckBox();
    final ExtendedTextBox delay = new ExtendedTextBox();
    final ExtendedTextBox recurrence = new ExtendedTextBox();
    serviceName.getTextBox().setText(service.getName());
    serviceDescription.getTextBox().setText(service.getDescription());
    scriptPath.getTextBox().setText(service.getScriptPath());
    enabled.setValue(service.isEnabled());
    delay.getTextBox().setText(String.valueOf(service.getDelay()));
    recurrence.getTextBox().setText(String.valueOf(service.getRecurrence()));
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceName.getTextBox().getText().trim().isEmpty()) {
                serviceName.setError("Name can't be empty");
                return false;
            } else if (!serviceName.getTextBox().getText().trim().matches(Utils.SERVICE_NAME_MATCHER)) {
                serviceName.setError("Name can contain only letters, numbers and underscore.");
                return false;
            } else {
                serviceName.setOk();
                // fill script path on service name change
                scriptPath.getTextBox().setValue("./" + serviceName.getTextBox().getText().trim().toLowerCase().replaceAll(Utils.SERVICE_NAME_TO_SCRIP_PATH_MATCHER, "_"));
                return true;
            }
        }
    };
    serviceName.setValidator(validator);
    enabled.setText("Enabled / Disabled");
    final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
                delay.setError("Delay must be a number (time in minutes) !");
                return false;
            } else {
                delay.setOk();
                return true;
            }
        }
    };
    delay.setValidator(delayValidator);
    final ExtendedTextBox.TextBoxValidator recurrenceValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
                recurrence.setError("Recurrence must be a number!");
                return false;
            } else {
                recurrence.setOk();
                return true;
            }
        }
    };
    recurrence.setValidator(recurrenceValidator);
    final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (scriptPath.getTextBox().getText().trim().isEmpty()) {
                scriptPath.setError("Script path can't be empty !");
                return false;
            } else {
                scriptPath.setOk();
                return true;
            }
        }
    };
    scriptPath.setValidator(scriptValidator);
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    // send button
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveServiceDetails());
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (validator.validateTextBox() && delayValidator.validateTextBox() && scriptValidator.validateTextBox() && recurrenceValidator.validateTextBox()) {
                Service serv = JsonUtils.clone(service).cast();
                serv.setName(serviceName.getTextBox().getText().trim());
                String desc = serviceDescription.getTextBox().getText().trim();
                if (desc.isEmpty())
                    desc = null;
                serv.setDescription(desc);
                serv.setDelay(Integer.parseInt(delay.getTextBox().getText().trim()));
                serv.setRecurrence(Integer.parseInt(recurrence.getTextBox().getText().trim()));
                serv.setEnabled(enabled.getValue());
                serv.setScriptPath(scriptPath.getTextBox().getText().trim());
                UpdateService request = new UpdateService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, true, events));
                request.updateService(serv);
            }
        }
    });
    // cancel button
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    });
    // Add some standard form options
    // fill form
    layout.setHTML(0, 0, "Name:");
    layout.setHTML(1, 0, "Description:");
    layout.setHTML(2, 0, "Status:");
    layout.setHTML(3, 0, "Delay:");
    layout.setHTML(4, 0, "Recurrence:");
    layout.setHTML(5, 0, "Script path:");
    layout.setWidget(0, 1, serviceName);
    layout.setWidget(1, 1, serviceDescription);
    layout.setWidget(2, 1, enabled);
    layout.setWidget(3, 1, delay);
    layout.setWidget(4, 1, recurrence);
    layout.setWidget(5, 1, scriptPath);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(saveButton);
    menu.addWidget(cancelButton);
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Label(com.google.gwt.user.client.ui.Label) FlexTable(com.google.gwt.user.client.ui.FlexTable) Service(cz.metacentrum.perun.webgui.model.Service) UpdateService(cz.metacentrum.perun.webgui.json.servicesManager.UpdateService) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) UpdateService(cz.metacentrum.perun.webgui.json.servicesManager.UpdateService) CheckBox(com.google.gwt.user.client.ui.CheckBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 5 with ExtendedTextBox

use of cz.metacentrum.perun.webgui.widgets.ExtendedTextBox in project perun by CESNET.

the class AddSecurityTeamManagerTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add member");
    final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
    this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            ArrayList<User> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                users.getSelectionModel().setSelected(list.get(0), true);
            }
        }
    }));
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<User> table;
    if (session.isPerunAdmin()) {
        table = users.getTable(new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
    } else {
        table = users.getTable();
    }
    rebuildAlreadyAddedWidget();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToSecurityTeam());
    final TabItem tab = this;
    // search textbox
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            startSearching(text);
            searchString = text;
        }
    }, searchButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // FIXME - Should have only one callback to core
                    final int n = i;
                    AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // put names to already added
                            alreadyAddedList.add(list.get(n));
                            rebuildAlreadyAddedWidget();
                            // unselect added person
                            users.getSelectionModel().setSelected(list.get(n), false);
                            // clear search
                            searchBox.getTextBox().setText("");
                        }
                    }));
                    request.addSecurityTeamAdmin(securityTeam, list.get(i));
                }
            }
        }
    });
    // if some text has been searched before
    if (!searchString.equals("")) {
        searchBox.getTextBox().setText(searchString);
        startSearching(searchString);
    }
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(alreadyAdded);
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) User(cz.metacentrum.perun.webgui.model.User) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ArrayList(java.util.ArrayList) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) AddAdmin(cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)34 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)34 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)33 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)32 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)32 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)31 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)18 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)18 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)15 ArrayList (java.util.ArrayList)13 PerunError (cz.metacentrum.perun.webgui.model.PerunError)9 User (cz.metacentrum.perun.webgui.model.User)8 FindCompleteRichUsers (cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers)7 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)6 UserDetailTabItem (cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem)5 AddAdmin (cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin)4 ImageResource (com.google.gwt.resources.client.ImageResource)3 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)3 SetAttributeRights (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)3 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)3