コード例 #1
0
ファイル: IOPanel.java プロジェクト: hal/core
  protected Widget buildFormPanel(
      final ResourceDescription definition,
      SecurityContext securityContext,
      boolean enableFormEdit) {
    final ModelNodeFormBuilder.FormAssets formAssets =
        new ModelNodeFormBuilder()
            .setConfigOnly()
            .setResourceDescription(definition)
            .setSecurityContext(securityContext)
            .build();
    if (enableFormEdit) {
      formAssets
          .getForm()
          .setToolsCallback(
              new FormCallback() {
                @Override
                public void onSave(Map changeSet) {
                  IOPanel.this.onModify(
                      selectionModel.getSelectedObject().getName(),
                      formAssets.getForm().getChangedValues());
                }

                @Override
                public void onCancel(Object entity) {
                  formAssets.getForm().cancel();
                }
              });
    }

    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            Property worker = selectionModel.getSelectedObject();
            if (worker != null) {
              formAssets.getForm().edit(worker.getValue());
            } else {
              formAssets.getForm().clearValues();
            }
          }
        });

    VerticalPanel formPanel = new VerticalPanel();
    formPanel.setStyleName("fill-layout-width");
    formPanel.add(formAssets.getHelp().asWidget());
    formPanel.add(formAssets.getForm().asWidget());

    return formPanel;
  }
コード例 #2
0
  private ToolStrip setupTableButtons() {
    ToolStrip tools = new ToolStrip();
    ToolButton addButton =
        new ToolButton(
            Console.CONSTANTS.common_label_add(),
            event -> {
              ModelNodeFormBuilder.FormAssets addFormAssets =
                  new ModelNodeFormBuilder()
                      .setResourceDescription(resourceDescription)
                      .setCreateMode(true)
                      .unsorted()
                      .exclude("permissions")
                      .setCreateNameAttribute(false)
                      .setSecurityContext(securityContext)
                      .build();
              addFormAssets.getForm().setEnabled(true);

              DefaultWindow dialog = new DefaultWindow(Console.MESSAGES.newTitle("Permission"));
              AddResourceDialog.Callback callback =
                  new AddResourceDialog.Callback() {
                    @Override
                    public void onAdd(ModelNode payload) {
                      circuit.dispatch(
                          new AddListAttribute(
                              ElytronStore.CONSTANT_PERMISSION_MAPPER_ADDRESS,
                              "permissions",
                              permissionMapping,
                              payload));
                      dialog.hide();
                    }

                    @Override
                    public void onCancel() {
                      dialog.hide();
                    }
                  };
              AddResourceDialog addDialog =
                  new AddResourceDialog(addFormAssets, resourceDescription, callback);
              dialog.setWidth(480);
              dialog.setHeight(360);
              dialog.setWidget(addDialog);
              dialog.setGlassEnabled(true);
              dialog.center();
            });
    ToolButton removeButton =
        new ToolButton(
            Console.CONSTANTS.common_label_delete(),
            event -> {
              final ModelNode selection = selectionModel.getSelectedObject();
              if (selection != null) {
                Feedback.confirm(
                    "Filter",
                    Console.MESSAGES.deleteConfirm(
                        "Permission " + selection.get("class-name").asString()),
                    isConfirmed -> {
                      if (isConfirmed) {
                        circuit.dispatch(
                            new RemoveListAttribute(
                                ElytronStore.CONSTANT_PERMISSION_MAPPER_ADDRESS,
                                permissionMapping,
                                "permissions",
                                selection));
                      }
                    });
              }
            });
    tools.addToolButtonRight(addButton);
    tools.addToolButtonRight(removeButton);
    return tools;
  }
