Search in sources :

Example 1 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class CreateAttributeDefinitionTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // creates HTML elements
    final ExtendedTextBox attributeDisplayName = new ExtendedTextBox();
    final ExtendedTextBox attributeName = new ExtendedTextBox();
    final ExtendedTextBox attributeDescription = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (attributeName.getTextBox().getText().trim().isEmpty()) {
                attributeName.setError("Name of attribute can't be empty.");
            } else if (!attributeName.getTextBox().getText().trim().matches(Utils.ATTRIBUTE_FRIENDLY_NAME_MATCHER)) {
                attributeName.setError("Name of attribute can contain only letters, numbers, dash and colon.");
            } else {
                attributeName.setOk();
                return true;
            }
            return false;
        }
    };
    final ExtendedTextBox.TextBoxValidator descriptionValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDescription.getTextBox().getText().trim().isEmpty()) {
                attributeDescription.setOk();
                return true;
            } else {
                attributeDescription.setError("Description of attribute can't be empty.");
                return false;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator displayNameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDisplayName.getTextBox().getText().trim().isEmpty()) {
                attributeDisplayName.setOk();
                return true;
            } else {
                attributeDisplayName.setError("Display name of attribute can't be empty.");
                return false;
            }
        }
    };
    attributeName.setValidator(nameValidator);
    attributeDisplayName.setValidator(displayNameValidator);
    attributeDescription.setValidator(descriptionValidator);
    final ListBox entityListBox = new ListBox();
    final ListBox definitionListBox = new ListBox();
    final ListBox typeListBox = new ListBox();
    // fill listboxs with pre-defined values
    entityListBox.addItem("facility", "urn:perun:facility:");
    entityListBox.addItem("resource", "urn:perun:resource:");
    entityListBox.addItem("group", "urn:perun:group:");
    entityListBox.addItem("group_resource", "urn:perun:group_resource:");
    entityListBox.addItem("host", "urn:perun:host:");
    entityListBox.addItem("member", "urn:perun:member:");
    entityListBox.addItem("member_group", "urn:perun:member_group:");
    entityListBox.addItem("member_resource", "urn:perun:member_resource:");
    entityListBox.addItem("user", "urn:perun:user:");
    entityListBox.addItem("user_ext_source", "urn:perun:ues:");
    entityListBox.addItem("user_facility", "urn:perun:user_facility:");
    entityListBox.addItem("vo", "urn:perun:vo:");
    entityListBox.addItem("entityless", "urn:perun:entityless:");
    definitionListBox.addItem("def", "attribute-def:def");
    definitionListBox.addItem("opt", "attribute-def:opt");
    definitionListBox.addItem("virt", "attribute-def:virt");
    definitionListBox.addItem("core", "attribute-def:core");
    typeListBox.addItem("String", "java.lang.String");
    typeListBox.addItem("Integer", "java.lang.Integer");
    typeListBox.addItem("Boolean", "java.lang.Boolean");
    typeListBox.addItem("Array", "java.util.ArrayList");
    typeListBox.addItem("LinkedHashMap", "java.util.LinkedHashMap");
    // prepare layout for this tab
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    TabMenu menu = new TabMenu();
    // BUTTONS
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createAttributeDefinition());
    menu.addWidget(createButton);
    // close tab events & enable, disable buttons
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(createButton, this, true);
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (nameValidator.validateTextBox() && descriptionValidator.validateTextBox() && displayNameValidator.validateTextBox()) {
                String displayName = attributeDisplayName.getTextBox().getText().trim();
                String friendlyName = attributeName.getTextBox().getText().trim();
                String description = attributeDescription.getTextBox().getText().trim();
                String namespace = entityListBox.getValue(entityListBox.getSelectedIndex()) + definitionListBox.getValue(definitionListBox.getSelectedIndex());
                String type = typeListBox.getValue(typeListBox.getSelectedIndex());
                boolean isUnique = unique.getValue();
                CreateAttribute request = new CreateAttribute(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        AttributeDefinition a = jso.cast();
                        ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
                        AttributeRights right = AttributeRights.create(a.getId(), "SELF");
                        list.add(getRightsFromWidgets(selfRead, selfWrite, selfReadPublic, selfWritePublic, selfReadVo, selfWriteVo, right));
                        AttributeRights right2 = AttributeRights.create(a.getId(), "VOADMIN");
                        list.add(getRightsFromWidgets(voRead, voWrite, right2));
                        AttributeRights right3 = AttributeRights.create(a.getId(), "GROUPADMIN");
                        list.add(getRightsFromWidgets(groupRead, groupWrite, right3));
                        AttributeRights right4 = AttributeRights.create(a.getId(), "FACILITYADMIN");
                        list.add(getRightsFromWidgets(facilityRead, facilityWrite, right4));
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                                closeTabEvents.onFinished(jso);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.createAttributeDefinition(displayName, friendlyName, description, namespace, type, isUnique);
            }
        }
    });
    // insert layout
    layout.setHTML(0, 0, "Friendly name:");
    layout.setWidget(0, 1, attributeName);
    layout.setHTML(1, 0, "Display name:");
    layout.setWidget(1, 1, attributeDisplayName);
    layout.setHTML(2, 0, "Description:");
    layout.setWidget(2, 1, attributeDescription);
    layout.setHTML(3, 0, "Entity:");
    layout.setWidget(3, 1, entityListBox);
    layout.setHTML(4, 0, "Definition type:");
    layout.setWidget(4, 1, definitionListBox);
    layout.setHTML(5, 0, "Value type:");
    layout.setWidget(5, 1, typeListBox);
    layout.setHTML(6, 0, "Unique:");
    layout.setWidget(6, 1, unique);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>SELF_PUBLIC</strong>");
    rightsTable.setHTML(0, 3, "<strong>SELF_VO</strong>");
    rightsTable.setHTML(0, 4, "<strong>VO</strong>");
    rightsTable.setHTML(0, 5, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 6, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, selfReadPublic);
    rightsTable.setWidget(2, 2, selfWritePublic);
    rightsTable.setWidget(1, 3, selfReadVo);
    rightsTable.setWidget(2, 3, selfWriteVo);
    rightsTable.setWidget(1, 4, voRead);
    rightsTable.setWidget(2, 4, voWrite);
    rightsTable.setWidget(1, 5, groupRead);
    rightsTable.setWidget(2, 5, groupWrite);
    rightsTable.setWidget(1, 6, facilityRead);
    rightsTable.setWidget(2, 6, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    vp.add(layout);
    vp.add(rightsTable);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) CreateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.CreateAttribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)

