Feed aggregator

The Best of the Week (Apr 03): SQL Zone

Javalobby Syndicated Feed - Sat, 11-Apr-15 22:00
Make sure you didn't miss anything with this list of the Best of the Week in the SQL Zone (April 03 - April 10). Here they are, in order of popularity: Preview Text:  Make sure you didn't miss anything with this list of the Best of the Week in the SQL Zone (April 03 - April 10). This week's topics include an avoiding dead lock when...
Categories: Java

How to Batch DELETE Statements with Hibernate

Javalobby Syndicated Feed - Fri, 10-Apr-15 23:00
Introduction In my previous post, I explained the Hibernate configurations required for batching INSERT and UPDATE statements. This post will continue this topic with DELETE statements batching. Domain model entities We’ll start with the following entity model: Preview Text:  In my previous post, I explained the Hibernate configurations...
Categories: Java

Connect a Mobile App and a Spark Core - An International IoT Day Project

Javalobby Syndicated Feed - Fri, 10-Apr-15 23:00
Written by Jen Looper It’s the Fifth Annual International Internet of Things Day! If you’re not familiar with this worldwide celebration of all Things Internet, you can learn about it here. According to this website, “the time is now to start having the important conversations on the technologies, security, data privacy, and enormous potential that an ‘Internet of Things’ is...
Categories: Java

The Best of the Week (Apr 03): Cloud Zone

Javalobby Syndicated Feed - Fri, 10-Apr-15 23:00
Make sure you didn't miss anything with this list of the Best of the Week in the Cloud Zone (April 03 - April 10). Here they are, in order of popularity: Preview Text:  Make sure you didn't miss anything with this list of the Best of the Week in the Cloud Zone (April 03 - April 10). This week's topics include an AWS cloud journey,...
Categories: Java

Vagrant Cloud - Creating Vagrant Box Files for a VirtualBox Provider in AWS

Javalobby Syndicated Feed - Fri, 10-Apr-15 23:00
[This article was written by Michael Sverdlik.] Preview Text:  Many developers often need to create easily reproducible development environments – for anything from testing to troubleshooting, and even continued development across teams. To this end, many technologies have arisen to answer this need from Vagrant and VirtualBox, and even Docker...
Categories: Java

Holy Momentum Batman! Spark and Cassandra (circa 2015) w/ Datastax Connector and Java

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
Over a year ago, I did a post on Spark and Cassandra.  At the time, Calliope was your best bet.  Since then, Spark has exploded in popularity. Preview Text:  Over a year ago, I did a post on Spark and Cassandra. At the time, Calliope was your best bet. Since then, Spark has exploded in popularity. Legacy ...
Categories: Java

Clinical Trials and Machine Learning

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
Arguments over the difference between statistics and machine learning are often pointless. There is a huge overlap between the two approaches to analyzing data, sometimes obscured by differences in vocabulary. However, there is one distinction that is helpful. Statistics aims to build accurate models of phenomena, implicitly leaving the exploitation of these models to...
Categories: Java

Where is the Constraint in Software Development?

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
I just had a thought about the relationship between software development and the Theory of Constraints. It probably isn’t a new thought, although it seems to differ from some of the analyses I’ve seen elsewhere. Also, I probably won’t be able to express it in any coherent way; but here goes… Preview Text:  The constraint is our limited...
Categories: Java

Changing the Tires

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
You're driving down the highway trying to reach a distant destination. You've had delays such as traffic along the way, and you know that you're going to have to "push it" in order to have any hope at all of arriving on time. You start to feel something strange in the steering wheel. The car seems to be pulling to one side and the steering is rather "mushy". It dawns on you that you're losing air...
Categories: Java

Zero Downtime of Coherence Infrastructure (24x7 Availability) as part of Planned Deployment Strategy

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
Coherence is a reliable in-memory data grid product offering OOTB failover & continuous availability with extreme scalability. But we at times, face challenges during Coherence deployment and tend to lean towards clean restart of entire Coherence Cluster. Preview Text:  Coherence is a reliable in-memory data grid product offering OOTB...
Categories: Java

Tracking Events Through Complex Stacks

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
[This article was written by Marc Concannon] Preview Text:  Recently, I went through the general issue of how systems have become more complex, utilizing more and more components and frameworks from 3rd parties. Legacy Sponsored:  unsponsored
Categories: Java

Geek Reading April 9, 2015

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
Two excellent articles lead your reading today. First, Stack Overflow reports on their 2015 developer survey. It is an interesting look into the people that frequent the site which could be seen as a representative sample of our industry. On Road Less Traveled, we get a first hand account of one man’s experiences at Apple and why he quit. A very good, if not entirely surprising, article that...
Categories: Java

