private void setupTable() {
    table = new DefaultCellTable<>(5);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> principals = createColumn("principals");
    Column<ModelNode, String> roles = createColumn("roles");
    principals.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    roles.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(principals, "Principals");
    table.addColumn(roles, "Roles");
    table.setColumnWidth(principals, 30, Style.Unit.PCT);
    table.setColumnWidth(roles, 30, Style.Unit.PCT);
  }
  private void setupTable() {
    table = new DefaultCellTable<>(5);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> classNameColumn = createColumn("class-name");
    Column<ModelNode, String> moduleColumn = createColumn("module");
    Column<ModelNode, String> targetNameColumn = createColumn("target-name");
    Column<ModelNode, String> actionColumn = createColumn("action");
    classNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    moduleColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    targetNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    actionColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(classNameColumn, "Class name");
    table.addColumn(moduleColumn, "Module");
    table.addColumn(targetNameColumn, "Target name");
    table.addColumn(actionColumn, "Action");
    table.setColumnWidth(classNameColumn, 40, Style.Unit.PCT);
    table.setColumnWidth(moduleColumn, 20, Style.Unit.PCT);
    table.setColumnWidth(targetNameColumn, 25, Style.Unit.PCT);
    table.setColumnWidth(actionColumn, 15, Style.Unit.PCT);
  }
  @SuppressWarnings("unchecked")
  public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-popupLayout-width");

    // table
    table = new DefaultCellTable<>(5);
    dataProvider = new ListDataProvider<>();
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> matchRuleColumn =
        new TextColumn<ModelNode>() {
          @Override
          public String getValue(ModelNode node) {
            // as the match-rules attribute is a list of attributes
            // none of them is required, so there is not a unique colum to show, so all defined
            // attributes are
            // displayed, there is a "view" button that shows all attributes nicely formatted in a
            // ModelNodeForm
            StringBuilder content = new StringBuilder();
            for (Property prop : node.asPropertyList()) {
              content
                  .append(prop.getName())
                  .append(": ")
                  .append(prop.getValue().asString())
                  .append(", ");
            }
            return StringUtils.shortenStringIfNecessary(content.toString(), 120);
          }
        };

    Column<ModelNode, ModelNode> linkOpenDetailsColumn =
        new Column<ModelNode, ModelNode>(
            new ViewLinkCell<>(
                Console.CONSTANTS.common_label_view(),
                (ActionCell.Delegate<ModelNode>) selection -> showDetailModal(selection))) {
          @Override
          public ModelNode getValue(ModelNode node) {
            return node;
          }
        };

    linkOpenDetailsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(matchRuleColumn, "");
    table.addColumn(linkOpenDetailsColumn, "Option");
    table.setColumnWidth(linkOpenDetailsColumn, 8, Style.Unit.PCT);

    panel.add(mainTableTools());
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // ===================== match-rule form popup
    popupLayout.setStyleName("window-content");

    // read-only form to show details of match-rules attribute
    ModelNodeFormBuilder.FormAssets detailForm =
        new ModelNodeFormBuilder()
            .setResourceDescription(resourceDescription)
            .setCreateMode(false)
            .unsorted()
            .setCreateNameAttribute(false)
            .setSecurityContext(securityContext)
            .build();
    matchRulesForm = detailForm.getForm();

    popupDialogOptions.showCancel(false);
    Widget formWidget = detailForm.getForm().asWidget();
    popupLayout.add(formWidget);

    return panel;
  }
示例#4
0
  private Widget getMainPanel() {
    SimplePanel panel = new SimplePanel();
    panel.setWidth("100%");
    panel.setHeight("100%");

    dataGrid = new DataGrid<RuleInfo>(MAX_RULES, RuleInfo.KEY_PROVIDER);
    dataGrid.setHeight(MAIN_HEIGHT);

    Column<RuleInfo, String> columnName =
        addColumn(
            new TextCell(),
            "Rule Name",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getName();
              }
            },
            null);

    Column<RuleInfo, String> ruleType =
        addColumn(
            new TextCell(),
            "Type",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getType().toUpperCase();
              }
            },
            null);

    Column<RuleInfo, ImageResource> ruleEnabled =
        addColumn(
            new ImageResourceCell(),
            "Enabled",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isEnabled()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    Column<RuleInfo, ImageResource> instead =
        addColumn(
            new ImageResourceCell(),
            "Instead",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isInstead()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    dataGrid.setColumnWidth(columnName, "200px");
    dataGrid.setColumnWidth(ruleType, "120px");
    dataGrid.setColumnWidth(ruleEnabled, "100px");
    dataGrid.setColumnWidth(instead, "100px");

    ruleType.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    ruleEnabled.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    instead.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    dataGrid.setLoadingIndicator(new Image(PgStudio.Images.spinner()));

    dataProvider.addDataDisplay(dataGrid);

    dataGrid.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        (new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            RuleInfo rule = selectionModel.getSelectedObject();
            ruleDef.setText(rule.getDefinition());
          }
        }));

    panel.add(dataGrid);

    return panel.asWidget();
  }