Package ca.nengo.config

Examples of ca.nengo.config.ListProperty


    for (String string : myConfiguration.getPropertyNames()) {
      Property p = myConfiguration.getProperty(string);
      if (p instanceof SingleValuedProperty) {
        args.add(((SingleValuedProperty) p).getValue());
      } else if (p instanceof ListProperty) {
        ListProperty lp = (ListProperty) p;
        Object array = Array.newInstance(p.getType(), lp.getNumValues());
        for (int i = 0; i < lp.getNumValues(); i++) {
          Array.set(array, i, lp.getValue(i));
        }
        args.add(array);
      }
    }
View Full Code Here


    if (event.isPopupTrigger() && event.getComponent().equals(myTree) && path != null) {
      myTree.setSelectionPath(path);
     
      JPopupMenu popup = new JPopupMenu();
      if (path.getLastPathComponent() instanceof ListProperty) {
        final ListProperty p = (ListProperty) path.getLastPathComponent();
        if (!p.isFixedCardinality()) {
          JMenuItem addValueItem = new JMenuItem("Add");
          addValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent E) {
              myModel.addValue(path, getValue(p.getType()), null);
            }
          });
          popup.add(addValueItem);       
        }
      } else if (path.getLastPathComponent() instanceof NamedValueProperty) {
        final NamedValueProperty p = (NamedValueProperty) path.getLastPathComponent();
        if (!p.isFixedCardinality()) {
          JMenuItem addValueItem = new JMenuItem("Add");
          addValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent E) {
              String name = JOptionPane.showInputDialog(myTree, "Value Name");
              myModel.addValue(path, getValue(p.getType()), name);
            }
          });
          popup.add(addValueItem);
        }
      } else if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
        final Property p = (Property) path.getParentPath().getLastPathComponent();
        if (p.isMutable() && !MainHandler.getInstance().canHandle(p.getType())) {
          final JMenuItem replaceValueItem = new JMenuItem("Replace");
          replaceValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Class<?> currentType = ((Value) path.getLastPathComponent()).getObject().getClass();
              Object o = NewConfigurableDialog.showDialog(replaceValueItem, p.getType(), currentType);
              if (o != null) {
                try {
                  myModel.setValue(path, o);
                } catch (StructuralException ex) {
                  ConfigExceptionHandler.handle(ex, ex.getMessage(), event.getComponent());
                }
              }
            }
          });
          popup.add(replaceValueItem);                 
        }
       
        if (!p.isFixedCardinality()) {
          if (p instanceof ListProperty) {
            JMenuItem insertValueItem = new JMenuItem("Insert");
            insertValueItem.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                myModel.insertValue(path, getValue(p.getType()));
              }
            });
            popup.add(insertValueItem);           
          }
          JMenuItem removeValueItem = new JMenuItem("Remove");
          removeValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              myModel.removeValue(path);
            }
          });
          popup.add(removeValueItem);       
        }
       
      }
     
      JMenuItem refreshItem = new JMenuItem("Refresh");
      refreshItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          myModel.refresh(path);
        }
      });
      popup.add(refreshItem);
     
      //property help on either property or property value ...
      Property property = null;
      if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
        property = (Property) path.getParentPath().getLastPathComponent();
      } else if (path.getLastPathComponent() instanceof Property) {
        property = (Property) path.getLastPathComponent();
      }     
      if (property != null) {
        JMenuItem helpItem = new JMenuItem("Help");
        final Property p = property;
        helpItem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String documentation = p.getDocumentation();
            if (documentation != null)
              ConfigUtil.showHelp(documentation);
          }       
        });
        popup.add(helpItem);
