/** * This is a utility method which is able to retrieve the view connector this * action has been executed on from its context. It uses well-known context * keys of the action context which are: * <ul> * <li> {@code ActionContextConstants.VIEW_CONNECTOR} to get the the view * value connector the action executes on. * </ul> * <p> * The returned connector mainly serves for acting on the view component the * action has to be triggered on. * * @param context * the action context. * @return the value connector this action was triggered on. */ protected IValueConnector getViewConnector(Map<String, Object> context) { return getViewConnector(null, context); }
/** * This is a utility method which is able to retrieve the view connector this * action has been executed on from its context. It uses well-known context * keys of the action context which are: * <ul> * <li> {@code ActionContextConstants.VIEW_CONNECTOR} to get the the view * value connector the action executes on. * </ul> * <p> * The returned connector mainly serves for acting on the view component the * action has to be triggered on. * * @param viewPermId * the view permId to search for. The view hierarchy is climed to the top and then a chid view with the searched * permId is recursively searched. * @param context * the action context. * @return the value connector this action was triggered on. */ protected IValueConnector getViewConnectorFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getViewConnector(viewPathFromPermId, context); }
/** * Sets the selected indices of the UI component if it is a collection * component (table, list, ...). More accurately, the selected indices are set * to the view connector that adapts the UI component to the Jspresso binding * architecture. * * @param viewPath * the view index path to follow. * <ul> * <li>A positive integer n means the nth child.</li> * <li>A negative integer -n means the nth parent.</li> * </ul> * @param selectedIndices * the selected indices to store in the action context. * @param context * the action context. */ protected void setSelectedIndices(int[] viewPath, int[] selectedIndices, Map<String, Object> context) { IValueConnector selectableConnector = getViewConnector(viewPath, context); while (selectableConnector != null && !(selectableConnector instanceof ISelectable)) { selectableConnector = selectableConnector.getParentConnector(); } if (selectableConnector != null) { ((ISelectable) selectableConnector).setSelectedIndices(selectedIndices); } }
/** * This is a versatile helper method that retrieves the selected model either * from the 1st selected child connector if the action was triggered on a * collection connector or from the connector itself. * * @param <T> * type inference return. * @param viewPath * the view index path to follow. * <ul> * <li>A positive integer n means the nth child.</li> * <li>A negative integer -n means the nth parent.</li> * </ul> * @param context * the action context. * @return the selected model. */ protected <T> T getSelectedModel(int[] viewPath, Map<String, Object> context) { IValueConnector viewConnector = getViewConnector(viewPath, context); T selectedModel; if (viewConnector instanceof IItemSelectable) { selectedModel = ((IItemSelectable) viewConnector).getSelectedItem(); if (selectedModel instanceof IValueConnector) { selectedModel = ((IValueConnector) selectedModel).getConnectorValue(); } } else { selectedModel = getModel(viewPath, context); } return selectedModel; }
IValueConnector viewConnector = getViewConnector(viewPath, context); if (viewConnector != null) { IValueConnector modelConnector = viewConnector.getModelConnector();
IValueConnector selectableConnector = getViewConnector(viewPath, context); while (selectableConnector != null && !(selectableConnector instanceof ISelectable)) { if (selectableConnector.getParentConnector() != null) {