use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class AddDependencyTabItem method draw.
public Widget draw() {
// TITLE
titleWidget.setText("Add dependency");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
// fill listbox after callback finishes
final JsonCallbackEvents localEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listBox.clear();
ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
if (execs != null && !execs.isEmpty()) {
execs = new TableSorter<ExecService>().sortByService(execs);
for (int i = 0; i < execs.size(); i++) {
listBox.addItem(execs.get(i));
if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
// preselect different type of exec service from same service
listBox.setSelected(execs.get(i), true);
}
}
addButton.setEnabled(true);
} else {
listBox.addItem("No exec service available");
}
}
@Override
public void onLoadingStart() {
listBox.clear();
listBox.addItem("Loading...");
addButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
listBox.addItem("Error while loading");
addButton.setEnabled(false);
}
};
// callback for all services
ListExecServices callback = new ListExecServices(0, localEvents);
callback.retrieveData();
// layout
layout.setHTML(0, 0, "ExecService:");
layout.setHTML(1, 0, "Depend On:");
layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
layout.setWidget(1, 1, listBox);
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
CreateDependency request = new CreateDependency(closeTabEvents);
request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
}
});
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
menu.addWidget(addButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class AddExecServiceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create exec service");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// prepares layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
layout.setWidth("350px");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// define objects
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createExecService());
Label serviceLabel = new Label();
serviceLabel.setText(service.getName() + " (" + serviceId + ")");
final ListBox type = new ListBox();
type.addItem("GENERATE", "GENERATE");
type.addItem("SEND", "SEND");
final VerticalPanel fp = new VerticalPanel();
final RadioButton radio1 = new RadioButton("rd-type", "GENERATE + SEND");
final RadioButton radio2 = new RadioButton("rd-type", "GENERATE");
final RadioButton radio3 = new RadioButton("rd-type", "SEND");
radio1.setValue(true);
fp.add(radio1);
fp.add(radio2);
fp.add(radio3);
final CheckBox enabled = new CheckBox();
enabled.setText("Enabled / Disabled");
enabled.setValue(true);
final ExtendedTextBox delay = new ExtendedTextBox();
delay.getTextBox().setText(DEFAULT_DELAY);
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 scriptPath = new ExtendedTextBox();
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);
// put default path
scriptPath.getTextBox().setValue("./" + service.getName());
// layout
layout.setHTML(0, 0, "Service:");
layout.setHTML(1, 0, "Type:");
layout.setHTML(2, 0, "Status:");
layout.setHTML(3, 0, "Delay:");
layout.setHTML(4, 0, "Script path:");
layout.setWidget(0, 1, serviceLabel);
layout.setWidget(1, 1, fp);
layout.setWidget(2, 1, enabled);
layout.setWidget(3, 1, delay);
layout.setWidget(4, 1, scriptPath);
// send button
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (delayValidator.validateTextBox() && scriptValidator.validateTextBox()) {
int delayNum = Integer.parseInt(delay.getTextBox().getText().trim());
InsertExecService request = new InsertExecService(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
if (radio1.getValue()) {
request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
} else if (radio2.getValue()) {
request.addExecService(service, "GENERATE", enabled.getValue(), delayNum, scriptPath.getTextBox().getText().trim());
} else if (radio3.getValue()) {
request.addExecService(service, "SEND", enabled.getValue(), delayNum, scriptPath.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, false);
}
});
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 cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class CreateServiceTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final ExtendedTextBox serviceName = new ExtendedTextBox();
final ExtendedTextBox scriptPath = new ExtendedTextBox();
final CheckBox enabled = new CheckBox();
final ExtendedTextBox delay = new ExtendedTextBox();
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");
enabled.setValue(true);
delay.getTextBox().setText(DEFAULT_DELAY);
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 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");
FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// close tab events
final TabItem tab = this;
TabMenu menu = new TabMenu();
// fill form
layout.setHTML(0, 0, "Name:");
layout.setHTML(1, 0, "Status:");
layout.setHTML(2, 0, "Delay:");
layout.setHTML(3, 0, "Script path:");
layout.setWidget(0, 1, serviceName);
layout.setWidget(1, 1, enabled);
layout.setWidget(2, 1, delay);
layout.setWidget(3, 1, scriptPath);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
// create button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createService());
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox() && delayValidator.validateTextBox() && scriptValidator.validateTextBox()) {
CreateCompleteService request = new CreateCompleteService(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
request.createCompleteService(serviceName.getTextBox().getText().trim(), scriptPath.getTextBox().getText().trim(), Integer.parseInt(delay.getTextBox().getText().trim()), enabled.getValue());
}
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
menu.addWidget(createButton);
menu.addWidget(cancelButton);
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
// add tabs to the main panel
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class EditExecServiceTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit ExecService");
VerticalPanel vp = new VerticalPanel();
final CheckBox enabled = new CheckBox();
enabled.setText("Enabled / Disabled");
enabled.setValue(execService.isEnabled());
final ExtendedTextBox delay = new ExtendedTextBox();
delay.getTextBox().setText("" + execService.getDefaultDelay());
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 scriptPath = new ExtendedTextBox();
scriptPath.getTextBox().setValue(execService.getScriptPath());
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, "Save changes of ExecService");
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!scriptValidator.validateTextBox() && !delayValidator.validateTextBox())
return;
ExecService es = JsonUtils.clone(execService).cast();
es.setEnabled(enabled.getValue());
es.setDefaultDelay(Integer.parseInt(delay.getTextBox().getValue().trim()));
es.setScriptPath(scriptPath.getTextBox().getValue().trim());
UpdateExecService request = new UpdateExecService(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
request.updateExecService(es);
}
});
// cancel button
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
// Add some standard form options
layout.setHTML(0, 0, "Enabled:");
layout.setWidget(0, 1, enabled);
layout.setHTML(1, 0, "Script path:");
layout.setWidget(1, 1, scriptPath);
layout.setHTML(2, 0, "Delay:");
layout.setWidget(2, 1, delay);
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();
}
use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.
the class ServiceDestinationsTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Service destinations");
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// Adds menu to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// buttons
final CustomButton addDestButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addDestination());
final CustomButton removeDestButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
menu.addWidget(addDestButton);
menu.addWidget(removeDestButton);
menu.addWidget(new HTML("<strong>Selected facility:</strong>"));
// listbox with facilities
final ListBoxWithObjects<Facility> ls = new ListBoxWithObjects<Facility>();
menu.addWidget(ls);
// get empty table used for destinations
final GetAllRichDestinations callback = new GetAllRichDestinations(null, service);
callback.showFacilityColumn(true);
callback.showServiceColumn(false);
// do not make callback yet
final CellTable<Destination> table = callback.getEmptyTable();
if (lastSelectedFacilityId == 0) {
callback.retrieveData();
}
// refresh events called when selection changes or callback ends
final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
if (ls.getSelectedIndex() == 0) {
// fills table with destinations of all facilities
callback.clearTable();
callback.retrieveData();
} else {
callback.clearTable();
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
// fills table with destinations of selected facility
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
JsArray<Destination> dst = JsonUtils.jsoAsArray(jso);
for (int i = 0; i < dst.length(); i++) {
callback.addToTable(dst.get(i));
}
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
}
public void onError(PerunError error) {
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
}
};
final GetDestinations callback = new GetDestinations(ls.getSelectedObject(), service, localEvents);
callback.retrieveData();
}
}
};
// fills listbox and table with dest. for all service facilities
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ls.clear();
ArrayList<Facility> facs = JsonUtils.jsoAsList(jso);
facs = new TableSorter<Facility>().sortByName(facs);
// if no facility
if (facs.size() == 0) {
ls.addItem("No facility available");
return;
}
for (int i = 0; i < facs.size(); i++) {
ls.addItem(facs.get(i));
if (facs.get(i).getId() == lastSelectedFacilityId) {
ls.setSelected(facs.get(i), true);
}
}
ls.addAllOption();
if (lastSelectedFacilityId == 0) {
// select all
ls.setItemSelected(0, true);
} else {
// was selected
addDestButton.setEnabled(true);
refreshEvents.onFinished(null);
}
}
public void onError(PerunError error) {
ls.addItem("Error while loading");
addDestButton.setEnabled(false);
}
public void onLoadingStart() {
ls.clear();
ls.addItem("Loading...");
addDestButton.setEnabled(false);
}
};
final GetAssignedFacilities assignedFacilities = new GetAssignedFacilities(PerunEntity.SERVICE, serviceId, events);
assignedFacilities.retrieveData();
ls.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (ls.getSelectedIndex() > 0) {
// store last selected facility id
addDestButton.setEnabled(true);
lastSelectedFacilityId = ls.getSelectedObject().getId();
} else {
addDestButton.setEnabled(false);
lastSelectedFacilityId = 0;
}
refreshEvents.onFinished(null);
}
});
// CLICK HANDLERS FOR BUTTONS
addDestButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddFacilityDestinationTabItem(ls.getSelectedObject()));
}
});
removeDestButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// get
final ArrayList<Destination> destsToRemove = callback.getTableSelectedList();
UiElements.showDeleteConfirm(destsToRemove, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < destsToRemove.size(); i++) {
if (i == destsToRemove.size() - 1) {
RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton, refreshEvents));
request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
} else {
RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton));
request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
}
}
}
});
}
});
// filter box
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
callback.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterDestinationByFacility());
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
removeDestButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeDestButton);
// add tabs to the main panel
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations