Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Internally setting value of a property
Internally setting value of a property [message #130025] Thu, 17 August 2006 17:56 Go to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Hello,
Anyone who has an idea how to achieve this simple scenario with JVE.

My Project has a file named input.txt. My composite needs to display
the content of this input.txt file. My composite has a setter, but I
only want to set the relative path of this input.txt instead of the
absolute path. The reason for this is if the user copies this java file
to another project, and the project has input.txt, it will work without
having to change the path in the java file.

So here are the steps I this I need to do to get this scenario work:

1. Find out the current IProject location by looking at the current
editing editor and get the IFileEditorInput.
2. Pass this information to JVE's JVM that interpretes this composite
class (I am not sure how this can be done)...




class Composite
{

private void initialize()
{
MyComposite composite = new MyComposite(this,SWT.NONE);
composite.setInputFile("input.txt");
.......
}
}
Re: Internally setting value of a property [message #130038 is a reply to message #130025] Thu, 17 August 2006 18:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jefmyers.us.ibm.com

Hung,

You can follow the pattern that's used to load images - by creating a
url that's relative to the location of the class. For instance you can
use composite.setInputFile(getClass().getResource("/input.txt")), then
use a URLInputStream to open that url to read the file. This has the
additional advantage of working if you package the resource along with
your classes into a jar file.

Hope this helps,
- Jeff
Re: Internally setting value of a property [message #130061 is a reply to message #130038] Thu, 17 August 2006 21:58 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Thanks Jeff,
That's a good idea....I'll try it out. I have another question though.
Below are the sample code. MyComposite has setter/getter for
inputFile, and what I want to do is to pass this common inputFile to
each of the AnotherComposite. I can't get this to work b/c it
complains that getInputFile() needs a receiver. If I replace it with
this.getInputFile(), it says no such method in Composite class. Thanks.


Class Composite1 extends MyComposite
{
private void initialize()
{
setInputFile("test.txt");
....

AnotherComposite comp = new AnotherComposite(...);
comp.setInputFile(getInputFile());
....

AnotherComposite comp1 = new AnotherComposite1(...);
comp1.setInputFile(getInputFile());
}
}

class MyComposite extends Composite
{
public void setInputFile(..) {..}

public String getInputFile() {....}
}

Jeff Myers wrote:
> Hung,
>
> You can follow the pattern that's used to load images - by creating a
> url that's relative to the location of the class. For instance you can
> use composite.setInputFile(getClass().getResource("/input.txt")), then
> use a URLInputStream to open that url to read the file. This has the
> additional advantage of working if you package the resource along with
> your classes into a jar file.
>
> Hope this helps,
> - Jeff
Re: Internally setting value of a property [message #130085 is a reply to message #130061] Thu, 17 August 2006 22:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Don't worry about it. It just means that we can't evaluate the
setInputFile as a property. But since it isn't a property there isn't a
problem. It doesn't stop your code from working.

Hung Lam wrote:
> Thanks Jeff,
> That's a good idea....I'll try it out. I have another question though.
> Below are the sample code. MyComposite has setter/getter for
> inputFile, and what I want to do is to pass this common inputFile to
> each of the AnotherComposite. I can't get this to work b/c it
> complains that getInputFile() needs a receiver. If I replace it with
> this.getInputFile(), it says no such method in Composite class. Thanks.
>
>
> Class Composite1 extends MyComposite
> {
> private void initialize()
> {
> setInputFile("test.txt");
> ....
>
> AnotherComposite comp = new AnotherComposite(...);
> comp.setInputFile(getInputFile());
> ....
>
> AnotherComposite comp1 = new AnotherComposite1(...);
> comp1.setInputFile(getInputFile());
> }
> }
>
> class MyComposite extends Composite
> {
> public void setInputFile(..) {..}
>
> public String getInputFile() {....}
> }
>
> Jeff Myers wrote:
>
>> Hung,
>>
>> You can follow the pattern that's used to load images - by creating a
>> url that's relative to the location of the class. For instance you
>> can use composite.setInputFile(getClass().getResource("/input.txt")),
>> then use a URLInputStream to open that url to read the file. This has
>> the additional advantage of working if you package the resource along
>> with your classes into a jar file.
>>
>> Hope this helps,
>> - Jeff

--
Thanks,
Rich Kulp
Re: Internally setting value of a property [message #130109 is a reply to message #130085] Thu, 17 August 2006 23:42 Go to previous messageGo to next message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Rich,
Thank you. But I want to be able to set that inputFile, and I want to
get that inputFile from the MyComposite by calling getInputFile().

Rich Kulp wrote:
> Don't worry about it. It just means that we can't evaluate the
> setInputFile as a property. But since it isn't a property there isn't a
> problem. It doesn't stop your code from working.
>
> Hung Lam wrote:
>> Thanks Jeff,
>> That's a good idea....I'll try it out. I have another question though.
>> Below are the sample code. MyComposite has setter/getter for
>> inputFile, and what I want to do is to pass this common inputFile to
>> each of the AnotherComposite. I can't get this to work b/c it
>> complains that getInputFile() needs a receiver. If I replace it with
>> this.getInputFile(), it says no such method in Composite class. Thanks.
>>
>>
>> Class Composite1 extends MyComposite
>> {
>> private void initialize()
>> {
>> setInputFile("test.txt");
>> ....
>>
>> AnotherComposite comp = new AnotherComposite(...);
>> comp.setInputFile(getInputFile());
>> ....
>>
>> AnotherComposite comp1 = new AnotherComposite1(...);
>> comp1.setInputFile(getInputFile());
>> }
>> }
>>
>> class MyComposite extends Composite
>> {
>> public void setInputFile(..) {..}
>>
>> public String getInputFile() {....}
>> }
>>
>> Jeff Myers wrote:
>>
>>> Hung,
>>>
>>> You can follow the pattern that's used to load images - by creating a
>>> url that's relative to the location of the class. For instance you
>>> can use composite.setInputFile(getClass().getResource("/input.txt")),
>>> then use a URLInputStream to open that url to read the file. This
>>> has the additional advantage of working if you package the resource
>>> along with your classes into a jar file.
>>>
>>> Hope this helps,
>>> - Jeff
>
Re: Internally setting value of a property [message #130206 is a reply to message #130109] Fri, 18 August 2006 14:15 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

It won't work. We don't "execute" the class being edited. We interpret
it. We can't run because it is being edited, you can only run a class
that is saved and compiled. Because of this we can't run arbitrary
methods in the class being edited. getInputFile() is an arbitrary
method. It isn't a bean that we know anything about.

If you dropped the class on another class then it would be executed
because we executed used classes since that class has been saved and
compiled.
--
Thanks,
Rich Kulp
Re: Internally setting value of a property [message #614549 is a reply to message #130025] Thu, 17 August 2006 18:22 Go to previous message
Jeff Myers is currently offline Jeff MyersFriend
Messages: 396
Registered: July 2009
Senior Member
Hung,

You can follow the pattern that's used to load images - by creating a
url that's relative to the location of the class. For instance you can
use composite.setInputFile(getClass().getResource("/input.txt")), then
use a URLInputStream to open that url to read the file. This has the
additional advantage of working if you package the resource along with
your classes into a jar file.

Hope this helps,
- Jeff
Re: Internally setting value of a property [message #614551 is a reply to message #130038] Thu, 17 August 2006 21:58 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Thanks Jeff,
That's a good idea....I'll try it out. I have another question though.
Below are the sample code. MyComposite has setter/getter for
inputFile, and what I want to do is to pass this common inputFile to
each of the AnotherComposite. I can't get this to work b/c it
complains that getInputFile() needs a receiver. If I replace it with
this.getInputFile(), it says no such method in Composite class. Thanks.


Class Composite1 extends MyComposite
{
private void initialize()
{
setInputFile("test.txt");
....

AnotherComposite comp = new AnotherComposite(...);
comp.setInputFile(getInputFile());
....

AnotherComposite comp1 = new AnotherComposite1(...);
comp1.setInputFile(getInputFile());
}
}

class MyComposite extends Composite
{
public void setInputFile(..) {..}

public String getInputFile() {....}
}

Jeff Myers wrote:
> Hung,
>
> You can follow the pattern that's used to load images - by creating a
> url that's relative to the location of the class. For instance you can
> use composite.setInputFile(getClass().getResource("/input.txt")), then
> use a URLInputStream to open that url to read the file. This has the
> additional advantage of working if you package the resource along with
> your classes into a jar file.
>
> Hope this helps,
> - Jeff
Re: Internally setting value of a property [message #614553 is a reply to message #130061] Thu, 17 August 2006 22:12 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Don't worry about it. It just means that we can't evaluate the
setInputFile as a property. But since it isn't a property there isn't a
problem. It doesn't stop your code from working.

Hung Lam wrote:
> Thanks Jeff,
> That's a good idea....I'll try it out. I have another question though.
> Below are the sample code. MyComposite has setter/getter for
> inputFile, and what I want to do is to pass this common inputFile to
> each of the AnotherComposite. I can't get this to work b/c it
> complains that getInputFile() needs a receiver. If I replace it with
> this.getInputFile(), it says no such method in Composite class. Thanks.
>
>
> Class Composite1 extends MyComposite
> {
> private void initialize()
> {
> setInputFile("test.txt");
> ....
>
> AnotherComposite comp = new AnotherComposite(...);
> comp.setInputFile(getInputFile());
> ....
>
> AnotherComposite comp1 = new AnotherComposite1(...);
> comp1.setInputFile(getInputFile());
> }
> }
>
> class MyComposite extends Composite
> {
> public void setInputFile(..) {..}
>
> public String getInputFile() {....}
> }
>
> Jeff Myers wrote:
>
>> Hung,
>>
>> You can follow the pattern that's used to load images - by creating a
>> url that's relative to the location of the class. For instance you
>> can use composite.setInputFile(getClass().getResource("/input.txt")),
>> then use a URLInputStream to open that url to read the file. This has
>> the additional advantage of working if you package the resource along
>> with your classes into a jar file.
>>
>> Hope this helps,
>> - Jeff

--
Thanks,
Rich Kulp
Re: Internally setting value of a property [message #614555 is a reply to message #130085] Thu, 17 August 2006 23:42 Go to previous message
hung is currently offline hungFriend
Messages: 117
Registered: July 2009
Senior Member
Rich,
Thank you. But I want to be able to set that inputFile, and I want to
get that inputFile from the MyComposite by calling getInputFile().

Rich Kulp wrote:
> Don't worry about it. It just means that we can't evaluate the
> setInputFile as a property. But since it isn't a property there isn't a
> problem. It doesn't stop your code from working.
>
> Hung Lam wrote:
>> Thanks Jeff,
>> That's a good idea....I'll try it out. I have another question though.
>> Below are the sample code. MyComposite has setter/getter for
>> inputFile, and what I want to do is to pass this common inputFile to
>> each of the AnotherComposite. I can't get this to work b/c it
>> complains that getInputFile() needs a receiver. If I replace it with
>> this.getInputFile(), it says no such method in Composite class. Thanks.
>>
>>
>> Class Composite1 extends MyComposite
>> {
>> private void initialize()
>> {
>> setInputFile("test.txt");
>> ....
>>
>> AnotherComposite comp = new AnotherComposite(...);
>> comp.setInputFile(getInputFile());
>> ....
>>
>> AnotherComposite comp1 = new AnotherComposite1(...);
>> comp1.setInputFile(getInputFile());
>> }
>> }
>>
>> class MyComposite extends Composite
>> {
>> public void setInputFile(..) {..}
>>
>> public String getInputFile() {....}
>> }
>>
>> Jeff Myers wrote:
>>
>>> Hung,
>>>
>>> You can follow the pattern that's used to load images - by creating a
>>> url that's relative to the location of the class. For instance you
>>> can use composite.setInputFile(getClass().getResource("/input.txt")),
>>> then use a URLInputStream to open that url to read the file. This
>>> has the additional advantage of working if you package the resource
>>> along with your classes into a jar file.
>>>
>>> Hope this helps,
>>> - Jeff
>
Re: Internally setting value of a property [message #614562 is a reply to message #130109] Fri, 18 August 2006 14:15 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

It won't work. We don't "execute" the class being edited. We interpret
it. We can't run because it is being edited, you can only run a class
that is saved and compiled. Because of this we can't run arbitrary
methods in the class being edited. getInputFile() is an arbitrary
method. It isn't a bean that we know anything about.

If you dropped the class on another class then it would be executed
because we executed used classes since that class has been saved and
compiled.
--
Thanks,
Rich Kulp
Previous Topic:How can I build to .exe file
Next Topic:How to edit JFace in VE
Goto Forum:
  


Current Time: Fri Apr 26 01:26:57 GMT 2024

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

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

Back to the top