Creating a new Thread in Vaadin Java with GWT Graphics - java

I'm creating my first Vaadin Project and I have lots of problems understanding how it works. I created a new widget, that uses GWT Graphics and I drew some objects on the screen. However sometimes, instead of displaying the DrawingArea, my browser shows me this error
Widgetset 'com.example.jtpwebapp.JtpwebappWidgetset' does not contain implementation for com.example.jtpwebapp.MyComponent. Check its component connector's #Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.
The other components are just fine. For example, this error shows up if I simply create a new Thread
new Thread() {
public void run() {}
}.start();
The widgetset re-compilation gives me no errors. I'm not changing the #Connect mapping nor editing the module file.
There is really not much code to share, I created a new Vaadin widget using the Eclipse plugin and edited only in a few places.
I get this error also, when I try to make my widget implement a ClickHandler.

GWT only contains an emulated subset of the Java runtime environment. Thread is one of the classes that's not included; JavaScript doesn't support threading so there's no way for the GWT compiler to generate the code for it. The full reference of what's supported is available here.
Now, missing emulation does unfortunately not show up at compile-time, but GWT does perform checks against the JRE emulation library. You just have to run your app in developer mode. The Debugging Client-Side Code section in Book of Vaadin does a pretty good job at explaining how to achieve that with Vaadin.

Related

Save and reload layout in Eclipse 4 RCP

I am doing application using Eclipse 4 rcp. I general it is single perspective UI with layout based on Part View's, what allows me to drag, and reorder layout. Problem is that it is automatically persisted.
Is it possible to handle that process? I would like to create handler which would reset my layout to stock.
I saw tutorial here: Eclipse 4 Model Persistence - Tutorial but did not catch that point:
-Should I really override ResourceHandler.
-What is required to write hadlers like in example. Because line:
E4XMIResourceFactory e4xmiResourceFactory = new E4XMIResourceFactory();
Resource resource = e4xmiResourceFactory.createResource(null);
throws compile time exception:
The type org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl cannot be resolved. It is indirectly referenced from required .class files.
I maybe someone can explain or give a simple example, how to handle basic persistence of layout. Or at least hot to revert it to such, which was programmed
Include the plugin org.eclipse.emf.ecore.xmi in your plug-in's dependencies to resolve XMIResourceFactoryImpl (and org.eclipse.emf.ecore for Resource)
The author of this tutorial is one of the main Eclipse developers and his tutorials are usually accurate.
If you just want your application to always start with the original layout you can specify the -clearPersistedState option in the program arguments in your xxx.product file. You can also use -persistState false to stop the persistence of the model altogether.

GWT example app and the GWT Designer: what you see is not what you get

I am new to GWT. Followed the GWT docs to set up the Google plugin and the GWT designer in Eclipse "Juno" (V4.2). Created a Web application with the example code. It runs and displays nicely in Firefox:
Then I open the Java class that implements EntryPoint using the WindowBuilder, and the canvas shows something different. The input field label "Please enter your name:" is not visible, and the "Send" button is under the input field, rather than to its right. Screenshot below:
Since the whole point in using the GWT designer is to get the layout right visually, it is kind of disconcerting to see it not working in a WYSIWYG manner with the example code.
Question A: Is there a way of fixing this discrepancy? Are there some config files or HTML or CSS that perhaps need to be edited so that the designer's view matches what the browser would display when the example app is running?
Question B: Is the GWT designer working "as advertised" in your everyday practice? Can I trust this tool? If not, what alternatives would you recommend?
I found the GWT designer a pita tool on eclipse platform which takes memory hogging to whole new level even in comparison to GWT Hosted mode!!!!!
List of GWT Articles from Dev Guide on google.
Preferre Option at enterprise workplace
HTML/CSS/UIBinder for rich look and feel
Handcoded GWT Layouting and Widgets for complex gui behaviour/performance.
Edit - *GWT Designer is hardly updated/maintained* - I have seen only 10 odd checkins in a year. I wish i am wrong ( does google team not update the public svn !!! ) - https://code.google.com/p/gwt-designer/source/list
It becouse in the example project, Gwt inject widgets to existed html. So, you have one part of style in html, and second part in rendered gwt widgets. And it is looks ugly.
If you will use only gwt style approch (without any html styles, e.t.c), designer will be predictable and totaly wysiwyg.

Refreshing Swing application with Eclipse/MyEclipse

