Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Loading Java class in the Plugin environment
Loading Java class in the Plugin environment [message #120766] Fri, 17 March 2006 05:40 Go to next message
Eclipse UserFriend
Originally posted by: rash_star.yahoo.com

Hi All,
I want to load a java file in to the plugin environment. Can it be
done using the BeanProxy technology? The one given in the visual editor
tutorial tells the bean proxy method, which is similar to the java
reflection package can be used, only when we get the edit domain of the
visual editor. Is there any other way, where I can load a java file giving
a physical location of the file and invoke methods on it or parse that
code to extract certain values in the plugin environment.

Thank You and Best Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #120770 is a reply to message #120766] Fri, 17 March 2006 15:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Not really. That is usually not done because it can be dangerous. If you
don't know anything about the .class file you don't know what it could
do to your IDE. The Eclipse plugin concept is based upon then concept of
portable self-contained bundles that don't require special external jars
just to run.

The question is why do you need to do this. First, you can't load a java
file. A java file is not compiled, it needs to be a .class file. Second
what do you need out of it. Do you need to run it, or do you just need
to get some info (such as AST syntax) out of the java file? To parse the
java file without actually executing it you can the jdt's AST parser. It
will parse the file into a syntax structure that you can walk to find
out many things about the class, down to exactly what statements are
executed and even the comments in the code.

Rashmi H.R wrote:
> Hi All,
> I want to load a java file in to the plugin environment. Can it be
> done using the BeanProxy technology? The one given in the visual editor
> tutorial tells the bean proxy method, which is similar to the java
> reflection package can be used, only when we get the edit domain of the
> visual editor. Is there any other way, where I can load a java file
> giving a physical location of the file and invoke methods on it or parse
> that code to extract certain values in the plugin environment.
>
> Thank You and Best Regards,
> Rashmi H.R
>

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #120968 is a reply to message #120770] Tue, 28 March 2006 08:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,

Thanks for the reply. Yes I was talking about loading the .class for a
java class. I have a Component tree that is similar to the Bean tree in
the Visual Editor, but with a different categorization. There are some
methods in my visual class that do not correspond to any visual component.
The V.E does not invoke such methods that are not visual in nature, even
if they are called in the Visual Class.
I need invoke these non-visual methods for building some functional
part of my component tree. These methods have to be explicitly invoked to
get the required values. Hence I was talking about loading the .class
through java reflection method.

Can you please guide me in this regard?

Thank You & Best Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #121012 is a reply to message #120968] Tue, 28 March 2006 19:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You still don't invoke in the IDE because we don't actually invoke your
classes on the IDE vm. We create another VM and invoke them there.

Can you be a little more specific (maybe a small example) of these non
visual methods and how they would normally be called in the code?

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #121418 is a reply to message #121012] Wed, 05 April 2006 08:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich ,
Let me explain the scenario in which i needing to get the non-visual
objects such as custom eventListeners.

Consider a custom widget say 'TextComponent' . And a custom event
listener called 'MyEventListener'.
The code for my event listener is given below,


Class: MyEventListener

package eventListenerTestPlugin.event;

import java.util.EventListener;
import java.util.HashMap;

public abstract class MyEventListener implements EventListener
{
public static HashMap propertyValue;
private String name = "";
private String evtName;
private String evtStyle;

/**
* @param evtName
*/
public MyEventListener(String evtName){
this.evtName = evtName;
}

/**
* @param evtName
* @param evttype
*/
public MyEventListener(String evtName, String evttype){
setEvtType(evttype);

}

/**
* @return Returns the evtName.
*/
public String getEvtName(){
return evtName;
}

/**
* @param evtName
* The evtName to set.
*/
public void setEvtName(String evtName){
this.evtName = evtName;
}

/**
* @return Returns the evtType.
*/
public String getEvtType() {
return evtType;
}

/**
* @param evttype
* The evttype to set.
*/
public void setEvtType(String evtType){
this.evttype = evtType;
}



}
MyEventListener has constructer accepting event type and the event name.

The Component class 'TextComponent' defines a method called
'addEventListeners(MyEventLister())'.
Variable 'evtListeners' is of type Hashmap.

public void addEventListeners(MyEventListener evtListener)
{
evtListeners.put(evtListener.getEvtName(),evtListener);
}


In the test visual class the component defination is as follows.


/**
* This method initializes textFieldComponent
*
* @return eventListenerTestPlugin.widgets.TextComponent
*/
private TextComponent getTextComponent() {
if (textComponent == null) {
textComponent = new TextComponent();
textComponent.setBounds(new java.awt.Rectangle(82,78,69,20));
textComponent.setLabelName("Name ");
textComponent.setName("Name");
textComponent.addEventListeners(
new MyEventListener("Event1" ,"type2")
{
public void handleEvent() {
EvtListenerTest.callMethod1() ;
}
}
);
textComponent.addEventListeners(
new MyEventListener("Event2" ,"type1")
{
public void handleEvent() {
EvtListenerTest.callMethod2() ;
}
}
);

}

return textFieldComponent;
}


Considering the above component. I want to load all the EventListeners on
the component 'textComponent' on to the Bean Tree with event name as the
Node label.


Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #121454 is a reply to message #121418] Wed, 05 April 2006 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

If you change the name of your add/remove event listener they would show
up on the tree. The standard java Beans specs says event listeners
should follow the following pattern. If they do, then they should show
up on the tree. (Note: It doesn't actually call these listeners at VE
design time, it just shows them in the tree for you).

The pattern is:

public void addLISTNERNAME(LISTENER)
public void removeLISTNERNAME(LISTENER)

where LISTENERNAME is the name of the listener class,
and LISTENER must inherit from java.util.EventListener

Your example is almost there. The add/remove methods should be

public void addMyEventListener(MyEventListener listener)
public void removeMyEventListener(MyEventListener listener)

If you do that they will show in the beans list.
--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #121527 is a reply to message #121454] Fri, 07 April 2006 06:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,

Thanks for the reply. I was able to make the necessary changes to my
files. The listener methods are now visible on the V.E 's bean tree.
I need to load these Listeners on my custom tree with the "Event Name" as
the Node Label. As mentioned in my example, the constructor for
MyEventListener class accepts two parameters, that represents the ‘Event
Name’ and ‘Event Type’ as shown below

public MyEventListener(String evtName, String evttype)

The tree node representing this Event Listener should have node label as
the ‘Event Name’.

I am unable to get any details of the Listener from the Eclipse API.
During the process of debugging, I came across EventMethodTreeEditPart in
the TreeViewer class, from the EditDomain of the V.E. This seems to have
the structural details of the handle event method of the listener. Apart
from this I was not able to gather more info regarding the Event Name or
Event Type of the Listener. Kindly help me retrieve this information.

Thank You and Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #121597 is a reply to message #121527] Fri, 07 April 2006 14:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

What is it you need to do with this info? You won't be able to display
it in the tree because you can't override the label processing for an
event in the JavaBeans tree.


--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #121947 is a reply to message #121597] Mon, 10 April 2006 11:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,
I am not modifying the V.E's bean tree. As I mentioned in the sample
scenario before, I have a Custom Tree built in Swing that represents the
visual class. Hence, I have full control on the label of the tree node.
Please help me find this information (Event Name, Event Type).

Thank You & Regards,
Rashmi.H.R
Re: Loading Java class in the Plugin environment [message #121995 is a reply to message #121947] Mon, 10 April 2006 14:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I'm confused. Are you inside the VE (i.e. you had extended the VE) or
are you running your application?

Rashmi H.R wrote:
> Hi Rich, I am not modifying the V.E's bean tree. As I mentioned in the
> sample scenario before, I have a Custom Tree built in Swing that
> represents the visual class. Hence, I have full control on the label of
> the tree node. Please help me find this information (Event Name, Event
> Type).
>
> Thank You & Regards,
> Rashmi.H.R
>
>

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #122059 is a reply to message #121995] Tue, 11 April 2006 05:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,
Thanks for the reply. I have a plugin application. I have not extended
V.E. I parse the Graphical treeviewer of the V.E's Editdomain, and load
those editparts on to my custom tree(Swing tree embedded inside a eclipse
view).

Thank You and Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #122109 is a reply to message #122059] Tue, 11 April 2006 15:00 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I'm not sure I can help you. We keep a record of there was an event
listener added to a part and the AST expression that did the adding. But
if your "eventName" is an expression and not a literal (i.e. it is
something like getAName() versus "AName") then there is no way to get
the result of that method call. We don't actually instantiate your class
being edited. We parse it and try to interpret what it means as best we
can. We don't model everything and the expression that is used to do the
add is not modeled and evaluated.

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612327 is a reply to message #120766] Fri, 17 March 2006 15:29 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Not really. That is usually not done because it can be dangerous. If you
don't know anything about the .class file you don't know what it could
do to your IDE. The Eclipse plugin concept is based upon then concept of
portable self-contained bundles that don't require special external jars
just to run.

The question is why do you need to do this. First, you can't load a java
file. A java file is not compiled, it needs to be a .class file. Second
what do you need out of it. Do you need to run it, or do you just need
to get some info (such as AST syntax) out of the java file? To parse the
java file without actually executing it you can the jdt's AST parser. It
will parse the file into a syntax structure that you can walk to find
out many things about the class, down to exactly what statements are
executed and even the comments in the code.

Rashmi H.R wrote:
> Hi All,
> I want to load a java file in to the plugin environment. Can it be
> done using the BeanProxy technology? The one given in the visual editor
> tutorial tells the bean proxy method, which is similar to the java
> reflection package can be used, only when we get the edit domain of the
> visual editor. Is there any other way, where I can load a java file
> giving a physical location of the file and invoke methods on it or parse
> that code to extract certain values in the plugin environment.
>
> Thank You and Best Regards,
> Rashmi H.R
>

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612369 is a reply to message #120770] Tue, 28 March 2006 08:59 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,

Thanks for the reply. Yes I was talking about loading the .class for a
java class. I have a Component tree that is similar to the Bean tree in
the Visual Editor, but with a different categorization. There are some
methods in my visual class that do not correspond to any visual component.
The V.E does not invoke such methods that are not visual in nature, even
if they are called in the Visual Class.
I need invoke these non-visual methods for building some functional
part of my component tree. These methods have to be explicitly invoked to
get the required values. Hence I was talking about loading the .class
through java reflection method.

Can you please guide me in this regard?

Thank You & Best Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #612374 is a reply to message #120968] Tue, 28 March 2006 19:07 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

You still don't invoke in the IDE because we don't actually invoke your
classes on the IDE vm. We create another VM and invoke them there.

Can you be a little more specific (maybe a small example) of these non
visual methods and how they would normally be called in the code?

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612480 is a reply to message #121012] Wed, 05 April 2006 08:47 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich ,
Let me explain the scenario in which i needing to get the non-visual
objects such as custom eventListeners.

Consider a custom widget say 'TextComponent' . And a custom event
listener called 'MyEventListener'.
The code for my event listener is given below,


Class: MyEventListener

package eventListenerTestPlugin.event;

import java.util.EventListener;
import java.util.HashMap;

public abstract class MyEventListener implements EventListener
{
public static HashMap propertyValue;
private String name = "";
private String evtName;
private String evtStyle;

/**
* @param evtName
*/
public MyEventListener(String evtName){
this.evtName = evtName;
}

/**
* @param evtName
* @param evttype
*/
public MyEventListener(String evtName, String evttype){
setEvtType(evttype);

}

/**
* @return Returns the evtName.
*/
public String getEvtName(){
return evtName;
}

/**
* @param evtName
* The evtName to set.
*/
public void setEvtName(String evtName){
this.evtName = evtName;
}

/**
* @return Returns the evtType.
*/
public String getEvtType() {
return evtType;
}

/**
* @param evttype
* The evttype to set.
*/
public void setEvtType(String evtType){
this.evttype = evtType;
}



}
MyEventListener has constructer accepting event type and the event name.

The Component class 'TextComponent' defines a method called
'addEventListeners(MyEventLister())'.
Variable 'evtListeners' is of type Hashmap.

public void addEventListeners(MyEventListener evtListener)
{
evtListeners.put(evtListener.getEvtName(),evtListener);
}


In the test visual class the component defination is as follows.


/**
* This method initializes textFieldComponent
*
* @return eventListenerTestPlugin.widgets.TextComponent
*/
private TextComponent getTextComponent() {
if (textComponent == null) {
textComponent = new TextComponent();
textComponent.setBounds(new java.awt.Rectangle(82,78,69,20));
textComponent.setLabelName("Name ");
textComponent.setName("Name");
textComponent.addEventListeners(
new MyEventListener("Event1" ,"type2")
{
public void handleEvent() {
EvtListenerTest.callMethod1() ;
}
}
);
textComponent.addEventListeners(
new MyEventListener("Event2" ,"type1")
{
public void handleEvent() {
EvtListenerTest.callMethod2() ;
}
}
);

}

return textFieldComponent;
}


Considering the above component. I want to load all the EventListeners on
the component 'textComponent' on to the Bean Tree with event name as the
Node label.


Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #612492 is a reply to message #121418] Wed, 05 April 2006 14:28 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

If you change the name of your add/remove event listener they would show
up on the tree. The standard java Beans specs says event listeners
should follow the following pattern. If they do, then they should show
up on the tree. (Note: It doesn't actually call these listeners at VE
design time, it just shows them in the tree for you).

The pattern is:

public void addLISTNERNAME(LISTENER)
public void removeLISTNERNAME(LISTENER)

where LISTENERNAME is the name of the listener class,
and LISTENER must inherit from java.util.EventListener

Your example is almost there. The add/remove methods should be

public void addMyEventListener(MyEventListener listener)
public void removeMyEventListener(MyEventListener listener)

If you do that they will show in the beans list.
--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612506 is a reply to message #121454] Fri, 07 April 2006 06:08 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,

Thanks for the reply. I was able to make the necessary changes to my
files. The listener methods are now visible on the V.E 's bean tree.
I need to load these Listeners on my custom tree with the "Event Name" as
the Node Label. As mentioned in my example, the constructor for
MyEventListener class accepts two parameters, that represents the ‘Event
Name’ and ‘Event Type’ as shown below

public MyEventListener(String evtName, String evttype)

The tree node representing this Event Listener should have node label as
the ‘Event Name’.

I am unable to get any details of the Listener from the Eclipse API.
During the process of debugging, I came across EventMethodTreeEditPart in
the TreeViewer class, from the EditDomain of the V.E. This seems to have
the structural details of the handle event method of the listener. Apart
from this I was not able to gather more info regarding the Event Name or
Event Type of the Listener. Kindly help me retrieve this information.

Thank You and Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #612519 is a reply to message #121527] Fri, 07 April 2006 14:11 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

What is it you need to do with this info? You won't be able to display
it in the tree because you can't override the label processing for an
event in the JavaBeans tree.


--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612571 is a reply to message #121597] Mon, 10 April 2006 11:21 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,
I am not modifying the V.E's bean tree. As I mentioned in the sample
scenario before, I have a Custom Tree built in Swing that represents the
visual class. Hence, I have full control on the label of the tree node.
Please help me find this information (Event Name, Event Type).

Thank You & Regards,
Rashmi.H.R
Re: Loading Java class in the Plugin environment [message #612580 is a reply to message #121947] Mon, 10 April 2006 14:43 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I'm confused. Are you inside the VE (i.e. you had extended the VE) or
are you running your application?

Rashmi H.R wrote:
> Hi Rich, I am not modifying the V.E's bean tree. As I mentioned in the
> sample scenario before, I have a Custom Tree built in Swing that
> represents the visual class. Hence, I have full control on the label of
> the tree node. Please help me find this information (Event Name, Event
> Type).
>
> Thank You & Regards,
> Rashmi.H.R
>
>

--
Thanks,
Rich Kulp
Re: Loading Java class in the Plugin environment [message #612589 is a reply to message #121995] Tue, 11 April 2006 05:32 Go to previous message
Eclipse UserFriend
Originally posted by: rashmi_h_r.rediffmail.com

Hi Rich,
Thanks for the reply. I have a plugin application. I have not extended
V.E. I parse the Graphical treeviewer of the V.E's Editdomain, and load
those editparts on to my custom tree(Swing tree embedded inside a eclipse
view).

Thank You and Regards,
Rashmi H.R
Re: Loading Java class in the Plugin environment [message #612596 is a reply to message #122059] Tue, 11 April 2006 15:00 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I'm not sure I can help you. We keep a record of there was an event
listener added to a part and the AST expression that did the adding. But
if your "eventName" is an expression and not a literal (i.e. it is
something like getAName() versus "AName") then there is no way to get
the result of that method call. We don't actually instantiate your class
being edited. We parse it and try to interpret what it means as best we
can. We don't model everything and the expression that is used to do the
add is not modeled and evaluated.

--
Thanks,
Rich Kulp
Previous Topic:What are the Events fired when a component is resized in VE?
Next Topic:Dealing with BoxLayout
Goto Forum:
  


Current Time: Fri Apr 26 18:48:29 GMT 2024

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

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

Back to the top