sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/internal/ui/graph/ChartContainer.java
changeset 15 0367d2db2c06
parent 6 f65f740e69f9
equal deleted inserted replaced
14:bb339882c6e9 15:0367d2db2c06
    20 import org.eclipse.core.resources.IProject;
    20 import org.eclipse.core.resources.IProject;
    21 import org.eclipse.core.runtime.IProgressMonitor;
    21 import org.eclipse.core.runtime.IProgressMonitor;
    22 import org.eclipse.core.runtime.IStatus;
    22 import org.eclipse.core.runtime.IStatus;
    23 import org.eclipse.core.runtime.Status;
    23 import org.eclipse.core.runtime.Status;
    24 import org.eclipse.draw2d.ColorConstants;
    24 import org.eclipse.draw2d.ColorConstants;
       
    25 import org.eclipse.jface.window.Window;
    25 import org.eclipse.swt.SWT;
    26 import org.eclipse.swt.SWT;
    26 import org.eclipse.swt.events.ControlAdapter;
    27 import org.eclipse.swt.events.ControlAdapter;
    27 import org.eclipse.swt.events.ControlEvent;
    28 import org.eclipse.swt.events.ControlEvent;
    28 import org.eclipse.swt.events.PaintEvent;
    29 import org.eclipse.swt.events.PaintEvent;
    29 import org.eclipse.swt.events.PaintListener;
    30 import org.eclipse.swt.events.PaintListener;
    49 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModel;
    50 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModel;
    50 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener;
    51 import com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener;
    51 import com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo;
    52 import com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo;
    52 
    53 
    53 /**
    54 /**
    54  *  Container for the complete AnalyzeTool chart (x and y axis as well as graph)
    55  * Container for the complete AnalyzeTool chart (x and y axis as well as graph)
    55  *
    56  * 
    56  */
    57  */
    57 public class ChartContainer extends Composite implements IMemoryActivityModelChangeListener{
    58 public class ChartContainer extends Composite implements
    58 	
    59 		IMemoryActivityModelChangeListener {
       
    60 
       
    61 	static final int OPT_DRAWING_LIMIT = 25000;
    59 	private static final String ICON_PROPVIEW = "icons/properties.gif";//$NON-NLS-1$
    62 	private static final String ICON_PROPVIEW = "icons/properties.gif";//$NON-NLS-1$
    60 	private static final String ICON_HELP = "icons/linkto_help.gif";//$NON-NLS-1$
    63 	private static final String ICON_HELP = "icons/linkto_help.gif";//$NON-NLS-1$
    61 	
    64 	private static final String ICON_GRAPH_SETTINGS = "icons/graph_settings.png";//$NON-NLS-1$
       
    65 
    62 	private AnalyzeToolGraph graphCanvas;
    66 	private AnalyzeToolGraph graphCanvas;
    63 	private YAxis yAxis;
    67 	private YAxis yAxis;
    64 	private Combo processCombo;
    68 	private Combo processCombo;
    65 	private IMemoryActivityModel model;
    69 	private IMemoryActivityModel model;
    66 	private UIJob iRefreshUIJob;
    70 	private UIJob iRefreshUIJob;
    67 	
    71 
       
    72 	/** threshold for display of allocations */
       
    73 	private String thresholdVal;
       
    74 	private boolean thresholdAbove;
       
    75 	private ToolItem settingsButton;
       
    76 
    68 	/**
    77 	/**
    69 	 * Constructor
    78 	 * Constructor
    70 	 * 
    79 	 * 
    71 	 * @param parent
    80 	 * @param parent
    72 	 *            a widget which will be the parent of the new instance (cannot
    81 	 *            a widget which will be the parent of the new instance (cannot
    77 	public ChartContainer(Composite parent, int style) {
    86 	public ChartContainer(Composite parent, int style) {
    78 		super(parent, SWT.NONE);
    87 		super(parent, SWT.NONE);
    79 		setBackground(parent.getBackground());
    88 		setBackground(parent.getBackground());
    80 		constructChartArea();
    89 		constructChartArea();
    81 	}
    90 	}
    82 	
    91 
    83 	/**
    92 	/**
    84 	 * Builds up the main composite when opening for the first time
    93 	 * Builds up the main composite when opening for the first time
    85 	 */
    94 	 */
    86 	private void constructChartArea(){
    95 	private void constructChartArea() {
    87 		setLayout(new FormLayout());
    96 		setLayout(new FormLayout());
    88 			
    97 
    89 		Label processLabel = new Label(this, SWT.CENTER);
    98 		Label processLabel = new Label(this, SWT.CENTER);
    90 		processLabel.setText("Process:");
    99 		processLabel.setText("Process:");
    91 		processCombo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN);
   100 		processCombo = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN);
    92 
   101 
    93 		
   102 		ToolBar toolBar = new ToolBar(this, SWT.RIGHT | SWT.FLAT);
    94 		ToolBar toolBar = new ToolBar (this, SWT.RIGHT | SWT.FLAT);
   103 
    95 		
   104 		settingsButton = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT);
    96 		//toolbar button to open the Eclipse Properties view
   105 		settingsButton.addSelectionListener(new SelectionListener() {
    97 		ToolItem propViewItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT );
       
    98 		propViewItem.addSelectionListener(new SelectionListener(){
       
    99 
   106 
   100 			public void widgetDefaultSelected(SelectionEvent e) {
   107 			public void widgetDefaultSelected(SelectionEvent e) {
   101 				//do nothing by design
   108 				// do nothing by design
   102 			}
   109 			}
   103 
   110 
   104 			public void widgetSelected(SelectionEvent e) {
   111 			public void widgetSelected(SelectionEvent e) {
   105                 try {
   112 				// SettingsInputDialog dialog = new
   106                     PlatformUI.getWorkbench()
   113 				// SettingsInputDialog(thresholdVal, getShell());
   107                     .getActiveWorkbenchWindow().getActivePage()
   114 				GraphSettingsDialog dialog = new GraphSettingsDialog(
   108                     .showView("org.eclipse.ui.views.PropertySheet");//$NON-NLS-1$
   115 						getShell(), thresholdVal, thresholdAbove);
   109             } catch (PartInitException ex) {
   116 				if (dialog.open() == Window.OK) {
   110                     Activator.getDefault().log(IStatus.ERROR, ex.getMessage(), ex);
   117 					thresholdVal = dialog.getThresholdString();
   111             }
   118 					thresholdAbove = dialog.getAbove();
   112 			}
   119 					graphCanvas.setThreshold(dialog.getThreshold(),
   113 			
   120 							thresholdAbove);
       
   121 					graphCanvas.redraw();
       
   122 				}
       
   123 			}
       
   124 		});
       
   125 		settingsButton.setImage(Activator.getDefault().getImage(
       
   126 				ICON_GRAPH_SETTINGS));
       
   127 		settingsButton.setToolTipText("Graph Settings");
       
   128 		thresholdAbove = true; // initial value
       
   129 
       
   130 		// toolbar button to open the Eclipse Properties view
       
   131 		ToolItem propViewItem = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT);
       
   132 		propViewItem.addSelectionListener(new SelectionListener() {
       
   133 
       
   134 			public void widgetDefaultSelected(SelectionEvent e) {
       
   135 				// do nothing by design
       
   136 			}
       
   137 
       
   138 			public void widgetSelected(SelectionEvent e) {
       
   139 				try {
       
   140 					PlatformUI.getWorkbench().getActiveWorkbenchWindow()
       
   141 							.getActivePage().showView(
       
   142 									"org.eclipse.ui.views.PropertySheet");//$NON-NLS-1$
       
   143 				} catch (PartInitException ex) {
       
   144 					Activator.getDefault().log(IStatus.ERROR, ex.getMessage(),
       
   145 							ex);
       
   146 				}
       
   147 			}
       
   148 
   114 		});
   149 		});
   115 		propViewItem.setImage(Activator.getDefault().getImage(ICON_PROPVIEW));
   150 		propViewItem.setImage(Activator.getDefault().getImage(ICON_PROPVIEW));
   116 		propViewItem.setToolTipText("Show Properties View");
   151 		propViewItem.setToolTipText("Show Properties View");
   117 
   152 
   118 		//toolbar button to show some navigation help and open the F1 help
   153 		// toolbar button to show some navigation help and open the F1 help
   119 		ToolItem helpItem = new ToolItem (toolBar, SWT.PUSH | SWT.FLAT );
   154 		ToolItem helpItem = new ToolItem(toolBar, SWT.PUSH | SWT.FLAT);
   120 		helpItem.addSelectionListener(new SelectionListener(){
   155 		helpItem.addSelectionListener(new SelectionListener() {
   121 
   156 
   122 			public void widgetDefaultSelected(SelectionEvent e) {
   157 			public void widgetDefaultSelected(SelectionEvent e) {
   123 				//do nothing by design
   158 				// do nothing by design
   124 			}
   159 			}
   125 
   160 
   126 			public void widgetSelected(SelectionEvent e) {
   161 			public void widgetSelected(SelectionEvent e) {
   127 				PlatformUI.getWorkbench().getHelpSystem().displayHelp(AnalyzeToolHelpContextIDs.ANALYZE_GRAPH);
   162 				PlatformUI.getWorkbench().getHelpSystem().displayHelp(
   128 			}
   163 						AnalyzeToolHelpContextIDs.ANALYZE_GRAPH);
   129 			
   164 			}
       
   165 
   130 		});
   166 		});
   131 		helpItem.setImage(Activator.getDefault().getImage(ICON_HELP));
   167 		helpItem.setImage(Activator.getDefault().getImage(ICON_HELP));
   132 		helpItem.setToolTipText("Quick navigtion help\n-------------------------\nZoom in: select a region of the graph (mouse left-click and drag).\nZoom out: mouse right-click.\n\nSelect memory operation: mouse left-click in the graph.\nMove selection to next or previous using arrow left and arrow right keys.\n\nFor more help press F1");
   168 		helpItem
   133 		
   169 				.setToolTipText("Quick navigtion help\n-------------------------\nZoom in: select a region of the graph (mouse left-click and drag).\nZoom out: mouse right-click.\n\nSelect memory operation: mouse left-click in the graph.\nMove selection to next or previous using arrow left and arrow right keys.\n\nFor more help press F1");
       
   170 
   134 		yAxis = new YAxis(this);
   171 		yAxis = new YAxis(this);
   135 		yAxis.createContent();
   172 		yAxis.createContent();
   136 		graphCanvas = new AnalyzeToolGraph(this);
   173 		graphCanvas = new AnalyzeToolGraph(this);
   137 		graphCanvas.setSize(500, 450);
   174 		graphCanvas.setSize(500, 450);
   138 		
   175 
   139 		FormData formData = new FormData();
   176 		FormData formData = new FormData();
   140 		formData.top = new FormAttachment(0,2);
   177 		formData.top = new FormAttachment(0, 2);
   141 		formData.left   = new FormAttachment(0, 2);
   178 		formData.left = new FormAttachment(0, 2);
   142 		formData.height = processCombo.getBounds().height;
   179 		formData.height = processCombo.getBounds().height;
   143 		processLabel.setLayoutData(formData);
   180 		processLabel.setLayoutData(formData);
   144 		
   181 
   145 		formData = new FormData();
   182 		formData = new FormData();
   146 		formData.top = new FormAttachment(0);
   183 		formData.top = new FormAttachment(0);
   147 		formData.left   = new FormAttachment(processLabel, 10, SWT.BOTTOM);
   184 		formData.left = new FormAttachment(processLabel, 10, SWT.BOTTOM);
   148 		processCombo.setLayoutData(formData);
   185 		processCombo.setLayoutData(formData);
   149 
   186 
   150 		formData = new FormData();
   187 		formData = new FormData();
   151 		formData.top = new FormAttachment(0, 2);
   188 		formData.top = new FormAttachment(0, 2);
   152 		formData.right   = new FormAttachment(100, 2);
   189 		formData.right = new FormAttachment(100, 2);
   153 		toolBar.setLayoutData(formData);
   190 		toolBar.setLayoutData(formData);
   154 		
   191 
   155 		formData = new FormData();
   192 		formData = new FormData();
   156 		formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM);
   193 		formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM);
   157 		formData.bottom = new FormAttachment(100);
   194 		formData.bottom = new FormAttachment(100);
   158 		formData.left   = new FormAttachment(0);
   195 		formData.left = new FormAttachment(0);
   159 		formData.width  = 60;
   196 		formData.width = 60;
   160 		yAxis.setLayoutData(formData);
   197 		yAxis.setLayoutData(formData);
   161 		
   198 
   162 		formData = new FormData();
   199 		formData = new FormData();
   163 		formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM);
   200 		formData.top = new FormAttachment(processCombo, 5, SWT.BOTTOM);
   164 		formData.bottom = new FormAttachment(100);
   201 		formData.bottom = new FormAttachment(100);
   165 		formData.left   = new FormAttachment(yAxis, 0, SWT.RIGHT);
   202 		formData.left = new FormAttachment(yAxis, 0, SWT.RIGHT);
   166 		formData.right  = new FormAttachment(100);
   203 		formData.right = new FormAttachment(100);
   167 		graphCanvas.setLayoutData(formData);
   204 		graphCanvas.setLayoutData(formData);
   168 		
   205 
   169 		yAxis.setBackground(ColorConstants.white);
   206 		yAxis.setBackground(ColorConstants.white);
   170 		yAxis.addPaintListener(new PaintListener()
   207 		yAxis.addPaintListener(new PaintListener() {
   171 		{
       
   172 
   208 
   173 			public void paintControl(PaintEvent event) {
   209 			public void paintControl(PaintEvent event) {
   174 				
   210 
   175 				if(yAxis != null)
   211 				if (yAxis != null)
   176 					yAxis.paintYAxis(event.gc);
   212 					yAxis.paintYAxis(event.gc);
   177 			}		
   213 			}
   178 		});
   214 		});
   179 		
   215 
   180 		graphCanvas.setBackground(new Color(Display.getDefault(), new RGB(255,255,255)));
   216 		graphCanvas.setBackground(new Color(Display.getDefault(), new RGB(255,
       
   217 				255, 255)));
   181 		graphCanvas.createContent();
   218 		graphCanvas.createContent();
   182 		graphCanvas.addControlListener(new ControlAdapter() {
   219 		graphCanvas.addControlListener(new ControlAdapter() {
   183 			@Override
   220 			@Override
   184 			public void controlResized(ControlEvent e) {
   221 			public void controlResized(ControlEvent e) {
   185 				//the client area of the graph panel might change if a scrollbar gets added/removed 
   222 				// the client area of the graph panel might change if a
   186 				//this needs to be passed on to the y axis
   223 				// scrollbar gets added/removed
   187 				if (yAxis.getHeight() !=  graphCanvas.getClientArea().height){
   224 				// this needs to be passed on to the y axis
       
   225 				if (yAxis.getHeight() != graphCanvas.getClientArea().height) {
   188 					yAxis.setHeight(graphCanvas.getClientArea().height);
   226 					yAxis.setHeight(graphCanvas.getClientArea().height);
   189 					yAxis.redraw();
   227 					yAxis.redraw();
   190 				}
   228 				}
   191 			}
   229 			}
   192 			
   230 
   193 		});
   231 		});
   194 		
   232 
   195 		iRefreshUIJob = new UIJob("Updating process combo box"){
   233 		iRefreshUIJob = new UIJob("Updating process combo box") {
   196 
   234 
   197 			@Override
   235 			@Override
   198 			public IStatus runInUIThread(IProgressMonitor arg0) {
   236 			public IStatus runInUIThread(IProgressMonitor arg0) {
   199 				processCombo.removeAll();
   237 				processCombo.removeAll();
   200 				// Update combo box
   238 				// Update combo box
   201 				if (model.getProcesses().size() == 0){
   239 				if (model.getProcesses().size() == 0) {
   202 					processCombo.add("No data available");
   240 					processCombo.add("No data available");
   203 					processCombo.select(0);
   241 					processCombo.select(0);
       
   242 					settingsButton.setEnabled(false);
   204 				} else {
   243 				} else {
   205 					for (ProcessInfo p : model.getProcesses()) {
   244 					for (ProcessInfo p : model.getProcesses()) {
   206 						processCombo.add(String.format("%s with %d leak(s)",p.getProcessName() != null ? p.getProcessName() : p.getProcessID(), p.getMemLeaksNumber()));
   245 						processCombo.add(String.format("%s with %d leak(s)", p
       
   246 								.getProcessName() != null ? p.getProcessName()
       
   247 								: p.getProcessID(), p.getMemLeaksNumber()));
   207 					}
   248 					}
   208 					processCombo.setVisibleItemCount(10);
   249 					processCombo.setVisibleItemCount(10);
   209 				}
   250 				}
   210 				processCombo.pack();
   251 				processCombo.pack();
   211 				return Status.OK_STATUS;
   252 				return Status.OK_STATUS;
   212 			}
   253 			}
   213 			
   254 
   214 		};
   255 		};
   215 		iRefreshUIJob.setSystem(true);
   256 		iRefreshUIJob.setSystem(true);
   216 		
   257 
   217 		processCombo.addSelectionListener(new SelectionListener(){
   258 		processCombo.addSelectionListener(new SelectionListener() {
   218 
   259 
   219 			public void widgetDefaultSelected(SelectionEvent e) {
   260 			public void widgetDefaultSelected(SelectionEvent e) {
   220 				//do nothing by design
   261 				// do nothing by design
   221 			}
   262 			}
   222 
   263 
   223 			public void widgetSelected(SelectionEvent e) {
   264 			public void widgetSelected(SelectionEvent e) {
   224 				int sel = processCombo.getSelectionIndex();
   265 				int sel = processCombo.getSelectionIndex();
   225 				if (model.getProcesses().size()>sel){
   266 				if (model.getProcesses().size() > sel) {
   226 					ProcessInfo process = model.getProcesses().get(processCombo.getSelectionIndex());
   267 					ProcessInfo process = model.getProcesses().get(
       
   268 							processCombo.getSelectionIndex());
   227 					model.setSelectedProcess(process);
   269 					model.setSelectedProcess(process);
   228 					processCombo.setSize(processCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT));
   270 					processCombo.setSize(processCombo.computeSize(SWT.DEFAULT,
   229 				}
   271 							SWT.DEFAULT));
   230 			}
   272 					int ops = model.getSelectedProcess().getAllocsFrees()
   231 			
   273 							.size();
   232 		});
   274 					settingsButton.setEnabled(ops > 0
   233 		
   275 							&& ops <= OPT_DRAWING_LIMIT ? true : false);
   234 				
   276 				}
       
   277 			}
       
   278 		});
       
   279 
   235 		layout();
   280 		layout();
   236 		PlatformUI.getWorkbench().getHelpSystem().setHelp(
   281 		PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
   237 				this,
       
   238 				AnalyzeToolHelpContextIDs.ANALYZE_GRAPH);
   282 				AnalyzeToolHelpContextIDs.ANALYZE_GRAPH);
   239 	}
   283 	}
   240 
   284 
   241 	/**
   285 	/**
   242 	 * Sets a new model. Note the redraw of the new content only happens on 
   286 	 * Sets a new model. Note the redraw of the new content only happens on
   243 	 * callbacks to model change listeners.
   287 	 * callbacks to model change listeners.
   244 	 * @param aProject The currently selected project in the IDE, used for pinpointing
   288 	 * 
   245 	 * 
   289 	 * @param aProject
   246 	 * @param newModel the new IMemoryActivityModel to set
   290 	 *            The currently selected project in the IDE, used for
       
   291 	 *            pinpointing
       
   292 	 * 
       
   293 	 * @param newModel
       
   294 	 *            the new IMemoryActivityModel to set
   247 	 */
   295 	 */
   248 	public void setInput(IProject aProject, IMemoryActivityModel newModel) {
   296 	public void setInput(IProject aProject, IMemoryActivityModel newModel) {
   249 		if (this.model != null){
   297 		if (this.model != null) {
   250 			this.model.removeListener(this);
   298 			this.model.removeListener(this);
   251 		}
   299 		}
   252 		this.model = newModel;
   300 		this.model = newModel;
   253 		this.model.addListener(this);
   301 		this.model.addListener(this);
   254 
   302 
   257 		if (aProject != null) {
   305 		if (aProject != null) {
   258 			graphCanvas.setProject(aProject);
   306 			graphCanvas.setProject(aProject);
   259 		}
   307 		}
   260 	}
   308 	}
   261 
   309 
   262 	/* (non-Javadoc)
   310 	/*
   263 	 * @see com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener#onProcessSelected(com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo)
   311 	 * (non-Javadoc)
       
   312 	 * 
       
   313 	 * @see
       
   314 	 * com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener
       
   315 	 * #onProcessSelected
       
   316 	 * (com.nokia.s60tools.analyzetool.engine.statistic.ProcessInfo)
   264 	 */
   317 	 */
   265 	public void onProcessSelected(ProcessInfo p) {
   318 	public void onProcessSelected(ProcessInfo p) {
   266 		//do nothing by design
   319 		// do nothing by design
   267 	}
   320 	}
   268 
   321 
   269 	/* (non-Javadoc)
   322 	/*
   270 	 * @see com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener#onProcessesAdded()
   323 	 * (non-Javadoc)
       
   324 	 * 
       
   325 	 * @see
       
   326 	 * com.nokia.s60tools.analyzetool.engine.IMemoryActivityModelChangeListener
       
   327 	 * #onProcessesAdded()
   271 	 */
   328 	 */
   272 	public void onProcessesAdded() {
   329 	public void onProcessesAdded() {
   273 		iRefreshUIJob.cancel();
   330 		iRefreshUIJob.cancel();
   274 		iRefreshUIJob.schedule();
   331 		iRefreshUIJob.schedule();
   275 		
   332 	}
   276 	}	
   333 
   277 	
       
   278 	@Override
   334 	@Override
   279 	public void update(){
   335 	public void update() {
   280 		graphCanvas.zoomGraph();
   336 		graphCanvas.zoomGraph();
   281 		graphCanvas.redraw();
   337 		graphCanvas.redraw();
   282 		yAxis.redraw();
   338 		yAxis.redraw();
   283 	}
   339 	}
   284 }
   340 }