use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class GetAttributesDefinition method getTable.
/**
* Returns table widget with attributes definitions
*
* @return table widget
*/
public CellTable<AttributeDefinition> getTable() {
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<AttributeDefinition>(list);
// Cell table
table = new PerunTable<AttributeDefinition>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<AttributeDefinition> columnSortHandler = new ListHandler<AttributeDefinition>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<AttributeDefinition>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("No attribute defined in Perun.");
// checkbox column column
if (checkable) {
table.addCheckBoxColumn();
}
// ID COLUMN
table.addIdColumn("Attr ID", tableFieldUpdater, 100);
// FRIENDLY NAME COLUMN
final Column<AttributeDefinition, AttributeDefinition> friendlyNameColumn = JsonUtils.addColumn(new PerunAttributeFriendlyNameCell((tableFieldUpdater != null) ? "customClickableTextCell" : ""), new JsonUtils.GetValue<AttributeDefinition, AttributeDefinition>() {
public AttributeDefinition getValue(AttributeDefinition object) {
return object;
}
}, (tableFieldUpdater != null) ? new FieldUpdater<AttributeDefinition, AttributeDefinition>() {
@Override
public void update(int index, AttributeDefinition object, AttributeDefinition value) {
// pass field updater to original one
if (tableFieldUpdater != null)
tableFieldUpdater.update(index, object, value.getFriendlyName());
}
} : null);
// ENTITY COLUMN
final Column<AttributeDefinition, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {
public String getValue(AttributeDefinition object) {
return object.getEntity();
}
}, tableFieldUpdater);
// DEFINITION COLUMN
final Column<AttributeDefinition, String> definitionColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {
public String getValue(AttributeDefinition object) {
return object.getDefinition();
}
}, tableFieldUpdater);
// TYPE COLUMN
final Column<AttributeDefinition, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {
public String getValue(AttributeDefinition object) {
if (object.getType() != null) {
return object.getType().substring(object.getType().lastIndexOf(".") + 1);
}
return "";
}
}, tableFieldUpdater);
// UNIQUE COLUMN
final Column<AttributeDefinition, String> uniqueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {
public String getValue(AttributeDefinition object) {
return String.valueOf(object.isUnique());
}
}, tableFieldUpdater);
// DESCRIPTION COLUMN
final Column<AttributeDefinition, String> descriptionColumn = new Column<AttributeDefinition, String>(new TextInputCell()) {
public String getValue(AttributeDefinition attrDef) {
if (attrDef.getDescription() == null) {
return "";
} else {
return attrDef.getDescription();
}
}
};
descriptionColumn.setFieldUpdater(new FieldUpdater<AttributeDefinition, String>() {
@Override
public void update(int i, final AttributeDefinition attributeDefinition, final String s) {
attributeDefinition.setDescription(s.trim());
selectionModel.setSelected(attributeDefinition, true);
}
});
// DISPLAY NAME COLUMN
final Column<AttributeDefinition, String> displayNameColumn = new Column<AttributeDefinition, String>(new TextInputCell()) {
public String getValue(AttributeDefinition attrDef) {
return attrDef.getDisplayName();
}
};
displayNameColumn.setFieldUpdater(new FieldUpdater<AttributeDefinition, String>() {
@Override
public void update(int i, final AttributeDefinition attributeDefinition, final String s) {
attributeDefinition.setDisplayName(s.trim());
selectionModel.setSelected(attributeDefinition, true);
}
});
friendlyNameColumn.setSortable(true);
columnSortHandler.setComparator(friendlyNameColumn, new Comparator<AttributeDefinition>() {
public int compare(AttributeDefinition o1, AttributeDefinition o2) {
return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
}
});
entityColumn.setSortable(true);
columnSortHandler.setComparator(entityColumn, new Comparator<AttributeDefinition>() {
public int compare(AttributeDefinition o1, AttributeDefinition o2) {
return o1.getEntity().compareToIgnoreCase(o2.getEntity());
}
});
definitionColumn.setSortable(true);
columnSortHandler.setComparator(definitionColumn, new Comparator<AttributeDefinition>() {
public int compare(AttributeDefinition o1, AttributeDefinition o2) {
return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
}
});
typeColumn.setSortable(true);
columnSortHandler.setComparator(typeColumn, new Comparator<AttributeDefinition>() {
public int compare(AttributeDefinition o1, AttributeDefinition o2) {
return o1.getType().compareToIgnoreCase(o2.getType());
}
});
uniqueColumn.setSortable(true);
columnSortHandler.setComparator(uniqueColumn, new Comparator<AttributeDefinition>() {
public int compare(AttributeDefinition o1, AttributeDefinition o2) {
return String.valueOf(o1.isUnique()).compareToIgnoreCase(String.valueOf(o2.isUnique()));
}
});
// Add the column sort handler.
table.setColumnWidth(friendlyNameColumn, 250.0, Unit.PX);
table.setColumnWidth(entityColumn, 100.0, Unit.PX);
table.setColumnWidth(definitionColumn, 100.0, Unit.PX);
table.setColumnWidth(typeColumn, 100.0, Unit.PX);
table.setColumnWidth(uniqueColumn, 100.0, Unit.PX);
// Add the columns.
table.addColumn(friendlyNameColumn, "Name");
// attributesTable.addColumn(namespaceColumn, "Namespace");
table.addColumn(entityColumn, "Entity");
table.addColumn(definitionColumn, "Definition");
table.addColumn(typeColumn, "Type");
table.addColumn(uniqueColumn, "Unique");
if (editable) {
table.addColumn(displayNameColumn, "Display name");
table.addColumn(descriptionColumn, "Description");
}
return table;
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class GetAttributesDefinition method setList.
public void setList(ArrayList<AttributeDefinition> list) {
clearTable();
this.list.addAll(list);
for (AttributeDefinition a : list) {
oracle.add(a.getFriendlyName());
}
dataProvider.flush();
dataProvider.refresh();
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class ServiceRequiredAttributesTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(service.getName()) + ": Required attributes");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// create new json call for required attributes of service with id=?
final GetServiceRequiredAttributes servReqAttr = new GetServiceRequiredAttributes(serviceId);
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
final ExtendedSuggestBox box = new ExtendedSuggestBox(servReqAttr.getOracle());
// custom event
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(servReqAttr);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addRequiredAttribute(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new AddRequiredAttributesTabItem(service), true);
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedRequiredAttributes());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
final ArrayList<AttributeDefinition> attrsForRemoving = servReqAttr.getTableSelectedList();
UiElements.showDeleteConfirm(attrsForRemoving, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < attrsForRemoving.size(); i++) {
if (i == attrsForRemoving.size() - 1) {
RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.mergeEvents(events, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// clear filter since filter ignores next call for some reason
box.getSuggestBox().setText("");
}
})));
request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
} else {
RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton));
request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
menu.addFilterWidget(box, new PerunSearchEvent() {
@Override
public void searchFor(String text) {
servReqAttr.filterTable(text);
}
}, "Filter required attributes by name");
vp.add(menu);
vp.setCellHeight(menu, "30px");
// get table = make call
CellTable<AttributeDefinition> reqAttrTable = servReqAttr.getTable();
// create scroll panel for table
reqAttrTable.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(reqAttrTable);
sp.addStyleName("perun-tableScrollPanel");
sp.setWidth("100%");
vp.add(sp);
vp.setCellHeight(sp, "100%");
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(servReqAttr, reqAttrTable, removeButton);
session.getUiElements().resizePerunTable(sp, 350, this);
// add tabs to the main panel
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class GetAttributesDefinition method onFinished.
/**
* Called, when operation finishes successfully.
*/
public void onFinished(JavaScriptObject jso) {
clearTable();
for (AttributeDefinition a : JsonUtils.<AttributeDefinition>jsoAsList(jso)) {
// check namespace for core
if (noCore && a.getDefinition().equals("core")) {
// do not add anything
} else {
// if not empty, proceed to check
if (!entities.isEmpty()) {
if (entities.contains(a.getEntity())) {
// add
addToTable(a);
}
} else {
addToTable(a);
}
}
}
sortTable();
loaderImage.loadingFinished();
session.getUiElements().setLogText("Attribute definitions loaded: " + list.size());
events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.
the class GetAttributesDefinition method removeFromBackupTable.
/**
* Removes object as row from table
*
* @param object AttributeDefinition to be removed as row
*/
public void removeFromBackupTable(AttributeDefinition object) {
fullBackup.remove(object);
list.remove(object);
selectionModel.setSelected(object, false);
oracle.clear();
for (AttributeDefinition def : fullBackup) {
oracle.add(def.getFriendlyName());
}
dataProvider.flush();
dataProvider.refresh();
}
Aggregations