/** * Gets he application translation provider out of the action context. This * method simply delegates to the context backend controller. * * @param context * the action context. * @return the translation provider. */ protected ITranslationProvider getTranslationProvider(Map<String, Object> context) { return getBackendController(context); }
/** * Gets the model this action was triggered on. * * @param <T> * type inference return. * @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 model. */ protected <T> T getModelFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getModel(viewPathFromPermId, context); }
/** * Gets the model connector this action was triggered on. The model connector * is the versatile binding structure that adapts the actual model to the * Jspresso binding architecture. The actual model is stored in the model * connector value. Unless developing very generic actions, this method will * rarely be used in favor of the more concrete {@code getXXXModel} * context accessors. * * @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 model connector this action was triggered on. */ protected IValueConnector getModelConnectorFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getModelConnector(viewPathFromPermId, context); }
/** * Gets the model descriptor this action was 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 model connector this action was triggered on. */ protected IModelDescriptor getModelDescriptorFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getModelDescriptor(viewPathFromPermId, context); }
/** * This is a versatile helper method that retrieves the selected models model * either from the selected child connectors if the action was triggered on a * collection connector or from the connector itself. * * @param <T> * type inference return. * @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 list of selected models. */ protected <T> List<T> getSelectedModelsFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getSelectedModels(viewPathFromPermId, context); }
IValueConnector modelConnector = getModelConnector(viewPath, context); if (modelConnector == null) { return null; if (modelConnector instanceof ICollectionConnector) { models = new ArrayList<>(); int[] selectedIndices = getSelectedIndices(viewPath, context); if (selectedIndices != null && selectedIndices.length > 0) { for (int selectedIndice : selectedIndices) { T model = getSelectedModel(viewPath, context); models = Collections.singletonList(model);
/** * Retrieves the selected models indices out of the model connector if it's a * collection connector and set them as selected indices in the action * context. * * @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 selectedModels * the list of models to select in the view connector. * @param context * the action context. */ protected void setSelectedModelsFromPermId(String viewPermId, Collection<?> selectedModels, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); setSelectedModels(viewPathFromPermId, selectedModels, context); }
/** * Gets the selected indices out of the UI component if it is a collection * component (table, list, ...). More accurately, the selected indices are * taken from the view connector that adapts the UI component to the Jspresso * binding architecture. * * @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 selected indices stored in the action context. */ protected int[] getSelectedIndicesFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getSelectedIndices(viewPathFromPermId, context); }
/** * 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 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 selected model. */ protected <T> T getSelectedModelFromPermId(String viewPermId, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); return getSelectedModel(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 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 selectedIndices * the selected indices to store in the action context. * @param context * the action context. */ protected void setSelectedIndicesFromPermId(String viewPermId, int[] selectedIndices, Map<String, Object> context) { int[] viewPathFromPermId = ViewHelper.getViewPathFromPermId(viewPermId, getView(context)); setSelectedIndices(viewPathFromPermId, selectedIndices, 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); }
/** * Retrieves the selected models indices out of the model connector if it's a * collection connector and set them as selected indices in the action * context. * * @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 selectedModels * the list of models to select in the view connector. * @param context * the action context. */ protected void setSelectedModels(int[] viewPath, Collection<?> selectedModels, Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(viewPath, context); if (modelConnector instanceof ICollectionConnector) { setSelectedIndices(viewPath, ConnectorHelper.getIndicesOf((ICollectionConnector) modelConnector, selectedModels), context); } }
/** * Retrieves the locale the action has to use to execute. This method * delegates to the context backend controller that in turn will delegate to * the session. * * @param context * the action context. * @return the locale the action executes in. */ protected Locale getLocale(Map<String, Object> context) { IFrontendController<?, ?, ?> frontController = getFrontendController(context); if (frontController != null) { return frontController.getLocale(); } return getBackendController(context).getLocale(); }
/** * 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; }
/** * Gets the model connector this action was triggered on following a model path described as a dotted string. * * @param modelPath * the model path to follow as a dotted string. * @param context * the action context. * @return the model connector this action was triggered on. */ protected IValueConnector getModelConnector(String modelPath, Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(context); if (modelConnector instanceof ICollectionConnectorProvider) { int[] selectedIndices = getSelectedIndices(context); if (selectedIndices.length > 0) { modelConnector = ((ICollectionConnectorProvider) modelConnector).getCollectionConnector().getChildConnector( selectedIndices[0]); } } if (modelConnector != null) { if (modelPath != null) { String[] modelSteps = modelPath.split("\\."); for (String modelStep : modelSteps) { modelConnector = ((ICompositeValueConnector) modelConnector).getChildConnector(modelStep); } } return modelConnector; } return null; }
/** * Gets the model connector this action was triggered on. The model connector * is the versatile binding structure that adapts the actual model to the * Jspresso binding architecture. The actual model is stored in the model * connector value. Unless developing very generic actions, this method will * rarely be used in favor of the more concrete {@code getXXXModel} * context accessors. * * @param context * the action context. * @return the model connector this action was triggered on. */ protected IValueConnector getModelConnector(Map<String, Object> context) { return getModelConnector((int[]) 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 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 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} to get the the view the action * executes on. * </ul> * <p> * The returned view mainly serves for acting on the view component the action * has to be triggered on. * * @param <T> * type inference return. * @param context * the action context. * @return the view this action was triggered on. */ protected <T> IView<T> getView(Map<String, Object> context) { return getView(null, context); }
/** * Gets the model this action was triggered on. * * @param <T> * type inference return. * @param context * the action context. * @return the model. */ protected <T> T getModel(Map<String, Object> context) { return getModel(null, context); }
/** * Gets the selected indices out of the UI component if it is a collection * component (table, list, ...). More accurately, the selected indices are * taken from the view connector that adapts the UI component to the Jspresso * binding architecture. * * @param context * the action context. * @return the selected indices stored in the action context. */ protected int[] getSelectedIndices(Map<String, Object> context) { return getSelectedIndices(null, context); }