1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
15 import java
.util
.Iterator
;
17 import org
.eclipse
.core
.expressions
.PropertyTester
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
24 * <b><u>TracePropertyTester</u></b>
27 public class TracePropertyTester
extends PropertyTester
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private static String isInTraceFolder
= "isInTraceFolder"; //$NON-NLS-1$
34 private static String isExperimentTrace
= "isExperimentTrace"; //$NON-NLS-1$
35 private static String hasSupplementaryFiles
= "hasSupplementaryFiles"; //$NON-NLS-1$
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
44 public TracePropertyTester() {
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
55 public boolean test(Object receiver
, String property
, Object
[] args
, Object expectedValue
) {
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
) {
64 TmfTraceElement trace
= (TmfTraceElement
) item
;
65 if (!(trace
.getParent() instanceof TmfTraceFolder
)) {
76 // Check if the parent of a trace element is an experiment
77 if (isExperimentTrace
.equals(property
)) {
78 if (receiver
!= null && receiver
instanceof TmfTraceElement
) {
79 TmfTraceElement trace
= (TmfTraceElement
) receiver
;
80 return trace
.getParent() instanceof TmfExperimentElement
;
85 // Check if traces has supplementary files
86 if (hasSupplementaryFiles
.equals(property
)) {
87 if (receiver
== null) {
91 if (receiver
instanceof TmfTraceElement
) {
92 TmfTraceElement trace
= (TmfTraceElement
) receiver
;
93 return trace
.hasSupplementaryResources();
94 } else if (receiver
instanceof TmfExperimentElement
) {
95 TmfExperimentElement trace
= (TmfExperimentElement
) receiver
;
96 boolean hasHistory
= false;
97 for (TmfTraceElement aTrace
: trace
.getTraces()) {
98 hasHistory
|= aTrace
.hasSupplementaryResources();