Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d717889fb32eb7ae493c00e303e261de7ac179c6 (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
/*******************************************************************************
 * 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.internal.oprofile.ui.model;

import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelEvent;
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelSession;
import org.eclipse.linuxtools.internal.oprofile.ui.OprofileUiPlugin;
import org.eclipse.swt.graphics.Image;

/**
 * Top level elements displayed in the view -- events that oprofile 
 *  has profiled. Must have children sessions.
 */
public class UiModelEvent implements IUiModelElement {
	private IUiModelElement _parent = null;		//parent node -- necessary?
	private OpModelEvent _event;				//the node in the data model
	private UiModelSession _sessions[];			//this node's children
	
	public UiModelEvent(OpModelEvent event) {
		if (event != null) {
			_event = event;
			refreshModel();
		}
	}

	/**
	 * Create the ui sessions from the data model.
	 */
	private void refreshModel() {
		OpModelSession dataModelSessions[] = _event.getSessions();
		_sessions = new UiModelSession[dataModelSessions.length];
		
		for (int i = 0; i < dataModelSessions.length; i++) {
			_sessions[i] = new UiModelSession(this, dataModelSessions[i]);
		}
	}

	@Override
	public String toString() {
		return (_event == null ? "" : _event.getName()); //$NON-NLS-1$
	}

	/** IUiModelElement functions **/
	public String getLabelText() {
		return toString();
	}
	
	public IUiModelElement[] getChildren() {
		return _sessions;
	}

	public boolean hasChildren() {
		return (_sessions == null || _sessions.length == 0 ? false : true);
	}

	public IUiModelElement getParent() {
		return _parent;
	}

	public Image getLabelImage() {
		return OprofileUiPlugin.getImageDescriptor(OprofileUiPlugin.EVENT_ICON).createImage();
	}
}

Back to the top