tmf: Drop generics from ITmfTrace and TmfExperiment
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesView.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Comparator;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.NullProgressMonitor;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IToolBarManager;
25 import org.eclipse.jface.action.Separator;
26 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
27 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
28 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
29 import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;
30 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
31 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
32 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
33 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
34 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
35 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
36 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
37 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
38 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
39 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
40 import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
41 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
42 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
43 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier2;
44 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
45 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
46 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
47 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;
48 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
49 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;
50 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
51 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;
52 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
53 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
54 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
55 import org.eclipse.swt.SWT;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Display;
58 import org.eclipse.ui.IActionBars;
59
60 /**
61 * Main implementation for the LTTng 2.0 kernel Resource view
62 *
63 * @author Patrick Tasse
64 */
65 public class ResourcesView extends TmfView {
66
67 // ------------------------------------------------------------------------
68 // Constants
69 // ------------------------------------------------------------------------
70
71 /** View ID. */
72 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
73
74 /** Initial time range */
75 private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec
76
77 /**
78 * Redraw state enum
79 */
80 private enum State { IDLE, BUSY, PENDING }
81
82 // ------------------------------------------------------------------------
83 // Fields
84 // ------------------------------------------------------------------------
85
86 // The time graph viewer
87 TimeGraphViewer fTimeGraphViewer;
88
89 // The selected experiment
90 private TmfExperiment fSelectedExperiment;
91
92 // The time graph entry list
93 private ArrayList<TraceEntry> fEntryList;
94
95 // The time graph entry list synchronization object
96 final private Object fEntryListSyncObj = new Object();
97
98 // The start time
99 private long fStartTime;
100
101 // The end time
102 private long fEndTime;
103
104 // The display width
105 private final int fDisplayWidth;
106
107 // The next resource action
108 private Action fNextResourceAction;
109
110 // The previous resource action
111 private Action fPreviousResourceAction;
112
113 // The zoom thread
114 private ZoomThread fZoomThread;
115
116 // The redraw state used to prevent unnecessary queuing of display runnables
117 private State fRedrawState = State.IDLE;
118
119 // The redraw synchronization object
120 final private Object fSyncObj = new Object();
121
122 // ------------------------------------------------------------------------
123 // Classes
124 // ------------------------------------------------------------------------
125
126 private class TraceEntry implements ITimeGraphEntry {
127 // The Trace
128 private final CtfKernelTrace fTrace;
129 // The start time
130 private final long fTraceStartTime;
131 // The end time
132 private final long fTraceEndTime;
133 // The children of the entry
134 private final ArrayList<ResourcesEntry> fChildren;
135 // The name of entry
136 private final String fName;
137
138 public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {
139 fTrace = trace;
140 fChildren = new ArrayList<ResourcesEntry>();
141 fName = name;
142 fTraceStartTime = startTime;
143 fTraceEndTime = endTime;
144 }
145
146 @Override
147 public ITimeGraphEntry getParent() {
148 return null;
149 }
150
151 @Override
152 public boolean hasChildren() {
153 return fChildren != null && fChildren.size() > 0;
154 }
155
156 @Override
157 public ResourcesEntry[] getChildren() {
158 return fChildren.toArray(new ResourcesEntry[0]);
159 }
160
161 @Override
162 public String getName() {
163 return fName;
164 }
165
166 @Override
167 public long getStartTime() {
168 return fTraceStartTime;
169 }
170
171 @Override
172 public long getEndTime() {
173 return fTraceEndTime;
174 }
175
176 @Override
177 public boolean hasTimeEvents() {
178 return false;
179 }
180
181 @Override
182 public Iterator<ITimeEvent> getTimeEventsIterator() {
183 return null;
184 }
185
186 @Override
187 public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
188 return null;
189 }
190
191 public CtfKernelTrace getTrace() {
192 return fTrace;
193 }
194
195 public void addChild(ResourcesEntry entry) {
196 int index;
197 for (index = 0; index < fChildren.size(); index++) {
198 ResourcesEntry other = fChildren.get(index);
199 if (entry.getType().compareTo(other.getType()) < 0) {
200 break;
201 } else if (entry.getType().equals(other.getType())) {
202 if (entry.getId() < other.getId()) {
203 break;
204 }
205 }
206 }
207 entry.setParent(this);
208 fChildren.add(index, entry);
209 }
210 }
211
212 private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {
213 @Override
214 public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
215 int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
216 if (result == 0) {
217 result = o1.getName().compareTo(o2.getName());
218 }
219 return result;
220 }
221 }
222
223 private class ZoomThread extends Thread {
224 private final long fZoomStartTime;
225 private final long fZoomEndTime;
226 private final IProgressMonitor fMonitor;
227
228 public ZoomThread(long startTime, long endTime) {
229 super("ResourcesView zoom"); //$NON-NLS-1$
230 fZoomStartTime = startTime;
231 fZoomEndTime = endTime;
232 fMonitor = new NullProgressMonitor();
233 }
234
235 @Override
236 public void run() {
237 ArrayList<TraceEntry> entryList = null;
238 synchronized (fEntryListSyncObj) {
239 entryList = fEntryList;
240 }
241 if (entryList == null) {
242 return;
243 }
244 long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);
245 for (TraceEntry traceEntry : entryList) {
246 for (ITimeGraphEntry child : traceEntry.getChildren()) {
247 if (fMonitor.isCanceled()) {
248 break;
249 }
250 ResourcesEntry entry = (ResourcesEntry) child;
251 if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {
252 entry.setZoomedEventList(null);
253 } else {
254 List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);
255 if (zoomedEventList != null) {
256 entry.setZoomedEventList(zoomedEventList);
257 }
258 }
259 redraw();
260 }
261 }
262 }
263
264 public void cancel() {
265 fMonitor.setCanceled(true);
266 }
267 }
268
269 // ------------------------------------------------------------------------
270 // Constructors
271 // ------------------------------------------------------------------------
272
273 /**
274 * Default constructor
275 */
276 public ResourcesView() {
277 super(ID);
278 fDisplayWidth = Display.getDefault().getBounds().width;
279 }
280
281 // ------------------------------------------------------------------------
282 // ViewPart
283 // ------------------------------------------------------------------------
284
285 /* (non-Javadoc)
286 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
287 */
288 @Override
289 public void createPartControl(Composite parent) {
290 fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
291
292 fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider());
293
294 fTimeGraphViewer.setTimeCalendarFormat(true);
295
296 fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {
297 @Override
298 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {
299 long startTime = event.getStartTime();
300 long endTime = event.getEndTime();
301 TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));
302 TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());
303 broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));
304 startZoomThread(startTime, endTime);
305 }
306 });
307
308 fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {
309 @Override
310 public void timeSelected(TimeGraphTimeEvent event) {
311 long time = event.getTime();
312 broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));
313 }
314 });
315
316 final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
317 @Override
318 public void run() {
319 if (TmfExperiment.getCurrentExperiment() != null) {
320 selectExperiment(TmfExperiment.getCurrentExperiment());
321 }
322 }
323 };
324 thread.start();
325
326 // View Action Handling
327 makeActions();
328 contributeToActionBars();
329 }
330
331 /* (non-Javadoc)
332 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
333 */
334 @Override
335 public void setFocus() {
336 fTimeGraphViewer.setFocus();
337 }
338
339 // ------------------------------------------------------------------------
340 // Signal handlers
341 // ------------------------------------------------------------------------
342
343 /**
344 * Handler for the ExperimentSelected signal
345 *
346 * @param signal
347 * The incoming signal
348 */
349 @TmfSignalHandler
350 public void experimentSelected(final TmfExperimentSelectedSignal signal) {
351 if (signal.getExperiment().equals(fSelectedExperiment)) {
352 return;
353 }
354
355 final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
356 @Override
357 public void run() {
358 selectExperiment(signal.getExperiment());
359 }
360 };
361 thread.start();
362 }
363
364 /**
365 * Handler for the TimeSynch signal
366 *
367 * @param signal
368 * The incoming signal
369 */
370 @TmfSignalHandler
371 public void synchToTime(final TmfTimeSynchSignal signal) {
372 if (signal.getSource() == this || fSelectedExperiment == null) {
373 return;
374 }
375 final long time = signal.getCurrentTime().normalize(0, -9).getValue();
376 Display.getDefault().asyncExec(new Runnable() {
377 @Override
378 public void run() {
379 if (fTimeGraphViewer.getControl().isDisposed()) {
380 return;
381 }
382 fTimeGraphViewer.setSelectedTime(time, true);
383 startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());
384 }
385 });
386 }
387
388 /**
389 * Handler for the RangeSynch signal
390 *
391 * @param signal
392 * The incoming signal
393 */
394 @TmfSignalHandler
395 public void synchToRange(final TmfRangeSynchSignal signal) {
396 if (signal.getSource() == this || fSelectedExperiment == null) {
397 return;
398 }
399 final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();
400 final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();
401 final long time = signal.getCurrentTime().normalize(0, -9).getValue();
402 Display.getDefault().asyncExec(new Runnable() {
403 @Override
404 public void run() {
405 if (fTimeGraphViewer.getControl().isDisposed()) {
406 return;
407 }
408 fTimeGraphViewer.setStartFinishTime(startTime, endTime);
409 fTimeGraphViewer.setSelectedTime(time, false);
410 startZoomThread(startTime, endTime);
411 }
412 });
413 }
414
415 /**
416 * Handler for the StatesystemBuildCompleted signal
417 *
418 * @param signal
419 * The incoming signal
420 */
421 @TmfSignalHandler
422 public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {
423 final TmfExperiment selectedExperiment = fSelectedExperiment;
424 if (selectedExperiment == null || selectedExperiment.getTraces() == null) {
425 return;
426 }
427 for (ITmfTrace trace : selectedExperiment.getTraces()) {
428 if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {
429 final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$
430 @Override
431 public void run() {
432 // rebuild the model
433 selectExperiment(selectedExperiment);
434 }
435 };
436 thread.start();
437 }
438 }
439 }
440
441 // ------------------------------------------------------------------------
442 // Internal
443 // ------------------------------------------------------------------------
444
445 private void selectExperiment(TmfExperiment experiment) {
446 fStartTime = Long.MAX_VALUE;
447 fEndTime = Long.MIN_VALUE;
448 fSelectedExperiment = experiment;
449 ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();
450 for (ITmfTrace trace : experiment.getTraces()) {
451 if (trace instanceof CtfKernelTrace) {
452 CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;
453 IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
454 long startTime = ssq.getStartTime();
455 long endTime = ssq.getCurrentEndTime() + 1;
456 TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, trace.getName(), startTime, endTime);
457 entryList.add(groupEntry);
458 fStartTime = Math.min(fStartTime, startTime);
459 fEndTime = Math.max(fEndTime, endTime);
460 List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
461 ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
462 for (int i = 0; i < cpuQuarks.size(); i++) {
463 int cpuQuark = cpuQuarks.get(i);
464 int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
465 ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);
466 groupEntry.addChild(entry);
467 cpuEntries[i] = entry;
468 }
469 List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
470 ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
471 for (int i = 0; i < irqQuarks.size(); i++) {
472 int irqQuark = irqQuarks.get(i);
473 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
474 ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);
475 groupEntry.addChild(entry);
476 irqEntries[i] = entry;
477 }
478 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
479 ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
480 for (int i = 0; i < softIrqQuarks.size(); i++) {
481 int softIrqQuark = softIrqQuarks.get(i);
482 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
483 ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);
484 groupEntry.addChild(entry);
485 softIrqEntries[i] = entry;
486 }
487 }
488 }
489 synchronized (fEntryListSyncObj) {
490 fEntryList = (ArrayList<TraceEntry>) entryList.clone();
491 }
492 refresh(INITIAL_WINDOW_OFFSET);
493 for (TraceEntry traceEntry : entryList) {
494 CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();
495 IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();
496 long startTime = ssq.getStartTime();
497 long endTime = ssq.getCurrentEndTime() + 1;
498 long resolution = (endTime - startTime) / fDisplayWidth;
499 for (ResourcesEntry entry : traceEntry.getChildren()) {
500 List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, new NullProgressMonitor());
501 entry.setEventList(eventList);
502 redraw();
503 }
504 }
505 }
506
507 private static List<ITimeEvent> getEventList(ResourcesEntry entry,
508 long startTime, long endTime, long resolution, boolean includeNull,
509 IProgressMonitor monitor) {
510 IStateSystemQuerier2 ssq = (IStateSystemQuerier2) entry.getTrace().getStateSystem();
511 startTime = Math.max(startTime, ssq.getStartTime());
512 endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);
513 if (endTime <= startTime) {
514 return null;
515 }
516 List<ITimeEvent> eventList = null;
517 int quark = entry.getQuark();
518 try {
519 if (entry.getType().equals(Type.CPU)) {
520 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
521 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);
522 eventList = new ArrayList<ITimeEvent>(statusIntervals.size());
523 long lastEndTime = -1;
524 for (ITmfStateInterval statusInterval : statusIntervals) {
525 if (monitor.isCanceled()) {
526 return null;
527 }
528 int status = statusInterval.getStateValue().unboxInt();
529 long time = statusInterval.getStartTime();
530 long duration = statusInterval.getEndTime() - time + 1;
531 if (!statusInterval.getStateValue().isNull()) {
532 if (lastEndTime != time && lastEndTime != -1) {
533 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
534 }
535 eventList.add(new ResourcesEvent(entry, time, duration, status));
536 lastEndTime = time + duration;
537 } else {
538 if (includeNull) {
539 eventList.add(new ResourcesEvent(entry, time, duration));
540 }
541 }
542 }
543 } else if (entry.getType().equals(Type.IRQ)) {
544 List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
545 eventList = new ArrayList<ITimeEvent>(irqIntervals.size());
546 long lastEndTime = -1;
547 boolean lastIsNull = true;
548 for (ITmfStateInterval irqInterval : irqIntervals) {
549 if (monitor.isCanceled()) {
550 return null;
551 }
552 long time = irqInterval.getStartTime();
553 long duration = irqInterval.getEndTime() - time + 1;
554 if (!irqInterval.getStateValue().isNull()) {
555 int cpu = irqInterval.getStateValue().unboxInt();
556 eventList.add(new ResourcesEvent(entry, time, duration, cpu));
557 lastIsNull = false;
558 } else {
559 if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
560 eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
561 }
562 if (includeNull) {
563 eventList.add(new ResourcesEvent(entry, time, duration));
564 }
565 lastIsNull = true;
566 }
567 lastEndTime = time + duration;
568 }
569 } else if (entry.getType().equals(Type.SOFT_IRQ)) {
570 List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);
571 eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());
572 long lastEndTime = -1;
573 boolean lastIsNull = true;
574 for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
575 if (monitor.isCanceled()) {
576 return null;
577 }
578 long time = softIrqInterval.getStartTime();
579 long duration = softIrqInterval.getEndTime() - time + 1;
580 if (!softIrqInterval.getStateValue().isNull()) {
581 int cpu = softIrqInterval.getStateValue().unboxInt();
582 eventList.add(new ResourcesEvent(entry, time, duration, cpu));
583 } else {
584 if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {
585 eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));
586 }
587 if (includeNull) {
588 eventList.add(new ResourcesEvent(entry, time, duration));
589 }
590 lastIsNull = true;
591 }
592 lastEndTime = time + duration;
593 }
594 }
595 } catch (AttributeNotFoundException e) {
596 e.printStackTrace();
597 } catch (TimeRangeException e) {
598 e.printStackTrace();
599 } catch (StateValueTypeException e) {
600 e.printStackTrace();
601 }
602 return eventList;
603 }
604
605 private void refresh(final long windowRange) {
606 Display.getDefault().asyncExec(new Runnable() {
607 @Override
608 public void run() {
609 if (fTimeGraphViewer.getControl().isDisposed()) {
610 return;
611 }
612 ITimeGraphEntry[] entries = null;
613 synchronized (fEntryListSyncObj) {
614 entries = fEntryList.toArray(new ITimeGraphEntry[0]);
615 }
616 Arrays.sort(entries, new TraceEntryComparator());
617 fTimeGraphViewer.setInput(entries);
618 fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);
619
620 long endTime = fStartTime + windowRange;
621
622 if (fEndTime < endTime) {
623 endTime = fEndTime;
624 }
625 fTimeGraphViewer.setStartFinishTime(fStartTime, endTime);
626
627 startZoomThread(fStartTime, endTime);
628 }
629 });
630 }
631
632
633 private void redraw() {
634 synchronized (fSyncObj) {
635 if (fRedrawState == State.IDLE) {
636 fRedrawState = State.BUSY;
637 } else {
638 fRedrawState = State.PENDING;
639 return;
640 }
641 }
642 Display.getDefault().asyncExec(new Runnable() {
643 @Override
644 public void run() {
645 if (fTimeGraphViewer.getControl().isDisposed()) {
646 return;
647 }
648 fTimeGraphViewer.getControl().redraw();
649 fTimeGraphViewer.getControl().update();
650 synchronized (fSyncObj) {
651 if (fRedrawState == State.PENDING) {
652 fRedrawState = State.IDLE;
653 redraw();
654 } else {
655 fRedrawState = State.IDLE;
656 }
657 }
658 }
659 });
660 }
661
662 private void startZoomThread(long startTime, long endTime) {
663 if (fZoomThread != null) {
664 fZoomThread.cancel();
665 }
666 fZoomThread = new ZoomThread(startTime, endTime);
667 fZoomThread.start();
668 }
669
670 private void makeActions() {
671 fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();
672 fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);
673 fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
674 fNextResourceAction = fTimeGraphViewer.getNextItemAction();
675 fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);
676 fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);
677 }
678
679 private void contributeToActionBars() {
680 IActionBars bars = getViewSite().getActionBars();
681 fillLocalToolBar(bars.getToolBarManager());
682 }
683
684 private void fillLocalToolBar(IToolBarManager manager) {
685 manager.add(fTimeGraphViewer.getShowLegendAction());
686 manager.add(new Separator());
687 manager.add(fTimeGraphViewer.getResetScaleAction());
688 manager.add(fTimeGraphViewer.getPreviousEventAction());
689 manager.add(fTimeGraphViewer.getNextEventAction());
690 manager.add(fPreviousResourceAction);
691 manager.add(fNextResourceAction);
692 manager.add(fTimeGraphViewer.getZoomInAction());
693 manager.add(fTimeGraphViewer.getZoomOutAction());
694 manager.add(new Separator());
695 }
696 }
This page took 0.046995 seconds and 6 git commands to generate.