Beispiel #1
0
  @SuppressWarnings("unchecked")
  Mbui_HandlebarsView(MbuiContext mbuiContext) {
    super(mbuiContext);

    AddressTemplate metadata0Template = AddressTemplate.of("/subsystem=foo");
    this.metadata0 = mbuiContext.metadataRegistry().lookup(metadata0Template);
    this.handlebarElements = new HashMap<>();

    LayoutBuilder layoutBuilder =
        new LayoutBuilder()
            .row()
            .column()
            .div()
            .innerHtml(
                SafeHtmlUtils.fromSafeConstant(
                    "<h1>Handlebars</h1><p>Current time: {{org.jboss.hal.ballroom.Format.shortDateTime(new java.util.Date())}}</p>"))
            .rememberAs("html0")
            .end()
            .end()
            .end();
    handlebarElements.put("html0", layoutBuilder.referenceFor("html0"));

    Element root = layoutBuilder.build();
    initElement(root);
  }
Beispiel #2
0
 @Override
 protected void reload() {
   ResourceAddress address = ROOT_TEMPLATE.resolve(statementContext);
   Operation operation = new Operation.Builder(READ_RESOURCE_OPERATION, address).build();
   dispatcher.execute(
       operation,
       result -> getView().update(result),
       (o, failure) -> {
         MessageEvent.fire(
             getEventBus(),
             Message.error(
                 resources.constants().unknownResource(),
                 resources.messages().unknownResource(address.toString(), failure)));
         getView().clear();
       });
 }
Beispiel #3
0
 @Override
 protected FinderPath finderPath() {
   return FinderPath.subsystemPath(statementContext.selectedProfile(), ROOT_TEMPLATE.lastValue());
 }
Beispiel #4
0
/** @author Harald Pehl */
public class IiopPresenter extends MbuiPresenter<IiopPresenter.MyView, IiopPresenter.MyProxy> {

  // @formatter:off
  @ProxyStandard
  @Requires(ROOT_ADDRESS)
  @NameToken(NameTokens.IIOP)
  public interface MyProxy extends ProxyPlace<IiopPresenter> {}

  public interface MyView extends MbuiView<IiopPresenter> {
    void update(ModelNode modelNode);

    void clear();
  }
  // @formatter:on

  static final String ROOT_ADDRESS = "/{selected.profile}/subsystem=iiop-openjdk";
  private static final AddressTemplate ROOT_TEMPLATE = AddressTemplate.of(ROOT_ADDRESS);

  private final StatementContext statementContext;
  private final Dispatcher dispatcher;
  private final Resources resources;

  @Inject
  public IiopPresenter(
      final EventBus eventBus,
      final MyView view,
      final MyProxy myProxy,
      final Finder finder,
      final StatementContext statementContext,
      final Dispatcher dispatcher,
      final Resources resources) {
    super(eventBus, view, myProxy, finder);
    this.statementContext = statementContext;
    this.dispatcher = dispatcher;
    this.resources = resources;
  }

  @Override
  protected void onBind() {
    super.onBind();
    getView().setPresenter(this);
  }

  @Override
  protected FinderPath finderPath() {
    return FinderPath.subsystemPath(statementContext.selectedProfile(), ROOT_TEMPLATE.lastValue());
  }