Example 2 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class GetServiceRequiredAttributes method getTable.

/**
 * Returns table widget with required attributes for service
 *
 * @return table widget
 */
public CellTable<AttributeDefinition> getTable() {
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<AttributeDefinition>(list);
    // Cell table
    table = new PerunTable<AttributeDefinition>(list);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // 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("Service has no required attribute.");
    // checkbox column column
    table.addCheckBoxColumn();
    // ID COLUMN
    table.addIdColumn("Attribute ID");
    // FRIENDLY NAME COLUMN
    final Column<AttributeDefinition, AttributeDefinition> friendlyNameColumn = JsonUtils.addColumn(new PerunAttributeFriendlyNameCell(), new JsonUtils.GetValue<AttributeDefinition, AttributeDefinition>() {

        public AttributeDefinition getValue(AttributeDefinition object) {
            return object;
        }
    }, null);
    /*
		// NAMESPACE COLUMN
		TextColumn<AttributeDefinition> namespaceColumn = new TextColumn<AttributeDefinition>() {
		public String getValue(AttributeDefinition attrDef) {
		return String.valueOf(attrDef.getNamespace());
		}
		};
		*/
    // ENTITY COLUMN
    TextColumn<AttributeDefinition> entityColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return attrDef.getEntity();
        }
    };
    // DEFINITION COLUMN
    TextColumn<AttributeDefinition> definitionColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return attrDef.getDefinition();
        }
    };
    // TYPE COLUMN
    TextColumn<AttributeDefinition> typeColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return String.valueOf(renameContent(attrDef.getType()));
        }
    };
    // SORTING
    /*
			 namespaceColumn.setSortable(true);
			 columnSortHandler.setComparator(namespaceColumn, new Comparator<AttributeDefinition>() {
			 public int compare(AttributeDefinition o1, AttributeDefinition o2) {
			 return o1.getNamespace().compareToIgnoreCase(o2.getNamespace());
			 }
			 });
			 */
    friendlyNameColumn.setSortable(true);
    columnSortHandler.setComparator(friendlyNameColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
        }
    });
    // Sorting value column
    entityColumn.setSortable(true);
    columnSortHandler.setComparator(entityColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getEntity().compareToIgnoreCase(o2.getEntity());
        }
    });
    // Sorting value column
    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());
        }
    });
    table.setColumnWidth(friendlyNameColumn, 250.0, Unit.PX);
    table.setColumnWidth(entityColumn, 120.0, Unit.PX);
    table.setColumnWidth(definitionColumn, 120.0, Unit.PX);
    table.setColumnWidth(typeColumn, 120.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, "Value type");
    table.addDescriptionColumn();
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) PerunAttributeFriendlyNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 3 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class GetServiceRequiredAttributes method filterTable.