JBoss Fuse - Fuse workshop 101 - Part One

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:30
On my way to Hong Kong for a day of workshop on JBoss Fuse, and as I go through my Slide deck, I cannot find any decent easy workshop for beginners. Therefore I decide make a workshop that is easy for Camel first timer to get their hands dirty. The first of part of the workshop is an introduction to Camel, it first goes through what is exactly inside JBoss Fuse. For part one of the workshop,...
Categories: Java

SpringOne2GX 2014 Replay: Groovy AST Transformations

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:00
Recorded at SpringOne2GX 2014.Speaker: Paul KingMore Groovy TrackSlides: http://www.slideshare.net/SpringCentral/groovy-asttransforms-paulkingsep2014bIn this talk you'll learn about some of Groovy's AST transformations. Preview Text:  In this talk you'll learn about some of Groovy's AST transformations. Legacy ...
Categories: Java

Introducing the New Cypher Query Optimizer

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:00
Originally Written by Petra SelmerYou’ll have seen the excitement around the Neo4j 2.2 Release, and might have seen a few items about the Cypher query language. We in the Cypher team are delighted that our new Cypher Query Optimizer, codenamed ‘Ronja’, has been a big part of the release, and we’d love to share some of the details with you. Preview Text:  ...
Categories: Java

Why Manual Testing is Still Necessary

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:00
Automated processes are making headway across numerous industries, and software development has been changed forever thanks to these initiatives. Many teams are exploring how to automate the vast majority of their tests to ensure that repeatable tests are executed while giving quality assurance employees time to complete other tasks. Preview Text:  ...
Categories: Java

"New Agile" Slides from #AgileEE

Javalobby Syndicated Feed - Fri, 10-Apr-15 22:00
Had great fun presenting the New Agile today at Agile Eastern Europe in Kiev. Here are the slides. Preview Text:  Had great fun presenting the New Agile today at Agile Eastern Europe in Kiev. Here are the slides. Legacy Sponsored:  unsponsored
Categories: Java

Tweaking the Menu Bar of JavaFX 8 Applications on OS X

codecentric Blog - Fri, 10-Apr-15 05:19

JavaFX provides a simple means to create platform independent applications with a graphical UI. This platform independence, however, usually comes at a price. As the compiled code is supposed to run on all supported operating systems, JavaFX does not support all unique operating system specific UI elements. This is usually not a big problem, but it can be rather annoying in certain cases.

On OS X, the application’s menu bar is usually detached from the application’s main window and shown at the very top of the desktop instead. In contrast to the regular menu of a JavaFX application, this menu bar always contains the Apple menu and something that is called application menu. This application menu is created for every application regardless of whether it uses an own menu bar or not and contains items to show, hide and quit the application. Native Mac OS applications also use the application menu for example for preferences, the about menu and other application related menu items. Unfortunately, JavaFX does not provide any means to access this menu let alone adding new custom items to it. This can be particularly annoying when menu items are labeled “Java” or contain the entire package name of your main class.

In this blog post, I describe how to access the application menu using Cocoa native bindings from Eclipse SWT to modify default application menu items and adding new custom items. With the resulting code, JavaFX applications are able to use the default Mac OS menu bar just like any native application.

The following example shows how to add a menu bar to a JavaFX application. It also sets the useSystemMenuBarProperty to true in order to put the menu bar at the very top of the screen instead of adding it to the application window.

@Override
public void start(Stage primaryStage) throws Exception {
  MenuBar menuBar = new MenuBar();
  menuBar.useSystemMenuBarProperty().set(true);
 
  Menu menu = new Menu("java");
  MenuItem item = new MenuItem("Test");
 
  menu.getItems().add(item);
  menuBar.getMenus().add(menu);
 
  primaryStage.setScene(new Scene(new Pane(menuBar)));
  primaryStage.show();
}

The problem with that code is that it does not affect the automatically generated application menu in any way. The menu items are just added to the right of the already existing application menu. Therefore, I created a small tool called NSMenuFX on Github that provides access to the generated menu bar using Eclipse SWT. For convenience, it allows for converting the auto generated Mac OS menu bar into a JavaFX MenuBar. This menu bar can then be modified just like any JavaFX menu bar and converted back to a Mac OS native NSMenuBar. In the following, I outline how to use this tool and how it uses Cocoa native bindings to provide the described functionality.

Accessing the auto generated menu bar with NSMenuFX is fairly simple, as outlined in the following example:

NSMenuBarAdapter adapter = new NSMenuBarAdapter();
MenuBar menuBar = adapter.getMenuBar();

The first Menu of menuBar now contains the application menu with all its default items. To access this menu, NSMenuBarAdapter uses the NSApplication class of Eclipse SWT. This is pretty much straight forward as NSApplication provides direct access to the application’s menu bar by calling

NSMenu mainMenu = NSApplication.sharedApplication().mainMenu()

