ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meta...@locus.apache.org
Subject cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs ACSTaskElement.java ACSTaskElementBeanInfo.java
Date Fri, 17 Nov 2000 22:39:02 GMT
metasim     00/11/17 14:39:02

  Modified:    src/antidote/org/apache/tools/ant/gui/acs
                        ACSTaskElement.java ACSTaskElementBeanInfo.java
  Log:
  Started work on a Properties Bean property editor.
  
  Revision  Changes    Path
  1.2       +62 -1     jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElement.java
  
  Index: ACSTaskElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ACSTaskElement.java	2000/11/11 04:54:04	1.1
  +++ ACSTaskElement.java	2000/11/17 22:39:01	1.2
  @@ -53,17 +53,22 @@
    */
   package org.apache.tools.ant.gui.acs;
   
  -import com.sun.xml.tree.ElementNode;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NamedNodeMap;
  +import java.util.*;
   
   /**
    * Element containing a property definition.
    * 
  - * @version $Revision: 1.1 $ 
  + * @version $Revision: 1.2 $ 
    * @author Simeon Fitch 
    */
   public class ACSTaskElement extends ACSTreeNodeElement {
       /** Property name for the task type. */
       public static final String TASK_TYPE = "taskType";
  +    /** Property name for attributes. It's called "namedValues" so
  +     *  it doesn't collide with the Node.getAttributes() method. */
  +    public static final String NAMED_VALUES = "namedValues";
   
   	/** 
   	 * Default ctor.
  @@ -79,6 +84,62 @@
   	 */
       public String getTaskType() {
           return getTagName();
  +    }
  +
  +
  +	/** 
  +	 * Get the attributes (named value mappings). This method is not named
  +     * getAttributes() because there is already a method of that name in
  +     * the Node interface.
  +	 * 
  +	 * @return Name-value mappings.
  +	 */
  +    public Properties getNamedValues() {
  +        Properties retval = new Properties();
  +
  +        NamedNodeMap attribs = getAttributes();
  +        for(int i = 0, len = attribs.getLength(); i < len; i++) {
  +            Node n = attribs.item(i);
  +            retval.setProperty(n.getNodeName(), n.getNodeValue());
  +        }
  +        return retval;
  +    }
  +
  +
  +	/** 
  +	 * Set the attributes. This method sets the Node attirbutes using 
  +     * the given Map containing name-value pairs.
  +	 * 
  +	 * @param attributes New attribute set.
  +	 */
  +    public void setNamedValues(Properties props) {
  +        // XXX this code really sucks. It is really annoying that the 
  +        // DOM interfaces don't have a general "setAttributes()" or
  +        // "removeAllAttributes()" method, but instead make you 
  +        // remove each attribute individually, or require you to figure
  +        // out what the differences are between the two. 
  +
  +        // Although this is very inefficient, I'm taking the conceptually
  +        // simplistic approach to this and brute force removing the existing 
  +        // set and replacing it with a brand new set. If this becomes a 
  +        // performance concern (which I doubt it will) it can be optimized 
  +        // later.
  +
  +        Properties old = getNamedValues();
  +
  +        Enumeration enum = old.propertyNames();
  +        while(enum.hasMoreElements()) {
  +            String name = (String) enum.nextElement();
  +            removeAttribute(name);
  +        }
  +        
  +        enum = props.propertyNames();
  +        while(enum.hasMoreElements()) {
  +            String key = (String) enum.nextElement();
  +            setAttribute(key, props.getProperty(key));
  +        }
  +
  +        firePropertyChange(NAMED_VALUES, old, props);
       }
   
   }
  
  
  
  1.3       +5 -1      jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java
  
  Index: ACSTaskElementBeanInfo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ACSTaskElementBeanInfo.java	2000/11/16 22:38:41	1.2
  +++ ACSTaskElementBeanInfo.java	2000/11/17 22:39:01	1.3
  @@ -59,7 +59,7 @@
   /**
    * BeanInfo for the ACSTaskElement class.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class ACSTaskElementBeanInfo extends BaseBeanInfo {
  @@ -101,6 +101,8 @@
                   new PropertyDescriptor(ACSTaskElement.TASK_TYPE, 
                                          ACSTaskElement.class,
                                          "getTaskType", null),
  +                new PropertyDescriptor(ACSTaskElement.NAMED_VALUES, 
  +                                       ACSTaskElement.class),
                   new PropertyDescriptor(ACSTaskElement.XML_STRING, 
                                          ACSTaskElement.class,
                                          "getXMLString", null)
  @@ -109,6 +111,8 @@
               retval[0].setDisplayName(getResources().getString(
                   getClass(),ACSTaskElement.TASK_TYPE));
               retval[1].setDisplayName(getResources().getString(
  +                getClass(),ACSTaskElement.NAMED_VALUES));
  +            retval[2].setDisplayName(getResources().getString(
                   getClass(),ACSTaskElement.XML_STRING));
   
               setSortingOrder(retval);
  
  
  

Mime
View raw message