Hi Friends,

NetBeans is promoting NetBeans Community Awards here:

http://www.netbeans.org/community/articles/javaone/2006/community-awards.html

Is really great to be included to this team,  these dudes I believe really deserve a recognizement like this.

One of my votes will go to David Strupl :) He looks like one great friend from Brazil Einar Saukas :), besides he did a lot of great things inside NetBeans.

I don't know why Cláudio Miranda, was not in this list, he is one very active community member, and due to his influence a couple of years a go, I am a Netbeans user.

Cláudio, I am sharing this indication with you! Say Hello to your family: Eliane(his wife), Rafael, Murilo and the youngest Renato :)

See you at JavaOne 2006!


Now using Greenbox for Netbeans, you can create a web project with support to Spring, Hibernate and Java Server Faces, with all required libraries to run it.
Check it on the following images:


Image 1 - First step to create a new greenbox project



Image 2 - Final step when you are creating a Greenbox WebProject

Now, I can show you a preview of Greenbox Modules inside NetBeans, We call this module "GAP"(it is not a chothe's trade mark =) ), - Greenbox Annotations Processor .

1 - First Step, you should use Annotations in Greenbox, such as the following image:



2- Second Step  is simple, just pick which element you wanna create and ok, Greenbox will create all elements for you!



In the following links you can see the images above better:

Take a look how easy are Greenbox Annotations! Basically we have only two Annotation's elements:
  • Greenbox
  • GreenboxField
You will get one simple pojo, and will add annotation for java class, and its attributes (fields). Based on this simples pojo (DDD), we will generate all sources (Java, XML, Properties and more).

Take a look on Pojo Pessoa(Person), used for tests:

 1 package br.com.summatech.pessoa;
 2

 3 import<../../span__br.com.versatiliti.annotations.Dao.css;
 4
import<../../span__greenbox.Greenbox.css;
 5
import<../../span__greenbox.Greenbox.cssField;
 6

7
/**
 8 * Pojo for UseCase Pessoa
 9 * @author edgarsilva
10
*/
11 @Greenbox(tableName="PESSOA",
12         clientType="web",
13         frameworkCombination="jsf-spring-hibernate")
14 public class Pessoa {
15    
16     @GreenboxField(columnName="CODIGO",
17             label="Codigo da Pessoa",
18             primaryKey="yes",
19
             displaySize="10",
20
             maxSize="5",
21
             hint="Entre com o codigo da Pessoa")
22
     private Integer codigo;
23
24     @GreenboxField(columnName="NOME",
25             label="Nome",
26             displaySize="40",
27
             maxSize="50",
28
             hint="Entre com o nome da Pessoa",
29
             validationExpression="not-null")
30     private String nome;
31     @GreenboxField(columnName="EMAIL",
32
             label="E-Mail",
33             displaySize="60",
34             maxSize="200",
35             hint="Entre com o Email da Pessoa",
36             validationExpression="not-null")
37    
38
     private String email;
39
    
40
41
     /** Creates a new instance of Pessoa */
42     public Pessoa() {
43
     }
44    
45
    
46
    
47
}
48

Doc's Annotations:

Greenbox - Valid only for Classes
 Greenbox    
  tableName Represents which table this usecase will persist data

clientType
Defines if client is Web(JSF) or Desktop (Swing)

frameworkCombination
N/A (default: Spring+Hibernate+JSF)

GreenboxField - you can use only for Attributes (FIELDS) in the class
 GreenboxField    
   columnName Colum the column in the table
   primaryKey  Defines if is primary key attribute (OR/Mapping) default= "no
   displaySize  Display Size in TextField rendered by JSF ou JTextField

maxSize
Max size of characters inside Textfield

hint
Tooltip of this Field rendered as JTextField or by JSF

Any idea, or suggestion feel you free to send an email to edgarsilva  (la em) gmail.com

cya

Ok, now It is serious, in the past Greenbox was very particular framework, shared by some friends in Brazil, however we are much more serious, after my session approved in JavaOne, We are investing too much in to make this project such as a real serious and professional Project.

I did a lot of changes in Greenbox, allowing it work with different paths of templates, I added annotations support, and used a lot of sources produced by Fabiano Franz and Lucas Balensiefer.

Righ now greenbox is managed by Alexandre Gomes, and he did a good separation:
  • Greenbox Framework- Core Framework - greenbox<RELEASE>.jar
  • Greenbox Annotations - Core Annotations - greenbox-annotations<RELEASE>.jar
  • NetBeans GB Db IDE - NetBeans plugins running over NetBeans DB Modules to get informations such as Tables, Fields and genereates classes and its attributes.
  • NetBeans Greenbox Annotations Processor - Most professional development over Greenbox, this plugin allow you create very useful applications using Annotations to generate Spring, Hibernate, JSF Applications, and soon JSF+EJB 3.0, basically We will show this development in JavaOne 2006.
For Greenbox Framework, we are using Maven to manage and build the project.

I am writing this points in my blog to organize my ideas, and to share all work I've been doing last days.

We were evaluating JavaForge, due to Subversion project, but we are stabilishing our CVS again in Java.Net.

Hope you enjoy this project, and you can help it too, see https://greenbox.dev.java.net


                 
NetBeans Guys published my interview on NetBeans Home Page, Thanks guys!

If you want to check it out click here tor read this interview

Visit NetBeans Website

I am back and will publish soon new interesting entries.

cya
A Really simple tip for Maven2 users, the following portion inside your pom.xml file, and the mvn site command, can generate the PMD reports automatically for you:

<reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <format>html</format>
                    <linkXref>true</linkXref>
                    <sourceEncoding>utf-8</sourceEncoding>
                    <minimumTokens>100</minimumTokens>
                </configuration>
            </plugin>

        </plugins>
    </reporting>

Good Luck!

 I would like to user reporting from stat-cvs in Maven2, But I haven´t found how to do that, or to do this same approach for Subversion, I will continue looking for, If I found it, I will blot it!
This post will show you how to generate sources with greenbox without read informations from database or xmi files.

What you will Need?

  • greenbox2.0-snapshot.jar
  • velocity1.4.x,jar
  • velocity-deps.jar
Creating a basic Class which we will use a Metamodel instance, which we will fill by our own hands to show the work done by greenbox engine while behind the scenes, take a look on that class:

package greenboxsamples;

import ../../page/java.util.ArrayList.css;
import ../../page/net.java.dev.greenbox.base.Attribute.css;
import ../../page/net.java.dev.greenbox.base.Clazz.css;
import ../../page/net.java.dev.greenbox.base.GreenboxContext.css;
import ../../page/net.java.dev.greenbox.core.util.source.generator.base.ClassGeneratorBase.css;

/**
 * Greenbox Usage Samples-Kit
 * @author edgar
 */
public class SimpleVO {
   
    /** Creates a new instance of SimpleVO */
    public SimpleVO() {
    }
   
    public static void main(String args[]) {
       
        //create a new Clazz Instance, which represents a Metamodel
        Clazz classe = new Clazz();
       
       
        //Setting Package Name and Class Name
        classe.setPackageName("com.summatech.contact");
        classe.setClassName("Contact");
       
        //creating some fields attributes
       
       
        Attribute id = new Attribute();
        id.setName("id");
        id.setDataType("int");
        id.setAcessor("private");
               
       
        Attribute name = new Attribute();
        name.setName("name");
        name.setDataType("String");
        name.setAcessor("private");
       
       
        Attribute email = new Attribute();
        email.setName("email");
        email.setDataType("String");
        email.setAcessor("private");
       
        ArrayList attributes = new ArrayList();
       
        attributes.add(id);
        attributes.add(name);
        attributes.add(email);
       
        classe.setAttributes(attributes);
       
       
        GreenboxContext ctx = new GreenboxContext();
        ctx.declareVariable("classe",classe);
        ctx.declareVariable("atributos",classe.getAttributes());
        ctx.declareVariable("this","this");
        ctx.declareVariable("today",new java.util.Date().toString());
        try {
           
           
            System.out.println(
                   ClassGeneratorBase.getInstance().
                    generateSourceByTemplateName(classe,"pojo",ctx));
           
        } catch (Exception ex) {
            ex.printStackTrace();
        }
       
 
    }
   
}


Look that we did all declarations, and with the help from that following template file (pojo.vm) located into template folder in running path:

package  ${classe.packageName}.pojo;
 
import ../../page/java.io.Serializable.css;
 
/**
 * Classe de dominío do conceito ${classe.className}
 *
 * @version 1.0
 * @since ${today}
 * @author GreenBox Framework
 */
public class ${classe.className} implements Serializable {
 
    /**
     * Atributos
     */
#foreach( $atributo in $atributos )
    private ${atributo.dataType} ${atributo.name};
#end
 
    /**
     * Construtor em branco do Value Object / Data Transfer Object Pattern de ${classe.className}
     */
    public ${classe.className}() {
    } 
}



We had the following output:

init:
deps-jar:
Compiling 1 source file to /home/edgar/summa/projetos/netbeans/greenbox-samples/build/classes
Note: /home/edgar/summa/projetos/netbeans/greenbox-samples/src/greenboxsamples/SimpleVO.java
compile-single:
run-single:
package  com.summatech.contact.pojo;

import ../../page/java.io.Serializable.css;

/**
 * Classe de dominío do conceito Contact
 *
 * @version 1.0
 * @since Fri Jan 13 04:03:08 GMT 2006
 * @author GreenBox Framework
 */
public class Contact implements Serializable {

    /**
     * Atributos
     */
    private int id;
    private String name;
    private String email;

    /**
     * Construtor em branco do Value Object
     */
    public Contact() {
    }

}

BUILD SUCCESSFUL (total time: 2 seconds)



Summary


In that tutorial, we checked that the class GreenboxContext is useful to declare which variables will be visible for templates.

The templates are really simples velocity templates.

See you next time

Edgar Silva

Hi Folks...

My friend Claudio Miranda had published a great video teaching how you can create beans and add them to Pallete into NetBeans. Watch this video clicking here

Claudio, congratulations your blog at Java.Net is cool !
I've working at Greenbox 2.0, and I changed my building process from ANT to Maven2.x. In fact Apache ANT is fanstastic, but I can have some cool new features with Maven2.0, and I am so happy with how easy and simple is to work with Maven 2.
After created my Maven Project, using my simple new command line to do that . I was thinking with Me: "Would be goood to work with Maven 2 and NetBeans 5!", but I said to myself : "I think it is a dream, cause it is a real awesome way to work". But after few minutes and with Google helps, I got MavenIDE project, which is pretty good for JBuilder, Eclipse and IDEA, however it  is really incredible for NetBeans.
If you are a NetBeans 5 user, you should read this informations in how to get Maven 2 Support for NetBeans here .
The process to intall is easy, and you can get all related informations and a lot of screenshots and tips here :
http://docs.codehaus.org/display/MEVENIDE/MevenideNetbeans2.0
To install is really easy, you unzip the files , go to Tools/Update Center, select the "Install Manually Downloaded Modules (nbm. Files) . After select all nbms files unpacked from zip file, and click next until to finish intalling process.
Then you can go to menu File/Open and choose your Maven's project folder, and nothing else... You'll you see the magic! As you can see in the following image:

Click here to see this image better

NetBeans5+Maven2 : A Real productive and happy enviroment to produce real inteligent projects :)

 

