Thursday, November 19, 2009

[Announcement] Browser Suite released!

I just released a preview version of the Browser Suite for Servoy 5.

This is a suite of native components, all "Servoy-Aware" and tightly integrated with the Servoy platform.

The suite is released as Open Source under the terms of the LGPL license.

It contains:
- a browser bean
- a flash player bean
- a html editor bean
- a client plugin to rule them all
- a server plugin to configure
- an installer to help deployment

You will find it on the Servoy Stuff web site.

Check it out!

Tuesday, August 18, 2009

[Java Bean development] How to build a bean for Servoy - Part 8

Finally! Here is the last part of the bean tutorial.

As promised, we add some event handling to our Slider bean, in the Smart client and the Web client.

This one is little and easy, so get it now to finish building the Slider yourself and tell you mama you did it ;-)

I hope you enjoyed this serie and that you learned one or two tricks that will prove useful when you build the next generation of beans and plugins for the next generation of Servoy :))

Get it here and as usual, feel free to comment, criticize, question, suggest and request!

Monday, August 3, 2009

[Java Bean development] How to build a bean for Servoy - Part 7

Part 7 just arrived!

This time we integrate a JavaScript library in our bean to fully emulate the Swing Slider in the Web client!

It takes some tweaking with JavaScript and some more Java/Wicket Behavior coding to do that, but if you’ve gone this far, the end result will be rewarding enough!

So, download the stuff here now and amaze your colleagues with this funny slider jumping in your preferred browser ;-)

In the next (final?) part, we will integrate some events handling as suggested by someone in this very blog!

So you see, you too can add your comments, questions and suggestions: I do read them!

Monday, July 27, 2009

[Java Bean development] How to build a bean for Servoy - Part 6

Part 6 of the saga is now available, don't miss it!

In this one we apply everything we learned in the previous part in our "test bean" to our ServoySlider to promote it to level 1 of "Web compatible" bean: a simple text input for the web client acting as a replacement for our rich Swing bean.

Needless to say that in our next part we will need to add some JavaScript magic to the web client to make it act as a real Slider.

Still, this part is essential to understanding how to transform a Swing bean into a full fledged Servoy-Aware Servoy bean, Smart AND Web compatible.

So get it here now before others will steal it ;-)

Comments and suggestions most welcome, here and there!

Wednesday, July 15, 2009

[Java Bean development] How to build a bean for Servoy - Part 5

Finally part 5 is here!

And it's all you have dreamed about: we build a Servoy-Aware input bean of type Text, with a JTextField for the Swing part and a Panel and TextField for the Wicket part (we particularly focus on the Wicket implementation), and then we link the two with an IServoyBeanFactory implementation. That's 37 pages of highly condensed information for you!

So in a word, this one is wicked! - Sorry, I just couldn't resist! :)

You can download it here already, and it comes with compiled bean and full Eclipse solution.

As usual, bring on the comments, questions, suggestions... they are all welcome!

Happy Wicket coding!

Wednesday, July 8, 2009

[Java Bean development] How to build a bean for Servoy - Part 4

Yet another part of condensed information for this tutorial on how to build beans for Servoy.

You will learn how to turn a plain old JSlider into a full fledged input component ready to drop onto your Servoy solution, using a dataProvider, and with some cool enhancements like i18n readiness, support for double and floating point numbers with adjustable “on-the-fly” precision factor.

Yes, sir! That’s all on the menu. You ordered it! You got it!

You will also learn more about the “uncertainty principle”, some refactoring tricks in Eclipse, digging into the Swing sources and a few more niceties…

If you can’t make some good cofee with this bean tutorial, there’s no more hope for me!

Get it here now!

As usual, comments, suggestions, questions, are very welcome.

Sunday, July 5, 2009

[Commentary] Approaching 5,000 Visits!

Since this blog was first made public - in December of 2007 - nearly 5,000 visitors have stopped by to make contributions, discuss the contributions of others or learn about Java and Servoy. Here's to the next 5K visitors, and thanks for everyone's support!

In the last 2.5 years, this blog has primarily been entirely community supported, but in years to come I hope that Servoy corporate gets on board and helps to bring even more of the community to this sharing space. I also hope that as the visitor count continues to climb, the great community-driven content that visitors have come to expect continues, and that the handful of motivated community-centric Servoy developers whom have continously, generously contributed to this space inspire others to share [maybe for the first time].

IMHO, Servoy's extensibility thru Java is probably it's most marketable feature (despite the fact that it is not marketed). I have never worked with another tool that had so much [undocumented] horsepower; facilitating developer access to a vast wealth of free programming tools. The ability to script Java with JavaScript combined with a plugin and bean API, the headless client API, plus the ability to deploy servlets via the distributed servlet container/servoy server are major features of Servoy, and this blog helps developers leverage and discover them.

Saturday, July 4, 2009

[Java Bean development] How to build a bean for Servoy - Part 3

This new part of the tutorial deals with putting some finishing touches to our bean's implementation.

In short we will "polish the bean" (nothing kinky about it ;-)

After finishing this tutorial your bean will definitely look more professional and your users will not see the difference between this and a regular Servoy element.

It is available right here, right now!

Feel free to comment and suggest, I always like to hear from you!

Thursday, July 2, 2009

[Java Bean development] How to build a bean for Servoy - Part 2

It's here already?

You bet! This time the plot thickens, and you will surprise all your friends at the cocktail party, with the definitive answer to the quintessential question: now what is wrong with regular Java-Beans?

After the Da Vinci code, they will learn everything about the ServoySlider bean project (very hush hush stuff :)

You can download it straight from here.

As usual, comments, suggestions, etc... are very much welcome!

