Showing posts with label rcp. Show all posts
Showing posts with label rcp. Show all posts

Monday, February 18, 2013

Talking about INSPIRE: of Humboldts and Hales

I just wrote a blog post about the Humboldt Alignment Editor here. It is written in Italian and I don't think I will have the energy to translate it in English right now (sorry!), but for the tutorial part, I think that google translate might do the trick. :)
Obviously if you have questions, just post them here, I will be happy to answer.



Friday, November 4, 2011

HyUml apps for yUML

Woa... it has been a busy time and my posting force has really dropped. There are a lot of news in the jgrasstools, uDig and open source world to tell about, but for now I will just announce this (I do not need my brain to write about certain things).

I recently got in need to be able to do some design on the road on an android tablet. So I started to search in the market and found some apps. They all were posing as gui to the really nice yUML project.
I found that an amazing idea, but the available tools didn't have certain features I felt were necessary:

* to have an editor and uml view aside of each other
* be able to easily load and save files and dump the image to disk
* be on both android and desktop

That is why I started HyUml:


It is already very usable and it is coded in really few time and with no resources, but it serves the purpose and I am having a good time with it. It is obviously open sourced, so maybe you can also make use of it.

Some snaps:

RCP Version:


Well, maybe I should add that in the lower left panel you get the html img tag text that you can put inside a wiki to have the diagram generated there. This is nifty :)


Android version:



While the android version is in the market, the rcp version has to be built as an eclipse application. For thos interested in the source code of the two projects, they are both on bitbucket on the hyuml repository.

Enjoy..

Wednesday, April 27, 2011

Open the properties view

Why do I always forget? Need to nail it down.

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.ui.views.PropertySheet");

Thursday, August 5, 2010

PreferenceConverter

I was wondering how to save colors or non int/double/boolean/string values into rcp preferences. As usual it is very easy if you know the tool to use. :)

So from Color -> Preference

IPreferenceStore store = ...
Color red = Display.getDefault().getSystemColor(SWT.COLOR_RED);
PreferenceConverter.setDefault(store, "COLOR_KEY", red.getRGB());


And back: Preference -> Color

RGB colorRgb = PreferenceConverter.getColor(store, "COLOR_KEY");
Color red = new Color( Display.getDefault(), colorRgb);


Same applies for example for Fonts or Rectangle and other nice things.

Thursday, July 1, 2010

java.lang.NoClassDefFoundError: javax/media/jai/iterator/RandomIter

Man, this is the last time you fool me!
At least so I wished... anyways...
You are writing an eclipse RCP application that bases also on JAI?

Well, you might incur into the error:
java.lang.NoClassDefFoundError: javax/media/jai/iterator/RandomIter

or something similar.
Also you would swear that the jars are in your classpath.
Also you will browse the whole internet for solutions.
Also you won't find them. (at least I didn't)
Because the ease of all this is in running the application with the following VM argument:

-Dosgi.parentClassloader=ext



When I don't create new RCP apps in a while it fools me again. Also you should not try to solve this between 11 pm and 1 am. It would fool you... again.




As suggested a small addition: In my case the problem is due to the fact I use to keep the jai jars inside the jre and therefore it is needed to tell the classloader to load also the jre extentions (which is where I keep the jars).

Saturday, April 18, 2009

Custom crs and startup memory

It seems that if Friday the 17th (in Italy) is ment to be a very bad luck day, then Saturday has to be a very lucky bugfix and hacking day.

I finally got to work on some bugs that were bothering the JGrass and BeeGIS community, and I also got a couple of things that might interest you.

The first is right now for Italians, but I will explain how it might get expanded to interested.
In JGrass we now finally ship a custom epsg database, which is basically extended with some reference systems that we need a lot in Italy.


So as you can see from the pictures, if you now search for Italian Monte Mario, you get also the more precise ones that contain the needed Bursa Wolf parameters (I borrowed them from daddy GRASS :) ).

If you have similar issues and need a particular reference system (existing and documented please :) ), drop a mail in the JGrass mailinglist and I might add it.