@Override
public void filterTable(String filter) {
    // store list only for first time
    if (fullBackup.isEmpty() || fullBackup == null) {
        fullBackup.addAll(list);
    }
    // always clear selected items
    selectionModel.clear();
    list.clear();
    if (filter.equalsIgnoreCase("")) {
        list.addAll(fullBackup);
    } else {
        for (AttributeDefinition attr : fullBackup) {
            // store facility by filter
            if (attr.getFriendlyName().toLowerCase().startsWith(filter.toLowerCase())) {
                list.add(attr);
            }
        }
    }
    if (list.isEmpty() && !filter.isEmpty()) {
        loaderImage.setEmptyResultMessage("No required attribute matching '" + filter + "' found.");
    } else {
        loaderImage.setEmptyResultMessage("No required attribute found.");
    }
    dataProvider.flush();
    dataProvider.refresh();
    loaderImage.loadingFinished();
}
Also used : AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition)

Example 4 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class GetServiceRequiredAttributes method setList.

public void setList(ArrayList<AttributeDefinition> list) {
    clearTable();
    this.list.addAll(list);
    for (AttributeDefinition def : list) {
        oracle.add(def.getFriendlyName());
    }
    dataProvider.flush();
    dataProvider.refresh();
}
Also used : AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition)

Example 5 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class GetAttributesDefinition method filterTable.

public void filterTable(String filter) {
    // store list only for first time
    if (fullBackup.isEmpty() || fullBackup == null) {
        fullBackup.addAll(list);
    }
    // always clear selected items
    selectionModel.clear();
    list.clear();
    if (filter.equalsIgnoreCase("")) {
        list.addAll(fullBackup);
    } else {
        for (AttributeDefinition attr : fullBackup) {
            // store facility by filter
            if (attr.getFriendlyName().toLowerCase().startsWith(filter.toLowerCase())) {
                list.add(attr);
            }
        }
    }
    if (list.isEmpty() && !filter.isEmpty()) {
        loaderImage.setEmptyResultMessage("No attribute definition matching '" + filter + "' found.");
    } else {
        loaderImage.setEmptyResultMessage("No attribute defined in Perun.");
    }
    dataProvider.flush();
    dataProvider.refresh();
    loaderImage.loadingFinished();
}
Also used : AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition)

Aggregations

AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)14 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 ArrayList (java.util.ArrayList)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)3 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 TextBox (com.google.gwt.user.client.ui.TextBox)2 GetAttributesDefinition (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 PerunAttributeFriendlyNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 TextInputCell (com.google.gwt.cell.client.TextInputCell)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1