Search in sources :

Example 31 with ClickEvent

use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.

the class MemberAddToGroupTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Add to group(s)");
    // main widget panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final GetAllGroups groups = new GetAllGroups(member.getVoId());
    menu.addFilterWidget(new ExtendedSuggestBox(groups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
            if (groups.getList().size() == 1) {
                // select if filtered result is single group
                groups.getSelectionModel().setSelected(groups.getList().get(0), true);
            }
        }
    }, "Filter groups by name");
    final TabItem tab = this;
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add member to selected group(s)");
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ArrayList<Group> list = groups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - should have only one callback to core
                for (int i = 0; i < list.size(); i++) {
                    final Group g = list.get(i);
                    AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            groups.getSelectionModel().setSelected(g, false);
                            alreadyAddedList.add(g);
                            rebuildAlreadyAddedWidget();
                        }
                    }));
                    request.addMemberToGroup(g, member);
                }
            }
        }
    });
    menu.addWidget(addButton);
    addButton.setEnabled(false);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    CellTable<Group> table = groups.getTable();
    JsonUtils.addTableManagedButton(groups, table, addButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    rebuildAlreadyAddedWidget();
    vp.add(alreadyAdded);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) 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) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember)

Example 32 with ClickEvent

use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.

the class CreateMailTabItem method draw.

public Widget draw() {
    String title = "";
    if (group != null) {
        title = group.getName();
        entity = PerunEntity.GROUP;
        entityId = groupId;
    } else {
        title = vo.getName();
        entity = PerunEntity.VIRTUAL_ORGANIZATION;
        entityId = voId;
    }
    this.titleWidget.setText("Add email notification");
    // languages
    ArrayList<String> languages = new ArrayList<String>();
    if (!Utils.getNativeLanguage().isEmpty()) {
        languages.add(Utils.getNativeLanguage().get(0));
    }
    languages.add(0, "en");
    // vertical panel
    VerticalPanel vp = new VerticalPanel();
    vp.setWidth("500px");
    vp.setHeight("350px");
    // tab panel
    tabPanel.addStyleName("smallTabPanel");
    tabPanel.addStyleName("smallTabPanelWithBorder");
    tabPanel.setHeight("350px");
    // basic settings
    tabPanel.add(basicInformationTab(), "Basic settings");
    // for each locale add tab
    for (String locale : languages) {
        tabPanel.add(messageTab(locale), "Lang: " + locale);
    }
    tabPanel.add(availableTagsTab(), "Available tags");
    // add menu
    final TabItem tab = this;
    TabMenu tabMenu = new TabMenu();
    saveButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createEmailNotificationForApplication(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            String appType = applicationTypeListbox.getValue(applicationTypeListbox.getSelectedIndex());
            String mailType = mailTypeListbox.getValue(mailTypeListbox.getSelectedIndex());
            boolean send = sendingEnabledCheckBox.getValue();
            HashMap<String, MailText> messages = new HashMap<String, MailText>();
            // messages
            for (Map.Entry<String, TextArea> entry : messagesTextAreas.entrySet()) {
                String locale = entry.getKey();
                String subject = messagesSubjects.get(entry.getKey()).getValue();
                String text = entry.getValue().getText();
                MailText mt = MailText.construct(locale, subject, text);
                messages.put(locale, mt);
            }
            // create object
            ApplicationMail appMail = ApplicationMail.construct(appType, form.getId(), mailType, send, messages);
            // request
            AddApplicationMail req = new AddApplicationMail(entity, JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab));
            req.addMail(appMail, entityId);
        }
    });
    tabMenu.addWidget(saveButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // add tab panel to main panel
    vp.add(tabPanel);
    vp.setCellWidth(tabPanel, "500px");
    vp.setCellHeight(tabPanel, "350px");
    vp.add(tabMenu);
    vp.setCellHeight(tabMenu, "30px");
    vp.setCellHorizontalAlignment(tabMenu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) AddApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.AddApplicationMail) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HashMap(java.util.HashMap) Map(java.util.Map) AddApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.AddApplicationMail)

Example 33 with ClickEvent

use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.

the class CreateMailTabItem method messageTab.

/**
	 * Returns message texarea
	 *
	 * @param locale
	 * @return
	 */
