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-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.core.settings;

import java.beans.*;
import java.util.*;

import org.openide.actions.*;
import org.openide.util.actions.*;

/**
 * A simple property editor allowing to select class name of default action.
 *
 * @author  Petr Kuzel
 */
public final class DefaultActionPropertyEditor extends PropertyEditorSupport {
    
    /** Action name to its class name map */
    private static Map name2class = new TreeMap();
    
    static {
        String dname, cname;
        dname = SystemAction.get(EditAction.class).getName();
        cname = EditAction.class.getName();
        name2class.put(dname, cname);
        
        dname = SystemAction.get(OpenAction.class).getName();
        cname = OpenAction.class.getName();
        name2class.put(dname, cname);        

//        dname = SystemAction.get(PopupAction.class).getName();
//        cname = PopupAction.class.getName();
//        name2class.put(dname, cname);        

        dname = SystemAction.get(ViewAction.class).getName();
        cname = ViewAction.class.getName();
        name2class.put(dname, cname);        
        
        //??? some more actions as check would be handy. We should define them
        // in core as a cookie actions
        
    }
    
    /** Creates new DefaultActionPropertyEditor */
    public DefaultActionPropertyEditor() {        
    }
    
    /**
     * @return display names of suitable actions
     */
    public String[] getTags() {
        Set names = name2class.keySet();
        return (String[]) names.toArray(new String[names.size()]);
    }
    
    public void setAsText(String action) {
        String klass = (String) name2class.get(action);
        if (klass != null) {
            setValue(klass);
        } else {
            setValue(null);  // we could findout whether it is not an action defined by class name
                             // it is a feature for experienced users that will be implemented by request
        }
    }

    /**
     * Represent propery value as a text.
     */
    public String getAsText() {
        String className = (String) getValue();
        if (className == null) {
            return Util.THIS.getString("PROP_system_default_action");
        } else {
            Iterator it = name2class.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                String next = (String) name2class.get(key);
                if (next == null) continue;
                if (next.equals(className)) return key;
            }
            return className;  // for diagnostics purposes
        }        
    }
    
    public boolean supportsEditingTaggedValues () {
        return false;
    }
    
    public boolean hasInPlaceCustomEditor () {
        return false;
    }

    public boolean isPaintable() {
        return false;
    }
}
... 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.