Commit | Line | Data |
---|---|---|
ed963ef6 FC |
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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
1cceddbe | 14 | |
15 | import java.util.Iterator; | |
ed963ef6 FC |
16 | |
17 | import org.eclipse.core.expressions.PropertyTester; | |
1cceddbe | 18 | import org.eclipse.jface.viewers.IStructuredSelection; |
ed963ef6 FC |
19 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; |
20 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; | |
1cceddbe | 21 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; |
ed963ef6 FC |
22 | |
23 | /** | |
24 | * <b><u>TracePropertyTester</u></b> | |
25 | * <p> | |
26 | */ | |
27 | public class TracePropertyTester extends PropertyTester { | |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Constants | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
1cceddbe | 33 | private static String isInTraceFolder = "isInTraceFolder"; //$NON-NLS-1$ |
ed963ef6 | 34 | private static String isExperimentTrace = "isExperimentTrace"; //$NON-NLS-1$ |
0f0d17bb | 35 | private static String hasHistoryFile = "hasHistoryFile"; //$NON-NLS-1$ |
ed963ef6 FC |
36 | |
37 | // ------------------------------------------------------------------------ | |
38 | // Constructor | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
41 | /** | |
42 | * Default constructor | |
43 | */ | |
44 | public TracePropertyTester() { | |
45 | } | |
46 | ||
47 | // ------------------------------------------------------------------------ | |
48 | // IPropertyTester | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
51 | /* (non-Javadoc) | |
52 | * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) | |
53 | */ | |
54 | @Override | |
55 | public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { | |
1cceddbe | 56 | |
57 | // Check if the selected elements are in the trace folder | |
58 | if (isInTraceFolder.equals(property)) { | |
59 | if (receiver != null && receiver instanceof IStructuredSelection) { | |
60 | Iterator<?> iter = ((IStructuredSelection) receiver).iterator(); | |
61 | while (iter.hasNext()) { | |
62 | Object item = iter.next(); | |
63 | if (item instanceof TmfTraceElement) { | |
f4c52cea | 64 | TmfTraceElement trace = (TmfTraceElement) item; |
1cceddbe | 65 | if (!(trace.getParent() instanceof TmfTraceFolder)) { |
66 | return false; | |
67 | } | |
68 | } else { | |
69 | return false; | |
70 | } | |
71 | } | |
72 | return true; | |
73 | } | |
74 | } | |
75 | ||
ed963ef6 | 76 | // Check if the parent of a trace element is an experiment |
1cceddbe | 77 | if (isExperimentTrace.equals(property)) { |
78 | if (receiver != null && receiver instanceof TmfTraceElement) { | |
ed963ef6 | 79 | TmfTraceElement trace = (TmfTraceElement) receiver; |
ed963ef6 FC |
80 | return trace.getParent() instanceof TmfExperimentElement; |
81 | } | |
1cceddbe | 82 | return false; |
ed963ef6 | 83 | } |
0f0d17bb AM |
84 | |
85 | if (hasHistoryFile.equals(property)) { | |
5e4bf87d BH |
86 | if (receiver == null) { |
87 | return false; | |
88 | } | |
89 | ||
90 | if (receiver instanceof TmfTraceElement) { | |
91 | TmfTraceElement trace = (TmfTraceElement) receiver; | |
0f0d17bb AM |
92 | // If trace is under an experiment, use the original trace from the traces folder |
93 | trace = trace.getElementUnderTraceFolder(); | |
94 | return trace.hasSupplementaryFiles(); | |
5e4bf87d BH |
95 | } else if (receiver instanceof TmfExperimentElement) { |
96 | TmfExperimentElement trace = (TmfExperimentElement) receiver; | |
97 | for (TmfTraceElement aTrace : trace.getTraces()) { | |
0f0d17bb AM |
98 | // Since trace is under an experiment, use the original trace from the traces folder |
99 | aTrace = aTrace.getElementUnderTraceFolder(); | |
100 | return aTrace.hasSupplementaryFiles(); | |
5e4bf87d BH |
101 | } |
102 | } | |
103 | return false; | |
104 | } | |
105 | ||
ed963ef6 FC |
106 | return false; |
107 | } | |
108 | ||
109 | } |