The second thing is related to many users having memory issues in JGrass. Since defining the java heap is not always easy in rcp derivates, I finally added a preference page:


Here you can define:
  • the workspace path: where your projects are by default created
  • the locale: the language code that defines the user interface translation
  • the memory: the memory in megabytes that you want JGrass to use

PS: the new versions of jgrass and beegis are right now uploading and it will take several hour from my home connection, so please wait until Monday :)

Tuesday, April 7, 2009

How to add a shortcut binding to JGrass

Alright, I wanted to be able to open the console editor by shortcut.
Here the steps to to achieve it.

1) create a command. Use the org.eclipse.ui.commands extention point to do so.

2) create a category for your new command(s) if you do not have one already. Rightclick on the extention point of point 1) , choose new and then category.

3) create a new command by rightclicking on the extention point as in point 2).

4) fill in some basic info, as name, description, category and a unique id for the command.

It should look like the following:


keep in mind the green part, we will need it later.

5) create an actionset with your action in it. Use the org.eclipse.ui.actionSets extention point.

Filling in the basic stuff will lead to the following:


Note that the blue part is the class that will actually exacute the action.

Instead the green part is the id of the command created before. The command will be the link to the shortcut binding, which we will create now.

6) create the shortcut throught the org.eclipse.ui.bindings extention point.

That would look like:



Only two things to note here:
  1. commandid, which is again the id of the command created in 1)
  2. the shortcut definition in sequence: ESC M1+E which results in a vi-like shortcut: first press ESC and then ALT-E

That should be all I think.

Monday, October 13, 2008

How to get GRASS related preferences into your code

What to do when you need the mapset that is currently set for doing calculations or even the path to the GRASS GISBASE?

Go and buy some at your preferred store:

ScopedPreferenceStore preferences = (ScopedPreferenceStore) ConsoleEditorPlugin
.getDefault().getPreferenceStore();

String mapsetString = preferences.getString(PreferencesInitializer.CONSOLE_ARGV_MAPSET);

String gisbaseString = preferences
.getString(PreferencesInitializer.CONSOLE_ARGV_GISBASE);

Wednesday, September 24, 2008

rcp cdrom permissions

You might wonder about the title, but that us exactly what I tried to google for when I tried to launch my rcp application (the GisPublisher, a minimal GIS to do data publishing from a readonly media like a DVD) from DVD.
Well, the application has a intro part inside which pdf documentation can be browsed, which is built on html pages that have to be dinamically created on application startup (see some screenshots under Pubblicazione DVD Pguap on this page).

To make a long story very short, the problem is that some files have to be parsed and modified, while the DVD id readonly.

Well, this has an easy solution, because the rcp system can copy a whole pile of files over to an ad-hoc created workspace on the users disk in his home folder.

To do so, you just have to create a config.ini file for the rcp product, which containes some lines like the following:



osgi.instance.area=@user.home/yourapp
osgi.configuration.area=@user.home/yourapp
osgi.sharedconfiguration.area=@user.home/yourapp



This in fact is not enough, and that can be the tricky part. To properly work, the plugins have to be exported packaged as individual jar archives (as the export dialog for plugins and fragments states) and not as folders.

Once those two easy things are done, the application will take a little while to startup the first time (depending on what it needs to copy over to the disk), but will work like a charm.

Tuesday, March 25, 2008

How to keep track of memory status

In our field of application, heavily using raster maps and analysing them, we get into out-of-memory problems rather often. Not always these exceptions are trapped and we end up waiting for something that will never come.

So one way to keep track of all this, is the nice FreeMem plugin by Markus Oliver. It is really easy to install throught the update manager (explained in the last post).
Just enter http://www.junginger.biz/eclipse/ as your new remote update site.

Install it and restart JGrass (Udig/Eclipse, it will work for all of them). In the list of loadable views there will be a new one, the FreeMem, which will look like this:



In the list of installable plugins there is also a RSS-feed reader. Just for fun I installed it also in JGrass and inserted as test the feed to this blog :)



I love this rcp environment!

Tuesday, March 18, 2008

How to load plugins from an update site

Imagine you want to install the very experimental and pre-pre-alpha beegis geonotes inside my current JGrass installation. What would you do?
Nothing easier than that:

