Package org.apache.isis.viewer.scimpi.dispatcher.context

Examples of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext


        }
        request.appendHtml("</div>");
    }

    private Crumbs getCrumbs(final Request request) {
        final RequestContext context = request.getContext();
        Crumbs crumbs = (Crumbs) context.getVariable(_HISTORY);
        if (crumbs == null) {
            crumbs = new Crumbs();
            context.addVariable(_HISTORY, crumbs, Scope.SESSION);
        }
        return crumbs;
    }
View Full Code Here


public class Collection extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        ObjectAdapter collection;

        final String field = request.getOptionalProperty(FIELD);
        if (field != null) {
            final String id = request.getOptionalProperty(OBJECT);
            final ObjectAdapter object = context.getMappedObjectOrResult(id);
            final ObjectAssociation objectField = object.getSpecification().getAssociation(field);
            if (!objectField.isOneToManyAssociation()) {
                throw new ScimpiException("Field " + objectField.getId() + " is not a collection");
            }
            IsisContext.getPersistenceSession().resolveField(object, objectField);
            collection = objectField.get(object);
        } else {
            final String id = request.getOptionalProperty(COLLECTION);
            collection = context.getMappedObjectOrResult(id);
        }

        final RepeatMarker marker = request.createMarker();

        final String variable = request.getOptionalProperty(ELEMENT_NAME);
        final String scopeName = request.getOptionalProperty(SCOPE);
        final Scope scope = RequestContext.scope(scopeName, Scope.REQUEST);
        final String rowClassesList = request.getOptionalProperty(ROW_CLASSES, ODD_ROW_CLASS + "|" + EVEN_ROW_CLASS);
        String[] rowClasses = new String[0];
        if (rowClassesList != null) {
            rowClasses = rowClassesList.split("[,|/]");
        }

        final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
        if (facet.size(collection) == 0) {
            request.skipUntilClose();
        } else {
            final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
            int row = 0;
            while (iterator.hasNext()) {
                final ObjectAdapter element = iterator.next();
                context.addVariable("row", "" + (row + 1), Scope.REQUEST);
                if (rowClassesList != null) {
                    context.addVariable("row-class", rowClasses[row % rowClasses.length], Scope.REQUEST);
                }
                context.addVariable(variable, context.mapObject(element, scope), scope);
                marker.repeat();
                request.processUtilCloseTag();
                row++;
            }
        }
View Full Code Here

public class RunAction extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        final String objectId = request.getOptionalProperty(OBJECT);
        final ObjectAdapter object = MethodsUtils.findObject(context, objectId);

        final String methodName = request.getRequiredProperty(METHOD);
View Full Code Here

public class EditObject extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        final String objectId = request.getOptionalProperty(OBJECT);
        final String forwardEditedTo = request.getOptionalProperty(VIEW);
        final String forwardErrorTo = request.getOptionalProperty(ERROR);
        final boolean hideNonEditableFields = request.isRequested(HIDE_UNEDITABLE, false);
        final boolean showIcon = request.isRequested(SHOW_ICON, showIconByDefault());
        String buttonTitle = request.getOptionalProperty(BUTTON_TITLE);
        String formTitle = request.getOptionalProperty(FORM_TITLE);
        final String formId = request.getOptionalProperty(FORM_ID, request.nextFormId());
        final String variable = request.getOptionalProperty(RESULT_NAME);
        final String resultOverride = request.getOptionalProperty(RESULT_OVERRIDE);
        final String scope = request.getOptionalProperty(SCOPE);
        final String className = request.getOptionalProperty(CLASS, "edit full");
        final String id = request.getOptionalProperty(ID);
        final String completionMessage = request.getOptionalProperty(MESSAGE);

        final ObjectAdapter object = context.getMappedObjectOrResult(objectId);
        final String actualObjectId = context.mapObject(object, Scope.INTERACTION);
        final String version = context.mapVersion(object);

        final FormState entryState = (FormState) context.getVariable(ENTRY_FIELDS);

        final ObjectSpecification specification = object.getSpecification();
        final FormFieldBlock containedBlock = new FormFieldBlock() {
            @Override
            public boolean isVisible(final String name) {
                final ObjectAssociation fld = specification.getAssociation(name);
                final boolean isVisible = fld.isVisible(IsisContext.getAuthenticationSession(), object).isAllowed();
                final boolean isUseable = fld.isUsable(IsisContext.getAuthenticationSession(), object).isAllowed();
                return isVisible && isUseable;
            }

            @Override
            public ObjectAdapter getCurrent(final String name) {
                ObjectAdapter value = null;
                if (entryState != null) {
                    final FieldEditState field2 = entryState.getField(name);
                    value = field2.getValue();
                }
                if (value == null) {
                    final ObjectAssociation fld = specification.getAssociation(name);
                    value = fld.get(object);
                }
                return value;
            }

            @Override
            public boolean isNullable(final String name) {
                final ObjectAssociation fld = specification.getAssociation(name);
                return !fld.isMandatory();
            }
        };

        request.setBlockContent(containedBlock);
        request.processUtilCloseTag();

        final AuthenticationSession session = IsisContext.getAuthenticationSession();
        List<ObjectAssociation> viewFields = specification.getAssociations(ObjectAssociationFilters.dynamicallyVisible(session, object));
        viewFields = containedBlock.includedFields(viewFields);
        final InputField[] formFields = createFields(viewFields);

        initializeFields(context, object, formFields, entryState, !hideNonEditableFields);
        setDefaults(context, object, formFields, entryState, showIcon);

        copyFieldContent(context, object, formFields, showIcon);
        overrideWithHtml(context, containedBlock, formFields);
        String errors = null;
        if (entryState != null && entryState.isForForm(formId)) {
            copyEntryState(context, object, formFields, entryState);
            errors = entryState.getError();
        }

        final String errorView = context.fullFilePath(forwardErrorTo == null ? context.getResourceFile() : forwardErrorTo);
        final List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
        hiddenFields.add(new HiddenInputField("_" + OBJECT, actualObjectId));
        hiddenFields.add(new HiddenInputField("_" + VERSION, version));
        hiddenFields.add(new HiddenInputField("_" + FORM_ID, formId));
        hiddenFields.add(completionMessage == null ? null : new HiddenInputField("_" + MESSAGE, completionMessage));
        hiddenFields.add(forwardEditedTo == null ? null : new HiddenInputField("_" + VIEW, context.fullFilePath(forwardEditedTo)));
        hiddenFields.add(new HiddenInputField("_" + ERROR, errorView));
        hiddenFields.add(variable == null ? null : new HiddenInputField("_" + RESULT_NAME, variable));
        hiddenFields.add(resultOverride == null ? null : new HiddenInputField("_" + RESULT_OVERRIDE, resultOverride));
        hiddenFields.add(scope == null ? null : new HiddenInputField("_" + SCOPE, scope));