Monday, June 29, 2009

[Java Bean development] How to build a bean for Servoy - Part 1

Everything you always wanted to know about beans in Servoy (but were afraid to ask).

Starting gently (or so it seems) with this first part of the definitive bean tutorial: how to use regular beans with scripting in Servoy, you can download it right here.

The next parts will be more involved as we will dig deeper into the Servoy public API unknown territory, we will wrap our bean into a Servoy-Aware bean and keep adding functionalities until in the end, at last, everything is revealed!

So fasten your seat belt and get ready for the ride...
And as usual, feel free to comment and beg for more ;-)

Friday, June 19, 2009

[Java How-To] Video preview of upcoming tutorial

I just made a video to give you something to wait for: it shows the next component that I am going to explain at length in a new series of tutorials. About Servoy Beans this time!

In the video you will see two components in the context of the first (prequel) tutorial that will be about how to use these two components in Servoy with build-in Java integration (thanks to Rhino).

In the following tutorials, we will have a look at how to go even further by wrapping around these components to build a full featured Servoy Aware Bean, that will be released as Open Source (of course) and usable in any Servoy client (with Servoy v4.1+). Anyway, that’s the plan ;-)

There might as much as 6 to 8 tutorials in this series… you have been warned!

Download the video here (avi file in a zip archive to save some bandwidth, total is 8,77 MB).

Sunday, June 14, 2009

[Java Plug-In Development] How to build a plugin for Servoy - Part 3

Here is the final part of the tutorial on "How to build a plugin for Servoy".
That's part 3 for you.

26 pages of condensed information. After that you will speak fluent Java language even during your sleep ;-)

And this time, you won't even have the excuse of broken downloads, thanks to a generous hosting provided by ROCLASI Software Solutions.

So, download it here and keep an eye on the next big tutorial, I've got some new stuff cooking that will definitively make java-addicts out of you all.

And feel free to comment, question an suggest, you know I'm listening!

Enjoy!

Tuesday, June 9, 2009

[Java Plug-In Development] How to build a plugin for Servoy - Part 2

The second part of the tutorial is here!

It is bigger, bulkier, - it will leave nothing in the dark.

Try it, and if you can't do a plugin for Servoy after that, I will seriously consider converting to needlework, - or not ;-)

Download part 2 and be prepared for part 3 - coming soon!

Again, feel free to comment, question an suggest, I'm all ears!

Enjoy!

Sunday, June 7, 2009

[Java Plug-In Development] How to build a plugin for Servoy - Part 1

I have started today a new series of tutorials on how to build plugins and beans for Servoy, entitled "Everything you always wanted to know about plugins and beans (but were afraid to ask)"

This article is the first one and the first part of the topic.

It is a step by step tutorial, which will show you in great details how to build a simple but totally operational Servoy plugin, to get all the principles into place.

This first part is mostly about how to configure the Eclipse environment to get ready to code new plugins and beans for Servoy, it is intended as an introduction and touches the use of Servoy as an Eclipse distribution, and how to set it up for that task.

Questions, suggestions, comments are most welcome.

Enjoy!

Monday, March 30, 2009

[JavaScript]Working With JavaScript Arrays

I just wanted to share a link I came across with the help of Paul Bakker from Servoy - it's one that's all about using JavaScript arrays in JavaScript 1.6.

This page should be titled "Everything you wanted to know about arrays but were afraid to ask" - it's an excellent resource whether you're a beginner or intermediate Servoy user!

If you've been struggling with arrays - or you know arrays but didn't know the cool new functions for them in JS 1.6 - then you owe it to yourself to check it out.

Wednesday, February 25, 2009

[Docs][Java Plug-In Development] Using JGraph in Servoy




Stefaan Mahieu has been kind enough to write free documentation for the Servoy community on how to use JGraph in Servoy. Additionally I have wrapped [most of] the JGraph API into a free, source-distributed plugin*. Using the documentation and plugin together any Servoy developer will now be able to utilize the excellent graphing functionality available in JGraph.








About JGraph