View Full Code Here

   */
  public void addValue(TreePath parentPath, Object value, String name) {
    try {
      Object parent = parentPath.getLastPathComponent();
      if (parent instanceof ListProperty) {
        ListProperty property = (ListProperty) parent;
        property.addValue(value);

        TreeModelEvent event = new TreeModelEvent(this, parentPath, new int[]{property.getNumValues()-1}, new Object[]{value});
        for (int i = 0; i <myListeners.size(); i++) {
          myListeners.get(i).treeNodesInserted(event);
        }
      } else if (parent instanceof NamedValueProperty) {
        NamedValueProperty property = (NamedValueProperty) parent;
        property.setValue(name, value);
        refresh(parentPath);
      } else {
        throw new RuntimeException("Can't add child to a " + parent.getClass().getName());
      }
    } catch (StructuralException e) {
View Full Code Here

   */
  public void insertValue(TreePath path, Object value) {
    try {
      Object parent = path.getParentPath().getLastPathComponent();
      if (parent instanceof ListProperty && path.getLastPathComponent() instanceof Value) {
        ListProperty property = (ListProperty) parent;
        Value toInsertBefore = (Value) path.getLastPathComponent();
        property.insert(toInsertBefore.getIndex(), value);

        Value node = new Value(toInsertBefore.getIndex(), value);
        TreeModelEvent insertEvent = new TreeModelEvent(this, path.getParentPath(),
            new int[]{toInsertBefore.getIndex()}, new Object[]{node});
        TreeModelEvent changeEvent = getIndexUpdateEvent(this, path.getParentPath(),
            toInsertBefore.getIndex()+1, property.getNumValues());
        for (int i = 0; i <myListeners.size(); i++) {
          myListeners.get(i).treeNodesInserted(insertEvent);
          myListeners.get(i).treeNodesChanged(changeEvent);
        }

View Full Code Here

      if (path.getLastPathComponent() instanceof Value && (parent instanceof ListProperty || parent instanceof NamedValueProperty)) {
        Value toRemove = (Value) path.getLastPathComponent();
        int numValues = 0;

        if (parent instanceof ListProperty) {
          ListProperty property = (ListProperty) parent;
          property.remove(toRemove.getIndex());
          numValues = property.getNumValues();
        } else if (parent instanceof NamedValueProperty) {
          NamedValueProperty property = (NamedValueProperty) parent;
          property.removeValue(toRemove.getName());
          numValues = property.getValueNames().size();
        }

        TreeModelEvent removeEvent = new TreeModelEvent(this, path.getParentPath(),
            new int[]{toRemove.getIndex()}, new Object[]{toRemove});
        TreeModelEvent changeEvent = getIndexUpdateEvent(this, path.getParentPath(),
View Full Code Here

          List<String> propertyNames = c.getPropertyNames();
          Collections.sort(propertyNames);
          result = c.getProperty(propertyNames.get(index));
        }
      } else if (parent instanceof ListProperty) {
        ListProperty p = (ListProperty) parent;
        Object o = p.getValue(index);
        result = new Value(index, o);
      } else if (parent instanceof NamedValueProperty) {
        NamedValueProperty p = (NamedValueProperty) parent;
        String name = p.getValueNames().get(index);
        Object o = p.getValue(name);
        result = new Value(index, o);
        ((Value) result).setName(name);
      } else if (parent instanceof SingleValuedProperty) {
        if (index == 0) {
          Object o = ((SingleValuedProperty) parent).getValue();
View Full Code Here

        Value v = (Value) child;
        if (p.getValue() != null && p.getValue().equals(v.getObject())) {
          index = 0;
        }
      } else if (parent instanceof ListProperty) {
        ListProperty p = (ListProperty) parent;
        Value v = (Value) child;
        for (int i = 0; i < p.getNumValues() && index == -1; i++) {
          if (p.getValue(i) != null && p.getValue(i).equals(v.getObject())) {
                        index = i;
                    }
        }
      } else if (parent instanceof NamedValueProperty) {
        NamedValueProperty p = (NamedValueProperty) parent;
        String name = ((Value) child).getName();
        for (int i = 0; i < p.getValueNames().size() && index == -1; i++) {
          if (p.getValueNames().get(i).equals(name)) {
                        index = i;
                    }
        }
      }
    } catch (StructuralException e) {
View Full Code Here

TOP

Related Classes of ca.nengo.config.ListProperty

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.