alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.beans;

import java.beans.*;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.util.ResourceBundle;

import org.openide.NotifyDescriptor;
import org.openide.src.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;

/** Node representing a indexed property.
* @see FieldElement
* @author Petr Hrebejk
*/
public class IdxPropertyPatternNode extends PropertyPatternNode  {
    /** Create a new field node.
    * @param element field element to represent
    * @param writeable true to be writable
    */
    public IdxPropertyPatternNode( IdxPropertyPattern pattern, boolean writeable) {
        super(pattern, writeable);
    }

    /* Resolve the current icon base.
    * @return icon base string.
    */
    protected String resolveIconBase() {

        switch (((PropertyPattern)pattern).getMode()) {
        case PropertyPattern.READ_WRITE:
            return IDXPROPERTY_RW;
        case PropertyPattern.READ_ONLY:
            return IDXPROPERTY_RO;
        case PropertyPattern.WRITE_ONLY:
            return IDXPROPERTY_WO;
        default:
            return null;
        }
    }

    /* Creates property set for this node */
    protected Sheet createSheet () {

        Sheet sheet = super.createSheet();
        Sheet.Set ps = sheet.get(Sheet.PROPERTIES);

        ps.put(createIndexedTypeProperty( writeable ));
        ps.put(createIndexGetterProperty( false ));
        ps.put(createIndexSetterProperty( false ));

        return sheet;
    }

    /** Gets the localized string name of property pattern type i.e.
     * "Indexed Property", "Property".
     */
    String getTypeForHint() {
        return PatternNode.getString( "HINT_IndexedProperty" );
    }

    /** Overrides the default implementation of clone node
    */
    public Node cloneNode() {
        return new IdxPropertyPatternNode((IdxPropertyPattern)pattern, writeable);
    }

    /** Create a property for the indexed property type.
      * @param canW false to force property to be read-only
      * @return the property
      */
    protected Node.Property createIndexedTypeProperty(boolean canW) {
        return new PatternPropertySupport(PROP_INDEXEDTYPE, Type.class, canW) {

                   /** Gets the value */

                   public Object getValue () {
                       return ((IdxPropertyPattern)pattern).getIndexedType();
                   }

                   /** Sets the value */
                   public void setValue(Object val) throws IllegalArgumentException,
                       IllegalAccessException, InvocationTargetException {
                       super.setValue(val);
                       if (!(val instanceof Type))
                           throw new IllegalArgumentException();

                       try {
                           pattern.patternAnalyser.setIgnore( true );
                           ((IdxPropertyPattern)pattern).setIndexedType((Type)val);
                           pattern.patternAnalyser.setIgnore( false );
                       }
                       catch (SourceException e) {
                           throw new InvocationTargetException(e);
                       }

                   }

                   /** Define property editor for this property. */
                   public PropertyEditor getPropertyEditor () {
                       return new PropertyTypeEditor();
                   }
               };
    }

    protected Node.Property createTypeProperty(boolean canW) {
        return new PatternPropertySupport(PROP_TYPE, Type.class, canW) {

                   /** Gets the value */

                   public Object getValue () {
                       return ((PropertyPattern)pattern).getType();
                   }

                   /** Sets the value */
                   public void setValue(Object val) throws IllegalArgumentException,
                       IllegalAccessException, InvocationTargetException {
                       super.setValue(val);
                       if (!(val instanceof Type))
                           throw new IllegalArgumentException();


                       try {
                           pattern.patternAnalyser.setIgnore( true );
                           ((PropertyPattern)pattern).setType((Type)val);
                           pattern.patternAnalyser.setIgnore( false );
                       }
                       catch (SourceException e) {
                           throw new InvocationTargetException(e);
                       }

                   }

                   public PropertyEditor getPropertyEditor () {
                       return new IdxPropertyTypeEditor();
                   }
               };
    }


    /** Create a property for the getter method.
     * @param canW false to force property to be read-only
     * @return the property
     */

    protected Node.Property createIndexGetterProperty(boolean canW) {
        return new PatternPropertySupport(PROP_INDEXEDGETTER, String.class, canW) {

                   /** Gets the value */

                   public Object getValue () {
                       ElementFormat fmt = new ElementFormat ("{n} ({p})"); // NOI18N
                       MethodElement method = ((IdxPropertyPattern)pattern).getIndexedGetterMethod();
                       if ( method == null )
                           return PatternNode.getString("LAB_NoMethod");
                       else
                           return (fmt.format (method));
                   }
               };
    }

    /** Create a property for the getter method.
     * @param canW false to force property to be read-only
     * @return the property
     */

    protected Node.Property createIndexSetterProperty(boolean canW) {
        return new PatternPropertySupport(PROP_INDEXEDSETTER, String.class, canW) {

                   /** Gets the value */

                   public Object getValue () {
                       ElementFormat fmt = new ElementFormat ("{n} ({p})"); // NOI18N
                       MethodElement method = ((IdxPropertyPattern)pattern).getIndexedSetterMethod();
                       if ( method == null )
                           return PatternNode.getString("LAB_NoMethod");
                       else
                           return (fmt.format (method));
                   }
               };
    }

}

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.