JGraph is an open source graph visualization library written in Java. JGraph provides a range of graph drawing functionality for client-side or server-side applications. Look on the JGraph website (http://www.JGraph.com) for examples.

As always comments and suggestions are welcomed. Particularly you might want to drop Steffan a note to say thanks for all of the time he spent putting together such a nice, free resource.

*Please note that the FREE JGraph plugin is considered to be development code, and is not designed for production use. Additionally it is not supported, and not all interfaces have been implemented. If you would like to make the plugin production worthy and/or support or adopt it, the license it is distributed under allows for that.

Sunday, October 5, 2008

[Java How-To] #4 "Splash" Screens without a Plugin (Servoy 4)

Java How-To's are intended to provide real-world examples of how Java can be used to easily extend Servoy in useful ways. I will try to post a new one as often as possible.

Description

Because of the excellent support Servoy provides for scripting Java (via Rhino), creating a custom splash screen is a relatively simple scripting task, and you don't need a plugin to do it. All you need instead is a little knowledge of Swing, and enough skill with Photoshop® to create a cool splash image. ;-)

The code below creates a new frame, undecorates it (which is what makes it look like a "splash"), sizes it, shapes it, centers it, adds a graphic and text component from the media library and then displays the newly created frame for a specified period of time. The frame is disposed automatically thereafter.

You don't need to modify this code at all to get it working. Just upload a PNG image named "splash.png" to your Servoy media library, and also upload a simple text document named credits.txt. If you do want to edit this code though you certainly can. An example of doing so might be adding a progress meter or adding a border to the components etc.

If you want to change how long the splash is displayed for, just change the value of application.sleep(...).


Try this! I think you will be surprised at how good it works/looks.

Java Classes Used

For more information about any of the Java classes used, click their corresponding link below.

Total Lines of Code

Around 50

The Servoy 4 Code

function showSplash()
{
var pkgs = new JavaImporter(Packages.javax.swing.border.EmptyBorder,
Packages.javax.swing.ImageIcon,
Packages.javax.swing.JFrame,
Packages.javax.swing.JPanel,
Packages.javax.swing.JLabel,
Packages.javax.swing.JEditorPane,

java.awt.BorderLayout,
java.awt.Frame,
java.awt.Insets,
java.awt.GraphicsEnvironment,
java.awt.Point,
java.awt.Rectangle,

java.net.URL);

with(pkgs) {

// Create the splash frame and its components
var splash_panel = new JPanel(new BorderLayout(0,0));

var splash_image = new JLabel(new ImageIcon(new URL("media:///splash.png")));

var splash_credits_pane = new JEditorPane(new URL("media:///credits.txt"));
splash_credits_pane.setEditable(false);
splash_credits_pane.setMargin(new Insets(20,20,20,20));

splash_panel.add(splash_image, BorderLayout.CENTER);
splash_panel.add(splash_credits_pane, BorderLayout.SOUTH);
splash_panel.setBorder(new EmptyBorder(0,0,0,0));

var splash_frame = new JFrame();
splash_frame.setUndecorated(true);
splash_frame.getContentPane().add(splash_panel);
splash_frame.pack();

/*
Size/shape and center the splash frame

The bulk of this code was borrowed from a public post on Sun's
Java forum then converted to Servoy/JS.

See: http://forums.sun.com/thread.jspa?threadID=508444
*/
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
var center = ge.getCenterPoint();
var bounds = ge.getMaximumWindowBounds();

var w = Math.max(bounds.width/2, Math.min(splash_frame.getWidth(), bounds.width)); // Using JS Math here, not Java Math
var h = Math.max(bounds.height/2, Math.min(splash_frame.getHeight(), bounds.height));
var x = center.x - w/2;
var y = center.y - h/2;

splash_frame.setBounds(x, y, w, h);

if (w == bounds.width && h == bounds.height)
{
splash_frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}

// splash_frame.pack(); Optionally pack here (instead of above) to have the splash resize to shape of image

splash_frame.validate();

splash_frame.show();

application.sleep(3000);

splash_frame.dispose();
}
}


IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

Sunday, September 7, 2008

[Commentary] ServoyWorld 2008

I recently returned from my trip to Las Vegas, and ServoyWorld 2008 - had a great time. I finally had an opportunity to meet many of the developers with whom I had been conversing for a couple of years, and also had an opportunity to speak with Servoy engineers and the executive team.

What I took away from this conference, apart from some good tips and tricks, was an overall feeling that Servoy is moving forward, and that the team behind the Servoy product is both committed and driven. I expect that Servoy will continue to advance technically; delivering the features that developers and businesses need to remain a step ahead of the competition and to appropriately leverage new technologies. I am personally very glad for my professional commitment to, and investment in the Servoy product, and have been assured that such commitments and investments will create measurable ROI for myself and others.

It was great to be at ServoyWorld 2008. Thanks to the Servoy community and to Servoy corporate for all of their time and effort in putting the event together, and making it a success.

Below is a [grainy, low-quality] picture of the Engineering Panel fielding questions at the end of the conference - it was taken from my phone.



Wednesday, August 6, 2008

[Commentary] Taking a Short Break from Blogging

I am currently working to update the Java for Servoy Devlopers Whitepaper for Servoy 4.0, and because of time constraints, am going to be taking a short break from blogging here. During this time, if anyone from the Servoy community would like to fill the gap by submitting new posts, please drop me a line. Or if you have an author account already, don't be shy ;-)

Tuesday, June 17, 2008

[Harmless Hacks] Accessing Smart Client's Progress Bar


Servoy client's main application frame is comprised of the usual sorts of Swing components. Some of those swing components are accessible through scripting - via the solution object model (and/or the plugin API) - while others are not. For example the status text (JLabel) in the "statusbar" - the one that usually displays "Ready" - is accessible through scripting while the progress bar (JProgressBar) in the very same "statusbar" is not.

Awhile back I had posted a feature request asking for access to the main application frame's progress bar through the plugin API. Some time has gone by since that feature request so I started to look at how to gain access on my own; I had a particular need. Turns out there isn't much to it.

In the code below we are traversing through the layers of components that comprise the servoy client frame. When we get to the JProgressBar component, we set its "indeterminate" property to true - illustrating how to access it.

We could also script other properties of the JProgressBar and even create loops that update the meter for a particular purpose, but there are other examples out there that show you how to work with progress bars and the purpose of this post is really to show you how to gain access to the progress bar, not how to use it. If you read between the lines here a little I think you will realize that a lot more of the Servoy UI is scriptable then you realize.


// This code compatible with Servoy 4 only (b/c of the use of JavaImporter)
function accessSmartClientsProgressBar()
{
var SwingGui = new JavaImporter(java.awt);

with (SwingGui)
{
var parentframe = new Frame.getFrames();
}

var contentpane = parentframe[0].getContentPane();
var components = contentpane.getComponents();
var subcomponents = components[0].getComponents();
var statusbarcomponents = subcomponents[1].getComponents();

statusbarcomponents[7].indeterminate = true;
}

COMPATIBILITY: This code was tested in Servoy 4 RC1. It will most likely work in earlier 4 builds too. It could also be modified slightly to work in 3.x and maybe even 2.x.

IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

Friday, June 13, 2008

[Rhino] JavaImporter

The upcoming release of Servoy 4 (currently in RC1) is set to deliver a number of new features to the Servoy platform. Among them is an updated version of Rhino, the JavaScript "engine" used by Servoy.

Rhino 1.6r7, the release currently included with Servoy 4, is actually a "minor, bug-fix release," but of course includes all the great new features introduced throughout 1.6rx - meaning to the best of my knowledge - no Rhino features have been disabled by Servoy! Alongside other new features introduced in Rhino 1.6rx such as E4X, a new global constructor known as "JavaImporter" surfaced.

Per the Rhino 1.6r1 change log, "JavaImporter...allows [you] to omit explicit package names when scripting Java." On the surface this may not seem like much of a feature, but in addition to the important technical advantages it provides over older techniques (detailed in the change log), JavaImporter can help to keep your code clean, organized and more readable [when scripting Java].

Have a look at how it is used (borrowed from: http://www.mozilla.org/rhino/rhino16R1.html):

var SwingGui = new JavaImporter(Packages.javax.swing,
Packages.javax.swing.event,
Packages.javax.swing.border,
java.awt.event,
java.awt.Point,
java.awt.Rectangle,
java.awt.Dimension);
...

with (SwingGui) {
var mybutton = new JButton(test);
var mypoint = new Point(10, 10);
var myframe = new JFrame();
...
}

In the above code, the variable SwingGui is assigned the value of JavaImporter, an ImporterTopLevel object, which is subsequently used in a with statement to instantiate classes from packages that were initially passed to the JavaImporter constructor. What you can take from this code is that Java packages can now be easily organized and more easily referenced within your Servoy code. You can assign collections of certain packages to certain variables, giving those variables descriptive names such as "SwingGui," then calling them as necessary. Also, you can easily add packages to the JavaImporter constructor as necessary, and the classes from those packages you add will become available throughout your solution, wherever you have used the variable to which they were assigned.

If you script Java from within your Servoy solutions, give JavaImporter a try.

Thursday, May 8, 2008

[Working with Java Beans] Access Quickbooks from Servoy

If you have any clients that need an external application to talk to Quickbooks, ibiz Quickbooks Integrator from /n Software (www.nsoftware.com) may be your answer. They provide a javabean that you can drop into Servoy and quickly begin talking to Quickbooks. This article documents the basic process of connecting to the bean.

Basic installation

  1. Download the Quickbooks Integrator from http://www.nsoftware.com/

  2. Install or unzip the files

  3. Find the file "ibizqb.jar" and copy it to the /servoy/beans" directory

  4. If you want to access the classes and methods of the bean directly without having to place the bean on your Servoy form, also copy the ibizqb.jar file to "/servoy/lib".

  5. There is a jar file called "deploy.jar" in the same directory. This is the production version of the bean. When you go live, use this file instead of ibizqb.jar, placing it in the same directories as above. ibizqb.jar is a little larger and contains more debug code.

  6. The trial version of the bean has a 3-sec delay built in to every call. This will make the communication seem slow. This delay is removed when you purchase a licensed version.

  7. Quickbooks Remote Connector (allows the bean to talk to Quickbooks over an HTTP connection)

  8. Install the ibiz Quickbooks Remote Connector on the Windows machine where Quickbooks is installed

  9. After installation, find the Remote Connector program in your Start menu and launch it

  10. Start the Remote Connector by clicking on the START button

  11. Note the network name of the computer where Remote Connector is installed. You'll need this on your Servoy machine to connect

Creating a sample form in Servoy using the ibizqb bean:



  1. Open blank form and name it "beantest". It can be based on any table at this point. For the sample form, we won't actually write any data to a table

  2. Create a couple of global variable fields you can use to view data from Quickbooks and place them on this form (gTest1, gTest2)

  3. Place a button on your form to use to fire the method we'll create that talks to Quickbooks

  4. Select the button object you just created and double-click the onAction property. Create a new Method called "qbTest" and click OK. We'll get to the editor in a minute to finish the method coding

  5. Click on the Bean icon on the toolbar. It looks like a little brown coffee bean

  6. Select "Customer" from the list of available bean objects. Servoy will add an object to the form with a name like "bean_315". You'll need to note this name so you can find it under your form elements node in the Editor

  7. Click on the Editor icon on the toolbar and the editor will open

  8. The new method you created above should be open and blank in the editor (qbTest). If not, navigate to -Application/Forms/beantest and click on it, then click the "new method" icon to create a new method on our form and name it "qbTest"

Below, are two versions of qbTest that you can try. Make sure to change the method your button uses for onAction to test out the other method shown below.

Reading from Quickbooks: get a customer (copy and paste the code below into your method)

// substitute the name of your Quickbooks computer name for  
elements.bean_115.QBConnectionString = "URL='http://yoda:2080'"
elements.bean_115.openQBConnection
// Set QBRequestId to an empty string or to a unique string every time to make a call to QB.
// You can query QB with QBRequestId to see if your request was accepted, but for now we're not using it
elements.bean_115.QBRequestId = '' // this is two single quotes, representing an empty string
// Look in your existing Quickbooks customer list and find the name of a company to put in here
// this method will retrieve a customer record from QB
elements.bean_115.getByName("My Company")

// Now that we have a customer record, show the contact name on our form to prove it
// Make sure your customer actually has a contact name filled in
globals.gTest1 = elements.bean_115.contactName

Try this out by running your form and clicking on the button. If you have everything right, you should get back your contact name. If nothing happens, you will need to troubleshoot. Look for the following errors:

  1. Is your firewall blocking port 2080 on the Quickbooks machine?

  2. Did you START the remote connector on the Quickbooks machine and open Quickbooks?

  3. Did you locate the name of the Quickbooks computer and put that name in the method above in the QBConnectionString property?

  4. Does your customer have the contact name field populated with a name in Quickbooks?

Now, let's update a piece of information in Quickbooks and show that we can write to it:

elements.bean_115.QBConnectionString = "URL='http://yoda:2080'"

elements.bean_115.openQBConnection
elements.bean_115.QBRequestId = ''
elements.bean_115.getByName("My Company")
// Now that we have a customer record, let's change the altphone property in QB
elements.bean_115.altPhone = '999-999-9999'
// Write the record back to QB - WARNING: this will overwrite the Alt Phone field on this record
elements.bean_115.update()

If all went well, you're now talking to Quickbooks from Servoy with only 4-5 lines of code!

HELP Files
When you unzipped the ibiz files, it should have created a Javadoc directory. Go to this directory and open the file "index.html". In this file you will be able to lookup all the properties and methods for each class available in the bean. There are many object types you can work with in Quickbooks (i.e. payments, invoices, customers, etc) All are documented in Javadoc.

In our next article, I will describe how to utilize the ibizqb.jar objects directly, without having to use a bean on a form. This will allow you to create multiple instances of each object and put them into arrays, allowing you to do things like hold all customers in memory at once, instead of reading them one at a time.

Friday, April 4, 2008

[Java Plug-In Development] How to Add Your Own Column Validators and Column Converters with the Plug-In API

While in the Dataproviders area of Servoy, there are column properties that allow you to choose Validation, or Conversion for that column.  In this post, I'll show you how to create plug-ins to add your own items to those lists.

Column Validation

Servoy has several built-in validators that are included in the default_validators.jar plugin that ships with Servoy.  In addition, I have a free plugin at Servoy Guy:  Validator Pro. However, you may want to use the Java Plugin-API to add your own items to that list, so here we go...
  • Make a new class, lets call it ValidatorPlugin.java and have the class implement IClientPlugin, and IColumnValidatorProvider. (com.servoy.j2db.plugins.IColumnValidatorProvider)
  • If you have eclipse automatically include the required methods from those classes, you'll have a few methods you'll need to implement.  Most are self-explanatory, but the main one is "public IColumnValidators[] getColumnValidators()".  That method needs to return back an array of classes that implement IColumnValidator.  So, onto our next class...
  • Make a new class, lets call it MyValidator.java, and have the class implement IColumnValidator. (com.servoy.j2db.dataprocessing.IColumnValidator)  Again, if you have eclipse move in the required methods, you'll see several to implement
  • First, there is "Public Map getDefaultProperties()".  This needs to return back a Map of properties that will be shown to the user when they choose this validator.  For example, the servoy.SizeValidator shows "length" as a property.  So, here you can have it return back the properties you want the user to be able to input
  • Second, there is "public String getName()".  This returns back the name that shows up in the validator.  So that your validator doesn't conflict with any others use a notation like companyName.validatorname.
  • Third, there is "public in[] getSupportedColumnTypes()".  This returns back an array representing the different column types that this validator can be used on, like TEXT, INTEGER, NUMBER, etc.  To get those integers you can use com.servoy.j2db.persistence.IColumnTypes .  For example com.servoy.j2db.persistence.IColumnTypes.TEXT
  • Finally we get to the meat of this class.  There is "public void validate(Map props, Object arg) throws IllegalArgumentException".  This passes in the a Map as the props variable which allows you to know what properties the user entered for those available properties.  It also passes in arg as an Object, which represents the value in the column being validated.  Here is where you'll put you own business logic to determine if the input is valid.  If it isn't valid you must throw an IllegalArgumentException
  • So, now lets go back to our ValidatorPlugin.java class, and have it return back a new set array, like "return new IColumnValidator[]{MyValidator}

Column Conversion

Again Servoy has a JSON column conversion built in allowing you to serialize objects. In addition, I have a free plugin at Servoy Guy: Column Converter Pro.  Again however, you may want to use the Java Plugin-API to add your own items to that list.
  • Make a new class, lets call it ColumnConverterPlugin.java and have the class implement IClientPlugin and IColumnConverterProvider. (com.servoy.j2db.plugins.IColumnConverterProvider)
  • You'll now need to implement "public IColumnConverter[] getColumnConverters()".  Just like before, this needs to return back an array of objects, but this time they are IColumnConverter classes.
  • So make a new class, lets call it MyColumnConverter.java, and have it implement IColumnConverter (com.servoy.j2db.dataprocessing.IColumnConverter)
  • First, there is "Public Map getDefaultProperties()". This needs to return back a Map of properties that will be shown to the user when they choose this validator. For example, the StringSerializer shows "length" as a property. So, here you can have it return back the properties you want the user to be able to input.
  • Second, there is "public String getName()". This returns back the name that shows up in the converter. So that your validator doesn't conflict with any others use a notation like companyName.convertername.
  • Third, there is "public in[] getSupportedColumnTypes()". This returns back an array representing the different column types that this converter can be used on, like TEXT, INTEGER, NUMBER, etc. To get those integers you can use com.servoy.j2db.persistence.IColumnTypes . For example com.servoy.j2db.persistence.IColumnTypes.TEXT
  • Next, there are 2 methods that do the bulk of the work...
  • "public Object convertFromObject(Map props, int columnType, Object obj)": passes in the properties that the user defined, an integer representing the column type, and an object representing the value of the data in the column.  Here you can write your own business logic to determine what you want returned back to convertFromObject.
  • "public Object convertToObject(Map props, int columnType, Object obj)": passes in the properties that the user defined, an integer representing the column type, and an object representing the value of the data in the column. Here you can write your own business logic to determine what you want returned back to convertToObject.
  • Finally, lets go back to our ColumnConverterPlugin.java class.  Our getColumnConverters needs to return back our converter class.  Such as "return new IColumnConverter[]{new MyColumnConverter.java}".  In your example, you may choose to return back a new array of IColumnConverter objects, or just return back a static set stored in a variable.
So, after compilation, and added to the plugin directory, you should now have your plugin working with Column Converters and Column Validators.  Don't forget to create your jnlp file if you need this working in Smart Client.

Author: Scott Butler, Senior Sales Engineer, Servoy USA

Wednesday, March 5, 2008

[Java How To] #3 Creating MD5 Hashes Without a Plugin

*UPDATE: Servoy 4 appears to provide a built-in function for creating base-64-encoded, MD5 hashes. The function is located in "Utils" and as of RC1 is named "stringMD5HashBase64".


A PDF version of this post, which includes a code walkthru, is available here



Java How-To's are intended to provide real-world examples of how Java can be used to easily extend Servoy in useful ways. I will try to post a new one as often as possible.

Description

If you thought you needed a plugin to create MD5 hashes, think again. Because Servoy has such great support for Java, you can actually create MD5 hashes without using a plugin, by simply embedding some Java code directly within your Servoy method.

Java Classes Used

For more information about any of the Java classes used, click their corresponding link below.


Total Lines of Code

20 or so

The Servoy Code

var string_to_hash = 'Hello World!';

// Get an array of bytes from the input string
var in_array = Array(string_to_hash.length);
var in_char;

for (var i = 0; i < in_char =" string_to_hash.slice(i,i+1)" inbytearray =" new" i =" 0;" md =" Packages.java.security.MessageDigest.getInstance(" md5_bytearray =" md.digest(in_array);" md5_hash =" '';//empty" md5_array =" new" i =" 0;"> 2) {
// Take right most 2 chars
md5_array[i] = md5_array[i].substr(md5_array[i].length - 2, 2);
}

if ((md5_byteArray[i] >= 0 ) && (md5_byteArray[i] <= 15)) { // Pre-pend a '0' since the hex to string fails to do so - typical to forget! md5_array[i] = '0' + md5_array[i]; } md5_hash += md5_array[i];//concatenate } return md5_hash;

In Summary

That's it! Creating MD5 hashes without a plugin. Please post any questions or comments you may have to the blog.

IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

[Harmless Hacks] Hacking Servoy's Frame Title & Icon


This post is only available in PDF format. You can download it here.


Have you ever wanted to change the title or the icon image when you deploy your Servoy solution?

In this blog post I will show you how it can be done using some Java knowledge...


The Servoy Code

//2008.March.01
/*
Sets the top level window title and/or icon.
Author: T. Parry, Prospect IT Consulting Inc, venture@compmore.net

Ensure this is called after servoy has finished messing with the title.

Default image is/was greek letter psi: 'd:/temp/icons/images/Math/psi.gif';
Default title is/was: 'IT Service & Support Toolkit by Prospect IT Consulting'

The place where it is best to use this is...
*/
var myTitle = null;//no change
var myIconImageLoc = null;//no change
if (arguments && (arguments.length > 0)) {
if ( arguments[0] ) {
myTitle = arguments[0];
}
if (arguments[1]) {
var myIconImageLoc = arguments[1];
}

var frames = Packages.java.awt.Frame.getFrames();
if (myTitle) {
var prevTitle = frames[0].getTitle();//save it or do something with it
frames[0].setTitle(myTitle);// [0] is the top most frame - set a new title
}
if (myIconImageLoc) {
//var myIconImage = new Packages.java.awt.image.BufferedImage;

var kit = new Packages.java.awt.Toolkit.getDefaultToolkit();
var imageToUse = kit.getImage(myIconImageLoc);
frames[0].setIconImage(imageToUse);
}
}//if arguments

return;

The Servoy Code (Using an Image From the Media Library)

frames[0].setIconImage(new Packages.javax.swing.ImageIcon(new Packages.java.net.URL("media:///my_image.gif")).getImage());

IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

Tuesday, February 19, 2008

[Java How-To] #2 Writing XML Without a Plugin

*Update: Because of the inherent support for E4X in Rhino 1.6r1 and above, Servoy 4's support for XML is greatly improved. For more information, see the "XML" and "XMLList" nodes in the "JS Lib" within Servoy Developer's new  "Solution Explorer."

Java How-To's are intended to provide real-world examples of how Java can be used to easily extend Servoy in useful ways. I will try to post a new one as often as possible.


Description

If you thought you needed a plugin to write XML, think again. Because Servoy has such great support for Java, you can actually write XML documents without using a plugin, by simply embedding some Java code directly within your Servoy methods. The amount of code it takes to create an XML document complete with processing instructions, attributes and comments is minimal, and is shown below...

By the way...Servoy 4 (from what I have heard) introduces the ability to write XML documents without having to script any Java *or* use a plugin :-) To learn more about that, read up on Rhino (1.6 or greater).

Java Classes Used

For more information about any of the Java classes used, click their corresponding link below.

Total Lines of Code

Less than 15

The Servoy Code (Creating an XML Document)

var document_builder_factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();

var document_builder = document_builder_factory.newDocumentBuilder();

// Create document
var doc = document_builder.newDocument(); // Doc is an object

// Create and append a processing instruction
var processing_instruction = doc.createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"http://www.domain.tld/style.css\" media=\"all\"");
doc.appendChild(processing_instruction);

// Create root element and append to document
var root_element = doc.createElement("root");
doc.appendChild(root_element);

// Insert a comment in front of the root element
var comment = doc.createComment("I am a comment");
doc.insertBefore(comment, root_element);

// Create a child element ("child1") of the root element
var child_element1 = doc.createElement("child1");
root_element.appendChild(child_element1);

// Create an attribute for child element1
child_element1.setAttribute("attr", "value");

// Add a text node to child_element1
child_element1.appendChild(doc.createTextNode("Child 1"));


The Servoy Code (Writing Your XML Document out to a String)

var transformer_factory = new Packages.javax.xml.transform.TransformerFactory.newInstance();

var transformer = transformer_factory.newTransformer();

var dom_source = new Packages.javax.xml.transform.dom.DOMSource(doc); // Pass in your document object here

var string_writer = new Packages.java.io.StringWriter();

var stream_result = new Packages.javax.xml.transform.stream.StreamResult(string_writer);

transformer.transform(dom_source, stream_result);

var xml_string = string_writer.toString(); // At this point you could use the Servoy XMLReader plugin to read your XML String.

application.output(xml_string);


In Summary

That's it! Writing XML without a plugin. Please post any questions or comments you may have to the blog.

IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

Monday, February 18, 2008

[Eclipse] Finding an Eclipse Plugin


A PDF version of this post, complete with screenshots, is available here.


One of the issues I had with learning eclipse early on was the frustration of finding all those dependent plugins that were prerequisites for the plugin I wanted to load. First I would find the dependent plugin, load it then load my new plugin only to find another dependency showing up.

Then I stumbled on the update manager and life is far easier now! (Although you can still do the installation the tedious way if you really have to.)

Instead of downloading the files from the supplier site and installing them yourself to the correct eclipse plugins directory use the update approach instead.

The update approach works for most plugins that I have encountered so far. Here is the way that it works:

From the eclipse Help menu select "Software Updates" then "Find and Install". A dialog pops up with a choice of "Search for updates of the currently installed features" or "Search for new features to install". The latter is the choice that you want.

Now a dialog pops up (“Update sites to visit”) with a list of check boxes for features and various buttons. In your case click on the "New Remote Site...". In the next dialog enter some name by which you want to remember the site such as "Omnesoft", and enter the url on the next line.

For example, I know Jeff wanted to use an obfuscator plugin so enter "Obfuscate" for the name. For the url you should open your browser to the site of the plugin provider and search for the eclipse plugin update url. In his case he first chose http://obfuscate4e.partmaster.de/download.

However, this gives rise to errors if you continue. Digging deeper into the site you will find the correct url as follows:

http://obfuscate4e.partmaster.de/updates.

This is the url specifically for the eclipse update manager to use.

Clicking OK closes this dialog and returns you to the “Update sites to visit” dialog. The site that you have entered now shows up with a check box beside it.


Having entered the info for the new remote site you still do not know if there are dependencies for the new plugin (unless you were really diligent and actually read the new plugin site for instructions!).


Now click on the finish button to go to the next stage. At this point the manager is merely searching for the "updates" and "new" plugins.

Now the “Search Results” dialog pops up. It actually shows you the results of the search, amazing! Of course you might get the error message if you site url is incorrect. Now check the box beside the Obfuscate to indicate that you want this to be installed. (If you expand the selection you can find all the components that are in the selection).


Here is where the manager shines: click on the "Select Required" button to allow it to search for dependencies and populate the list of features with those others, if any. You should get into the habit of clicking on this button to save some aggravation later! You may or may not see additional features to be installed. You may have already installed some pre-requisite plugins from an earlier feature install.


One last bit of setup: click next to accept the license terms (or abandon if it is not for you!) in the new dialog box “Feature License”.


Click next again to finally get to the “Installation” dialog. Wow that is a l ot of setup. Now you see a list of the features and their description that have been selected for installation. Usually the default installation location is ok, but you can can change it if you know the consequences. (Meaning that you have some advanced knowledge that has been painfully extricated from the various help guides).


One last click of the “Finish” button and ...oops you may get a “Duplicate Conflicts” detection dialog popup. This really means that some version of a plugin already uses a version of a plugin and there might be two versions. Well now is where your risk taking part of your brain starts to vacillate. (In other words do a backup of your entire eclipse directory structure if you are unsure in case the warning really does kill the eclipse setup!). Being bold we continue anyway...


So the “Update Manager” windows appears and starts to initialize but whoa...another warning pops up! My goodness who wrote all this paranoia code? Well I for one appreciate the warnings so I can make an, ahem, informed decision.


A “Feature Verification” dialog pops up and is requesting you to make yet another commitment. I typically just click the “Install All” button because I get fed up reading all the warnings from all the dependent features! Well I do live dangerously.


Assuming all goes well the last dialog asks if it can restart eclipse for the changes to take effect. So this is it. Might as well continue and take the plunge and test it...restart it is.


So by the time eclipse shuts down and restarts your fourth coffee is now cold. Go and check that the feature you have installed is installed properly. Since there are many types of plugins you will have to do that part on your own.


Good luck now.


Rolling your own”.

For those wanting to install their own plugins into the eclipse directory and then find that a plugin is still missing from another source then follow these steps.


On the eclipse web site for plugins do a search for the missing plugin.


Try this central site first and choose a secondary site that best suits your needs.:

http://www.eclipse.org/community/pluginsites.php


Read the instructions for this missing plugin/feature in case it too has dependents that have to be loaded. For example Matisse, the GUI designer for Java, has three or more plugins for it to run properly.


Jeff's problem: (finally!)

Searching for documentation on eclipse plugins is somewhat tedious. When I started searching for “org.eclipse.pde” under plugins it failed, so I tried “pde” by itself and got some answers but they did not stem to be a good match. Digging around a bit more I thought I would see if it was a project under eclipse and found:


http://www.eclipse.org/pde/


This has a good description of the project. PDE is the “Plug-in Development Environment“ for those wishing to make plugins for eclipse. There you can find that it is comprised of two components itself.


Note that this statement:

“PDE is built atop the Platform and JDT, and ships as part of the Eclipse SDK. “ indicates that pde should have been installed with the original eclipse install but perhaps there was something not quite right about the initial installation so you might want to revisit that to ensure that pde is already there or not.


By searching for a list of projects I did find the PDE project itself and the download here:

http://www.eclipse.org/projects/project_summary.php?projectid=eclipse.pde


I hope that this is not TMI (too much information).


Regards,

Tom

Monday, February 11, 2008

[Docs] Eclipse QuickStart for Servoy Developers

Tom Parry of Prospect IT Consulting, Inc. has been kind enough to compile a number of excellent Eclipse learning resources into a FREE document for Servoy Developers. The document is entitled "Eclipse QuickStart for Servoy Developers" and is available for download by clicking here, or clicking the "Eclipse QuickStart" link under the "Whitepapers/Other Downloads" heading.
Tom has invited your criticisms and commentary, and has also agreed to supplement the document with additional information where necessary, per your requests.
To reach Tom regarding his QuickStart document, drop a comment on this blog or e-mail him directly. His e-mail is available in the QuickStart document.

Wednesday, January 30, 2008

[Java How-To] #1 FTP Without a Plugin

Java How-To's are intended to provide real-world examples of how Java can be used to easily extend Servoy in useful ways. I will try to post a new one as often as possible.

Description

If you thought you needed a plugin for FTP, think again. Because Servoy has such great support for Java, you can actually perform FTP functions without using a plugin, by simply embedding some Java code directly within your Servoy methods. The amount of code it takes to create an FTP client, and perform a non-secure FTP GET or PUT action [for example] is minimal, and is shown below...

Java Classes Used

For more information about any of the Java classes used, click their corresponding link below.

Total Lines of Code

Less than 20

The Servoy Code (GET)

var FTPClient = new Packages.sun.net.ftp.FtpClient();
FTPClient.openServer("myserver.com");
FTPClient.login("usrname", "password");
FTPClient.binary();
//FTPClient.cd();

var buffered_input_stream = new Packages.java.io.BufferedInputStream(FTPClient.get("myfile.txt"));

var output_stream = new Packages.java.io.FileOutputStream("/save/path/myfile.txt");
buffered_output_stream = new Packages.java.io.BufferedOutputStream(output_stream);

var buffer = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);

