Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 901f9a1c0f2747e3cc6c07f1346aaca09e036819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2008 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation 
 *******************************************************************************/ 
package org.eclipse.linuxtools.oprofile.ui.model;

import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSymbol;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiMessages;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin;
import org.eclipse.swt.graphics.Image;

/**
 * Children of sessions in the view -- the binary which was profiled. 
 * May or may not have child symbols. Note that although the dependent
 * images are children of OpModelImages in the data model, for usability's
 * sake they are children of the parent session in the tree.
 * @since 1.1
 */
public class UiModelImage implements IUiModelElement {
	private IUiModelElement parent;		//parent element, may be UiModelSession or UiModelDependent
	private OpModelImage image;			//the node in the data model
	private UiModelSymbol symbols[];		//this node's child (symbols)
	private int totalCount;				//total number of samples 
	private int depCount;					//number of samples from dependent images

	/**
	 * Constructor to the UiModelImage class
	 * @param parent The parent element
	 * @param image The image node object in the data model
	 * @param totalCount The total number of samples
	 * @param depCount The number of samples from dependent images
	 */
	public UiModelImage(IUiModelElement parent, OpModelImage image, int totalCount, int depCount) {
		this.parent = parent;
		this.image = image;
		this.symbols = null;
		this.totalCount = totalCount;
		this.depCount = depCount;
		refreshModel();
	}
	/**
	 * Create the ui symbols from the data model.
	 */
	private void refreshModel() {
		OpModelSymbol[] dataModelSymbols = image.getSymbols();
		
		//dependent images may not have symbols
		if (dataModelSymbols != null) {
			symbols = new UiModelSymbol[dataModelSymbols.length];
	
			for (int i = 0; i < dataModelSymbols.length; i++) {
				symbols[i] = new UiModelSymbol(this, dataModelSymbols[i], totalCount);
			}
		}
	}
	
	@Override
	public String toString() {
		if (image.getCount() == OpModelImage.IMAGE_PARSE_ERROR) {
			return OprofileUiMessages.getString("opxmlParse.error.multipleImages"); //$NON-NLS-1$
		} else {
			double countPercentage = (double)(image.getCount() - depCount) / (double)totalCount;
			String percentage = OprofileUiPlugin.getPercentageString(countPercentage);
			
			return percentage + " " + OprofileUiMessages.getString("uimodel.percentage.in") + image.getName(); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
	
	/** IUiModelElement functions **/
	public String getLabelText() {
		return toString();
	}

	/**
	 * Returns the children of this element.
	 * @return An array of child elements or null
	 */
	public IUiModelElement[] getChildren() {
		IUiModelElement children[] = null;
		
		if (symbols != null) {
			children = new IUiModelElement[symbols.length];
			
			for (int i = 0; i < symbols.length; i++) {
				children[i] = symbols[i];
			}
		}
		
		return children;
	}
	/**
	 * Returns if the element has any children.
	 * @return true if the element has children, false otherwise
	 */
	public boolean hasChildren() {
		return (symbols == null || symbols.length == 0 ? false : true);
	}

	/**
	 * Returns the element's parent.
	 * @return parent The parent element or null
	 */
	public IUiModelElement getParent() {
		return parent;
	}

	/**
	 * Returns the Image to display next to the text in the tree viewer.
	 * @return an Image object of the icon
	 */
	public Image getLabelImage() {
		return OprofileUiPlugin.getImageDescriptor(OprofileUiPlugin.IMAGE_ICON).createImage();
	}
}

Back to the top