View Full Code Here

            throw new UnknownTypeException(type);
        }
    }

    private String onlyItem(final Request request, final String field, final ObjectAdapter collection, final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        final ObjectAdapter element = iterator.next();
        final String elementId = context.mapObject(element, Scope.INTERACTION);
        buffer.append("<img class=\"small-icon\" src=\"" + request.getContext().imagePath(element) + "\" alt=\"" + element.getSpecification().getShortIdentifier() + "\"/>" + element.titleString() + "\n");
        buffer.append("<input type=\"hidden\" name=\"" + field + "\" value=\"" + elementId + "\" />\n");
        return buffer.toString();
    }
View Full Code Here

        buffer.append("<input type=\"hidden\" name=\"" + field + "\" value=\"" + elementId + "\" />\n");
        return buffer.toString();
    }

    private String radioButtonList(final Request request, final String field, final boolean allowNotSet, final ObjectAdapter collection, final ObjectAdapter selectedItem, final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        if (allowNotSet) {
            buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"null\"></input><br/>\n");
        }
        while (iterator.hasNext()) {
            final ObjectAdapter element = iterator.next();
            final String elementId = context.mapObject(element, Scope.INTERACTION);
            final String title = element.titleString();
            final String checked = element == selectedItem ? "checked=\"checked\"" : "";
            buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"" + elementId + "\"" + checked + ">" + title + "</input><br/>\n");
        }
