NetBeans Day Athens 26 August 2016

June 20, 2016 Leave a comment

NetBeans Days is an international event that takes places in various countries around the world, since JavaOne 2014, where the idea was conceived. It is about the NetBeans IDE and Rich Client Platform as well as up to date information of the Java programming language (and also other languages that are supported by NetBeans).

The NetBeans Community, in collaboration with the Hub of Innovation & Entrepreneurship of Technopolis City of Athens is proud to invite you to a free event, on Friday 26 August, regarding the NetBeans IDE and Rich Client Platform. Take the opportunity to learn about the latest tips and tricks of the NetBeans IDE and the NetBeans platform by experts on the subject.

Agenda:

9:30-10:00: Registration, coffee

10:00-10:30: Welcome and NetBeans roadmap (Geertjan Wielenga: NetBeans Product Manager, Oracle)

10:30-10:45: Coffee Break

10:45-12:00: Oracle JET – workshop (Geertjan Wielenga: NetBeans Product Manager, Oracle)

12:00-13:00: Lunch Break

13:00-14:30: Developing mixed Java/Groovy projects with Gradle using Netbeans – workshop (Kostas Saidis: Niovity)

14:30-15:15: Build a Java EE 7 application using Netbeans and Jboss Forge and deploy it in WildFly 10.1 in 30 minutes – workshop (Emmanuel Hugonnet: RedHat)

15:15-15:30: Coffee Break

15:30-16:30: NetBeans for PHP developers; real world examples (Alexius Diakogiannis)

16:30-17:00: Othelo puzzle game using NetBeans, Java Swing and Artificial Intelligence (Dimitrios Mendrinos)

17:00-17:30: Converting a Swing application to JavaFX and Dukescript – workshop (Ioannis Kostaras)

 

Categories: Conference

NetBeans Days in Athens 17-18 April 2015

February 17, 2015 Leave a comment

The NetBeans Community invites you to a 2-days free event regarding the NetBeans IDE and Rich Client Platform. The event will be hosted in Athens from Friday, 17 to Saturday, 18 April 2015.

You will have the chance to learn about the latest tips and tricks of the NetBeans IDE and the NetBeans platform by experts on the subject.

The free event lasts from 9:00 to 16:00 on Friday and from 9:00 to 12:30 on Saturday. This is an amazing opportunity to combine your passion with holidays and taste the amazing Hellenic cuisine.

Coffee will be provided and we look forward to a fun-filled and active day, at the end of which you will have gained many new insights, while extending your network.

The event will take place at a great venue, the Aquis Mare Nostrum Hotel Thalasso outside Athens just 20′ from Athens airport and by the Aegean sea.

Prices (VAT inclusive) if you choose to stay at the hotel:

– Rich breakfast buffet
– Rich lunch buffet and the following drinks in limitless consumption during dinner: white / pink / red wine, draft beer, juices, soft drinks

– Single main building room with mountain views: 75 EUR per room per night in Half pension
– Double main building room with mountain views: 85 EUR per room per night in Half pension
– Double main building room or bungalow with sea view: 105 euros per room per night half pension
– Triple room in bungalow with sea view: 135 euros per room per night half pension

Lunch buffet fee: 15 euros extra per person per meal, suppl. unlimited consumption of white / pink / red wine, draft beer, juices, soft drinks.

The event is sponsored by the Anderson Software Group, which provides training in Java and JavaFX, C++, Python and Perl, OOD and UML, Linux, and C#. The organizers would like to thank the Anderson Software Group for their support of this event!

Please register here.

Aquis Mare Nostrum Hotel Thalasso
Leoforos Vravronos 30
Artemis 190 16, Greece
lat, lon: 37.930312, 24.006113 (37° 55′ 49”, 24° 0′ 22′)

Categories: Conference

Recipe 15: How to add a toggle action

February 2, 2015 Leave a comment

Problem: How can I add a toggle button as an action? I tried to add a JToggleButton but it doesn’t work.

Solution: JToggleButton doesn’t really work with the NetBeans toolbar, instead use BooleanStateAction. Here are the steps to follow:

  1. Create a new Action, e.g.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.util.NbBundle.Messages;

