Search in sources :

Example 1 with DatePicker

use of com.google.gwt.user.datepicker.client.DatePicker 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)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 DatePicker (com.google.gwt.user.datepicker.client.DatePicker)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1