-
Notifications
You must be signed in to change notification settings - Fork 43
/
CanImplement.java
90 lines (80 loc) · 3.07 KB
/
CanImplement.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
/*******************************************************************************
* Copyright (c) 2019 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.jdt.ui.wizards;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.reddeer.common.exception.RedDeerException;
import org.eclipse.reddeer.common.matcher.RegexMatcher;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.common.wait.WaitWhile;
import org.eclipse.reddeer.core.matcher.WithTextMatcher;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.swt.condition.TableHasRows;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.table.DefaultTable;
import org.eclipse.reddeer.swt.impl.text.DefaultText;
import org.eclipse.reddeer.workbench.core.condition.JobIsRunning;
/**
* Interface that brings default behavior for Class/Interface/Enum wizards that can 'implement'.
* @author odockal
*
*/
public interface CanImplement {
/**
* Add extended interface.
*
* @param interfaceName String with name of interface to add
*/
public default void addExtendedInterface(String interfaceName) {
new PushButton("Add...").click();
new DefaultShell(new WithTextMatcher(new RegexMatcher("[Extended|Implemented].*Interfaces Selection")));
new DefaultText(0).setText(interfaceName);
new WaitUntil(new JobIsRunning(), TimePeriod.MEDIUM, false);
new WaitWhile(new JobIsRunning(), TimePeriod.MEDIUM, false);
new WaitUntil(new TableHasRows(new DefaultTable(0)), TimePeriod.DEFAULT, false);
switch (new DefaultTable(0).getItems().size()) {
case 0:
throw new RedDeerException("No item was found for given interface name '" + interfaceName + "'.");
case 1:
new PushButton("OK").click();
break;
default:
throw new RedDeerException("More than 1 item was found for given interface name '" + interfaceName + "'.");
}
}
/**
* Remove extended interface.
*
* @param interfaceName String with name of interface to remove
*/
public default void removeExtendedInterface(String interfaceName) {
DefaultTable table = new DefaultTable(0);
table.getItem(interfaceName).select();
new PushButton("Remove").click();
}
/**
* Returns list of names of extended interfaces.
*
* @return List of extended interfaces
*/
public default ArrayList<String> getExtendedInterfaces() {
DefaultTable table = new DefaultTable(0);
List<TableItem> tableItems = table.getItems();
ArrayList<String> tableItemNames = new ArrayList<String>();
for (TableItem item : tableItems) {
tableItemNames.add(item.getText());
}
return tableItemNames;
}
}