View Full Code Here

        return buffer.toString();
    }

    private String dropdownList(final Request request, final String field, final boolean allowNotSet, final ObjectAdapter collection, final ObjectAdapter selectedItem, String size, final CollectionFacet facet) {
        final RequestContext context = request.getContext();
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        final StringBuffer buffer = new StringBuffer();
        size = size == null ? "" : " size =\"" + size + "\"";
        buffer.append("<select name=\"" + field + "\"" + size + " >\n");
        if (allowNotSet) {
            buffer.append("  <option value=\"null\"></option>\n");
        }
        while (iterator.hasNext()) {
            final ObjectAdapter element = iterator.next();
            final String elementId = context.mapObject(element, Scope.INTERACTION);
            final String title = element.titleString();
            final String checked = element == selectedItem ? "selected=\"selected\"" : "";
            buffer.append("  <option value=\"" + elementId + "\"" + checked + ">" + title + "</option>\n");
        }
        buffer.append("</select>\n");
View Full Code Here

        final String name = request.getOptionalProperty(NAME);
        final boolean showAsButton = request.isRequested("show-as-button", false);
        final String linkClass = request.getOptionalProperty(CLASS, showAsButton ? "button" : defaultLinkClass());
        final String containerClass = request.getOptionalProperty(CONTAINER_CLASS, "action");
        final String object = request.getOptionalProperty(OBJECT);
        final RequestContext context = request.getContext();
        String objectId = object != null ? object : (String) context.getVariable(RequestContext.RESULT);
        ObjectAdapter adapter = MethodsUtils.findObject(context, objectId);

        // REVIEW this is common used code
        final String fieldName = request.getOptionalProperty(FIELD);
        if (fieldName != null) {
            final ObjectAssociation field = adapter.getSpecification().getAssociation(fieldName);
            if (field == null) {
                throw new ScimpiException("No field " + fieldName + " in " + adapter.getSpecification().getFullIdentifier());
            }
            if (field.isVisible(IsisContext.getAuthenticationSession(), adapter).isVetoed()) {
                throw new ForbiddenException(field, ForbiddenException.VISIBLE);
            }
            IsisContext.getPersistenceSession().resolveField(adapter, field);
            adapter = field.get(adapter);
            if (adapter != null) {
                objectId = context.mapObject(adapter, Scope.INTERACTION);
            }
        }

        if (adapter != null && valid(request, adapter)) {
            final String variable = request.getOptionalProperty("param-name", RequestContext.RESULT);
            final String variableSegment = variable + "=" + objectId;

            String view = request.getOptionalProperty(VIEW);
            if (view == null) {
                view = defaultView();
            }
            view = context.fullUriPath(view);
            final String classSegment = " class=\"" + linkClass + "\"";
            final String titleSegment = title == null ? "" : (" title=\"" + title + "\"");
            String additionalSegment = additionalParameters(request);
            additionalSegment = additionalSegment == null ? "" : "&amp;" + additionalSegment;
            if (showAsButton) {
                request.appendHtml("<div class=\"" + containerClass + "\">");
            }
            request.appendHtml("<a" + classSegment + titleSegment + " href=\"" + view + "?" + variableSegment + context.encodedInteractionParameters() + additionalSegment + "\">");
            request.pushNewBuffer();
            request.processUtilCloseTag();
            final String buffer = request.popBuffer();
            if (buffer.trim().length() > 0) {
                request.appendHtml(buffer);
View Full Code Here

public abstract class AbstractTableView extends AbstractElementProcessor {

    @Override
    public void process(final Request request) {
        final RequestContext context = request.getContext();

        ObjectAdapter collection;
        String parentObjectId = null;
        boolean isFieldEditable = false;
        final String field = request.getOptionalProperty(FIELD);
        final String tableClass = request.getOptionalProperty(CLASS);
        ObjectSpecification elementSpec;
        if (field != null) {
            final String objectId = request.getOptionalProperty(OBJECT);
            final ObjectAdapter object = context.getMappedObjectOrResult(objectId);
            if (object == null) {
                throw new ScimpiException("No object for result or " + objectId);
            }
            final ObjectAssociation objectField = object.getSpecification().getAssociation(field);
            if (!objectField.isOneToManyAssociation()) {
                throw new ScimpiException("Field " + objectField.getId() + " is not a collection");
            }
            isFieldEditable = objectField.isUsable(IsisContext.getAuthenticationSession(), object).isAllowed();
            getPersistenceSession().resolveField(object, objectField);
            collection = objectField.get(object);
            final TypeOfFacet facet = objectField.getFacet(TypeOfFacet.class);
            elementSpec = facet.valueSpec();
            parentObjectId = objectId == null ? context.mapObject(object, Scope.REQUEST) : objectId;
        } else {
            final String id = request.getOptionalProperty(COLLECTION);
            collection = context.getMappedObjectOrResult(id);
            elementSpec = collection.getElementSpecification();
        }

        final String summary = request.getOptionalProperty("summary");
        final String rowClassesList = request.getOptionalProperty(ROW_CLASSES, ODD_ROW_CLASS + "|" + EVEN_ROW_CLASS);
View Full Code Here

    }

    protected abstract TableContentWriter createRowBuilder(final Request request, RequestContext context, final String parent, final List<ObjectAssociation> allFields, ObjectAdapter collection);

    public static void write(final Request request, final ObjectAdapter collection, final String summary, final TableContentWriter rowBuilder, final String tableClass, final String[] rowClasses) {
        final RequestContext context = request.getContext();

        final String summarySegment = summary == null ? "" : (" summary=\"" + summary + "\"");
        final String classSegment = tableClass == null ? "" : (" class=\"" + tableClass + "\"");
        request.appendHtml("<table" + classSegment + summarySegment + ">");
        rowBuilder.writeHeaders(request);
        rowBuilder.writeFooters(request);

        request.appendHtml("<tbody>");
        final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
        final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
        int row = 1;
        while (iterator.hasNext()) {
            final ObjectAdapter element = iterator.next();

            context.addVariable("row", "" + (row), Scope.REQUEST);
            String cls = "";
            if (rowClasses != null) {
                cls = " class=\"" + rowClasses[row % rowClasses.length] + "\"";
            }
            request.appendHtml("<tr" + cls + ">");
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.