Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Passing a variable to View from Application.java
icon4.gif  Passing a variable to View from Application.java [message #627016] Wed, 22 September 2010 19:31 Go to next message
walid ammous is currently offline walid ammousFriend
Messages: 5
Registered: September 2010
Junior Member
Hello,

I would like to know if it is possible to pass a variable from Application.java class to View.java
I don't want to use static variables. what I want is: in the start() method in Application.java, I declare a variable and then pass it to View.java ?

[Updated on: Wed, 22 September 2010 19:33]

Report message to a moderator

Re: Passing a variable to View from Application.java [message #627910 is a reply to message #627016] Thu, 23 September 2010 06:52 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 22.09.2010 21:31, walid ammous wrote:
> I would like to know if it possible to pass a variable from
> Application.java class to View.java
> I don't want to use static variables. what I want is: in the start()
> method in Application.java, is there a way to pass a variable to
> View.java ?

Different approaches are possible. I would probably use the
org.eclipse.ui.services extension point and define either
a service or a source provider that allows to fill in data
on one side (your Application.Java) and read it from another
side (your view).

HTH & Greetings from Bremen,

Daniel Krügler
Re: Passing a variable to View from Application.java [message #627937 is a reply to message #627910] Thu, 23 September 2010 07:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I'm not sure that the org.eclipse.ui.service (the workbench) is already
up at this point - I'd better use OSGi-Services.

Tom

Am 23.09.10 08:52, schrieb Daniel Krügler:
> On 22.09.2010 21:31, walid ammous wrote:
>> I would like to know if it possible to pass a variable from
>> Application.java class to View.java
>> I don't want to use static variables. what I want is: in the start()
>> method in Application.java, is there a way to pass a variable to
>> View.java ?
>
> Different approaches are possible. I would probably use the
> org.eclipse.ui.services extension point and define either
> a service or a source provider that allows to fill in data
> on one side (your Application.Java) and read it from another
> side (your view).
>
> HTH & Greetings from Bremen,
>
> Daniel Krügler
Re: Passing a variable to View from Application.java [message #627966 is a reply to message #627937] Thu, 23 September 2010 07:53 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 23.09.2010 09:29, Tom Schindl wrote:
> I'm not sure that the org.eclipse.ui.service (the workbench) is already
> up at this point - I'd better use OSGi-Services.

Good argument, Tom. In this case I would preferably use the declarative
services approach, which provides a good compromise between the
conveniences of an extension-point-like customization point and the
possibly required core features.

- Daniel

> Tom
>
> Am 23.09.10 08:52, schrieb Daniel Krügler:
>> On 22.09.2010 21:31, walid ammous wrote:
>>> I would like to know if it possible to pass a variable from
>>> Application.java class to View.java
>>> I don't want to use static variables. what I want is: in the start()
>>> method in Application.java, is there a way to pass a variable to
>>> View.java ?
>>
>> Different approaches are possible. I would probably use the
>> org.eclipse.ui.services extension point and define either
>> a service or a source provider that allows to fill in data
>> on one side (your Application.Java) and read it from another
>> side (your view).
>>
>> HTH& Greetings from Bremen,
>>
>> Daniel Krügler
>
Re: Passing a variable to View from Application.java [message #627969 is a reply to message #627016] Thu, 23 September 2010 08:03 Go to previous messageGo to next message
walid ammous is currently offline walid ammousFriend
Messages: 5
Registered: September 2010
Junior Member
Thank you very much Tom and Daniel.
What I understood is that I need to use either OSG-Services or declarative service approach.
Unfortunately I am not familiar with these. So could you please show me some Real Implementation of these techniques.

So let's say I have a variable (int x) that I declared in Application.java.

    public Object start(IApplicationContext context) {
        Display display = PlatformUI.createDisplay();
        //declare a variable x
        int x = 0;
       //what to write here in order to use one of those techniques.
        try {
            int returnCode = PlatformUI.createAndRunWorkbench(display,
                    new ApplicationWorkbenchAdvisor());

            if (returnCode == PlatformUI.RETURN_RESTART) {
                return IApplication.EXIT_RESTART;
            }
            return IApplication.EXIT_OK;
        } finally {
            display.dispose();
        }
    }




and then in View.java
	public void createPartControl(Composite parent) {
//how to retrieve the variable here
		
	}

[Updated on: Thu, 23 September 2010 08:05]

Report message to a moderator

Re: Passing a variable to View from Application.java [message #628019 is a reply to message #627969] Thu, 23 September 2010 08:45 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well there are many tutorials out there talking about DS (there's even a
PDE Wizard to create an example).

I just throught about another solution which is Q&D but you can pass
information information through the Display#setData(String,Object) and
use Control#getDisplay()#getData(String) in your code.

The display is by defintion a singleton in an SWT-UI application :-)

Tom

Am 23.09.10 10:03, schrieb walid ammous:
> Thank you very much Tom and Daniel.
> What I understood is that I need to use either OSG-Services or
> declarative service approach.
> Unfortunately I am not familiar with these. So could you please show me
> some Real Implementation of these techniques.
>
> So let's say I have a variable (int x) that I declared in Application.java.
>
>
> public Object start(IApplicationContext context) {
> Display display = PlatformUI.createDisplay();
> //open Login window
> int x = 0;
> //what to write here in order to use one of those //techniques.
> try {
> int returnCode = PlatformUI.createAndRunWorkbench(display,
> new ApplicationWorkbenchAdvisor());
>
> if (returnCode == PlatformUI.RETURN_RESTART) {
> return IApplication.EXIT_RESTART;
> }
> return IApplication.EXIT_OK;
> } finally {
> display.dispose();
> }
> }
>
>
>
>
> and then in View.java
>
> public void createPartControl(Composite parent) {
> //how to retrieve the variable here
>
> }
Re: Passing a variable to View from Application.java [message #628710 is a reply to message #627016] Thu, 23 September 2010 18:19 Go to previous messageGo to next message
walid ammous is currently offline walid ammousFriend
Messages: 5
Registered: September 2010
Junior Member
Thank you so much for the idea Smile
the display didnt work for me but I created a Singletone class from scratch and it works perfectly.

Thanks for the idea again Very Happy
Re: Passing a variable to View from Application.java [message #628797 is a reply to message #627016] Fri, 24 September 2010 08:04 Go to previous messageGo to next message
walid ammous is currently offline walid ammousFriend
Messages: 5
Registered: September 2010
Junior Member
Hi guyz Smile

I have another question.
The situation is the following :
I have two Views.
So what is the best way to tell the second View to start doing some work when some specific event happens in the first View.
Re: Passing a variable to View from Application.java [message #628802 is a reply to message #628797] Fri, 24 September 2010 08:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Use EventAdmin from OSGi where ViewA publishes an event and ViewB
subscribes to it.

Tom

Am 24.09.10 10:04, schrieb walid ammous:
> Hi guyz :)
>
> I have another question.
> The situation is the following :
> I have two Views. So what is the best way to tell the second View to
> start doing some work when some specific event happens in the first View.
Re: Passing a variable to View from Application.java [message #628854 is a reply to message #628802] Fri, 24 September 2010 13:07 Go to previous message
walid ammous is currently offline walid ammousFriend
Messages: 5
Registered: September 2010
Junior Member
Thanx Tom.

can you post a simple example on how to use this EventAdmin or do you have a good link (Tutorial) about it?
Previous Topic:Links to files in the About dialog AboutText variable
Next Topic:Editor Title
Goto Forum:
  


Current Time: Thu Sep 26 19:48:38 GMT 2024

Powered by FUDForum. Page generated in 0.04892 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top