If you wanna use Maven 2.x, this can be a useful tip

Creating a Maven Project Creator Command Line

I've been using Maven 2.x, and I am very happy with their new features, to install is really easy, you can get all informations on Maven Site , and I create a simple but usefeul command line to allow you create project easier.

After to configura your path and this command mvn --version is working fine, you can create your projects. Then if you are using Windows, you can create a file called createproject.bat , ant put the following text:

@ echo off
echo Maven - Create Projects
mvn archetype:create -DgroupId=%1 -DartifactId=%2
echo Project %2 Created sucessfully

Then, you can create in any folder a Maven Project, calling your new command line as the following example:

E:\java\maven2>createproject net.java.dev.greenbox greenbox2

See that %1 is your package, and %2 your project name.

Look the output result:

E:\java\maven2>createproject net.java.dev.greenbox greenbox2
Maven - Create Projects
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
in-1.0-alpha-3.jar
6K downloaded
[INFO] ----------------------------------------------------------------------------

.... and more

I hope it could be as useful for you as it is for me !  After execute this command, you'll can see a Maven2's project structure, to put you java sources files, in addition a pom.xml file, which will guide you to build really inteligent projects :)

On my NetBeans Plugins development stuff, I've been discovering a lot of nice things, some I must to read netbeans sources, other I can get some tips on NBDEV-LIST, which is useful sometimes,and the last instance I must to say thanks my friends Tim Boudreau and Charlie Hunt, for help me too.

