Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 167609 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+4 lines)
Lines 23-26 Link Here
23
JVMTI_ANALYSIS_TYPE_VIEW_UML_CLASS		= UML2 Class Interactions
23
JVMTI_ANALYSIS_TYPE_VIEW_UML_CLASS		= UML2 Class Interactions
24
JVMTI_ANALYSIS_TYPE_THRD_DESCRIPTION_TYPE = Thread Statistics
24
JVMTI_ANALYSIS_TYPE_THRD_DESCRIPTION_TYPE = Thread Statistics
25
JVMTI_ANALYSIS_TYPE_HEAP_DESCRIPTION_TYPE = Memory Statistics
25
JVMTI_ANALYSIS_TYPE_HEAP_DESCRIPTION_TYPE = Memory Statistics
26
JVMTI_ANALYSIS_TYPE_THREAD_STATES_DESCRIPTION_TYPE = Thread States
27
JVMTI_ANALYSIS_TYPE_CALL_STACK_DESCRIPTION_TYPE = Call Stack
26
JVMTI_ANALYSIS_TYPE_THRD_TOOLTIP        = Open Thread Statistics
28
JVMTI_ANALYSIS_TYPE_THRD_TOOLTIP        = Open Thread Statistics
29
JVMTI_ANALYSIS_TYPE_THREAD_STATES_TOOLTIP = Open Thread States
30
JVMTI_ANALYSIS_TYPE_CALL_STACK_TOOLTIP  = Open Call Stack
(-)plugin.xml (+44 lines)
Lines 90-95 Link Here
90
             id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatisticViewAction"
90
             id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatisticViewAction"
91
             name="%JVMTI_ANALYSIS_TYPE_THRD_DESCRIPTION_TYPE"
91
             name="%JVMTI_ANALYSIS_TYPE_THRD_DESCRIPTION_TYPE"
92
             type="org.eclipse.tptp.analysisType.jvmti.thread"/>
92
             type="org.eclipse.tptp.analysisType.jvmti.thread"/>
93
       <analyzerExtension
94
             class="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatesViewAction"
95
             extension="trace"
96
             id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatesViewAction"
97
             name="%JVMTI_ANALYSIS_TYPE_THREAD_STATES_DESCRIPTION_TYPE">
98
       </analyzerExtension>
93
	</extension>
99
	</extension>
94
100
95
   	<extension
101
   	<extension
Lines 101-106 Link Here
101
            class="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer"
107
            class="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer"
102
            id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer">
108
            id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer">
103
      </view>
109
      </view>
110
      <view
111
            category="org.eclipse.hyades.trace.internal.ui.trace"
112
            class="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatesViewer"
113
            id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatesViewer"
114
            name="%JVMTI_ANALYSIS_TYPE_THREAD_STATES_DESCRIPTION_TYPE"/>
115
      <view
116
            category="org.eclipse.hyades.trace.internal.ui.trace"
117
            class="org.eclipse.tptp.trace.jvmti.internal.client.views.CallStackViewer"
118
            id="org.eclipse.tptp.trace.jvmti.internal.client.views.CallStackView"
119
            name="%JVMTI_ANALYSIS_TYPE_CALL_STACK_DESCRIPTION_TYPE">
120
      </view>
104
   	</extension>
121
   	</extension>
105
122
106
   	<extension
123
   	<extension
Lines 113-118 Link Here
113
               relationship="stack"
130
               relationship="stack"
114
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer">
131
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer">
115
         </view>
132
         </view>
133
         <view
134
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatesViewer"
135
               relationship="stack"
136
               relative="org.eclipse.hyades.trace.views.adapter.internal.ExecutionStatisticViewer2"
137
               visible="false">
138
         </view>
139
         <view
140
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.CallStackViewer"
141
               relationship="bottom"
142
               relative="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatesViewer"
143
               visible="false">
144
         </view>
116
      </perspectiveExtension>
145
      </perspectiveExtension>
117
   	</extension>
146
   	</extension>
118
147
Lines 130-135 Link Here
130
               toolbarPath="trace/group.statistic"
159
               toolbarPath="trace/group.statistic"
131
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatisticViewAction">
160
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatisticViewAction">
132
         </action>
161
         </action>
162
         <action
163
               class="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatesViewAction"
164
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenThreadStatesViewAction"
165
               label="%JVMTI_ANALYSIS_TYPE_THREAD_STATES_DESCRIPTION_TYPE"
166
               style="push"
167
               toolbarPath="trace/group.statistic"
168
               tooltip="%JVMTI_ANALYSIS_TYPE_THREAD_STATES_TOOLTIP"/>
169
         <action
170
               class="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenCallStackViewAction"
171
               id="org.eclipse.tptp.trace.jvmti.internal.client.views.OpenCallStackViewAction"
172
               label="%JVMTI_ANALYSIS_TYPE_CALL_STACK_DESCRIPTION_TYPE"
173
               style="push"
174
               toolbarPath="trace/group.statistic"
175
               tooltip="%JVMTI_ANALYSIS_TYPE_CALL_STACK_TOOLTIP">
176
         </action>
133
      </actionSet>
177
      </actionSet>
134
   </extension>
178
   </extension>
135
179
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadStatisticViewer.java (-32 / +40 lines)
Lines 25-39 Link Here
25
import org.eclipse.jface.action.MenuManager;
25
import org.eclipse.jface.action.MenuManager;
26
import org.eclipse.tptp.platform.common.ui.internal.CommonUIConstants;
26
import org.eclipse.tptp.platform.common.ui.internal.CommonUIConstants;
27
27
28
public class ThreadStatisticViewer extends TraceViewer implements IContextViewer {
28
public class ThreadStatisticViewer extends TraceViewer implements
29
		IContextViewer {
29
30
30
	protected Action _chooseColumns;   
31
	protected Action _chooseColumns;
31
	protected Action _sortByColumn;
32
	protected Action _sortByColumn;
33
	protected Action _openCallStackView;
32
	protected ContextSelectionMenuListener _contextSelectionMenuListener;
34
	protected ContextSelectionMenuListener _contextSelectionMenuListener;
33
	
35
34
	protected String _context;
36
	protected String _context;
35
	protected boolean _contextChanged;
37
	protected boolean _contextChanged;
36
	
38
37
	public ThreadStatisticViewer() {
39
	public ThreadStatisticViewer() {
38
		super();
40
		super();
39
	}
41
	}
Lines 49-63 Link Here
49
	 * return the view title
51
	 * return the view title
50
	 */
52
	 */
51
	public String getViewTitle() {
53
	public String getViewTitle() {
52
		return UIMessages.TITLE;
54
		return UIMessages.THREAD_STATISTIC_TITLE;
53
	}
55
	}
54
	
56
55
	/**
57
	/**
56
	 * Returns the default page message.
58
	 * Returns the default page message.
57
	 * 
59
	 * 
58
	 */
60
	 */
59
	public String getDefaultPageMessage() {
61
	public String getDefaultPageMessage() {
60
		
62
61
		return UIMessages._269;
63
		return UIMessages._269;
62
	}
64
	}
63
65
Lines 68-74 Link Here
68
	public ContextSelectionMenuListener getContextSelectionMenuListener() {
70
	public ContextSelectionMenuListener getContextSelectionMenuListener() {
69
		if (_contextSelectionMenuListener == null)
71
		if (_contextSelectionMenuListener == null)
70
			_contextSelectionMenuListener = new ContextSelectionMenuListener();
72
			_contextSelectionMenuListener = new ContextSelectionMenuListener();
71
		
73
72
		return _contextSelectionMenuListener;
74
		return _contextSelectionMenuListener;
73
	}
75
	}
74
76
Lines 85-109 Link Here
85
			_contextChanged = _context != null;
87
			_contextChanged = _context != null;
86
		else
88
		else
87
			_contextChanged = !context.equals(_context);
89
			_contextChanged = !context.equals(_context);
88
		
90
89
		_context = context;
91
		_context = context;
90
		
92
91
		if (_contextChanged && refresh && getCurrentPage() != null)
93
		if (_contextChanged && refresh && getCurrentPage() != null)
92
			((TraceViewerPage)getCurrentPage()).refreshPage();
94
			((TraceViewerPage) getCurrentPage()).refreshPage();
93
	}
95
	}
94
96
95
	public void updateContext() {
97
	public void updateContext() {
96
		ContextUpdaterHelper.setCurrentFocusContextLanguage(getSelectedContext());
98
		ContextUpdaterHelper
99
				.setCurrentFocusContextLanguage(getSelectedContext());
97
		_contextChanged = false;
100
		_contextChanged = false;
98
	}
101
	}
99
102
100
    public Object[] getViewerControls()
103
	public Object[] getViewerControls() {
101
    {
104
		if (getCurrentPage() instanceof ThreadStatisticPage) {
102
    	if (getCurrentPage() instanceof ThreadStatisticPage) {
105
			return new Object[] { ((ThreadStatisticPage) getCurrentPage())
103
    		return new Object[] { ((ThreadStatisticPage)getCurrentPage()).getView().getTree() };
106
					.getView().getTree() };
104
    	}
107
		}
105
    	return null;
108
		return null;
106
    }
109
	}
107
110
108
	public EObject getObjectToView(EObject selObject) {
111
	public EObject getObjectToView(EObject selObject) {
109
		if (selObject == null)
112
		if (selObject == null)
Lines 117-125 Link Here
117
				TRCAgentProxy agent = (TRCAgentProxy) agents.get(idx);
120
				TRCAgentProxy agent = (TRCAgentProxy) agents.get(idx);
118
				if (agent == null || agent.eIsProxy())
121
				if (agent == null || agent.eIsProxy())
119
					continue;
122
					continue;
120
				if (agent
123
				if (agent.getType()
121
					.getType()
124
						.equals(CommonUIConstants.PROFILE_AGENT_TYPE)) {
122
					.equals(CommonUIConstants.PROFILE_AGENT_TYPE)) {
123
					nbOfAgents++;
125
					nbOfAgents++;
124
					a = agent;
126
					a = agent;
125
				}
127
				}
Lines 130-152 Link Here
130
		}
132
		}
131
		return selObject;
133
		return selObject;
132
	}
134
	}
133
	
135
134
	public void makeActions() {
136
	public void makeActions() {
135
		super.makeActions();
137
		super.makeActions();
136
138
137
		String strChooseColumns = TraceUIMessages._56;
139
		String strChooseColumns = TraceUIMessages._56;
138
		_chooseColumns = new Action(strChooseColumns) {
140
		_chooseColumns = new Action(strChooseColumns) {
139
			public void run() {
141
			public void run() {
140
				ThreadStatisticPage page = (ThreadStatisticPage)getCurrentPage();
142
				ThreadStatisticPage page = (ThreadStatisticPage) getCurrentPage();
141
				if (page == null) {
143
				if (page == null) {
142
					return;
144
					return;
143
				}
145
				}
144
				ThreadStatisticView view = page.getView();
146
				ThreadStatisticView view = page.getView();
145
				view.getChooseColumnsAction(view.getColumnDataList(), view.getColumnsPreferencesKey()).run();
147
				view.getChooseColumnsAction(view.getColumnDataList(),
148
						view.getColumnsPreferencesKey()).run();
146
			}
149
			}
147
		};
150
		};
148
		_chooseColumns.setText(strChooseColumns);
151
		_chooseColumns.setText(strChooseColumns);
149
		TracePluginImages.setImageDescriptors(_chooseColumns, TracePluginImages.T_LCL, TracePluginImages.IMG_CHOOSECOLUMNS);
152
		TracePluginImages.setImageDescriptors(_chooseColumns,
153
				TracePluginImages.T_LCL, TracePluginImages.IMG_CHOOSECOLUMNS);
150
		_chooseColumns.setDescription(strChooseColumns);
154
		_chooseColumns.setDescription(strChooseColumns);
151
		_chooseColumns.setToolTipText(strChooseColumns);
155
		_chooseColumns.setToolTipText(strChooseColumns);
152
		_chooseColumns.setEnabled(true);
156
		_chooseColumns.setEnabled(true);
Lines 154-160 Link Here
154
		String strSortByColumn = TraceUIMessages._58;
158
		String strSortByColumn = TraceUIMessages._58;
155
		_sortByColumn = new Action(strSortByColumn) {
159
		_sortByColumn = new Action(strSortByColumn) {
156
			public void run() {
160
			public void run() {
157
				ThreadStatisticPage page = (ThreadStatisticPage)getCurrentPage();
161
				ThreadStatisticPage page = (ThreadStatisticPage) getCurrentPage();
158
				if (page == null) {
162
				if (page == null) {
159
					return;
163
					return;
160
				}
164
				}
Lines 162-182 Link Here
162
				view.getSortByColumnAction().run();
166
				view.getSortByColumnAction().run();
163
			}
167
			}
164
		};
168
		};
165
		
169
166
		_sortByColumn.setText(strSortByColumn);
170
		_sortByColumn.setText(strSortByColumn);
167
		TracePluginImages.setImageDescriptors(_sortByColumn, TracePluginImages.T_LCL, TracePluginImages.IMG_SORTCOLUMNS);
171
		TracePluginImages.setImageDescriptors(_sortByColumn,
172
				TracePluginImages.T_LCL, TracePluginImages.IMG_SORTCOLUMNS);
168
		_sortByColumn.setDescription(strSortByColumn);
173
		_sortByColumn.setDescription(strSortByColumn);
169
		_sortByColumn.setToolTipText(strSortByColumn);
174
		_sortByColumn.setToolTipText(strSortByColumn);
170
		_sortByColumn.setEnabled(true);
175
		_sortByColumn.setEnabled(true);
171
		
176
177
		_openCallStackView = new OpenCallStackViewAction();
178
172
		IMenuManager menum = getViewSite().getActionBars().getMenuManager();
179
		IMenuManager menum = getViewSite().getActionBars().getMenuManager();
173
		menum.add(_chooseColumns);
180
		menum.add(_chooseColumns);
174
		menum.add(_sortByColumn);
181
		menum.add(_sortByColumn);
175
		
182
		menum.add(_openCallStackView);
183
176
		MenuManager submenu = new MenuManager(TraceUIMessages._222);
184
		MenuManager submenu = new MenuManager(TraceUIMessages._222);
177
		submenu.addMenuListener(getContextSelectionMenuListener());
185
		submenu.addMenuListener(getContextSelectionMenuListener());
178
		menum.add(submenu);
186
		menum.add(submenu);
179
		
187
180
		getViewSite().getActionBars().updateActionBars();
188
		getViewSite().getActionBars().updateActionBars();
181
	}
189
	}
