The Source for Java Technology Collaboration
User: Password:



Edgar Silva's Blog

Community: NetBeans Archives


NetBeans Dream Team as a Community Team

Posted by edgars on January 19, 2007 at 09:40 AM | Permalink | Comments (2)

Roumen is a really fast blogger, this already is in his blog =). As I am one of these guys, I wanna say thanks to NetBeans's Team, and I hope we can do a good job on NetBeans Dream Team.

First of all, we are defining how the project will work, however I can say that you will have very interesting good news, and please prepare yourself to join with us in that interesting Project.

Is not so usual I write non-techinical stuff, although I would like to share a funny initial view :
The NBDT is composed by 11 founding members, as I am a typical Brazilian, is really impossible don't think in Soccer! (Team+11 Players==Soccer). However, instead of the the brazilian soccer team terrible failure in the last world cup, where all players wanted the attentions individually, I am sure We have to be completelly different and to turn the NBDT an open channel where we can hear the community , where we can see a real good team (such as German and Italy =) on last WorldCup)!.

I wanna also say hello to all NBDT members! There is another Brazilian involved: Vinicius Senger, which is my friend, but I guess that he prefers surf =).

I will keep you in touch about the news from NetBeans Dream Team here on my Java.Net blog, and if you understand portuguese, you can go to my PT_BR blog.

Italy
Italy, the WorldCup 2006 Champion (a good example of a Team)
inter.jpg
Internacional from Brazil, the Toyota 2006 World Champion, another good example of "No Stars...Yes Union".


Using the Java Source Editor and Syntax highlight in any JEditorPane

Posted by edgars on January 17, 2007 at 10:52 AM | Permalink | Comments (2)

On the my new JSF Palette Components I've been doing, It allows users get any BackingBean (bean) from the Project, to make it possible, I was looking for on NetBeans Dev Wiki. And I get this entry: http://wiki.netbeans.org/wiki/view/DevFaqEditorJEPForMimeType . However, I think this might works on NetBeans 6.0, cause doing like this entry says ...

EditorKit kit = CloneableEditorSupport.getEditorKit("text/x-java");
JEditorPane jep = new JEditorPane();
jep.setEditorKit(kit);

I in fact did not have success. But, NetBeans Platform, offers great resources, as I did something similar to Greenbox for NetBeans , I did the following code for what I was needing:


      /** Creates new form JavaCodePanel */
    public JavaCodePanel() {
        initComponents();
        beanCode.setContentType("text/x-java");
        EditorKit kit = JEditorPane.createEditorKitForContentType("text/x-java");
        kit.install(beanCode);
        beanCode.setEditorKit(kit);
    }

On the code the beanCode is a JEditorPane, and now this will have the same actions you can see on default Java Editor.
Look on the following image this component working:


javacode.PNG
javacode2.PNG
javacode3.PNG

NetBeans Plugin Dev : Listing all packages from default main project

Posted by edgars on January 17, 2007 at 05:25 AM | Permalink | Comments (0)

Hi everybody, after some free time this week, I am almost finishing the new JSF Palette for NetBeans. In the following image you can see its actual state:
1.PNG
As we are always doing comercial applications for serveral niches of business, it´s really cool to imagine you could work as an IDE Developer, while you aren't hired to do that, you can do it to help you save time in projects or simply for fun. I will show you now the secrets behind the following dialog:
JSFMESSAGES.PNG
I used this dialog when a user is inserting the tag f:loadBundle, in JSP source, we might set the package name, property file name and the var reference name to this tag. Than we are listing all packages from our default main project in a simple JComboBox. To do this, I am using the following code:

    protected void initializeComboPackages() {
        Project p = OpenProjects.getDefault().getMainProject();
        Sources src = (Sources) p.getLookup().lookup(Sources.class);
        if (src!=null)  {
            SourceGroup[] groups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            if (groups.length>0) {
               SourceGroup group = groups[0];
               packages.setModel(PackageView.createListView(group));
               packages.setRenderer(PackageView.listRenderer());
               
            }
        }
        
    }

In the code "packages" is a JComboBox. If you want create some plugin using similar feature, now you have this described here.
Cya
Edgar Silva - edgar (em) edgarsilva.com.br



NetBeans's JSF Palette Part II

