Search in sources :

Example 46 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class AddUserExtSourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add ext. identity");
    VerticalPanel vp = new VerticalPanel();
    // get available ext sources
    final ListBoxWithObjects<ExtSource> extSourcesDropDown = new ListBoxWithObjects<ExtSource>();
    final TextBox externalLogin = new TextBox();
    final TextBox loaTextBox = new TextBox();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add external identity to user");
    // fill listbox
    JsonCallbackEvents fillEvent = new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            extSourcesDropDown.clear();
            extSourcesDropDown.addItem("Error while loading");
            callDone = false;
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            extSourcesDropDown.clear();
            ArrayList<ExtSource> list = JsonUtils.jsoAsList(jso);
            list = new TableSorter<ExtSource>().sortByName(list);
            if (list == null || list.isEmpty()) {
                extSourcesDropDown.addItem("No external sources available");
                return;
            }
            for (ExtSource ex : list) {
                extSourcesDropDown.addItem(ex);
            }
            callDone = true;
            if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
                addButton.setEnabled(true);
            }
        }

        @Override
        public void onLoadingStart() {
            extSourcesDropDown.clear();
            extSourcesDropDown.addItem("Loading...");
            callDone = false;
        }
    };
    // callback
    final GetExtSources extSources = new GetExtSources(fillEvent);
    extSources.retrieveData();
    // create layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "External login:");
    layout.setWidget(0, 1, externalLogin);
    layout.setHTML(1, 0, "External source:");
    layout.setWidget(1, 1, extSourcesDropDown);
    layout.setHTML(2, 0, "Level of Assurance:");
    layout.setWidget(2, 1, loaTextBox);
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.setStyleName(i, 0, "itemName");
    }
    cellFormatter.setStyleName(3, 1, "inputFormInlineComment");
    layout.setHTML(3, 1, "0 - not verified = default</br>1 - verified email</br>2 - verified identity</br>3 - verified identity, strict password strength");
    TabMenu menu = new TabMenu();
    // close tab events
    final JsonCallbackEvents addExtSrcEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, this);
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ExtSource selected = extSourcesDropDown.getObjectAt(extSourcesDropDown.getSelectedIndex());
            String login = externalLogin.getText();
            AddUserExtSource request = new AddUserExtSource(addExtSrcEvents);
            int loa = 0;
            if (JsonUtils.checkParseInt(loaTextBox.getText())) {
                loa = Integer.parseInt(loaTextBox.getText());
            } else {
                JsonUtils.cantParseIntConfirm("Level of Assurance", loaTextBox.getText());
                return;
            }
            request.addUserExtSource(userId, login.trim(), selected, loa);
        }
    });
    addButton.setEnabled(false);
    menu.addWidget(addButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab);
        }
    }));
    KeyUpHandler handler = new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
                addButton.setEnabled(true);
            } else {
                addButton.setEnabled(false);
            }
        }
    };
    externalLogin.addKeyUpHandler(handler);
    loaTextBox.addKeyUpHandler(handler);
    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) GetExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetExtSources) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) AddUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.AddUserExtSource) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.AddUserExtSource) ExtSource(cz.metacentrum.perun.webgui.model.ExtSource) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 47 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class VoResourcesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources state");
    final TabItem tab = this;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    final CustomButton cb = UiElements.getRefreshButton(this);
    help.setWidget(0, 0, cb);
    help.getFlexCellFormatter().setWidth(0, 0, "80px");
    help.setHTML(0, 1, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 1, "100px");
    help.setHTML(0, 2, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "green");
    help.setHTML(0, 3, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setStyleName(0, 3, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 4, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 4, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 4, "notdetermined");
    /*
			 help.setHTML(0, 5, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 5, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 5, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 5, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    help.setHTML(0, 5, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetAllResourcesState callback = new GetAllResourcesState(voId, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<ResourceState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<ResourceState>().sortByResourceName(list);
                for (final ResourceState state : list) {
                    content.setHTML(mainrow, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()) + "<span class=\"now-managing\" style=\"display: inline-block; position: relative; top: -8px;\">" + state.getResource().getName() + "</span>");
                    ArrayList<Task> tasks = new TableSorter<Task>().sortByService(JsonUtils.<Task>jsoAsList(state.getTasks()));
                    if (tasks == null || tasks.isEmpty())
                        notDeterminedCounter++;
                    boolean allOk = true;
                    for (Task tsk : tasks) {
                        if (tsk.getStatus().equalsIgnoreCase("ERROR")) {
                            errorCounter++;
                            allOk = false;
                            break;
                        }
                    }
                    if (allOk && tasks != null && !tasks.isEmpty())
                        okCounter++;
                    ListDataProvider<Task> dataProvider = new ListDataProvider<Task>();
                    PerunTable<Task> table;
                    // Table data provider.
                    dataProvider = new ListDataProvider<Task>(tasks);
                    // Cell table
                    table = new PerunTable<Task>(tasks);
                    table.removeRowCountChangeHandler();
                    // Connect the table to the data provider.
                    dataProvider.addDataDisplay(table);
                    // Sorting
                    ColumnSortEvent.ListHandler<Task> columnSortHandler = new ColumnSortEvent.ListHandler<Task>(dataProvider.getList());
                    table.addColumnSortHandler(columnSortHandler);
                    // set empty content & loader
                    AjaxLoaderImage loaderImage = new AjaxLoaderImage();
                    loaderImage.setEmptyResultMessage("No service configuration was propagated to this resource.");
                    table.setEmptyTableWidget(loaderImage);
                    loaderImage.loadingFinished();
                    table.addIdColumn("Task Id");
                    // Service column
                    Column<Task, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {

                        public String getValue(Task task) {
                            return String.valueOf(task.getExecService().getService().getName());
                        }
                    }, null);
                    // status column
                    Column<Task, String> statusColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {

                        public String getValue(Task task) {
                            return String.valueOf(task.getStatus());
                        }
                    }, null);
                    // start COLUMN
                    TextColumn<Task> startTimeColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getStartTime();
                        }
                    };
                    // end COLUMN
                    TextColumn<Task> endTimeColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getEndTime();
                        }
                    };
                    // schedule COLUMN
                    TextColumn<Task> scheduleColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getSchedule();
                        }
                    };
                    // Add the columns.
                    table.addColumn(serviceColumn, "Service");
                    table.addColumn(statusColumn, "Status");
                    table.addColumn(scheduleColumn, "Scheduled");
                    table.addColumn(startTimeColumn, "Started");
                    table.addColumn(endTimeColumn, "Ended");
                    // set row styles based on task state
                    table.setRowStyles(new RowStyles<Task>() {

                        public String getStyleNames(Task row, int rowIndex) {
                            if (row.getStatus().equalsIgnoreCase("NONE")) {
                                return "rowdarkgreen";
                            } else if (row.getStatus().equalsIgnoreCase("DONE")) {
                                return "rowgreen";
                            } else if (row.getStatus().equalsIgnoreCase("PROCESSING")) {
                                return "rowyellow";
                            } else if (row.getStatus().equalsIgnoreCase("ERROR")) {
                                return "rowred";
                            }
                            return "";
                        }
                    });
                    table.setWidth("100%");
                    content.setWidget(mainrow + 1, 0, table);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    mainrow++;
                    mainrow++;
                }
            }
            // set counters
            help.setHTML(0, 2, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 4, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        //help.setHTML(0, 5, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities for VO
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ListDataProvider(com.google.gwt.view.client.ListDataProvider) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ArrayList(java.util.ArrayList) GetAllResourcesState(cz.metacentrum.perun.webgui.json.propagationStatsReader.GetAllResourcesState) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) TextColumn(com.google.gwt.user.cellview.client.TextColumn) PerunTable(cz.metacentrum.perun.webgui.widgets.PerunTable) RowStyles(com.google.gwt.user.cellview.client.RowStyles) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 48 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class AddVoManagerTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add manager");
    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.addSelectedManagersToVo());
    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, !alreadyAddedList.isEmpty());
        }
    }));
    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.addVoAdmin(vo, 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) 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)

Example 49 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class EditVoDetailsTabItem method draw.

public Widget draw() {
    titleWidget = new Label("Edit VO name");
    VerticalPanel vp = new VerticalPanel();
    // textboxes which set the class data when updated
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    nameTextBox.getTextBox().setText(vo.getName());
    nameTextBox.getTextBox().setMaxLength(128);
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setOk();
                return true;
            } else {
                nameTextBox.setError("Name can't be empty.");
                return false;
            }
        }
    };
    nameTextBox.setValidator(nameValidator);
    // 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 VO name");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (!nameValidator.validateTextBox())
                return;
            VirtualOrganization v = JsonUtils.clone(vo).cast();
            v.setName(nameTextBox.getTextBox().getText().trim());
            UpdateVo request = new UpdateVo(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
            request.updateVo(v);
        }
    });
    // 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, "Short name:");
    layout.setHTML(0, 1, vo.getShortName());
    layout.setHTML(1, 0, "Name:");
    layout.setWidget(1, 1, nameTextBox);
    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) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) UpdateVo(cz.metacentrum.perun.webgui.json.vosManager.UpdateVo) 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 50 with TabItem

use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.

the class CreateCategoryTabItem method draw.

public Widget draw() {
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final CustomButton addCategory = TabMenu.getPredefinedButton(ButtonType.ADD, "Add category");
    menu.addWidget(addCategory);
    FlexTable table = new FlexTable();
    table.setStyleName("inputFormFlexTable");
    // textboxes which set the class data when updated
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    final ExtendedTextBox rankTextBox = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setError("Name can't be empty.");
                return false;
            }
            nameTextBox.setOk();
            return true;
        }
    };
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (rankTextBox.getTextBox().getText().trim().isEmpty()) {
                rankTextBox.setError("Rank value can't be empty.");
                return false;
            } else {
                try {
                    Double.parseDouble(rankTextBox.getTextBox().getText().trim());
                } catch (Exception e) {
                    rankTextBox.setError("Value must be in like: 0.5, 1.0 etc.");
                    return false;
                }
            }
            rankTextBox.setOk();
            return true;
        }
    };
    nameTextBox.setValidator(validator);
    rankTextBox.setValidator(validator2);
    final TabItem tab = this;
    addCategory.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                CreateCategory request = new CreateCategory(JsonCallbackEvents.closeTabDisableButtonEvents(addCategory, tab));
                request.createCategory(nameTextBox.getTextBox().getText().trim(), Double.parseDouble(rankTextBox.getTextBox().getText().trim()));
            }
        }
    });
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(table);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    table.setHTML(0, 0, "Name:");
    table.setWidget(0, 1, nameTextBox);
    table.setHTML(1, 0, "Rank:");
    table.setWidget(1, 1, rankTextBox);
    for (int i = 0; i < table.getRowCount(); i++) {
        table.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    table.setHTML(2, 1, "Values like: 0.0 , 0.5 , 1.2 , etc.");
    table.getFlexCellFormatter().setStyleName(2, 1, "inputFormInlineComment");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : 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) CreateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.CreateCategory)

Aggregations

TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)84 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)76 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)76 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)71 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)68 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)56 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)54 ArrayList (java.util.ArrayList)47 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)30 PerunError (cz.metacentrum.perun.webgui.model.PerunError)21 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)19 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)14 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)13 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)13 User (cz.metacentrum.perun.webgui.model.User)13 Group (cz.metacentrum.perun.webgui.model.Group)11 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)11 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)10 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)10 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)10