use of com.google.gwt.event.dom.client.ClickHandler 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)) {
AssignServices request = new AssignServices(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab, true));
request.assignService(resourceId, servicesToAssign);
}
}
});
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(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();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class ResourceAssignedGroupsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": manage assigned groups");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
final GetAssignedGroups resourceGroups = new GetAssignedGroups(resourceId);
final JsonCallbackEvents localEvents = JsonCallbackEvents.refreshTableEvents(resourceGroups);
CustomButton assignGroupButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignGroupToResource(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AssignGroupTabItem(resource), true);
}
});
final CustomButton removeGroupButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupFromResource());
removeGroupButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Group> groupsForRemoving = resourceGroups.getTableSelectedList();
String text = "Following groups will be removed from resource.";
UiElements.showDeleteConfirm(groupsForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
RemoveGroupsFromResource request = new RemoveGroupsFromResource(JsonCallbackEvents.disableButtonEvents(removeGroupButton, localEvents));
request.removeGroupsFromResource(groupsForRemoving, resource);
}
});
}
});
if (!session.isVoAdmin(resource.getVoId())) {
resourceGroups.setCheckable(false);
assignGroupButton.setEnabled(false);
}
menu.addWidget(assignGroupButton);
menu.addWidget(removeGroupButton);
menu.addFilterWidget(new ExtendedSuggestBox(resourceGroups.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
resourceGroups.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterGroup());
// display menu to vo admin only
if (session.isVoAdmin(resource.getVoId())) {
resourceGroups.setCheckable(true);
vp.add(menu);
vp.setCellHeight(menu, "30px");
} else {
resourceGroups.setCheckable(false);
}
// table with field updater which leads to group detail
CellTable<Group> table = resourceGroups.getTable(new FieldUpdater<Group, String>() {
public void update(int index, Group object, String value) {
session.getTabManager().addTab(new GroupDetailTabItem(object));
}
});
removeGroupButton.setEnabled(false);
if (session.isVoAdmin(resource.getVoId()))
JsonUtils.addTableManagedButton(resourceGroups, table, removeGroupButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(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 ResourceDetailTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()));
// main widget panel
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
AbsolutePanel dp = new AbsolutePanel();
// dp.setStyleName("decoration");
final FlexTable menu = new FlexTable();
menu.setCellSpacing(5);
// MAIN INFO PANEL
// resource info
menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()));
Label resourceName = new Label();
resourceName.setText(Utils.getStrippedStringWithEllipsis(resource.getName(), 40));
resourceName.setStyleName("now-managing");
resourceName.setTitle(resource.getName());
menu.setWidget(0, 1, resourceName);
menu.setHTML(0, 2, " ");
menu.getFlexCellFormatter().setWidth(0, 2, "25px");
int column = 3;
final JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
new GetEntityById(PerunEntity.RICH_RESOURCE, resourceId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
resource = jso.cast();
open();
draw();
}
}).retrieveData();
}
};
CustomButton change = new CustomButton("", ButtonTranslation.INSTANCE.editResourceDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
change.setEnabled(false);
change.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// prepare confirm content
Resource r = resource.cast();
session.getTabManager().addTabToCurrentTab(new EditResourceDetailsTabItem(r, events));
}
});
menu.setWidget(0, column, change);
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
if (JsonUtils.isExtendedInfoVisible()) {
menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + resource.getId() + "</span>");
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
}
if (facilityId > 0) {
// facility admin view
menu.setHTML(0, column, "<strong>VO:</strong><br/><span class=\"inputFormInlineComment\">" + resource.getVoId() + " / " + SafeHtmlUtils.fromString(resource.getVo().getShortName()).asString() + "</span>");
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
}
menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + SafeHtmlUtils.fromString((resource.getDescription() != null) ? resource.getDescription() : "").asString() + " </span>");
if (session.isFacilityAdmin(resource.getFacilityId())) {
column++;
menu.setHTML(0, column, " ");
menu.getFlexCellFormatter().setWidth(0, column, "25px");
column++;
Anchor a = new Anchor("View facility details >>");
a.setStyleName("pointer");
a.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new FacilityDetailTabItem(resource.getFacility()));
}
});
menu.setWidget(0, column, a);
}
dp.add(menu);
vp.add(dp);
vp.setCellHeight(dp, "30px");
// TAB PANEL WITH INNER TABS
tabPanel.clear();
Resource r = resource.cast();
tabPanel.add(new ResourceAssignedGroupsTabItem(r), "Assigned groups");
tabPanel.add(new ResourceAssignedServicesTabItem(r), "Assigned services");
tabPanel.add(new ResourceSettingsTabItem(r, null), "Service settings");
tabPanel.add(new ResourceGroupSettingsTabItem(r), "Group settings");
tabPanel.add(new ResourceMemberSettingsTabItem(resource), "Member settings");
if (session.isVoAdmin(r.getVoId()) || session.isVoObserver(r.getVoId())) {
tabPanel.add(new ResourceTagsTabItem(r), "Tags");
}
// Resize must be called after page fully displays
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
tabPanel.finishAdding();
}
});
vp.add(tabPanel);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class SecurityTeamSelectTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// Get vos request
final GetSecurityTeams teams = new GetSecurityTeams();
if (!session.isPerunAdmin()) {
teams.setCheckable(false);
}
// Events for reloading when finished
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(teams);
TabMenu tabMenu = new TabMenu();
// add menu to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
tabMenu.addWidget(UiElements.getRefreshButton(this));
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createSecurityTeam(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateSecurityTeamTabItem());
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, buttonTranslation.deleteSecurityTeam());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<SecurityTeam> itemsToRemove = teams.getTableSelectedList();
UiElements.showDeleteConfirm(itemsToRemove, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < itemsToRemove.size(); i++) {
DeleteSecurityTeam request;
if (i == itemsToRemove.size() - 1) {
request = new DeleteSecurityTeam(JsonCallbackEvents.disableButtonEvents(removeButton, events));
} else {
request = new DeleteSecurityTeam(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteSecurityTeam(itemsToRemove.get(i).getId(), false);
}
}
});
}
});
tabMenu.addWidget(removeButton);
// filter
tabMenu.addFilterWidget(new ExtendedSuggestBox(teams.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
teams.filterTable(text);
}
}, buttonTranslation.filterSecurityTeam());
tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
tabMenu.addWidget(new HTML("<strong>Please select Team you want to manage.</strong>"));
final TabItem tab = this;
// get the table with custom onclick
CellTable<SecurityTeam> table = teams.getTable(new FieldUpdater<SecurityTeam, String>() {
@Override
public void update(int i, SecurityTeam securityTeam, String string) {
session.getTabManager().addTab(new SecurityTeamDetailTabItem(securityTeam));
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
});
// 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 the table to the main panel
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, 0, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickHandler in project perun by CESNET.
the class EditServiceDetailsTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit service");
VerticalPanel vp = new VerticalPanel();
final ExtendedTextBox serviceName = new ExtendedTextBox();
final ExtendedTextBox serviceDescription = new ExtendedTextBox();
final ExtendedTextBox scriptPath = new ExtendedTextBox();
final CheckBox enabled = new CheckBox();
final ExtendedTextBox delay = new ExtendedTextBox();
final ExtendedTextBox recurrence = new ExtendedTextBox();
serviceName.getTextBox().setText(service.getName());
serviceDescription.getTextBox().setText(service.getDescription());
scriptPath.getTextBox().setText(service.getScriptPath());
enabled.setValue(service.isEnabled());
delay.getTextBox().setText(String.valueOf(service.getDelay()));
recurrence.getTextBox().setText(String.valueOf(service.getRecurrence()));
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (serviceName.getTextBox().getText().trim().isEmpty()) {
serviceName.setError("Name can't be empty");
return false;
} else if (!serviceName.getTextBox().getText().trim().matches(Utils.SERVICE_NAME_MATCHER)) {
serviceName.setError("Name can contain only letters, numbers and underscore.");
return false;
} else {
serviceName.setOk();
// fill script path on service name change
scriptPath.getTextBox().setValue("./" + serviceName.getTextBox().getText().trim().toLowerCase().replaceAll(Utils.SERVICE_NAME_TO_SCRIP_PATH_MATCHER, "_"));
return true;
}
}
};
serviceName.setValidator(validator);
enabled.setText("Enabled / Disabled");
final ExtendedTextBox.TextBoxValidator delayValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
delay.setError("Delay must be a number (time in minutes) !");
return false;
} else {
delay.setOk();
return true;
}
}
};
delay.setValidator(delayValidator);
final ExtendedTextBox.TextBoxValidator recurrenceValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!JsonUtils.checkParseInt(delay.getTextBox().getText().trim())) {
recurrence.setError("Recurrence must be a number!");
return false;
} else {
recurrence.setOk();
return true;
}
}
};
recurrence.setValidator(recurrenceValidator);
final ExtendedTextBox.TextBoxValidator scriptValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (scriptPath.getTextBox().getText().trim().isEmpty()) {
scriptPath.setError("Script path can't be empty !");
return false;
} else {
scriptPath.setOk();
return true;
}
}
};
scriptPath.setValidator(scriptValidator);
// 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 saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveServiceDetails());
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox() && delayValidator.validateTextBox() && scriptValidator.validateTextBox() && recurrenceValidator.validateTextBox()) {
Service serv = JsonUtils.clone(service).cast();
serv.setName(serviceName.getTextBox().getText().trim());
String desc = serviceDescription.getTextBox().getText().trim();
if (desc.isEmpty())
desc = null;
serv.setDescription(desc);
serv.setDelay(Integer.parseInt(delay.getTextBox().getText().trim()));
serv.setRecurrence(Integer.parseInt(recurrence.getTextBox().getText().trim()));
serv.setEnabled(enabled.getValue());
serv.setScriptPath(scriptPath.getTextBox().getText().trim());
UpdateService request = new UpdateService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, true, events));
request.updateService(serv);
}
}
});
// 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
// fill form
layout.setHTML(0, 0, "Name:");
layout.setHTML(1, 0, "Description:");
layout.setHTML(2, 0, "Status:");
layout.setHTML(3, 0, "Delay:");
layout.setHTML(4, 0, "Recurrence:");
layout.setHTML(5, 0, "Script path:");
layout.setWidget(0, 1, serviceName);
layout.setWidget(1, 1, serviceDescription);
layout.setWidget(2, 1, enabled);
layout.setWidget(3, 1, delay);
layout.setWidget(4, 1, recurrence);
layout.setWidget(5, 1, scriptPath);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(saveButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations