/** * 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); }
/** * Gets the model descriptor this action was triggered on. * * @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 model connector this action was triggered on. */ protected IModelDescriptor getModelDescriptor(int[] viewPath, Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(viewPath, context); if (modelConnector != null) { return modelConnector.getModelDescriptor(); } return null; }
/** * Gets the model descriptor this action was triggered on. * * @param modelPath * the model path to follow as a dotted string. * @param context * the action context. * @return the model descriptor this action was triggered on. */ protected IModelDescriptor getModelDescriptor(String modelPath, Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(modelPath, context); if (modelConnector != null) { return modelConnector.getModelDescriptor(); } 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 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); }
/** * 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); } }
IValueConnector modelConnector = getModelConnector(viewPath, context); if (modelConnector == null) { return null;
/** * Gets the parent model this action was triggered on. * * @param <T> * type inference return. * @param context * the action context. * @return the parent model. */ protected <T> T getParentModel(Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(context); if (modelConnector != null) { if (modelConnector.getParentConnector() != null) { return modelConnector.getParentConnector().getConnectorValue(); } } return null; }
/** * 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 this action was triggered on. * * @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 model. */ protected <T> T getModel(int[] viewPath, Map<String, Object> context) { IValueConnector modelConnector = getModelConnector(viewPath, context); if (modelConnector != null) { if (modelConnector instanceof ICompositeValueConnector) { return modelConnector.getConnectorValue(); } else if (modelConnector.getModelProvider() != null) { return modelConnector.getModelProvider().getModel(); } } return null; }