use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class AttributeDefinitionsTabItem method draw.
public Widget draw() {
// create main panel for content
VerticalPanel mainPage = new VerticalPanel();
mainPage.setWidth("100%");
// create new instance for jsonCall
final GetAttributesDefinition attrDef = new GetAttributesDefinition();
final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDef.getOracle());
// custom events for reloading when created or deleted
final JsonCallbackEvents refreshTabEvents = JsonCallbackEvents.mergeEvents(JsonCallbackEvents.refreshTableEvents(attrDef), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (box.getSuggestBox().getValue() != null)
attrDef.filterTable(box.getSuggestBox().getValue());
}
});
// TAB MENU
TabMenu tabMenu = new TabMenu();
tabMenu.addWidget(UiElements.getRefreshButton(this));
// create buttons
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, buttonTranslation.createAttributeDefinition(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateAttributeDefinitionTabItem());
}
}));
// remove button
final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, buttonTranslation.deleteAttributeDefinition());
deleteButton.setEnabled(false);
deleteButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<AttributeDefinition> attrDefToBeDeleted = attrDef.getTableSelectedList();
String text = "Following attribute definitions will be deleted.</p><p style=\"color: red;\">All stored values of such attributes will be deleted too!";
UiElements.showDeleteConfirm(attrDefToBeDeleted, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attrDefToBeDeleted.size(); i++) {
final int x = i;
DeleteAttribute request = new DeleteAttribute(JsonCallbackEvents.disableButtonEvents(deleteButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// remove deleted attrs from table
attrDef.removeFromBackupTable(attrDefToBeDeleted.get(x));
}
}));
request.deleteAttributeDefinition(attrDefToBeDeleted.get(i).getId());
}
}
});
}
});
tabMenu.addWidget(deleteButton);
// filter box
tabMenu.addFilterWidget(box, new PerunSearchEvent() {
public void searchFor(String text) {
attrDef.filterTable(text);
}
}, buttonTranslation.filterAttributeDefinition());
final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
final ArrayList<AttributeDefinition> list = attrDef.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
final int x = i;
UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
attrDef.getSelectionModel().setSelected(list.get(x), false);
}
}));
request.updateAttribute(list.get(i));
}
}
}
});
tabMenu.addWidget(saveButton);
// if checkbox is checked only entityless attributes will be shown
CheckBox showEntitylessBox = new CheckBox("Show only Entityless Attributes");
showEntitylessBox.setValue(false);
showEntitylessBox.addValueChangeHandler(valueChangeEvent -> {
if (showEntitylessBox.getValue()) {
attrDef.setEntity("entityless");
} else {
attrDef.setEntities(new HashSet<>());
}
attrDef.retrieveData();
});
tabMenu.addWidget(showEntitylessBox);
// add menu to page
mainPage.add(tabMenu);
mainPage.setCellHeight(tabMenu, "30px");
CellTable<AttributeDefinition> attrDefTable = attrDef.getTable(new FieldUpdater<AttributeDefinition, String>() {
@Override
public void update(int index, AttributeDefinition object, String value) {
if (object.getEntity().equals("entityless")) {
session.getTabManager().addTabToCurrentTab(new EntitylessAttributesDetailTabItem(object), true);
} else {
session.getTabManager().addTabToCurrentTab(new AttributeDefinitionDetailTabItem(object), true);
}
}
});
attrDefTable.setStyleName("perun-table");
ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
scrollTable.addStyleName("perun-tableScrollPanel");
JsonUtils.addTableManagedButton(attrDef, attrDefTable, deleteButton);
// put page into scroll panel
mainPage.add(scrollTable);
session.getUiElements().resizePerunTable(scrollTable, 350, this);
this.contentWidget.setWidget(mainPage);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class PerunSearchParametersWidget method addParameter.
/**
* Adds a parameter
*/
protected void addParameter() {
TextBox tb = new TextBox();
final ListBoxWithObjects<AttributeDefinition> lb = new ListBoxWithObjects<AttributeDefinition>();
inputs.put(lb, tb);
lb.addAllItems(availableAttrDefs);
rebuild();
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class PerunSearchParametersWidget method rebuild.
/**
* Method which rebuild whole searcher widget when number of params changes
*/
protected void rebuild() {
ft.clear();
// ft.setHTML(0, 0, "<h3>" + "Search by parameters:" + "</h3>");
// ft.getFlexCellFormatter().setColSpan(0, 0, 4);
int row = 1;
for (Map.Entry<ListBoxWithObjects<AttributeDefinition>, TextBox> entry : inputs.entrySet()) {
final ListBoxWithObjects<AttributeDefinition> lb = entry.getKey();
int selectedItem = lb.getSelectedIndex();
lb.clear();
lb.addAllItems(availableAttrDefs);
lb.setSelectedIndex(selectedItem);
CustomButton rb = new CustomButton("", SmallIcons.INSTANCE.deleteIcon());
ft.setWidget(row, 0, lb);
ft.setText(row, 1, "=");
ft.setWidget(row, 2, entry.getValue());
ft.setWidget(row, 3, rb);
if (inputs.entrySet().size() <= 1) {
// allow remove if more than 1
rb.setEnabled(false);
rb.setTitle("Enabled only when more than 1 parameter is used.");
}
rb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
inputs.keySet().remove(lb);
rebuild();
}
});
row++;
}
ft.setWidget(row, 0, addParameterButton);
ft.setHTML(row, 1, "");
ft.setWidget(row, 2, searchButton);
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class AddRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText("Add required attributes");
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
final GetAttributesDefinition attrDefs = new GetAttributesDefinition();
attrDefs.setEditable(false);
CellTable<AttributeDefinition> table = attrDefs.getTable();
TabMenu menu = new TabMenu();
final TabItem tab = this;
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedRequiredAttribute());
final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDefs.getOracle());
menu.addFilterWidget(box, new PerunSearchEvent() {
@Override
public void searchFor(String text) {
attrDefs.filterTable(text);
if (attrDefs.getList().size() == 1) {
attrDefs.getSelectionModel().setSelected(attrDefs.getList().get(0), true);
}
}
}, ButtonTranslation.INSTANCE.filterAttributeDefinition());
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<AttributeDefinition> attributesToAdd = attrDefs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(attributesToAdd)) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attributesToAdd.size(); i++) {
final int n = i;
AddRequiredAttribute request = new AddRequiredAttribute(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// unselect added attribute
attrDefs.getSelectionModel().setSelected(attributesToAdd.get(n), false);
alreadyAddedList.add(attributesToAdd.get(n));
rebuildAlreadyAddedWidget();
// clear search
box.getSuggestBox().setText("");
}
}));
request.addRequiredAttribute(serviceId, attributesToAdd.get(i).getId());
}
}
}
});
menu.addWidget(addButton);
// cancel button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(attrDefs, table, addButton);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
mainTab.add(menu);
mainTab.setCellHeight(menu, "30px");
mainTab.add(alreadyAdded);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
// add tabs to the main panel
this.contentWidget.setWidget(mainTab);
return getWidget();
}
Aggregations