コード例 #3
0
ファイル: ChildView.java プロジェクト: baranowb/core
  private void _showAddDialog(
      final ModelNode address,
      boolean isSingleton,
      SecurityContext securityContext,
      ModelNode description) {
    List<Property> tuples = address.asPropertyList();
    String type = "";
    if (tuples.size() > 0) {
      type = tuples.get(tuples.size() - 1).getName();
    }

    ModelNodeFormBuilder builder =
        new ModelNodeFormBuilder()
            .setCreateMode(true)
            .setSingleton(isSingleton)
            .setResourceDescription(description)
            .setSecurityContext(securityContext);

    ModelNodeFormBuilder.FormAssets assets = builder.build();

    final ModelNodeForm form = assets.getForm();
    form.setEnabled(true);

    if (form.hasWritableAttributes()) {
      final DefaultWindow window = new DefaultWindow(Console.MESSAGES.createResource(type));
      window.addStyleName("browser-view");

      DialogueOptions options =
          new DialogueOptions(
              new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                  // save
                  FormValidation validation = form.validate();
                  if (!validation.hasErrors()) {
                    presenter.onAddChildResource(address, form.getUpdatedEntity());
                    window.hide();
                  }
                }
              },
              new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                  // cancel
                  window.hide();
                }
              });

      VerticalPanel layout = new VerticalPanel();
      layout.setStyleName("fill-layout-width");
      ModelNode opDescription = description.get("operations").get("add").get("description");
      ContentDescription text = new ContentDescription(opDescription.asString());
      layout.add(text);
      layout.add(assets.asWidget());

      WindowContentBuilder content = new WindowContentBuilder(layout, options);
      window.trapWidget(content.build());
      window.setGlassEnabled(true);
      window.setWidth(480);
      window.setHeight(360);
      window.center();
    } else {
      // no writable attributes
      Feedback.alert(
          Console.CONSTANTS.cannotCreateChildResource(),
          Console.MESSAGES.noConfigurableAttributes(address.toString()));
    }
  }
コード例 #4
0
  private ToolStrip mainTableTools() {
    ToolStrip tools = new ToolStrip();
    ToolButton addButton =
        new ToolButton(
            Console.CONSTANTS.common_label_add(),
            event -> {
              ModelNodeFormBuilder.FormAssets addFormAssets =
                  new ModelNodeFormBuilder()
                      .setResourceDescription(resourceDescription)
                      .setCreateMode(true)
                      .unsorted()
                      .setCreateNameAttribute(false)
                      .setSecurityContext(securityContext)
                      .build();
              addFormAssets.getForm().setEnabled(true);
              addFormAssets
                  .getForm()
                  .addFormValidator(
                      (formItems, formValidation) -> {

                        // at least one field is necessary to fill
                        boolean allEmpty = true;
                        for (FormItem formItem : formItems) {
                          if (!formItem.isUndefined()) {
                            allEmpty = false;
                            break;
                          }
                        }
                        if (allEmpty) {
                          formValidation.addError("match-abstract-type");
                          FormItem mechanismNameFormItem =
                              formItem(formItems, "match-abstract-type");
                          mechanismNameFormItem.setErrMessage(
                              "At least one field must contain valid values.");
                          mechanismNameFormItem.setErroneous(true);
                        }
                      });

              DefaultWindow dialog = new DefaultWindow(Console.MESSAGES.newTitle("Match Rule"));
              AddResourceDialog.Callback callback =
                  new AddResourceDialog.Callback() {
                    @Override
                    public void onAdd(ModelNode payload) {
                      for (Property node : payload.asPropertyList()) {
                        // remove undefined attributes
                        if (!node.getValue().isDefined()) {
                          payload.remove(node.getName());
                        }
                      }
                      circuit.dispatch(
                          new AddListAttribute(
                              ElytronStore.AUTHENTICATION_CONTEXT_ADDRESS,
                              MATCH_RULES,
                              authContextName,
                              payload));
                      dialog.hide();
                    }

                    @Override
                    public void onCancel() {
                      dialog.hide();
                    }
                  };
              AddResourceDialog addDialog =
                  new AddResourceDialog(addFormAssets, resourceDescription, callback);
              dialog.setWidth(480);
              dialog.setHeight(510);
              dialog.setWidget(addDialog);
              dialog.setGlassEnabled(true);
              dialog.center();
            });
    ToolButton removeButton =
        new ToolButton(
            Console.CONSTANTS.common_label_delete(),
            event -> {
              final ModelNode selection = selectionModel.getSelectedObject();
              if (selection != null) {
                Feedback.confirm(
                    "Match Rule",
                    Console.MESSAGES.deleteConfirm("Match Rule " + selection.asString()),
                    isConfirmed -> {
                      if (isConfirmed) {
                        circuit.dispatch(
                            new RemoveListAttribute(
                                ElytronStore.AUTHENTICATION_CONTEXT_ADDRESS,
                                authContextName,
                                MATCH_RULES,
                                selection));
                      }
                    });
              }
            });
    tools.addToolButtonRight(addButton);
    tools.addToolButtonRight(removeButton);
    return tools;
  }
コード例 #5
0
  @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;
  }