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();
}
Aggregations