Posts Tagged ‘java’

* Eclipse Plugin Q&A

Posted on March 25th, 2009 by Dave Johnson. Filed under Web, phonegap, programming.

If you are one of the unfortunate few that has decided to, for profit or insanity, write an Eclipse plugin here are a few of the questions that I had during my ordeal and the answer or closest thing to an answer that I can come up with.

Q: How should I get started with Eclipse plug-ins?

A: Read a book. I did not do this and really regret it now I think. There are few different ones available that I assume explain all the intricacies. The Google can only help so much. Having said that, the approach that I took was to look at the code of another Eclipse plug-in and borrow from that :) Some of the better links I put up on Delicious.

Q: How do I make my plugin show up in the new project list?

A: This one seems like it should be easy to find out how to do but it actually wasn’t that easy. So it is pretty easy to get started using one of the samples in Eclipse like the file editor sample that creates a “New file” wizard. While that wizard does not launch from the “New project” menu it can be augmented to be a project creation wizard pretty easily. The important bit is setting project=”true” on your wizard in the plugin.xml file for the Eclipse newWizards extension.

<extension point="org.eclipse.ui.newWizards">
    project="true" ... />

Q: Now that I have a new project wizard how do I know that a project was created using that wizard or is that type of project so that you can create debug or run configurations accordingly?

A: This is where project “Natures” come in. A project can have different natures associated with it to support different functionality in Eclipse. You need to create a class that implements the IProjectNature interface.

public class PhoneGapProjectNature implements IProjectNature

You can reference that project Nature from the plugin.xml through the org.eclipse.core.resources.natures extension point.

<extension id="com.phonegap.phonegapnature" name="PhoneGap Nature"
    <run class="com.phonegap.project.PhoneGapProjectNature"/>
  <builder id="com.phonegap.phonegapbuilder"></builder>

This enables one to connect certain builders to a nature - in the case of PhoneGap we don’t actually use a builder since it is just HTML and JavaScript but we do set and read the nature from the plug-in code.

To set the nature of the project when it is created in the new project wizard we can set the project nature(s) on the project description like this:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription description =
description.setNatureIds(new String[] { PhoneGapPlugin.PHONEGAP_NATURE_ID });

In the case of PhoneGap, we use this project nature information in the properties of the Run and Debug configurations such that a developer can create configurations and choose the project that the configuration should launch when they click Run or Debug. In the configuration we iterate over the projects collection of the workspace and check if each project has the PhoneGap nature, if it does we add it to a combo box.

boolean bb = projects[i].hasNature(PhoneGapPlugin.PHONEGAP_NATURE_ID);
if (projects[i].hasNature(PhoneGapPlugin.PHONEGAP_NATURE_ID)) {

Q: How do I store preferences and configuration default values?

A: In your AddLaunch method of the LaunchAdder, which you call from the createProject method of your NewProjecWizard class like this:

  projectHandle.getName(), "");

you will need have some code like this:

ILaunchConfigurationWorkingCopy wc = DebugPlugin.getDefault()
.newInstance(null, DebugPlugin.getDefault()
wc.setAttribute("KEY", "value");
final ILaunchConfiguration config = wc.doSave();

Q: How do I access resources like files to populate a new project with?

A: Put any files that you will want to copy to a project into a namespace like com.phonegap.resources then you can access it like this:

String rootContent = StreamUtils.readContent(
this.getClass().getResourceAsStream("/com/phonegap/resources/root.html"), null

Where StreamUtils is just a wrapper for doing the stream reading.

Q: I am getting a “class not found” error when I debug what should I do?

A: Get Eclipse 3.4 if you don’t already have it.

Q: I want to support the debug / run menus but to do that I need org.eclipse.debug.ui/core references - where do I find those?

A: Add them to the dependcies list in the plugin.xml visual editor. First add core then the ui one will be available.

That’s about all I can muster for the moment but will try to put up some more tips later!

Tags: , , , , , .

* BlackBerry PhoneGap Progress Report

Posted on December 6th, 2008 by Dave Johnson. Filed under phonegap.

BlackBerry PhoneGap
We had a PhoneGap sprint just over a week ago which was pretty successful for me and my BlackBerry ambitions as well as everyone else. Through that sprint and over the past week, despite some setbacks, I got the OS v4.5 installed on my phone and the simulator on my computer giving me access to a few new things but I was sad to find that a few other things were still sorely lacking that are pretty important for something like PhoneGap. Just so you know, OS v4.5 is the latest OS that will run on my Curve 8310 - 4.6 will run on the Bold, Pearl Flip and newer Curves while 4.7 works on the Storm. The two biggest gaffs by RIM are in the BlackBerry web browser for OS v4.5 where that the following rather important features are missing:

  1. You can’t pass function pointers to setTimeout.
  2. You can’t access DOM Nodes in any way shape or form (aside from form fields). So there is no getElementById or innerHTML on the resulting nodes. This make web application development a little bit difficult.
  3. There is no XMLHttpRequest object.
  4. While not really expected, there is no SQLite support
    anywhere on the phone as of yet, let alone the browser.

Anyhow, despite those setbacks on the v4.5 OS I did get the communication between the BlackBerry device and the web page all dialed now. Not only that but I have implemented the W3C geolocation API and am going to follow that same pattern for the other APIs. Check out the geolocation JavaScript interface as well as the platform specific implementation.

In the actual BlackBerry code there is lots of boiler plate stuff. The main hurdle was figuring what the best (or any) way to embed the browser in the application was and enable communication between JavaScript in the browser and the BlackBerry Java code. In the end I pretty much had to take the route of implementing the browser myself through the BrowserContentManager. This means that I have to implement lots of functionality, but it also means that I am in control of cookies and responsible for accepting them from JavaScript in the web page through the implementation of the browser fields RenderingApplication.eventOccurred method when the event type is EVENT_SET_HTTP_COOKIE and returning them to JavaScript by implementing the RenderingApplication.GetHTTPCookie method.

When the set cookie event occurs I parse out the cookies looking for one named bb_command and expect it to contain some JSON object (that is parsed with the J2ME port of a Java JSON lib) with a command property (like for opening maps or getting the GPS location) and some arguments (like points to plot on the map or how long to vibrate for). The case statement just looks like this:

switch (command)
  case 0:
    this._getLocation = true;
  case 1:
      new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT,
  case 2:
      new CameraArguments()
  case 3:
    if (Alert.isVibrateSupported())
  case 4:
      new PhoneArguments(PhoneArguments.ARG_CALL,

where args is just a JSON string that the various methods like getPhoneNumber parse to get the args they want.

I will post some more specific code snippets like how to send text messages and so on very soon.

Tags: , , , , , , , , .

* Complete UI Q4

Posted on September 26th, 2008 by Dave Johnson. Filed under AJAX, JavaScript, Nitobi, completeui.

Some big changes are coming in the Q4 release of Complete UI. Big!

Of course there is a slew of JavaScript bug fixes for all the components with Grid receiving the most attention for IE 8, Safari 3, Firefox 3 and Chrome.

There are a bunch of changes to the Java side of Complete UI with more great JSP and JSF code to make it even easier to use Complete UI in your Java project.

Finally, we have also made huge changes to the ASP.NET Grid and Combo code - and are working on the rest of the components as I am writing this! I think that anyone using ASP.NET will be very happy with the new direction of the ASP.NET code :)
We are shooting for an on time Oct 1 release but there is so much we are trying to fit in it might be a bit late - but it will be well worth waiting for!

Tags: , , , , , , , .