Posted by edgars on January 12, 2007 at 10:24 AM | Permalink | Comments (3)

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!

Creating a new Components Palette for Java Server Faces Dev in NetBeans 5.5

Posted by edgars on January 11, 2007 at 09:44 AM | Permalink | Comments (1)

Motivation

If you want to create an application using Java Server Faces using NetBeans you have really useful features as which turn this task simple. Nevertheless we have a lot of open-source projects that can help us on JSF Developement, such as: MyFaces, Facelets , IceFaces , Ajax4JSF and others. I am sure, that some of the developers envolved with these projects would like to make the development easier using their components. If you need a complete solution to make your components availabe in NetBeans, this post can to give out some tips and tricks in how to do that.

NetBeans Benefits for JSF Components Creators

NetBeans, since of its default installation, counts with a lot of nice features, as the following:

  • JSP and JSPX Syntax Highlight
  • HTML and XHTML Syntax Highlight
  • XML Syntax Highlight
  • Code Completion for JSP, XML and HTML
  • An embedded TomCat to test and debug
  • Web Project Types and features for JSF and Struts
  • Component Palette Items for HTML and JSP

If NetBeans did these things for us, why is not possible to add our own components on JSP/JSF Component Palette?I am sure you can think: "This sound quite hard...", However I can say: Don't worry! Read this post and I am sure you will have a different spot.

Creating a New Module Suite Project

A Module Suite is necessay to create a set of new Modules, our Components Items are one Project Module inside a Module Suite. Besides palette components, we could to add new modules to suite, in addition to this, when you create a suite you can run another NetBean´s instance, and then dubug and test our modules can be easier. To create a new Module Suite, click on File/New/Project, and then select NetBeans Plugin-Modules category and click on the Module Suite Project., as it is shown in the following image:


1.JPG

Click on Next button, and fill the suite's data with the following information:

  • Project Name: faces-pro
  • Project Location: This you can to choose anything you want

Creating a New Module Project

A Module Project is your set of plugin(s), we often use a Module to add one or more plugins in NetBeans. As well as you can use one Project Module per new Plugin you are creating. To create a new one, click on File/New/Project menu and select NetBeans Plugin-Modules category and click on the Module Project..After click on Next button, you will see the Project settings informations, basically we have to give a name to project and select which Suite this module will be inserted on, as it is shown in the following image:


2.JPG

After to click on Next button, you will see some informations about your Module Project, look the following list:

  • Code Base Name: The standard package for your classes and files
  • Module Display Name: Some impressive display name, for example: Java Server Faces Pro Tags
  • Code Base Name: The standard package for your classes and files
  • Localizing Bundle: NetBeans really cares to I18N so everything you did in your plugins always you will have a file to put your messages, informations and etc
  • XML Layer: This is in my opinion the most important file when you are doing NetBean's plugins, just because almost everything you expose to NetBeans platform enviorement is declared on this file, such as our new Palette Items.
Take a Look in the following image to figure out how you can fill these informations:


3.JPG

Creating a JSP Palette Component Item: SelectOneMenu

The SelectOneMenu is responsible in generating an html select with some dinamic data. Then, We will create a class to represent this code generation inside of JSP file. The class will be called SelectOne.java .
The following code shows you how you can handle the drag and drop from palette to source editor in NetBeans:


import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.text.ActiveEditorDrop;

public class SelectOne implements  ActiveEditorDrop {
    
    final protected SelectOnePanel tag = new SelectOnePanel();
    
    private String id;
    
    private String value;
    
    private String tagValue;
    
    /** Creates a new instance of SelectOne */
    public SelectOne() {
    }
    
    private String createBody() {
        getPropsForTag();
        String SelectOne;
        SelectOne = getTagValue();
        return SelectOne;
    }
    