1) in the help menu go on software updates -> find and install:



2) select on search for new features and go next:



3) push the New Remote Site button and enter the update site you which to install the plugin from. In this example I will use beesgis-extentions update site which is here:
http://www.beegis.org/upd-beegis/eu.hydrologis.jgrass.beegis-updatesite/




4) after clicking OK and finish, a list of available packages supplied by the update-site will appear. Select what you want to install:




5) next you will be asked to agree the licenses and so on.



6) if the packages are not signed, you will be warned and prompt about installation. If you are sure, just press install all.



7) you will be asked to restart JGrass. Do so and after restart you will find the geonotes layer in you mapgraphics and the geonotes tool in the info category tools.



The update is done. You can enjoy your new plugin.

To be honest there is one more step to go, since without the right database and database tables there is nothing to be done.

So get the database zipped from here and unzip it into some folder of your choice.

Now let's tell jgrass where the database is. Open the preferences, (Window->Preferences) and under HSQLDB server point to the unzipped geebisdatabase server:



Restart JGrass and the game is done.


PS: if you instead are interested in creating an update site for others, have a look at this nice article from the eclipse wiki.

Sunday, February 17, 2008

How to use the progressmonitor

This notes were in the udig developers manual, but they do not seem to exist any more (perhaps I just can't find them :)). However, before they get lost from the google cache (which is were I found them), I past them here for convenience:



* Always start the progress monitor and do at least 1 bit of work. For example:

monitor.beginTask("Working", 4);
monitor.worked(1);


* Always finish started job.

try{
monitor.beginTask("Working", 4);
monitor.worked(1);
// some work
}finally{
monitor.done();
}


* Make use of SubProgressMonitor if sending the monitor to another method:

try{
monitor.beginTask("Working", 8);
monitor.worked(1);

SubProgressMonitor sub=new SubProgressMonitor(monitor, 3);
doSomeWork(sub);
sub.done(); // don't forget to make sure the sub monitor is done

sub=new SubProgressMonitor(monitor, 3);
doSomeMoreWork(sub);
sub.done(); // don't forget to make sure the sub monitor is done (callee might not use it)

}finally{
monitor.done();
}

How to launch a tool programmatically

So you have your nice tool and want to launch it without having the user to click on a dedicated button?


IAction tool = ApplicationGIS.getToolManager().getToolAction(toolId, toolCategoryId);
tool.run();

Saturday, February 16, 2008

How to open a file with the OS standard application

SWT supplies a very nice class for this: org.eclipse.swt.program.Program
Just supply the absolute path to the file you want to open and the magic is done.



Program.launch(fullPath);

Monday, February 11, 2008

How to retrieve an image for an action or button

There are several way to achieve this:

1) many common images (undo, redo, file, folder, cut, copy) are available through the org.eclipse.ui.ISharedImages interface:

Image folderImg = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);


2) If you have your own image in the plugin path, with the help of AbstractUIPlugin:

ImageDescriptor imageDescriptorFromPlugin = AbstractUIPlugin.imageDescriptorFromPlugin(MyFunnyPlugin.PLUGIN_ID, "icons/stop.gif");

The good thing is that the path is relative to the plugin containing it (in this case MyFunnyPlugin) and is URL-alike, i.e. slash on every operating system.
Sometimes all you need is the descriptor, as in the case of actions:


Action stopGpsAction = new Action(){
public void run() {
// stop that thing
}
};
stopGpsAction.setImageDescriptor(imageDescriptorFromPlugin));


sometimes you need the image instead, as in the case of icons for buttons:


Button stop = new Button(commandGroup, SWT.PUSH | SWT.BORDER);
stop.setImage(imageDescriptorFromPlugin.createImage());



3) If however your resource lies in the same package of the calling class, you can exploit:

ImageData imageData = new ImageData(getClass().getResourceAsStream("legenda_pioggia.png"));
Image image = new Image(display, imageData);

Thursday, February 7, 2008

How to properly log errors, so that a user can send them to you

