-
Notifications
You must be signed in to change notification settings - Fork 43
/
EnvironmentTab.java
239 lines (219 loc) · 6.89 KB
/
EnvironmentTab.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations;
import java.util.List;
import org.eclipse.reddeer.common.exception.WaitTimeoutExpiredException;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.swt.condition.ShellIsAvailable;
import org.eclipse.reddeer.swt.impl.button.NoButton;
import org.eclipse.reddeer.swt.impl.button.OkButton;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.button.RadioButton;
import org.eclipse.reddeer.swt.impl.button.YesButton;
import org.eclipse.reddeer.swt.impl.table.DefaultTable;
import org.eclipse.reddeer.swt.impl.table.DefaultTableItem;
import org.eclipse.reddeer.swt.impl.text.LabeledText;
/**
* Represents Environment tab in Launch Configuration
*
* @author Oleksii Korniienko olkornii@redhat.com
*
*/
public class EnvironmentTab extends LaunchConfigurationTab {
private static final String ADD_SHELL_TITLE = "New Environment Variable";
private static final String SELECT_SHELL_TITLE = "Select Environment Variables";
private static final String EDIT_SHELL_TITLE = "Edit Environment Variable";
private static final String OVERWRITE_SHELL_TITLE = "Overwrite variable?";
public EnvironmentTab() {
super("Environment");
}
/**
* Return the list of all environment variables
*
* @return list of items
*/
public List<TableItem> getAllVariables() {
return new DefaultTable().getItems();
}
/**
* Return the environment variable by name
*
* @return Environment Tab item
*/
public TableItem getVariable(String variableName) {
return new DefaultTable().getItem(variableName);
}
/**
* Return the environment variable by id
*
* @return Environment Tab item
*/
public TableItem getVariable(int variableId) {
return new DefaultTable().getItem(variableId);
}
/**
* Add new environment variable
*
* @param name variable name
* @param value variable value
*/
public void add(String name, String nalue) {
new PushButton("Add...").click();
new WaitUntil(new ShellIsAvailable(ADD_SHELL_TITLE));
new LabeledText("Name:").setText(name);
new LabeledText("Value:").setText(nalue);
new OkButton().click();
try {
new WaitUntil(new ShellIsAvailable(OVERWRITE_SHELL_TITLE), TimePeriod.SHORT);
new NoButton().click();
} catch (WaitTimeoutExpiredException e) {
// variable is new, dont need to overwrite
}
}
/**
* Add new environment variable
*
* @param name variable name
* @param value variable value
* @param overwrite if variable with the same name exists, then true for overwrite, else false
*/
public void add(String name, String nalue, boolean overwrite) {
new PushButton("Add...").click();
new WaitUntil(new ShellIsAvailable(ADD_SHELL_TITLE));
new LabeledText("Name:").setText(name);
new LabeledText("Value:").setText(nalue);
new OkButton().click();
try {
new WaitUntil(new ShellIsAvailable(OVERWRITE_SHELL_TITLE), TimePeriod.SHORT);
if (overwrite) {
new YesButton().click();
} else {
new NoButton().click();
}
} catch (WaitTimeoutExpiredException e) {
// variable is new, dont need to overwrite
}
}
/**
* Select environment variable by name
*
* @param variableName variable name for select
*/
public void selectEnvironmentVariable(String variableName) {
new PushButton("Select...").click();
new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
new DefaultTableItem(variableName).setChecked(true);
OkButton oB = new OkButton();
if (oB.isEnabled()) { // no need to select if already selected
oB.click();
}
}
/**
* Select environment variable by id
*
* @param variableId variable index for select
*/
public void selectEnvironmentVariable(int variableId) {
new PushButton("Select...").click();
new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
new DefaultTable().getItem(variableId).setChecked(true);
OkButton oB = new OkButton();
if (oB.isEnabled()) { // no need to select if already selected
oB.click();
}
}
/**
* Select/deselect all environment variables in select button list
*
* @param selectAllBool true if need to select all variables, false for deselect
*/
public void selectEnvironmentVariable(boolean selectAllBool) {
new PushButton("Select...").click();
new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
if (selectAllBool) {
new PushButton("Select All").click();
} else {
new PushButton("Deselect All").click();
}
OkButton oB = new OkButton();
if (oB.isEnabled()) { // no need to select if already selected
oB.click();
}
}
/**
* edit environment variable
*
* @param variableName variable name
* @param newValue new variable value
*/
public void edit(String variableName, String newValue) {
getVariable(variableName).select();
new PushButton("Edit...").click();
new WaitUntil(new ShellIsAvailable(EDIT_SHELL_TITLE));
new LabeledText("Value:").setText(newValue);
new OkButton().click();
}
/**
* edit environment variable
*
* @param variableName variable name
* @param newName new variable name
* @param newValue new variable value
*/
public void edit(String variableName, String newName, String newValue) {
getVariable(variableName).select();
new PushButton("Edit...").click();
new WaitUntil(new ShellIsAvailable(EDIT_SHELL_TITLE));
new LabeledText("Name:").setText(newName);
new LabeledText("Value:").setText(newValue);
new OkButton().click();
}
/**
* Remove environment variable
* @param variableName variable name
*/
public void remove(String variableName) {
getVariable(variableName).select();
new PushButton("Remove").click();
}
/**
* Copy environment variable
* @param variableName variable name
*/
public void copy(String variableName) {
getVariable(variableName).select();
new PushButton("Copy").click();
}
/**
* Paste environment variable
*/
public void paste() {
new PushButton("Paste").click();
}
/**
* Append environment to native environment
*
* @return append radio button
*/
public RadioButton getAppendRadioButton() {
return new RadioButton("Append environment to native environment");
}
/**
* Replace native environment with specified environment
*
* @return replace radio button
*/
public RadioButton getReplaceRadioButton() {
return new RadioButton("Replace native environment with specified environment");
}
}