    public boolean handleTransfer(JTextComponent targetComponent) {
        String body = createBody();
        try {
            FacesPaletteUtilities.insert(body, targetComponent);
        } catch (BadLocationException ble) {
            return false;
        }
        return true;
    }
    
    
    protected void getPropsForTag() {
        DialogDescriptor tagdialogdescriptor = 
new DialogDescriptor(tag,"Java Server Faces Pro");
        tagdialogdescriptor.setModal(true);
        tagdialogdescriptor.setLeaf(true);
        tagdialogdescriptor.setOptionType(DialogDescriptor.OK_CANCEL_OPTION);
        
        Object ret =  DialogDisplayer.getDefault().notify(tagdialogdescriptor);
        
        if (ret == DialogDescriptor.OK_OPTION) {
          StringBuffer buffer = new StringBuffer();
          buffer.append(String.format("", tag.id.getText(), tag.value.getText()));
          buffer.append("\n  ");
          buffer.append("\n");
          
          setTagValue(buffer.toString());
        } else {
          setTagValue("");
        }

As you can see our SelectMenu class, implements the org.openide.text.ActiveEditorDrop, as which allow us to drag an item from palette and drop on source code, basically the executed method to automate this task is called: handleTransfer(). Look that in the method calling we have other two pieces: createBody() and FacesPaletteUtilities.insert(body, targetComponent). We will describe these methods in the following list:

  • createBody() : This method calls a Dialog to interact with user before insert the code. This dialog basically ask you about the values that we can fill in the SelecOneMenu tag (id and value).
  • FacesPaletteUtilities.insert(): This static method is a helper to handle the text insertion on the source code.

Using Dialogs to Interact with Users

Certainly you are really proud with yourself, cause you are improving a lot the NetBeans IDE with your own component´s palette, and then you will give out a real gift to community that want use your group of components or even your internal development team. That´s you can give a professional impression about your pallete, to make it real we create a simple JPanel, and the most important items on this JPanel are 2 JTextFields, called id and value, respectivelly . They have to declared as public

, because we will access them from other class, although you can create getter and setters if you want. Look on the following image and imagine how you can design your JPanel:
4.JPG
At this point, you can ask me: "Hey Edgar, and the rest of the code? The method where I transfer the JTextField´s value to my SelectMenu.createBody() method? Where is it? The answer is incredibly easy: NetBeans provides a real set of helpers when we are creating a plugin or a complete RCP Application, so NetBeans gives for us two class called respectivelly: DialogDescriptor and DialogDisplayer, and togethet with these classes, we have all infrastructe to handle the which button is clicked by users, it you can see here in the following code:
    protected void getPropsForTag() {
        DialogDescriptor tagdialogdescriptor = new DialogDescriptor(tag,"Java Server Faces Pro");
        tagdialogdescriptor.setModal(true);
        tagdialogdescriptor.setLeaf(true);
        tagdialogdescriptor.setOptionType(DialogDescriptor.OK_CANCEL_OPTION);
        
        Object ret =  DialogDisplayer.getDefault().notify(tagdialogdescriptor);
        
        if (ret == DialogDescriptor.OK_OPTION) {
          StringBuffer buffer = new StringBuffer();
          buffer.append(String.format("", tag.id.getText(), tag.value.getText()));
          buffer.append("\n  ");
          buffer.append("\n");
          
          setTagValue(buffer.toString());
        } else {
          setTagValue("");
        }
    }

If the user presses on OK button, we return the correct value, inserting the informations contained on the JTextFields. Furthermore, the presentation, threading and other swing stuff will be managed by NetBeans.

Creating a Insertion code Helper: FacesPaletteUtilities

This class acts as a helper when we want to add some text in a existing source opened in the our JSP Editor. Look its source code in the following code listing:

import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.Formatter;

public class FacesPaletteUtilities {
    public static void insert(String s, JTextComponent target)
    throws BadLocationException {
        insert(s, target, true);
    }
    
    public static void insert(String s, JTextComponent target, boolean reformat)
    throws BadLocationException {
        
        if (s == null)
            s = "";
        
        Document doc = target.getDocument();
        if (doc == null)
            return;
        
        if (doc instanceof BaseDocument)
            ((BaseDocument)doc).atomicLock();
        
        int start = insert(s, target, doc);
        
        if (reformat && start >= 0 && doc instanceof BaseDocument) {  
            int end = start + s.length();
            Formatter f = ((BaseDocument)doc).getFormatter();
            f.reformat((BaseDocument)doc, start, end);
        }
        
        if (doc instanceof BaseDocument)
            ((BaseDocument)doc).atomicUnlock();
        
    }
    
    private static int insert(String s, JTextComponent target, Document doc)
    throws BadLocationException {
        
        int start = -1;
        try {
            //at first, find selected text range
            Caret caret = target.getCaret();
            int p0 = Math.min(caret.getDot(), caret.getMark());
            int p1 = Math.max(caret.getDot(), caret.getMark());
            doc.remove(p0, p1 - p0);
            
            //replace selected text by the inserted one
            start = caret.getDot();
            doc.insertString(start, s, null);
        } catch (BadLocationException ble) {}
        
        return start;
    }
}

Declaring Additional informations and Resources

Now it´s time to create a component descriptor file, which is a XML file. This file describes informations about our component, you will this file on the same package of SelectMenu class. The file name will be SelectOne.xml, and its content is the following:
5.JPG
As you can see we had been definied the: Class component item, its icon representation for both sizes (16X16 and 32X32). Moreover we definied the keys for name and description of our component item.

Declaring our Component in layer.xml

This one of the most important steps on this post, we will declare our component inside Netbeans enviroment. Look this file in the following image:
6.JPG
Well, that´s all you need to create a new item on JSF Palette. Now you can Run your Module Suite.

Some Details about Modules Development

Libraries Dependencies

When you are creating a NetBean´s Module , depending of the kind of things you are creating, some dependencies should be mandatories. To add these dependencies, click with left button over your Module Project and click on Properties option, take a look on Libraries Item on left list, on this panel you can add your module´s dependencies.
To this module we did, you will need the modules shown on the following image:
7.JPG

Icons for your Components

The years I spent on University was not enough to learn how to create cool and beautiful icons, In addition, I am not an artist as my famous friend: Tim Boudreau , that created a lot of NetBeans's icons.
Then if you want your users really excited with, is had better you have some friends in our team that don't create your icons. =)

Showing our plugin In Action

Now it's time to see our plugin running:
Look our new Component Item and new Palette:
8.JPG
Dragging our component to Source Editor:
9.JPG
The Code was inserted on the JSP source code editor:
10.JPG

I hope this post could be useful for frameworks developers, or even developers at companies using NetBeans and want to create or add your own component items to turn JSP and JSF delopment easier and faster.

If you want the project´s files, please send me an e-mail: edgar (em) edgarsilva.com.br

Creating a new Components Palette for Java Server Faces Dev in NetBeans 5.5

Posted by edgars on January 11, 2007 at 09:44 AM | Permalink | Comments (1)

Motivation

If you want to create an application using Java Server Faces using NetBeans you have really useful features as which turn this task simple. Nevertheless we have a lot of open-source projects that can help us on JSF Developement, such as: MyFaces, Facelets , IceFaces , Ajax4JSF and others. I am sure, that some of the developers envolved with these projects would like to make the development easier using their components. If you need a complete solution to make your components availabe in NetBeans, this post can to give out some tips and tricks in how to do that.

NetBeans Benefits for JSF Components Creators

NetBeans, since of its default installation, counts with a lot of nice features, as the following:

  • JSP and JSPX Syntax Highlight
  • HTML and XHTML Syntax Highlight
  • XML Syntax Highlight
  • Code Completion for JSP, XML and HTML
  • An embedded TomCat to test and debug
  • Web Project Types and features for JSF and Struts
  • Component Palette Items for HTML and JSP

If NetBeans did these things for us, why is not possible to add our own components on JSP/JSF Component Palette?I am sure you can think: "This sound quite hard...", However I can say: Don't worry! Read this post and I am sure you will have a different spot.

Creating a New Module Suite Project

A Module Suite is necessay to create a set of new Modules, our Components Items are one Project Module inside a Module Suite. Besides palette components, we could to add new modules to suite, in addition to this, when you create a suite you can run another NetBean´s instance, and then dubug and test our modules can be easier. To create a new Module Suite, click on File/New/Project, and then select NetBeans Plugin-Modules category and click on the Module Suite Project., as it is shown in the following image:


1.JPG

Click on Next button, and fill the suite's data with the following information:

  • Project Name: faces-pro
  • Project Location: This you can to choose anything you want

Creating a New Module Project

A Module Project is your set of plugin(s), we often use a Module to add one or more plugins in NetBeans. As well as you can use one Project Module per new Plugin you are creating. To create a new one, click on File/New/Project menu and select NetBeans Plugin-Modules category and click on the Module Project..After click on Next button, you will see the Project settings informations, basically we have to give a name to project and select which Suite this module will be inserted on, as it is shown in the following image:


2.JPG

After to click on Next button, you will see some informations about your Module Project, look the following list:

  • Code Base Name: The standard package for your classes and files
  • Module Display Name: Some impressive display name, for example: Java Server Faces Pro Tags
  • Code Base Name: The standard package for your classes and files
  • Localizing Bundle: NetBeans really cares to I18N so everything you did in your plugins always you will have a file to put your messages, informations and etc
  • XML Layer: This is in my opinion the most important file when you are doing NetBean's plugins, just because almost everything you expose to NetBeans platform enviorement is declared on this file, such as our new Palette Items.
Take a Look in the following image to figure out how you can fill these informations:


3.JPG

Creating a JSP Palette Component Item: SelectOneMenu

The SelectOneMenu is responsible in generating an html select with some dinamic data. Then, We will create a class to represent this code generation inside of JSP file. The class will be called SelectOne.java .
The following code shows you how you can handle the drag and drop from palette to source editor in NetBeans:


import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.text.ActiveEditorDrop;

public class SelectOne implements  ActiveEditorDrop {
    
    final protected SelectOnePanel tag = new SelectOnePanel();
    
    private String id;
    
    private String value;
    
    private String tagValue;
    
    /** Creates a new instance of SelectOne */
    public SelectOne() {
    }
    
    private String createBody() {
        getPropsForTag();
        String SelectOne;
        SelectOne = getTagValue();
        return SelectOne;
    }
    
    public boolean handleTransfer(JTextComponent targetComponent) {
        String body = createBody();
        try {
            FacesPaletteUtilities.insert(body, targetComponent);
        } catch (BadLocationException ble) {
            return false;
        }
        return true;
    }
    
    
    protected void getPropsForTag() {
        DialogDescriptor tagdialogdescriptor = 
new DialogDescriptor(tag,"Java Server Faces Pro");
        tagdialogdescriptor.setModal(true);
        tagdialogdescriptor.setLeaf(true);
        tagdialogdescriptor.setOptionType(DialogDescriptor.OK_CANCEL_OPTION);
        
        Object ret =  DialogDisplayer.getDefault().notify(tagdialogdescriptor);
        
        if (ret == DialogDescriptor.OK_OPTION) {
          StringBuffer buffer = new StringBuffer();
          buffer.append(String.format("", tag.id.getText(), tag.value.getText()));
          buffer.append("\n  ");
          buffer.append("\n");
          
          setTagValue(buffer.toString());
        } else {
          setTagValue("");
        }

As you can see our SelectMenu class, implements the org.openide.text.ActiveEditorDrop, as which allow us to drag an item from palette and drop on source code, basically the executed method to automate this task is called: handleTransfer(). Look that in the method calling we have other two pieces: createBody() and FacesPaletteUtilities.insert(body, targetComponent). We will describe these methods in the following list:

  • createBody() : This method calls a Dialog to interact with user before insert the code. This dialog basically ask you about the values that we can fill in the SelecOneMenu tag (id and value).
  • FacesPaletteUtilities.insert(): This static method is a helper to handle the text insertion on the source code.

Using Dialogs to Interact with Users

Certainly you are really proud with yourself, cause you are improving a lot the NetBeans IDE with your own component´s palette, and then you will give out a real gift to community that want use your group of components or even your internal development team. That´s you can give a professional impression about your pallete, to make it real we create a simple JPanel, and the most important items on this JPanel are 2 JTextFields, called id and value, respectivelly . They have to declared as public

, because we will access them from other class, although you can create getter and setters if you want. Look on the following image and imagine how you can design your JPanel:
4.JPG
At this point, you can ask me: "Hey Edgar, and the rest of the code? The method where I transfer the JTextField´s value to my SelectMenu.createBody() method? Where is it? The answer is incredibly easy: NetBeans provides a real set of helpers when we are creating a plugin or a complete RCP Application, so NetBeans gives for us two class called respectivelly: DialogDescriptor and DialogDisplayer, and togethet with these classes, we have all infrastructe to handle the which button is clicked by users, it you can see here in the following code:
    protected void getPropsForTag() {
        DialogDescriptor tagdialogdescriptor = new DialogDescriptor(tag,"Java Server Faces Pro");
        tagdialogdescriptor.setModal(true);
        tagdialogdescriptor.setLeaf(true);
        tagdialogdescriptor.setOptionType(DialogDescriptor.OK_CANCEL_OPTION);
        
        Object ret =  DialogDisplayer.getDefault().notify(tagdialogdescriptor);
        
        if (ret == DialogDescriptor.OK_OPTION) {
          StringBuffer buffer = new StringBuffer();
          buffer.append(String.format("", tag.id.getText(), tag.value.getText()));
          buffer.append("\n  ");
          buffer.append("\n");
          
          setTagValue(buffer.toString());
        } else {
          setTagValue("");
        }
    }

If the user presses on OK button, we return the correct value, inserting the informations contained on the JTextFields. Furthermore, the presentation, threading and other swing stuff will be managed by NetBeans.

Creating a Insertion code Helper: FacesPaletteUtilities

This class acts as a helper when we want to add some text in a existing source opened in the our JSP Editor. Look its source code in the following code listing:

import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.Formatter;

public class FacesPaletteUtilities {
    public static void insert(String s, JTextComponent target)
    throws BadLocationException {
        insert(s, target, true);
    }
    
    public static void insert(String s, JTextComponent target, boolean reformat)
    throws BadLocationException {
        
        if (s == null)
            s = "";
        
        Document doc = target.getDocument();
        if (doc == null)
            return;
        
        if (doc instanceof BaseDocument)
            ((BaseDocument)doc).atomicLock();
        
        int start = insert(s, target, doc);
        
        if (reformat && start >= 0 && doc instanceof BaseDocument) {  
            int end = start + s.length();
            Formatter f = ((BaseDocument)doc).getFormatter();
            f.reformat((BaseDocument)doc, start, end);
        }
        
        if (doc instanceof BaseDocument)
            ((BaseDocument)doc).atomicUnlock();
        
    }
    
    private static int insert(String s, JTextComponent target, Document doc)
    throws BadLocationException {
        
        int start = -1;
        try {
            //at first, find selected text range
            Caret caret = target.getCaret();
            int p0 = Math.min(caret.getDot(), caret.getMark());
            int p1 = Math.max(caret.getDot(), caret.getMark());
            doc.remove(p0, p1 - p0);
            
            //replace selected text by the inserted one
            start = caret.getDot();
            doc.insertString(start, s, null);
        } catch (BadLocationException ble) {}
        
        return start;
    }
}

Declaring Additional informations and Resources

Now it´s time to create a component descriptor file, which is a XML file. This file describes informations about our component, you will this file on the same package of SelectMenu class. The file name will be SelectOne.xml, and its content is the following:
5.JPG
As you can see we had been definied the: Class component item, its icon representation for both sizes (16X16 and 32X32). Moreover we definied the keys for name and description of our component item.

Declaring our Component in layer.xml

This one of the most important steps on this post, we will declare our component inside Netbeans enviroment. Look this file in the following image:
6.JPG
Well, that´s all you need to create a new item on JSF Palette. Now you can Run your Module Suite.

Some Details about Modules Development

Libraries Dependencies

When you are creating a NetBean´s Module , depending of the kind of things you are creating, some dependencies should be mandatories. To add these dependencies, click with left button over your Module Project and click on Properties option, take a look on Libraries Item on left list, on this panel you can add your module´s dependencies.
To this module we did, you will need the modules shown on the following image:
7.JPG

Icons for your Components

The years I spent on University was not enough to learn how to create cool and beautiful icons, In addition, I am not an artist as my famous friend: Tim Boudreau , that created a lot of NetBeans's icons.
Then if you want your users really excited with, is had better you have some friends in our team that don't create your icons. =)

Showing our plugin In Action

Now it's time to see our plugin running:
Look our new Component Item and new Palette:
8.JPG
Dragging our component to Source Editor:
9.JPG
The Code was inserted on the JSP source code editor:
10.JPG

I hope this post could be useful for frameworks developers, or even developers at companies using NetBeans and want to create or add your own component items to turn JSP and JSF delopment easier and faster.

If you want the project´s files, please send me an e-mail: edgar (em) edgarsilva.com.br

New CSS Editor in NetBeans 5.5

Posted by edgars on January 08, 2007 at 08:50 AM | Permalink | Comments (0)

Hi Everybody, After reload my energy in the beach and had been enjoing my holidays at Floripa(Brazil's South Region):
floripa.gif
I am back to publish some interesting stuff here =)

In fact, Netbeans 5.5 swells its number of features in each new version, in case of 5.5, the main focus is "Enable JEE development really easy". That's why some really impressive new features are quite hidden, one of these is CSS Editor. To see the NB CSS Editor in action, just create or open a CSS file. Check it out in the following image:
css1.JPG

Creating a New Style

Create a new Style is really easy, first of all click on the following button:
css2.JPG
Then you can create a rule(style) creating a class o defining an html element, as you can see the following image: css3.JPG

As you can see, edit or create CSS files in NetBeans is as easy as you did in HTML tools such as Macromedia Dreamweaver(TM) or Ultradev(TM), in despite of the fact in NetBeans this feature is completelly free and integrated with a complete set of tools for Java Web Development.

Have Fun with NetBeans CSS Editor!

Learning EJB 3.0, JPA and JSF with NetBeans 5.5

Posted by edgars on November 16, 2006 at 01:33 AM | Permalink | Comments (18)

Hi Folks,
Well, so much time without post anything here, I've been quite busy these last months, but now I have a couple of time to share with you how to learn and develop an Application using: NetBeans 5.5, JSF, EJB and JPA.

First of all, I will assume that you had installed the folowing software:

- NetBeans 5.5 (final version)
- GlassFish or Sun Java System Application Server 9

With that software, we are able to continue this tutorial. In this post you will see part I and Part II

Part I

You will need some concepts to understand this tutorial, that's why I am providing basics words about the technologies we are using here.

Introduction to JSF

Java Server Faces has a new version, the JSF 2.0, result of JSR 252,basically this technology is the standard choice when you think about Web Development using Java. Even you can others, such as Tapestry, Wicket or any other, JSF belongs the standard as member of Java EE 5.

Please see more detailed informations about JSF here.


Introduction to JPA

Inside of EJB 3.0 specification, under JSR 220. The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO. Customers now no longer face the choice between incompatible non-standard persistence models for object/relational mapping. In addition, the Java Persistence API is usable both within Java SE environments as well as within Java EE, allowing many more developers to take advantage of a standard persistence API.

See more detailed informations here.

Introduction to EJB 3.0

EJB 3.0 brings the simplicity to JEE developer, such as we can see in older frameworks, however EJB is a standard, also definied in JSR 220, such as JPA. There are good new stuffs on EJB 3.0, my preferred feature is the EJB Interpectors, that can act as Aspects(AOP) inside my enterprise beans context.

See more detailed informations here.


Use Case Development: Maitain Manufacturer

This Use Case is responsable for create, delete, update and list a Manufacturer, using:

- A JSP using JSF tags as web client side tier.
- A BackingBeans which invokes a Stateless Session Bean
- A Stateless Session Bean as a Façade which calls the persitence Tier.
- Persitence Tier using JPA
- The entire UseCase will be deployed at GlassFish.

NetBeans 5.5 : Configuring GlassFish in NetBeans 5.5
See ScreenCast

Here you will discover how to integrate Glassfish or Sun Java System App Server 9 with NetBeans 5.5.

NetBeans 5.5 : Creating the Enterprise Project (EJB Tier and WebTier)
See ScreenCast

NetBeans 5.5 : Creating the Entity Class
See ScreenCast

NetBeans 5.5 : Creating the Session Façade for Entity Class
See ScreenCast

NetBeans 5.5 - Testing our First Deployment on Sun Java Systema Application Server 9
ScreenCast

NetBeans 5.5 : Creating Java Server Pages for Listing
See ScreenCast

NetBeans 5.5 : Creating the BackingBean to invoke SLSB Façade and listing Data on JSP Page
See ScreenCast

Part II - Editing and JSF related Issues

NetBeans 5.5 : Creating Form for Edit Manufacturer
See ScreenCast

NetBeans 5.5 : We will show you how to add relationship funcionality using NetBeans, JSF, JPA and EJB.

I hope you can enjoy it, and I would like to say thanks to my friend Leandro, your laptop was really useful, because there's not a FREE software as Wink for MacOS =), but I am trying ViewletBuilder and others.



NetBeans Plugin: Janino Plugin

Posted by edgars on August 14, 2006 at 06:58 AM | Permalink | Comments (0)

A famous friend of mine Bruno , is leading a development here at Summa Technologies do Brasil.
He asked to me how easy or hard would be create a new Editor special for Janino in NetBeans, this editor should have sintax highlight, code-completion and so on, cause his team was in troubles to edit and to turn it fast and easy to edit.
After a couple of minutes and a good answer on NB-DEV-LIST EVERYTHING is ready to use.

Now my friends at Summa are happy with opportunity of to edit and create with a real productivity for Janino files using NetBeans.

If you want donwload it click here The following images shows Janino in action:

1

2

Hope this can be useful for anybody else.

Usign NetBeans Diff Module

Posted by edgars on August 03, 2006 at 12:51 PM | Permalink | Comments (0)

I am doing some related issues with Diff Module in Greenbox NetBeans Plugin.

Basically, when user generates a code by second time, the NetBeans will ask to him "Hey you did some changes in original file, would you like to see the diff between old file and new file you are generating?", If User presse "yes" button, The Diff module will appear to user.

To invoke the Diff Panel on NetBeans you can use something similar to following source code:

  DiffVisualizer diff = (DiffVisualizer) Lookup.getDefault().lookup(DiffVisualizer.class);
    DiffProvider dprov = (DiffProvider) Lookup.getDefault().lookup(DiffProvider.class);
    StreamSource src = (StreamSource) Lookup.getDefault().lookup(StreamSource.class);  
    DiffPresenter v = (DiffPresenter) Lookup.getDefault().lookup(DiffPresenter.class);
class MyInfo extends DiffPresenter.Info {
   private Difference[] differences; 
    
public MyInfo(String name1, String name2, String title1, String title2,
              String mimeType, boolean chooseProviders, boolean chooseVisualizers) {
    super(name1,name2,title1,title2,mimeType,chooseProviders,chooseVisualizers);
  }
  public void setDifferences(Difference[] adiff) {
     differences = adiff;
  }

  public Difference[] getDifferences() {
      return differences;
  }

  public Difference[] getInitialDifferences() {
      return differences;
  }

  public  Reader createFirstReader() throws FileNotFoundException {
    Reader f = new FileReader("/Users/edgarsilva/summa/dev/GreenboxBaseProject/web/WEB-INF/spring-context.xml");
    return f;
  }
  
  public  Reader createSecondReader() throws FileNotFoundException{
   
      
      String springContext = new String("");
      try {        
              springContext= ClassGeneratorBase.getInstance().generateSourceByTemplateName(getClasse(),"springContext",initializeGreenboxContextAndVariables(),"/templates");
      } catch (Exception e ) {
         e.printStackTrace();
      }
      
      return new StringReader(springContext); 
  }
    
    }
    
      MyInfo i = new MyInfo("old","new","old","new","text/xml",true,true);
        try {
            
            s1 =  new FileReader("/Users/edgarsilva/summa/dev/GreenboxBaseProject/web/WEB-INF/spring-context.xml");
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
            String springContext = new String("");
            try {        
                    springContext= ClassGeneratorBase.getInstance().generateSourceByTemplateName(getClasse(),"springContext",initializeGreenboxContextAndVariables(),"/templates");
            } catch (Exception e ) {
               e.printStackTrace();
            }
      
      s2 = new StringReader(springContext); 
    
 try {
    v = new DiffPresenter(i);
    
    v.setProvider(dprov);
    v.setVisualizer(diff);
    diffPanel.add(v,BorderLayout.CENTER);
      
 }catch (Exception e) {
    NbUtils.showMessage(e.getMessage());
 }

The main point, you should pay atention is the fact to extend the class DiffPresenter.Info , in order to allow it works correctlly.

Any different tip will be appreciated in the comments section.

The Following Image shows the results of this testing code:
diff

cya

Ajax Java Slides

Posted by edgars on June 13, 2006 at 02:29 PM | Permalink | Comments (0)

Dave Johnson - eBusiness Applications' CTO, just posted his slides for the AJAX + Java Webinar and some screencasts showing how to use DWR with NetBeans over the weekend and I will be presenting that along with a few slides about AJAX + Java on a webcast over at developer.com. Check out the link there for all the details.

Congratulations Dave!

Edgar





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds