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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javadoc.comments;

import org.openide.nodes.Node;
import org.openide.util.NbBundle;
import org.openide.util.HelpCtx;
import org.openide.util.actions.CookieAction;
import org.openide.cookies.SourceCookie;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataFolder;
import org.openide.filesystems.FileStateInvalidException;
import org.netbeans.modules.javacore.internalapi.JMIElementCookie;

/**
 * Searches given folder for java sources and provides their Javadoc
 * correction dialogs.
 *
 * @author   Petr Hrebejk
 */
public class AutoCommentAction extends CookieAction {
    
    static final long serialVersionUID =4989490116568783623L;
    /** Human presentable name of the action. This should be
     * presented as an item in a menu.
     * @return the name of the action
     */
    public String getName() {
        return NbBundle.getBundle( AutoCommentAction.class ).getString("CTL_AUTOCOMMENT_MenuItem");    //NOI18N
    }
    
    /** Cookie classes contains one class returned by cookie () method.
     */
    protected final Class[] cookieClasses() {
        return new Class[] { DataFolder.class, SourceCookie.Editor.class };
    }
    
    /** All must be DataFolders or JavaDataObjects
     */
    protected int mode() {
        return MODE_ALL;
    }
    
    /** Help context where to find more about the action.
     * @return the help context for this action
     */
    public HelpCtx getHelpCtx() {
        return new HelpCtx(AutoCommentAction.class);
    }
    
    
    protected boolean enable( Node[] activatedNodes ) {
        if( activatedNodes.length == 0 )
            return false;
        int jdoCount = 0;
        for( int i = 0; i < activatedNodes.length; i++ ){
            if (activatedNodes[i].getCookie(JMIElementCookie.class) == null // hierarchy node?
                    && activatedNodes[i].getCookie(SourceCookie.class) == null) { // java node?
                
                continue;
            }
            
            DataObject doj = (DataObject) activatedNodes[i].getCookie(DataObject.class);
            if( doj != null && doj.getPrimaryFile().isReadOnly() )
                continue;
            jdoCount++;
        }
        if( jdoCount != 0)
            return true;
        else {
            return findInFolder( activatedNodes );
        }
    }
    
    /**
     * @param activatedNodes activated nodes on which look up
     * @return true if there is any commentable source
     */
    private boolean findInFolder( Node[] activatedNodes ){
        for( int i = 0; i < activatedNodes.length; i++ ){
            DataFolder df = (DataFolder)activatedNodes[i].getCookie(DataFolder.class);
            
            if( df == null )
                continue;
            
            try {
                if(df.getPrimaryFile().getFileSystem().isDefault())
                    continue;
            }
            catch(FileStateInvalidException fsie) {
                continue;
            }
            
            return true;
        }
        return false;
    }

    protected boolean asynchronous() {
        return false;
    }

    /** This method is called by one of the "invokers" as a result of
     * some user's action that should lead to actual "performing" of the action.
     * This default implementation calls the assigned actionPerformer if it
     * is not null otherwise the action is ignored.
     */
    public void performAction( Node[] nodes ) {
        
        AutoCommentTopComponent acTopComponent = AutoCommentTopComponent.getDefault();
        
        acTopComponent.open();
        acTopComponent.requestActive();
        
        acTopComponent.setAutoCommenter( new AutoCommenter( nodes ));
    }
    
//    protected String iconResource(){
//        return "org/netbeans/modules/javadoc/resources/autocomment.gif"; //NOI18N
//    }
}
... 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.