@ActionID(category = "Options",
id = "todo.controller.options.QuickFilterAction")
@ActionRegistration(iconBase = "todo/controller/options/find16.png",
displayName = "#CTL_QuickFilterAction")
@ActionReferences({
    @ActionReference(path = "Menu/Options", position = 50),
    @ActionReference(path = "Toolbars/Options", position = 50),
    @ActionReference(path = "Shortcuts", name = "F3")
})
@Messages("CTL_QuickFilterAction=Quick Filter")
public final class QuickFilterAction implements ActionListener {

    public void actionPerformed(ActionEvent e) {
        // TODO implement action body
    }
}

2.  Extend BooleanStateAction and since it implements ActionListener this can be deleted from our action:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.util.NbBundle.Messages;

@ActionID(category = "Options",
id = "todo.controller.options.QuickFilterAction")
@ActionRegistration(iconBase = "todo/controller/options/find16.png",
displayName = "#CTL_QuickFilterAction")
@ActionReferences({
    @ActionReference(path = "Menu/Options", position = 50),
    @ActionReference(path = "Toolbars/Options", position = 50),
    @ActionReference(path = "Shortcuts", name = "F3")
})
@Messages("CTL_QuickFilterAction=Quick Filter")
public final class QuickFilterAction extends BooleanStateAction {

 @Override
 protected void initialize() {
   super.initialize();
   setBooleanState(Settings.isSearchVisible());
 }

 @Override
 public void actionPerformed(ActionEvent e) {
   super.actionPerformed(e);
   TasksTopComponent tasksTopComponent = (TasksTopComponent) WindowManager.getDefault().findTopComponent("TasksTopComponent");
   tasksTopComponent.setSearchVisible(getBooleanState());
 }

 @Override
 public String getName() {
   return "Quick Filter";
 }

 @Override
 public HelpCtx getHelpCtx() {
   return HelpCtx.DEFAULT_HELP;
 }

 @Override
 protected String iconResource() {
   return "todo/controller/options/find16.png";
 }
}

Since, due to lazy initialization, it doesn’t recognize the values passed in the annotations, we need to override the iconResource() method. Because, by default, it is selected, we need to set it to unselected in the initialize() method.

Categories: Action, Filter, Quick Search

Recipe 14: How to add a Quick Filter

February 1, 2015 Leave a comment

Problem: How can I display a Quick Filter button with a Quick Filter text field to filter my OutlineView?

Solution:  In Recipe 9 we showed how to create a QuickFilter in order to filter an OutlineView. NetBeans RCP allows you to create a graphical filter text field in order to filter your OutlineView dynamically based on what you are typing (display the Notifications window by clicking on menu Window | IDE Tools | Notifications for an example — you need to have NetBeans version 7.3 or later).

notifications

In the class that contains your TopComponent or your panel you need to define the following:

/** Quick Search filter */
private final QuickSearch quickSearch;
/** Callback */
private final QuickSearch.Callback quickFilterCallback = new QuickFilterCallback();

and in the constructor (you need to create an empty JPanel — here called pnlQuickSearchFilter — that will host the quick filter text box):

GridBagConstraints searchConstrains = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
quickSearch = QuickSearch.attach(pnlQuickSearchFilter, searchConstrains, quickFilterCallback, true);
FilterRepository.getInstance().addPropertyChangeListener(pcl);
setSearchVisible(Settings.isSearchVisible());

QuickFilterCallback is called when the user types something in the quick filter text field:

private class QuickFilterCallback implements QuickSearch.Callback {

    @Override
    public void quickSearchUpdate(String searchText) {
        FilterRepository.getInstance().setQuickSearchFilter(searchText);
        if (quickSearch != null && !quickSearch.isAlwaysShown()) {
            setSearchVisible(true);
        }
    }

    @Override
    public void showNextSelection(boolean forward) {
    }

    @Override
    public String findMaxPrefix(String prefix) {
        return prefix;
    }

    @Override
    public void quickSearchConfirmed() {
    }

    @Override
    public void quickSearchCanceled() {
        FilterRepository.getInstance().setQuickSearchFilter(null);
    }
}

FilterRepository handles the quick filter:

