[solved] singleton part [message #1060685] |
Mon, 27 May 2013 19:22 |
AIT YAHIA Idir Messages: 39 Registered: April 2013 |
Member |
|
|
hi all.
this is what I want to do
I created a single Tableviewer in postContruction, and the user load the data from an external XML file via a menu command.
but when I try to load data via a method in the class, the recovered viewer is null (the method is called from a new instance of the class).
and I have a NullPointerException
I tried to make a class as singleton with anotation @Singleton, but i can't get existing instance (
it's the basic approach look like, but it's been two days that I'm trying to fix without success.
can someone help me by telling me how to proceed.
thanks in advance
My viepart class
@Singleton
public class MyViewPart {
private TableViewer viewer;
@PostConstruct
public void createControls(Composite parent)
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
{ // my code here }
public void loadData(filename)()
{
// my code here
}
}
My Menu commande handler
public class LoadDataHandler {
@Execute
public void execute() {
Shell shell = new Shell(Display.getDefault());
DirectoryDialog dialog = new DirectoryDialog(shell);
String fileSelected = dialog.open();
MyViewPart data = new MyViewPart();
data.loadData(fileSelected);
}
}
[Updated on: Tue, 28 May 2013 18:23] Report message to a moderator
|
|
|
|
|
|
Re: singleton part [message #1060768 is a reply to message #1060738] |
Tue, 28 May 2013 11:52 |
AIT YAHIA Idir Messages: 39 Registered: April 2013 |
Member |
|
|
i have tried your example i have not Exception but the @Execute execute methode is not fired,
in my MyViewPart Class il inject a Shell object and constructor like this, something wrong
public class MyViewPart {
@Inject private final Shell shell;
private TableViewer viewer;
List<satellite> Sate;
@Inject public MyViewPart (Composite parent,Shell shell) {
this.shell = shell;
}
@PostConstruct
public void createControls(Composite parent)
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
{ // my code here }
public void loadData(filename)()
{
// my code here
}
}
[Updated on: Tue, 28 May 2013 11:53] Report message to a moderator
|
|
|
|
|
|
|
|
Re: singleton part [message #1060845 is a reply to message #1060833] |
Tue, 28 May 2013 15:54 |
AIT YAHIA Idir Messages: 39 Registered: April 2013 |
Member |
|
|
Following your suggestion,
when using the @optional anotation on the parameter MyViewPart the handler is fired and Data object is null.
I could get my Part with EPartService (the result object is not null) but when i try to get the class name
MPart todoPart = EPartService.findPart("com.example.e4.rcp.todo.part.todooverview");
//
System.out.println(todoPart.getClass().getName());
i get this
Quote:org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl
this is not the name of the class associated with the Part
[Updated on: Tue, 28 May 2013 15:56] Report message to a moderator
|
|
|
|
|
|
Re: singleton part [message #1060925 is a reply to message #1060886] |
Wed, 29 May 2013 08:10 |
AIT YAHIA Idir Messages: 39 Registered: April 2013 |
Member |
|
|
I thought as the Shell is injected the probleme of Focus is turned off causes , yes my handler is triggered by a menu action,
in my case i need only one instance of my part, but in my whole project i have other case where i have a parts which will be multi-instantiated, i will see this when the time has comes,
in the training purpose, I would make an example with my part Focused, to see what happens
thank you again
[Updated on: Wed, 29 May 2013 08:16] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.26565 seconds