Search in sources :

Example 11 with CustomButton

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

the class PreviewFormTabItem method draw.

public Widget draw() {
    if (form.getGroup() != null) {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(form.getGroup().getShortName()) + ": form preview");
    } else {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(form.getVo().getName()) + ": form preview");
    }
    final TabItem tab = this;
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final ScrollPanel sp = new ScrollPanel();
    final CustomButton switchType = new CustomButton(ButtonTranslation.INSTANCE.switchToExtensionButton(), ButtonTranslation.INSTANCE.switchBetweenInitialAndExtension(), SmallIcons.INSTANCE.applicationFormIcon());
    switchType.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // switch type
            if (appType.equalsIgnoreCase("EXTENSION")) {
                appType = "INITIAL";
                switchType.setText(ButtonTranslation.INSTANCE.switchToExtensionButton());
            } else {
                appType = "EXTENSION";
                switchType.setText(ButtonTranslation.INSTANCE.switchToInitialButton());
            }
            // prepare new
            prepareApplicationForm(sp);
        }
    });
    menu.addWidget(switchType);
    if (!Utils.getNativeLanguage().isEmpty()) {
        final CustomButton switchLocale = new CustomButton(ButtonTranslation.INSTANCE.switchToCzechButton(Utils.getNativeLanguage().get(1)), ButtonTranslation.INSTANCE.switchBetweenCzechAndEnglish(), SmallIcons.INSTANCE.locateIcon());
        menu.addWidget(switchLocale);
        switchLocale.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                // switch type
                if (locale.equalsIgnoreCase("en")) {
                    locale = Utils.getNativeLanguage().get(0);
                    switchLocale.setText(ButtonTranslation.INSTANCE.switchToEnglishButton());
                } else {
                    locale = "en";
                    switchLocale.setText(ButtonTranslation.INSTANCE.switchToCzechButton(Utils.getNativeLanguage().get(1)));
                }
                // prepare new
                prepareApplicationForm(sp);
            }
        });
    }
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    prepareApplicationForm(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
    contentWidget.setWidget(vp);
    return getWidget();
}
Also used : TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu)

Example 12 with CustomButton

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

the class AssignServiceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Assign service");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetServices services = new GetServices();
    final CellTable<Service> table = services.getEmptyTable(new FieldUpdater<Service, String>() {

        public void update(int index, Service object, String value) {
            session.getTabManager().addTab(new ResourceSettingsTabItem(resource, object));
        }
    });
    // remove already assigned services from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetAssignedServices alreadyAssigned = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Service> srvToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < srvToRemove.length(); i++) {
                        services.removeFromTable(srvToRemove.get(i));
                    }
                    if (services.getList().size() == 1) {
                        table.getSelectionModel().setSelected(services.getList().get(0), true);
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    };
    services.setEvents(localEvents);
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedServicesToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Service> servicesToAssign = services.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(servicesToAssign)) {
                for (int i = 0; i < servicesToAssign.size(); i++) {
                    if (i != servicesToAssign.size() - 1) {
                        // call json normaly
                        AssignService request = new AssignService(JsonCallbackEvents.disableButtonEvents(assignButton));
                        request.assignService(servicesToAssign.get(i).getId(), resourceId);
                    } else {
                        // last change - call json with update
                        AssignService request = new AssignService(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                        request.assignService(servicesToAssign.get(i).getId(), resourceId);
                    }
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(services.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            services.filterTable(text);
            if (services.getList().size() == 1) {
                table.getSelectionModel().setSelected(services.getList().get(0), true);
            }
        }
    }, "Filter services by name");
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    services.retrieveData();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(services, table, assignButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsArray(com.google.gwt.core.client.JsArray) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.webgui.model.Service) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) 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) AssignService(cz.metacentrum.perun.webgui.json.resourcesManager.AssignService) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 13 with CustomButton

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