182
}
190
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/UIMessages.java (-9 / +7 lines)
Lines 17-45 Link Here
17
public class UIMessages {
17
public class UIMessages {
18
	private static final String BUNDLE_NAME = "org.eclipse.tptp.trace.jvmti.internal.client.views.messages"; //$NON-NLS-1$
18
	private static final String BUNDLE_NAME = "org.eclipse.tptp.trace.jvmti.internal.client.views.messages"; //$NON-NLS-1$
19
19
20
	public static String TITLE;
20
	public static String THREAD_STATISTIC_TITLE;
21
	public static String THREAD_STATES_TITLE;
22
	public static String LEGEND_LABEL;
23
	public static String CURRENT_TIME;
24
	public static String SELECTED_TIME;
25
	public static String TIME_SCALE;
21
26
22
	public static String _261;
27
	public static String _261;
23
24
	public static String _262;
28
	public static String _262;
25
26
	public static String _263;
29
	public static String _263;
27
28
	public static String _264;
30
	public static String _264;
29
30
	public static String _265;
31
	public static String _265;
31
32
	public static String _266;
32
	public static String _266;
33
33
	public static String _267;
34
	public static String _269;
34
	public static String _269;
35
35
36
	private UIMessages() {
36
	private UIMessages() {
37
		// Do not instantiate
37
		// Do not instantiate
38
39
	}
38
	}
40
39
41
	static {
40
	static {
42
		NLS.initializeMessages(BUNDLE_NAME, UIMessages.class);
41
		NLS.initializeMessages(BUNDLE_NAME, UIMessages.class);
43
	}
42
	}
44
45
}
43
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadStatisticView.java (-246 / +225 lines)
Lines 57-103 Link Here
57
import org.eclipse.swt.widgets.TableColumn;
57
import org.eclipse.swt.widgets.TableColumn;
58
import org.eclipse.swt.widgets.Tree;
58
import org.eclipse.swt.widgets.Tree;
59
import org.eclipse.swt.widgets.TreeItem;
59
import org.eclipse.swt.widgets.TreeItem;
60
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.Utils;
60
61
61
/**
62
/**
62
 * This view contains thread statistics data.
63
 * This view contains thread statistics data.
63
 */
64
 */
64
public class ThreadStatisticView extends StatisticView {
65
public class ThreadStatisticView extends StatisticView {
65
66
67
	static final int COL_CLASS_NAME = 0;
68
	static final int COL_THREAD_NAME = 1;
69
	static final int COL_STATE = 2;
70
	static final int COL_RUN_TIME = 3;
71
	static final int COL_WAIT_TIME = 4;
72
	static final int COL_BLOCK_TIME = 5;
73
	static final int COL_BLOCK_COUNT = 6;
74
	static final int COL_DEADLOCK_TIME = 7;
75
	static final int COL_DEADLOCK_COUNT = 8;
76
66
	public static String PREFERENCE_KEY_PREFIX = "org.eclipse.hyades.trace.views.statistic.";
77
	public static String PREFERENCE_KEY_PREFIX = "org.eclipse.hyades.trace.views.statistic.";
67
	private boolean _isEmpty;
78
	private boolean _isEmpty;
68
	protected ContextInfoContainer _contextInfo;
79
	protected ContextInfoContainer _contextInfo;
69
80
70
	protected ColumnLabelAdapter[] _columns;
81
	protected ColumnLabelAdapter[] _columns;
71
	
82
72
	public ThreadStatisticView(Composite parent, TraceViewerPage page){
83
	public ThreadStatisticView(Composite parent, TraceViewerPage page) {
73
		super(parent, page);
84
		super(parent, page);
74
		
85
75
		createColumnsLabelProviders();
86
		createColumnsLabelProviders();
76
	}
87
	}
77
	
88
78
	protected String getContextHelpId()
89
	protected String getContextHelpId() {
79
	{
90
		return TraceUIPlugin.getPluginId() + ".stvw0001";
80
		return TraceUIPlugin.getPluginId()+".stvw0001";
91
	}
81
	}
92
82
	
93
	public void createColumnsLabelProviders() {
83
	public void createColumnsLabelProviders()
84
	{
85
		_columns = new ColumnLabelAdapter[] {
94
		_columns = new ColumnLabelAdapter[] {
86
			new ThreadClassNameColumnLabel(),
95
				new ThreadClassNameColumnLabel(),
87
			new ThreadNameColumnLabel(),
96
				new ThreadNameColumnLabel(),
88
			new ThreadStartTimeColumnLabel(),
97
				//new ThreadStartTimeColumnLabel(),
89
			new ThreadStopTimeColumnLabel(),
98
				//new ThreadStopTimeColumnLabel(),
90
			new ThreadStateColumnLabel(),
99
				new ThreadStateColumnLabel(),
91
			new ThreadRunningTimeColumnLabel(),
100
				new ThreadRunningTimeColumnLabel(),
92
//			new ThreadSleepingTimeColumnLabel(),
101
				//new ThreadSleepingTimeColumnLabel(),
93
			new ThreadWaitingTimeColumnLabel(),
102
				new ThreadWaitingTimeColumnLabel(),
94
			new ThreadBlockedTimeColumnLabel(),
103
				new ThreadBlockedTimeColumnLabel(),
95
			new ThreadBlockCountColumnLabel(),
104
				new ThreadBlockCountColumnLabel(),
96
			new ThreadDeadlockedTimeColumnLabel(),
105
				new ThreadDeadlockedTimeColumnLabel(),
97
			new ThreadDeadlockCountColumnLabel()
106
				new ThreadDeadlockCountColumnLabel() };
98
		};
99
	}
107
	}
100
	
108
101
	class ThreadStatisticTreeViewer extends TreeViewer {
109
	class ThreadStatisticTreeViewer extends TreeViewer {
102
		public ThreadStatisticTreeViewer(Composite parent) {
110
		public ThreadStatisticTreeViewer(Composite parent) {
103
			super(parent);
111
			super(parent);
Lines 111-160 Link Here
111
			item.setExpanded(true);
119
			item.setExpanded(true);
112
			createChildren(item);
120
			createChildren(item);
113
		}
121
		}
114
		
122
115
	    /**
123
		/**
116
	     * Returns the current selection for this provider.
124
		 * Returns the current selection for this provider.
117
	     * 
125
		 * 
118
	     * @return the current selection
126
		 * @return the current selection
119
	     */
127
		 */
120
	    public ISelection getSelection()
128
		public ISelection getSelection() {
121
	    {
129
			ISelection sel = super.getSelection();
122
	    	ISelection sel = super.getSelection();
130
			if (sel != null && !sel.isEmpty()) {
123
	    	if(sel != null && !sel.isEmpty())
131
				Object obj = ((IStructuredSelection) sel).getFirstElement();
124
	    	{
132
				if (obj instanceof ThreadDetails)
125
	    		Object obj = ((IStructuredSelection)sel).getFirstElement();
133
					return new StructuredSelection(((ThreadDetails) obj).getThread());
126
	    		if(obj instanceof ThreadDetails)
134
			}
127
	    			return new StructuredSelection(((ThreadDetails)obj).getThread());
135
			return sel;
128
	    	}
136
		}
129
	    	return sel;
137
130
	    }
138
	}
131
		
139
132
	}
140
	public class ThreadStatisticContentProvider implements ITreeContentProvider {
133
141
134
	public class ThreadStatisticContentProvider implements ITreeContentProvider
142
		public Object[] getChildren(Object element) {
135
	{
136
		
137
		public Object[] getChildren(Object element)
138
		{
139
			return null;
143
			return null;
140
		}
144
		}
141
		
145
142
		public Object getParent(Object element) {
146
		public Object getParent(Object element) {
143
			return null;
147
			return null;
144
		}		
148
		}
145
149
146
		public boolean hasChildren(Object element) {
150
		public boolean hasChildren(Object element) {
147
			return false;
151
			return false;
148
		}
152
		}
149
		
153
150
		/**
154
		/**
151
		 * return the list of elements to display in the table tree
155
		 * return the list of elements to display in the table tree
152
		 */
156
		 */
153
		public Object[] getElements(Object inputElement) {
157
		public Object[] getElements(Object inputElement) {
154
			Object[] threads = PerftraceUtil.getAllThreads(_page.getMOFObject(), false);
158
			Object[] threads = PerftraceUtil.getAllThreads(
159
					_page.getMOFObject(), false);
155
			Object[] elements = new Object[threads.length];
160
			Object[] elements = new Object[threads.length];
156
			for (int i=0; i < threads.length; i++) {
161
			for (int i = 0; i < threads.length; i++) {
157
				elements[i] = new ThreadDetails((TRCThread)threads[i]);
162
				elements[i] = new ThreadDetails((TRCThread) threads[i]);
158
			}
163
			}
159
			return elements;
164
			return elements;
160
		}
165
		}
Lines 165-231 Link Here
165
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
170
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
166
		}
171
		}
167
	}
172
	}
168
	
173
169
	public class ThreadStatisticLabelProvider extends LabelProvider
174
	public class ThreadStatisticLabelProvider extends LabelProvider implements
170
		implements ITableLabelProvider {
175
			ITableLabelProvider {
171
		protected StatisticView _viewer;
176
		protected StatisticView _viewer;
172
		
177
173
		public ThreadStatisticLabelProvider(StatisticView viewer) {
178
		public ThreadStatisticLabelProvider(StatisticView viewer) {
174
			_viewer = viewer;
179
			_viewer = viewer;
175
		}
180
		}
176
181
177
		public String getColumnText(Object obj, int col) {
182
		public String getColumnText(Object obj, int col) {
178
			StatisticTableColumnInfo info = StatisticTableColumnInfo.getStatisticTableColumnInfo(_viewer.getTree().getColumn(col));
183
			StatisticTableColumnInfo info =
179
            int pos = info.getColumnData().getInitalPos();
184
				StatisticTableColumnInfo.getStatisticTableColumnInfo(_viewer.getTree().getColumn(col));
180
185
			int pos = info.getColumnData().getInitalPos();
181
            if (pos >= 0 && pos < _columns.length) {
186
182
            	return getElementColumnText(obj, _columns[pos], info.isDeltaColumn());
187
			if (pos >= 0 && pos < _columns.length) {
183
            } else {
188
				return getElementColumnText(obj, _columns[pos], info.isDeltaColumn());
184
            	return "";
189
			} else {
185
            }
190
				return "";
191
			}
186
		}
192
		}
187
		
193
188
		public Image getColumnImage(Object obj, int col) {
194
		public Image getColumnImage(Object obj, int col) {
189
			StatisticTableColumnInfo info = StatisticTableColumnInfo.getStatisticTableColumnInfo(_viewer.getTree().getColumn(col));
195
			StatisticTableColumnInfo info = 
190
            int pos = info.getColumnData().getInitalPos();
196
				StatisticTableColumnInfo.getStatisticTableColumnInfo(_viewer.getTree().getColumn(col));
191
			
197
			int pos = info.getColumnData().getInitalPos();
192
            if (pos == 4) { // thread state
198
193
            	
199
			if (pos == COL_STATE) { // thread state
194
            }
200
			}
195
            
201
196
			if(info.isDeltaColumn())
202
			if (info.isDeltaColumn())
197
				return null;
203
				return null;
198
204
199
            if (pos >= 0 && pos < _columns.length) {
205
			if (pos >= 0 && pos < _columns.length) {
200
            	return getElementColumnImage(obj, _columns[pos], info.isDeltaColumn());
206
				return getElementColumnImage(obj, _columns[pos], info.isDeltaColumn());
201
            } else {
207
			} else {
202
            	return null;
208
				return null;
203
            }
209
			}
204
		}
210
		}
205
	}
211
	}
206
212
207
	public class ThreadStatisticSorter extends StatisticSorter {
213
	public class ThreadStatisticSorter extends StatisticSorter {
208
		
214
209
		public int compare(Viewer viewer, Object e1, Object e2) {
215
		public int compare(Viewer viewer, Object e1, Object e2) {
210
            if (_pos >= 0 && _pos < _columns.length) {
216
			if (_pos >= 0 && _pos < _columns.length) {
211
				return _sortSequence * compareElements(e1, e2, _columns[_pos], _info.isDeltaColumn());
217
				return _sortSequence * compareElements(e1, e2, _columns[_pos], _info.isDeltaColumn());
212
            } else {
218
			} else {
213
            	return 0;
219
				return 0;
214
            }
220
			}
215
		}
221
		}
216
	}
222
	}
217
223
218
	public class ThreadStatisticFilter extends StatisticFilter{
224
	public class ThreadStatisticFilter extends StatisticFilter {
219
		
225
220
		public ThreadStatisticFilter() {
226
		public ThreadStatisticFilter() {
221
			super();
227
			super();
222
		}
228
		}
223
		
229
224
		public boolean select(Viewer viewer, Object parent, Object element) {
230
		public boolean select(Viewer viewer, Object parent, Object element) {
225
			
231
226
			boolean flag = true;
232
			boolean flag = true;
227
			String compareText = (element instanceof TRCThread) ? 
233
			String compareText = (element instanceof TRCThread) ? PerftraceUtil.getThreadName((TRCThread) element) : "";
228
					PerftraceUtil.getThreadName((TRCThread)element) : "";
229
234
230
			if (_noPattern)
235
			if (_noPattern)
231
				return true;
236
				return true;
Lines 259-353 Link Here
259
			return flag;
264
			return flag;
260
		}
265
		}
261
	}
266
	}
262
	
267
263
	public String getDefaultColumnsTemplate()
268
	public String getDefaultColumnsTemplate() {
264
	{	
269
		return IContextAttributes.THREAD_CLASS_NAME + ":" + COL_CLASS_NAME + ":" + String.valueOf(ColumnData.NONDELETABLE | ColumnData.IS_VISIBLE | ColumnData.NONMOVABLE) + ":left:150,"
265
		return IContextAttributes.THREAD_CLASS_NAME 	+ ":0:" 
270
				+ IContextAttributes.THREAD_NAME + ":" + COL_THREAD_NAME + ":" + String.valueOf(ColumnData.NONDELETABLE | ColumnData.IS_VISIBLE | ColumnData.NONMOVABLE) + ":left:120,"
266
				+ String.valueOf(ColumnData.NONDELETABLE | ColumnData.IS_VISIBLE | ColumnData.NONMOVABLE) + ":left:150,"
271
				//+ IContextAttributes.THREAD_START_TIME + ":2:" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
267
			+  IContextAttributes.THREAD_NAME			+ ":1:" 
272
				//+ IContextAttributes.THREAD_STOP_TIME + ":3:" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
268
				+ String.valueOf(ColumnData.NONDELETABLE | ColumnData.IS_VISIBLE | ColumnData.NONMOVABLE) + ":left:120,"
273
				+ IContextAttributes.THREAD_STATE + ":" + COL_STATE + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
269
			+  IContextAttributes.THREAD_START_TIME		+ ":2:" 
274
				+ IContextAttributes.THREAD_RUNNING_TIME + ":" + COL_RUN_TIME + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:120," 
270
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
275
				//+ IContextAttributes.THREAD_SLEEPING_TIME + ":6:" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
271
			+  IContextAttributes.THREAD_STOP_TIME		+ ":3:" 
276
				+ IContextAttributes.THREAD_WAITING_TIME + ":" + COL_WAIT_TIME + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
272
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
277
				+ IContextAttributes.THREAD_BLOCKED_TIME + ":" + COL_BLOCK_TIME+ ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
273
			+  IContextAttributes.THREAD_STATE			+ ":4:" 
278
				+ IContextAttributes.THREAD_BLOCK_COUNT + ":" + COL_BLOCK_COUNT + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
274
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
279
				+ IContextAttributes.THREAD_DEADLOCKED_TIME + ":" + COL_DEADLOCK_TIME + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
275
			+  IContextAttributes.THREAD_RUNNING_TIME	+ ":5:" 
280
				+ IContextAttributes.THREAD_DEADLOCK_COUNT + ":" + COL_DEADLOCK_COUNT + ":" + String.valueOf(ColumnData.IS_VISIBLE) + ":right:80"
276
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
277
//			+  IContextAttributes.THREAD_SLEEPING_TIME	+ ":6:" 
278
//				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
279
			+  IContextAttributes.THREAD_WAITING_TIME	+ ":6:" 
280
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
281
			+  IContextAttributes.THREAD_BLOCKED_TIME	+ ":7:" 
282
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:120,"
283
			+  IContextAttributes.THREAD_BLOCK_COUNT	+ ":8:" 
284
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
285
			+  IContextAttributes.THREAD_DEADLOCKED_TIME+ ":9:" 
286
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80,"
287
				+  IContextAttributes.THREAD_DEADLOCK_COUNT	+ ":10:" 
288
				+ String.valueOf(ColumnData.IS_VISIBLE) + ":right:80"
289
				;
281
				;
290
	}		
282
	}
291
	
283
292
	public boolean isEmptyUpdate()
284
	public boolean isEmptyUpdate() {
293
	{
285
		// Object[] threads = PerftraceUtil.getAllThreads(_page.getMOFObject(), false);
294
//		Object[] threads = PerftraceUtil.getAllThreads(_page.getMOFObject(), false);
286
		// for (int i = 0; i < threads.length; i++) {
295
//		for (int i = 0; i < threads.length; i++) {
287
		// TRCThread thread = (TRCThread)threads[i];
296
//			TRCThread thread = (TRCThread)threads[i];
288
		// for (Iterator it = thread.getThreadEvents().iterator(); it.hasNext();
297
//			for (Iterator it = thread.getThreadEvents().iterator(); it.hasNext(); ) {
289
		// ) {
298
//				Object event = it.next();
290
		// Object event = it.next();
299
//				if (event instanceof TRCThreadWaitingForLockEvent
291
		// if (event instanceof TRCThreadWaitingForLockEvent
300
//						|| event instanceof TRCThreadWaitingForObjectEvent
292
		// || event instanceof TRCThreadWaitingForObjectEvent
301
//						|| event instanceof TRCThreadSleepingEvent
293
		// || event instanceof TRCThreadSleepingEvent
302
//						|| event instanceof TRCThreadDeadLockEvent) {
294
		// || event instanceof TRCThreadDeadLockEvent) {
303
					return false;
295
		return false;
304
//				}
296
		// }
305
//			}
297
		// }
306
//		}
298
		// }
307
//		return true;
299
		// return true;
308
	}
300
	}
309
	
301
310
	public IContentProvider getContentProvider()
302
	public IContentProvider getContentProvider() {
311
	{
312
		return new ThreadStatisticContentProvider();
303
		return new ThreadStatisticContentProvider();
313
	}
304
	}
314
	
305
315
	public LabelProvider getTableLabelProvider()
306
	public LabelProvider getTableLabelProvider() {
316
	{
317
		return new ThreadStatisticLabelProvider(this);
307
		return new ThreadStatisticLabelProvider(this);
318
	}
308
	}
319
	
309
320
	protected StatisticSorter getViewerSorterInstance()
310
	protected StatisticSorter getViewerSorterInstance() {
321
	{
322
		return new ThreadStatisticSorter();
311
		return new ThreadStatisticSorter();
323
	}
312
	}
324
	
313
325
	protected StatisticFilter getFilterInstance()
314
	protected StatisticFilter getFilterInstance() {
326
	{
327
		return new ThreadStatisticFilter();
315
		return new ThreadStatisticFilter();
328
	}	
316
	}
329
	
317
330
	public String getColumnsPreferencesKey()
318
	public String getColumnsPreferencesKey() {
331
	{
319
		return PREFERENCE_KEY_PREFIX + "ThreadStats2";
332
		return PREFERENCE_KEY_PREFIX + "ThreadStats1";
320
	}
333
	}
321
334
	
322
	protected String getViewTypeStr() {
335
	protected String getViewTypeStr()
336
	{
337
		return org.eclipse.hyades.trace.views.adapter.internal.TraceConstants.THREAD_STATS_VIEW;
323
		return org.eclipse.hyades.trace.views.adapter.internal.TraceConstants.THREAD_STATS_VIEW;
338
	}	
324
	}
339
	
325
340
	public void updateButtons() {
326
	public void updateButtons() {
341
	}	
327
	}
342
	
328
343
	protected void showPercentUpdate() {
329
	protected void showPercentUpdate() {
344
	}	
330
	}
345
	
331
346
	
332
	public void update() {
347
	public void update()
333
		if (_page instanceof ThreadStatisticPage) {
348
	{
349
		if(_page instanceof ThreadStatisticPage)
350
		{
351
			if (_contextInfo != null)
334
			if (_contextInfo != null)
352
				_contextInfo.setMOFObject(_page.getMOFObject());
335
				_contextInfo.setMOFObject(_page.getMOFObject());
353
		}
336
		}
Lines 355-369 Link Here
355
		for (int i = 0; i < _columns.length; i++) {
338
		for (int i = 0; i < _columns.length; i++) {
356
			_columns[i].resetMap();
339
			_columns[i].resetMap();
357
		}
340
		}
358
		
341
359
		super.update();
342
		super.update();
360
343
361
		if(_page instanceof ThreadStatisticPage)
344
		if (_page instanceof ThreadStatisticPage) {
362
		{
363
			_isEmpty = isEmptyUpdate();
345
			_isEmpty = isEmptyUpdate();
364
		}
346
		}
365
	}
347
	}
366
	
348
367
	public boolean isEmpty() {
349
	public boolean isEmpty() {
368
		return _isEmpty;
350
		return _isEmpty;
369
	}
351
	}
Lines 385-391 Link Here
385
							if (width > 0) {
367
							if (width > 0) {
386
								Region region = new Region();
368
								Region region = new Region();
387
								gc.getClipping(region);
369
								gc.getClipping(region);
388
								region.add(event.x, event.y, width, event.height); 
370
								region.add(event.x, event.y, width, event.height);
389
								gc.setClipping(region);
371
								gc.setClipping(region);
390
								region.dispose();
372
								region.dispose();
391
							}
373
							}
Lines 398-413 Link Here
398
						gc.setBackground(background);
380
						gc.setBackground(background);
399
						event.detail &= ~SWT.SELECTED;
381
						event.detail &= ~SWT.SELECTED;
400
					}
