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.web.core.syntax;

import java.awt.event.ActionEvent;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.net.URL;


import javax.servlet.jsp.tagext.*;
import javax.swing.text.Document;


import org.netbeans.editor.ext.*;
import org.netbeans.editor.ext.java.*;
import org.netbeans.modules.editor.java.NbCompletionJavaDoc;
import org.openide.util.RequestProcessor;
import org.openide.util.NbBundle;





/** Support for displaying Javadoc and similar help information
 * in editor.
 *
 *  @author  Radim Kubacki, Petr Pisl
 *  @since module version 1.8
 */
public class JspCompletionJavaDoc extends NbCompletionJavaDoc {

    /** Creates a new instance of NbCompletionJavaDoc */
    public JspCompletionJavaDoc(ExtEditorUI extEditorUI) {
        super(extEditorUI);
    }

    public synchronized void actionPerformed(ActionEvent e) {
        CompletionItem.JspResultItem item = isJspResultItem();
        if (item != null && item.hasHelp()) {
            cancelPerformingThread();
            JspDocParsingThread pt = new JspDocParsingThread(item);
            RequestProcessor.getDefault ().post(pt);
            return;
        }

        super.actionPerformed(e);
    }    

    /** When it returens true, then the icon for opening in external browser is enabled,
     *  else the icon is disabled.
     */
    public boolean  isExternalJavaDocMounted(){
        CompletionItem.JspResultItem ri = isJspResultItem();
        if (ri != null)
            return ri.getHelpURL() != null;
        return super.isExternalJavaDocMounted();
    }
    public Object parseLink(String link, Object obj){
        if (obj instanceof JCClass || obj == null){
             return parseLink(link, (JCClass)obj);
         }
         return null;
    }
    
    public void openInExternalBrowser(){
        CompletionItem.JspResultItem ri = isJspResultItem();
        if (ri != null) {
            URL url = isJspResultItem().getHelpURL();
            if (url != null)
                org.openide.awt.HtmlBrowser.URLDisplayer.getDefault().showURL(url);
        }
    }
        
    /** It finds out, wherether the currentContent includes a JspResultItem. 
     *  If yes, than the JspResultItem is returned. If no, then null is returned.
     */
    private CompletionItem.JspResultItem isJspResultItem(){
        if (currentContent instanceof CompletionItem.JspResultItem)
            return (CompletionItem.JspResultItem)currentContent;
        if (currentContent instanceof CompletionItem.DelegatingResultItem 
            && ((CompletionItem.DelegatingResultItem)currentContent).resultItem instanceof CompletionItem.JspResultItem){
            return    (CompletionItem.JspResultItem) ((CompletionItem.DelegatingResultItem)currentContent).resultItem;
        }
        return null;
    }
    
    /** If true, the javadoc popup will remain open during completion item change
     *  and "Searching..." dialog will be shown. If the javadoc item will not be found,
     *  the "Javadoc Not Found" message will be also shown
     *  If false, then only valid javadoc content will be shown
     */
    protected boolean alwaysDisplayPopup(){
        return false;
    }
    
    /** Runnable for building of doc related to JSP items. */
    private class JspDocParsingThread implements Runnable{
        
        Object content;
        boolean running = true;
        
        public JspDocParsingThread(Object content){
            this.content = content;
        }
        
        void stopTask(){
            running = false;
        }
        
         
        private void showJavaDoc(String preparedText, boolean goToSource){
            if (running){
                getJavaDocView().setContent(preparedText);
                setGoToSourceEnabled(goToSource);
                if (running){ 
                    setJavaDocVisible(true);
                }
            }
        }
        
        
        
        public void run(){
            if (content instanceof CompletionItem.JspResultItem){
                String help = ((CompletionItem.JspResultItem) content).getHelp();
                if (help != null)
                    showJavaDoc (help, 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.