/
PropertySheet.java
144 lines (125 loc) · 3.83 KB
/
PropertySheet.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.eclipse.ui.views.properties;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.reddeer.common.condition.AbstractWaitCondition;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.swt.api.TreeItem;
import org.eclipse.reddeer.swt.impl.toolbar.DefaultToolItem;
import org.eclipse.reddeer.swt.impl.tree.DefaultTree;
import org.eclipse.reddeer.swt.impl.tree.DefaultTreeItem;
import org.eclipse.reddeer.workbench.impl.view.WorkbenchView;
/**
* Manages Properties View
*
* Use this class if you change properties of many elements
* and you need to be sure, that properties tabs of focused
* element are rendered yet.
*
* If rendered tabs doesn't change for 10 seconds,
* class assume that is still focused the same element and it is ok.
*
* @author Vlado Pakan, jomarko@redhat.com
*
*/
public class PropertySheet extends WorkbenchView{
/**
* Constructs the view with "Properties".
*/
public PropertySheet() {
super("Properties");
}
/**
* Returns list of Properties.
*
* @return list of Properties
*/
public List<PropertySheetProperty> getProperties(){
activate();
LinkedList<PropertySheetProperty> properties = new LinkedList<PropertySheetProperty>();
for (TreeItem treeItem : new DefaultTree(cTabItem).getAllItems()){
properties.add(new PropertySheetProperty(treeItem));
}
return properties;
}
/**
* Returns ViewProperty with propertyName.
*
* @param propertyNamePath the property name path
* @return ViewProperty with propertyName
*/
public PropertySheetProperty getProperty(String... propertyNamePath){
activate();
return new PropertySheetProperty(new DefaultTreeItem(new DefaultTree(cTabItem), propertyNamePath));
}
/**
* Sets whether to show categories.
*
* @param toggle Indicates whether to show categories
*/
public void toggleShowCategories(boolean toggle){
activate();
new DefaultToolItem(cTabItem.getFolder(), "Show Categories")
.toggle(toggle);
}
/**
* Sets whether to show advanced properties.
*
* @param toggle Indicates whether to show advanced properties
*/
public void toggleShowAdvancedProperties(boolean toggle){
activate();
new DefaultToolItem(cTabItem.getFolder(), "Show Advanced Properties")
.toggle(toggle);
}
/**
* Selects tab with a given label.
*
* @param label Label
*/
public void selectTab(String label) {
activate();
List<String> old = new ArrayList<String>();
try{
old = new TabbedPropertyList(cTabItem, 0).getTabs();
}catch(Exception ex) {
//probably not rendered yet
}
if (!old.contains(label)) {
new WaitUntil(new AnotherTabsRendered(old), TimePeriod.DEFAULT, false);
}
new TabbedPropertyList(cTabItem, 0).selectTab(label);
}
private class AnotherTabsRendered extends AbstractWaitCondition {
private List<String> old;
public AnotherTabsRendered(List<String> old) {
this.old = old;
}
@Override
public boolean test() {
List<String> actual = new ArrayList<String>();
try{
actual = new TabbedPropertyList(cTabItem, 0).getTabs();
}catch(Exception ex) {
//probably not rendered yet
}
return !actual.equals(old);
}
@Override
public String description() {
return "Wait for tabs of focused element to be rendered";
}
}
}