private Widget messageTab(String locale) {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("500px", "350px");
    vp.setSpacing(10);
    // layout
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    // inputs
    TextBox tb = new TextBox();
    tb.setWidth("385px");
    messagesSubjects.put(locale, tb);
    TextArea ta = new TextArea();
    ta.setSize("450px", "190px");
    messagesTextAreas.put(locale, ta);
    // adds inputs to the flex table
    ft.setHTML(0, 0, "Subject:");
    ftf.setStyleName(0, 0, "itemName");
    ft.setWidget(0, 1, tb);
    ft.setHTML(1, 0, "Text:");
    ftf.setStyleName(1, 0, "itemName");
    //ftf.setColSpan(1, 0, 2);
    Anchor a = new Anchor("see available tags >>");
    a.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // select last tab
            tabPanel.selectTab(tabPanel.getWidgetCount() - 1);
        }
    });
    ft.setWidget(1, 1, a);
    ft.setWidget(2, 0, ta);
    ftf.setColSpan(2, 0, 2);
    vp.add(ft);
    vp.add(new HTML("&nbsp;"));
    return vp;
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 34 with ClickEvent

use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.

the class EditFormItemTabItem method buildItemsTable.

private FlexTable buildItemsTable(final FlexTable boxItemTable, final Map<String, String> values, final String locale) {
    // clear before rebuild
    boxItemTable.clear(true);
    int boxRow = 0;
    // clear options boxes
    final Map<TextBox, TextBox> currentOptions = new HashMap<TextBox, TextBox>();
    optionsBoxes.put(locale, currentOptions);
    boxRow++;
    Label boxContentLabel = new Label(item.getType().substring(0, 1) + item.getType().toLowerCase().substring(1) + " options:");
    boxItemTable.setWidget(boxRow, 0, boxContentLabel);
    boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 0, "itemName");
    boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
    boxRow++;
    HTML comment = new HTML("Define possible options for selection in SELECTIONBOX, COMBOBOX, CHECKBOX, RADIO widget. Empty options are not used.");
    comment.setStyleName("inputFormInlineComment");
    boxItemTable.setWidget(boxRow, 0, comment);
    boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
    boxRow++;
    TabMenu menu = new TabMenu();
    //menu.setWidth("100%");
    boxItemTable.setWidget(boxRow, 0, menu);
    boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 4);
    boxRow++;
    final CustomButton sortButton = new CustomButton("Sort by label (A-Z)", SmallIcons.INSTANCE.sortAscendingIcon());
    menu.addWidget(sortButton);
    final CustomButton sortButton2 = new CustomButton("Sort by label (Z-A)", SmallIcons.INSTANCE.sortDescendingIcon());
    menu.addWidget(sortButton2);
    sortButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // OPTIONS
            Map<TextBox, TextBox> localeTextboxes = optionsBoxes.get(locale);
            Map<String, String> keyValue = new HashMap<String, String>();
            for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.entrySet()) {
                String key = textBoxes.getKey().getText();
                String value = textBoxes.getValue().getText();
                if (key != null && !key.equals("") && value != null && !value.equals("")) {
                    keyValue.put(key.trim(), value.trim());
                }
            }
            List<String> values = new ArrayList<String>(keyValue.values());
            Collections.sort(values, Collator.getNativeComparator());
            Map<String, String> sortedValues = new HashMap<String, String>();
            for (String value : values) {
                for (String key : keyValue.keySet()) {
                    if (Objects.equals(keyValue.get(key), value)) {
                        sortedValues.put(key, keyValue.get(key));
                    }
                }
            }
            buildItemsTable(boxItemTable, sortedValues, locale);
        }
    });
    sortButton2.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // OPTIONS
            Map<TextBox, TextBox> localeTextboxes = optionsBoxes.get(locale);
            Map<String, String> keyValue = new HashMap<String, String>();
            for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.entrySet()) {
                String key = textBoxes.getKey().getText();
                String value = textBoxes.getValue().getText();
                if (key != null && !key.equals("") && value != null && !value.equals("")) {
                    keyValue.put(key.trim(), value.trim());
                }
            }
            List<String> values = new ArrayList<String>(keyValue.values());
            Collections.sort(values, Collections.reverseOrder(Collator.getNativeComparator()));
            Map<String, String> sortedValues = new HashMap<String, String>();
            for (String value : values) {
                for (String key : keyValue.keySet()) {
                    if (Objects.equals(keyValue.get(key), value)) {
                        sortedValues.put(key, keyValue.get(key));
                    }
                }
            }
            buildItemsTable(boxItemTable, sortedValues, locale);
        }
    });
    // for each add new row
    for (Map.Entry<String, String> entry : values.entrySet()) {
        final TextBox keyTextBox = new TextBox();
        final TextBox valueTextBox = new TextBox();
        currentOptions.put(keyTextBox, valueTextBox);
        keyTextBox.setText(entry.getKey());
        valueTextBox.setText(entry.getValue());
        boxItemTable.setHTML(boxRow, 0, "Value:");
        boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 0, "itemName");
        boxItemTable.setWidget(boxRow, 1, keyTextBox);
        boxItemTable.setHTML(boxRow, 2, "Label:");
        boxItemTable.getFlexCellFormatter().setStyleName(boxRow, 2, "itemName");
        boxItemTable.setWidget(boxRow, 3, valueTextBox);
        boxRow++;
    }
    // button for adding new
    CustomButton addNewButton = new CustomButton(ButtonTranslation.INSTANCE.addButton(), ButtonTranslation.INSTANCE.addNewSelectionBoxItem(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            final int r = boxItemTable.getRowCount();
            final TextBox keyTextBox = new TextBox();
            final TextBox valueTextBox = new TextBox();
            currentOptions.put(keyTextBox, valueTextBox);
            boxItemTable.insertRow(r - 1);
            boxItemTable.setHTML(r - 1, 0, "Value:");
            boxItemTable.getFlexCellFormatter().setStyleName(r - 1, 0, "itemName");
            boxItemTable.setWidget(r - 1, 1, keyTextBox);
            boxItemTable.setHTML(r - 1, 2, "Label:");
            boxItemTable.getFlexCellFormatter().setStyleName(r - 1, 2, "itemName");
            boxItemTable.setWidget(r - 1, 3, valueTextBox);
            UiElements.runResizeCommands(tab);
        }
    });
    boxItemTable.setWidget(boxRow, 0, addNewButton);
    boxItemTable.getFlexCellFormatter().setColSpan(boxRow, 0, 2);
    return boxItemTable;
}
Also used : HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) JSONString(com.google.gwt.json.client.JSONString) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with ClickEvent