var read_count = 0;

while((read_count = buffered_input_stream.read(buffer)) > 0)
{
buffered_output_stream.write(buffer, 0, read_count);
}

buffered_output_stream.close();

FTPClient.closeServer();


The Servoy Code (PUT)

var FTPClient = new Packages.sun.net.ftp.FtpClient();
FTPClient.openServer("myserver.com");
FTPClient.login("usrname", "password");
FTPClient.binary();
//FTPClient.cd();

var write_count = 0;

var bytes_in = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);

var file_input_stream = new Packages.java.io.FileInputStream("/Local/file/path/foo.gif");

var buffered_output_stream = new Packages.java.io.BufferedOutputStream(FTPClient.put("/Remote/file/path/foo.gif"));

while ((write_count = file_input_stream.read(bytes_in)) >= 0) {
buffered_output_stream.write(bytes_in, 0, write_count);
}

file_input_stream.close();

buffered_output_stream.close();

FTPClient.closeServer();


In Summary

That's it! FTP without a plugin. If you would like to see the code for other FTP functions, drop a comment on the blog.


* The classes that Sun includes with the Java 2 SDK, Standard Edition, fall into package groups java.*, javax.*, org.* and sun.*. All but the sun.* packages are a standard part of the Java platform and will be supported into the future. In general, packages such as sun.*, that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc).


IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

Friday, January 18, 2008

[Misc] 150 Downloads from 20 Countries!

"Java for Servoy Developers" is certainly getting some good attention, with more than 150 downloads from 20 countries in just a couple of weeks!

Just a reminder, if you have read the whitepaper and wish to provide feedback, please drop a comment on this blog. Anyone with a Google account can write comments.

Thanks for your support!

Wednesday, January 2, 2008

[Commentary] Hidden Tasty Goodness

I really enjoyed reading Jeff's "Java for Servoy Developers" tutorial - it was really a good first-pass at helping non-Java folks understand that they can write Java code directly in the product.

I don't think that functionality is necessarily "hidden" - but it's also not completely obvious, either. We do state all over the place that you can write Java in Servoy - but we don't tell you "how" to do it. That's really not our place as a tool developer.

There are excellent resources available (a lot of them are outline in the paper) - and it just takes a little playing around to familiarize yourself with how stuff works.

I'm not a Java programmer - never even read a book - but I was able to follow Jeff's tutorial and get some basic Java working. There are TONS of things you can do in Java - and the best part is - chances are good that someone else already has!

There is loads of Java code all over the Internet that you can use as reference, as well as hundreds of beans and applets that will make your Servoy experience as advanced as you want to make it.

So - go ahead - try it out. You'll be glad you did.

Bob Cusick
Servoy USA

Monday, December 31, 2007

[Docs] Welcome

Welcome to Java for Servoy Developers – a blog created to facilitate community support for all things Java and Servoy.

If you have not yet read the "Java for Servoy Developers" whitepaper, I suggest you do as it lays the foundation for learning Java within the context of Servoy, and is a great starting point for anyone interested in better understanding Servoy's Java capabilities.

This blog is sponsored, managed and maintained by Jeff Bader. And is contributed to generously by the Servoy community.