Say that we are writing a Java Swing application and we use Eclipse or MyEclipse to develop it. In web applications, you make code changes, you save and your ant deployment file takes care of the deployment of the changed files. Then you just refresh or hard refresh the web page and the changes appear there. Can we do the same thing for a Swing applications so that we don't have to close and open the program from the beginning every time we make a change?
I don't think so because you need hot code replacement ! Maybee using another framework.
You can't simply do that because once JVM is started, it loads the class files once and will not reload it untill next loading request. But you can use ClassLoader to load modified class files dynamically.
The following two articles may help:
IBM article on "hot class swap"
"Who Said Runtime Class Reloading Is Hard in Java?"
The first one is in Chinese, but you can look at the code and the result. I think the second article is more helpful for a GUI application.
In MyEclipse you can start your application in debug mode instead of run mode and changes you make will be pushed to the target VM; if changes you make cannot be replaced you'll see a dialog informing you the replace failed and you will need to restart your application. You don't need to place any breakpoints in the application, just starting in debug mode is sufficient.
As Guillaume states above, changes to the class structure will typically not be hot-synched, but changes within existing methods should be fine.
Obviously, how successfully hot-synched changes affect your running application would depend on your application design.

Using OSGi to attach JMenuItems to GUI

I have created an application and now I want it to make a plugin ready. I have decided to use Apache Felix and after reading tutorial, I am not sure, whether it was a choice that I wanted to.
I want to change my application, so that it loads at the beginning Bundles from /plugins folder and adds every Bundle as a JMenuItem to JMenu. I could have done it using ClassLoader, but I thought OSGi was exactly what I wanted, but then I encountered some problems:
there is a command line for OSGi, but I need it to be implemented in my application, without any user interaction, hard code its default behaviour in code.
there is behaviour of a Bundle ( start() and stop() methods inherited from org.osgi.framework.BundleActivator) that Bundle invokes at the beginning, but I actually want my application, to do something with a Bundle, not a Bundle to do something with an application.
So could you tell me, whether it is possible to make it using OSGi (etc. Apache Felix) or should I implement it using ClassLoader and then explicitly convert a .jar plugin's Main Class to JMenuItem and add it to my JMenu (it is worse, because it doesn't support dynamic change of application and doesn't give me a chance to learn OSGi).
EDIT: I am thinking about sth like: http://karussell.wordpress.com/2009/09/16/plugable-swing-a-hello-world-osgi-example/ , but I cannot find any tutorial.
Why would you create a menu item for every bundle that exists in the view? That doesn't really make sense.
You /could/ do it by creating your GUI app, and then in the start() method, persist the context and then use that to query a list of all bundles in the system. You would probably want to do that on demand when your menu was shown (so you see a current list).
However, you're really thinking in the wrong direction. What you want to do is look for /services/. When a service comes in, you use that service to populate your menu item. That way, you can have multiple services per bundle and the services can have some form of interaction.
Neil Bartlett and myself did a talk on exactly this approach for a Swing-based application (though using registered Action objects). The demo and presentation are still available from this location:
http://www.eclipsezone.com/files/jsig/
Note that this was done at the time of OSGi v4, so you might find the install fails with a mismatched version of the import framework. If so, crack open the file and ensure that it doesn't say Import-Package: org.osgi.framework;version="[1.3.0,1.4.0)" or some such - get rid of the version numbers and it should still run fine today.

Dynamic language switching in an Eclipse RCP application

I am working on an Eclipse RCP application with localization. A user should be able to change the language used in the application on the fly. A restart of the application should not take place during this language switch. It should also be possible to switch between languages written from left to right and languages written from right to left.
Is there a (good) way to solve this problem?
According to this thread:
Most of the eclipse libraries load up their language info on widget creation. If you change your locale afterwards you need to restart eclipse to have it take effect.
You could write that kind of dynamic behaviour into your own SWT program, however (when the locale switches, you'd need to call setText(*) on everything :-)
So this is not currently managed dynamically unless you program it yourself...
Other rcp/plugins application like Birt specify the same instructions (i.e. "Restart Eclipse" at the end...)
That said, a slightly different problem was set in this thread:
switch the language setting, restart, and then run in that language
I got it to work by reading bug 222023 and mimicking org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction
I tried it manually:
added "-configuration #user.home/.myapp/configuration" to the launcher.ini
added "osgi.nl" to the users config.ini residing there and it worked.
Since I can access the config-Location via Platform.getConfigurationLocation() I guess that could be the way.
Note: adding "osgi.nl" to the webstart jnlp works too.
You would need to call setText on each widget, with the respective text. Since there is no text variable mapping on the widgets, you would have to do that completely manually as well.

Categories