So I would like to share some experiences, I did some nice things using Borland Primetime for JBuilder, and a couple of things using Eclipse, but now, I am trying to improve my development team doing it with generation code and a lot of collaboration and continuous integration. Now, is time to show some simple tricks.

Showing simple messages in NetBeans Platform

    public void showMessage(String str) {
        NotifyDescriptor.Message desc = new NotifyDescriptor.Message(str);
        DialogDisplayer.getDefault().notify( desc );
    }
This will show a simple message, I created a method to do this generic. Apologize me the method name if remind you Delphi but I loved Delphi in the past :)

Using Confirmation Messages

       NotifyDescriptor.Confirmation nd =
                        new NotifyDescriptor.Confirmation( 
                            getBundle( "MSG_ConfirmOpenWitConnection" ),
                            getBundle( "CTL_NotSignedConfirmation" ),
                            NotifyDescriptor.YES_NO_OPTION 
                        );
                    nd.setOptions( new Object[] {
                            NotifyDescriptor.YES_OPTION,
                            NotifyDescriptor.NO_OPTION } );
                    Object ret = DialogDisplayer.getDefault().notify( nd );
                    openTables = ret.equals (NotifyDescriptor.YES_OPTION);
The example above, you have to look on ret variable, which holds the boolean result, to do anything you want after this. The first parameter on Confirmation is "The Question message", after, the "Box Title", and ending with the buttons options.

