I have headless (CLI) RCP app, normally handling command line options, but i'd occasionally need to show parts of the a gui anyway.
Is there a way to open a view part standalone(detached is fine) when PlatformUI/Workbench is not running?
WorkbenchPage.showView(the one I'd normally use to open the view) normally throws "workbench is not running" exception, which is expected of course in headless mode.
Is there some reasonable hack to do this? I tried running the RCP workbench with the event loop - the problem is that it's blocking execution and it seems too heavyweight.
I know I can create new Shell embedding the widget of the view, for it but then I'd miss the toolbars/menus that come with the proper view.
All the UI code is completely dependent on the workbench running. The workbench must be started with PlatformUI.createandRunWorkbench. So it is not possible to show a UI without doing this.
The simple SWT only Shell seems the easiest way.
Exclude the concept of RCP, and work with SWT/JFace components only.
Build some factory methods that simulate PlatformUI.createandRunWorkbench. Instead, they will create Shells and run the event loops themselves.
To me, this seems like a bit of an overkill if the app is going to be large. It it's not THAT enterprise-ish, then I guess you could do without the workbench framework. Be careful for dangling resources, though.
Related
A bit of background: I have a 3rd party code base that I would like to leave intact. I suspect that by a mistake, one thing that I need from it depends on SwingUtilities.isEventDispatchThread returning true, while the code is in general designed to work as an IDE plugin as well as command line tool.
The command line tool is running in headless mode. What can I do - being able to execute arbitrary code before the isEventDispatchThread call is made - to ensure that EDT is running?
Assuming, of course, that it's possible at all.
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.
I am looking for a way to come back to the standard Java View in Eclipse after the application I'm debugging is over.
Is it possible to accomplish that? That is the default behaviour in some other IDEs (Visual Studio, for instance) and I'd prefer to have it that way. It's so boring to have to go an manually switch the view again to the initial one :(
Thanks
Eclipse is a generic platform where you can have a dozen type of different launch configurations, so a good and usable 'generic' implementation of this feature is not trivial.
However, there is an open bug report for this feature, which has some activity recently so there is a chance that this feature will be included after Eclipse 3.7.
I wrote a plugin that does what you want. Here's the update site:
http://backtojava.s3-website-us-east-1.amazonaws.com/
I didn't categorize the feature, so when you look for it, unselect the "Group items by category" checkbox.
And here's the project on Eclipse Labs I made to host the source:
https://hg.codespot.com/a/eclipselabs.org/backtojava
I haven't checked the Feature project in; just the plugin.
I personally have never seen such a feature. I also wouldn't consider such a feature desirable. Rare would be the occasion where I would be in debug mode for only a single run. Typically, the editing window provided in the debug mode is sufficient for any edits I would make during a debugging session.
Do you have to use Eclipse? There are other Java IDEs, for example in Intellij IDEA you can set the debug window 'unpinned', so it hides when you click on the editor. Personally I would find that behaviour annoying but it might work for you.
I have a test that exercises a custom Swing component using java.awt.Robot. I'd like to run the test in our build server, but the build servers run on locked windows machines, and Robot.keyPress(char) doesn't work with the screen locked. The keystrokes I'm sending are sometimes things like down arrow and backspace, so sending them directly to the document isn't helpful.
Currently I'm just using junit's Assume to skip the tests if keyboard entry doesn't work on the first try, but I'd like to leave these test enabled. I would assume someone out there is running these kinds of tests against a Swing gui. Any ideas?
A stab in the dark: perhaps a VM (like VirtualBox) could be running in the background, but would for all intents and purposes be "awake and unlocked" as far as the robot knows. The virtual box would run your unit tests.
have you tried using the headless mode of java ?
I guess java.awt.Robot won't work in this case, since it specifically depends upon awt being loaded. in such a case, one should better rely upon gui testing frameworks, like the cool (and running in headless mode) fest-swing.
When I start my SWT Application from Eclipse, the Shell always starts up in the background, with the IDE in front of it.
I tried everything, like setting the focus, activating the shell, etc.
Did someone else experience the same behaviour and maybe even solved it?
When you activate a Shell (usually via the open() method), SWT asks the window manager on your given platform to make the shell active. However, depending on the window manager, the shell might not become the top-most shell on the desktop. Here's an article with some interesting info about opening shells (see section "11.4.6 Opening a Shell").
If this is the cause of your issue, you may be able to use the forceActive() method of the Shell class to force the shell to become active. However, depending on your application, you may not want to adopt this approach. The following is a warning from the article:
Most Programs Should Never Need to Use
forceActive()
Forcing a shell to be active should be
reserved for those occasions when you
must get the attention of the user
(which is almost never). After all, do
you like it when another window steals
your keystrokes?
Double check your manifest to see if you're missing anything. That is to say if you are doing this via Eclipse RCP