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 FC |
34 | private static String isExperimentTrace = "isExperimentTrace"; //$NON-NLS-1$ |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Constructor | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | /** | |
41 | * Default constructor | |
42 | */ | |
43 | public TracePropertyTester() { | |
44 | } | |
45 | ||
46 | // ------------------------------------------------------------------------ | |
47 | // IPropertyTester | |
48 | // ------------------------------------------------------------------------ | |
49 | ||
50 | /* (non-Javadoc) | |
51 | * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) | |
52 | */ | |
53 | @Override | |
54 | public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { | |
1cceddbe | 55 | |
56 | // Check if the selected elements are in the trace folder | |
57 | if (isInTraceFolder.equals(property)) { | |
58 | if (receiver != null && receiver instanceof IStructuredSelection) { | |
59 | Iterator<?> iter = ((IStructuredSelection) receiver).iterator(); | |
60 | while (iter.hasNext()) { | |
61 | Object item = iter.next(); | |
62 | if (item instanceof TmfTraceElement) { | |
f4c52cea | 63 | TmfTraceElement trace = (TmfTraceElement) item; |
1cceddbe | 64 | if (!(trace.getParent() instanceof TmfTraceFolder)) { |
65 | return false; | |
66 | } | |
67 | } else { | |
68 | return false; | |
69 | } | |
70 | } | |
71 | return true; | |
72 | } | |
73 | } | |
74 | ||
ed963ef6 | 75 | // Check if the parent of a trace element is an experiment |
1cceddbe | 76 | if (isExperimentTrace.equals(property)) { |
77 | if (receiver != null && receiver instanceof TmfTraceElement) { | |
ed963ef6 | 78 | TmfTraceElement trace = (TmfTraceElement) receiver; |
ed963ef6 FC |
79 | return trace.getParent() instanceof TmfExperimentElement; |
80 | } | |
1cceddbe | 81 | return false; |
ed963ef6 FC |
82 | } |
83 | ||
84 | return false; | |
85 | } | |
86 | ||
87 | } |