Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » singleton part (make Editor as singleton )
singleton part [message #1060685] Mon, 27 May 2013 15:22 Go to next message
AIT YAHIA Idir is currently offline AIT YAHIA Idir
Messages: 2
Registered: April 2013
Junior 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: Mon, 27 May 2013 16:17]

Report message to a moderator

Re: singleton part [message #1060702 is a reply to message #1060685] Tue, 28 May 2013 02:48 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 526
Registered: July 2012
Senior Member
If you create your instance with the new operator there is no injection. I think what you want to do is inject the current available MyViewPart into your LoadDataHandler.execute()
Previous Topic:Eclipse 4.2 (Helios) taking long time to open in Fedora 18
Goto Forum:
  


Current Time: Tue May 28 04:01:03 EDT 2013

Powered by FUDForum. Page generated in 0.01745 seconds