use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.

the class EditMailFooterTabItem method draw.

public Widget draw() {
    final FlexTable content = new FlexTable();
    content.setStyleName("inputFormFlexTable");
    content.setWidth("360px");
    final TextArea footer = new TextArea();
    footer.setSize("340px", "200px");
    content.setHTML(0, 0, "Footer text:");
    content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    content.setWidget(1, 0, footer);
    content.setHTML(2, 0, "This text will be added as footer for all email notifications (replacing {mailFooter} tag in mail definition).");
    content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    if (group == null) {
        ids.put("vo", voId);
    } else {
        ids.put("group", groupId);
    }
    final ArrayList<Attribute> list = new ArrayList<Attribute>();
    final GetListOfAttributes call = new GetListOfAttributes(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            list.addAll(JsonUtils.<Attribute>jsoAsList(jso));
            // only if attribute exists
            if (list != null && !list.isEmpty()) {
                for (Attribute a : list) {
                    if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
                        // if value not null - enter
                        if (!a.getValue().equalsIgnoreCase("null")) {
                            footer.setText(a.getValue());
                        }
                    }
                }
            }
        }
    });
    ArrayList<String> l = new ArrayList<String>();
    if (group == null) {
        l.add("urn:perun:vo:attribute-def:def:mailFooter");
    } else {
        l.add("urn:perun:group:attribute-def:def:mailFooter");
    }
    call.getListOfAttributes(ids, l);
    final TabItem tab = this;
    VerticalPanel vp = new VerticalPanel();
    TabMenu menu = new TabMenu();
    final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveMailFooter());
    save.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // will be set
            ArrayList<Attribute> toSend = new ArrayList<Attribute>();
            // will be removed
            ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
            for (Attribute a : list) {
                String oldValue = a.getValue();
                String newValue = "";
                if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
                    newValue = footer.getText();
                } else {
                    // other than mailFooter attributes must be skipped
                    continue;
                }
                if (oldValue.equalsIgnoreCase(newValue) || (oldValue.equalsIgnoreCase("null") && newValue.equalsIgnoreCase(""))) {
                    // skip this cycle
                    continue;
                } else {
                    if (newValue.equalsIgnoreCase("")) {
                        // value was cleared
                        toRemove.add(a);
                    } else {
                        // set value
                        a.setValue(newValue);
                        // value was changed / added
                        toSend.add(a);
                    }
                }
            }
            // requests
            SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            RemoveAttributes removeRequest = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            // send if not empty
            if (!toRemove.isEmpty()) {
                removeRequest.removeAttributes(ids, toRemove);
            }
            if (!toSend.isEmpty()) {
                request.setAttributes(ids, toSend);
            }
        }
    });
    menu.addWidget(save);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(content);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) 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) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)385 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)382 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)161 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)135 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)124 ArrayList (java.util.ArrayList)117 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)105 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)76 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)42 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)41 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)40 PerunError (cz.metacentrum.perun.webgui.model.PerunError)36 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)32 HashMap (java.util.HashMap)32 Button (com.google.gwt.user.client.ui.Button)30 Image (com.google.gwt.user.client.ui.Image)28 HTML (com.google.gwt.user.client.ui.HTML)26 Button (org.gwtbootstrap3.client.ui.Button)26 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)25 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)23