Reading Bundles from TopCompoent Window

    private static String getBundle( String key ) {
        return NbBundle.getMessage
    ( REPLACEBYYOURTOPCOMPONENTCLASS.class, key );
    }  

Next time, I will put more tips and tricks to build very useful things in NB plugins development.

see you soon!
Edgar Silva (edgar (em) summa-tech.com )

Are you using Spring Framework, Hibernate and Java Server Faces together?????

And you are tired to manage and to write too much code... Take a look in that Greenbox Thinlet´s Version.

Click here to watch the video

Hi my friends...

Now I will show you how easy is to create a Window Component Plugin in NetBeans 5.0.

My first video received a lot of comments, the main comment was about the quality, I think it is better!

I would like to say thanks to William Lima (Versatiliti Technologies), for host my HTML file wich points to SWF file!

Click here to see!

Thanks for comments! See you
Edgar Silva - edgar (em) summa-tech.com

DAO Pattern Definition

Access to data varies depending on the source of the data. Access to persistent storage, such as to a database, varies greatly depending on the type of storage (relational databases, object-oriented databases, flat files, and so forth) and the vendor implementation.
Reference: Blue Prints

Introduction

When you are creating your application framework, you would like to persist your data using smart techniques, and I am not talking about Hibernate, JDO, OJB or anything else, however I can ask for you? Can your application support a storage system replacement without any problem? If your asnwer is NO, this text will be useful for you.

Define a Interface as foundation for DAOs

