Skip to main content

NetBeans's JSF Palette Part II

Posted by edgars on January 12, 2007 at 10:24 AM PST

NetBeans platform is really cool, I´ve been creating some new items for JSP Palette, and maybe I publish this plugin in some place, even I know that NetBeans Team can do it much better than I. Although my newest palette items are working pretty well. And I can show you some additional tricks.

Some additional Tips to do New Items

I created an abstract class called, AbstractPaletteComponent , and then it is the base class for any new Tag. This following souce listing shows you how this works:

import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.text.ActiveEditorDrop;

/**
* @author Edgar Silva
*/

abstract public class AbstractPaletteComponent implements ActiveEditorDrop {
    final protected IdAndValueDialog tag = new IdAndValueDialog();
   
    private String tagValue;
   
    /** Creates a new instance of SelectOne */
    public AbstractPaletteComponent() {
    }
   
    private String createBody() {
        setTagValue(getPropsForTag());
        String tag;
        tag = getTagValue();
        return tag;
    }
   
    public boolean handleTransfer(JTextComponent targetComponent) {
        String body = createBody();
        try {
            FacesPaletteUtilities.insert(body, targetComponent);
        } catch (BadLocationException ble) {
            return false;
        }
        return true;
    }
   
    protected abstract String getPropsForTag();

    public String getTagValue() {
        return tagValue;
    }

    public void setTagValue(String tagValue) {
        this.tagValue = tagValue;
    }
   
    public void showErrorMessage(String text) {
      NotifyDescriptor.Message msg = new NotifyDescriptor.Message(text);
      msg.setMessageType(NotifyDescriptor.ERROR_MESSAGE);
      DialogDisplayer.getDefault().notify(msg);
    }
}

And now, create new items into palette is a really simple task. I created a new Item do generate the source of SelectItem, and this tags could be a lot of items, that´s why I created a new JPanel with JTable where I can to handle and manage the items. Look in the following images this new Component in action:


Drag and Drop the Component from Palette to the source:


11.JPG

Code Generated:

12.JPG

I hope you can enjoy this examples!

Related Topics >>