One of the biggest problems we had in the past in JGrass, was the fact that the users usually send an email to the list telling that JGrass "doesn't work". No other explenation, no way for us to understand. Since JGrass at that time was really buggy, it all got a mantainance nightmare.

The new JGrass has a solution to all this given by the Eclipse/Udig framework, which is the possibility to log the errors and let the user send the log to some poor guy that then has to understand what is happening. This is much better for us than the "doesn't work".

Obviously a developer will have to include some small snippet into his code to get the logging enabled. Here it is:

Step 1: insert the following code snippet into your Plugin Activator class



public static void log( String message2, Throwable t ) {
if (getDefault() == null) {
t.printStackTrace();
return;
}
String message = message2;
if (message == null)
message = ""; //$NON-NLS-1$
int status = t instanceof Exception || message != null ? IStatus.ERROR : IStatus.WARNING;
getDefault().getLog().log(new Status(status, PLUGIN_ID, IStatus.OK, message, t));
}


Step 2: call the logging method from every needed part of your code, i.e. everywhere an exception is thrown and you would like to know it.
For example in the JGrass catalog plugin that would look like:



try {
// ... your code
} catch (Exception e) {
JGrassPlugin.log("JGrassPlugin problem:eu.hydrologis.udig.catalog.internal.jgrass
#JGrassMapGeoResource#getIdentifier", e);
e.printStackTrace();
}


this would be an exception thrown inside the
class: JGrassMapGeoResource
package: eu.hydrologis.udig.catalog.internal.jgrass
method: getIdentifier

You do not think I wrote that by myself, right?
The Eclipse template engine helps you in this. If you want it the same as above, just add the following template to the java->editor->templates list (all in one line):


${pluginActivator}.log("${pluginActivator} problem:
${enclosing_package}#${enclosing_type}#
${enclosing_method}", ${throwable}); //$$NON-NLS-1$$



This will automagically insert the method-class-package, you just have to supply the plugin activator class name and the name of the exception.


If everything is done well then the user should be able to go under submit the log


And send us the content of everything that has been logged.



Please use that thing :)

Wednesday, February 6, 2008

How to easily add menus & actions to jface/swt viewers - adding a table row

Assume you created a nice new empty table to be filled by a user.
And let's say you created a first empty row with two columns.


List elements = new ArrayList();

TableViewer tViewer = new TableViewer(parent, SWT.MULTI);
table = tViewer.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableLayout layout = new TableLayout();
layout.addColumnData(new ColumnWeightData(50, true));
layout.addColumnData(new ColumnWeightData(50, true));
table.setLayout(layout);
TableColumn dateColumn = new TableColumn(table, SWT.LEFT);
dateColumn.setText("DATE");
TableColumn dischargeColumn = new TableColumn(table, SWT.LEFT);
dischargeColumn.setText("DISCHARGE");
TableLabelProvider sLP = new TableLabelProvider(); // implement this yourself
tViewer.setLabelProvider(sLP);
tViewer.setContentProvider(new ArrayContentProvider());
// the empty row
elements.add(new String[]{"", ""});
// set the input
tViewer.setInput(elements);


what to do very quickly to add a new row?
After fiddling a bit around with listeners and such stuff, I decided to exploit the menus:


// add a popup for new rows
MenuManager popManager = new MenuManager();
IAction menuAction = new NewRowAction();
popManager.add(menuAction);
Menu menu = popManager.createContextMenu(table);
table.setMenu(menu);


And how easy is the creation of the action?
Like that:


private class NewRowAction extends Action {
public NewRowAction() {
super("Add a new row");
}
public void run() {
elements.add(new String[]{"", ""});
tViewer .refresh();
}
}


et voila', right-click on the table and tell it to add the new row.

Friday, January 25, 2008

How to threat threads right when in the wrong thread

Not sure if it is only me, but sometimes you are in a display thread and you need to stop to do others gui things like open a dialog and ask the user something, but there is confusion about wrong thread access exceptions and if not that, then perhaps, the thing doesn't stop were it should and... and... if you feel like that, like panic, just sit down again, take a deep break and look what good guys can show you (not me, but the eclipse guys :))


goGo = false;

// create a thread and inside do a syncExec
Thread thread = new Thread(){
public void run() {
Display.getDefault().syncExec(new Runnable(){
public void run() {
SomeDialog someDialog = new SomeDialog();
someDialog.open(Display.getDefault().getActiveShell());
goGo = true;
}
});
}
};
thread.start();

// wait for the dialog to finish
while( !goGo ) {
try {
Thread.sleep(300);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}


and then finally do whatever you have to do with the asked result.

Thursday, January 24, 2008

How to solve the rcp-mozilla-browser exception problem in linux

As most of you probably know, the Eclipse-rcp environment uses native GUI resources, which steals to java the whole portability fun. The nice thing about it is that SWT looks 1000000 times better than swing (in the author's opinion).

One problem that could occur, is that some of the underlying resource is not found from time to time, as for example in the case of Linux OS and the swt browser widget.

The error thrown in that case is something like:
Exception in thread "Thread-3" org.eclipse.swt.SWTError: No more
handles [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]
at org.eclipse.swt.SWT.error(SWT.java:3589)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:292)
at org.eclipse.swt.browser.Browser.(Browser.java:109)
at...

It seems that the environmental variable MOZILLA_FIVE_HOME has not been set, so let's try to set it.
In my case I add to my .bashrc the following line:

export MOZILLA_FIVE_HOME=/usr/lib/mozilla-firefox/

and magic is done! (please take care that the folder is the right one. For example on my newest linux it is: /usr/lib/firefox/)

If the magic at that point should not be done, then probably you need to run:

sudo apt-get install xul-runner





Wednesday, January 23, 2008

How to join the JGrass development

There is an effort ongoing to create a n uptodate documentation on the JGrass wiki at the following page:

http://jgrass.wiki.dev.fsc.bz.it/jgrass/Setup_Development_Environment


Please give feedback on the manual, we are working on it and need to know where the problems are.


Note that the howto was kept on one single site in order to be able to export the tutorial as a pdf manual.




WARNING
THE PART BELOW THIS LINE IS KEPT ONLY FOR THE RECORD, IT IS NO MORE UPTODATE:

To develop on JGrass you need 2 things to start:

1) the udig development environment + some additional plugins needed by JGrass

There is a very nice quickguide from the udig community here to get started.
We supply the target platform needed to develop. This is the udig sdk plus some more plugins added that are needed by JGrass. These are from the eclipse framework, mainly due to the fact that we have a console and this one needs some editor addons.

You can get this all here just choose the latest. The content of this has to be set as target platform in your eclipse plugin development environment.

2) the whole infinity of JGrass plugins :)

