Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fec820311de555aa2c9cdc9261af5aa920f7a759 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.delegates;

import java.util.List;
import java.util.Map.Entry;

import org.eclipse.core.runtime.Assert;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.persistence.utils.DataHelper;
import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
import org.eclipse.tcf.te.tcf.locator.utils.CommonUtils;
import org.eclipse.tcf.te.tcf.locator.utils.SimulatorUtils;
import org.eclipse.tcf.te.ui.interfaces.services.INodePropertiesTableUIDelegate;
import org.eclipse.tcf.te.ui.tables.properties.NodePropertiesTableTableNode;

/**
 * Node properties table filter UI delegate implementation.
 */
public class NodePropertiesTableUIDelegate implements INodePropertiesTableUIDelegate {

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.interfaces.services.INodePropertiesTableUIDelegate#isFiltered(java.lang.Object, java.lang.String, java.lang.Object)
	 */
	@Override
	public boolean isFiltered(Object context, String name, Object value) {
		Assert.isNotNull(context);
		Assert.isNotNull(name);

		if (context instanceof IPeerNode) {
			if ((name.equals(IPeerProperties.PROP_SIM_TYPE) || name.startsWith(IPeerProperties.PROP_SIM_PROPERTIES))) {
				return !SimulatorUtils.isSimulatorEnabled((IPeerNode)context);
			}
			if (name.equals(IPeerProperties.PROP_PING_TIMEOUT)) {
				return SimulatorUtils.isSimulatorEnabled((IPeerNode)context);
			}
			if (name.startsWith(IPeerProperties.PROP_MODE_PROPERTIES)) {
				return !IPeerProperties.MODE_STOP.equals(CommonUtils.getMode((IPeerNode)context));
			}
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.interfaces.services.INodePropertiesTableUIDelegate#expandNodesAfterSort(java.lang.Object, java.util.List)
	 */
	@Override
	public void expandNodesAfterSort(Object context, List<NodePropertiesTableTableNode> sortedNodes) {
		String[] keysToExpand = new String[]{IPeerProperties.PROP_SIM_PROPERTIES, IPeerProperties.PROP_MODE_PROPERTIES};
		for (String key : keysToExpand) {
			int i = sortedNodes.indexOf(new NodePropertiesTableTableNode(key, "")); //$NON-NLS-1$
			if (i >= 0) {
				NodePropertiesTableTableNode node = sortedNodes.get(i);
				IPropertiesContainer data = DataHelper.decodePropertiesContainer(node.value);
				if (data != null && !data.isEmpty()) {
					sortedNodes.remove(i);
					sortedNodes.add(i++, new NodePropertiesTableTableNode(key, "")); //$NON-NLS-1$
					for (Entry<String,Object> entry : data.getProperties().entrySet()) {
						if (entry.getValue() != null) {
							if (!isFiltered(context, entry.getKey(), entry.getValue())) {
								sortedNodes.add(i++, new NodePropertiesTableTableNode("     " + entry.getKey(), entry.getValue().toString())); //$NON-NLS-1$
							}
						}
					}
				}
			}
		}
	}
}

Back to the top