Home » Eclipse Projects » Eclipse 4 » questions about context
questions about context [message #496649] |
Tue, 10 November 2009 19:07 |
Gary Horen Messages: 19 Registered: July 2009 |
Junior Member |
|
|
I'm playing around with contexts, and have some questions:
I see that I can get injection of services like Logger and
IPreferenceService from a context. I'm not understanding how an object (i.e.
part, in this case) instantiated by a context can expose services or
properties that others can consume.
1. From what I've read, I expected to be able to set a property in a context
and get notification of the change through injection, e.g. if I instantiate
the following part through application.xmi in the photo demo, I would expect
that when the button is clicked, the context would inject the new value into
setTextValue(). But, setTextValue is not called. I think I'm
misunderstanding the pattern -- is there an intention that a property change
in the context could be listened to through injection?
public class ButtonPart {
@In(optional=true)
public void setTextValue(String s)
{
System.out.println("s");
}
public ButtonPart(Composite parent, final IWorkspace workspace, final
IEclipseContext outputContext)
{
Button button = new Button(parent, SWT.PUSH);
button.setText("Set Text");
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
outputContext.set("TextValue", "Quack");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
GridLayoutFactory.fillDefaults().generateLayout(parent);
}
}
2. Watching in the debugger, it seems that each instantiated part is passed
a different, parentless context (i.e.
IEclipseContext#get(IContextConstants.PARENT) returns null). I was expecting
that parts would be able to communicate with each other through the context,
i.e. that you could put a button in one part, that, when clicked, would
result in an injection into another part. If all the parts have different
and unconnected contexts though, I can't see how that would work, so I must
be misunderstanding something. Is there an intent for parts to be able to
communicate this way?
Thanks
-Gary
|
|
|
Re: questions about context [message #496874 is a reply to message #496649] |
Wed, 11 November 2009 15:48 |
|
You're on the right track, but it's the outputContext that's thowing you off. Things have changed quite a bit in 1.0, we're just heading into our M2 next week.
What you are trying should work in a current I build (although admittedly it's an extra step for an unknown reason).
public class ButtonPart {
@Inject @Optional
public void setTextValue(String s) {
System.out.println(s);
}
public ButtonPart(Composite parent, final IWorkspace workspace, final
IEclipseContext context)
{
Button button = new Button(parent, SWT.PUSH);
button.setText("Set Text");
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
context.set("textValue", "Quack");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// ...
}
In a current I build, you should get your context (as opposed to a parentless one).
In 0.9, you can always ask for your MContributedPart (or equivalent part of the model) and get the context out of there instead, that would allow provide you with your context.
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Re: questions about context [message #564637 is a reply to message #496649] |
Wed, 11 November 2009 15:48 |
|
You're on the right track, but it's the outputContext that's thowing you off. Things have changed quite a bit in 1.0, we're just heading into our M2 next week.
What you are trying should work in a current I build (although admittedly it's an extra step for an unknown reason).
public class ButtonPart {
@Inject @Optional
public void setTextValue(String s) {
System.out.println(s);
}
public ButtonPart(Composite parent, final IWorkspace workspace, final
IEclipseContext context)
{
Button button = new Button(parent, SWT.PUSH);
button.setText("Set Text");
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
context.set("textValue", "Quack");
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// ...
}
In a current I build, you should get your context (as opposed to a parentless one).
In 0.9, you can always ask for your MContributedPart (or equivalent part of the model) and get the context out of there instead, that would allow provide you with your context.
PW
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Goto Forum:
Current Time: Fri Mar 29 14:15:29 GMT 2024
Powered by FUDForum. Page generated in 0.02535 seconds
|