Search in sources :

Example 6 with ListDataProvider

use of com.google.gwt.view.client.ListDataProvider in project ovirt-engine by oVirt.

the class HostNetworkInterfaceListViewItem method createLogicalNetworkContainer.

private Container createLogicalNetworkContainer() {
    List<HostVLan> logicalNetworks = calculateLogicalNetworks(getEntity());
    Row content = new Row();
    Column gridColumn = new Column(ColumnSize.SM_12);
    content.add(gridColumn);
    Container container = createItemContainerPanel(content);
    CellTable<HostVLan> logicalNetworkTable = new CellTable<>(MAX_LOGICAL_NETWORKS, (Resources) GWT.create(CellTablePopupTableResources.class));
    logicalNetworkTable.getElement().addClassName(Styles.TABLE);
    logicalNetworkTable.getElement().addClassName(PatternflyConstants.PF_TABLE_STRIPED);
    logicalNetworkTable.getElement().addClassName(PatternflyConstants.PF_TABLE_BORDERED);
    ListDataProvider<HostVLan> logicalNetworkDataProvider = new ListDataProvider<>();
    logicalNetworkDataProvider.addDataDisplay(logicalNetworkTable);
    logicalNetworkDataProvider.setList(logicalNetworks);
    final HostVLanNameRenderer renderer = new HostVLanNameRenderer();
    // Setup columns
    AbstractIconTypeColumn<HostVLan> management = new AbstractIconTypeColumn<HostVLan>() {

        @Override
        public IconType getValue(HostVLan logicalNetwork) {
            if (logicalNetwork.getInterface() != null && logicalNetwork.getInterface().getIsManagement()) {
                return IconType.INSTITUTION;
            }
            return null;
        }

        @Override
        public SafeHtml getTooltip(HostVLan logicalNetwork) {
            return SafeHtmlUtils.fromSafeConstant(constants.managementNetworkLabel());
        }
    };
    IconTypeHeader managementHeader = new IconTypeHeader(IconType.INSTITUTION, ICON_COLOR, SafeHtmlUtils.fromSafeConstant(constants.managementNetworkLabel()));
    management.getCell().setColor(SafeHtmlUtils.fromSafeConstant(ICON_COLOR));
    logicalNetworkTable.addColumn(management, managementHeader);
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(management, "40px");
    AbstractIconTypeColumn<HostVLan> sync = new AbstractIconTypeColumn<HostVLan>() {

        @Override
        public IconType getValue(HostVLan logicalNetwork) {
            if (logicalNetwork != null && logicalNetwork.getInterface() != null && isOutOfSync(logicalNetwork.getInterface().getNetworkImplementationDetails())) {
                return IconType.CHAIN_BROKEN;
            }
            return null;
        }

        @Override
        public SafeHtml getTooltip(HostVLan logicalNetwork) {
            return SafeHtmlUtils.fromSafeConstant(constants.hostOutOfSync());
        }
    };
    IconTypeHeader syncHeader = new IconTypeHeader(IconType.CHAIN_BROKEN, ICON_COLOR, SafeHtmlUtils.fromSafeConstant(constants.hostOutOfSync()));
    sync.getCell().setColor(SafeHtmlUtils.fromSafeConstant(RED));
    logicalNetworkTable.addColumn(sync, syncHeader);
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(sync, "40px");
    TextColumn<HostVLan> vlan = new TextColumn<HostVLan>() {

        @Override
        public String getValue(HostVLan logicalNetwork) {
            if (logicalNetwork == null || logicalNetwork.getName() == null || logicalNetwork.getName().isEmpty()) {
                return "";
            }
            return renderer.render(logicalNetwork);
        }
    };
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(vlan, "175px");
    logicalNetworkTable.addColumn(vlan, constants.vlanInterface());
    TextColumn<HostVLan> networkName = new TextColumn<HostVLan>() {

        @Override
        public String getValue(HostVLan logicalNetwork) {
            return logicalNetwork.getNetworkName();
        }
    };
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(networkName, "175px");
    logicalNetworkTable.addColumn(networkName, constants.networkNameInterface());
    TextColumn<HostVLan> ipv4 = new TextColumn<HostVLan>() {

        @Override
        public String getValue(HostVLan logicalNetwork) {
            return logicalNetwork.getIpv4Address() != null ? logicalNetwork.getIpv4Address() : "";
        }
    };
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(ipv4, "175px");
    logicalNetworkTable.addColumn(ipv4, constants.ipv4AddressInterface());
    TextColumn<HostVLan> ipv6 = new TextColumn<HostVLan>() {

        @Override
        public String getValue(HostVLan logicalNetwork) {
            return logicalNetwork.getIpv6Address() != null ? logicalNetwork.getIpv6Address() : "";
        }
    };
    // $NON-NLS-1$
    logicalNetworkTable.setColumnWidth(ipv6, "175px");
    logicalNetworkTable.addColumn(ipv6, constants.ipv6AddressInterface());
    TextColumn<HostVLan> emptyTail = new TextColumn<HostVLan>() {

        @Override
        public String getValue(HostVLan logicalNetwork) {
            return "";
        }
    };
    logicalNetworkTable.addColumn(emptyTail, "");
    gridColumn.add(logicalNetworkTable);
    return container;
}
Also used : ListDataProvider(com.google.gwt.view.client.ListDataProvider) HostVLanNameRenderer(org.ovirt.engine.ui.webadmin.widget.renderer.HostVLanNameRenderer) Container(org.gwtbootstrap3.client.ui.Container) Column(org.gwtbootstrap3.client.ui.Column) AbstractIconTypeColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractIconTypeColumn) TextColumn(com.google.gwt.user.cellview.client.TextColumn) CellTable(com.google.gwt.user.cellview.client.CellTable) IconTypeHeader(org.ovirt.engine.ui.common.widget.table.header.IconTypeHeader) HostVLan(org.ovirt.engine.ui.uicommonweb.models.hosts.HostVLan) Row(org.gwtbootstrap3.client.ui.Row) AbstractIconTypeColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractIconTypeColumn) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 7 with ListDataProvider