The slightly more tricky part starts by converting the NSMenu to a JavaFX MenuBar, since the two concepts are slightly different. In JavaFX, there is one MenuBar object containing several Menus whereas each Menu can contain MenuItems or further Menus. As depicted in the example above, Cocoa does not have the concept of a menu bar object but uses a NSMenu object instead. This menu solely consists of NSMenuItems, whereas each of this items has a title and an optional submenu. The title of these items is what is shown in the OS X menu bar whereas the submenus are the menus that open when you click on them. The submenus also contain NSMenuItems with, again, optional submenus. To shine a bit more light on the Cocoa Menu structure, consider the following code snippet that loops over the items of the OS X menu bar. It uses the ToJavaFXConverter to convert submenus to the respective JavaFX Menu classes and adds them to a MenuBar.

NSArray itemArray = mainMenu.itemArray();
for (long i = 0; i < itemArray.count(); i++) {
  NSMenuItem item = new NSMenuItem(itemArray.objectAtIndex(i));
  bar.getMenus().add(toJavaFX.convert(item.submenu()));
}

The most interesting part of this code snippet is that the itemArray does not contain the actual NSMenuItems but only a sequence of Cocoa native object IDs. To bind a Java object to the respective native object, this object id must be passed in to the constructor. The convert method that is called subsequently then recurses through the submenu and converts all elements to their JavaFX counterparts.

Most aspects of the menu item conversion, like the title or the accelerator are pretty much straight forward and can be, more or less, directly translated. The menu item’s click action is, however, a bit more complicated as Cocoa uses selectors to call a given method whereas JavaFX uses EventHandler objects that are assigned to the menu item and called in case they are clicked. If you are not familiar with Objective-C, selectors can be loosely thought of as reflections defining method names that should be called on a given object. For the conversion from Cocoa to JavaFX, NSMenuBarAdapter creates a dummy EventHandler containing the selector address as well as a reference to the object on which the selector should be executed.

A bit more challenging is the conversion from JavaFX to Cocoa, as it requires the conversion from EventHandler objects to Objective-C selectors. Therefore, a new selector can be created at runtime by calling OS.sel_registerName(String name). By default, selectors are invoked on the delegate object of the application, which is an instance of SWTApplicationDelegate. To enable SWTApplicationDelegate to respond to the new selector, a respective method can be added at runtime as outlined in the following snippet taken from ToCocoaConverter. The implementation of the method is provided by a Callback object, which is called from Objective-C.

Callback callback = new Callback(new MenuHookObject(handler), "actionProc", 3);
long delegateClass = OS.objc_lookUpClass("SWTApplicationDelegate");
OS.class_addMethod(delegateClass, selector, callback.getAddress(), "@:@");

The constructor of the callback object takes a Java object, the name of the method that should be called and the number of parameters. As depicted above, MenuHookObject.actionProc takes three arguments, i.e. a reference to its own object, a reference to the selector as well as a reference to the calling object. The same parameters are used for the method that is added to the delegate object as indicated by the signature @:@ (@ represents a NSObject reference, : represents a selector reference). When actionProc is called, MenuHookObject just calls the JavaFX EventHandler that was passed in to its constructor.

By being able to convert a JavaFX MenuBar back to a Objective-C Menu, the auto generated menu bar can simple be replaced with a modified or even entirely new version of the menu bar. The following example shows how to use NSMenuFX to add an “About” menu to the generated application menu.

    // Create a new menu item
    MenuItem about = new MenuItem("About");
    about.setOnAction(new EventHandler<ActionEvent>() {
	@Override
	public void handle(ActionEvent event) {
	    // Open a new JavaFX dialog
	}
    });
 
    // Add the menu item as first element to the application menu
    menuBar.getMenus().get(0).getItems().add(0, about);
 
    // Update the menu bar
    adapter.setMenuBar(menuBar);

I hope this article provides you with some interesting insights about Cocoa native bindings and how to use them to tweak the Mac OS menu bar items from JavaFX. Feel free to contact me directly if you have any further questions or leave a comment right below this post.

The post Tweaking the Menu Bar of JavaFX 8 Applications on OS X appeared first on codecentric Blog.

Categories: Agile, Java, TDD & BDD

Lattice and Spring Cloud: Resilient Sub-structure for Your Cloud-Native Spring Applications

Javalobby Syndicated Feed - Thu, 09-Apr-15 23:00
Written by Matt Stine on the Spring blog We believe that the development of cloud-native application architectures is the next great evolutionary phase of enterprise application development. Preview Text:  We believe that the development of cloud-native application architectures is the next great evolutionary phase of enterprise...
Categories: Java

Netflix Debuts Vector, a New Performance and Monitoring Tool

Javalobby Syndicated Feed - Thu, 09-Apr-15 23:00
Preview Text:  The kind folks at Netflix are constantly improving our lives, and their latest endeavor reaches beyond providing an enormous library of fine cinema. Netflix just debuted a performance and monitoring tool, Vector. Legacy Sponsored:  unsponsored
Categories: Java

Thread Slivers eBook at Amazon

Syndicate content