package org.netbeans.filters.filter.checklist;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public final class FilterRepository {

    /** Property when a new quick filter is applied. */
    public static final String PROP_QUICK_FILTER = "QUICK-FILTER";
    /** Observable. */
    private PropertyChangeSupport pcs = null;
    /** A quick search filter. */
    private String quickSearchFilter;

    /** Constructor, default. */
    private FilterRepository() {
    }

    /**
     * Singleton.
     *
     * @return the single instance of this class.
     */
    public static FilterRepository getInstance() {
        return SingletonHolder.INSTANCE;
    }

    /** SingletonHolder. */
    private static final class SingletonHolder {

        /** The only INSTANCE. */
        private static final FilterRepository INSTANCE = new FilterRepository();

        /** Private. */
        private SingletonHolder() {
        }
    }

    /**
     * @return a thread-safe PropertyChangeSupport
     */
    private PropertyChangeSupport getPropertyChangeSupport() {
        if (pcs == null) {
            pcs = new PropertyChangeSupport(this);
        }
        return pcs;
    }

    public void addPropertyChangeListener(PropertyChangeListener pcl) {
        getPropertyChangeSupport().addPropertyChangeListener(pcl);
    }

    public void removePropertyChangeListener(PropertyChangeListener pcl) {
        getPropertyChangeSupport().removePropertyChangeListener(pcl);
    }

    public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
        getPropertyChangeSupport().addPropertyChangeListener(name, pcl);
    }

    public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
        getPropertyChangeSupport().removePropertyChangeListener(name, pcl);
    }

    /**
     * Quick search filter is used by bottom panel.
     *
     * @param searchText
     * text to filter
     */
    public void setQuickSearchFilter(String searchText) {
        String oldFilter = quickSearchFilter;
        quickSearchFilter = (searchText == null || searchText.isEmpty()) ? null : searchText;
        getPropertyChangeSupport().firePropertyChange(PROP_QUICK_FILTER, oldFilter, quickSearchFilter);
    }

    public boolean isQuickSearchFilter() {
        return quickSearchFilter != null;
    }

    public String getQuickSearchFilter() {
        return quickSearchFilter;
    }
}

Settings class (copied from NetBeans source code):

import java.util.prefs.Preferences;
import org.openide.util.NbPreferences;

/**
 * @author jpeska
 */
public class Settings {

   private static final String SEARCH_VISIBLE = "searchVisible"; //NOI18N
   private static final boolean DEFAULT_SEARCH_VISIBLE = true;

   private Settings() {
   }

   public static boolean isSearchVisible() {
      return getPreferences().getBoolean(SEARCH_VISIBLE, DEFAULT_SEARCH_VISIBLE);
   }

   public static void setSearchVisible(boolean searchVisible) {
      getPreferences().putBoolean(SEARCH_VISIBLE, searchVisible);
   }

   private static Preferences getPreferences() {
      return NbPreferences.forModule(Settings.class);
   }
}

setSearchVisible() method does the actual filtering of the OutlineView using the setQuickFilter() and unsetQuickFilter() methods explained in Recipe 9.

    /**
     * @param visible if {@code true} then display the quick search panel
     */
    public void setSearchVisible(boolean visible) {
        quickSearch.setAlwaysShown(visible);
        if (!visible) {
            unsetQuickFilter();
        } else if (FilterRepository.getInstance().isQuickSearchFilter()) {
            setQuickFilter(0, getQuickFilter(FilterRepository.getInstance().getQuickSearchFilter()));
        }
        Settings.setSearchVisible(visible);
    }

    /**
     * Create a QuickFilter from the given String.
     *
     * @param qsFilter filter as String
     * @return a QuickFilter from the given String
     */
    private QuickFilter getQuickFilter(String qsFilter) {
        return (Object aValue) -> {
            if (aValue instanceof TaskNode) {
                Task task = ((TaskNode) aValue).getLookup().lookup(Task.class);
                return task.getDescription().contains(qsFilter)
                        || String.valueOf(task.getPriority()).contains(qsFilter)
                        || task.getDueDate().toString().contains(qsFilter);
            } else {
                return false;
            }
        };
    }

In the above example we show how to filter an OutlineView that contains TaskNodes. The filter is trying to match the Task‘s description, priority or due date.

