~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to oprofile/org.eclipse.linuxtools.oprofile.ui/src/org/eclipse/linuxtools/internal/oprofile/ui/model/UiModelRoot.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2008,2009 Red Hat, Inc.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation 
 
10
 *******************************************************************************/ 
 
11
package org.eclipse.linuxtools.internal.oprofile.ui.model;
 
12
 
 
13
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelEvent;
 
14
import org.eclipse.linuxtools.internal.oprofile.core.model.OpModelRoot;
 
15
import org.eclipse.swt.graphics.Image;
 
16
 
 
17
/**
 
18
 * Convenience class for creating the UI model from the oprofile data model,
 
19
 *  via a single point of access.
 
20
 */
 
21
public class UiModelRoot implements IUiModelElement {
 
22
        private static UiModelRoot uiModelRoot = new UiModelRoot();     //singleton
 
23
        private UiModelEvent[] events;                                                  //this node's children
 
24
        private UiModelError rootError;
 
25
 
 
26
        /** constructor, private for singleton use **/
 
27
        protected UiModelRoot() {
 
28
                events = null;
 
29
                rootError = null;
 
30
        }
 
31
        
 
32
        /**
 
33
         * Get the instance of this ui model root.
 
34
         * @return the ui model root object
 
35
         */
 
36
        public static UiModelRoot getDefault() {
 
37
                return uiModelRoot;
 
38
        }
 
39
 
 
40
        /**
 
41
         * Kick off creating the UI model from the data model. Meant to 
 
42
         *      be called from UI code. The refreshModel() method is called for 
 
43
         *  the child elements from their constructor.
 
44
         */
 
45
        public void refreshModel() {
 
46
                OpModelEvent dataModelEvents[] = getModelDataEvents();
 
47
                
 
48
                rootError = null;
 
49
                events = null;
 
50
 
 
51
                if (dataModelEvents == null || dataModelEvents.length == 0) {
 
52
                        rootError = UiModelError.NO_SAMPLES_ERROR;
 
53
                } else {
 
54
                        events = new UiModelEvent[dataModelEvents.length];
 
55
                        for (int i = 0; i < dataModelEvents.length; i++) {
 
56
                                events[i] = new UiModelEvent(dataModelEvents[i]);
 
57
                        }
 
58
                }
 
59
        }
 
60
        
 
61
        protected OpModelEvent[] getModelDataEvents() {
 
62
                OpModelRoot modelRoot = OpModelRoot.getDefault();
 
63
                return modelRoot.getEvents();
 
64
        }
 
65
 
 
66
        /** IUiModelElement functions **/
 
67
        public String getLabelText() {
 
68
                return null;
 
69
        }
 
70
 
 
71
        public IUiModelElement[] getChildren() {
 
72
                if (events != null)
 
73
                        return events;
 
74
                else
 
75
                        return new IUiModelElement[] { rootError };
 
76
        }
 
77
 
 
78
        public boolean hasChildren() {
 
79
                return true;
 
80
        }
 
81
 
 
82
        public IUiModelElement getParent() {
 
83
                return null;
 
84
        }
 
85
 
 
86
        public Image getLabelImage() {
 
87
                return null;
 
88
        }
 
89
}