Skip to content

Commit e803e46

Browse files
add ItemNode class for suites/tests in a tree
1 parent a972c50 commit e803e46

File tree

1 file changed

+157
-0
lines changed
  • sqldev/src/main/java/org/utplsql/sqldev/model/runner

1 file changed

+157
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright 2021 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev.model.runner;
17+
18+
import java.util.Enumeration;
19+
import java.util.HashSet;
20+
import java.util.Set;
21+
22+
import javax.swing.Icon;
23+
import javax.swing.tree.DefaultMutableTreeNode;
24+
25+
import org.utplsql.sqldev.resources.UtplsqlResources;
26+
27+
public class ItemNode extends DefaultMutableTreeNode {
28+
29+
private static final long serialVersionUID = -4053143673822661743L;
30+
31+
public ItemNode(Item userObject) {
32+
super(userObject, userObject instanceof Suite);
33+
}
34+
35+
public String getId() {
36+
return ((Item) getUserObject()).getId();
37+
}
38+
39+
public String getName() {
40+
return ((Item) getUserObject()).getName();
41+
}
42+
43+
public String getDescription() {
44+
return ((Item) getUserObject()).getDescription();
45+
}
46+
47+
public Double getExecutionTime() {
48+
return ((Item) getUserObject()).getExecutionTime();
49+
}
50+
51+
public Set<String> getTestPackages() {
52+
HashSet<String> testPackages = new HashSet<>();
53+
Enumeration<?> orderedNodes = preorderEnumeration();
54+
while (orderedNodes.hasMoreElements()) {
55+
ItemNode node = (ItemNode) orderedNodes.nextElement();
56+
if (node.getUserObject() instanceof Test) {
57+
Test test = (Test) node.getUserObject();
58+
testPackages.add(test.getOwnerName() + "." + test.getObjectName());
59+
}
60+
}
61+
return testPackages;
62+
}
63+
64+
public Set<String> getOwners() {
65+
HashSet<String> owners = new HashSet<>();
66+
Enumeration<?> children = children();
67+
while (children.hasMoreElements()) {
68+
ItemNode child = (ItemNode) children.nextElement();
69+
owners.add(child.getOwnerName());
70+
}
71+
return owners;
72+
}
73+
74+
public String getOwnerName() {
75+
String ownerName = null;
76+
Enumeration<?> orderedNodes = preorderEnumeration();
77+
while (orderedNodes.hasMoreElements()) {
78+
ItemNode node = (ItemNode) orderedNodes.nextElement();
79+
if (node.getUserObject() instanceof Test) {
80+
Test test = (Test) node.getUserObject();
81+
if (ownerName == null) {
82+
ownerName = test.getOwnerName();
83+
} else if (!ownerName.equals(test.getOwnerName())) {
84+
ownerName = "***";
85+
break;
86+
}
87+
}
88+
}
89+
return ownerName;
90+
}
91+
92+
public String getPackageName() {
93+
String packageName = null;
94+
Enumeration<?> orderedNodes = preorderEnumeration();
95+
while (orderedNodes.hasMoreElements()) {
96+
ItemNode node = (ItemNode) orderedNodes.nextElement();
97+
if (node.getUserObject() instanceof Test) {
98+
Test test = (Test) node.getUserObject();
99+
if (packageName == null) {
100+
packageName = test.getObjectName();
101+
} else if (!packageName.equals(test.getObjectName())) {
102+
packageName = "***";
103+
break;
104+
}
105+
}
106+
}
107+
return packageName;
108+
}
109+
110+
public String getProcedureName() {
111+
String procedureName = null;
112+
Enumeration<?> orderedNodes = preorderEnumeration();
113+
while (orderedNodes.hasMoreElements()) {
114+
ItemNode node = (ItemNode) orderedNodes.nextElement();
115+
if (node.getUserObject() instanceof Test) {
116+
Test test = (Test) node.getUserObject();
117+
if (procedureName == null) {
118+
procedureName = test.getProcedureName();
119+
} else if (!procedureName.equals(test.getProcedureName())) {
120+
procedureName = "***";
121+
break;
122+
}
123+
}
124+
}
125+
return procedureName;
126+
}
127+
128+
public Icon getStatusIcon() {
129+
Item item = (Item) getUserObject();
130+
Icon icon = item.getStatusIcon();
131+
if (icon == null) {
132+
if (item.getId() != null) {
133+
if (item instanceof Test) {
134+
icon = UtplsqlResources.getIcon("PROCEDURE_ICON");
135+
} else if (item.getId().contains("context_#")) {
136+
icon = UtplsqlResources.getIcon("PROCEDURE_FOLDER_ICON");
137+
} else {
138+
if (item.getName().equals(getPackageName())) {
139+
icon = UtplsqlResources.getIcon("PACKAGE_ICON");
140+
} else {
141+
icon = UtplsqlResources.getIcon("PACKAGE_FOLDER_ICON");
142+
}
143+
}
144+
}
145+
}
146+
return icon;
147+
}
148+
149+
public Icon getWarningIcon() {
150+
return ((Item) getUserObject()).getWarningIcon();
151+
}
152+
153+
public Icon getInfoIcon() {
154+
return ((Item) getUserObject()).getInfoIcon();
155+
}
156+
157+
}

0 commit comments

Comments
 (0)