/** * Given a connector, this method loops upward to the parent/child * relationship to determine the first connector of the hierarchy. * * @param connector * the connector to look the root parent connector for. * @return the root parent connector. */ public static IValueConnector getRootConnector(IValueConnector connector) { if (connector == null) { return null; } IValueConnector parentConnector = connector; while (parentConnector.getParentConnector() != null) { parentConnector = parentConnector.getParentConnector(); } return parentConnector; } }
private IValueConnector getComponentConnector(IValueConnector connector) { if (connector == null) { return null; } /* connector.getModelDescriptor() instanceof IComponentDescriptorProvider<?> */ if (connector instanceof ICompositeValueConnector && !(connector instanceof ICollectionConnector)) { return connector; } return getComponentConnector(connector.getParentConnector()); }
private boolean isCollectionConnectorDescendant(IValueConnector connector) { if (connector == null) { return false; } if (connector instanceof ICollectionConnector) { return true; } return isCollectionConnectorDescendant(connector.getParentConnector()); }
/** * Retrieves a connector tree path following the parent/child relationship. * * @param rootConnector * the root connector of the hierarchy. The returned tree path will * start from this connector. * @param connector * the connector to look the tree path for. * @return the connector's tree path. */ public static TreePath getTreePathForConnector(IValueConnector rootConnector, IValueConnector connector) { List<IValueConnector> treePath = new ArrayList<IValueConnector>(); IValueConnector parentConnector = connector; while (parentConnector != null && parentConnector != rootConnector) { if (!(parentConnector instanceof ICollectionConnector) || !(parentConnector.getParentConnector() instanceof ICollectionConnectorProvider)) { treePath.add(parentConnector); } parentConnector = parentConnector.getParentConnector(); } if (parentConnector == rootConnector) { treePath.add(parentConnector); Collections.reverse(treePath); return new TreePath(treePath.toArray()); } return null; } }
/** * Retrieves a connector tree path following the parent/child relationship. * * @param rootConnector * the root connector of the hierarchy. The returned tree path will * start from this connector. * @param connector * the connector to look the tree path for. * @return the connector's tree path. */ public static TreePath getTreePathForConnector(IValueConnector rootConnector, IValueConnector connector) { List<IValueConnector> treePath = new ArrayList<>(); IValueConnector parentConnector = connector; while (parentConnector != null && parentConnector != rootConnector) { if (!(parentConnector instanceof ICollectionConnector) || !(parentConnector.getParentConnector() instanceof ICollectionConnectorProvider)) { treePath.add(parentConnector); } parentConnector = parentConnector.getParentConnector(); } if (parentConnector == rootConnector) { treePath.add(parentConnector); Collections.reverse(treePath); return new TreePath(treePath.toArray()); } return null; } }
/** * Retrieves a connector tree path following the parent/child relationship. * * @param rootConnector * the root connector of the hierarchy. The returned tree path will * start from this connector. * @param connector * the connector to look the tree path for. * @return the connector's tree path. */ public static TreePath getTreePathForConnector(IValueConnector rootConnector, IValueConnector connector) { List<IValueConnector> treePath = new ArrayList<IValueConnector>(); IValueConnector parentConnector = connector; while (parentConnector != null && parentConnector != rootConnector) { if (!(parentConnector instanceof ICollectionConnector) || !(parentConnector.getParentConnector() instanceof ICollectionConnectorProvider)) { treePath.add(parentConnector); } parentConnector = parentConnector.getParentConnector(); } if (parentConnector == rootConnector) { treePath.add(parentConnector); Collections.reverse(treePath); return new TreePath(treePath.toArray()); } return null; } }
/** * Retrieves a connector tree path following the parent/child relationship. * * @param rootConnector * the root connector of the hierarchy. The returned tree path will * start from this connector. * @param connector * the connector to look the tree path for. * @return the connector's tree path. */ public static TreePath getTreePathForConnector(IValueConnector rootConnector, IValueConnector connector) { List<IValueConnector> treePath = new ArrayList<IValueConnector>(); IValueConnector parentConnector = connector; while (parentConnector != null && parentConnector != rootConnector) { if (!(parentConnector instanceof ICollectionConnector) || !(parentConnector.getParentConnector() instanceof ICollectionConnectorProvider)) { treePath.add(parentConnector); } parentConnector = parentConnector.getParentConnector(); } if (parentConnector == rootConnector) { treePath.add(parentConnector); Collections.reverse(treePath); return new TreePath(treePath.toArray()); } 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; }
/** * Retrieves a connector tree path following the parent/child relationship. * * @param rootConnector * the root connector of the hierarchy. The returned tree path will * start from this connector. * @param connector * the connector to look the tree path for. * @return the connector's tree path. */ public static TreePath getTreePathForConnector(IValueConnector rootConnector, IValueConnector connector) { List<IValueConnector> treePath = new ArrayList<IValueConnector>(); IValueConnector parentConnector = connector; while (parentConnector != null && parentConnector != rootConnector) { if (!(parentConnector instanceof ICollectionConnector) || !(parentConnector.getParentConnector() instanceof ICollectionConnectorProvider)) { treePath.add(parentConnector); } parentConnector = parentConnector.getParentConnector(); } if (parentConnector == rootConnector) { treePath.add(parentConnector); Collections.reverse(treePath); return new TreePath(treePath.toArray()); } return null; } }
/** * Retrieves a connector complete path following the parent/child * relationship. * * @param connector * the connector to look the tree path for. * @return the list of connector identifiers from the root connector to the * looked-up connector. */ public static List<String> getPathToConnector(IValueConnector connector) { if (connector == null) { return null; } List<String> path = new ArrayList<>(); IValueConnector parentConnector = connector; while (parentConnector != null) { path.add(parentConnector.getId()); parentConnector = parentConnector.getParentConnector(); } Collections.reverse(path); return path; }
/** * refined to return a collection connector. * <p> * {@inheritDoc} */ @Override protected ICollectionConnector getModelConnector(Map<String, Object> context) { IValueConnector connector = super.getModelConnector(getViewPath(), context); // for handling table editing connectors... while (connector != null && !(connector instanceof ICollectionConnector)) { connector = connector.getParentConnector(); } return (ICollectionConnector) connector; }
IValueConnector selectableConnector = getViewConnector(viewPath, context); while (selectableConnector != null && !(selectableConnector instanceof ISelectable)) { if (selectableConnector.getParentConnector() != null) { selectableConnector = selectableConnector.getParentConnector(); } else {
/** * 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); } }
/** * Retrieves the query component out of the context. * * @param context * the action context. * @return the query component. */ @Override protected IQueryComponent getQueryComponent(Map<String, Object> context) { IValueConnector queryEntityConnector = (IValueConnector) context .get(CreateQueryComponentAction.QUERY_MODEL_CONNECTOR); if (queryEntityConnector == null) { queryEntityConnector = getModelConnector(context); while (queryEntityConnector != null && !(queryEntityConnector.getConnectorValue() instanceof IQueryComponent)) { // climb the connector hierarchy to retrieve the IQueryComponent // connector. queryEntityConnector = queryEntityConnector.getParentConnector(); } } IQueryComponent queryComponent = null; if (queryEntityConnector != null && queryEntityConnector.getConnectorValue() != null) { queryComponent = queryEntityConnector .getConnectorValue(); } return queryComponent; }
private boolean isRecycling(IValueConnector connector) { if (connector instanceof AbstractValueConnector) { return ((AbstractValueConnector) connector).isMute() || isCollectionConnectorDescendant(connector) && isRecycling( connector.getModelConnector()) || isRecycling(connector.getParentConnector()); } else { return false; } }
@Override public void propertyChange(PropertyChangeEvent evt) { IValueConnector connector = (IValueConnector) evt.getSource(); if (connector.getParentConnector() instanceof IRenderableCompositeValueConnector && ((IRenderableCompositeValueConnector) connector.getParentConnector()).getRenderingConnector() == connector) { } else if (connector.getParentConnector() == null && connector.getId() == null) {
private Coordinates computeCoordinates(IValueConnector connector) { IValueConnector cellConnector = connector; ICompositeValueConnector rowConnector = cellConnector.getParentConnector(); while (rowConnector != null && rowConnector.getParentConnector() != collectionConnector) { cellConnector = rowConnector; rowConnector = rowConnector.getParentConnector(); } int col = -1; int row = -1; if (rowConnector != null) { row = computeRow(rowConnector); for (String key : columnConnectorKeys) { if (rowConnector.getChildConnector(key) == cellConnector) { break; } col++; } } return new Coordinates(row, col); }
/** * Utility implementation to factorize method support. This should only be * used by subclasses which implement {@code IItemSelectable}. * * @param evt * the item selection event to propagate. */ protected void implFireSelectedItemChange(ItemSelectionEvent evt) { selectedItem = evt.getSelectedItem(); if (itemSelectionSupport != null && (evt.getSource() == this || isTrackingChildrenSelection())) { itemSelectionSupport.fireSelectedConnectorChange(evt); } IValueConnector parentConnector = getParentConnector(); while (parentConnector != null && !(parentConnector instanceof IItemSelectable)) { parentConnector = parentConnector.getParentConnector(); } if (parentConnector != null) { ((IItemSelectable) parentConnector).fireSelectedItemChange(evt); } }
@Override public void valueChange(ValueChangeEvent evt) { IRenderableCompositeValueConnector connector = (IRenderableCompositeValueConnector) ((IValueConnector) evt .getSource()).getParentConnector(); if (!isRecycling(connector)) { RemoteCompositeValueState state = (RemoteCompositeValueState) ((IRemoteStateOwner) connector).getState(); RemoteValueCommand command = new RemoteValueCommand(); command.setTargetPeerGuid(state.getGuid()); command.setValue(state.getValue()); command.setDescription(state.getDescription()); command.setIconImageUrl(state.getIconImageUrl()); remoteCommandHandler.registerCommand(command); } } };
@Override public void selectionChange(SelectionChangeEvent evt) { IValueConnector connector = (IValueConnector) evt.getSource(); IValueConnector parentConnector = connector.getParentConnector(); if (parentConnector instanceof ICollectionConnectorProvider && ((ICollectionConnectorProvider) parentConnector).getCollectionConnector() == connector