use of cz.metacentrum.perun.webgui.widgets.TabMenu 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();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.
the class EditMailTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Edit notification");
// languages
ArrayList<String> languages = appMail.getLocales();
if (!Utils.getNativeLanguage().isEmpty() && !languages.contains(Utils.getNativeLanguage().get(0))) {
languages.add(Utils.getNativeLanguage().get(0));
}
if (!languages.contains("en"))
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.SAVE, ButtonTranslation.INSTANCE.saveEmailNotificationForApplication(), new ClickHandler() {
public void onClick(ClickEvent event) {
// values
boolean send = sendingEnabledCheckBox.getValue();
appMail.setSend(send);
// 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);
appMail.setMessage(locale, mt);
}
// request
UpdateApplicationMail req = new UpdateApplicationMail(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab));
req.updateMail(appMail);
}
});
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();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu 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 cz.metacentrum.perun.webgui.widgets.TabMenu 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();
}
use of cz.metacentrum.perun.webgui.widgets.TabMenu 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();
}
Aggregations