Package org.openquark.cal.valuenode

Examples of org.openquark.cal.valuenode.ListValueNode


        } else {

            // We do some special tool tip if the ValueNode is a ListValueNode.
            if (valueNode instanceof ListValueNode) {

                ListValueNode listValueNode = (ListValueNode)valueNode;
                String iconToolTip = "<i>" + valueEditorManager.getTypeName(typeExpr) + "</i>";
                int elementCount = listValueNode.getNElements();
                iconToolTip = iconToolTip + " (length " + elementCount + ")";
                getTypeIcon().setToolTipText("<html><body>" + iconToolTip + "</body></html>");

                // No break here.  Want to go with default stuff.
            }
View Full Code Here


               
                if (getListElementType().rootRecordType() == null) {
                    throw new IllegalStateException();
                }
               
                ListValueNode listValueNode = (ListValueNode)getValueNode();
                int listSize = listValueNode.getNElements();
               
                if (listSize > 0 && listValueNode.getValueAt(0) instanceof NTupleValueNode) {
                    // list of tuple value nodes.
                   
                    // Check if renaming causes a list of tuple to be converted to a list of record.
                    // True if renaming a list of tuple, unless the name really didn't change.
                    if (!oldName.equals(newName)) {
                       
                        // Have to convert a list of NTuples to a list of records.
                       
                        // Note: It might be better to move some of this code to nTupleValueNode.transmute(),
                        //   or ValueNodeTransformer.transform().  This duplicates some work though.
                       
                        ValueNodeBuilderHelper valueNodeBuilderHelper =
                            valueEditorHierarchyManager.getValueEditorManager().getValueNodeBuilderHelper();
                       
                        RecordValueNode.RecordValueNodeProvider recordVNProvider =
                            new RecordValueNode.RecordValueNodeProvider(valueNodeBuilderHelper);
                       
                        // Get the new record type.
                        TypeExpr recordTypeExpr = AbstractRecordValueNode.getRecordTypeForRenamedField(getListElementType(), oldName, newName);
                       
                        // Iterate through the list and convert tuple nodes to record nodes.
                        for (int i = 0; i < listSize; i++) {
                           
                            // Get the tuple node.
                            NTupleValueNode nTupleValueNode = (NTupleValueNode)listValueNode.getValueAt(i);
                           
                            // Get the list of values.
                            List<ValueNode> fieldValueList = new ArrayList<ValueNode>(nTupleValueNode.getValue());
                           
                            // Create and set the record value node with the list of values.
View Full Code Here

    private Map<ValueNode, TypeExpr> getValueNodeToUnconstrainedTypeMap() {
       
        Map<ValueNode, TypeExpr> returnMap = new HashMap<ValueNode, TypeExpr>();
       
        // Get the value nodes for the list and the items in the list.
        ListValueNode listValueNode = (ListValueNode)getValueNode();
        List<ValueNode> listElementNodes = listValueNode.getValue();
       
        // Determine whether we are dealing with a generic list, list of tuples or list of records
        ValueNode firstChild = listElementNodes.get(0);
        boolean isListOfNTupleVNs = firstChild instanceof NTupleValueNode;        // isListRecord will also be true.
       
View Full Code Here

    @Override
    public void commitChildChanges(ValueNode oldChild, ValueNode newChild) {
       
        // Get the copy of the current value node, type switched if necessary.
       
        ListValueNode oldValueNode = (ListValueNode)getValueNode();
        ListValueNode newValueNode;
        if (!oldChild.getTypeExpr().sameType(newChild.getTypeExpr())) {
   
            Map<ValueNode, TypeExpr> valueNodeToUnconstrainedTypeMap = getValueNodeToUnconstrainedTypeMap();
            Map<ValueNode, ValueNode> commitValueMap = valueEditorManager.getValueNodeCommitHelper().getCommitValues(oldChild, newChild, valueNodeToUnconstrainedTypeMap);
           
            PreludeTypeConstants typeConstants = valueEditorManager.getPreludeTypeConstants();
            TypeExpr charType = typeConstants.getCharType();
            ValueNode newValueNodeFromMap = commitValueMap.get(oldValueNode);

            // HACK: if it's a ListOfCharValueNode, convert it to a ListValueNode.
            //   What we need is a way to guarantee the type of value node that is returned by getCommitValues().
            //   This is not possible with the current form of transmuteValueNode() though.
            if (newValueNodeFromMap instanceof ListOfCharValueNode) {
                ListOfCharValueNode charListValueNode = (ListOfCharValueNode)newValueNodeFromMap;
                char[] charListValueArray = charListValueNode.getStringValue().toCharArray();

                ArrayList<ValueNode> newListValue = new ArrayList<ValueNode>(charListValueArray.length);
                for (final char charListValue : charListValueArray) {
                    newListValue.add(new LiteralValueNode(Character.valueOf(charListValue), charType));
                }
               
                newValueNode = new ListValueNode(newListValue, typeConstants.getCharListType(), new LiteralValueNode(new Character('a'), charType));
                replaceValueNode(newValueNode, true);
                return;

            } else {
                newValueNode = (ListValueNode)newValueNodeFromMap;
            }

        } else {
            newValueNode = (ListValueNode)oldValueNode.copyValueNode();
        }       
       
       
        // Modify the new value node so that the old child is replaced by the new child.
        // Note that the cell editor may now be editing a different row so we have to search for the row that changed
        //   This can happen if one clicks from an editor for one cell to another cell
        //   (eg. in a list of colours, from a colour value editor for one cell, onto the cell editor for another cell.)

        List<ValueNode> oldChildrenList = oldValueNode.getValue();
        List<ValueNode> newChildrenList = newValueNode.getValue();

        boolean isListRecord = getListElementType().rootRecordType() != null;
       
        if (consolidateColumns || !isListRecord) {
            for (int i = 0, listSize = newValueNode.getNElements(); i < listSize; i++) {
                if (oldChildrenList.get(i) == oldChild) {
                    TypeExpr childType = (newChildrenList.get(i)).getTypeExpr();
                    newValueNode.setValueNodeAt(i, newChild.copyValueNode(childType));
                    break;
                }
            }

        } else {
            // isListRecord == true, ie. must be a list of records (or tuples).
            AbstractRecordValueNode firstChild = (AbstractRecordValueNode)oldChildrenList.get(0);
           
            // To find the child that changed, for each value in the list, have to iterate through the tuple/record.
            int listSize = newValueNode.getNElements();
           
            int childrenSize = firstChild.getNFieldNames();

            // TODO: Note that new record value nodes may have more/less fields than the old nodes,
            // because of type switch
View Full Code Here

TOP

Related Classes of org.openquark.cal.valuenode.ListValueNode

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.