the class AssignTagTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add tag");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetAllResourcesTags tags = new GetAllResourcesTags(PerunEntity.VIRTUAL_ORGANIZATION, resource.getVoId());
    final CellTable<ResourceTag> table = tags.getTable();
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedTagsToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<ResourceTag> tagsToAssign = tags.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(tagsToAssign)) {
                for (int i = 0; i < tagsToAssign.size(); i++) {
                    if (i != tagsToAssign.size() - 1) {
                        // call json normaly
                        AssignResourceTag request = new AssignResourceTag(resourceId, JsonCallbackEvents.disableButtonEvents(assignButton));
                        request.assignResourceTag(tagsToAssign.get(i));
                    } else {
                        // last change - call json with update
                        AssignResourceTag request = new AssignResourceTag(resourceId, JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                        request.assignResourceTag(tagsToAssign.get(i));
                    }
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(tags.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            tags.filterTable(text);
            // if single group, select
            if (tags.getList().size() == 1) {
                table.getSelectionModel().setSelected(tags.getList().get(0), true);
            }
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(tags, table, assignButton);
    tags.retrieveData();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : AssignResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.AssignResourceTag) 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) GetAllResourcesTags(cz.metacentrum.perun.webgui.json.resourcesManager.GetAllResourcesTags) AssignResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.AssignResourceTag) ResourceTag(cz.metacentrum.perun.webgui.model.ResourceTag) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 14 with CustomButton

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

the class MembershipExpirationTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Set membership expiration");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("350px", "100%");
    final FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    layout.setStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "Current expiration:");
    layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    layout.setHTML(0, 1, member.getStatus());
    final Attribute expire = member.getAttribute("urn:perun:member:attribute-def:def:membershipExpiration");
    String expirationValue = null;
    if (expire != null && !"null".equalsIgnoreCase(expire.getValue())) {
        layout.setHTML(0, 1, expire.getValue());
        expirationValue = expire.getValue().substring(0, ((expire.getValue().length() > 10) ? 9 : expire.getValue().length() - 1));
    } else {
        layout.setHTML(0, 1, "<i>never</i>");
    }
    layout.setHTML(1, 0, "New expiration:");
    layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    final CustomButton changeButton = new CustomButton("Save", "Save changes in membership expiration date", SmallIcons.INSTANCE.diskIcon());
    final DatePicker picker = new DatePicker();
    picker.setWidth("100%");
    layout.getFlexCellFormatter().setColSpan(2, 0, 2);
    layout.setWidget(2, 0, picker);
    picker.addValueChangeHandler(new ValueChangeHandler<Date>() {

        @Override
        public void onValueChange(ValueChangeEvent<Date> dateValueChangeEvent) {
            layout.setHTML(1, 1, DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
            changeButton.setEnabled(true);
            changeOrNever = true;
        }
    });
    try {
        // set values if possible
        picker.setCurrentMonth(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
        picker.setValue(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
    } catch (Exception ex) {
        // if not parseable, display current date
        picker.setCurrentMonth(new Date());
        picker.setValue(new Date());
    }
    Anchor anchor = new Anchor("Set expiration to 'never'");
    anchor.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            layout.setHTML(1, 1, "<i>never</i>");
            changeOrNever = false;
            changeButton.setEnabled(true);
        }
    });
    layout.setWidget(3, 0, anchor);
    layout.getFlexCellFormatter().setColSpan(3, 0, 2);
    layout.getFlexCellFormatter().getElement(3, 0).setAttribute("style", "text-align: right;");
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    // by default false
    changeButton.setEnabled(false);
    changeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (changeOrNever) {
                expire.setValueAsString(DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("member", member.getId());
                SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
                ArrayList<Attribute> list = new ArrayList<Attribute>();
                list.add(expire);
                request.setAttributes(ids, list);
            } else {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("member", member.getId());
                RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
                ArrayList<Attribute> list = new ArrayList<Attribute>();
                list.add(expire);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(changeButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), 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 : Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) ArrayList(java.util.ArrayList) Date(java.util.Date) 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) DatePicker(com.google.gwt.user.datepicker.client.DatePicker) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 15 with CustomButton

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

the class AuditLogTabItem method draw.

public Widget draw() {
    // page main tab
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    // number of messages
    final TextBox tb = new TextBox();
    tb.setText(String.valueOf(count));
    tb.setWidth("100px");
    // menu panel
    TabMenu menu = new TabMenu();
    mainTab.add(menu);
    mainTab.setCellHeight(menu, "30px");
    CustomButton refreshButton = TabMenu.getPredefinedButton(ButtonType.REFRESH, ButtonTranslation.INSTANCE.refreshAuditMessages());
    // retrieve messages
    final GetAuditMessagesByCount call = new GetAuditMessagesByCount(JsonCallbackEvents.disableButtonEvents(refreshButton));
    call.setCount(count);
    CellTable<AuditMessage> table = call.getTable();
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    mainTab.add(sp);
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(sp, 350, this);
    // refresh button action
    refreshButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (JsonUtils.checkParseInt(tb.getText())) {
                call.clearTable();
                count = Integer.parseInt(tb.getText());
                call.setCount(count);
                call.retrieveData();
            } else {
                JsonUtils.cantParseIntConfirm("Number of messages", tb.getText());
            }
        }
    });
    menu.addWidget(refreshButton);
    // enter key = refresh on count text box
    tb.addKeyPressHandler(new KeyPressHandler() {

        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (JsonUtils.checkParseInt(tb.getText())) {
                    call.clearTable();
                    count = Integer.parseInt(tb.getText());
                    call.setCount(count);
                    call.retrieveData();
                } else {
                    JsonUtils.cantParseIntConfirm("Number of messages", tb.getText());
                }
            }
        }
    });
    // add textbox into menu
    menu.addWidget(new HTML("<strong>Number of messages: </strong>"));
    menu.addWidget(tb);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : AuditMessage(cz.metacentrum.perun.webgui.model.AuditMessage) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAuditMessagesByCount(cz.metacentrum.perun.webgui.json.auditMessagesManager.GetAuditMessagesByCount) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)174 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)161 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)161 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)132 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)115 ArrayList (java.util.ArrayList)113 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)98 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)71 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)38 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)32 PerunError (cz.metacentrum.perun.webgui.model.PerunError)30 HashMap (java.util.HashMap)29 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)21 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)20 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)20 Map (java.util.Map)20 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)19 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)19 Group (cz.metacentrum.perun.webgui.model.Group)17 User (cz.metacentrum.perun.webgui.model.User)17