use of com.google.gwt.event.dom.client.ClickHandler 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, true));
RemoveAttributes removeRequest = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
// 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, isRefreshParentOnClose());
}
}));
vp.add(content);
vp.add(menu);
vp.setCellHeight(menu, "30px");
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class MailsTabItem method draw.
public Widget draw() {
final GetApplicationMails mailsRequest;
String title = "";
if (group != null) {
title = group.getName();
entity = PerunEntity.GROUP;
entityId = group.getId();
mailsRequest = new GetApplicationMails(entity, group.getId());
} else {
title = vo.getName();
entityId = vo.getId();
mailsRequest = new GetApplicationMails(entity, vo.getId());
}
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(title) + ": " + "Email notifications");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// add button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateMailTabItem(vo, group, form));
}
}));
// remove button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMail());
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
String text = "Following mail definitions will be removed and users won't receive them anymore.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1) {
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteMail(list.get(i).getId(), entityId);
} else {
// refresh table on last call
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(mailsRequest)));
request.deleteMail(list.get(i).getId(), entityId);
}
}
}
});
}
});
// enable button
CustomButton enableButton = TabMenu.getPredefinedButton(ButtonType.ENABLE, ButtonTranslation.INSTANCE.enableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, true);
}
}
});
menu.addWidget(enableButton);
// disable button
CustomButton disableButton = TabMenu.getPredefinedButton(ButtonType.DISABLE, ButtonTranslation.INSTANCE.disableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, false);
}
}
});
menu.addWidget(disableButton);
menu.addWidget(new CustomButton(ButtonTranslation.INSTANCE.mailFooterButton() + "…", ButtonTranslation.INSTANCE.editMailFooter(), SmallIcons.INSTANCE.emailIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (group == null) {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(vo));
} else {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(group));
}
}
}));
CustomButton copy;
if (group == null) {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromVo(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(voId, 0));
}
});
} else {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromGroupButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromGroup(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(group.getVoId(), groupId));
}
});
}
menu.addWidget(copy);
// TABLE
CellTable<ApplicationMail> table = mailsRequest.getTable(new FieldUpdater<ApplicationMail, String>() {
public void update(int index, ApplicationMail appMail, String value) {
session.getTabManager().addTabToCurrentTab(new EditMailTabItem(appMail));
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
removeButton.setEnabled(false);
enableButton.setEnabled(false);
disableButton.setEnabled(false);
JsonUtils.addTableManagedButton(mailsRequest, table, removeButton);
JsonUtils.addTableManagedButton(mailsRequest, table, enableButton);
JsonUtils.addTableManagedButton(mailsRequest, table, disableButton);
session.getUiElements().resizePerunTable(sp, 100);
firstTabPanel.add(sp);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler 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, true));
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, isRefreshParentOnClose());
}
}));
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();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class CreateFacilityResourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create resource");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// form inputs
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final TextBox descriptionTextBox = new TextBox();
final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
// local events fills the listbox of Vos and Slds
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// fill VOs listbox
vosDropDown.clear();
ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
vos = new TableSorter<VirtualOrganization>().sortByName(vos);
for (VirtualOrganization vo : vos) {
vosDropDown.addItem(vo);
}
if (!vos.isEmpty())
createButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
vosDropDown.clear();
vosDropDown.addItem("Loading...");
createButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
vosDropDown.clear();
vosDropDown.addItem("Error while loading");
createButton.setEnabled(false);
}
};
// load available VOs
final GetVos vos = new GetVos(event);
vos.setForceAll(true);
vos.retrieveData();
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add some standard form options
layout.setHTML(0, 0, "On facility:");
layout.setHTML(0, 1, SafeHtmlUtils.fromString((facility.getName() != null) ? facility.getName() : "").asString());
layout.setHTML(1, 0, "For VO:");
layout.setWidget(1, 1, vosDropDown);
layout.setHTML(2, 0, "Name:");
layout.setWidget(2, 1, nameTextBox);
layout.setHTML(3, 0, "Description:");
layout.setWidget(3, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setWidth("350px");
TabMenu menu = new TabMenu();
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;
}
};
nameTextBox.setValidator(validator);
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// loads new tab when creating successful, also disable button
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onLoadingStart() {
(JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
}
public void onFinished(JavaScriptObject jso) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
Resource res = (Resource) jso;
session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
}
public void onError(PerunError error) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
}
};
if (validator.validateTextBox()) {
// request
CreateResource request = new CreateResource(localEvents);
request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
}
}
});
menu.addWidget(createButton);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler 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, SafeHtmlUtils.fromString(member.getStatus()).asString());
layout.getFlexCellFormatter().getElement(0, 1).setAttribute("style", "width: 100%; font-size: 130%;");
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, SafeHtmlUtils.fromString((expire.getValue() != null) ? expire.getValue() : "").asString());
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()));
layout.getFlexCellFormatter().getElement(1, 1).setAttribute("style", "width: 100%; font-size: 130%;");
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>");
layout.getFlexCellFormatter().getElement(1, 1).setAttribute("style", "width: 100%; font-size: 130%;");
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, false, events));
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, false, events));
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, isRefreshParentOnClose());
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations