use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class ResourceSettingsTabItem method draw.
public Widget draw() {
if (service != null) {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
} else {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
}
vp.setSize("100%", "100%");
vp.clear();
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// callback
final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
resAttrs.setIds(ids);
final GetAttributesV2 attrs = new GetAttributesV2();
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
resAttrs.setCheckable(false);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
attrs.setCheckable(false);
// puts first table
final CellTable<Attribute> table = resAttrs.getEmptyTable();
final CellTable<Attribute> table2 = attrs.getEmptyTable();
// if for one service only modify empty table message
if (service != null) {
AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
}
final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
sp.setWidget(table);
sp2.setWidget(table2);
// switch between assigned and all
final CheckBox chb = new CheckBox();
chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
// default true
chb.setValue(lastOfferAvailableOnly);
// event which fills the listbox and call getRequiredAttributes
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// clear services list
servList.clear();
// process services
ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
srv = new TableSorter<Service>().sortByName(srv);
for (int i = 0; i < srv.size(); i++) {
// fill listbox
servList.addItem(srv.get(i));
}
if (servList.isEmpty()) {
servList.addNotSelectedOption();
lastSelectedService = 0;
indexInList = 0;
attrs.retrieveData();
setTable(false);
return;
}
if (lastSelectedService == 0 && chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
if (indexInList == 0) {
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (indexInList == 1) {
servList.setSelectedIndex(1);
}
} else if (lastSelectedService == 0 && chb.getValue() == false) {
servList.addNotSelectedOption();
servList.setSelectedIndex(0);
attrs.retrieveData();
setTable(false);
return;
} else if (lastSelectedService != 0) {
if (chb.getValue() == true) {
servList.addNotSelectedOption();
servList.addAllOption();
} else {
servList.addNotSelectedOption();
}
// remove last service, we can't be sure it was loaded again
ids.remove("service");
// either all or specific service
servList.setSelectedIndex(1);
for (Service s : servList.getAllObjects()) {
if (s.getId() == lastSelectedService) {
// service selected last time was found in a list
servList.setSelected(s, true);
ids.put("service", s.getId());
break;
}
}
}
// make call
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
@Override
public void onError(PerunError error) {
servList.clear();
servList.addItem("Error while loading");
if (required) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
} else {
((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
}
}
@Override
public void onLoadingStart() {
servList.removeAllOption();
servList.removeNotSelectedOption();
servList.clear();
servList.addItem("Loading...");
}
};
final GetAssignedServices services = new GetAssignedServices(resourceId, event);
final GetServices allServices = new GetServices(event);
// offer services selection
if (serviceId == 0) {
// services listbox
servList.setTitle("Services");
attrs.setIds(ids);
// on change of service update table
servList.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if service selected
if (servList.getSelectedIndex() == 0) {
attrs.retrieveData();
setTable(false);
lastSelectedService = 0;
indexInList = 0;
return;
} else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
ids.remove("service");
lastSelectedService = 0;
indexInList = 1;
} else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
ids.put("service", servList.getSelectedObject().getId());
lastSelectedService = servList.getSelectedObject().getId();
}
lastOfferAvailableOnly = chb.getValue();
resAttrs.clearTable();
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
});
if (chb.getValue() == false) {
allServices.retrieveData();
} else {
services.retrieveData();
}
} else {
// retrieve data for selected service only
lastSelectedService = serviceId;
lastOfferAvailableOnly = chb.getValue();
ids.put("service", serviceId);
resAttrs.setIds(ids);
resAttrs.retrieveData();
setTable(true);
}
// refresh table event - refresh only on finished / on error keep selected
final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
// add save changes to menu
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
menu.addWidget(saveChangesButton);
// set button disable event
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
saveChangesButton.setEnabled(false);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
request.setAttributes(ids, list);
}
}
});
// add set new to menu
CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getList();
} else {
list = attrs.getList();
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
setNewAttributeButton.setEnabled(false);
if (service == null) {
menu.addWidget(setNewAttributeButton);
}
// fill button
final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
menu.addWidget(fillDefaultButton);
// remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
// remove button event
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
removeButton.setEnabled(false);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = new ArrayList<Attribute>();
if (required) {
list = resAttrs.getTableSelectedList();
} else {
list = attrs.getTableSelectedList();
}
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeButton);
// add service selection to menu and switcher
if (serviceId == 0) {
menu.addWidget(new HTML("<strong>Selected service: </strong>"));
menu.addWidget(servList);
menu.addWidget(chb);
}
// checkbox switcher on click
chb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (chb.getValue() == false) {
lastOfferAvailableOnly = false;
allServices.retrieveData();
} else {
lastOfferAvailableOnly = true;
services.retrieveData();
}
}
});
fillDefaultButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// automatically try to fill all attributes
ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
if (required) {
prepareList = resAttrs.getTableSelectedList();
} else {
prepareList = attrs.getTableSelectedList();
}
final ArrayList<Attribute> list = prepareList;
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resourceId);
FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {
boolean wasRequiredTable = required;
@Override
public void onFinished(JavaScriptObject jso) {
// remove attribute from original table and put new ones
ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
for (Attribute a : newList) {
for (Attribute oldA : list) {
// deselect old
if (a.getId() == oldA.getId()) {
if (wasRequiredTable) {
resAttrs.getSelectionModel().setSelected(oldA, false);
resAttrs.removeFromTable(oldA);
} else {
attrs.getSelectionModel().setSelected(oldA, false);
attrs.removeFromTable(oldA);
}
}
}
if (wasRequiredTable) {
// add new
resAttrs.addToTable(a);
// select returned
resAttrs.getSelectionModel().setSelected(a, true);
} else {
// add new
attrs.addToTable(a);
// select returned
attrs.getSelectionModel().setSelected(a, true);
}
}
if (wasRequiredTable) {
resAttrs.sortTable();
} else {
attrs.sortTable();
}
}
}));
request.fillAttributes(ids, list);
}
}
});
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
fillDefaultButton.setEnabled(false);
/* TODO - not implemented
Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
menu.addWidget(checkValuesButton);
checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");
checkValuesButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("not yet implemented");
}
});
*/
table.addStyleName("perun-table");
table.setWidth("100%");
table2.addStyleName("perun-table");
table2.setWidth("100%");
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
sp2.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp2, 350, this);
// default is required attributes
setTable(true);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class AddSecurityTeamManagerTabItem method draw.
public Widget draw() {
titleWidget.setText("Add member");
final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
ArrayList<User> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
users.getSelectionModel().setSelected(list.get(0), true);
}
}
}));
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table;
if (session.isPerunAdmin()) {
table = users.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new UserDetailTabItem(user));
}
});
} else {
table = users.getTable();
}
rebuildAlreadyAddedWidget();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToSecurityTeam());
final TabItem tab = this;
// search textbox
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
startSearching(text);
searchString = text;
}
}, searchButton);
tabMenu.addWidget(addButton);
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<User> list = users.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
for (int i = 0; i < list.size(); i++) {
// FIXME - Should have only one callback to core
final int n = i;
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
alreadyAddedList.add(list.get(n));
rebuildAlreadyAddedWidget();
// unselect added person
users.getSelectionModel().setSelected(list.get(n), false);
// clear search
searchBox.getTextBox().setText("");
}
}));
request.addSecurityTeamAdmin(securityTeam, list.get(i));
}
}
}
});
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
startSearching(searchString);
}
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(users, table, addButton);
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(alreadyAdded);
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class CreateSecurityTeamTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final ExtendedTextBox descriptionTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setMaxLength(128);
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setOk();
return true;
} else {
nameTextBox.setError("Name can't be empty.");
return false;
}
}
};
nameTextBox.setValidator(nameValidator);
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createSecurityTeam());
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!nameValidator.validateTextBox())
return;
CreateSecurityTeam request = new CreateSecurityTeam(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// new SecTeam must be editable by user in GUI, because it is already in PERUN
SecurityTeam team = jso.cast();
session.addEditableSecurityTeam(team.getId());
}
}));
request.createSecurityTeam(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getTextBox().getText().trim());
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
});
// Add some standard form options
layout.setHTML(0, 0, "Name:");
layout.setWidget(0, 1, nameTextBox);
layout.setHTML(1, 0, "Description:");
layout.setWidget(1, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(createButton);
menu.addWidget(cancelButton);
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 CreateMailTabItem method draw.
public Widget draw() {
String title = "";
if (group != null) {
title = group.getName();
entity = PerunEntity.GROUP;
entityId = groupId;
} else {
title = vo.getName();
entity = PerunEntity.VIRTUAL_ORGANIZATION;
entityId = voId;
}
this.titleWidget.setText("Add email notification");
// languages
ArrayList<String> languages = new ArrayList<String>();
if (!Utils.getNativeLanguage().isEmpty()) {
languages.add(Utils.getNativeLanguage().get(0));
}
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.CREATE, ButtonTranslation.INSTANCE.createEmailNotificationForApplication(), new ClickHandler() {
public void onClick(ClickEvent event) {
String appType = applicationTypeListbox.getValue(applicationTypeListbox.getSelectedIndex());
String mailType = mailTypeListbox.getValue(mailTypeListbox.getSelectedIndex());
boolean send = sendingEnabledCheckBox.getValue();
HashMap<String, MailText> messages = new HashMap<String, MailText>();
// 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);
messages.put(locale, mt);
}
// create object
ApplicationMail appMail = ApplicationMail.construct(appType, form.getId(), mailType, send, messages);
// request
AddApplicationMail req = new AddApplicationMail(entity, JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, true));
req.addMail(appMail, entityId);
}
});
tabMenu.addWidget(saveButton);
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// 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 com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class CreateMailTabItem method messageTab.
/**
* Returns message texarea
*
* @param locale
* @return
*/
private Widget messageTab(String locale) {
VerticalPanel vp = new VerticalPanel();
vp.setSize("500px", "350px");
vp.setSpacing(10);
// layout
FlexTable ft = new FlexTable();
ft.setStyleName("inputFormFlexTable");
FlexCellFormatter ftf = ft.getFlexCellFormatter();
// inputs
TextBox tb = new TextBox();
tb.setWidth("385px");
messagesSubjects.put(locale, tb);
TextArea ta = new TextArea();
ta.setSize("450px", "190px");
messagesTextAreas.put(locale, ta);
// adds inputs to the flex table
ft.setHTML(0, 0, "Subject:");
ftf.setStyleName(0, 0, "itemName");
ft.setWidget(0, 1, tb);
ft.setHTML(1, 0, "Text:");
ftf.setStyleName(1, 0, "itemName");
// ftf.setColSpan(1, 0, 2);
Anchor a = new Anchor("see available tags >>");
a.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// select last tab
tabPanel.selectTab(tabPanel.getWidgetCount() - 1);
}
});
ft.setWidget(1, 1, a);
ft.setWidget(2, 0, ta);
ftf.setColSpan(2, 0, 2);
vp.add(ft);
vp.add(new HTML(" "));
return vp;
}
Aggregations