use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class CreateGroupTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
// used for closing
final TabItem tab = this;
// form inputs
final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
final TextBox groupDescriptionTextBox = new TextBox();
final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
vosGroups.setVisible(false);
final CheckBox asSubGroup = new CheckBox("", false);
TabMenu menu = new TabMenu();
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
final HTML parentGroupText = new HTML("Parent group:");
parentGroupText.setVisible(false);
final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosGroups.clear();
ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
retGroups = new TableSorter<Group>().sortByName(retGroups);
for (Group g : retGroups) {
if (!g.isCoreGroup()) {
// SKIP CORE GROUPS !!
vosGroups.addItem(g);
if (g.getId() == groupId) {
// select default if passed to tab
vosGroups.setSelected(g, true);
}
}
}
if (vosGroups.getAllObjects().isEmpty()) {
vosGroups.addItem("No groups found");
} else {
createButton.setEnabled(true);
}
// call finished when user changed his mind
if (!asSubGroup.getValue()) {
createButton.setEnabled(true);
}
}
public void onLoadingStart() {
vosGroups.clear();
vosGroups.addItem("Loading...");
createButton.setEnabled(false);
}
public void onError(PerunError error) {
vosGroups.clear();
vosGroups.addItem("Error while loading");
if (!asSubGroup.getValue()) {
createButton.setEnabled(true);
}
}
});
// set title
if (PerunEntity.GROUP.equals(entity)) {
this.titleWidget.setText("Create sub-group");
asSubGroup.setValue(true);
createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
parentGroupText.setVisible(true);
vosGroups.setVisible(true);
groupsCall.retrieveData();
} else {
this.titleWidget.setText("Create group");
createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
}
asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
if (booleanValueChangeEvent.getValue() == true) {
// set title
titleWidget.setText("Create sub-group");
vosGroups.setVisible(true);
parentGroupText.setVisible(true);
groupsCall.retrieveData();
createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
} else {
titleWidget.setText("Create group");
vosGroups.setVisible(false);
parentGroupText.setVisible(false);
createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
createButton.setEnabled(true);
}
}
});
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
groupNameTextBox.setError("Name can't be empty.");
} else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
groupNameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
} else {
groupNameTextBox.setOk();
return true;
}
return false;
}
};
groupNameTextBox.setValidator(validator);
// send button
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!validator.validateTextBox())
return;
// creates a new request
CreateGroup cg = new CreateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
if (asSubGroup.getValue()) {
if (vosGroups.getSelectedObject() != null) {
cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
} else {
UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
}
} else {
cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText().trim());
}
}
});
// cancel button
cancelButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
});
// Add some standard form options
layout.setHTML(0, 0, "Name:");
layout.setWidget(0, 1, groupNameTextBox);
layout.setHTML(1, 0, "Description:");
layout.setWidget(1, 1, groupDescriptionTextBox);
layout.setHTML(2, 0, "As sub-group:");
layout.setWidget(2, 1, asSubGroup);
layout.setWidget(3, 0, parentGroupText);
layout.setWidget(3, 1, vosGroups);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
// button align
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.tabs.TabItem in project perun by CESNET.
the class EditGroupDetailsTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit group");
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox descriptionTextBox = new ExtendedTextBox();
descriptionTextBox.getTextBox().setText(group.getDescription());
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setText(group.getShortName());
// disable name change for core groups
nameTextBox.getTextBox().setEnabled(!group.isCoreGroup());
// 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.saveGroupDetails());
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
nameTextBox.setError("Name can't be empty.");
} else if (!nameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
nameTextBox.setError("Name can contain only a-z, A-Z, numbers, spaces, dots, '_' and '-'.");
} else {
nameTextBox.setOk();
return true;
}
return false;
}
};
nameTextBox.setValidator(validator);
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (!validator.validateTextBox())
return;
Group g = JsonUtils.clone(group).cast();
g.setDescription(descriptionTextBox.getTextBox().getText().trim());
String value = nameTextBox.getTextBox().getText().trim();
g.setShortName(value);
int index = g.getName().lastIndexOf(":");
if (index > 0) {
// short name append to base name
String baseName = g.getName().substring(0, index);
baseName += ":" + g.getShortName();
g.setName(baseName);
} else {
// short name is whole name
g.setName(value);
}
;
UpdateGroup request = new UpdateGroup(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
request.updateGroup(g);
}
});
// 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, "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(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.tabs.TabItem in project perun by CESNET.
the class AddHostsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": add hosts");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final ExtendedTextArea newHosts = new ExtendedTextArea();
newHosts.getTextArea().setSize("335px", "150px");
final ExtendedTextArea.TextAreaValidator validator = new ExtendedTextArea.TextAreaValidator() {
@Override
public boolean validateTextArea() {
if (newHosts.getTextArea().getText().trim().isEmpty()) {
newHosts.setError("Please enter at least one hostname to add it to facility.");
return false;
} else {
newHosts.setOk();
return true;
}
}
};
newHosts.setValidator(validator);
final CustomButton addHostsButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addHost());
// close tab, disable button
final TabItem tab = this;
addHostsButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextArea()) {
String hostnames = newHosts.getTextArea().getText().trim();
String[] hosts = hostnames.split("\n");
// trim whitespace
for (int i = 0; i < hosts.length; i++) {
hosts[i] = hosts[i].trim();
}
AddHosts request = new AddHosts(facility.getId(), JsonCallbackEvents.closeTabDisableButtonEvents(addHostsButton, tab));
request.addHosts(hosts);
}
}
});
TabMenu menu = new TabMenu();
menu.addWidget(addHostsButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
// layout
final FlexTable layout = new FlexTable();
layout.setWidth("350px");
layout.setStyleName("inputFormFlexTable");
FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
layout.setHTML(0, 0, "Hostnames:");
layout.setWidget(1, 0, newHosts);
cellFormatter.addStyleName(0, 0, "itemName");
layout.setHTML(2, 0, "Enter one host per line. You can use \"[x-y]\" in hostname to generate hosts with numbers from x to y. This replacer can be specified multiple times in one hostname to generate MxN combinations.");
cellFormatter.addStyleName(2, 0, "inputFormInlineComment");
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class EditFacilityDetailsTabItem method draw.
public Widget draw() {
titleWidget = new Label("Edit facility");
VerticalPanel vp = new VerticalPanel();
// textboxes which set the class data when updated
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
nameTextBox.getTextBox().setText(facility.getName());
final TextBox descriptionTextBox = new TextBox();
descriptionTextBox.setText(facility.getDescription());
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;
} else if (!nameTextBox.getTextBox().getText().trim().matches(Utils.FACILITY_NAME_MATCHER)) {
nameTextBox.setError("Name can contain only letters, numbers, dash, dot and underscore.");
return false;
} else {
nameTextBox.setOk();
return true;
}
}
};
nameTextBox.setValidator(validator);
// 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.saveFacilityDetails());
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox()) {
Facility fac = JsonUtils.clone(facility).cast();
fac.setName(nameTextBox.getTextBox().getText().trim());
fac.setDescription(descriptionTextBox.getText().trim());
UpdateFacility request = new UpdateFacility(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab, events));
request.updateFacility(fac);
}
}
});
// 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, "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(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.tabs.TabItem in project perun by CESNET.
the class ShellChangeTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
final FlexTable ft = new FlexTable();
ft.setWidth("350px");
ft.setStyleName("inputFormFlexTable");
ft.setHTML(0, 0, "Available shells:");
ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
final ListBox shells = new ListBox();
shells.setWidth("200px");
ft.setWidget(0, 1, shells);
vp.add(ft);
final CustomButton selectShellButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save preferred shell");
// callback for available shells
GetAttributes attrs = new GetAttributes(new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
shells.clear();
shells.addItem("Error while loading");
}
@Override
public void onFinished(JavaScriptObject jso) {
shells.clear();
ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
if (list.isEmpty() || list == null) {
shells.addItem("No shells available");
return;
}
// fill shells
for (Attribute a : list) {
if (a.getFriendlyName().equalsIgnoreCase("shells")) {
for (int i = 0; i < a.getValueAsJsArray().length(); i++) {
// fill shell values
shells.addItem(a.getValueAsJsArray().get(i));
}
break;
}
}
// set selected
for (int i = 0; i < shells.getItemCount(); i++) {
if (shells.getValue(i).equals(a.getValue())) {
shells.setSelectedIndex(i);
break;
}
}
if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
selectShellButton.setEnabled(false);
} else {
selectShellButton.setEnabled(true);
}
}
@Override
public void onLoadingStart() {
shells.clear();
shells.addItem("Loading...");
}
});
final TabItem tab = this;
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
selectShellButton.setEnabled(false);
selectShellButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// OK click button
// set new value
a.setValue(shells.getValue(shells.getSelectedIndex()));
// send request
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", resource.getFacilityId());
SetAttribute request = new SetAttribute(JsonCallbackEvents.disableButtonEvents(selectShellButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// refresh only what's necessary
events.onFinished(jso);
// don't refresh underlaying tab
session.getTabManager().closeTab(tab, false);
}
}));
request.setAttribute(ids, a);
}
});
attrs.getResourceAttributes(resource.getId());
attrs.retrieveData();
shells.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
selectShellButton.setEnabled(false);
} else {
selectShellButton.setEnabled(true);
}
}
});
final CustomButton defaultButton = new CustomButton("Use default", "", SmallIcons.INSTANCE.lightningIcon());
defaultButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("user", userId);
ids.put("facility", resource.getFacilityId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(defaultButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// refresh only what's necessary
events.onFinished(jso);
// don't refresh underlaying tab
session.getTabManager().closeTab(tab, false);
}
}));
ArrayList<Attribute> list = new ArrayList<Attribute>();
list.add(a);
request.removeAttributes(ids, list);
}
});
menu.addWidget(selectShellButton);
menu.addWidget(defaultButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
contentWidget.setWidget(vp);
return getWidget();
}
Aggregations