Package org.openquark.cal.valuenode

Examples of org.openquark.cal.valuenode.ValueNode


     * @param newValue  the new current value
     */
    private void changeValue(double newValue) {
        currentValue = newValue;

        ValueNode oldValue = getValueNode();

        Object newValueObj = integerValues
                                ? (Object) new Integer((int) newValue)
                                : (Object) new Double(newValue);

View Full Code Here


                       
                        // Try to get outputable only editor
                        editor = valueEditorManager.getValueEditorForValueNode(valueEditorHierarchyManager, getValueNode(), true);
                        if (editor == null) {
                            // No outputable editor. Create string value node and edit this
                            ValueNode node = valueEditorManager.getValueNodeBuilderHelper().getValueNodeForTypeExpr(valueEditorManager.getTypeCheckInfo().getTypeChecker().getTypeFromString(CAL_Prelude.TypeConstructors.String.getQualifiedName(), CAL_Prelude.MODULE_NAME, null));
                            node.setOutputJavaValue(getValueNode().getTextValue());
                            editor = valueEditorManager.getValueEditorForValueNode(valueEditorHierarchyManager, node, true);
                        }
                    }
                    handleLaunchEditor(editor, getLaunchEditorButton());
                }
View Full Code Here

     * the value in the ValueNode.
     */
    private void updateDisplayedValue() {

        // Handle this depending on type.
        ValueNode valueNode = getValueNode();
        TypeExpr typeExpr = valueNode.getTypeExpr();

        // Note: if this is set as output, then the value field will not be a
        // DateTimeValueEntryField, but a text field!
        if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeDate)) {

            DateTimeValueEntryField dateTimeVef = (DateTimeValueEntryField) getValueField();
            dateTimeVef.setFormat(DateTimeValueEntryField.RELATIVEDATE);
            dateTimeVef.setDate(((RelativeDateValueNode)valueNode).getDateValue());

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeTime)) {

            DateTimeValueEntryField dateTimeVef = (DateTimeValueEntryField) getValueField();
            dateTimeVef.setFormat(DateTimeValueEntryField.RELATIVETIME);
            dateTimeVef.setDate(((RelativeTimeValueNode)valueNode).getTimeValue());

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeDateTime)) {

            DateTimeValueEntryField dateTimeVef = (DateTimeValueEntryField) getValueField();
            dateTimeVef.setFormat(DateTimeValueEntryField.RELATIVEDATETIME);
            dateTimeVef.setDate(((RelativeDateTimeValueNode)valueNode).getDateTimeValue());

        } else if (typeExpr.isNonParametricType(CAL_Time.TypeConstructors.Time)) {

            DateTimeValueEntryField dateTimeVef = (DateTimeValueEntryField) getValueField();
            dateTimeVef.setFormat(DateTimeValueEntryField.JTIME);
            dateTimeVef.setDate(((JTimeValueNode)valueNode).getJavaDate());

        } 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.
            }

            setTextValue(valueNode.getTextValue());
        }

       if (isEditable()) {
           getValueField().setForeground(valueEditorManager.isFieldEditable(typeExpr) ? Color.black : Color.gray);
       } else {
View Full Code Here

     * @param newValueNode
     */
    @Override
    public void setOwnerValueNode(ValueNode newValueNode) {
       
        ValueNode oldOwnerValueNode = getOwnerValueNode();

        super.setOwnerValueNode(newValueNode);
        TypeExpr typeExpr = getValueNode().getTypeExpr();

        // if the value changed, give it a new value entry field.
        if (oldOwnerValueNode == null || !oldOwnerValueNode.sameValue(newValueNode)) {

            // Set-up this ValueEntryPanel with the data in the ValueNode.
            String iconName = valueEditorManager.getTypeIconName(typeExpr);
            this.setTypeIcon(iconName);
   
View Full Code Here

        public void keyPressed(KeyEvent e) {
           
            int current = -1;
           
            for (int i = 0, size = valueNodeList.size(); i < size; i++) {
                ValueNode valueNode = valueNodeList.get(i);
                if (valueNode.sameValue(getValueNode())) {
                    current = i;
                    break;
                }
            }
           
            if (current == -1) {
                throw new IllegalStateException("invalid current value: " + getValueNode());
            }
           
            EnumeratedValueEditor editor = (EnumeratedValueEditor) getValueEditor();
            editor.setHighlightedValue(getValueNode());
           
            int keyCode = e.getKeyCode();
           
            if (keyCode == KeyEvent.VK_UP && current > 0) {
               
                ValueNode newValue = valueNodeList.get(current - 1);
                editor.setOwnerValueNode(newValue);
                handleLaunchEditor(editor, getLaunchEditorButton());
                e.consume();
               
            } else if (keyCode == KeyEvent.VK_DOWN && current < valueNodeList.size() - 1) {
               
                ValueNode newValue = valueNodeList.get(current + 1);
                editor.setOwnerValueNode(newValue);
                handleLaunchEditor(editor, getLaunchEditorButton());
                e.consume();
           
            } else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) {
View Full Code Here

        // add the record node itself to the result map
        resultMap.put(currentValueNode, leastConstrainedRecordType);

        // add all the record field nodes to the result map
        for (int j = 0; j < numFields; j++) {
            ValueNode currentFieldNode = currentValueNode.getValueAt(j);
            FieldName fieldName = hasFieldNames.get(j);
           
            TypeExpr leastConstrainedRecordElementType = leastConstrainedRecordType.getHasFieldType(fieldName);
                           
            resultMap.put(currentFieldNode, leastConstrainedRecordElementType);
View Full Code Here

    @Override
    public void commitChildChanges(ValueNode oldChild, ValueNode newChild) {
               
        // Get the copy of the current value node, type switched if necessary.
       
        ValueNode oldValueNode = getValueNode();
        AbstractRecordValueNode newValueNode;
        if (!oldChild.getTypeExpr().sameType(newChild.getTypeExpr())) {
           
            // A child is switching type. So calculate new types/values of all our field nodes
           
            Map<ValueNode, TypeExpr> valueNodeToUnconstrainedTypeMap = getValueNodeToUnconstrainedTypeMap();
            Map<ValueNode, ValueNode> commitValueMap = valueEditorManager.getValueNodeCommitHelper().getCommitValues(oldChild, newChild, valueNodeToUnconstrainedTypeMap);
           
            newValueNode = (AbstractRecordValueNode)commitValueMap.get(oldValueNode);

        } else {
            newValueNode = (AbstractRecordValueNode)oldValueNode.copyValueNode();
        }       
       
        // Update the values of the children to match the updated value
       
        List<ValueNode> currentChildrenList = UnsafeCast.<List<ValueNode>>unsafeCast(oldValueNode.getValue());          // unsafe.
        for (int i = 0, listSize = newValueNode.getTypeExpr().rootRecordType().getNHasFields(); i < listSize; i++) {
            if (currentChildrenList.get(i) == oldChild) {
                TypeExpr childType = newValueNode.getValueAt(i).getTypeExpr();
                newValueNode.setValueNodeAt(i, newChild.copyValueNode(childType));
                break;
View Full Code Here

           
            ValueEditorManager valueEditorManager = getValueEditorManager();
           
            for (int i = 0, size = valueNode.getTypeExpr().rootRecordType().getNHasFields(); i < size; i++) {
           
                ValueNode elementValueNode = valueNode.getValueAt(i);
               
                if (!valueEditorManager.isSupportedValueNode(elementValueNode, providerSupportInfo)) {
                    return false;
                }
            }
View Full Code Here

                           
                            // 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.
                            ValueNode recordValueNode = recordVNProvider.getNodeInstance(fieldValueList, null, recordTypeExpr);
                            ((ListValueNode)getValueNode()).setValueNodeAt(i, recordValueNode);
                        }
                   
                    } else {
                        // No conversion is necessary.
                    }
                   
                } else {
                    // Empty list, or list of record value nodes.
                   
                    // Iterate through the list of record nodes and change their type expressions
                   
                    for (int i = 0; i < listSize; i++) {
                       
                        AbstractRecordValueNode recordValueNode = (AbstractRecordValueNode)((ListValueNode)getValueNode()).getValueAt(i);
                        recordValueNode = recordValueNode.renameField(oldName, newName, valueEditorManager.getValueNodeBuilderHelper(), valueEditorManager.getValueNodeTransformer());
                        ((ListValueNode)getValueNode()).setValueNodeAt(i, recordValueNode);
                    }
                   
                }
               
View Full Code Here

        // 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.
       
        boolean isListRecord = getListElementType().rootRecordType() != null;
        int tupleSize = isListOfNTupleVNs ? ((NTupleValueNode)listElementNodes.get(0)).getTupleSize() : -1;

        // Calculate new unconstrained types for the list and the elements of the list.
        TypeExpr unconstrainedListType = getContext().getLeastConstrainedTypeExpr();
        TypeExpr unconstrainedListElementType;

        if (unconstrainedListType.rootTypeVar() != null ||
            (!consolidateColumns && isListRecord && unconstrainedListType.rootTypeConsApp().getArg(0).rootTypeVar() != null)) {  // check for [a]

            // The context is parametric (ie: a or [a]), so create the least constrained type
            // depending on the list element type:
           
            if (!consolidateColumns && isListOfNTupleVNs) {
           
                // Tuple least constrained type: (a, a, ... )
                unconstrainedListElementType = TypeExpr.makeTupleType(tupleSize);
               
            } else if (!consolidateColumns && isListRecord) {
           
                // Record least constrained type: {field1 = a, field2 = b, ...}
               
                // Build this from the existing fields
                List<FieldName> fieldNames = getListElementType().rootRecordType().getHasFieldNames();
                Map<FieldName, TypeExpr> fieldNameToTypeMap = new HashMap<FieldName, TypeExpr>();
                for (final FieldName fieldName : fieldNames) {
                    fieldNameToTypeMap.put(fieldName, TypeExpr.makeParametricType());
                }
               
                unconstrainedListElementType = TypeExpr.makeNonPolymorphicRecordType(fieldNameToTypeMap);
               
            } else {
           
                // General element least constrained type: (a)
                unconstrainedListElementType = TypeExpr.makeParametricType();
            }
           
            unconstrainedListType = valueEditorManager.getValueNodeBuilderHelper().getPreludeTypeConstants().makeListType(unconstrainedListElementType);

        } else {
       
            // Element type expression is bound to context
            unconstrainedListElementType = unconstrainedListType.rootTypeConsApp().getArg(0);

            //first build a field map containing all the fields from the context
            final Map<FieldName, TypeExpr> fieldMap; //map of all the fields in the context RecordFieldName -> TypeExpr
            if (unconstrainedListElementType instanceof RecordType) {
                fieldMap = ((RecordType) unconstrainedListElementType).getHasFieldsMap();
            } else {
                fieldMap = new HashMap<FieldName, TypeExpr>();
            }

            //add all the additional fields from the editor
            if (firstChild.getTypeExpr() instanceof RecordType ) {
                RecordType elementType = (RecordType ) firstChild.getTypeExpr(); // unconstrainedListElementType;
                for (int i = 0; i < elementType.getNHasFields(); i++) {
                    final FieldName fieldName = elementType.getHasFieldNames().get(i);
                    if (!fieldMap.containsKey(fieldName)) {
                        fieldMap.put(fieldName, TypeExpr.makeParametricType());
                    }
                }
            }
           
            //make sure the element type is actually supposed to be a record - otherwise just use generic type
            if (!(firstChild.getTypeExpr() instanceof RecordType) &&
                !  (unconstrainedListElementType instanceof RecordType)) {
                unconstrainedListElementType = TypeExpr.makeParametricType();
            } else {
                unconstrainedListElementType = TypeExpr.makeNonPolymorphicRecordType(fieldMap);
            }
            unconstrainedListType = valueEditorManager.getValueNodeBuilderHelper().getPreludeTypeConstants().makeListType(unconstrainedListElementType);           
        }
       
       
        // Populate the map
       
        // List
        returnMap.put(listValueNode, unconstrainedListType);

        // List items
        for (final ValueNode listElementNode : listElementNodes) {//.iterator(); it.hasNext(); ) {
            returnMap.put(listElementNode, unconstrainedListElementType);
           
            if (!consolidateColumns) {
               
                // For tuple and record lists, we have to also put the individual elements of the list items
               
                if (isListOfNTupleVNs) {
                   
                    NTupleValueNode currentTupleValue = (NTupleValueNode)listElementNode;
                    RecordType unconstrainedListElementRecordType = (RecordType)unconstrainedListElementType;
                    Map<FieldName, TypeExpr>  hasFieldsMap = unconstrainedListElementRecordType.getHasFieldsMap();
                    int j = 0;
                    for (final TypeExpr unconstrainedTupleElementType : hasFieldsMap.values()) {
                        ValueNode currentTupleItem = currentTupleValue.getValueAt(j);
                        returnMap.put(currentTupleItem, unconstrainedTupleElementType);
                        ++j;
                    }
                   
                } else if (isListRecord) {
                   
                    List<FieldName> contextRecordFieldNames = ((RecordType)unconstrainedListElementType).getHasFieldNames();
                    RecordValueNode currentRecordValue = (RecordValueNode)listElementNode;
                    for (int j = 0, n = currentRecordValue.getNFieldNames(); j < n; j++) {
                        ValueNode currentFieldItem = currentRecordValue.getValueAt(j);
                       
                        TypeExpr unconstrainedFieldType;
                        if (contextRecordFieldNames.contains(currentRecordValue.getFieldName(j))) {
                           
                            unconstrainedFieldType = ((RecordType)unconstrainedListElementType).getHasFieldType(currentRecordValue.getFieldName(j));
View Full Code Here

TOP

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

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.