Package ca.nengo.config

Examples of ca.nengo.config.NamedValueProperty


            }
          });
          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


        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

        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

      } 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

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

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.