382
					}
401
				}						
383
				}
402
	
384
403
				ThreadDetails thread = (ThreadDetails) event.item.getData();
385
				ThreadDetails thread = (ThreadDetails) event.item.getData();
404
				int state = ThreadDetails.UNKNOWN;
386
				int state = ThreadDetails.UNKNOWN;
405
				if (event.index == 4) { // thread state
387
				if (event.index == COL_STATE) { // thread state
406
					state = thread.getState();
388
					state = thread.getState();
407
				} else if (event.index == 8 // block count 
389
				} else if (event.index == COL_BLOCK_COUNT // block count
408
						&& thread.getBlockCount() > 0) {
390
						&& thread.getBlockCount() > 0) {
409
					state = ThreadDetails.BLOCKED;
391
					state = ThreadDetails.BLOCKED;
410
				} else if (event.index == 10 // deadlock count 
392
				} else if (event.index == COL_DEADLOCK_COUNT // deadlock count
411
						&& thread.getDeadlockCount() > 0) {
393
						&& thread.getDeadlockCount() > 0) {
412
					state = ThreadDetails.DEADLOCK;
394
					state = ThreadDetails.DEADLOCK;
413
				}
395
				}
Lines 416-451 Link Here
416
					GC gc = event.gc;
398
					GC gc = event.gc;
417
					Color foreground = gc.getForeground();
399
					Color foreground = gc.getForeground();
418
					Color background = gc.getBackground();
400
					Color background = gc.getBackground();
419
	
401
420
					int c1 = ThreadDetails.getStateColor(state);
402
					int c1 = ThreadDetails.getStateColor(state);
421
					int c2 = selected ? SWT.COLOR_GRAY : SWT.COLOR_WHITE;
403
					int c2 = selected ? SWT.COLOR_GRAY : SWT.COLOR_WHITE;
422
					Color sysBack = display.getSystemColor(c1);
404
					Color sysBack = display.getSystemColor(c1);
423
					Color sysFore = display.getSystemColor(c2);
405
					Color sysFore = display.getSystemColor(c2);
424
					Color fore = mixColors(display, sysBack, sysFore, 1, 4);
406
					Color fore = Utils.mixColors(display, sysBack, sysFore, 1, 4);
425
					Color back = mixColors(display, sysBack, sysFore, 1, 1);
407
					Color back = Utils.mixColors(display, sysBack, sysFore, 1, 1);
408
409
					gc.setAdvanced(true);
410
					if (gc.getAdvanced()) {
411
						gc.setAlpha(180);
412
					}
426
413
427
	 				gc.setAdvanced(true);
428
	 				if (gc.getAdvanced()) {
429
	 					gc.setAlpha(180);
430
	 				}
431
	
432
					gc.setBackground(back);
414
					gc.setBackground(back);
433
					gc.setForeground(fore);
415
					gc.setForeground(fore);
434
					gc.fillGradientRectangle(event.x, event.y, event.width, event.height, false);
416
					gc.fillGradientRectangle(event.x, event.y, event.width, event.height, false);
435
	
417
436
					gc.setForeground(foreground);
418
					gc.setForeground(foreground);
437
					gc.setBackground(background);
419
					gc.setBackground(background);
438
					back.dispose();
420
					back.dispose();
439
					fore.dispose();
421
					fore.dispose();
440
				}
422
				}
441
			}
423
			}
442
443
			private Color mixColors(Display display, Color c1, Color c2, int w1, int w2) {
444
				return new Color(display,
445
						(w1 * c1.getRed() + w2 * c2.getRed()) / (w1 + w2), 
446
						(w1 * c1.getGreen() + w2 * c2.getGreen()) / (w1 + w2), 
447
						(w1 * c1.getBlue() + w2 * c2.getBlue()) / (w1 + w2));
448
			}
449
		};
424
		};
450
		tree.addListener(SWT.EraseItem, listener);
425
		tree.addListener(SWT.EraseItem, listener);
451
		return tree;
426
		return tree;
Lines 460-521 Link Here
460
	}
435
	}
461
436
462
	protected void handleSelectionEvent() {
437
	protected void handleSelectionEvent() {
463
		ITraceSelection model =
438
		ITraceSelection model = UIPlugin.getDefault().getSelectionModel(_page.getMOFObject());
464
			UIPlugin.getDefault().getSelectionModel(_page.getMOFObject());
465
		if (model.size() > 0) {
439
		if (model.size() > 0) {
466
			Object sel = model.getFirstElement();
440
			Object sel = model.getFirstElement();
467
			if (sel != null) {
441
			if (sel != null) {
468
				select(sel);
442
				select(sel);
469
				
470
				if (sel instanceof EObject)
443
				if (sel instanceof EObject)
471
					updateStatusContext(ContextManager.getContextLanguage(ContextUpdaterHelper.getContext((EObject)sel)));
444
					updateStatusContext(ContextManager.getContextLanguage(ContextUpdaterHelper.getContext((EObject) sel)));
472
			}
445
			}
473
		}
446
		}
474
	}
447
	}
475
448
476
	public void updateModelSelection() {
449
	public void updateModelSelection() {
477
		ISelection selection = getTreeViewer().getSelection();
450
		ISelection selection = getTreeViewer().getSelection();
478
		if(selection != null && !selection.isEmpty())
451
		Object sel = null;
479
		{
452
		if (selection != null && !selection.isEmpty()) {
480
			Object sel = ((IStructuredSelection)selection).getFirstElement();
453
			sel = ((IStructuredSelection) selection).getFirstElement();
481
			if(sel instanceof ThreadDetails)
454
			if (sel instanceof ThreadDetails)
482
				notifyViewSelectionChanged(this, ((ThreadDetails)sel).getThread());
455
				sel = ((ThreadDetails) sel).getThread();
483
			else	
456
			notifyViewSelectionChanged(this, sel);
484
				notifyViewSelectionChanged(this,sel);
457
		}
458
	}
459
460
	public TRCThread getSelectedThread() {
461
		TRCThread thread = null;
462
		ISelection selection = getTreeViewer().getSelection();
463
		if (selection != null && !selection.isEmpty()) {
464
			Object sel = ((IStructuredSelection) selection).getFirstElement();
465
			if (sel instanceof TRCThread)
466
				thread = (TRCThread) sel;
467
			if (sel instanceof ThreadDetails)
468
				thread = ((ThreadDetails) sel).getThread();
485
		}
469
		}
470
		return thread;
486
	}
471
	}
487
472
488
	public void handleViewSelectionChangedEvent(ViewSelectionChangedEvent event) {
473
	public void handleViewSelectionChangedEvent(ViewSelectionChangedEvent event) {
489
		Object  source = event.getSource();
474
		Object source = event.getSource();
490
		if(source!=this){	
475
		if (source != this) {
491
			handleSelectionEvent();
476
			handleSelectionEvent();
492
		}
477
		} else {
493
		else
478
			ITraceSelection model = UIPlugin.getDefault().getSelectionModel(_page.getMOFObject());
494
		{
495
			ITraceSelection model =
496
				UIPlugin.getDefault().getSelectionModel(_page.getMOFObject());
497
			if (model.size() > 0) {
479
			if (model.size() > 0) {
498
				Object sel = model.getFirstElement();
480
				Object sel = model.getFirstElement();
499
				if (sel != null && sel instanceof EObject)
481
				if (sel != null && sel instanceof EObject)
500
						updateStatusContext(ContextManager.getContextLanguage(ContextUpdaterHelper.getContext((EObject)sel)));
482
					updateStatusContext(ContextManager.getContextLanguage(ContextUpdaterHelper.getContext((EObject) sel)));
501
			}
483
			}
502
		}
484
		}
503
	}
485
	}
504
486
505
	public void menuAboutToShow(IMenuManager menu) {
487
	public void menuAboutToShow(IMenuManager menu) {
506
507
		menu.add(getUpdateAction());
488
		menu.add(getUpdateAction());
508
		menu.add(fSeparator);
489
		menu.add(fSeparator);
509
		resetChooseColumnsAction();
490
		resetChooseColumnsAction();
510
		menu.add(
491
		menu.add(getChooseColumnsAction(getColumnDataList(),
511
			getChooseColumnsAction(
512
				getColumnDataList(),
513
				getColumnsPreferencesKey()));
492
				getColumnsPreferencesKey()));
514
		menu.add(
493
		menu.add(getSortByColumnAction());
515
			getSortByColumnAction());
516
					
517
	}
494
	}
518
	
495
519
	public void widgetSelected(SelectionEvent e) {
496
	public void widgetSelected(SelectionEvent e) {
520
		super.widgetSelected(e);
497
		super.widgetSelected(e);
521
		if (e.widget instanceof TableColumn) {
498
		if (e.widget instanceof TableColumn) {
Lines 528-534 Link Here
528
		super.resetColumns(list);
505
		super.resetColumns(list);
529
		expandFirstElement();
506
		expandFirstElement();
530
	}
507
	}
531
	
508
532
	protected void resetChooseColumnsAction() {
509
	protected void resetChooseColumnsAction() {
533
		_chooseColumnAction = null;
510
		_chooseColumnAction = null;
534
	}
511
	}
Lines 538-556 Link Here
538
			return;
515
			return;
539
		}
516
		}
540
		if (obj instanceof ThreadDetails) {
517
		if (obj instanceof ThreadDetails) {
541
			obj = ((ThreadDetails)obj).getThread();
518
			obj = ((ThreadDetails) obj).getThread();
542
		}
519
		}
543
		Tree tree = getTree();
520
		Tree tree = getTree();
544
		TreeItem[] items = tree.getItems();
521
		TreeItem[] items = tree.getItems();
545
		
522
546
		TreeItem item = null;
523
		TreeItem item = null;