At the moment there is no official release, therefore they have to be checked out from the official SVN repository, i.e. take all you can get from here. or simply do from commandline:

svn checkout https://svn.dev.cocos.bz//svnroot/jgrass/jgrass3.0/trunk



SOME NOTES:
  • trunc - here you find the base plugins, these should always work. Blame me if they don't!
  • community/moovida - this is my playground, so don't be too scared. Not all of the plugins are ready to rumble, but some of them will soon go trunc. What does NOT work or is NOT needed (i.e. DON'T blame me if they do not work):
    • eu.hydrologis.jgrass.advancedstyletest - is just a test for SLD stuff
    • eu.hydrologis.jgrass.mapgraphicdragger - drag legends and so for a walk
    • eu.hydrologis.jgrass.chart - has been a try for a view with BIRT charting
    • eu.hydrologis.jgrass.dwgdxf.datastores - this will come whenever there will be founds for it
    • eu.hydrologis.jgrass.feature - this is useless, for now
    • eu.hydrologis.jgrass.java2c2fortran.and.back - an example for bridging java-C-fortran in udig. Wrapped in an operation.
    • eu.hydrologis.jgrass.renderer.sites - renderer for old GRASS sites, not maintained for now
    • eu.hydrologis.jgrass.tools
    • eu.hydrologis.jgrass.ui
    • eu.hydrologis.jgrass.visad.libs - needs java3d
    • eu.hydrologis.jgrass.visad.view - needs java3d

last updated 2008_03_26