Edit a part context with an handler [message #833302] |
Sat, 31 March 2012 08:38 |
|
Goodmorning everyone,
I've got a problem.
I have an application with one Part who is linked to class editor.java
In this part there is a textarea and I'm trying to create a button menu who clean the textarea.
In editor.java there is this method:
@Inject
@Optional
public void setEditorTxt( @Named("setTxt") String text) {
txt.setText(text);
}
and in button's handler I've added this method:
@Execute
public <MApplication> void execute() {
MPart editor = partService.findPart("org.unifi.inf.tds.editorpart");
IEclipseContext cEditor = editor.getContext();
cEditor.set("setTxt", "");
}
First time I use the button, it works. Next time it doen't nothing.
Any suggestions?
Very thank you,
regards.
|
|
|
|
Re: Edit a part context with an handler [message #833557 is a reply to message #833302] |
Sat, 31 March 2012 17:52 |
Eclipse User |
|
|
|
A better way to do it as Brian suggested is to use IEventBroker.
Put this in the part class:
@Inject
public void clear(@Optional @UIEventTopic("CLEAR_IT") Object dummy){
if (txt!=null)
txt.setText("");
}
and this in the handler:
@Inject
IEventBroker eventBroker;
@Execute
public void execute() {
eventBroker.post("CLEAR_IT", null);
}
As to why your code doesn't work it's probably because the value in the context doesn't change and so it doesn't trigger a notification to the requester. But that isn't the proper way to handle events, IEventBroker is.
|
|
|
|
Re: Edit a part context with an handler [message #834680 is a reply to message #833557] |
Mon, 02 April 2012 08:56 |
|
Sopot Cela wrote on Sat, 31 March 2012 19:52
Put this in the part class:
@Inject
public void clear(@Optional @UIEventTopic("CLEAR_IT") Object dummy){
if (txt!=null)
txt.setText("");
}
and this in the handler:
@Inject
IEventBroker eventBroker;
@Execute
public void execute() {
eventBroker.post("CLEAR_IT", null);
}
I've tried to do this but method clear not be executed. eventBroker.post("CLEAR_IT", null); returns true but nothing happens.
Thank you for your kind,
TDS.
|
|
|
|
|
|
Re: Edit a part context with an handler [message #857450 is a reply to message #856125] |
Thu, 26 April 2012 14:49 |
|
I'm working again with part.
I want to create an infrastructure that opens part and gives them some information in a class called "EditorMaker".
I've seen this example on Vogella:
@Execute
public void open(
MyInput input
MApplication application,
EModelService modelService,
EPartService partService) {
// Assuming that all editors should open in the the stack with the
// ID "org.eclipse.e4.primaryDataStack"
MPartStack stack = (MPartStack) modelService.find("org.eclipse.e4.primaryDataStack", application);
MInputPart part = MBasicFactory.INSTANCE.createInputPart();
// Pointing to the contributing class
part.setContributionURI("bundleclass://de.vogella.rcp.e4.todo/de.vogella.rcp.e4.parts.Part1");
part.setInputURI(input.getInputURI());
part.setIconURI("platform:/plugin/de.vogella.rcp.e4.todo/icons/sample.gif");
part.setLabel(input.getName());
part.setTooltip(input.getTooltip());
part.setCloseable(true);
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
}
so I've tryed to do a code like that in my part's class:
@PostConstruct
public void createControls(Composite parent, EditorMaker em) {
System.out.println(em!=null);
}
EditorMaker is created by the handler which open the part.
But I've got this error:
org.eclipse.e4.core.di.InjectionException: Unable to process "Editor#createControls()": no actual value was found for the argument "EditorMaker".
Where is the mistake?
Thank you.
|
|
|
Re: Edit a part context with an handler [message #857472 is a reply to message #857450] |
Thu, 26 April 2012 15:10 |
Eclipse User |
|
|
|
That error shows that there is no value in the context which is an instance of EditorMarker. Putting 'em' as a parameter of a method annotated with @PostConstruct tells the framework to look for an instance of EditorMarker in the contexts up to the OSGi layer. Thus it does not make sense creating it in the handler and getting it injected at the same time.
In order for the injection to work, at some moment you should put it on a context accessible by the handler.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05458 seconds