547
		for (int j = 0; j < items.length; j++) {
524
		for (int j = 0; j < items.length; j++) {
548
			item = items[j];
525
			item = items[j];
549
526
550
			if (item!=null && !item.isDisposed()) {
527
			if (item != null && !item.isDisposed()) {
551
				Object data = item.getData();
528
				Object data = item.getData();
552
				if (data instanceof ThreadDetails) {
529
				if (data instanceof ThreadDetails) {
553
					data = ((ThreadDetails)data).getThread();
530
					data = ((ThreadDetails) data).getThread();
554
				}
531
				}
555
				if (data == obj) {
532
				if (data == obj) {
556
					tree.setSelection(item);
533
					tree.setSelection(item);
Lines 562-592 Link Here
562
539
563
	protected Composite createControl(Composite parent, ArrayList cols) {
540
	protected Composite createControl(Composite parent, ArrayList cols) {
564
		final Composite vc = super.createControl(parent, cols);
541
		final Composite vc = super.createControl(parent, cols);
565
		
542
566
		if (_page.getTraceViewer() instanceof MultiLevelStatisticViewer)
543
		if (_page.getTraceViewer() instanceof MultiLevelStatisticViewer) {
567
		{
568
			_contextInfo = new ContextInfoContainer();
544
			_contextInfo = new ContextInfoContainer();
569
			_contextInfo.setViewer((IContextViewer)_page.getTraceViewer());
545
			_contextInfo.setViewer((IContextViewer) _page.getTraceViewer());
570
			_contextInfo.createControl(vc);
546
			_contextInfo.createControl(vc);
571
			_contextInfo.addContextInfoContainerListener(
547
			_contextInfo.addContextInfoContainerListener(new IContextInfoContainerListener() {
572
					new IContextInfoContainerListener()
548
						public void visibilityChanged(boolean isVisible) {
573
					{
574
						public void visibilityChanged(boolean isVisible)
575
						{
576
							vc.layout(true, true);
549
							vc.layout(true, true);
577
						}
550
						}
578
					});
551
					});
579
		}
552
		}
580
		
553
581
		return vc;
554
		return vc;
582
	}
555
	}
583
	
556
584
	protected void updateStatusContext(IContextLanguage language)
557
	protected void updateStatusContext(IContextLanguage language) {
585
	{
586
		if (_contextInfo != null)
558
		if (_contextInfo != null)
587
			_contextInfo.updateStatusContext(language);
559
			_contextInfo.updateStatusContext(language);
588
	}
560
	}
589
	
561
590
	protected void firstTimeUpdate() {
562
	protected void firstTimeUpdate() {
591
		super.firstTimeUpdate();
563
		super.firstTimeUpdate();
592
		redrawTable();
564
		redrawTable();
Lines 598-609 Link Here
598
570
599
	public void redrawTable() {
571
	public void redrawTable() {
600
		getTree().setRedraw(false);
572
		getTree().setRedraw(false);
601
573
		ArrayList list = ColumnData.createColumnData(getColumnsPreferencesKey()
602
		ArrayList list = ColumnData.createColumnData(getColumnsPreferencesKey(), getDefaultColumnsTemplate());
574
				, getDefaultColumnsTemplate());
603
		resetColumns(list);
575
		resetColumns(list);
604
		_currentColumns = list;
576
		_currentColumns = list;
605
		getTree().setRedraw(true);
577
		getTree().setRedraw(true);
606
		
607
		refresh();
578
		refresh();
608
	}
579
	}
580
581
	public void dispose() {
582
		super.dispose();
583
	}
584
585
	public void widgetDefaultSelected(SelectionEvent arg0) {
586
		OpenCallStackViewAction.openCallStackView(false);
587
	}
609
}
588
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/messages.properties (-1 / +7 lines)
Lines 13-23 Link Here
13
# NLS_MESSAGEFORMAT_NONE
13
# NLS_MESSAGEFORMAT_NONE
14
# NLS_ENCODING=UTF-8
14
# NLS_ENCODING=UTF-8
15
15
16
TITLE = Thread Statistics
16
THREAD_STATISTIC_TITLE = Thread Statistics
17
THREAD_STATES_TITLE = Thread States
18
LEGEND_LABEL = Legend
19
CURRENT_TIME = Current Time
20
SELECTED_TIME = Selected Time
21
TIME_SCALE = Time Scale
17
_261 = Running
22
_261 = Running
18
_262 = Sleeping
23
_262 = Sleeping
19
_263 = Waiting
24
_263 = Waiting
20
_264 = Blocked
25
_264 = Blocked
21
_265 = Deadlock
26
_265 = Deadlock
22
_266 = Stopped
27
_266 = Stopped
28
_267 = Unknown
23
_269 = No thread statistics is available for display.\nEither you have no trace selected in the Profiling Monitor view or the current selection does not contain thread statistics information.\n\nNote:\nThis view is available only if the trace contains thread statistics. To collect this type of information, on the Profile tab in the Launch configuration, choose the Thread Statistics option.
29
_269 = No thread statistics is available for display.\nEither you have no trace selected in the Profiling Monitor view or the current selection does not contain thread statistics information.\n\nNote:\nThis view is available only if the trace contains thread statistics. To collect this type of information, on the Profile tab in the Launch configuration, choose the Thread Statistics option.
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/OpenThreadStatisticViewAction.java (-1 / +1 lines)
Lines 24-30 Link Here
24
24
25
public class OpenThreadStatisticViewAction extends OpenTraceViewAction {
25
public class OpenThreadStatisticViewAction extends OpenTraceViewAction {
26
26
27
	private final String VIEW_ID="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer";
27
	static final String VIEW_ID="org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatisticViewer";
28
	
28
	
29
	public OpenThreadStatisticViewAction() {
29
	public OpenThreadStatisticViewAction() {
30
		super("");
30
		super("");
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/ThreadStatesCtrl.java (+881 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import java.util.ArrayList;
18
import java.util.Hashtable;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Set;
22
23
import org.eclipse.emf.common.util.EList;
24
import org.eclipse.hyades.models.trace.TRCThread;
25
import org.eclipse.hyades.models.trace.TRCThreadEvent;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.ControlEvent;
30
import org.eclipse.swt.events.ControlListener;
31
import org.eclipse.swt.events.FocusEvent;
32
import org.eclipse.swt.events.FocusListener;
33
import org.eclipse.swt.events.KeyEvent;
34
import org.eclipse.swt.events.KeyListener;
35
import org.eclipse.swt.events.MouseEvent;
36
import org.eclipse.swt.events.MouseListener;
37
import org.eclipse.swt.events.MouseMoveListener;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.events.SelectionListener;
40
import org.eclipse.swt.graphics.GC;
41
import org.eclipse.swt.graphics.Point;
42
import org.eclipse.swt.graphics.Rectangle;
43
import org.eclipse.swt.widgets.Composite;
44
45
public class ThreadStatesCtrl extends TraceCtrl implements FocusListener,
46
		KeyListener, MouseMoveListener, MouseListener, ControlListener,
47
		SelectionListener {
48
49
	private ITimeDataProvider _timeProvider;
50
	boolean _isInFocus = false;
51
	private int _topItem = 0;
52
	private int _itemHeight = 18;
53
	private int _dragState = 0;
54
	private int _hitIdx = 0;
55
	private int _dragX0 = 0;
56
	private int _dragX = 0;
57
	private double _timeStep = 0.01;
58
	private double _time0bak;
59
	private double _time1bak;
60
	private ItemData _data = new ItemData();
61
	private ArrayList _selectionListeners;
62
63
	public ThreadStatesCtrl(Composite parent, TraceColorScheme colors) {
64
		super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.V_SCROLL);
65
		addFocusListener(this);
66
		addMouseListener(this);
67
		addMouseMoveListener(this);
68
		addKeyListener(this);
69
		addControlListener(this);
70
		getVerticalBar().addSelectionListener(this);
71
		getHorizontalBar().addSelectionListener(this);
72
	}
73
74
	public void setTimeProvider(ITimeDataProvider timeProvider) {
75
		_timeProvider = timeProvider;
76
		adjustScrolls();
77
		redraw();
78
	}
79
80
	public void addSelectionListener(SelectionListener listener) {
81
		if (listener == null)
82
			SWT.error(SWT.ERROR_NULL_ARGUMENT);
83
		if (null == _selectionListeners)
84
			_selectionListeners = new ArrayList();
85
		_selectionListeners.add(listener);
86
	}
87
88
	public void removeSelectionListener(SelectionListener listener) {
89
		if (null != _selectionListeners)
90
			_selectionListeners.remove(listener);
91
	}
92
93
	public void fireSelectionChanged() {
94
		if (null != _selectionListeners) {
95
			Iterator it = _selectionListeners.iterator();
96
			while (it.hasNext()) {
97
				SelectionListener listener = (SelectionListener) it.next();
98
				listener.widgetSelected(null);
99
			}
100
		}
101
	}
102
103
	public void fireDefaultSelection() {
104
		if (null != _selectionListeners) {
105
			Iterator it = _selectionListeners.iterator();
106
			while (it.hasNext()) {
107
				SelectionListener listener = (SelectionListener) it.next();
108
				listener.widgetDefaultSelected(null);
109
			}
110
		}
111
	}
112
113
	public void refreshData(Object threads[]) {
114
		_data.refreshData(threads);
115
		adjustScrolls();
116
		redraw();
117
	}
118
119
	public void adjustScrolls() {
120
		if (null == _timeProvider) {
121
			getVerticalBar().setValues(0, 1, 1, 1, 1, 1);
122
			getHorizontalBar().setValues(0, 1, 1, 1, 1, 1);
123
			return;
124
		}
125
		int page = countPerPage();
126
		if (_topItem + page > _data._items.length)
127
			_topItem = _data._items.length - page;
128
		if (_topItem < 0)
129
			_topItem = 0;
130
		getVerticalBar().setValues(_topItem, 0, _data._items.length, page, 1,
131
				page);
132
		double time0 = _timeProvider.getTime0();
133
		double time1 = _timeProvider.getTime1();
134
		double timeMin = _timeProvider.getMinTime();
135
		double timeMax = _timeProvider.getMaxTime();
136
		int timePage = (int) ((time1 - time0) / _timeStep);
137
		int timePos = (int) (time0 / _timeStep);
138
		getHorizontalBar().setValues(timePos, (int) (timeMin / _timeStep),
139
				(int) (timeMax / _timeStep), timePage, 1, timePage);
140
	}
141
142
	boolean ensureVisibleItem(int idx, boolean redraw) {
143
		boolean changed = false;
144
		if (idx < 0 || idx >= _data._items.length)
145
			return changed;
146
		if (idx < _topItem) {
147
			_topItem = idx;
148
			getVerticalBar().setSelection(_topItem);
149
			if (redraw)
150
				redraw();
151
			changed = true;
152
		} else {
153
			int page = countPerPage();
154
			if (idx >= _topItem + page) {
155
				_topItem = idx - page + 1;
156
				getVerticalBar().setSelection(_topItem);
157
				if (redraw)
158
					redraw();
159
				changed = true;
160
			}
161
		}
162
		return changed;
163
	}
164
165
	static TRCThreadEvent getFirstEvent(TRCThread thread) {
166
		EList list = thread.getThreadEvents();
167
		TRCThreadEvent event = null;
168
		if (!list.isEmpty())
169
			event = (TRCThreadEvent) list.get(0);
170
		return event;
171
	}
172
173
	static TRCThreadEvent findEvent(TRCThread thread, double time, int n) {
174
		EList list = thread.getThreadEvents();
175
		Iterator it = list.iterator();
176
		TRCThreadEvent event = null;
177
		TRCThreadEvent prevEvent = null;
178
		TRCThreadEvent nextEvent = null;
179
		if (it.hasNext()) {
180
			event = (TRCThreadEvent) it.next();
181
			double currTime = event.getTime();
182
			if (time < currTime) {
183
				if (1 != n)
184
					event = null;
185
				return event;
186
			}
187
			while (it.hasNext()) {
188
				nextEvent = (TRCThreadEvent) it.next();
189
				double nextTime = nextEvent.getTime();
190
				if (currTime <= time && time < nextTime) {
191
					if (1 == n)
192
						event = nextEvent;
193
					else if (-1 == n)
194
						event = prevEvent;
195
					return event;
196
				}
197
				prevEvent = event;
198
				event = nextEvent;
199
			}
200
		}
201
		if (1 == n)
202
			event = null;
203
		else if (-1 == n)
204
			event = prevEvent;
205
		return event;
206
	}
207
208
	static class Selection implements IStructuredSelection {
209
210
		List list = new ArrayList();
211
212
		public Object getFirstElement() {
213
			if (!list.isEmpty())
214
				return list.get(0);
215
			return null;
216
		}
217
218
		public Iterator iterator() {
219
			return list.iterator();
220
		}
221
222
		public int size() {
223
			return list.size();
224
		}
225
226
		public Object[] toArray() {
227
			return list.toArray();
228
		}
229
230
		public List toList() {
231
			return list;
232
		}
233
234
		public boolean isEmpty() {
235
			return list.isEmpty();
236
		}
237
	}
238
239
	public ISelection getSelection() {
240
		Selection sel = new Selection();
241
		TRCThread thread = getSelectedThread();
242
		if (null != thread && null != _timeProvider) {
243
			double selectedTime = _timeProvider.getSelectedTime();
244
			TRCThreadEvent event = findEvent(thread, selectedTime, 0);
245
			if (null != event)
246
				sel.list.add(event);
247
		}
248
		return sel;
249
	}
250
251
	public void selectEvent(int n) {
252
		if (null == _timeProvider)
253
			return;
254
		TRCThread thread = getSelectedThread();
255
		if (thread == _timeProvider)
256
			return;
257
		double selectedTime = _timeProvider.getSelectedTime();
258
		double endTime = _timeProvider.getEndTime();
259
		TRCThreadEvent nextEvent;
260
		if (-1 == n && selectedTime >= endTime)
261
			nextEvent = findEvent(thread, selectedTime, 0);
262
		else
263
			nextEvent = findEvent(thread, selectedTime, n);
264
		if (null != nextEvent) {
265
			_timeProvider.setSelectedTime(nextEvent.getTime(), true);
266
			fireSelectionChanged();
267
		}
268
		else if (1 == n) {
269
			_timeProvider.setSelectedTime(endTime, true);
270
			fireSelectionChanged();
271
		}
272
	}
273
274
	public void selectNextEvent() {
275
		selectEvent(1);
276
	}
277
278
	public void selectPrevEvent() {
279
		selectEvent(-1);
280
	}
281
282
	public TRCThread getSelectedThread() {
283
		TRCThread thread = null;
284
		int idx = getSelectedIndex();
285
		if (idx >= 0 && _data._items[idx] instanceof ThreadItem)
286
			thread = ((ThreadItem) _data._items[idx])._thread;
287
		return thread;
288
	}
289
290
	public int getSelectedIndex() {
291
		int idx = -1;
292
		for (int i = 0; i < _data._items.length; i++) {
293
			Item item = (Item) _data._items[i];
294
			if (item._selected) {
295
				idx = i;
296
				break;
297
			}
298
		}
299
		return idx;
300
	}
301
302
	boolean toggle(int idx) {
303
		boolean toggled = false;
304
		if (idx >= 0 && idx < _data._items.length) {
305
			Item item = (Item) _data._items[idx];
306
			if (item._hasChildren) {
307
				item._expanded = !item._expanded;
308
				_data.updateItems();
309
				adjustScrolls();
310
				redraw();
311
				toggled = true;
312
			}
313
		}
314
		return toggled;
315
	}
316
317
	int hitTest(int x, int y) {
318
		if (x < 0)
319
			return -1;
320
		if (y < 0)
321
			return -1;
322
		int hit = -1;
323
		int idx = y / _itemHeight;
324
		idx += _topItem;
325
		if (idx < _data._items.length)
326
			hit = idx;
327
		return hit;
328
	}
329
330
	double hitTimeTest(int x, int y) {
331
		if (null == _timeProvider)
332
			return -1;
333
		double hitTime = -1;
334
		Point size = getCtrlSize();
335
		double time0 = _timeProvider.getTime0();
336
		double time1 = _timeProvider.getTime1();
337
		int left = _timeProvider.getNameSpace();
338
		x -= left;
339
		if (x >= 0 && size.x >= left) {
340
			hitTime = time0 + (time1 - time0) * x / (size.x - left);
341
		}
342
		return hitTime;
343
	}
344
345
	void selectItem(int idx, boolean addSelection) {
346
		if (addSelection) {
347
			if (idx >= 0 && idx < _data._items.length) {
348
				Item item = (Item) _data._items[idx];
349
				item._selected = true;
350
			}
351
		} else {
352
			for (int i = 0; i < _data._items.length; i++) {
353
				Item item = (Item) _data._items[i];
354
				item._selected = i == idx;
355
			}
356
		}
357
		boolean changed = ensureVisibleItem(idx, true);
358
		if (!changed)
359
			redraw();
360
	}
361
362
	public int countPerPage() {
363
		int height = getCtrlSize().y;
364
		int count = 0;
365
		if (height > 0)
366
			count = height / _itemHeight;
367
		return count;
368
	}
369
370
	public int getTopIndex() {
371
		int idx = -1;
372
		if (_data._items.length > 0)
373
			idx = 0;
374
		return idx;
375
	}
376
377
	public int getBottomIndex() {
378
		int idx = _data._items.length - 1;
379
		return idx;
380
	}
381
382
	Point getCtrlSize() {
383
		Point size = getSize();
384
		size.x -= getVerticalBar().getSize().x;
385
		size.y -= getHorizontalBar().getSize().y;
386
		return size;
387
	}
388
389
	void getNameRect(Rectangle rect, Point size, int idx, int nameWidth) {
390
		idx -= _topItem;
391
		rect.x = 0;
392
		rect.y = idx * _itemHeight;
393
		rect.width = nameWidth;
394
		rect.height = _itemHeight;
395
	}
396
397
	void getStatesRect(Rectangle rect, Point size, int idx, int nameWidth) {
398
		idx -= _topItem;
399
		rect.x = nameWidth;
400
		rect.y = idx * _itemHeight;
401
		rect.width = size.x - rect.x;
402
		rect.height = _itemHeight;
403
	}
404
405
	void paint(Rectangle rect, GC gc) {
406
		Point size = getCtrlSize();
407
		if (size.x < 2 || size.y < 2 || null == _timeProvider)
408
			return;
409
		double time0 = _timeProvider.getTime0();
410
		double time1 = _timeProvider.getTime1();
411
		double endTime = _timeProvider.getEndTime();
412
		double selectedTime = _timeProvider.getSelectedTime();
413
		int left = _timeProvider.getNameSpace();
414
		// draw thread states
415
		Object[] items = _data._items;
416
		for (int i = _topItem; i < items.length; i++) {
417
			Item item = (Item) items[i];
418
			getNameRect(_rect0, size, i, left);
419
			if (_rect0.y >= size.y)
420
				break;
421
			if (item instanceof GroupItem) {
422
				getStatesRect(_rect1, size, i, left);
423
				_rect0.width += _rect1.width;
424
				drawName(item, _rect0, gc);
425
			} else {
426
				drawName(item, _rect0, gc);
427
				getStatesRect(_rect0, size, i, left);
428
				drawItemData(item, _rect0, time0, time1, endTime, selectedTime,
429
						gc);
430
			}
431
		}
432
		// fill free canvas area
433
		_rect0.x = 0;
434
		_rect0.y += _rect0.height;
435
		_rect0.width = size.x;
436
		_rect0.height = size.y - _rect0.y;
437
		if (_rect0.y < size.y) {
438
			gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND));
439
			gc.fillRectangle(_rect0);
440
		}
441
	}
442
443
	void drawName(Item item, Rectangle rect, GC gc) {
444
		if (item instanceof GroupItem) {
445
			gc.setBackground(_colors
446
					.getBkColorGroup(item._selected, _isInFocus));
447
			gc.fillRectangle(rect);
448
			if (item._selected && _isInFocus) {
449
				gc.setForeground(_colors.getBkColor(item._selected, _isInFocus,
450
						false));
451
				gc.drawRectangle(rect.x, rect.y, rect.width - 2,
452
						rect.height - 2);
453
			}
454
			gc.setForeground(_colors.getBkColor(false, false, false));
455
			gc.drawLine(rect.x, rect.y + rect.height - 1, rect.width - 1,
456
					rect.y + rect.height - 1);
457
			gc.setForeground(_colors
458
					.getFgColorGroup(item._selected, _isInFocus));
459
		} else {
460
			gc.setBackground(_colors.getBkColor(item._selected, _isInFocus,
461
					true));
462
			gc.setForeground(_colors.getFgColor(item._selected, _isInFocus));
463
			gc.fillRectangle(rect);
464
		}
465
		Utils.init(_rect1, rect);
466
		_rect1.x += 4;
467
		_rect1.width -= 4;
468
		int textWidth = 0;
469
		// draw text
470
		if (_rect1.width > 0)
471
			textWidth = Utils.drawText(gc, item._name, _rect1, true) + 8;
472
		// draw middle line
473
		Utils.init(_rect1, rect);
474
		_rect1.x += textWidth;
475
		_rect1.width -= textWidth;
476
		gc.setForeground(_colors.getColor(TraceColorScheme.LIGHT_LINE));
477
		if (_rect1.width > 0 && item instanceof ThreadItem) {
478
			int midy = _rect1.y + _rect1.height / 2;
479
			gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);
480
		}
481
		// gc.drawLine(_rect1.x + _rect1.width - 1, _rect1.y, _rect1.x +
482
		// _rect1.width - 1, _rect1.y + _rect1.height);
483
	}
484
485
	void drawItemData(Item item, Rectangle rect, double time0, double time1,
486
			double endTime, double selectedTime, GC gc) {
487
		if (rect.isEmpty())
488
			return;
489
		if (time1 <= time0) {
490
			gc.setBackground(_colors.getBkColor(false, false, false));
491
			gc.fillRectangle(rect);
492
			return;
493
		}
494
495
		Utils.init(_rect1, rect);
496
		boolean selected = item._selected;
497
		double K = (double) rect.width / (time1 - time0);
498
499
		if (item instanceof GroupItem) {
500
			gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus));
501
			gc.fillRectangle(rect);
502
		} else if (item instanceof ThreadItem) {
503
			TRCThread thread = ((ThreadItem) item)._thread;
504
			int x0 = rect.x;
505
			EList list = thread.getThreadEvents();
506
			Iterator it = list.iterator();
507
			TRCThreadEvent lastEvent = null;
508
			if (it.hasNext()) {
509
				TRCThreadEvent currEvent = (TRCThreadEvent) it.next();
510
				TRCThreadEvent nextEvent = null;
511
				double currEventTime = currEvent.getTime();
512
				double nextEventTime = currEventTime;
513
				x0 = rect.x + (int) ((currEventTime - time0) * K);
514
				int xEnd = rect.x + (int) ((time1 - time0) * K);
515
				int x1 = -1;
516
517
				// reduce rect
518
				_rect1.y += 3;
519
				_rect1.height -= 6;
520
521
				// fill space before first event
522
				if (x0 > rect.x) {
523
					_rect1.width = (x0 <= xEnd ? x0 : xEnd) - _rect1.x;
524
					gc.setBackground(_colors.getBkColor(selected, _isInFocus,
525
							false));
526
					gc.fillRectangle(_rect1);
527
					// draw middle line
528
					gc.setForeground(_colors
529
							.getColor(TraceColorScheme.MID_LINE));
530
					int midy = _rect1.y + _rect1.height / 2;
531
					gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);
532
				}
533
534
				// draw event states
535
				while (x0 <= xEnd && null != currEvent) {
536
					boolean stopped = false;//currEvent instanceof TRCThreadDeadEvent;
537
					if (it.hasNext()) {
538
						nextEvent = (TRCThreadEvent) it.next();
539
						nextEventTime = nextEvent.getTime();
540
					} else if (stopped) {
541
						nextEvent = null;
542
						nextEventTime = time1;
543
					} else {
544
						nextEvent = null;
545
						nextEventTime = endTime;
546
					}
547
					x1 = rect.x + (int) ((nextEventTime - time0) * K);
548
					if (x1 >= rect.x) {
549
						_rect1.x = x0 >= rect.x ? x0 : rect.x;
550
						_rect1.width = (x1 <= xEnd ? x1 : xEnd) - _rect1.x;
551
						boolean timeSelected = currEventTime <= selectedTime && selectedTime < nextEventTime;
552
						Utils.drawState(_colors, currEvent, _rect1, gc, selected, false, timeSelected);
553
					}
554
					lastEvent = currEvent;
555
					currEvent = nextEvent;
556
					currEventTime = nextEventTime;
557
					x0 = x1;
558
				}
559
			}
560
561
			// fill space after last event
562
			int xEnd = rect.x + rect.width;
563
			if (x0 < xEnd) {
564
				_rect1.x = x0 >= rect.x ? x0 : rect.x;
565
				_rect1.width = xEnd - _rect1.x;
566
				gc.setBackground(_colors.getBkColor(selected, _isInFocus, false));
567
				gc.fillRectangle(_rect1);
568
				// draw middle line
569
				gc.setForeground(_colors.getColor(Utils.getEventColor(lastEvent)));
570
				int midy = _rect1.y + _rect1.height / 2;
571
				int lw = gc.getLineWidth();
572
				gc.setLineWidth(2);
573
				gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);
574
				gc.setLineWidth(lw);
575
			}
576
577
			// draw focus ares
578
			Utils.init(_rect1, rect);
579
			gc.setForeground(_colors.getBkColor(false, false, false));
580
			int y = _rect1.y;
581
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
582
			y++;
583
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
584
			y++;
585
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
586
			y = _rect1.y + _rect1.height - 1;
587
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
588
			y--;
589
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
590
			y--;
591
			gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);
592
			// gc.setForeground(_colors.getBkColor(selected, _isInFocus,
593
			// false));
594
		}
595
596
		// draw selected time
597
		int x = rect.x + (int) ((selectedTime - time0) * K);
598
		if (x >= rect.x && x < rect.x + rect.width) {
599
			gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));
600
			gc.drawLine(x, rect.y, x, rect.y + rect.height);
601
		}
602
	}
603
604
	public void keyPressed(KeyEvent e) {
605
		int idx = -1;
606
		if (SWT.HOME == e.keyCode) {
607
			idx = getTopIndex();
608
		} else if (SWT.END == e.keyCode) {
609
			idx = getBottomIndex();
610
		} else if (SWT.ARROW_DOWN == e.keyCode) {
611
			idx = getSelectedIndex();
612
			if (idx < 0)
613
				idx = 0;
614
			else if (idx < _data._items.length - 1)
615
				idx++;
616
		} else if (SWT.ARROW_UP == e.keyCode) {
617
			idx = getSelectedIndex();
618
			if (idx < 0)
619
				idx = 0;
620
			else if (idx > 0)
621
				idx--;
622
		} else if (SWT.ARROW_LEFT == e.keyCode) {
623
			selectPrevEvent();
624
		} else if (SWT.ARROW_RIGHT == e.keyCode) {
625
			selectNextEvent();
626
		} else if (SWT.PAGE_DOWN == e.keyCode) {
627
			int page = countPerPage();
628
			idx = getSelectedIndex();
629
			if (idx < 0)
630
				idx = 0;
631
			idx += page;
632
			if (idx >= _data._items.length)
633
				idx = _data._items.length - 1;
634
		} else if (SWT.PAGE_UP == e.keyCode) {
635
			int page = countPerPage();
636
			idx = getSelectedIndex();
637
			if (idx < 0)
638
				idx = 0;
639
			idx -= page;
640
			if (idx < 0)
641
				idx = 0;
642
		} else if (SWT.CR == e.keyCode) {
643
			idx = getSelectedIndex();
644
			if (idx >= 0) {
645
				if (_data._items[idx] instanceof ThreadItem)
646
					fireDefaultSelection();
647
				else if (_data._items[idx] instanceof GroupItem)
648
					toggle(idx);
649
			}
650
			idx = -1;
651
		}
652
		if (idx >= 0) {
653
			selectItem(idx, false);
654
			fireSelectionChanged();
655
		}
656
	}
657
658
	public void keyReleased(KeyEvent e) {
659
	}
660
661
	public void focusGained(FocusEvent e) {
662
		_isInFocus = true;
663
		redraw();
664
	}
665
666
	public void focusLost(FocusEvent e) {
667
		_isInFocus = false;
668
		if (1 == _dragState) {
669
			setCapture(false);
670
			_dragState = 0;
671
		}
672
		redraw();
673
	}
674
675
	public void mouseMove(MouseEvent e) {
676
		Point size = getCtrlSize();
677
		if (1 == _dragState && null != _timeProvider) {
678
			int leftSpace = _timeProvider.getNameSpace();
679
			int x = e.x - leftSpace;
680
			if (x > 0 && size.x > leftSpace && _dragX != x) {
681
				_dragX = x;
682
				double K = (double) (size.x - leftSpace)
683
						/ (_time1bak - _time0bak);
684
				double timeDelta = (_dragX - _dragX0) / K;
685
				double time1 = _time1bak - timeDelta;
686
				double maxTime = _timeProvider.getMaxTime();
687
				if (time1 > maxTime)
688
					time1 = maxTime;
689
				double time0 = time1 - (_time1bak - _time0bak);
690
				if (time0 < 0)
691
					time0 = 0;
692
				_timeProvider.setStartFinishTime(time0, time1);
693
			}
694
		}
695
	}
696
697
	public void mouseDoubleClick(MouseEvent e) {
698
		if (1 == e.button) {
699
			int idx = hitTest(e.x, e.y);
700
			if (idx >= 0) {
701
				selectItem(idx, false);
702
				if (_data._items[idx] instanceof ThreadItem) {
703
					fireDefaultSelection();
704
				}
705
			}
706
		}
707
	}
708
709
	public void mouseDown(MouseEvent e) {
710
		if (null == _timeProvider)
711
			return;
712
		if (1 == e.button) {
713
			int idx = hitTest(e.x, e.y);
714
			if (idx >= 0) {
715
				if (_data._items[idx] instanceof ThreadItem) {
716
					double hitTime = hitTimeTest(e.x, e.y);
717
					if (hitTime >= 0) {
718
						_timeProvider.setSelectedTime(hitTime, false);
719
						setCapture(true);
720
						_dragState = 1;
721
						_dragX = _dragX0 = e.x - _timeProvider.getNameSpace();
722
						_time0bak = _timeProvider.getTime0();
723
						_time1bak = _timeProvider.getTime1();
724
					}
725
				} else if (_data._items[idx] instanceof GroupItem) {
726
					_hitIdx = idx;
727
					_dragState = 2;
728
				}
729
				selectItem(idx, false);
730
				fireSelectionChanged();
731
			}
732
		}
733
	}
734
735
	public void mouseUp(MouseEvent e) {
736
		if (0 != _dragState) {
737
			setCapture(false);
738
			if (2 == _dragState) {
739
				if (hitTest(e.x, e.y) == _hitIdx)
740
					toggle(_hitIdx);
741
			}
742
			_dragState = 0;
743
		}
744
	}
745
746
	public void controlMoved(ControlEvent e) {
747
	}
748
749
	public void controlResized(ControlEvent e) {
750
		adjustScrolls();
751
	}
752
753
	public void widgetDefaultSelected(SelectionEvent e) {
754
	}
755
756
	public void widgetSelected(SelectionEvent e) {
757
		if (e.widget == getVerticalBar()) {
758
			_topItem = getVerticalBar().getSelection();
759
			if (_topItem < 0)
760
				_topItem = 0;
761
			redraw();
762
		} else if (e.widget == getHorizontalBar() && null != _timeProvider) {
763
			int startTime = getHorizontalBar().getSelection();
764
			double time0 = _timeProvider.getTime0();
765
			double time1 = _timeProvider.getTime1();
766
			double range = time1 - time0;
767
			// _timeRangeFixed = true;
768
			time0 = _timeStep * startTime;
769
			time1 = time0 + range;
770
			_timeProvider.setStartFinishTime(time0, time1);
771
		}
772
	}
773
}
774
775
class Item {
776
	public boolean _expanded;
777
	public boolean _selected;
778
	public boolean _hasChildren;
779
	public String _name;
780
781
	Item(String name) {
782
		_name = name;
783
	}
784
785
	public String toString() {
786
		return _name;
787
	}
788
}
789
790
class ThreadItem extends Item {
791
	public TRCThread _thread;
792
793
	ThreadItem(TRCThread thread) {
794
		super(thread.getName());
795
		_thread = thread;
796
	}
797
}
798
799
class GroupItem extends Item {
800
	public ArrayList _threads;
801
802
	GroupItem(String name) {
803
		super(name);
804
		_threads = new ArrayList();
805
		_hasChildren = true;
806
	}
807
808
	void add(Object thread) {
809
		_threads.add(thread);
810
	}
811
}
812
813
class ItemData {
814
	public Object[] _items = new Object[0];
815
	private Object _threads[] = new Object[0];
816
	private Hashtable _groupTable = new Hashtable();
817
	private boolean _flatList;
818
819
	void clearGroups() {
820
		Set keys = _groupTable.keySet();
821
		Iterator it = keys.iterator();
822
		while (it.hasNext()) {
823
			String key = (String) it.next();
824
			GroupItem group = (GroupItem) _groupTable.get(key);
825
			group._threads.clear();
826
		}
827
	}
828
829
	void deleteEmptyGroups() {
830
		Set keys = _groupTable.keySet();
831
		Iterator it = keys.iterator();
832
		while (it.hasNext()) {
833
			String key = (String) it.next();
834
			GroupItem group = (GroupItem) _groupTable.get(key);
835
			if (group._threads.size() == 0)
836
				_groupTable.remove(key);
837
		}
838
	}
839
840
	public void updateItems() {
841
		ArrayList itemList = new ArrayList();
842
		Set keys = _groupTable.keySet();
843
		Iterator it = keys.iterator();
844
		while (it.hasNext()) {
845
			String key = (String) it.next();
846
			GroupItem group = (GroupItem) _groupTable.get(key);
847
			if (!_flatList)
848
				itemList.add(group);
849
			if (_flatList || group._expanded) {
850
				Iterator it2 = group._threads.iterator();
851
				while (it2.hasNext())
852
					itemList.add(new ThreadItem((TRCThread) it2.next()));
853
			}
854
		}
855
		_items = itemList.toArray();
856
	}
857
858
	public void refreshData(Object threads[]) {
859
		clearGroups();
860
		_threads = threads;
861
		String undef = "<undefined>";
862
		ArrayList groupList = new ArrayList();
863
		for (int i = 0; i < _threads.length; i++) {
864
			TRCThread thread = (TRCThread) _threads[i];
865
			String groupName = thread.getGroupName();
866
			if (null == groupName)
867
				groupName = undef;
868
			GroupItem group = (GroupItem) _groupTable.get(groupName);
869
			if (null == group) {
870
				group = new GroupItem(groupName);
871
				group._expanded = !groupName.equalsIgnoreCase("system")
872
						&& !groupName.equalsIgnoreCase(undef);
873
				_groupTable.put(groupName, group);
874
				groupList.add(group);
875
			}
876
			group.add(thread);
877
		}
878
		deleteEmptyGroups();
879
		updateItems();
880
	}
881
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/OpenCallStackViewAction.java (+76 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.views;
16
17
import org.eclipse.core.resources.IResourceStatus;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.hyades.trace.ui.UIPlugin;
21
import org.eclipse.hyades.trace.views.actions.internal.OpenTraceViewAction;
22
import org.eclipse.hyades.trace.views.internal.TraceUIMessages;
23
import org.eclipse.jface.action.IAction;
24
import org.eclipse.jface.dialogs.ErrorDialog;
25
import org.eclipse.jface.resource.ImageDescriptor;
26
import org.eclipse.ui.IWorkbenchWindow;
27
28
public class OpenCallStackViewAction extends OpenTraceViewAction {
29
30
	static final String VIEW_ID = "org.eclipse.tptp.trace.jvmti.internal.client.views.CallStackView";
31
32
	public OpenCallStackViewAction() {
33
		super("");
34
	}
35
36
	public OpenCallStackViewAction(String label) {
37
		super(label);
38
	}
39
40
	public OpenCallStackViewAction(String label, ImageDescriptor image) {
41
		super(label, image);
42
	}
43
44
	public boolean isVisibleForType(Object mofObject) {
45
		return true;
46
	}
47
48
	static public void openCallStackView(boolean showError) {
49
		IWorkbenchWindow window = UIPlugin.getDefault().getWorkbench()
50
				.getActiveWorkbenchWindow();
51
		try {
52
			UIPlugin.getActivePage().showView(VIEW_ID);
53
		} catch (Exception e) {
54
			if (showError) {
55
				String msg = TraceUIMessages._3;
56
				Status err = new Status(Status.WARNING,
57
						ResourcesPlugin.PI_RESOURCES,
58
						IResourceStatus.INTERNAL_ERROR, e.toString(), null);
59
				ErrorDialog.openError(window.getShell(), msg, "", err);
60
			}
61
			e.printStackTrace();
62
		}
63
	}
64
65
	public void run() {
66
		openCallStackView(true);
67
	}
68
69
	public void run(IAction action) {
70
		run();
71
	}
72
73
	public String getViewID() {
74
		return VIEW_ID;
75
	}
76
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/TraceCtrl.java (+63 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.PaintEvent;
19
import org.eclipse.swt.events.PaintListener;
20
import org.eclipse.swt.graphics.Color;
21
import org.eclipse.swt.graphics.GC;
22
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.graphics.Rectangle;
24
import org.eclipse.swt.widgets.Canvas;
25
import org.eclipse.swt.widgets.Composite;
26
27
public abstract class TraceCtrl extends Canvas implements PaintListener {
28
29
	protected TraceColorScheme _colors;
30
	protected Rectangle _rect0 = new Rectangle(0, 0, 0, 0);
31
	protected Rectangle _rect1 = new Rectangle(0, 0, 0, 0);
32
33
	public TraceCtrl(Composite parent, TraceColorScheme colors) {
34
		this(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS);
35
	}
36
37
	public TraceCtrl(Composite parent, TraceColorScheme colors, int style) {
38
		super(parent, style);
39
		_colors = colors;
40
		addPaintListener(this);
41
	}
42
43
	public void dispose() {
44
		super.dispose();
45
	}
46
47
	public void paintControl(PaintEvent e) {
48
		if (e.widget != this)
49
			return;
50
		Point size = getSize();
51
		if (size.x > 0 && size.y > 0) {
52
			Color colBackup = e.gc.getBackground();
53
			Utils.init(_rect0, 0, 0, size.x, size.y);
54
			paint(_rect0, e.gc);
55
			e.gc.setBackground(colBackup);
56
		}
57
	}
58
59
	void paint(Rectangle rect, GC gc) {
60
		gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND));
61
		gc.fillRectangle(rect);
62
	}
63
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/Utils.java (+168 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import org.eclipse.hyades.models.trace.TRCThreadDeadEvent;
18
import org.eclipse.hyades.models.trace.TRCThreadDeadLockEvent;
19
import org.eclipse.hyades.models.trace.TRCThreadEvent;
20
import org.eclipse.hyades.models.trace.TRCThreadRunningEvent;
21
import org.eclipse.hyades.models.trace.TRCThreadSleepingEvent;
22
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
23
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.graphics.Color;
26
import org.eclipse.swt.graphics.Device;
27
import org.eclipse.swt.graphics.GC;
28
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.graphics.Rectangle;
30
import org.eclipse.swt.widgets.Display;
31
32
public class Utils {
33
34
	static public void init(Rectangle rect) {
35
		rect.x = 0;
36
		rect.y = 0;
37
		rect.width = 0;
38
		rect.height = 0;
39
	}
40
41
	static public void init(Rectangle rect, int x, int y, int width, int height) {
42
		rect.x = x;
43
		rect.y = y;
44
		rect.width = width;
45
		rect.height = height;
46
	}
47
48
	static public void init(Rectangle rect, Rectangle source) {
49
		rect.x = source.x;
50
		rect.y = source.y;
51
		rect.width = source.width;
52
		rect.height = source.height;
53
	}
54
55
	static public void deflate(Rectangle rect, int x, int y) {
56
		rect.x += x;
57
		rect.y += y;
58
		rect.width -= x + x;
59
		rect.height -= y + y;
60
	}
61
62
	static public void inflate(Rectangle rect, int x, int y) {
63
		rect.x -= x;
64
		rect.y -= y;
65
		rect.width += x + x;
66
		rect.height += y + y;
67
	}
68
69
	static void dispose(Color col) {
70
		if (null != col)
71
			col.dispose();
72
	}
73
74
	static public Color mixColors(Device display, Color c1, Color c2, int w1,
75
			int w2) {
76
		return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())
77
				/ (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())
78
				/ (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())
79
				/ (w1 + w2));
80
	}
81
82
	static public Color getSysColor(int id) {
83
		return Display.getCurrent().getSystemColor(id);
84
	}
85
86
	static public Color mixColors(Color col1, Color col2, int w1, int w2) {
87
		return mixColors(Display.getCurrent(), col1, col2, w1, w2);
88
	}
89
90
	static public void drawState(TraceColorScheme colors, TRCThreadEvent event,
91
			Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected) {
92
		int colorIdx = getEventColor(event);
93
		drawState(colors, colorIdx, rect, gc, selected, rectBound, timeSelected);
94
	}
95
96
	static public void drawState(TraceColorScheme colors, int colorIdx,
97
			Rectangle rect, GC gc, boolean selected, boolean rectBound, boolean timeSelected) {
98
		if (rect.isEmpty())
99
			return;
100
		// FILL RECT
101
		int colorIdx1 = colorIdx;
102
		timeSelected = timeSelected && selected;
103
		if (selected)
104
			colorIdx1 = colorIdx + TraceColorScheme.STATES_SEL0 - TraceColorScheme.STATES0;
105
		gc.setBackground(colors.getColor(colorIdx1));
106
		gc.fillRectangle(rect);
107
		colorIdx1 = colorIdx + TraceColorScheme.STATES_BORDER0 - TraceColorScheme.STATES0;
108
		gc.setForeground(colors.getColor(colorIdx1));
109
		// DRAW BOUNDS
110
		if (!timeSelected) {
111
			if (rectBound && rect.width >= 3) {
112
				gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
113
			} else {
114
				gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
115
				gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
116
			}
117
		}
118
		// DRAW MID LINE
119
		int mindy = rect.y + rect.height / 2;
120
		if (TraceColorScheme.BLOCKED == colorIdx || TraceColorScheme.WAITING == colorIdx) {
121
			int s = gc.getLineStyle();
122
			int w = gc.getLineWidth();
123
			gc.setLineStyle(SWT.LINE_DOT);
124
			gc.setLineWidth(2);
125
			gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);
126
			gc.setLineStyle(s);
127
			gc.setLineWidth(w);
128
		} else if (TraceColorScheme.DEADLOCK == colorIdx || TraceColorScheme.STOPPED == colorIdx) {
129
			int w = gc.getLineWidth();
130
			gc.setLineWidth(2);
131
			gc.drawLine(rect.x, mindy, rect.x + rect.width, mindy);
132
			gc.setLineWidth(w);
133
		}
134
		// DRAW SELECTED BOUNDS
135
		if (timeSelected) {
136
			if (rect.width >= 3) {
137
				gc.setForeground(colors.getColor(TraceColorScheme.SELECTED_TIME));
138
				gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
139
				//gc.drawRectangle(rect.x + 1, rect.y + 1, rect.width - 3, rect.height - 3);
140
			} else {
141
				gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
142
				gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);				
143
			}
144
		}
145
	}
146
147
	static public int getEventColor(TRCThreadEvent event) {
148
		if (event instanceof TRCThreadRunningEvent)
149
			return TraceColorScheme.RUNNING;
150
		else if (event instanceof TRCThreadSleepingEvent)
151
			return TraceColorScheme.SLEEPING;
152
		else if (event instanceof TRCThreadDeadLockEvent)
153
			return TraceColorScheme.DEADLOCK;
154
		else if (event instanceof TRCThreadWaitingForLockEvent)
155
			return TraceColorScheme.BLOCKED;
156
		else if (event instanceof TRCThreadWaitingForObjectEvent)
157
			return TraceColorScheme.WAITING;
158
		else if (event instanceof TRCThreadDeadEvent)
159
			return TraceColorScheme.STOPPED;
160
		return TraceColorScheme.UNKNOWN;
161
	}
162
163
	static public int drawText(GC gc, String text, Rectangle rect, boolean transp) {
164
		Point size = gc.stringExtent(text);
165
		gc.drawText(text, rect.x, rect.y, transp);
166
		return size.x;
167
	}
168
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/OpenThreadStatesViewAction.java (+78 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.views;
16
17
import org.eclipse.core.resources.IResourceStatus;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.hyades.trace.ui.TraceViewer;
21
import org.eclipse.hyades.trace.ui.UIPlugin;
22
import org.eclipse.hyades.trace.views.actions.internal.OpenTraceViewAction;
23
import org.eclipse.hyades.trace.views.internal.TraceUIMessages;
24
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.ui.IViewPart;
28
import org.eclipse.ui.IWorkbenchPage;
29
import org.eclipse.ui.IWorkbenchWindow;
30
31
public class OpenThreadStatesViewAction extends OpenTraceViewAction {
32
33
	private final String VIEW_ID = "org.eclipse.tptp.trace.jvmti.internal.client.views.ThreadStatesViewer";
34
35
	public OpenThreadStatesViewAction() {
36
		super("");
37
	}
38
39
	public OpenThreadStatesViewAction(String label) {
40
		super(label);
41
	}
42
43
	public OpenThreadStatesViewAction(String label, ImageDescriptor image) {
44
		super(label, image);
45
	}
46
47
	public boolean isVisibleForType(Object mofObject) {
48
		return true;
49
	}
50
	
51
	public void run() {
52
		IWorkbenchWindow window = UIPlugin.getDefault().getWorkbench()
53
				.getActiveWorkbenchWindow();
54
		try {
55
			IWorkbenchPage persp = UIPlugin.getActivePage();
56
			IViewPart view = persp.showView(VIEW_ID);
57
			if (view != null && view instanceof TraceViewer) {
58
				((TraceViewer) view).addViewPage(getMofObject(), true);
59
			}
60
		} catch (Exception e) {
61
			String msg = TraceUIMessages._3;
62
			Status err = new Status(Status.WARNING,
63
					ResourcesPlugin.PI_RESOURCES,
64
					IResourceStatus.INTERNAL_ERROR, e.toString(), null);
65
			ErrorDialog.openError(window.getShell(), msg, "", err);
66
			e.printStackTrace();
67
		}
68
69
	}
70
71
	public void run(IAction action) {
72
		run();
73
	}
74
75
	public String getViewID() {
76
		return VIEW_ID;
77
	}
78
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadStatesViewer.java (+91 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.views;
16
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.hyades.trace.ui.TraceViewer;
19
import org.eclipse.hyades.trace.ui.TraceViewerPage;
20
import org.eclipse.jface.action.Action;
21
import org.eclipse.jface.action.IMenuManager;
22
import org.eclipse.jface.action.IToolBarManager;
23
import org.eclipse.ui.IActionBars;
24
import org.eclipse.ui.ISharedImages;
25
import org.eclipse.ui.PlatformUI;
26
27
public class ThreadStatesViewer extends TraceViewer {
28
29
	public ThreadStatesViewer() {
30
	}
31
32
	public TraceViewerPage createPage(EObject mofObject) {
33
		return new ThreadStatesPage(mofObject, this);
34
	}
35
36
	public String getViewTitle() {
37
		return UIMessages.THREAD_STATES_TITLE;
38
	}
39
40
	public void setFocus() {
41
		if (getCurrentPage() != null)
42
			getCurrentPage().setFocus();
43
	}
44
45
	public void makeActions() {
46
		super.makeActions();
47
		createActions();
48
		IActionBars bars = getViewSite().getActionBars();
49
		fillLocalPullDown(bars.getMenuManager());
50
		fillLocalToolBar(bars.getToolBarManager());
51
		bars.updateActionBars();
52
	}
53
54
	Action _selectNextEvent;
55
	Action _selectPrevEvent;
56
57
	private void createActions() {
58
		_selectNextEvent = new Action() {
59
			public void run() {
60
				if (getCurrentPage() instanceof ThreadStatesPage)
61
					((ThreadStatesPage) getCurrentPage()).selectNextEvent();
62
			}
63
		};
64
		_selectNextEvent.setText("Next");
65
		_selectNextEvent.setToolTipText("Select Next Event");
66
		_selectNextEvent.setImageDescriptor(PlatformUI.getWorkbench()
67
				.getSharedImages().getImageDescriptor(
68
						ISharedImages.IMG_TOOL_FORWARD));
69
		_selectPrevEvent = new Action() {
70
			public void run() {
71
				if (getCurrentPage() instanceof ThreadStatesPage)
72
					((ThreadStatesPage) getCurrentPage()).selectPrevEvent();
73
			}
74
		};
75
		_selectPrevEvent.setText("Prev");
76
		_selectPrevEvent.setToolTipText("Select Previous Event");
77
		_selectPrevEvent.setImageDescriptor(PlatformUI.getWorkbench()
78
				.getSharedImages().getImageDescriptor(
79
						ISharedImages.IMG_TOOL_BACK));
80
	}
81
82
	private void fillLocalPullDown(IMenuManager manager) {
83
		manager.add(_selectPrevEvent);
84
		manager.add(_selectNextEvent);
85
	}
86
87
	private void fillLocalToolBar(IToolBarManager manager) {
88
		manager.add(_selectPrevEvent);
89
		manager.add(_selectNextEvent);
90
	}
91
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/ThreadStatesPage.java (+319 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.views;
16
17
import org.eclipse.emf.common.util.EList;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.hyades.models.trace.TRCThread;
20
import org.eclipse.hyades.models.trace.TRCThreadEvent;
21
import org.eclipse.hyades.trace.ui.TraceViewer;
22
import org.eclipse.hyades.trace.ui.TraceViewerPage;
23
import org.eclipse.hyades.trace.ui.UIPlugin;
24
import org.eclipse.hyades.trace.ui.ViewSelectionChangedEvent;
25
import org.eclipse.hyades.trace.ui.internal.util.PerftraceUtil;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.ControlAdapter;
30
import org.eclipse.swt.events.ControlEvent;
31
import org.eclipse.swt.events.PaintEvent;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionListener;
34
import org.eclipse.swt.graphics.Rectangle;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.ITimeDataProvider;
38
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.LegendCtrl;
39
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.ThreadStatesCtrl;
40
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.TimeScaleCtrl;
41
import org.eclipse.tptp.trace.jvmti.internal.client.widgets.TraceColorScheme;
42
43
public class ThreadStatesPage extends TraceViewerPage implements
44
		ITimeDataProvider, SelectionListener {
45
46
	/* vars */
47
	double _minTimeInterval = .000001;
48
	double _selectedTime = -1;
49
	double _beginTime = 0;
50
	double _endTime = 0;
51
	double _time0 = 0;
52
	double _time1 = 0;
53
	double _time0_ = 0;
54
	double _time1_ = 0;
55
	double _time1bak = 0;
56
	double _timeStep = 0.01;
57
	boolean _timeRangeFixed = false;
58
	private int _nameWidth = 96;
59
	private int _legendHeight = 22;
60
	private int _timeScaleHeight = 22;
61
	private Composite _viewContainer;
62
	private ThreadStatesCtrl _stateCtrl;
63
	private LegendCtrl _legendCtrl;
64
	private TimeScaleCtrl _timeScaleCtrl;
65
	static TraceColorScheme _colors = new TraceColorScheme();
66
67
	/** ctor */
68
	public ThreadStatesPage(EObject mofObject, TraceViewer viewer) {
69
		super(mofObject, viewer);
70
	}
71
72
	/** Refresher */
73
	public void refreshPage() {
74
		if (null != _stateCtrl) {
75
			refreshData();
76
			_stateCtrl.redraw();
77
			_timeScaleCtrl.redraw();
78
		}
79
	}
80
81
	public void selectionChanged() {
82
	}
83
84
	public void update(boolean newPage) {
85
		refreshPage();
86
	}
87
88
	public void createControl(Composite parent) {
89
		_viewContainer = new Composite(parent, SWT.NULL);
90
		_legendCtrl = new LegendCtrl(_viewContainer, _colors);
91
		_timeScaleCtrl = new TimeScaleCtrl(_viewContainer, _colors);
92
		_timeScaleCtrl.setTimeProvider(this);
93
		_stateCtrl = new ThreadStatesCtrl(_viewContainer, _colors);
94
		_stateCtrl.setTimeProvider(this);
95
		_stateCtrl.addSelectionListener(this);
96
		_viewContainer.addControlListener(new ControlAdapter() {
97
			public void controlResized(ControlEvent event) {
98
				Rectangle r = _viewContainer.getClientArea();
99
				_legendCtrl.setBounds(r.x, r.y, r.width, _legendHeight);
100
				_timeScaleCtrl.setBounds(r.x, r.y + _legendHeight, r.width,
101
						_timeScaleHeight);
102
				_stateCtrl.setBounds(r.x, r.y + _legendHeight
103
						+ _timeScaleHeight, r.width, r.height - _legendHeight
104
						- _timeScaleHeight);
105
			}
106
		});
107
	}
108
109
	public void dispose() {
110
		_stateCtrl.dispose();
111
		_legendCtrl.dispose();
112
		_viewContainer.dispose();
113
		_colors.dispose();
114
		super.dispose();
115
	}
116
117
	/** Tries to set most convinient time range for display. */
118
	void setTimeRange(Object threads[]) {
119
		_endTime = 0;
120
		_beginTime = -1;
121
		TRCThreadEvent event;
122
		for (int i = 0; i < threads.length; i++) {
123
			TRCThread thread = (TRCThread) threads[i];
124
			double lastEventTime = thread.getStopTime();
125
			if (lastEventTime > thread.getStartTime()) {
126
				if (lastEventTime > _endTime)
127
					_endTime = lastEventTime;
128
			}
129
			EList list = thread.getThreadEvents();
130
			int len = list.size();
131
			if (len > 0) {
132
				event = (TRCThreadEvent) list.get(list.size() - 1);
133
				lastEventTime = event.getTime();
134
				if (lastEventTime > _endTime)
135
					_endTime = lastEventTime;
136
				event = (TRCThreadEvent) list.get(0);
137
				if (_beginTime < 0 || _beginTime > event.getTime())
138
					_beginTime = event.getTime();
139
			}
140
		}
141
		_endTime += 0.1;
142
		if (_beginTime < 0)
143
			_beginTime = 0;
144
	}
145
146
	void setTimeBounds() {
147
		_time0_ = _beginTime - (_endTime - _beginTime) * 0.05;
148
		if (_time0_ < 0)
149
			_time0_ = 0;
150
		_time1_ = _time0_ + (_endTime - _time0_) * 1.05;
151
		_time0_ = Math.floor(_time0_);
152
		_time1_ = Math.ceil(_time1_);
153
		if (!_timeRangeFixed) {
154
			_time0 = _time0_;
155
			_time1 = _time1_;
156
		}
157
	}
158
159
	void refreshData() {
160
		Object threads[] = PerftraceUtil.getAllThreads(getMOFObject(), false);
161
		if (null == threads)
162
			threads = new TRCThread[0];
163
		setTimeRange(threads);
164
		setTimeBounds();
165
		if (_selectedTime < 0 || _selectedTime > _endTime)
166
			_selectedTime = _endTime;
167
		_stateCtrl.refreshData(threads);
168
	}
169
170
	public Control getControl() {
171
		return _viewContainer;
172
	}
173
174
	public void setFocus() {
175
		if (null != _stateCtrl)
176
			_stateCtrl.setFocus();
177
	}
178
179
	public TRCThread getSelectedThread() {
180
		return _stateCtrl.getSelectedThread();
181
	}
182
183
	public ISelection getSelection() {
184
		return _stateCtrl.getSelection();
185
	}
186
187
	public double getTime0() {
188
		return _time0;
189
	}
190
191
	public double getTime1() {
192
		return _time1;
193
	}
194
195
	public double getMinTimeInterval() {
196
		return _minTimeInterval;
197
	}
198
199
	public int getNameSpace() {
200
		return _nameWidth;
201
	}
202
203
	public int getTimeSpace() {
204
		int w = _stateCtrl.getClientArea().width;
205
		return w - _nameWidth;
206
	}
207
208
	public double getSelectedTime() {
209
		return _selectedTime;
210
	}
211
212
	public double getBeginTime() {
213
		return _beginTime;
214
	}
215
216
	public double getEndTime() {
217
		return _endTime;
218
	}
219
220
	public double getMaxTime() {
221
		return _time1_;
222
	}
223
224
	public double getMinTime() {
225
		return _time0_;
226
	}
227
228
	public void setStartFinishTime(double time0, double time1) {
229
		_time0 = time0;
230
		if (_time0 < 0)
231
			_time0 = 0;
232
		_time1 = time1;
233
		if (_time1 - _time0 < _minTimeInterval)
234
			_time1 = _time0 + _minTimeInterval;
235
		if (_time1 > _time1_)
236
			_time1 = _time1_;
237
		_timeRangeFixed = true;
238
		_stateCtrl.adjustScrolls();
239
		_stateCtrl.redraw();
240
		_timeScaleCtrl.redraw();
241
	}
242
243
	public void resetStartFinishTime() {
244
		_timeRangeFixed = false;
245
		_time0 = _time0_;
246
		_time1 = _time1_;
247
		_stateCtrl.adjustScrolls();
248
		_stateCtrl.redraw();
249
		_timeScaleCtrl.redraw();
250
	}
251
252
	public void paintControl(PaintEvent e) {
253
	}
254
255
	public void setSelectedTime(double time, boolean ensureVisible) {
256
		_selectedTime = time;
257
		if (_selectedTime > _endTime)
258
			_selectedTime = _endTime;
259
		if (_selectedTime < _beginTime)
260
			_selectedTime = _beginTime;
261
		if (ensureVisible) {
262
			double timeSpace = (_time1 - _time0) * .1;
263
			double timeMid = (_time1 - _time0) * .5;
264
			if (_selectedTime < _time0 + timeSpace) {
265
				double dt = _time0 - _selectedTime + timeMid;
266
				_time0 -= dt;
267
				_time1 -= dt;
268
			} else if (_selectedTime > _time1 - timeSpace) {
269
				double dt = _selectedTime - _time1 + timeMid;
270
				_time0 += dt;
271
				_time1 += dt;
272
			}
273
			if (_time0 < 0) {
274
				_time1 -= _time0;
275
				_time0 = 0;
276
			} else if (_time1 > _time1_) {
277
				_time0 += _time1 - _time1_;
278
				_time1 = _time1_;
279
			}
280
		}
281
		_stateCtrl.adjustScrolls();
282
		_stateCtrl.redraw();
283
		_timeScaleCtrl.redraw();
284
	}
285
286
	public void updateModelSelection() {
287
		ISelection selection = getSelection();
288
		Object sel = null;
289
		if (selection != null && !selection.isEmpty()) {
290
			sel = ((IStructuredSelection) selection).getFirstElement();
291
			notifyViewSelectionChanged(this, sel);
292
		}
293
	}
294
295
	public void notifyViewSelectionChanged(Object source, Object selection) {
296
		UIPlugin.getDefault().getSelectionModel(getMOFObject()).add(selection);
297
		ViewSelectionChangedEvent event = UIPlugin.getDefault()
298
				.getViewSelectionChangedEvent();
299
		event.setSource(source);
300
		UIPlugin.getDefault().notifyViewSelectionChangedListener(event);
301
	}
302
303
	public void widgetDefaultSelected(SelectionEvent e) {
304
		OpenCallStackViewAction.openCallStackView(false);
305
		updateModelSelection();
306
	}
307
308
	public void widgetSelected(SelectionEvent e) {
309
		updateModelSelection();
310
	}
311
312
	public void selectNextEvent() {
313
		_stateCtrl.selectNextEvent();
314
	}
315
316
	public void selectPrevEvent() {
317
		_stateCtrl.selectPrevEvent();
318
	}
319
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/ITimeDataProvider.java (+44 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
public interface ITimeDataProvider {
18
19
	double getSelectedTime();
20
21
	double getBeginTime();
22
23
	double getEndTime();
24
25
	double getMinTime();
26
27
	double getMaxTime();
28
29
	double getTime0();
30
31
	double getTime1();
32
33
	double getMinTimeInterval();
34
35
	void setStartFinishTime(double time0, double time1);
36
37
	void setSelectedTime(double time, boolean ensureVisible);
38
39
	void resetStartFinishTime();
40
41
	int getNameSpace();
42
43
	int getTimeSpace();
44
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/views/CallStackViewer.java (+280 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.views;
16
17
import java.util.ArrayList;
18
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.hyades.models.trace.TRCMethod;
21
import org.eclipse.hyades.models.trace.TRCMethodInvocation;
22
import org.eclipse.hyades.models.trace.TRCThread;
23
import org.eclipse.hyades.models.trace.TRCThreadDeadEvent;
24
import org.eclipse.hyades.models.trace.TRCThreadDeadLockEvent;
25
import org.eclipse.hyades.models.trace.TRCThreadEvent;
26
import org.eclipse.hyades.models.trace.TRCThreadRunningEvent;
27
import org.eclipse.hyades.models.trace.TRCThreadSleepingEvent;
28
import org.eclipse.hyades.models.trace.TRCThreadWaitingForLockEvent;
29
import org.eclipse.hyades.models.trace.TRCThreadWaitingForObjectEvent;
30
import org.eclipse.hyades.trace.ui.IViewSelectionChangedListener;
31
import org.eclipse.hyades.trace.ui.UIPlugin;
32
import org.eclipse.hyades.trace.ui.ViewSelectionChangedEvent;
33
import org.eclipse.hyades.trace.views.util.internal.OpenSource;
34
import org.eclipse.jface.viewers.DoubleClickEvent;
35
import org.eclipse.jface.viewers.IDoubleClickListener;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.viewers.ITreeContentProvider;
38
import org.eclipse.jface.viewers.LabelProvider;
39
import org.eclipse.jface.viewers.TreeSelection;
40
import org.eclipse.jface.viewers.TreeViewer;
41
import org.eclipse.jface.viewers.Viewer;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.graphics.Image;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.ui.ISharedImages;
46
import org.eclipse.ui.PlatformUI;
47
import org.eclipse.ui.part.ViewPart;
48
49
public class CallStackViewer extends ViewPart implements
50
		IViewSelectionChangedListener {
51
52
	private TreeViewer _calStackCtrl;
53
	private Object _selection;
54
55
	public CallStackViewer() {
56
	}
57
58
	public void createPartControl(Composite parent) {
59
		_calStackCtrl = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL
60
				| SWT.FULL_SELECTION | SWT.SINGLE);
61
		_calStackCtrl.setContentProvider(new CallStackContentProvider());
62
		_calStackCtrl.setLabelProvider(new CallStackLabelProvider());
63
		_calStackCtrl.setInput(this);
64
		_calStackCtrl.addDoubleClickListener(new IDoubleClickListener() {
65
			public void doubleClick(DoubleClickEvent event) {
66
				OpenSource.openSource(getFirstSelectedElement());
67
			}
68
		});
69
		UIPlugin.getDefault().addViewSelectionChangedListener(this);
70
		UIPlugin.getDefault().getViewSelectionChangedEvent();
71
	}
72
73
	public void setFocus() {
74
		if (null != _calStackCtrl)
75
			_calStackCtrl.getControl().setFocus();
76
	}
77
78
	public void dispose() {
79
		UIPlugin.getDefault().removeViewSelectionChangedListener(this);
80
		super.dispose();
81
	}
82
83
	public Object getFirstSelectedElement() {
84
		Object obj = null;
85
		if (null != _calStackCtrl)
86
			obj = ((TreeSelection) _calStackCtrl.getSelection())
87
					.getFirstElement();
88
		return obj;
89
	}
90
91
	/** update view content */
92
	void update(Object selection) {
93
		if (null == _calStackCtrl)
94
			return;
95
		_selection = selection;
96
		_calStackCtrl.refresh();
97
	}
98
99
	public void handleObjectChanged(Object sel) {
100
		update(sel);
101
	}
102
103
	/**
104
	 * Compose String name for TRCMethodInvocation
105
	 * 
106
	 * @param method
107
	 * @return
108
	 */
109
	static String methodName(TRCMethodInvocation method) {
110
		TRCMethod m = method.getMethod();
111
		String name = "";
112
		name += m.getDefiningClass().getName();
113
		name += ".";
114
		name += m.getName();
115
		name += m.getSignature();
116
		name += " [" + m.getCalls() + "]";
117
		return name;
118
	}
119
120
	/**
121
	 * Compose String name for TRCThread
122
	 * 
123
	 * @param thread
124
	 * @return
125
	 */
126
	static String threadName(TRCThread thread) {
127
		String name = thread.getName();
128
		name += " [" + thread.getGroupName() + "]";
129
		return name;
130
	}
131
132
	static String getEventName(TRCThreadEvent event) {
133
		if (event instanceof TRCThreadRunningEvent) {
134
			return "RUNNING";
135
		} else if (event instanceof TRCThreadSleepingEvent) {
136
			return "SLEEPING";
137
		} else if (event instanceof TRCThreadDeadLockEvent) {
138
			return "DEADLOCK";
139
		} else if (event instanceof TRCThreadWaitingForLockEvent) {
140
			return "BLOCKED";
141
		} else if (event instanceof TRCThreadWaitingForObjectEvent) {
142
			return "WAITING";
143
		} else if (event instanceof TRCThreadDeadEvent) {
144
			return "STOPPED";
145
		}
146
		return "UNKNOWN";
147
	}
148
149
	/**
150
	 * Compose String name for TRCThreadEvent
151
	 * 
152
	 * @param event
153
	 * @return
154
	 */
155
	static String eventName(TRCThreadEvent event) {
156
		String name = event.getThread().getName();
157
		name += " [" + event.getThread().getGroupName() + "] State: " + getEventName(event);
158
		if (event instanceof TRCThreadWaitingForObjectEvent) {
159
			name += " Timeout=" + ((TRCThreadWaitingForObjectEvent)event).getTimeout();
160
		} else if (event instanceof TRCThreadWaitingForLockEvent) {
161
			TRCThread thread = ((TRCThreadWaitingForLockEvent)event).getLockingThread();
162
			if (null != thread)
163
				name += " by Thread=" + thread.getName();
164
		}
165
		return name;
166
	}
167
168
	/**
169
	 * Compose String name from object
170
	 * 
171
	 * @param obj
172
	 * @return
173
	 */
174
	public String getItemText(Object obj) {
175
		if (obj instanceof TRCMethodInvocation) {
176
			return methodName((TRCMethodInvocation) obj);
177
		}
178
		if (obj instanceof TRCThread) {
179
			return threadName((TRCThread) obj);
180
		}
181
		if (obj instanceof TRCThreadEvent) {
182
			return eventName((TRCThreadEvent) obj);
183
		}
184
		return obj.toString();
185
	}
186
187
	/**
188
	 * Icon image for object.
189
	 * 
190
	 * @param obj
191
	 * @return
192
	 */
193
	public Image getItemImage(Object obj) {
194
		Image img = null;
195
		String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
196
		if (obj instanceof TRCMethodInvocation) {
197
			imageKey = ISharedImages.IMG_OBJ_FILE;
198
		}
199
		if (null == img) {
200
			img = PlatformUI.getWorkbench().getSharedImages()
201
					.getImage(imageKey);
202
		}
203
		return img;
204
	}
205
206
	static final Object[] empty = new Object[0];
207
208
	class CallStackContentProvider implements ITreeContentProvider {
209
210
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
211
		}
212
213
		public void dispose() {
214
		}
215
216
		public Object[] getElements(Object parent) {
217
			Object[] ret = empty;
218
			if (null != _selection)
219
				ret = new Object[] { _selection };
220
			return ret;
221
		}
222
223
		public Object[] getChildren(Object parentElement) {
224
			Object[] ret = empty;
225
			if (parentElement instanceof TRCThread) {
226
				TRCThread thread = (TRCThread) parentElement;
227
				TRCMethodInvocation mi;
228
				ArrayList arrlist = new ArrayList();
229
				EList list = thread.getInitialInvocations();
230
				while (list != null && !list.isEmpty()) {
231
					mi = (TRCMethodInvocation) list.get(list.size() - 1);
232
					arrlist.add(mi);
233
					list = mi.getInvokes();
234
				}
235
				ret = arrlist.toArray();
236
			} else if (parentElement instanceof TRCThreadEvent) {
237
				// TODO: CS from event
238
				ret = new String[] { "Placeholder for EVENT's call stack...", };
239
			}
240
			return ret;
241
		}
242
243
		public Object getParent(Object element) {
244
			return null;
245
		}
246
247
		public boolean hasChildren(Object element) {
248
			boolean ret = false;
249
			if (element instanceof TRCThread) {
250
				ret = true;
251
			} else if (element instanceof TRCThreadEvent) {
252
				ret = true;
253
			}
254
			return ret;
255
		}
256
	}
257
258
	class CallStackLabelProvider extends LabelProvider {
259
		public String getText(Object obj) {
260
			return getItemText(obj);
261
		}
262
263
		public Image getImage(Object obj) {
264
			return getItemImage(obj);
265
		}
266
	}
267
268
	public void handleViewSelectionChangedEvent(ViewSelectionChangedEvent event) {
269
		Object source = event.getSource();
270
		if (source instanceof ThreadStatisticView) {
271
			ThreadStatisticView view = (ThreadStatisticView) source;
272
			TRCThread thread = view.getSelectedThread();
273
			update(thread);
274
		} else if (source instanceof ThreadStatesPage) {
275
			ThreadStatesPage page = (ThreadStatesPage) source;
276
			IStructuredSelection sel = (IStructuredSelection) page.getSelection();
277
			update(sel.getFirstElement());
278
		}
279
	}
280
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/TimeScaleCtrl.java (+303 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import org.eclipse.swt.events.MouseEvent;
18
import org.eclipse.swt.events.MouseListener;
19
import org.eclipse.swt.events.MouseMoveListener;
20
import org.eclipse.swt.graphics.GC;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.tptp.trace.jvmti.internal.client.views.UIMessages;
25
26
public class TimeScaleCtrl extends TraceCtrl implements MouseListener, MouseMoveListener {
27
28
	public TimeScaleCtrl(Composite parent, TraceColorScheme colors) {
29
		super(parent, colors);
30
		addMouseListener(this);
31
		addMouseMoveListener(this);
32
	}
33
34
	private ITimeDataProvider _timeProvider;
35
	private int _dragState = 0;
36
	private int _dragX0 = 0;
37
	private int _dragX = 0;
38
	private double _time0bak;
39
	private double _time1bak;
40
	private boolean _isInUpdate;
41
42
	public void setTimeProvider(ITimeDataProvider timeProvider) {
43
		_timeProvider = timeProvider;
44
	}
45
46
	private double _timeDeltaD;
47
	private long _timeDelta;
48
	private void calcTimeDelta(int width, double K) {
49
		long D[] = { 1, 2, 5, };
50
		long pow = 1;
51
		double powD = 0.000000001;
52
		long td = pow;
53
		double tdD = powD;
54
		double dx = tdD * K;
55
		int i = 0;
56
		while (dx < width) {
57
			td = D[i] * pow;
58
			tdD = D[i] * powD;
59
			dx = tdD * K;
60
			i++;
61
			if (i == 3) {
62
				i = 0;
63
				pow *= 10;
64
				powD *= 10;
65
			}
66
		}
67
		_timeDeltaD = tdD;
68
		_timeDelta = td;
69
	}
70
71
	static private TimeDraw _tds[] = new TimeDraw[] {
72
		new TimeDrawSec(),
73
		new TimeDrawMillisec(),
74
		new TimeDrawMicrosec(),
75
		new TimeDrawNanosec(),
76
	};
77
	
78
	static TimeDraw getTimeDraw(long timeDelta) {
79
		TimeDraw timeDraw;
80
		if (timeDelta >= 1000000000)
81
			timeDraw = _tds[0];
82
		else if (timeDelta >= 1000000)
83
			timeDraw = _tds[1];
84
		else if (timeDelta >= 1000) 
85
			timeDraw = _tds[2];
86
		else
87
			timeDraw = _tds[3];
88
		return timeDraw;
89
	}
90
91
	void paint(Rectangle rect, GC gc) {
92
93
		if (_isInUpdate || null == _timeProvider)
94
			return;
95
96
		if (null == _timeProvider) {
97
			gc.fillRectangle(rect);
98
			return;
99
		}
100
101
		gc.setBackground(_colors.getColor(TraceColorScheme.TOOL_BACKGROUND));
102
		gc.setForeground(_colors.getColor(TraceColorScheme.TOOL_FOREGROUND));
103
		double time0 = _timeProvider.getTime0();
104
		double time1 = _timeProvider.getTime1();
105
		double selectedTime = _timeProvider.getSelectedTime();
106
		int leftSpace = _timeProvider.getNameSpace();
107
		int timeSpace = _timeProvider.getTimeSpace();
108
109
		if (time1 <= time0) {
110
			gc.fillRectangle(rect);
111
			return;
112
		}
113
		double timeRange = time1 - time0;
114
		int numDigits = 8; // 11:222
115
		if (timeRange < .00001)
116
			numDigits = 16; // 11:222:333:444__
117
		else if (timeRange < .01)
118
			numDigits = 12; // 11:222:333__
119
120
		Utils.init(_rect1, rect);
121
		int labelWidth = gc.getCharWidth('0') * numDigits;
122
		double K = 1;
123
		if (rect.width - leftSpace > 0) {
124
			K = (double) timeSpace / (time1 - time0);
125
			calcTimeDelta(labelWidth, K);
126
		}
127
		TimeDraw timeDraw = getTimeDraw(_timeDelta);
128
129
		// draw top left area
130
		_rect1.width = leftSpace;
131
		gc.fillRectangle(_rect1);
132
		_rect1.x += 4;
133
		_rect1.width -= 4;
134
		if (_rect1.width > 0) {
135
			if (rect.width - leftSpace > 0)
136
				Utils.drawText(gc, "Time: " + timeDraw.hint(), _rect1, true);
137
			else
138
				Utils.drawText(gc, UIMessages.TIME_SCALE, _rect1, true);
139
		}
140
		_rect1.x -= 4;
141
		_rect1.width += 4;
142
143
		// prepare and draw right rect of the timescale
144
		_rect1.x += leftSpace;
145
		_rect1.width = rect.width - leftSpace;
146
147
		// draw bottom border and erase all other area
148
		gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1,
149
				rect.y + rect.height - 1);
150
		_rect1.height--;
151
		gc.fillRectangle(_rect1);
152
153
		if (_rect1.isEmpty())
154
			return;
155
156
		// draw selected time
157
		int x = _rect1.x + (int) ((selectedTime - time0) * K);
158
		if (x >= _rect1.x && x < _rect1.x + _rect1.width) {
159
			gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));
160
			gc.drawLine(x, _rect1.y + _rect1.height - 6, x, _rect1.y + _rect1.height);
161
			gc.setForeground(_colors.getColor(TraceColorScheme.TOOL_FOREGROUND));
162
		}
163
164
		// draw time scale ticks
165
		_rect1.y = rect.y;
166
		_rect1.height = rect.height - 4;
167
		_rect1.width = labelWidth;
168
		double time = Math.floor(time0 / _timeDeltaD) * _timeDeltaD;
169
		long t = (long)(time * 1000000000);
170
		int y = _rect1.y + _rect1.height;
171
		while (true) {
172
			x = rect.x + leftSpace + (int) ((time - time0) * K);
173
			if (x >= rect.x + leftSpace + rect.width - _rect1.width) {
174
				break;
175
			}
176
			if (x >= rect.x + leftSpace) {
177
				gc.drawLine(x, y, x, y + 4);
178
				_rect1.x = x;
179
				if (x + _rect1.width <= rect.x + rect.width)
180
					timeDraw.draw(gc, t, _rect1);
181
			}
182
			time += _timeDeltaD;
183
			t += _timeDelta;
184
		}
185
	}
186
187
	public void mouseDown(MouseEvent e) {
188
		if (1 == e.button && null != _timeProvider) {
189
			setCapture(true);
190
			_dragState = 1;
191
			_dragX = _dragX0 = e.x - _timeProvider.getNameSpace();
192
			_time0bak = _timeProvider.getTime0();
193
			_time1bak = _timeProvider.getTime1();
194
		}
195
	}
196
197
	public void mouseUp(MouseEvent e) {
198
		if (1 == _dragState) {
199
			setCapture(false);
200
			_dragState = 0;
201
		}
202
	}
203
204
	public void mouseMove(MouseEvent e) {
205
		Point size = getSize();
206
		if (1 == _dragState && null != _timeProvider) {
207
			int leftSpace = _timeProvider.getNameSpace();
208
			int x = e.x - leftSpace;
209
			if (x > 0 && size.x > leftSpace && _dragX != x) {
210
				_dragX = x;
211
				double time1 = _time0bak + (_time1bak - _time0bak) * _dragX0 / _dragX;
212
				_timeProvider.setStartFinishTime(_time0bak, time1);
213
			}
214
		}
215
	}
216
217
	public void mouseDoubleClick(MouseEvent e) {
218
		if (null != _timeProvider) {
219
			_timeProvider.resetStartFinishTime();
220
		}
221
	}
222
}
223
224
abstract class TimeDraw {
225
	static String S = ":";
226
	static String S0 = ":0";
227
	static String S00 = ":00";
228
229
	static String pad(long n) {
230
		String s = S;
231
		if (n < 10)
232
			s = S00;
233
		else if (n < 100)
234
			s = S0;
235
		return s + n;
236
	}
237
238
	public abstract void draw(GC gc, long time, Rectangle rect);
239
	public abstract String hint();
240
}
241
242
class TimeDrawSec extends TimeDraw {
243
	static String _hint = "sec";
244
245
	public void draw(GC gc, long time, Rectangle rect) {
246
		time /= 1000000000;
247
		Utils.drawText(gc, time + "", rect, true);
248
	}
249
250
	public String hint() {
251
		return _hint;
252
	}
253
}
254
255
class TimeDrawMillisec extends TimeDraw {
256
	static String _hint = "s:ms";
257
258
	public void draw(GC gc, long time, Rectangle rect) {
259
		time /= 1000000;
260
		long ms = time % 1000;
261
		time /= 1000;
262
		Utils.drawText(gc, time + pad(ms), rect, true);
263
	}
264
265
	public String hint() {
266
		return _hint;
267
	}
268
}
269
270
class TimeDrawMicrosec extends TimeDraw {
271
	static String _hint = "s:ms:mcs";
272
273
	public void draw(GC gc, long time, Rectangle rect) {
274
		time /= 1000;
275
		long mcs = time % 1000;
276
		time /= 1000;
277
		long ms = time % 1000;
278
		time /= 1000;
279
		Utils.drawText(gc, time + pad(ms) + pad(mcs), rect, true);
280
	}
281
282
	public String hint() {
283
		return _hint;
284
	}
285
}
286
287
class TimeDrawNanosec extends TimeDraw {
288
	static String _hint = "s:ms:mcs:ns";
289
290
	public void draw(GC gc, long time, Rectangle rect) {
291
		long ns = time % 1000;
292
		time /= 1000;
293
		long mcs = time % 1000;
294
		time /= 1000;
295
		long ms = time % 1000;
296
		time /= 1000;
297
		Utils.drawText(gc, time + pad(ms) + pad(mcs) + pad(ns), rect, true);
298
	}
299
300
	public String hint() {
301
		return _hint;
302
	}
303
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/LegendCtrl.java (+72 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.graphics.Point;
19
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.tptp.trace.jvmti.internal.client.views.UIMessages;
22
23
public class LegendCtrl extends TraceCtrl {
24
25
	static private String _names[];
26
27
	public LegendCtrl(Composite parent, TraceColorScheme colors) {
28
		super(parent, colors);
29
	}
30
	
31
	static private String [] getNames() {
32
		if (null == _names) {
33
			String names[] = {
34
					UIMessages._267, // "Unknown",
35
					UIMessages._261, // "Running",
36
					UIMessages._262, // "Sleeping",
37
					UIMessages._263, // "Waiting",
38
					UIMessages._264, // "Blocked",
39
					UIMessages._265, // "Deadlock",
40
					UIMessages._266, // "Stopped",
41
			};
42
			_names = names;
43
		}
44
		return _names;
45
	}
46
47
	void paint(Rectangle rect, GC gc) {
48
		gc.setBackground(_colors.getColor(TraceColorScheme.LEGEND_BACKGROUND));
49
		gc.fillRectangle(rect);
50
		// draw legend rect
51
		Utils.init(_rect1, rect);
52
		//gc.setForeground(_colors.getColor(TraceColorScheme.LEGEND_FOREGROUND));
53
		//gc.drawRectangle(_rect1.x, _rect1.y, _rect1.width - 1, _rect1.height - 1);
54
		// draw legend elements
55
		int idx = 0;
56
		String names[] = getNames();
57
		_rect1.x += 4;
58
		_rect1.y += 2;
59
		while (idx < names.length && _rect1.x < rect.x + rect.width) {
60
			Point size = gc.stringExtent(names[idx]);
61
			_rect1.width = 16;
62
			_rect1.height = size.y;
63
			Utils.drawState(_colors, idx, _rect1, gc, false, true, false);
64
			_rect1.x += _rect1.width + 2;
65
			_rect1.width = size.x;
66
			gc.setForeground(_colors.getColor(TraceColorScheme.LEGEND_FOREGROUND));
67
			Utils.drawText(gc, names[idx], _rect1, true);
68
			_rect1.x += _rect1.width + 8;
69
			idx++;
70
		}
71
	}
72
}
(-)src/org/eclipse/tptp/trace/jvmti/internal/client/widgets/TraceColorScheme.java (+281 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 1997-2006, Intel Corporation.
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
 *    Intel Corporation - Initial API and implementation
10
 *    Ruslan A. Scherbakov, Intel - Initial API and implementation
11
 *
12
 * $Id$ 
13
 *****************************************************************************/
14
15
package org.eclipse.tptp.trace.jvmti.internal.client.widgets;
16
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.graphics.Color;
19
20
public class TraceColorScheme {
21
22
	// state elements color indices
23
	static public final int UNKNOWN = 0;
24
	static public final int RUNNING = 1;
25
	static public final int SLEEPING = 2;
26
	static public final int WAITING = 3;
27
	static public final int BLOCKED = 4;
28
	static public final int DEADLOCK = 5;
29
	static public final int STOPPED = 6;
30
31
	static public final int STATES0 = 0;
32
	static public final int STATES1 = 7;
33
34
	// selected state elements color indices
35
	static public final int UNKNOWN_SEL = 7;
36
	static public final int RUNNING_SEL = 8;
37
	static public final int SLEEPING_SEL = 9;
38
	static public final int WAITING_SEL = 10;
39
	static public final int BLOCKED_SEL = 11;
40
	static public final int DEADLOCK_SEL = 12;
41
	static public final int STOPPED_SEL = 13;
42
43
	static public final int STATES_SEL0 = 7;
44
	static public final int STATES_SEL1 = 13;
45
46
	// colors indices for viewer controls
47
	static public final int BACKGROUND = 14;
48
	static public final int FOREGROUND = 15;
49
	static public final int BACKGROUND_SEL = 16;
50
	static public final int FOREGROUND_SEL = 17;
51
	static public final int BACKGROUND_SEL_NOFOCUS = 18;
52
	static public final int FOREGROUND_SEL_NOFOCUS = 19;
53
	static public final int TOOL_BACKGROUND = 20;
54
	static public final int TOOL_FOREGROUND = 21;
55
56
	// misc colors
57
	static public final int FIX_COLOR = 22;
58
	static public final int WHITE = 23;
59
	static public final int GRAY = 24;
60
	static public final int BLACK = 25;
61
	static public final int DARK_GRAY = 26;
62
63
	// selected state elements border color indices
64
	static public final int UNKNOWN_BORDER = 27;
65
	static public final int RUNNING_BORDER = 28;
66
	static public final int SLEEPING_BORDER = 29;
67
	static public final int WAITING_BORDER = 30;
68
	static public final int BLOCKED_BORDER = 31;
69
	static public final int DEADLOCK_BORDER = 32;
70
	static public final int STOPPED_BORDER = 33;
71
72
	static public final int STATES_BORDER0 = 27;
73
	static public final int STATES_BORDER1 = 33;
74
75
	static public final int MID_LINE = 34;
76
	static public final int RED = 35;
77
	static public final int GREEN = 36;
78
	static public final int BLUE = 37;
79
	static public final int YELLOW = 38;
80
	static public final int CYAN = 39;
81
	static public final int MAGENTA = 40;
82
83
	static public final int SELECTED_TIME = 41;
84
	static public final int LEGEND_BACKGROUND = 42;
85
	static public final int LEGEND_FOREGROUND = 43;
86
87
	// group items' colors
88
	static public final int GR_BACKGROUND = 44;
89
	static public final int GR_FOREGROUND = 45;
90
	static public final int GR_BACKGROUND_SEL = 46;
91
	static public final int GR_FOREGROUND_SEL = 47;
92
	static public final int GR_BACKGROUND_SEL_NOFOCUS = 48;
93
	static public final int GR_FOREGROUND_SEL_NOFOCUS = 49;
94
	
95
	static public final int LIGHT_LINE = 50;
96
	static public final int BACKGROUND_NAME = 51;
97
98
	static interface IColorProvider {
99
		public Color get();
100
	}
101
102
	static class SysCol implements IColorProvider {
103
		int syscol;
104
105
		SysCol(int syscol) {
106
			this.syscol = syscol;
107
		}
108
109
		public Color get() {
110
			return Utils.getSysColor(syscol);
111
		}
112
	}
113
114
	static class RGB implements IColorProvider {
115
		int r;
116
		int g;
117
		int b;
118
119
		RGB(int r, int g, int b) {
120
			this.r = r;
121
			this.g = g;
122
			this.b = b;
123
		}
124
125
		public Color get() {
126
			return new Color(null, r, g, b);
127
		}
128
	}
129
130
	static class Mix implements IColorProvider {
131
		IColorProvider cp1;
132
		IColorProvider cp2;
133
		int w1;
134
		int w2;
135
136
		Mix(IColorProvider cp1, IColorProvider cp2, int w1, int w2) {
137
			this.cp1 = cp1;
138
			this.cp2 = cp2;
139
			this.w1 = w1;
140
			this.w2 = w2;
141
		}
142
143
		Mix(IColorProvider cp1, IColorProvider cp2) {
144
			this.cp1 = cp1;
145
			this.cp2 = cp2;
146
			this.w1 = 1;
147
			this.w2 = 1;
148
		}
149
150
		public Color get() {
151
			Color col1 = cp1.get();
152
			Color col2 = cp2.get();
153
			Color col = Utils.mixColors(col1, col2, w1, w2);
154
			return col;
155
		}
156
	}
157
158
	static private final IColorProvider _providersMap[] = {
159
			//
160
			new RGB(100, 100, 100), // UNKNOWN
161
			new RGB(174, 200, 124), // RUNNING
162
			new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING
163
			new RGB(210, 150, 60), // WAITING
164
			new RGB(242, 225, 168), // BLOCKED
165
			new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK
166
			new RGB(200, 200, 200), // STOPPED
167
168
			new SysCol(SWT.COLOR_WHITE), // UNKNOWN_SEL
169
			new SysCol(SWT.COLOR_GREEN), // RUNNING_SEL
170
			new SysCol(SWT.COLOR_BLUE), // SLEEPING_SEL
171
			new SysCol(SWT.COLOR_CYAN), // WAITING_SEL
172
			new SysCol(SWT.COLOR_YELLOW), // BLOCKED_SEL
173
			new SysCol(SWT.COLOR_RED), // DEADLOCK_SEL
174
			new SysCol(SWT.COLOR_DARK_GRAY), // STOPPED_SEL
175
176
			new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND
177
			new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND
178
			new SysCol(SWT.COLOR_LIST_SELECTION), // BACKGROUND_SEL
179
			new SysCol(SWT.COLOR_LIST_SELECTION_TEXT), // FOREGROUND_SEL
180
			new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS
181
			new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS
182
			new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND
183
			new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // TOOL_FOREGROUND
184
185
			new SysCol(SWT.COLOR_GRAY), // FIX_COLOR
186
			new SysCol(SWT.COLOR_WHITE), // WHITE
187
			new SysCol(SWT.COLOR_GRAY), // GRAY
188
			new SysCol(SWT.COLOR_BLACK), // BLACK
189
			new SysCol(SWT.COLOR_DARK_GRAY), // DARK_GRAY
190
191
			new SysCol(SWT.COLOR_DARK_GRAY), // UNKNOWN_BORDER
192
			new RGB(75, 115, 120), // RUNNING_BORDER
193
			new SysCol(SWT.COLOR_DARK_BLUE), // SLEEPING_BORDER
194
			new RGB(242, 225, 168), // WAITING_BORDER
195
			new RGB(210, 150, 60), // BLOCKED_BORDER
196
			new SysCol(SWT.COLOR_DARK_RED), // DEADLOCK_BORDER
197
			new SysCol(SWT.COLOR_BLACK), // STOPPED_BORDER
198
199
			new SysCol(SWT.COLOR_GRAY), // MID_LINE
200
			new SysCol(SWT.COLOR_RED), // RED
201
			new SysCol(SWT.COLOR_GREEN), // GREEN
202
			new SysCol(SWT.COLOR_BLUE), // BLUE
203
			new SysCol(SWT.COLOR_YELLOW), // YELLOW
204
			new SysCol(SWT.COLOR_CYAN), // CYAN
205
			new SysCol(SWT.COLOR_MAGENTA), // MAGENTA
206
207
			new SysCol(SWT.COLOR_BLUE), // SELECTED_TIME
208
			new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // LEGEND_BACKGROUND
209
			new SysCol(SWT.COLOR_WIDGET_DARK_SHADOW), // LEGEND_FOREGROUND
210
211
			new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_BACKGROUND)),// GR_BACKGROUND
212
			new RGB(0, 0, 50), // GR_FOREGROUND
213
			new Mix(new RGB(200, 200, 100), new SysCol(SWT.COLOR_LIST_SELECTION)),  // GR_BACKGROUND_SEL
214
			new Mix(new RGB(150, 200, 240), new SysCol(SWT.COLOR_LIST_SELECTION_TEXT)), // GR_FOREGROUND_SEL
215
			new Mix(new RGB(222, 222, 155), new SysCol(SWT.COLOR_WIDGET_BACKGROUND)), // GR_BACKGROUND_SEL_NOFOCUS
216
			new RGB(0, 0, 50), // GR_FOREGROUND_SEL_NOFOCUS
217
218
			new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE
219
			new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME
220
	};
221
222
	private Color _colors[];
223
224
	public TraceColorScheme() {
225
		_colors = new Color[_providersMap.length];
226
	}
227
228
	public void dispose() {
229
		for (int i = 0; i < _colors.length; i++) {
230
			Utils.dispose(_colors[i]);
231
			_colors[i] = null;
232
		}
233
	}
234
235
	public Color getColor(int idx) {
236
		if (null == _colors[idx]) {
237
			if (idx >= STATES_SEL0 && idx <= STATES_SEL1) {
238
				Color col1 = getColor(idx - STATES_SEL0);
239
				Color col2 = getColor(BACKGROUND_SEL);
240
				_colors[idx] = Utils.mixColors(col1, col2, 3, 1);
241
			} else {
242
				_colors[idx] = _providersMap[idx].get();
243
			}
244
		}
245
		return _colors[idx];
246
	}
247
248
	public Color getBkColor(boolean selected, boolean focused, boolean name) {
249
		if (selected && focused)
250
			return getColor(BACKGROUND_SEL);
251
		if (selected)
252
			return getColor(BACKGROUND_SEL_NOFOCUS);
253
		if (name)
254
			return getColor(BACKGROUND_NAME);
255
		return getColor(BACKGROUND);
256
	}
257
258
	public Color getFgColor(boolean selected, boolean focused) {
259
		if (selected && focused)
260
			return getColor(FOREGROUND_SEL);
261
		if (selected)
262
			return getColor(FOREGROUND_SEL_NOFOCUS);
263
		return getColor(FOREGROUND);
264
	}
265
266
	public Color getBkColorGroup(boolean selected, boolean focused) {
267
		if (selected && focused)
268
			return getColor(GR_BACKGROUND_SEL);
269
		if (selected)
270
			return getColor(GR_BACKGROUND_SEL_NOFOCUS);
271
		return getColor(GR_BACKGROUND);
272
	}
273
274
	public Color getFgColorGroup(boolean selected, boolean focused) {
275
		if (selected && focused)
276
			return getColor(GR_FOREGROUND_SEL);
277
		if (selected)
278
			return getColor(GR_FOREGROUND_SEL_NOFOCUS);
279
		return getColor(GR_FOREGROUND);
280
	}
281
}

Return to bug 167609