-
Notifications
You must be signed in to change notification settings - Fork 188
/
SelectableBean.java
149 lines (127 loc) · 4.18 KB
/
SelectableBean.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
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.component.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.data.column.InlineMenuable;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
/**
* @author lazyman
*/
public class SelectableBean<T extends Serializable> extends Selectable<T> implements InlineMenuable, DebugDumpable {
private static final long serialVersionUID = 1L;
public static final String F_VALUE = "value";
private static final Trace LOGGER = TraceManager.getTrace(SelectableBean.class);
/**
* Value of object that this bean represents. It may be null in case that non-success result is set.
*/
private T value;
/**
* Result of object retrieval (or attempt of object retrieval). It case that it is not error the result is optional.
*/
private OperationResult result;
private List<InlineMenuItem> menuItems;
public SelectableBean() {
}
public SelectableBean(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public OperationResult getResult() {
return result;
}
public void setResult(OperationResult result) {
this.result = result;
}
public void setResult(OperationResultType resultType) throws SchemaException {
this.result = OperationResult.createOperationResult(resultType);
}
public List<InlineMenuItem> getMenuItems() {
if (menuItems == null) {
menuItems = new ArrayList<InlineMenuItem>();
}
return menuItems;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SelectableBean other = (SelectableBean) obj;
if (result == null) {
if (other.result != null) {
return false;
}
} else if (!result.equals(other.result)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
// In case both values are objects then compare only OIDs.
// that should be enough. Comparing complete objects may be slow
// (e.g. if the objects have many assignments) and Wicket
// invokes compare a lot ...
} else if (!MiscSchemaUtil.quickEquals(value, other.value)) {
return false;
}
return true;
}
@Override
public String debugDump() {
return debugDump(0);
}
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.indentDebugDump(sb, indent);
sb.append("SelectableBean\n");
DebugUtil.debugDumpWithLabelLn(sb, "value", value==null?null:value.toString(), indent+1);
DebugUtil.debugDumpWithLabelLn(sb, "result", result==null?null:result.toString(), indent+1);
DebugUtil.debugDumpWithLabel(sb, "menuItems", menuItems, indent+1);
return sb.toString();
}
}