package org.dawnsci.prototype.e4.nano.parts;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.dawnsci.analysis.api.dataset.IDataset;
import org.eclipse.dawnsci.analysis.api.io.IDataHolder;
import org.eclipse.dawnsci.analysis.api.io.ILoaderService;
import org.eclipse.dawnsci.analysis.dataset.impl.Random;
import org.eclipse.dawnsci.plotting.api.IPlotActionSystem;
import org.eclipse.dawnsci.plotting.api.IPlottingService;
import org.eclipse.dawnsci.plotting.api.IPlottingSystem;
import org.eclipse.dawnsci.plotting.api.PlotType;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.widgets.Composite;

public class PlotPart {

	IPlottingSystem<Composite> system;
	
	@Inject
	ILoaderService lService;
	
	@Inject
	public PlotPart(IPlottingService service){
		
	}
	
	@PostConstruct
	public void createComposite(Composite parent, MPart part,IPlottingService servicep) {
		try {
			system = servicep.createPlottingSystem();

		} catch (Exception ne) {
			throw new RuntimeException(ne); // Lazy
		}

//		String label = service.getActivePart().getLabel();
			
		system.createPlotPart(parent, part.getLabel(), null, PlotType.IMAGE, null);
		system.createPlot2D(Random.rand(new int[]{100,200}), null, null);
	}
	
	@Focus
	public void setFocus() {
		system.getPlotComposite().setFocus();
	}
	
	@Inject
	@Optional
	private void subscribeMyAppLoad
	  (@UIEventTopic("myapp/fileopen") 
	    String file) {
	  
		file.toString();
		lService.toString();
		try {
			IDataHolder data = lService.getData(file, null);
			IDataset dataset = data.getDataset("EDF");
			system.createPlot2D(dataset, null, null);
			data.toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	  }
	
}

@@ -1233,76 +1233,13 @@
 ne);
- // Lazy%0A%09%09%7D%0A%0A//%09%09String label = service.getActivePart().getLabel();
+%0A%09%09%7D%0A
 %0A%09%09%09
@@ -1321,76 +1321,8 @@
 l);%0A
-%09%09system.createPlot2D(Random.rand(new int%5B%5D%7B100,200%7D), null, null);%0A
 %09%7D%0A%09
@@ -1405,432 +1405,6 @@
 %7D%0A%09%0A
-%09@Inject%0A%09@Optional%0A%09private void subscribeMyAppLoad%0A%09  (@UIEventTopic(%22myapp/fileopen%22) %0A%09    String file) %7B%0A%09  %0A%09%09file.toString();%0A%09%09lService.toString();%0A%09%09try %7B%0A%09%09%09IDataHolder data = lService.getData(file, null);%0A%09%09%09IDataset dataset = data.getDataset(%22EDF%22);%0A%09%09%09system.createPlot2D(dataset, null, null);%0A%09%09%09data.toString();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09  %7D%0A%09%0A
 %7D%0A

Remove start noise plot