You can define a simple Interface, describing "WHAT" you would like to do, and not "HOW" to do. Getting this idea, we can to think in Interfaces usage. Take a look in the following code:
package br.org.soujava.framework.dao;
import ../../page/java.util.Collection.css;
/**
 *  @author Edgar Silva - [email protected]
 */
public interface IGenericDAO {
	public void save(Object object) throws DAOException;
	public void update(Object object) throws DAOException;
	public void remove(Object object) throws DAOException;
	public Object findByPrimaryKey(Object pk) throws DAOException;
	public Collection findAll() throws DAOException;
}

You can see that this interface can remind you the EJB EntityBeans model, if you are thinking it is correct! EntityBeans is a great idea, so We can continue using nice ideas(concepts) like that.
In fact, we are exposing that this interface says that It can save, update, remove or find results against Information storage.

We need a simple extension from java.lang.Exception called DAOException, which can be throwed by any method, its source can be as simple as in the following code section:

package br.org.soujava.jobs.framework.dao;
/**
 * @author Edgar Silva - [email protected]
 */
public class DAOException extends Exception {
   public DAOException(String message) {
      super(message);	
   }
 public DAOException(Throwable e) {
      super(e);	
   }
}

The Implementation

We talked previouslly about smart codes, so we need to create and use it automaticlly and easier! You can have two choices:
  • Create a DAOFactory class
  • Use Spring Framework

DAOFactory

This class will implement a couple of patterns,as such:
Singleton - We will use one and just one instance and
Factory Method - The method returns always an interface, but in execution it will return a concrete class as wich implements this interface, in this case IGenericDAO.
See the following code for DAOFactory:

import ../../page/java.io.IOException.css;
import ../../page/java.util.Properties.css;
/**
 * @author Edgar Silva
 *
 * Esta classe é reponsável em obter todos os DAOS para o Projeto, com base nos nomes
 * 

Implementa o Pattern : Singleton e AbstractFactory
* Para uso profissional, seria interessante ter uma HashMap com * os DAOS usados, para prover performance. */ public class DAOFactory { private static DAOFactory me = null; private Properties props = null; private DAOFactory() { try { props = new Properties(); props.load (DAOFactory.class.getResourceAsStream ("daos.properties")); } catch (IOException e) { e.printStackTrace(); } } public static DAOFactory getInstance() { if (null==me) { me = new DAOFactory(); } return me; } /** * Método que retorna o DAO, com base na chave de pesquisa do Arquivo de Properties daos.propeties,
* A Constante passada representa o DAO real que está registraod no arquivo.
* Poderia ser um arquivo XML. * @param name O nome da chave que representa a implementação real do DAO
* ex: getDAO(DAOFactory.DAO_CLIENTES); * Onde DAO_CLIENTES vale "clientes" * E no arquivo de props: * cliente=com.edgarsilva.framework.dao.jdo.ClienteJDOImpl * * */ public IGenericDAO getDAO(String name) { IGenericDAO retorno = null; try { retorno = (IGenericDAO) Class.forName (props.getProperty(name)).newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return retorno; } }

This code is very simple, I usually use it when I am providing Java training classes in Brazil

The DAOFactory is using a properties file to discover the real implementations for DAOs that will be requested by applications. like this following listing:

destino=br.gov.soujava.empregos.destino.impl.ojb.DestinoDAO
user=br.gov.soujava.empregos.usuario.dao.impl.ojb.ClienteDAO

You can create much better resource of reading, as such to auto-detect changes and update the properties in memory and other stuff.

Using Spring Framework

You can work with Dependency Injection, and you will use the context.xml used in all Spring Applications to describe this dependency.
Other nice Spring's feature is the ability to create DAOs implementations extends the HibernateDAOSupport class, which offer a lot of nice things to make your development easier.

This entry is to make you think that your applications can use dinamic configurations issues, and reduce the coupling between your layers, if you will use Spring or your own IoC framework, the most important is to use some useful DAO strategy as I this text is decribing.
Cya!