Пример #1
0
    /**
     * This is used for switching the type of a ValueNode within a given context. Basically, a
     * switch is made between valueNode and newValueNode, but their types are different.
     * Consequently, other valueNodes may be modified.
     *
     * <p>For example:
     *
     * <p>Let's say you have "add 1 2", where 1, 2 are of type Integer and are represented by
     * ValueNodes, then to switch '1' to '1.0' (a Double), you must switch '2' to '2.0' to avoid
     * type clashes.
     *
     * <p>This method will handle the switching of the associated types within a type context, so it
     * should so if you pass 1, 1.0 it'll convert 2 to 2.0 .
     *
     * <p>Note that you are able to pass in '5.0' as the new value if you'd like.
     *
     * @param oldValueNode your original ValueNode
     * @param newValueNode the valueNode that you want to arrive at
     */
    private void switchValueNodeTypeExpr(ValueNode oldValueNode, ValueNode newValueNode) {

      // Create the map from input to value node
      Map<PartInput, ValueNode> inputToValueNodeMap = new HashMap<PartInput, ValueNode>();
      for (final PartInput input : inputToEditorMap.keySet()) {
        ValueEditor editor = inputToEditorMap.get(input);
        inputToValueNodeMap.put(input, editor.getOwnerValueNode());
      }

      // Create the type switcher
      InputValueTypeSwitchHelper switcher =
          new InputValueTypeSwitchHelper(valueEditorManager.getValueNodeCommitHelper());

      // Get the switched values
      Map<PartInput, ValueNode> inputNewValueMap =
          switcher.getInputSwitchValues(oldValueNode, newValueNode, inputToValueNodeMap);

      // Now update with the switched values.
      for (final Map.Entry<PartInput, ValueNode> mapEntry : inputNewValueMap.entrySet()) {
        Gem.PartInput input = mapEntry.getKey();
        ValueNode newInputValue = mapEntry.getValue();

        ValueEditor editor = inputToEditorMap.get(input);

        editor.changeOwnerValue(newInputValue);
        editor.setSize(editor.getPreferredSize());
      }
    }
Пример #2
0
  /** Clears the data types and values of the arguments of the running gem */
  void resetArgumentValues() {
    // Loop thru the ValueEditors and reset their ValueNodes.
    for (final ValueEditor editor : valueEditorHierarchyManager.getTopValueEditors()) {

      // build the new ValueNode and give it to the argument panel
      TypeExpr leastConstrainedType = editor.getContext().getLeastConstrainedTypeExpr();
      ValueNode newNode =
          valueEditorHierarchyManager
              .getValueEditorManager()
              .getValueNodeBuilderHelper()
              .getValueNodeForTypeExpr(leastConstrainedType);

      editor.changeOwnerValue(newNode);
    }
  }