/**
   * Either creates a link for the action be rendered in a {@link ModalWindow}, or (if none can be
   * {@link ActionPromptProvider#getActionPrompt() provided}, or creates a link to the {@link
   * ActionPromptPage} (ie the {@link PageClassRegistry registered page} for {@link
   * PageType#ACTION_PROMPT action}s).
   *
   * <p>If the action's {@link ObjectAction#getSemantics() semantics} are {@link
   * ActionSemantics.Of#SAFE safe}, then concurrency checking is disabled; otherwise it is enforced.
   */
  protected AbstractLink newLink(
      final String linkId,
      final ObjectAdapter objectAdapter,
      final ObjectAction action,
      final ActionPromptProvider actionPromptProvider) {

    final ActionPrompt actionPrompt = actionPromptProvider.getActionPrompt();
    if (actionPrompt != null) {
      final ActionModel actionModel = ActionModel.create(objectAdapter, action);
      actionModel.setActionPrompt(actionPrompt);
      AjaxLink<Object> link =
          new AjaxLink<Object>(linkId) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {

              final ActionPanel actionPromptPanel =
                  (ActionPanel)
                      getComponentFactoryRegistry()
                          .createComponent(
                              ComponentType.ACTION_PROMPT,
                              actionPrompt.getContentId(),
                              actionModel);

              actionPrompt.setPanel(actionPromptPanel, target);
              actionPrompt.show(target);

              target.focusComponent(actionPromptPanel);
            }
          };
      link.add(new CssClassAppender("noVeil"));
      return link;

    } else {

      // use the action semantics to determine whether invoking this action will require a
      // concurrency check or not
      // if it's "safe", then we'll just continue without any checking.
      final ConcurrencyChecking concurrencyChecking =
          ConcurrencyChecking.concurrencyCheckingFor(action.getSemantics());
      final PageParameters pageParameters =
          ActionModel.createPageParameters(objectAdapter, action, concurrencyChecking);
      final Class<? extends Page> pageClass =
          getPageClassRegistry().getPageClass(PageType.ACTION_PROMPT);
      AbstractLink link = Links.newBookmarkablePageLink(linkId, pageParameters, pageClass);

      // special case handling if this a no-arg action is returning a URL
      if (action.getParameterCount() == 0) {
        addTargetBlankIfActionReturnsUrl(link, action);
      }

      return link;
    }
  }
Пример #2
0
  private void processElement(
      final Request request, final FormFieldBlock block, final String field) {
    final String type = request.getOptionalProperty(TYPE, "dropdown");
    if (!request.isPropertySpecified(METHOD) && request.isPropertySpecified(COLLECTION)) {
      final String id = request.getRequiredProperty(COLLECTION, Request.NO_VARIABLE_CHECKING);
      final String selector =
          showSelectionList(request, id, block.getCurrent(field), block.isNullable(field), type);
      block.replaceContent(field, selector);
    } else {
      final String objectId = request.getOptionalProperty(OBJECT);
      final String methodName = request.getRequiredProperty(METHOD);
      final ObjectAdapter object = MethodsUtils.findObject(request.getContext(), objectId);
      final ObjectAction action = MethodsUtils.findAction(object, methodName);
      if (action.getParameterCount() == 0) {
        final ObjectAdapter collection = action.execute(object, new ObjectAdapter[0]);
        final String selector =
            showSelectionList(
                request, collection, block.getCurrent(field), block.isNullable(field), type);
        block.replaceContent(field, selector);
      } else {
        final String id = "selector_options";
        final String id2 = (String) request.getContext().getVariable(id);
        final String selector =
            showSelectionList(request, id2, block.getCurrent(field), block.isNullable(field), type);

        final CreateFormParameter parameters = new CreateFormParameter();
        parameters.objectId = objectId;
        parameters.methodName = methodName;
        parameters.buttonTitle = request.getOptionalProperty(BUTTON_TITLE, "Search");
        parameters.formTitle = request.getOptionalProperty(FORM_TITLE);
        parameters.className = request.getOptionalProperty(CLASS, "selector");
        parameters.id = request.getOptionalProperty(ID);

        parameters.resultName = id;
        parameters.forwardResultTo = request.getContext().getResourceFile();
        parameters.forwardVoidTo = "error";
        parameters.forwardErrorTo = parameters.forwardResultTo;
        parameters.scope = Scope.REQUEST.name();
        request.pushNewBuffer();
        ActionForm.createForm(request, parameters);
        block.replaceContent(field, selector);

        request.appendHtml(request.popBuffer());
      }
    }
  }
  /**
   * Synthesises {@link ObjectAssociation}s from matching {@link ObjectAction}s of any of the
   * services that accept one parameter
   */
  private List<ObjectAssociation> createContributeeAssociations(
      final ObjectAdapter serviceAdapter) {

    final ObjectSpecification specification = serviceAdapter.getSpecification();
    final List<ObjectAction> serviceActions =
        specification.getObjectActions(
            ActionType.USER, Contributed.INCLUDED, Filters.<ObjectAction>any());

    final List<ObjectActionImpl> contributedActions = Lists.newArrayList();
    for (final ObjectAction serviceAction : serviceActions) {
      if (isAlwaysHidden(serviceAction)) {
        continue;
      }
      final NotContributedFacet notContributed = serviceAction.getFacet(NotContributedFacet.class);
      if (notContributed != null && notContributed.toAssociations()) {
        continue;
      }
      if (!serviceAction.hasReturn()) {
        continue;
      }
      if (serviceAction.getParameterCount() != 1
          || contributeeParameterMatchOf(serviceAction) == -1) {
        continue;
      }
      if (!(serviceAction instanceof ObjectActionImpl)) {
        continue;
      }
      if (!serviceAction.getSemantics().isSafeInNature()) {
        continue;
      }
      contributedActions.add((ObjectActionImpl) serviceAction);
    }

    return Lists.newArrayList(
        Iterables.transform(
            contributedActions, createContributeeAssociationFunctor(serviceAdapter, this)));
  }
Пример #4
0
 public String getNumParams() {
   return action != null ? "" + action.getParameterCount() : "";
 }