use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AssignTagTabItem method draw.
public Widget draw() {
titleWidget.setText("Add tag");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
final GetAllResourcesTags tags = new GetAllResourcesTags(PerunEntity.VIRTUAL_ORGANIZATION, resource.getVoId());
final CellTable<ResourceTag> table = tags.getTable();
final TabItem tab = this;
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedTagsToResource());
assignButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ResourceTag> tagsToAssign = tags.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(tagsToAssign)) {
for (int i = 0; i < tagsToAssign.size(); i++) {
if (i != tagsToAssign.size() - 1) {
// call json normaly
AssignResourceTag request = new AssignResourceTag(resourceId, JsonCallbackEvents.disableButtonEvents(assignButton));
request.assignResourceTag(tagsToAssign.get(i));
} else {
// last change - call json with update
AssignResourceTag request = new AssignResourceTag(resourceId, JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
request.assignResourceTag(tagsToAssign.get(i));
}
}
}
}
});
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(tags.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
tags.filterTable(text);
// if single group, select
if (tags.getList().size() == 1) {
table.getSelectionModel().setSelected(tags.getList().get(0), true);
}
}
}, ButtonTranslation.INSTANCE.filterGroup());
vp.add(menu);
vp.setCellHeight(menu, "30px");
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(tags, table, assignButton);
tags.retrieveData();
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 cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class MembershipExpirationTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Set membership expiration");
VerticalPanel vp = new VerticalPanel();
vp.setSize("350px", "100%");
final FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
layout.setStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "Current expiration:");
layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
layout.setHTML(0, 1, member.getStatus());
final Attribute expire = member.getAttribute("urn:perun:member:attribute-def:def:membershipExpiration");
String expirationValue = null;
if (expire != null && !"null".equalsIgnoreCase(expire.getValue())) {
layout.setHTML(0, 1, expire.getValue());
expirationValue = expire.getValue().substring(0, ((expire.getValue().length() > 10) ? 9 : expire.getValue().length() - 1));
} else {
layout.setHTML(0, 1, "<i>never</i>");
}
layout.setHTML(1, 0, "New expiration:");
layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
final CustomButton changeButton = new CustomButton("Save", "Save changes in membership expiration date", SmallIcons.INSTANCE.diskIcon());
final DatePicker picker = new DatePicker();
picker.setWidth("100%");
layout.getFlexCellFormatter().setColSpan(2, 0, 2);
layout.setWidget(2, 0, picker);
picker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(ValueChangeEvent<Date> dateValueChangeEvent) {
layout.setHTML(1, 1, DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
changeButton.setEnabled(true);
changeOrNever = true;
}
});
try {
// set values if possible
picker.setCurrentMonth(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
picker.setValue(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
} catch (Exception ex) {
// if not parseable, display current date
picker.setCurrentMonth(new Date());
picker.setValue(new Date());
}
Anchor anchor = new Anchor("Set expiration to 'never'");
anchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
layout.setHTML(1, 1, "<i>never</i>");
changeOrNever = false;
changeButton.setEnabled(true);
}
});
layout.setWidget(3, 0, anchor);
layout.getFlexCellFormatter().setColSpan(3, 0, 2);
layout.getFlexCellFormatter().getElement(3, 0).setAttribute("style", "text-align: right;");
TabMenu menu = new TabMenu();
final TabItem tab = this;
// by default false
changeButton.setEnabled(false);
changeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (changeOrNever) {
expire.setValueAsString(DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
ArrayList<Attribute> list = new ArrayList<Attribute>();
list.add(expire);
request.setAttributes(ids, list);
} else {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
ArrayList<Attribute> list = new ArrayList<Attribute>();
list.add(expire);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(changeButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
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 CreateOwnerTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// textboxes which set the class data when updated
final ExtendedTextBox ownerNameTextBox = new ExtendedTextBox();
final ExtendedTextBox ownerContactTextBox = new ExtendedTextBox();
final ListBox ownerType = new ListBox();
ownerType.addItem(ObjectTranslation.INSTANCE.ownerTypeAdministrative(), "administrative");
ownerType.addItem(ObjectTranslation.INSTANCE.ownerTypeTechnical(), "technical");
final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (ownerNameTextBox.getTextBox().getText().trim().isEmpty()) {
ownerNameTextBox.setError("Name can't be empty.");
return false;
}
ownerNameTextBox.setOk();
return true;
}
};
final ExtendedTextBox.TextBoxValidator contactValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (ownerContactTextBox.getTextBox().getText().trim().isEmpty()) {
ownerContactTextBox.setError("Contact can't be empty.");
return false;
}
ownerContactTextBox.setOk();
return true;
}
};
ownerNameTextBox.setValidator(nameValidator);
ownerContactTextBox.setValidator(contactValidator);
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add some standard form options
layout.setHTML(0, 0, "Name:");
layout.setWidget(0, 1, ownerNameTextBox);
layout.setHTML(1, 0, "Contact:");
layout.setWidget(1, 1, ownerContactTextBox);
layout.setHTML(2, 0, "Type:");
layout.setWidget(2, 1, ownerType);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
// buttons
TabMenu menu = new TabMenu();
final TabItem tab = this;
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createOwner());
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (nameValidator.validateTextBox() && contactValidator.validateTextBox()) {
CreateOwner request = new CreateOwner(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
request.createOwner(ownerNameTextBox.getTextBox().getText().trim(), ownerContactTextBox.getTextBox().getText().trim(), ownerType.getValue(ownerType.getSelectedIndex()));
}
}
});
menu.addWidget(createButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
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 CreateFacilityResourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Create resource");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// form inputs
final ExtendedTextBox nameTextBox = new ExtendedTextBox();
final TextBox descriptionTextBox = new TextBox();
final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
// send button
final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
// local events fills the listbox of Vos and Slds
JsonCallbackEvents event = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// fill VOs listbox
vosDropDown.clear();
ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
vos = new TableSorter<VirtualOrganization>().sortByName(vos);
for (VirtualOrganization vo : vos) {
vosDropDown.addItem(vo);
}
if (!vos.isEmpty())
createButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
vosDropDown.clear();
vosDropDown.addItem("Loading...");
createButton.setEnabled(false);
}
@Override
public void onError(PerunError error) {
vosDropDown.clear();
vosDropDown.addItem("Error while loading");
createButton.setEnabled(false);
}
};
// load available VOs
final GetVos vos = new GetVos(event);
vos.setForceAll(true);
vos.retrieveData();
// layout
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// Add some standard form options
layout.setHTML(0, 0, "On facility:");
layout.setHTML(0, 1, facility.getName());
layout.setHTML(1, 0, "For VO:");
layout.setWidget(1, 1, vosDropDown);
layout.setHTML(2, 0, "Name:");
layout.setWidget(2, 1, nameTextBox);
layout.setHTML(3, 0, "Description:");
layout.setWidget(3, 1, descriptionTextBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setWidth("350px");
TabMenu menu = new TabMenu();
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;
}
nameTextBox.setOk();
return true;
}
};
nameTextBox.setValidator(validator);
createButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// loads new tab when creating successful, also disable button
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onLoadingStart() {
(JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
}
public void onFinished(JavaScriptObject jso) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
Resource res = (Resource) jso;
session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
}
public void onError(PerunError error) {
(JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
}
};
if (validator.validateTextBox()) {
// request
CreateResource request = new CreateResource(localEvents);
request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
}
}
});
menu.addWidget(createButton);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
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 CreateFormItemTabItem method draw.
public Widget draw() {
// vertical panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("425px", "100%");
// flex table
final FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// select widget short name
final ExtendedTextBox shortNameTextBox = new ExtendedTextBox();
shortNameTextBox.setWidth("200px");
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (shortNameTextBox.getTextBox().getText().trim().isEmpty()) {
shortNameTextBox.setError("Short name can't be empty.");
return false;
} else {
shortNameTextBox.setOk();
return true;
}
}
};
shortNameTextBox.setValidator(validator);
// select widget type
final ListBox typeListBox = new ListBox();
for (String type : inputTypes.keySet()) {
typeListBox.addItem(inputTypes.get(type), type);
}
// insert after
final ListBox insertAfterListBox = new ListBox();
insertAfterListBox.addItem(" - insert to the beginning - ", 0 + "");
for (int i = 0; i < sourceList.size(); i++) {
ApplicationFormItem item = sourceList.get(i);
// with default en locale
RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, "");
String label = gen.getFormItem().getShortname();
// crop length
if (label.length() > CROP_LABEL_LENGTH) {
label = label.substring(0, CROP_LABEL_LENGTH);
}
// add to box
insertAfterListBox.addItem(label, (i + 1) + "");
}
layout.setHTML(0, 0, "Short name:");
layout.setWidget(0, 1, shortNameTextBox);
layout.setHTML(1, 0, "Input widget:");
layout.setWidget(1, 1, typeListBox);
layout.setHTML(2, 0, "Insert after:");
layout.setWidget(2, 1, insertAfterListBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setHTML(3, 0, "");
cellFormatter.setColSpan(3, 0, 2);
cellFormatter.setStyleName(3, 0, "inputFormInlineComment");
typeListBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
if (type.equals("TEXTFIELD")) {
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
} else if (type.equals("TEXTAREA")) {
layout.setHTML(3, 0, "Editable text area useful to gather longer text input with linebreaks, e.g. comments, SSH key");
} else if (type.equals("SELECTIONBOX")) {
layout.setHTML(3, 0, "Simple selection box with defined custom values that user can choose.");
} else if (type.equals("COMBOBOX")) {
layout.setHTML(3, 0, "Selection box with defined custom values and one special option: \"--custom value--\", which allows users to input own text (as simple text field).");
} else if (type.equals("CHECKBOX")) {
layout.setHTML(3, 0, "List of defined custom options with checkboxes. Selected values are gathered as comma separated string.");
} else if (type.equals("USERNAME")) {
layout.setHTML(3, 0, "Special text field to gather user`s login. It checks login availability on user input.");
} else if (type.equals("PASSWORD")) {
layout.setHTML(3, 0, "Two password fields to gather user`s new password. Input is never displayed. User must type same password in both fields.");
} else if (type.equals("VALIDATED_EMAIL")) {
layout.setHTML(3, 0, "Special text field to gather and verify user`s email address. Input is checked on email address format. If user enters new value, then validation email is sent. Application then can't be approved unless provided email address is validated.");
} else if (type.equals("SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to submit the form with custom label. All other form items are checked on valid input before submission. If it fails, form is not sent.");
} else if (type.equals("AUTO_SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to auto-submit the form with custom label. All other form items are checked on valid input before submission. If validation fail (at least once) user must submit form manually. If it's OK, then form is automatically submitted.");
} else if (type.equals("HTML_COMMENT")) {
layout.setHTML(3, 0, "Item is used to display custom HTML content anywhere on form. Useful for explanation descriptions, dividing parts of form etc.");
} else if (type.equals("HEADING")) {
layout.setHTML(3, 0, "Item is used to display customizable heading of form. Can have any HTML content.");
} else if (type.equals("TIMEZONE")) {
layout.setHTML(3, 0, "Selection box with pre-defined values of UTC timezones.");
} else if (type.equals("FROM_FEDERATION_HIDDEN")) {
layout.setHTML(3, 0, "Non-editable and hidden form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else if (type.equals("FROM_FEDERATION_SHOW")) {
layout.setHTML(3, 0, "Non-editable and visible form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else {
layout.setHTML(3, 0, "");
}
}
});
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
TabMenu menu = new TabMenu();
// create button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createFormItem(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox()) {
int positionToAdd = Integer.parseInt(insertAfterListBox.getValue(insertAfterListBox.getSelectedIndex()));
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
String shortName = shortNameTextBox.getTextBox().getText().trim();
createItem(shortName, type, positionToAdd);
}
}
}));
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations