Česky   |  Deutsch   |  English   |  Español   |  Français   |  Indonesia   |  日本語   |  한글   |  Polski   |  Português (BR)   |  Türkçe   |  中文   |  正體中文   |  Your Language  
PlanetNetbeans
Planet NetBeans is an aggregation of NetBeans related musings from all over the Blogosphere.
Feeds
[RSS 1.0 Feed] [RSS 2.0 Feed]
[FOAF Subscriptions] [OPML Subscriptions]
Do you blog about NetBeans ? Add your blog to PlanetNetBeans.
Feed Subscriptions
NetBeans Zone - The social network for developers (feed)
APIDesign - Blogs (feed)
Pandaconstantin (feed)
blogtrader - Blog (feed)
David R. Heffelfinger (feed)
Carsten Zerbst's Weblog (feed)
Winston Prakash's Weblog (feed)
markiewb's blog (feed)
Gualtiero Testa » Netbeans (feed)
James Selvakumar's Blog » netbeans (feed)
nB gUru » NetBeans (feed)
Newsintegrator Blog » netbeans (feed)
Praxis LIVE » NetBeans (feed)
ProNetBeans (feed)
TechAshram » NetBeans (feed)
There's no place like 127.0.0.1 » Netbeans (feed)
Paulo Canedo » NetBeans English (feed)
Anchialas' Java Blog (feed)
Need to find a title (feed)
Roger Searjeant's blog (feed)
Optonline Webmail (feed)
Michael's blog » NetBeans (feed)
Allan Lykke Christensen » NetBeans (feed)
Inspiration and Expression » Netbeans (feed)
J. O'Conner » NetBeans (feed)
Adam Bien (feed)
Ignacio Sánchez Ginés » NetBeans (feed)
Bernhard's Weblog (feed)
Ramon.Ramos (feed)
Ozone and Programming » netbeans (feed)
NetBeans Ruminations » NetBeans (feed)
Tiplite » netbeans (feed)
Bistro! 2.0 (feed)
Arun Gupta, Miles to go ... (feed)
Geertjan's Blog (feed)
.JARa's Bilingual Weblog (feed)
JavaFX Composer (feed)
The Java Jungle (feed)
Jesse Glick (feed)
Martin Grebac (feed)
The NetBeans Community Podcast (feed)
NetBeans Profiler (feed)
NetBeans for PHP (feed)
NetBeans Web Client (feed)
Rechtacek's (feed)
Virtual Steve (feed)
My First Blog - Satyajit Tripathi (feed)
The Aquarium (feed)
Tinuola Awopetu (feed)
Insert Witty Irony Here (feed)
mkleint (feed)
Anuradha (feed)
Netbeans6/6.5 my best practices (feed)
Java Evangelist John Yeary's Blog (feed)
Neil's Dev Stuff (feed)
Computer says null; (feed)
NetBeans Adventures, Java and more (feed)
NetBeans Community Docs Blog (feed)
The Netbeans Experience (feed)
NbPython/ jpydbg / pymvs (feed)
Shanbag's Blog (ರಜತ ಲೋಕ) (feed)
Wade Chandler's Programming Blog (feed)
Devlin's Lab (feed)
Big Al's Blog (feed)
Code Snakes (feed)
In perfect (spherical) shape (feed)
Van Couvering Is Not a Verb (feed)
Diego Torres Milano's blog (feed)
Vroom Framework (feed)
Messages from mrhaki (feed)
Jeff's Blog (feed)
Manikantan's Netbeans (feed)
Oliver Wahlen's Blog (feed)
Shuttle between Galaxies (feed)
Welcome to my live... (feed)
Netbeans IDE Blog by Tushar Joshi, Nagpur (feed)
Devel Blog (feed)
diamond-powder (feed)
Antonio's blog (feed)
Where's my Blog?!

Powered by:    Planet

Last updated:
April 24, 2014 10:05 PM
All times are UTC

Sponsored by
sponsored by Oracle

visit NetBeans website
Geertjan's Blog - April 24, 2014 11:04 AM
Meaningful HTML/Java DukeScript Framework Applications (Part 2)

OK, so now the application I started working on is even more meaningful.

Firstly, what is it all about? Well, with the DukeScript Framework, you use Java to write application logic, with HTML5 to render the UI. No Swing. No JavaFX. HTML takes the place of those toolkits. Then you can manipulate the HTML page from Java, use REST or WebSockets, and do anything else with Java that you might want to do.

So here's the state of my CRUD app right now, i.e., still only R, but with improved code (thanks Jarda), and now the selected customer is displayed when a row is selected. 

Let's start by looking at the HTML file that defines the above.

<html>
    <body>
        <h1>Sample Database</h1>
        <table border="1">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>City</th>
                    <th>State</th>
                    <th>Mail</th>
                </tr>
            </thead>
            <tbody data-bind="foreach: customers">
                <tr data-bind="click: $root.selectCustomer" style="cursor: pointer">
                    <td data-bind="text: name"></td>
                    <td data-bind="text: city"></td>
                    <td data-bind="text: state"></td>
                    <td data-bind="text: email"></td>
                </tr>
            </tbody>
        </table>
        <br/>
        <b>Current Selection</b>
        <p data-bind="with: selectedCustomer">
            <font color="red">Name</font>: <span data-bind="text: name"> </span>
            <br/>
            <font color="red">City</font>: <span data-bind="text: city"> </span>
        </p>
    </body>
</html>

What you see here is plain HTML together with Knockout bindings. The rows in the table are bound to properties in the model. When a row is selected, a method in the model is called that changes a property, which is bound with the Knockout "with" binding so that the currently selected name and city are shown.

Here's the definition of the Main class, which is annotated with the @Model annotation, and can be understood as a singleton:

@Model(className = "CrudApp", properties = {
    @Property(name = "selectedCustomer", type = CustomerData.class),
})
public final class Main {
    @ComputedProperty
    static java.util.List<CustomerData> customers() {
        EntityManager entityManager
                = Persistence.createEntityManagerFactory("myPU").
                createEntityManager();
        Query query = entityManager.createNamedQuery("Customer.findAll");
        List<CustomerData> arr = new ArrayList<>();
        for (Object object : query.getResultList()) {
            arr.add(((Customer) object).getData());
        }
        return arr;
    }
    @Function
    static void selectCustomer(CrudApp myModel, CustomerData data) {
        myModel.setSelectedCustomer(data);
    }
    private Main() {
    }
    /**
     * Launches the browser
     */
    public static void main(String... args) throws Exception {
        BrowserBuilder.newBrowser().
                loadPage("pages/index.html").
                loadClass(Main.class).
                invoke("onPageLoad", args).
                showAndWait();
        System.exit(0);
    }
    /**
     * Called when page is ready
     */
    public static void onPageLoad(String... args) throws Exception {
        new CrudApp().applyBindings();
    }
}

There's also a Customer POJO, i.e., a JPA entity, which in addition to the JPA annotations is annotated as follows:

@Model(className = "CustomerData", properties = {
    @Property(name = "name", type = String.class),
    @Property(name = "addressline1", type = String.class),
    @Property(name = "addressline2", type = String.class),
    @Property(name = "city", type = String.class),
    @Property(name = "state", type = String.class),
    @Property(name = "phone", type = String.class),
    @Property(name = "fax", type = String.class),
    @Property(name = "email", type = String.class),
    @Property(name = "creditLimit", type = int.class)
})

Plus, there's a getter that returns the CustomerData, so that the "customers()" method in the Main class can build up the list of customers.

The next step is to persist the data back into the database. Weird to be manipulating the DOM from Java but, obviously, great. 

Adam Bien - April 24, 2014 02:44 AM
Golden Times For Java Devs -- Interview with WJUG (Warszawa Java User Group)

Adam Bien: When the Warsaw JUG (http://warszawa.jug.pl) was founded? What was the very first meeting?

We had our first meeting in November 2006 with a talk about Apache Geronimo given by WJUG founder - Jacek Laskowski. However Warsaw Java User Group roots go even deeper, all the way back to the Polish BEA User Group.

Adam Bien: What makes WJUG "cool"?

Fellow developers you can talk to, ask questions and learn from. Big community which will help you find an answer, job, or something interesting to do. And above all a place where you can discover interesting technologies, share knowledge and learn best practices for free in a friendly group.

Adam Bien: How you would describe the climate for Java developers in Poland? Is there any demand for Java / Java EE developers on the market?

There’s much more work than people. The community is also strong and supportive. These are golden times for Java devs. It is not only easy to find a good job but also thanks to many international (GeeCON, 33rd Degree, Java Developers Days) and national (Confitura, Warsjawa) conferences, we can share our experiences and learn from the best.

Adam Bien: What are the goals of the WJUG?

Share knowledge and have fun! We also want to spread the word about software craftsmanship and good practices that we find important in our everyday work and hobby.

Adam Bien: After my session we met in a nice bar. The developers were extremely motivated and were constantly searching for new challenges, so we kept talking Javanese. Can you meet the member's expectations with a JUG?

We hope so. We are completely open, twice a year we have a meeting where anyone can join organizers, we have dedicated meetings for Spring/Groovy/JBoss users, we have special set of meetings for people new to Java and technologies around it, we have two big, and completely free conferences every year, we have one-day workshops… There is a lot going on, so I suppose we have something for everyone. Although we are still looking for new ideas and we like to find inspirations outside - this year we are organizing Devoxx4Kids for the first time.

Adam Bien: Would you appreciate more support from Oracle (the Java stuart)? If yes, what do you like to see?

We are doing fine on our own, so we don’t have any needs we can’t handle, but definitely, some love from Oracle would be welcome. Not sure about the details though. Java gadgets are always handy. And speakers. We’d love to have someone from Oracle at our regular meetings once in a while.

Adam Bien: Are you planning to participate in any open source projects / JCP activities?

Last month we had OpenJDK hackathon and we are planning OpenJDK test fest or two in a near future. As for the active participation in the JCP programme we haven't decided yet - there`s so much to be done there and so little time, maybe focusing on contributions to open source projects and libraries is the way to go. We have lots of individual contributors to the well known JVM frameworks and libraries and we encourage other WJUG members to join them and try to impact and improve open source projects as a group, not just as a bunch of individual contributors.Last but not least we will have an open-source brag in June, where anyone will have a chance to present his open source project.

Adam Bien: How many members the WJUG has? Are you happy with the participation. What could be improved?

It is hard to say exactly how many members we have. Our regular meetings gather usually from 50 to 200 people, conferences go over 1k. Our online discussions are subscribed by over 800 people and on our meetup there are over 600 people registered. Still not the numbers are important, but the quality of the meetings. We are constantly looking for interesting subjects, new speakers and ways for more effective networking. Together with our subgroups (Spring-Labs, Groovy User Group, Jboss User Group, etc.) we have practically 2 meetings per week.

Adam Bien: How the readers of this post could support your JUG?

Come over to our meetings, learn something interesting and share your knowledge by giving a talk. It’s simple.

Adam Bien: Thank you for the interview!
Real World Java EE Workshops [Airport Munich]>

Gualtiero Testa » Netbeans - April 23, 2014 07:51 PM
NetBeans User Guide in pdf, epub and mobi formats

NetBeans 8.0 User Guide is now available in ebook format: PDF, Mobi and EPub in addition to the traditional multi-page html files.

Available at Oracle Docs website.

Enjoy reading.


Filed under: Netbeans Tagged: documentation, epub, mobi, netbeans, oracle, pdf, user guide

NetBeans Zone - The social network for developers - April 23, 2014 03:07 PM
NetBeans Weekly News (Issue #636 - Apr 22, 2014)

Project News Join Free Virtual Developer Day Virtual Developer Day: Java 2014 - May 6th (Americas), May 14th (EMEA) and May 21st (APAC). Hear from experts in Java SE 8, Java EE 7 and Java Embedded. Watch tutorials including NetBeans from the experts to improve your expertise in Java, and ask questions during live chats. Preview Text:  In this...

Adam Bien - April 23, 2014 07:40 AM
javaee7-essentials-archetype v1.2 released

The version 1.2 of the javaee7-essentials-archetype was released.

Features:

  1. Java 8 is the default compiler source and target
  2. The name of the war is derived from the artifactId. The version is no more appended.

Create a project directly from the IDE (in NetBeans: New Project -> Maven -> Project From Archetype. Choose com.airhacks as groupId in the search box).

Or use the CLI:


mvn archetype:generate -Dfilter=com.airhacks:javaee7-essentials-archetype

The archetype's source is available at: https://github.com/AdamBien/javaee7-essentials-archetype. The project can be also directly cloned from: https://github.com/AdamBien/javaee-essentials-pom

Enjoy the lean way of coding! :-)

See you at Java EE Workshops at MUC Airport!


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - April 23, 2014 07:02 AM
Register Today for Virtual Developer Day!

Virtual Developer Day: Java 2014 is on May 6th (Americas), May 14th (EMEA), and May 21st (APAC).

Hear from experts on Java SE 8, Java EE 7, and Java Embedded.

Watch tutorials from the experts to improve your expertise in Java, and ask questions during live chats. This FREE virtual event will cover:

  • Java SE 8 New Features: Lambdas and more
  • The latest on the Java EE 7
  • How Java makes it easy for you to control a wide range of embedded devices

Go here to register.

Geertjan's Blog - April 22, 2014 02:03 PM
Meaningful HTML/Java DukeScript Framework Applications (Part 1)

In an effort to make a meaningful application on the DukeScript Framework, here's the start of a JPA-based CRUD app (right now, only R is supported):

There are three parts to this.

  1. Model. I generated JPA entity classes from my database. I ended up with the "Customer" class, which has relationships with "DiscountCode" and "MicroMarket". Then I added a new annotation, on top of all the JPA annotations, to the "Customer" class:
    @Model(className = "CustomerData", properties = {})

    Then, in the same class, i.e., in "Customer", I exposed the data as follows:

    @ComputedProperty
    static java.util.List customers() {
        EntityManager entityManager
                = Persistence.createEntityManagerFactory("myPU").
                createEntityManager();
        Query query = entityManager.createNamedQuery("Customer.findAll");
        return query.getResultList();
    }
  2. Controler. In the Main class, I changed "onPageLoad" to this:
    public static void onPageLoad(String... args) throws Exception {
        new CustomerData().applyBindings();
    }
  3. View. Finally, the "index.html" that is bound to the model is as follows:
    <html>
        <body>
            <h1>Sample Database</h1>
            <table border="1">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>City</th>
                        <th>State</th>
                        <th>Mail</th>
                    </tr>
                </thead>
                <tbody data-bind="foreach: customers">
                    <tr>
                        <td data-bind="text: $data.getName()"></td>
                        <td data-bind="text: $data.getCity()"></td>
                        <td data-bind="text: $data.getState()"></td>
                        <td data-bind="text: $data.getEmail()"></td>
                    </tr>
                </tbody>
            </table>
            <p>
        </body>
    </html>

Notice that the method "customers()" in the model is bound in the "foreach" in the view.

Probably I'm doing all kinds of things wrong. Probably I should be using properties in the model. Happy to be corrected. 

NetBeans Zone - The social network for developers - April 22, 2014 10:13 AM
Enrico Scantamburlo: My Five Favorite NetBeans IDE Features!

Following on from Ciprian Turcu, Mark Stephens, Josh June Preview Text:  Learn NetBeans tips and tricks from Enrico Scantamburlo as he introduces you to his favorite NetBeans features. Legacy Sponsored:  unsponsored

Geertjan's Blog - April 21, 2014 05:13 PM
Entity Expander for NetBeans IDE 8 (Part 5)

Now package-level expansion is supported:


When you select a template while on a package, as above, all Java classes within the package are all transformed at the same time, for example, choosing "Panel" above results in the below all being added in one go:

Go here to get it:

http://plugins.netbeans.org/plugin/53874

Geertjan's Blog - April 20, 2014 10:37 AM
Themes for NetBeans JPA Modeler

The latest release, which came out today, of the awesome JPA Modeler plugin for NetBeans (by Gaurav Gupta) provides a theme switcher. Click to enlarge the image below.

Not one line of code in the many classes you see above was created by me. Instead, they were all generated from the diagram, which was generated from my database.

Get it here:

http://plugins.netbeans.org/plugin/53057/jpa-modeler

Geertjan's Blog - April 19, 2014 02:15 PM
Entity Expander for NetBeans IDE 8 (Part 4)

Toni suggested it would be cool to create some templates for Nodes, ChildFactories, and TopComponents, on top of POJOs, for the Entity Expander that I blogged about last month

That way, NetBeans would have the start of something like EMF in Eclipse.

So, here are the templates I have so far.

Node ("BeanNode"):

package ${package};

import java.beans.IntrospectionException;
import java.util.List;
import javax.swing.Action;
import org.openide.nodes.BeanNode;
import org.openide.util.Utilities;

public class ${object}BeanNode extends BeanNode {
    
    public ${object}BeanNode(${object} bean) throws IntrospectionException {
        super(bean);
        //setDisplayName();
        //setShortDescription();
    }

    @Override
    public Action[] getActions(boolean context) {
        List myActions = 
            Utilities.actionsForPath("Actions/${object}");
        return myActions.toArray(new Action[myActions.size()]);
    }

}

Child Factory ("BeanChildFactory"):

package ${package};

import java.beans.IntrospectionException;
import java.util.List;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;

public class ${object}BeanChildFactory extends ChildFactory<${object}> {
    
    @Override
    protected boolean createKeys(List<${object}> toPopulate) {
        //connect to data source
        //and populate "toPopulate" list
        return true;
    }
    
    @Override
    protected Node createNodeForKey(${object} key) {
        ${object}BeanNode cbn = null;
        try {
            cbn = new ${object}BeanNode(key);
        } catch (IntrospectionException ex) {
            Exceptions.printStackTrace(ex);
        }
        return cbn;
    }
    
}

TopComponent ("ViewerTopComponent"):

package ${package};

import java.awt.BorderLayout;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

@TopComponent.Description(
        preferredID = "${object}ViewerTopComponent",
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(
        mode = "explorer", 
        openAtStartup = true)
@ActionID(category = "Window", 
        id = "${package}.${object}ViewerTopComponent")
@ActionReference(
        path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_${object}ViewerAction",
        preferredID = "${object}ViewerTopComponent"
)
@Messages({
    "CTL_${object}ViewerAction=${object}Viewer",
    "CTL_${object}ViewerTopComponent=${object}Viewer Window",
    "HINT_${object}ViewerTopComponent=This is a ${object}Viewer window"
})
public class ${object}ViewerTopComponent extends TopComponent implements ExplorerManager.Provider {
    
    private ExplorerManager em = new ExplorerManager();

    public ${object}ViewerTopComponent() {
        setName(Bundle.CTL_${object}ViewerTopComponent());
        setToolTipText(Bundle.HINT_${object}ViewerTopComponent());
        setLayout(new BorderLayout());
        //somehow create your children:
        //Children.create(new MyChildFactory(), true);
        Node rootNode = new AbstractNode(Children.LEAF);
        em.setRootContext(rootNode);
    }

    @Override
    public ExplorerManager getExplorerManager() {
        return em;
    }

}

Java Evangelist John Yeary's Blog - April 19, 2014 01:56 AM
JSF 2.2 Tip of the Day: Naughty Expression Language (EL)

Unexpected Effects

Many of you may know this already, but I was reminded the other day how this can catch even some of the most brilliant JSF developers. When you comment out a component in your xhtml page that has EL bindings, you may not be REALLY disabling it.
Expression Language (EL) is parsed and evaluated as the page is being rendered. As a result, any exposed EL syntax will be processed including functions which could have deleterious effects. For example, take a look at the following code, and guess what it will do.

So what happens?

Scary things happen....
  1. It executes
  2. Parser exception. The parser will try to find a property called doSomething
  3. It will execute, please note that there is no <h:form/>. It is not required since we are evaluating the EL.
  4. Parser exception. The parser will try to find a property called doSomethingElse

Sensei what do I do?

You have a couple of options. The first option is the easiest, and it is likely what you want anyway with your JSF pages. You can disable the comments. No need to transmit your development comments to the end users anyway. The second option is to add a - between the # and the { like this #-{indexBean.doSomethingElse()}.
The first option is handled by adding a configuration parameter to the web.xmlfile as shown below. Here is a more complete example: The result of the code is as follows:

The complete code example was developed using NetBeans 8.0 and GlassFish 4.0 on JDK 8. The code can be found here: auto-execute-el

markiewb's blog - April 18, 2014 12:13 PM
Some impressions from the NetBeans platform training in Leipzig

IMG_20140416_122649 IMG_20140416_132247 IMG_20140416_132257 IMG_20140416_132309

Benno Geertjan Reinhard Toni

1497868_600161820078985_7538296825980308817_o

IMG_20140417_125241


Geertjan's Blog - April 18, 2014 08:51 AM
org.netbeans.spi.palette.PaletteItemRegistration

With APIs from NetBeans IDE 8.0, there's the new annotations @PaletteItemRegistration and @PaletteItemRegistrations for registering items in a palette:

As you can see, you use the annotations in the package-info.java class, which you can create by using the template Java | Java Package Info in the New File dialog.

References:

http://bits.netbeans.org/dev/javadoc/org-netbeans-spi-palette/org/netbeans/spi/palette/PaletteItemRegistrations.html

http://bits.netbeans.org/dev/javadoc/org-netbeans-spi-palette/org/netbeans/spi/palette/PaletteItemRegistration.html

Therefore, will need to update this tutorial with the new annotations:

https://platform.netbeans.org/tutorials/nbm-palette-api1.html

Adam Bien - April 18, 2014 07:53 AM
Java 8, Method Handles and Concurrency Utilities For Java EE

Java 8 with method handles enables direct execution of synchronous (legacy) code asynchronously within a managed thread pool:

Prepare your questions—I will attempt to answer them…live. See you soon!

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

See you at Java EE Workshops at MUC Airport!


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - April 17, 2014 07:41 PM
Three Tips for DukeScript Fanboys

Here's my advice for DukeScript fanboys, of which there are some, but mainly two: Jaroslav Tulach and Toni Epple.

  1. Stop talking about "DukeScript". Whenever you say "DukeScript", any sane person assumes you're talking about a language. You're not. And that's what's confusing. You're talking about a framework. The DukeScript Framework is equivalent to HTML5 minus JavaScript plus Java. That's it. And that's a powerful message.

  2. Stop playing games. Instead, create real applications. Create CRUD applications, for example. Here's my humble first beginning, showing data from the Sample database in GlassFish displayed in HTML via Java in the JavaFX WebView thanks to the DukeScript Framework:

    But, please, make several complete scenarios that run out of the box, including, and especially, CRUD apps. This is where Vaadin and PrimeFaces have succeeded so far, i.e., they have complete widget samples, component demos, etc, etc, etc. Focus on business scenarios, not funny games.

  3. Seriously, sit down and think about all that stuff that you're exposing. Vaadin somehow gets away with it, because they're based on a known entity, i.e., GWT, and the DukeScript Framework should be able to do so, too. There's just so much going on in the background, it's scary. Somehow, you need to at least explain absolutely everything. Either shit or get off the pot, i.e., describe fully what's going on in the implementation or accept that it's going to be adopted by a small subset of developers. Since all the ideas in the DukeScript Framework are so completely brand new and so much magic is done via annotations, you either explain it all, down to the smallest details, or run the risk that no one will adopt it because, since there are several more understandable competitors, you're running the risk that something simpler, e.g., Vaadin, is going to become the standard, whether de-facto or not.
My two cents. And I have never been (very) wrong.

NetBeans Zone - The social network for developers - April 17, 2014 05:33 AM
Vaadin and NetBeans: Transporting Desktop Users to the Web

Bruno Freitas lives and works in Porto, Portugal, at BMAC, a private healthcare company. He is a software engineer building internal applications, while handling integration requirements with 3rd party software. As needed, he also manages Linux servers, databases, and network systems. Preview Text:  Bruno Freitas describes how NetBeans IDE and...

Geertjan's Blog - April 16, 2014 10:14 PM
Swedish Economy Modeling on the NetBeans Platform

WamSys AB, located in Gothenburg, Sweden, focuses on developing products with Oracle DB and the NetBeans Platform.

In particular, the NetBeans Platform is used as the basis of their Mozart Platform, which provides generic modules for custom Swing components, including a table component with support for grouping, "frozen" rows and columns, and built-in aggregates.

Furthermore, the Mozart Platform facilitates the building of products on top of it. For example, it has its own widget framework, providing a customizable start page comparable to a web portal, while the Options window manages look & feel properties, such as support for switching to the JTattoo look and feel.

Here you can see a YouTube clip of the Mozart table component:

https://www.youtube.com/watch?v=KTm6IrsTzDM

And here is a YouTube clip of the Mozart dashboard:

https://www.youtube.com/watch?v=o6nn4ns52t8

One of the products based on the Mozart Platform is Mozart Economy, a fully customizable billing system able to calculate fees based on complex conditions and provide data for invoicing. The system is used by Swedish schools for calculation of fees paid in preschool, where many different factors affect the price, such as the child's age, family income, and number of hours at school. The module corrects invoices over any period back in time with respect to changed conditions over time.

Another part of the solution is Mozart Statistics, which retrieves data from a database and creates statistical reports in Microsoft Excel, using the Apache POI library.  This enables customers to get powerful statistical reports with pivot tables and various type of charts.


NetBeans Zone - The social network for developers - April 15, 2014 09:09 PM
NetBeans Weekly News (Issue #635 - Apr 14, 2014)

Project News Plugin: Scala for NetBeans Caoyuan Deng has upgraded the Scala plugin for NetBeans 8! Get started with it today. Python in NetBeans IDE 8.0 Build Python projects in NetBeans 8 using the NetBeans-Python plugin. Preview Text:  In this issue: Working with Scala and Python in NetBeans 8.0; Using PrimeFaces' layout component; a...

Geertjan's Blog - April 15, 2014 06:08 PM
DukeScript Framework for Dummies

Jaroslav Tulach's Java/JavaScript framework DukeScript explained for dummies (e.g., me):

Or watch it here:

https://www.youtube.com/watch?v=v3ITo889ypI

Further info:

http://wiki.apidesign.org/wiki/DukeScript

http://www.slideshare.net/steveonjava/dukescript

http://nighthacking.com/dukescript-with-toni-epple/

APIDesign - Blogs - April 15, 2014 12:35 PM
Coolest NetBeans Plugin: MineSweeper!

MineSweeper is re-implementation of classical computer game available on each Microsoft Windows since the initial introduction in version 3.1. Surprisingly my kids (who otherwise spend hours with tablets) knew nothing about the game until...

I needed a demonstration for DukeScript technology that is using Java to code the application logic and HTML to render its UI. I decided to write a MineSweeper game as a basic demo. I've managed to execute the demo in a browser (via TeaVM) and Android (via DlvkBrwsr), but today I achieved another milestone: the MineSweeper module is available for every user of NetBeans 8.0!

Get the module via Tools/Plugins or visit its plugin page and enjoy your productivity boost!

In case you are interested in trying the code yourself, here is a way to get the sources:

$ hg clone http://source.apidesign.org/html~demo/
$ cd html~demo/
$ hg up -C 3d99b96ffbd4
$ mvn install
$ cd minesweeper/
$ mvn -Pnbrwsr install
# generates target/minesweeper-1.0-SNAPSHOT.nbm

and the system generates an NBM (NetBeans module file) which can be installed into your NetBeans! Give it a try and let's make NetBeans better by using more DukeScript APIs! Don't forget that you can package the same application to run on Android or in a browser. Become a developer that can: Write once, run anywhere!

--JaroslavTulach 12:35, 15 April 2014 (UTC)

Adam Bien - April 15, 2014 08:37 AM
Java 8: Reducing a List Into A CSV String


import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.junit.Test;

public class CSVStreamTest {

    @Test
    public void listToString() {
        List<String> mascots = new ArrayList<>();
        mascots.add("duke");
        mascots.add("juggy");

        String expected = "duke,juggy";
        String actual = mascots.stream().
                reduce((t, u) -> t + "," + u).
                get();
        assertThat(actual, is(expected));
    }
}

See you at Java EE Workshops at MUC Airport!


Real World Java EE Workshops [Airport Munich]>

Michael's blog » NetBeans - April 14, 2014 09:24 PM
Using Lambda expressions with JSF 2.2

JSF 2.2 comes in conjunction with EL 3.0. This version of the expression language offers a rarely known highlight: It is capable of using lambda expressions and streams. Even thought defined withing the Jave EE 7 spec (and not Java … Continue reading

Adam Bien - April 14, 2014 11:48 AM
How To Tackle JavaEE - DevCrowd Keynote

How to structure a JavaEE application? How to organize your code? What are the essential ingredients of a maintainable JavaEE application? How to be productive with JavaEE?

I discussed such questions during the DevCrowd keynote: http://2014.devcrowd.pl/agenda/.

Warning: I used slides in the first part of the keynote :-).

Any questions left? Prepare your questions and I will attempt to answer them …live. Drop a comment / question && see you at each first Monday of the month at 6 p.m (CET) [http://www.ustream.tv/channel/adambien]!

See you at Java EE Workshops at MUC Airport, particularly at the Java EE Architectures workshop, screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.!


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - April 11, 2014 08:14 AM
Python in NetBeans IDE 8.0

Copy this to the clipboard:

http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/nbms/updates.xml.gz

Then go to Tools | Plugins and open the Settings tab. Add the above as a new update center:

Then switch to the Available Plugins tab and you'll see the Python plugin:

Install the Python plugin:

Then create a new Python project, using the New Project dialog:

Give it a name and choose your platform. Either import existing sources as a new Python project...

...or create a Python project from scratch:

Then you have an editor with code completion, other editor features, plus a debugger:

Right-click a project to see a bunch of Python commands:

Add to the classpath after right-clicking a project and choosing Properties:

That's it, you're now ready to use Python in NetBeans IDE.

Geertjan's Blog - April 10, 2014 07:00 AM
Context-Sensitive TopComponent (Part 2)

Another way a TopComponent can be context sensitive is in the requirement that the menubar and toolbar need to relate to a specific TopComponent. Below you see that when Win1 is active, a different group of menus and toolbars is available...

... than when Win2 is active:


Part of the solution to this is described here recently about multiple rows of toolbars. However, this only addresses the topic of toolbars. What about menubars? And maybe other components too? I.e., when a TopComponent is active, it would be great if a subfolder of the FileSystem would become enabled, while all other parts would become disabled.

The complete solution to this scenario has been described before, here. Jesse Glick has all the code for this here:

https://bitbucket.org/jglick/dynamicmenudemo

What the above lets you do is create layer entries like this:

<folder name="win1">
    <folder name="Menu">
        <folder name="First">
            <attr name="position" intvalue="150"/>
        </folder>
        <file name="Help.hidden"/>
    </folder>
    <folder name="Toolbars">
        <file name="UndoRedo.hidden"/>
    </folder>
</folder>
<folder name="win2">
    <folder name="Menu">
        <folder name="Second">
            <attr name="position" intvalue="250"/>
        </folder>
    </folder>
</folder>

Then, each TopComponent can specify which folder they want to own:

associateLookup(Lookups.singleton(new SystemSubPathLayerProvider("win1")));

The "SystemSubPathLayerProvider" does all the work in the background to enable and disable items appropriately, whether they are toolbars, menubars, or whatever else.

Nothing is written to disk, this is all done programmatically within the code, and not written to the user directory.

Geertjan's Blog - April 09, 2014 07:00 AM
Context-Sensitive TopComponent (Part 1)

I picked up a cool idea from a Polish developer, Dominik Cebula, recently. In the same way that the NetBeans Platform has context sensitive Actions, there should be context sensitive TopComponents.

Only if an Object of a specific type specified in the public constructor of the TopComponent is found in the Lookup should it be possible to open the TopComponent. And then the Object is available to the TopComponent, without the TopComponent needing to implement a LookupListener.

For example, below "FlightLeg Editor" and "Delay Editor" are both disabled, because no "FlightLeg" and no "Delay" is in the Lookup. Hence it doesn't make sense to open the editor, i.e., when the Object for which the editor exists is not available.


On the other hand, below a "FlightLeg" is available in the Lookup, because one of the flight legs has been selected and hence the underlying "FlightLeg" object is now in the Lookup. Therefore, the "FlightLeg Editor" menu item is enabled so that an editor can be opened for editing the selected flight leg:


In the same way, here the "Delay Editor" can be opened, because an Object of the type "Delay" is published when a DelayNode is selected:


Here is one of these TopComponents:

@TopComponent.Description(
        preferredID = "FlightLegEditorTopComponent",
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(
        mode = "editor", 
        openAtStartup = false)
@ActionID(
        category = "Window", 
        id = "org.cool.viewer.FlightLegEditorTopComponent")
@ActionReference(
        path = "Menu/Window")
@ObjectTopComponent.OpenActionForObjectRegistration(
        displayName = "#CTL_EditorAction",
        preferredID = "FlightLegEditorTopComponent"
)
@NbBundle.Messages({
    "CTL_EditorAction=FlightLeg Editor",
})
public class FlightLegEditorTopComponent extends ObjectTopComponent implements ActionListener{
    private FlightLeg fl;
    //no-arg constructor is required:
    private FlightLegEditorTopComponent() {}
    public FlightLegEditorTopComponent(FlightLeg fl) {
        this.fl = fl;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        setDisplayName(fl.getName());
        open();
        requestActive();
    }
}

In the above, notice there is a public constructor that receives the domain object "FlightLeg" (i.e., for an airline-type application). Also, there's a new annotation up there, "@ObjectTopComponent.OpenActionForObjectRegistration".

Here's what that annotation looks like (copied and then simply renamed from "@TopComponent.OpenActionRegistration"):

public class ObjectTopComponent extends TopComponent {
    @Retention(RetentionPolicy.SOURCE)
    @Target({ ElementType.TYPE, ElementType.METHOD })
    public static @interface OpenActionForObjectRegistration {
        String displayName();
        String preferredID() default "";
    }
} 

However, the annotation above is processed in such a way that a context-sensitive Action is created that uses the type in the constructor of the TopComponent:

@SupportedSourceVersion(SourceVersion.RELEASE_6)
@ServiceProvider(service = Processor.class)
public final class ObjectTopComponentProcessor extends LayerGeneratingProcessor {
    public ObjectTopComponentProcessor() {
    }
    @Override
    public Set<String> getSupportedAnnotationTypes() {
        Set<String> hash = new HashSet<String>();
        hash.add(ObjectTopComponent.OpenActionForObjectRegistration.class.getCanonicalName());
        return hash;
    }
    @Override
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
        for (Element e : roundEnv.getElementsAnnotatedWith(ObjectTopComponent.OpenActionForObjectRegistration.class)) {
            ObjectTopComponent.OpenActionForObjectRegistration reg = e.getAnnotation(ObjectTopComponent.OpenActionForObjectRegistration.class);
            assert reg != null;
            Description info = findInfo(e);
            ActionID aid = e.getAnnotation(ActionID.class);
            if (aid != null) {
                File actionFile = layer(e).
                        file("Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance").
                        methodvalue("instanceCreate", "org.openide.windows.TopComponent", "openAction");
                actionFile.instanceAttribute("component", TopComponent.class, reg, null);
                if (reg.preferredID().length() > 0) {
                    actionFile.stringvalue("preferredID", reg.preferredID());
                }
                generateContext(e, actionFile);
                actionFile.bundlevalue("displayName", reg.displayName(), reg, "displayName");
                if (info != null && info.iconBase().length() > 0) {
                    actionFile.stringvalue("iconBase", info.iconBase());
                }
                actionFile.write();
            }
        }
        return true;
    }
    private void generateContext(Element e, File f) throws LayerGenerationException {
        ExecutableElement ee = null;
        ExecutableElement candidate = null;
        for (ExecutableElement element : ElementFilter.constructorsIn(e.getEnclosedElements())) {
            if (element.getKind() == ElementKind.CONSTRUCTOR) {
                candidate = element;
                if (!element.getModifiers().contains(Modifier.PUBLIC)) {
                    continue;
                }
                if (ee != null) {
                    throw new LayerGenerationException("Only one public constructor allowed", e, processingEnv, null); // NOI18N
                }
                ee = element;
            }
        }
        if (ee == null || ee.getParameters().size() != 1) {
            if (candidate != null) {
                throw new LayerGenerationException("Constructor has to be public with one argument", candidate);
            }
            throw new LayerGenerationException("Constructor must have one argument", ee);
        }
        VariableElement ve = (VariableElement) ee.getParameters().get(0);
        TypeMirror ctorType = ve.asType();
        switch (ctorType.getKind()) {
            case ARRAY:
                String elemType = ((ArrayType) ctorType).getComponentType().toString();
                throw new LayerGenerationException("Use List<" + elemType + "> rather than " + elemType + "[] in constructor", e, processingEnv, null);
            case DECLARED:
                break; // good
            default:
                throw new LayerGenerationException("Must use SomeType (or List<SomeType>) in constructor, not " + ctorType.getKind());
        }
        DeclaredType dt = (DeclaredType) ctorType;
        String dtName = processingEnv.getElementUtils().getBinaryName((TypeElement) dt.asElement()).toString();
        if ("java.util.List".equals(dtName)) {
            if (dt.getTypeArguments().isEmpty()) {
                throw new LayerGenerationException("Use List<SomeType>", ee);
            }
            f.stringvalue("type", binaryName(dt.getTypeArguments().get(0)));
            f.methodvalue("delegate", "org.openide.awt.Actions", "inject");
            f.stringvalue("injectable", processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString());
            f.stringvalue("selectionType", "ANY");
            f.methodvalue("instanceCreate", "org.openide.awt.Actions", "context");
            return;
        }
        if (!dt.getTypeArguments().isEmpty()) {
            throw new LayerGenerationException("No type parameters allowed in ", ee);
        }
        f.stringvalue("type", binaryName(ctorType));
        f.methodvalue("delegate", "org.openide.awt.Actions", "inject");
        f.stringvalue("injectable", processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString());
        f.stringvalue("selectionType", "EXACTLY_ONE");
        f.methodvalue("instanceCreate", "org.openide.awt.Actions", "context");
    }
    private String binaryName(TypeMirror t) {
        Element e = processingEnv.getTypeUtils().asElement(t);
        if (e != null && (e.getKind().isClass() || e.getKind().isInterface())) {
            return processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString();
        } else {
            return t.toString(); // fallback - might not always be right
        }
    }
    private Description findInfo(Element e) throws LayerGenerationException {
        Element type;
        switch (e.asType().getKind()) {
            case DECLARED:
                type = e;
                break;
            case EXECUTABLE:
                type = ((DeclaredType) ((ExecutableType) e.asType()).getReturnType()).asElement();
                break;
            default:
                throw new LayerGenerationException("" + e.asType().getKind(), e);
        }
        TopComponent.Description info = type.getAnnotation(TopComponent.Description.class);
        return info;
    }
}
 

The above processor is a combination of the TopComponentProcessor and the ActionProcessor in the NetBeans Platform.

And now you have a layer generating processor that creates a context sensitive Action for opening a TopComponent. If no Object of the type specified in the constructor of the TopComponent is in the Lookup, the Action will be disabled. If an Object of the specified type is available, the Action is enabled and immediately available to the TopComponent as soon as it is opened.

That's an example of a view that is bound to a model. Useful for editors that need to be created for one or more specific Objects. Data binding for TopComponents, hurray.

Geertjan's Blog - April 08, 2014 04:28 PM
Disable Module on Authentication Failure

The user starts the application. The splash screen is shown. Right after the modules are loaded, as indicated by the text in the splash screen, a small login screen appears. The user fills in the wrong login credentials and clicks OK. The text in the splash screen shows that one or more modules are being turned off. Then the main window of the application appears. Because the login credentials were wrong, one or more of the modules have been disabled. 

import java.util.List;
import org.netbeans.api.autoupdate.OperationContainer;
import org.netbeans.api.autoupdate.OperationException;
import org.netbeans.api.autoupdate.OperationSupport;
import org.netbeans.api.autoupdate.UpdateElement;
import org.netbeans.api.autoupdate.UpdateManager;
import org.netbeans.api.autoupdate.UpdateUnit;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.modules.OnStart;
import org.openide.util.Exceptions;

@OnStart
public class Startable implements Runnable {
    @Override
    public void run() {
        NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine("Name", "Login");
        //Got tired of typing it by hand:
        nd.setInputText("admin");
        Object response = DialogDisplayer.getDefault().notify(nd);
        if (response == NotifyDescriptor.OK_OPTION) {
            String username = nd.getInputText();
            NotifyDescriptor.Message msg;
            if (!username.equals("admin")) {
                List<UpdateUnit> updateUnits = 
                  UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
                for (UpdateUnit updateUnit : updateUnits) {
                    //Get each module that is installed:
                    UpdateElement el = updateUnit.getInstalled();
                    //Of those that are installed, if it has the code name base
                    //of the module we are interested in, and it is enabled,
                    //continue with this procedure to disable it:
                    if (el != null
                            && el.getCodeName().equals("com.mycompany.admin")
                            && el.isEnabled()) {
                        try {
                            //Specify how we want to handle the module; 
                            //here, we want to disable it:
                            OperationContainer oc = OperationContainer.createForDirectDisable();
                            oc.add(el);
                            //Finally, do the operation,
                            //passing a progress handle or, as in this case, null:
                            OperationSupport supp = (OperationSupport) oc.getSupport();
                            supp.doOperation(null);
                        } catch (OperationException ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    }
                }
            }
        }
    }
}

Finally, the module is not shown in the Plugin Manager, so that it cannot be enabled from there. Only if the user logs in correctly is the module enabled.

Related reading:

Adam Bien - April 08, 2014 09:55 AM
1st Airhacks Q&A And The Answers Are:

Additional 10 live questions, 1h and 83 live views. The first edition Airhacks Q & A was fun for me. I started with answering the 10 proposed questions, then got additional blog comments, tweets and chats in real time. After a 1h I had to catch QuestionsOverflowException and postponed some answers to the 2nd edition of Airhacks Q & A (Monday, May 5th, 6 PM (CET)): http://www.ustream.tv/channel/adambien.

Thanks for all the interactions during the event. It was fun for me ...and I saved lots of time.

Write your questions as comments to this post, drop me a tweet or write a comment on my youtube channel: https://www.youtube.com/user/bienadam. I will pick again the 10 most recent questions and will answer them at the next edition of Airhacks Q & A.

We have sufficient stuff to cover, this blog has about 5000 comments, and probably 20% of that number are unanswered questions.

See you at the regular Java EE Workshops at MUC Airport and particularly at Distributed Computing and Persistence with Enterprise Java. ...and live each first Monday of the month at 6 P.M (CET) http://www.ustream.tv/channel/adambien!

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.


Real World Java EE Workshops [Airport Munich]>

Geertjan's Blog - April 07, 2014 08:33 PM
Multiple Rows of Toolbars

Realized today that toolbars can be placed in different rows:

The above is a result of a file I named "All.xml" that has this content and is found in the same package as the layer.xml file:

<?xml version="1.0"?>
<!DOCTYPE Configuration PUBLIC "-//NetBeans IDE//DTD toolbar//EN"
 "http://www.netbeans.org/dtds/toolbar.dtd">
<Configuration>
    <Row>
        <Toolbar name="File" />
    </Row>
    <Row>
        <Toolbar name="UndoRedo" />
        <Toolbar name="Clipboard"/>
    </Row>
    <Row>
        <Toolbar name="Memory"/>
    </Row>
</Configuration>

It is registered as follows in the layer.xml file:

<folder name="Toolbars">
    <file name="All.xml" url="All.xml"/>
</folder>

And then, as a handy final step, here's code in one of my TopComponents for switching between different toolbar definitions:

@Override
protected void componentActivated() {
    ToolbarPool.getDefault().setConfiguration("All");
}
@Override
public void componentDeactivated() {
    ToolbarPool.getDefault().setConfiguration("Standard");
}

Here's some related reading: