Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to send message to my running RCP application
How to send message to my running RCP application [message #496661] Tue, 10 November 2009 15:25 Go to next message
fatih  is currently offline fatih
Messages: 6
Registered: November 2009
Junior Member
Hi everybody,

I have a little problem. Maybe somebody has an idea.

I am generating specific links for my application. Let's assume that these link are published in a website. Whenever the user clicks the link, which launches the user's default browser to handle the request. The browser knows that it cannot natively open this URL, so it consults with the Windows registry to determine how the action should be delegated.The registry looks up the myprotocol://... protocol and determines that there is an another application which is my RCP application in this case.

Shortly, I would like to send a message my running RCP application via OS and after that I will do something in my RCP application.

If I can't handle it with OS messages, I can make small program which sends the URL as a parameter to my running RCP application.

There is a similar program has been already implemented.
http://www.ibm.com/developerworks/library/os-eclipse-rcpurl/ index.html

But, I am looking for another solution. I don't want to put a server in my RCP application.

bye

Re: How to send message to my running RCP application [message #496679 is a reply to message #496661] Tue, 10 November 2009 17:14 Go to previous messageGo to next message
Heiko Ahlig is currently offline Heiko Ahlig
Messages: 62
Registered: July 2009
Member
Hi,
some month ago, I write maybe a little solution for your problem.
Here is my old post in the news group:

Hi at all,
Again and again I read that users have problems with his own RCP-apps
and the unique starts of this and also to handle app-args.
Because I had have the same problems some times ago, so I build a little
solution for this and I want present this today.
I hope it will helps somebody.
I build 2 examples, first only for unique start and the second for
unique start and handle application arguments for startup first time
and even more startup-trys.

For both examples I used this JUnique - libary from "Sauron Software" (
http://www.sauronsoftware.it/projects/junique/ (LGPL)).
For the second example also use the Apache-Commons-Lang (
http://commons.apache.org/lang/ (Apache License
Version 2.0)).

In the first example its really simple:
It must only import the JUnique-libary ( Ibuild a simple plugin from
this) and the Application.java hast to be modified in the start()-method:

public Object start(IApplicationContext context) throws Exception {
Display display = PlatformUI.createDisplay();
String id = context.getBrandingId();
boolean start;
try {
JUnique.acquireLock(id,null);
start = true;
} catch (AlreadyLockedException e) {
// Application already running.
start = false;
}
try {
if (start) {
int returnCode =
PlatformUI.createAndRunWorkbench(display, new
ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
else
return IApplication.EXIT_OK;
}
else{
MessageDialog.openInformation(display.getActiveShell(),
"Information", "App is allways runing. Finish now.");
return IApplication.EXIT_OK;
}

} finally {
display.dispose();
}

}

In my second example this must be some more modifications.
There I add an extension-point for fileHandling and other app arguments.
I also add one example for a fileHandler (for tests you can start it
with: "UniqueExample [PathToFile]" <- it reakcte of an "xml"-Extension)
and an Handler vor other/more arguments. At this point you register an
handler with an identifier which also must be also the first argument.
(For tests, you can start my example with: "UniqueExample
de.miku.unique.argssample.argsHandler [arg2] [arg3] [arg4]... ")

For additional questions ask here. ;)

Links:
http://eclipseexamples.nacorswelt.de/unique_simple.zip (first example)
http://eclipseexamples.nacorswelt.de/unique.zip (second example)

(Inside this zip files are a compiled example and the pure projects to
import into your own workspace)


Regards
Heiko

PS: How you have noticed, I have not really good english-skill - so I
dont write a great tutorial for this. I think many people than would not
understand this. ;)





Am 10.11.2009 21:25, schrieb fatih:
> Hi everybody,
>
> I have a little problem. Maybe somebody has an idea.
>
> I am generating specific links for my application. Let's assume that
> these link are published in a website. Whenever the user clicks the
> link, which launches the user's default browser to handle the request.
> The browser knows that it cannot natively open this URL, so it consults
> with the Windows registry to determine how the action should be
> delegated.The registry looks up the myprotocol://... protocol and
> determines that there is an another application which is my RCP
> application in this case.
> Shortly, I would like to send a message my running RCP application via
> OS and after that I will do something in my RCP application.
>
> If I can't handle it with OS messages, I can make small program which
> sends the URL as a parameter to my running RCP application.
>
> There is a similar program has been already implemented.
> http://www.ibm.com/developerworks/library/os-eclipse-rcpurl/ index.html
>
> But, I am looking for another solution. I don't want to put a server in
> my RCP application.
>
> bye
>
>
Re: How to send message to my running RCP application [message #496696 is a reply to message #496661] Tue, 10 November 2009 20:05 Go to previous messageGo to next message
fatih  is currently offline fatih
Messages: 6
Registered: November 2009
Junior Member
Hi Heiko,

Your solution is exactly what I want. Thanks a lot. But I have some questions about your second example.

I ran your application without any parameters. I let it running. Then, I ran again same app with a test.xml file as an argument. Second application was closed and test.xml was send to first running application. The screenshot here. But it says "error" on the screen.

http://img692.imageshack.us/img692/5369/output.jpg

Am I running the application right way?

I couldn't do the same thing in eclipse. I can run one instance and second one. But, it is not running same with your executable file.
I think, second app doesn't send the message to first one. I debug it a bit. I found something but I am not sure, I am right or not. Because I am new in the plug-in development.

In your UniqueMessageProxy class:
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( "de.miku.unique.appargs");

In this line, elements array has nothing. Should it be something in it?


p.s. Englisch is not too important. As you see my english is also not too good Smile

Thanks for your reply and help.



Re: How to send message to my running RCP application [message #496959 is a reply to message #496696] Wed, 11 November 2009 16:10 Go to previous message
Heiko Ahlig is currently offline Heiko Ahlig
Messages: 62
Registered: July 2009
Member
Hi Faith,
The old code was written long time ago. ;)
Today I reload it in my workspace and I saw red. ;)
Because the xml editor plugin was realy cryptic for me, so I rewrite a
more simpler example as txt file editor.

I also add 2 more product files, one withe an file argument and one with
some aruments.

Here is the code:

http://eclipseexamples.nacorswelt.de/unique_src1.0.1.zip

more coments below.

Try it again with this code ;) , I hope it will help you.



Greetings
Heiko


Am 11.11.2009 02:05, schrieb fatih:
> Hi Heiko,
>
> Your solution is exactly what I want. Thanks a lot. But I have some
> questions about your second example.
>
> I ran your application without any parameters. I let it running. Then, I
> ran again same app with a test.xml file as an argument. Second
> application was closed and test.xml was send to first running
> application. The screenshot here. But it says "error" on the screen.
>
>
>
> Am I running the application right way?
> I couldn't do the same thing in eclipse. I can run one instance and
> second one. But, it is not running same with your executable file.
> I think, second app doesn't send the message to first one.

hm for debuging it is a bit tricky,
I handle it with build the app and export it.
than I debug the first instance and starts the builded version with
arguments.
The UniqueMessageProxy.handle(...) method is the first point where the
message from the second instance are visible at my own code.

> I debug it a
> bit. I found something but I am not sure, I am right or not. Because I
> am new in the plug-in development.
> In your UniqueMessageProxy class: IConfigurationElement[] elements =
> Platform.getExtensionRegistry().getConfigurationElementsFor(
> "de.miku.unique.appargs");

There should (and at me are 2) elements in the array.
One for the txt file handler and one for the arguments handler.

>
> In this line, elements array has nothing. Should it be something in it?
>
> p.s. Englisch is not too important. As you see my english is also not
> too good :)
>
> Thanks for your reply and help.
>
>
>
>
Previous Topic:Change cursor
Next Topic:Databinding Confusion
Goto Forum:
  


Current Time: Thu Apr 17 11:43:54 EDT 2014

Powered by FUDForum. Page generated in 0.01534 seconds