use of com.google.gwt.view.client.ListDataProvider in project perun by CESNET.

the class VoResourcesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources state");
    final TabItem tab = this;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    final CustomButton cb = UiElements.getRefreshButton(this);
    help.setWidget(0, 0, cb);
    help.getFlexCellFormatter().setWidth(0, 0, "80px");
    help.setHTML(0, 1, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 1, "100px");
    help.setHTML(0, 2, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "green");
    help.setHTML(0, 3, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setStyleName(0, 3, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 4, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 4, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 4, "notdetermined");
    /*
			 help.setHTML(0, 5, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 5, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 5, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 5, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    help.setHTML(0, 5, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetAllResourcesState callback = new GetAllResourcesState(voId, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<ResourceState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<ResourceState>().sortByResourceName(list);
                for (final ResourceState state : list) {
                    content.setHTML(mainrow, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()) + "<span class=\"now-managing\" style=\"display: inline-block; position: relative; top: -8px;\">" + state.getResource().getName() + "</span>");
                    ArrayList<Task> tasks = new TableSorter<Task>().sortByService(JsonUtils.<Task>jsoAsList(state.getTasks()));
                    if (tasks == null || tasks.isEmpty())
                        notDeterminedCounter++;
                    boolean allOk = true;
                    for (Task tsk : tasks) {
                        if (tsk.getStatus().equalsIgnoreCase("ERROR") || tsk.getStatus().equalsIgnoreCase("SENDERROR") || tsk.getStatus().equalsIgnoreCase("GENERROR")) {
                            errorCounter++;
                            allOk = false;
                            break;
                        }
                    }
                    if (allOk && tasks != null && !tasks.isEmpty())
                        okCounter++;
                    ListDataProvider<Task> dataProvider = new ListDataProvider<Task>();
                    PerunTable<Task> table;
                    // Table data provider.
                    dataProvider = new ListDataProvider<Task>(tasks);
                    // Cell table
                    table = new PerunTable<Task>(tasks);
                    table.removeRowCountChangeHandler();
                    // Connect the table to the data provider.
                    dataProvider.addDataDisplay(table);
                    // Sorting
                    ColumnSortEvent.ListHandler<Task> columnSortHandler = new ColumnSortEvent.ListHandler<Task>(dataProvider.getList());
                    table.addColumnSortHandler(columnSortHandler);
                    // set empty content & loader
                    AjaxLoaderImage loaderImage = new AjaxLoaderImage();
                    loaderImage.setEmptyResultMessage("No service configuration was propagated to this resource.");
                    table.setEmptyTableWidget(loaderImage);
                    loaderImage.loadingFinished();
                    table.addIdColumn("Task Id");
                    // Service column
                    Column<Task, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {

                        public String getValue(Task task) {
                            return String.valueOf(task.getService().getName());
                        }
                    }, null);
                    // status column
                    Column<Task, String> statusColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {

                        public String getValue(Task task) {
                            return String.valueOf(task.getStatus());
                        }
                    }, null);
                    // start COLUMN
                    TextColumn<Task> startTimeColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getStartTime();
                        }
                    };
                    // end COLUMN
                    TextColumn<Task> endTimeColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getEndTime();
                        }
                    };
                    // schedule COLUMN
                    TextColumn<Task> scheduleColumn = new TextColumn<Task>() {

                        public String getValue(Task result) {
                            return result.getSchedule();
                        }
                    };
                    // Add the columns.
                    table.addColumn(serviceColumn, "Service");
                    table.addColumn(statusColumn, "Status");
                    table.addColumn(scheduleColumn, "Scheduled");
                    table.addColumn(startTimeColumn, "Started");
                    table.addColumn(endTimeColumn, "Ended");
                    // set row styles based on task state
                    table.setRowStyles(new RowStyles<Task>() {

                        public String getStyleNames(Task row, int rowIndex) {
                            if (row.getStatus().equalsIgnoreCase("NONE")) {
                                return "rowdarkgreen";
                            } else if (row.getStatus().equalsIgnoreCase("DONE")) {
                                return "rowgreen";
                            } else if (row.getStatus().equalsIgnoreCase("PROCESSING")) {
                                return "rowyellow";
                            } else if (Arrays.asList("GENERROR", "SENDERROR", "ERROR").contains(row.getStatus())) {
                                return "rowred";
                            } else if (row.getStatus().equalsIgnoreCase("WARNING")) {
                                return "roworange";
                            }
                            return "";
                        }
                    });
                    table.setWidth("100%");
                    content.setWidget(mainrow + 1, 0, table);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    mainrow++;
                    mainrow++;
                }
            }
            // set counters
            help.setHTML(0, 2, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 4, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        // help.setHTML(0, 5, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities for VO
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ListDataProvider(com.google.gwt.view.client.ListDataProvider) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ArrayList(java.util.ArrayList) GetAllResourcesState(cz.metacentrum.perun.webgui.json.tasksManager.GetAllResourcesState) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) TextColumn(com.google.gwt.user.cellview.client.TextColumn) PerunTable(cz.metacentrum.perun.webgui.widgets.PerunTable) RowStyles(com.google.gwt.user.cellview.client.RowStyles) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 8 with ListDataProvider

use of com.google.gwt.view.client.ListDataProvider in project drools-wb by kiegroup.

the class GuidedScoreCardEditor method addAttributeCellTable.

private Widget addAttributeCellTable(final FlexTable cGrid, final Characteristic characteristic, final boolean enumColumn, final String dataType, final List<String> operators) {
    String[] enumValues = null;
    if (characteristic != null) {
        // enum values
        if (enumColumn) {
            String factName = characteristic.getFact();
            String fieldName = characteristic.getField();
            enumValues = oracle.getEnumValues(factName, fieldName);
        }
    }
    final CellTable<Attribute> attributeCellTable = new CellTable<Attribute>();
    // Operators column
    final DynamicSelectionCell categoryCell = new DynamicSelectionCell(operators);
    final Column<Attribute, String> operatorColumn = new Column<Attribute, String>(categoryCell) {

        public String getValue(final Attribute object) {
            return object.getOperator();
        }
    };
    operatorColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            object.setOperator(value);
            attributeCellTable.redraw();
        }
    });
    // Value column
    Column<Attribute, String> valueColumn = null;
    if (enumValues != null && enumValues.length > 0) {
        valueColumn = new Column<Attribute, String>(new DynamicSelectionCell(Arrays.asList(enumValues))) {

            public String getValue(final Attribute object) {
                return object.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    if (valueColumn == null) {
        valueColumn = new Column<Attribute, String>(new CustomEditTextCell()) {

            public String getValue(final Attribute attribute) {
                return attribute.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    // Partial Score column
    final EditTextCell partialScoreCell = new EditTextCell();
    final Column<Attribute, String> partialScoreColumn = new Column<Attribute, String>(partialScoreCell) {

        public String getValue(final Attribute attribute) {
            return "" + attribute.getPartialScore();
        }
    };
    partialScoreColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            try {
                double d = Double.parseDouble(value);
                object.setPartialScore(d);
            } catch (Exception e1) {
                partialScoreCell.clearViewData(object);
            }
            attributeCellTable.redraw();
        }
    });
    // Reason Code column
    final Column<Attribute, String> reasonCodeColumn = new Column<Attribute, String>(new EditTextCell()) {

        public String getValue(final Attribute attribute) {
            return attribute.getReasonCode();
        }
    };
    reasonCodeColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            object.setReasonCode(value);
            attributeCellTable.redraw();
        }
    });
    final ActionCell.Delegate<Attribute> delegate = new ActionCell.Delegate<Attribute>() {

        public void execute(final Attribute attribute) {
            if (Window.confirm(GuidedScoreCardConstants.INSTANCE.promptDeleteAttribute())) {
                final List<Attribute> list = characteristicsAttrMap.get(cGrid).getList();
                list.remove(attribute);
                if ("boolean".equalsIgnoreCase(dataType)) {
                    ((Button) cGrid.getWidget(0, 3)).setEnabled(list.size() != 2);
                }
                attributeCellTable.redraw();
            }
        }
    };
    final Cell<Attribute> actionCell = new ActionCell<Attribute>(GuidedScoreCardConstants.INSTANCE.remove(), delegate);
    final Column<Attribute, String> actionColumn = new IdentityColumn(actionCell);
    // Add the columns.
    attributeCellTable.addColumn(operatorColumn, GuidedScoreCardConstants.INSTANCE.operator());
    attributeCellTable.addColumn(valueColumn, GuidedScoreCardConstants.INSTANCE.value());
    attributeCellTable.addColumn(partialScoreColumn, GuidedScoreCardConstants.INSTANCE.partialScore());
    attributeCellTable.addColumn(reasonCodeColumn, GuidedScoreCardConstants.INSTANCE.reasonCode());
    attributeCellTable.addColumn(actionColumn, GuidedScoreCardConstants.INSTANCE.actions());
    attributeCellTable.setWidth("100%", true);
    attributeCellTable.setColumnWidth(operatorColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(valueColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(partialScoreColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(reasonCodeColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(actionColumn, 20.0, Style.Unit.PCT);
    ListDataProvider<Attribute> dataProvider = new ListDataProvider<Attribute>();
    dataProvider.addDataDisplay(attributeCellTable);
    characteristicsAttrMap.put(cGrid, dataProvider);
    if ("boolean".equalsIgnoreCase(dataType)) {
        CustomEditTextCell etc = (CustomEditTextCell) attributeCellTable.getColumn(1).getCell();
        etc.setEnabled(false);
    }
    return (attributeCellTable);
}
Also used : EditTextCell(com.google.gwt.cell.client.EditTextCell) ListDataProvider(com.google.gwt.view.client.ListDataProvider) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) ActionCell(com.google.gwt.cell.client.ActionCell) CellTable(com.google.gwt.user.cellview.client.CellTable) IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) Column(com.google.gwt.user.cellview.client.Column) Button(org.gwtbootstrap3.client.ui.Button)

Aggregations

ListDataProvider (com.google.gwt.view.client.ListDataProvider)8 CellTable (com.google.gwt.user.cellview.client.CellTable)3 TextColumn (com.google.gwt.user.cellview.client.TextColumn)3 Column (com.google.gwt.user.cellview.client.Column)2 HasData (com.google.gwt.view.client.HasData)2 ArrayList (java.util.ArrayList)2 Column (org.gwtbootstrap3.client.ui.Column)2 Container (org.gwtbootstrap3.client.ui.Container)2 Row (org.gwtbootstrap3.client.ui.Row)2 Before (org.junit.Before)2 ActionCell (com.google.gwt.cell.client.ActionCell)1 EditTextCell (com.google.gwt.cell.client.EditTextCell)1 GWT (com.google.gwt.core.client.GWT)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1 ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)1 IdentityColumn (com.google.gwt.user.cellview.client.IdentityColumn)1 RowStyles (com.google.gwt.user.cellview.client.RowStyles)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 Label (com.google.gwt.user.client.ui.Label)1