  @Override
  protected void reload() {
    ResourceAddress address = ROOT_TEMPLATE.resolve(statementContext);
    Operation operation = new Operation.Builder(READ_RESOURCE_OPERATION, address).build();
    dispatcher.execute(
        operation,
        result -> getView().update(result),
        (o, failure) -> {
          MessageEvent.fire(
              getEventBus(),
              Message.error(
                  resources.constants().unknownResource(),
                  resources.messages().unknownResource(address.toString(), failure)));
          getView().clear();
        });
  }
}
  @Override
  public void process(
      final VariableElement field,
      final Element element,
      final String selector,
      final MbuiViewContext context) {
    MetadataInfo metadata = findMetadata(field, element, context);
    AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
    String title = element.getAttributeValue("title");
    if (title == null) {
      title = new LabelBuilder().label(template.lastKey());
    }
    DataTableInfo tableInfo =
        new DataTableInfo(
            field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title);
    context.addDataTableInfo(tableInfo);

    // actions
    org.jdom2.Element actionsContainer = element.getChild("actions");
    if (actionsContainer != null) {
      for (org.jdom2.Element actionElement : actionsContainer.getChildren("action")) {
        String handler = actionElement.getAttributeValue("handler");
        String handlerRef = actionElement.getAttributeValue("handler-ref");
        String actionTitle = actionElement.getAttributeValue("title");
        String scope = actionElement.getAttributeValue("scope");
        String nameResolver = actionElement.getAttributeValue("name-resolver");
        Element attributesContainer = actionElement.getChild("attributes");

        if (handler != null && handlerRef != null) {
          processor.error(
              field,
              "Multiple handlers specified for table#%s. Please specify only one of \"handler\" or \"handler-ref\".",
              selector);
        }
        if (handler != null) {
          if (!Handlebars.isExpression(handler)) {
            processor.error(
                field,
                "Invalid handler \"%s\" in data-table#%s: handler has to be an expression.",
                handler,
                selector);
          }
          if (actionTitle == null) {
            processor.error(
                field,
                "Invalid handler \"%s\" in data-table#%s: Title is mandatory.",
                handler,
                selector);
          }
        }
        if (handlerRef != null && HandlerRef.referenceFor(handlerRef) == null) {
          String knownHandlerRefs =
              Stream.of(HandlerRef.values()).map(HandlerRef::getRef).collect(joining(", "));
          processor.error(
              field,
              "Unknown handler-ref \"%s\" in data-table#%s: Please choose one of %s.",
              handlerRef,
              selector,
              knownHandlerRefs);
        }
        if (!HandlerRef.ADD_RESOURCE.getRef().equals(handlerRef) && attributesContainer != null) {
          processor.warning(
              field,
              "Attributes specified for handler-ref \"%s\" in data-table#%s: "
                  + "Attributes are only processed for \"%s\".",
              handlerRef,
              selector,
              HandlerRef.ADD_RESOURCE.name());
        }
        if (nameResolver != null && !Handlebars.isExpression(nameResolver)) {
          processor.error(
              field, "Name resolver in data-table#%s has to be an expression.", selector);
        }
        if (HandlerRef.REMOVE_RESOURCE.getRef().equals(handlerRef)
            && "*".equals(template.lastValue())
            && nameResolver == null) {
          processor.error(
              field,
              "\"%s\" handler-ref specified for data-table#%s and related metadata address ends in \"*\", "
                  + "but no name resolver is is provided.",
              HandlerRef.REMOVE_RESOURCE.getRef(),
              selector);
        }
        if (scope != null && !"selected".equals(scope)) {
          processor.error(
              field,
              "Unknown scope \"%s\" in handler-ref \"%s\" in data-table#%s: Only \"selected\" is supported.",
              scope,
              handlerRef,
              selector);
        }

        DataTableInfo.Action action =
            new DataTableInfo.Action(
                handlerRef != null ? handlerRef : handler, actionTitle, scope, nameResolver);
        tableInfo.addAction(action);

        if (attributesContainer != null) {
          processAttributes(field, attributesContainer).forEach(action::addAttribute);
        }
      }
    }

    // columns
    org.jdom2.Element columnsContainer = element.getChild("columns");
    if (columnsContainer != null) {
      for (org.jdom2.Element columnElement : columnsContainer.getChildren("column")) {
        String name = columnElement.getAttributeValue("name");
        String value = columnElement.getAttributeValue("value");

        if (name == null) {
          processor.error(
              field,
              "Invalid column \"%s\" in data-table#%s: name is mandatory.",
              xmlAsString(columnElement),
              selector);
        }
        if (value != null) {
          if (!Handlebars.isExpression(value)) {
            processor.error(
                field,
                "Invalid column \"%s\" in data-table#%s: value has to be an expression.",
                xmlAsString(columnElement),
                selector);
          }
        }
        DataTableInfo.Column column = new DataTableInfo.Column(name, value);
        tableInfo.addColumn(column);
      }
    }
  }