The last remaining change is the property change listener which listens to changes in FilterRepository.

    /** Listen to changes in the FilterRepository and filter the outline view
     * accordingly. */
    private final PropertyChangeListener pcl = (final PropertyChangeEvent evt) -> {
        SwingUtilities.invokeLater(() -> {
            // filter outline view on QuickSearchFilter input
            if (FilterRepository.PROP_QUICK_FILTER.equals(evt.getPropertyName())) {
                final String newQuickSearchFilter = (String) evt.getNewValue();
                if (newQuickSearchFilter != null && !newQuickSearchFilter.isEmpty()) {
                    unsetQuickFilter();   // should run in EDT
                    if (!newQuickSearchFilter.isEmpty()) { // should run in EDT
                        setQuickFilter(0, getQuickFilter(newQuickSearchFilter));
                    }
                } else {
                    unsetQuickFilter();  // should run in EDT
                }
            }
        });
    };
Categories: Filter, Quick Search

Recipe 13: Customize the menu and the toolbar(s)

March 4, 2014 Leave a comment

Problem

How can I customize the menu and the toolbar(s) of my RCP application?

Solution

Each module contains a layer.xml file which is something like a registry of the module. It contains information about the windows, menus, toolbars, actions etc. of the module. The RCP combines all layer.xml files of all modules to create the final application layout. Without getting into too much detail, you can display layer.xml of  a module by right-clicking on it and selecting: New | Other | Module Development | XML Layer. Then, if you expand the Imporant Files menu you see an XML Layer node which contains two subnodes: <this layer> and <this layer in context>. The first contains the menus, actions etc. of the current module (local registry) while the second is the global registry (of the application).

By right clicking, e.g. on a menu item, you have actions like Delete, Rename, New etc. which you can use to customise the menus according to your needs. Similar case for toolbars, actions etc.

Categories: Toolbar

Recipe 12: How can I disable closing/undocking of a TopComponent?

March 4, 2014 Leave a comment

Problem

All top components contain a tab with a close (x) button. Once the user closes it, the only way to display it is via the Window menu or via Window | Reset Windows. However, if the Window menu has been deleted, then there is no other way to display the top component than restarting the application.

Solution

The close (x) button can be disabled by adding the following command(s) in the constructor of the top component:

putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.TRUE);

When creating a new TopComponent, you can disable closing it by checking the

  • Closing not allowed
  • Undocking not allowed

checkboxes in the first page of the New Window wizard.

As an aside, if you wish to completely get rid of the tab, then follow the instructions given here. In short add in the TopComponent‘s constructor:

SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        UIManager.put("EditorTabDisplayerUI", "todo.view.NoTabsTabDisplayerUI");
    }
 }); 

and add the new class NoTabsTabDisplayerUI as mentioned in the aforementioned blog.

Categories: TopComponent

Recipe 11: Why my OutlineView is not refreshed?

March 2, 2014 Leave a comment

Problem

Your outline view needs to be updated from data that are received from the network or when you edit a cell and press ENTER, nothing happens. Or when you add/remove a row the outline view is not updated.

Solution

For the cells to be updated/refreshed, one needs to add a property change listener to the underlying bean that when a property is changed, the node is refreshed, e.g.

public class MyNode extends BeanNode<MyBean> {

   private final transient PropertyChangeListener pcl = new PropertyChangeListener() {

     @Override
     public void propertyChange(final PropertyChangeEvent evt) {
       firePropertySetsChange(null, getPropertySets());
     }
   };

   public MyNode(MyBean bean) throws IntrospectionException {
     super(bean, Children.LEAF, Lookups.singleton(bean));
     bean.addPropertyChangeListener(pcl);
   }
}

and you need to fire a property change in your bean when a property changed.
This will refresh your outline view each time a cell value is changed.
To refresh your outline view when a row is added/removed, you need to modify your ChildFactory accordingly, e.g.

public class MyChildFactory extends ChildFactory<MyBean> {

   private final MyProvider provider;
   private final transient PropertyChangeListener pcl = new PropertyChangeListener() {

     @Override
     public void propertyChange(final PropertyChangeEvent evt) {
       refresh(true);
     }
   };

   public MyChildFactory() {
     provider = Lookup.getDefault().lookup(MyProvider.class);
     provider.addPropertyChangeListener(pcl);
   }

   @Override
   protected boolean createKeys(final List<MyBean> toPopulate) {
     toPopulate.addAll(provider.list());
     return true;
   }
}

where MyProvider is a service provider that popuplates your ChildFactory. Again, you need to fire a property change in your provider when an instance of MyBean is added/removed from it.

Categories: OutlineView
Follow

Get every new post delivered to your Inbox.