Skip to content

Commit 8e29a05

Browse files
Grid State property is now exposed and handled by GXGridStateHandler and generated GridState SDT in GeneXusCore module is part of standard classes.
Issue 74024
1 parent f536d13 commit 8e29a05

File tree

6 files changed

+642
-0
lines changed

6 files changed

+642
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.genexus.webpanels.gridstate ;
2+
import com.genexus.*;
3+
import com.genexus.internet.*;
4+
import com.genexus.diagnostics.core.ILogger;
5+
import com.genexus.diagnostics.core.LogManager;
6+
import com.genexus.webpanels.GXWebObjectBase;
7+
import com.genexus.webpanels.WebSession;
8+
9+
public final class GXGridStateHandler {
10+
public static final ILogger logger = LogManager.getLogger(SdtGridState.class);
11+
private String gridName;
12+
private Runnable varsFromState;
13+
private Runnable varsToState;
14+
private String varsFromStateMethod;
15+
private String varsToStateMethod;
16+
private Object parent;
17+
private ModelContext context;
18+
private SdtGridState state;
19+
20+
private GXGridStateHandler(ModelContext context, String gridName, String programName) {
21+
this.context = context;
22+
this.gridName = programName + "_" + gridName + "_GridState";
23+
state = new SdtGridState(context);
24+
}
25+
26+
public GXGridStateHandler(ModelContext context, String gridName, String programName, Runnable varsFromState, Runnable varsToState) {
27+
this(context, gridName, programName);
28+
this.varsFromState = varsFromState;
29+
this.varsToState = varsToState;
30+
}
31+
32+
//Cosntructor por java <= 1.7
33+
public GXGridStateHandler(ModelContext context, String gridName, String programName, GXWebObjectBase parent, String varsFromStateMethod, String varsToStateMethod) {
34+
this(context, gridName, programName);
35+
this.varsFromStateMethod = varsFromStateMethod;
36+
this.varsToStateMethod = varsToStateMethod;
37+
this.parent = parent;
38+
}
39+
40+
private void runVarsToState() {
41+
if (this.varsToState != null)
42+
varsToState.run();
43+
else {
44+
try {
45+
parent.getClass().getMethod(varsToStateMethod).invoke(parent, (Object[]) null);
46+
} catch (Exception ex) {
47+
logger.error("Error invoking method " + varsToStateMethod + " for grid state " + gridName, ex);
48+
}
49+
}
50+
}
51+
52+
private void runVarsFromState() {
53+
if (this.varsFromState != null)
54+
varsFromState.run();
55+
else {
56+
try {
57+
parent.getClass().getMethod(varsFromStateMethod).invoke(parent, (Object[]) null);
58+
} catch (Exception ex) {
59+
logger.error("Error invoking method " + varsFromStateMethod + " for grid state " + gridName, ex);
60+
}
61+
}
62+
}
63+
64+
public String filterValues(int idx) {
65+
return state.getgxTv_SdtGridState_Inputvalues().elementAt(idx - 1).getgxTv_SdtGridState_InputValuesItem_Value();
66+
}
67+
68+
public void clearFilterValues() {
69+
state.getgxTv_SdtGridState_Inputvalues().clear();
70+
}
71+
72+
public void addFilterValue(String name, String value) {
73+
SdtGridState_InputValuesItem GridStateFilterValue = new SdtGridState_InputValuesItem(context);
74+
GridStateFilterValue.setgxTv_SdtGridState_InputValuesItem_Name(name);
75+
GridStateFilterValue.setgxTv_SdtGridState_InputValuesItem_Value(value);
76+
state.getgxTv_SdtGridState_Inputvalues().add(GridStateFilterValue, 0);
77+
}
78+
79+
public void saveGridState() {
80+
WebSession session = ((HttpContext) context.getHttpContext()).getWebSession();
81+
state.fromJSonString(session.getValue(gridName));
82+
runVarsToState();
83+
session.setValue(gridName, state.toJSonString());
84+
}
85+
86+
public void loadGridState() {
87+
HttpContext httpContext = (HttpContext) context.getHttpContext();
88+
HttpRequest httpRequest = httpContext.getHttpRequest();
89+
WebSession session = httpContext.getWebSession();
90+
if (GXutil.strcmp(httpRequest.getMethod(), "GET") == 0) {
91+
state.fromJSonString(session.getValue(gridName));
92+
runVarsFromState();
93+
}
94+
}
95+
96+
public int getFiltercount() {
97+
return state.getgxTv_SdtGridState_Inputvalues().size();
98+
}
99+
100+
public int getCurrentpage() {
101+
return state.getgxTv_SdtGridState_Currentpage();
102+
}
103+
104+
public void setCurrentpage(int value) {
105+
state.setgxTv_SdtGridState_Currentpage(value);
106+
}
107+
108+
public SdtGridState getState() {
109+
return this.state;
110+
}
111+
112+
public void setState(SdtGridState state) {
113+
this.state = state;
114+
}
115+
}
116+
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
package com.genexus.webpanels.gridstate ;
2+
import com.genexus.GXBaseCollection;
3+
import com.genexus.GXutil;
4+
import com.genexus.ModelContext;
5+
import com.genexus.xml.*;
6+
import java.util.*;
7+
import com.genexus.diagnostics.core.ILogger;
8+
import com.genexus.diagnostics.core.LogManager;
9+
10+
public final class SdtGridState extends GXXMLSerializable implements Cloneable, java.io.Serializable {
11+
public static final ILogger logger = LogManager.getLogger(SdtGridState.class);
12+
13+
public SdtGridState() {
14+
this(new ModelContext(SdtGridState.class));
15+
}
16+
17+
public SdtGridState(ModelContext context) {
18+
super(context, "SdtGridState");
19+
}
20+
21+
public SdtGridState(int remoteHandle, ModelContext context) {
22+
super(remoteHandle, context, "SdtGridState");
23+
}
24+
25+
public SdtGridState(StructSdtGridState struct) {
26+
this();
27+
setStruct(struct);
28+
}
29+
30+
private static java.util.HashMap mapper = new java.util.HashMap();
31+
32+
static {
33+
}
34+
35+
public String getJsonMap(String value) {
36+
return (String) mapper.get(value);
37+
}
38+
39+
public short readxml(com.genexus.xml.XMLReader oReader,
40+
String sName) {
41+
short GXSoapError = 1;
42+
formatError = false;
43+
sTagName = oReader.getName();
44+
if (oReader.getIsSimple() == 0) {
45+
GXSoapError = oReader.read();
46+
nOutParmCount = (short) (0);
47+
while (((GXutil.strcmp(oReader.getName(), sTagName) != 0) || (oReader.getNodeType() == 1)) && (GXSoapError > 0)) {
48+
readOk = (short) (0);
49+
if (GXutil.strcmp2(oReader.getLocalName(), "CurrentPage")) {
50+
gxTv_SdtGridState_Currentpage = (int) (getnumericvalue(oReader));
51+
readOk = (short) (1);
52+
GXSoapError = oReader.read();
53+
}
54+
if (GXutil.strcmp2(oReader.getLocalName(), "OrderedBy")) {
55+
gxTv_SdtGridState_Orderedby = (short) (getnumericvalue(oReader));
56+
if (GXSoapError > 0) {
57+
readOk = (short) (1);
58+
}
59+
GXSoapError = oReader.read();
60+
}
61+
if (GXutil.strcmp2(oReader.getLocalName(), "InputValues")) {
62+
if (gxTv_SdtGridState_Inputvalues == null) {
63+
gxTv_SdtGridState_Inputvalues = new GXBaseCollection<SdtGridState_InputValuesItem>(SdtGridState_InputValuesItem.class, "GridState.InputValuesItem", "GeneXus", remoteHandle);
64+
}
65+
if (oReader.getIsSimple() == 0) {
66+
GXSoapError = gxTv_SdtGridState_Inputvalues.readxmlcollection(oReader, "InputValues", "InputValuesItem");
67+
}
68+
if (GXSoapError > 0) {
69+
readOk = (short) (1);
70+
}
71+
if (GXutil.strcmp2(oReader.getLocalName(), "InputValues")) {
72+
GXSoapError = oReader.read();
73+
}
74+
}
75+
nOutParmCount = (short) (nOutParmCount + 1);
76+
if ((readOk == 0) || formatError) {
77+
context.globals.sSOAPErrMsg = context.globals.sSOAPErrMsg + "Error reading " + sTagName + GXutil.newLine();
78+
context.globals.sSOAPErrMsg = context.globals.sSOAPErrMsg + "Message: " + oReader.readRawXML();
79+
GXSoapError = (short) (nOutParmCount * -1);
80+
}
81+
}
82+
}
83+
return GXSoapError;
84+
}
85+
86+
public void writexml(com.genexus.xml.XMLWriter oWriter,
87+
String sName,
88+
String sNameSpace) {
89+
writexml(oWriter, sName, sNameSpace, true);
90+
}
91+
92+
public void writexml(com.genexus.xml.XMLWriter oWriter,
93+
String sName,
94+
String sNameSpace,
95+
boolean sIncludeState) {
96+
if ((GXutil.strcmp("", sName) == 0)) {
97+
sName = "GridState";
98+
}
99+
if ((GXutil.strcmp("", sNameSpace) == 0)) {
100+
sNameSpace = "GeneXus";
101+
}
102+
oWriter.writeStartElement(sName);
103+
if (GXutil.strcmp(GXutil.left(sNameSpace, 10), "[*:nosend]") != 0) {
104+
oWriter.writeAttribute("xmlns", sNameSpace);
105+
} else {
106+
sNameSpace = GXutil.right(sNameSpace, GXutil.len(sNameSpace) - 10);
107+
}
108+
oWriter.writeElement("CurrentPage", GXutil.trim(GXutil.str(gxTv_SdtGridState_Currentpage, 5, 0)));
109+
if (GXutil.strcmp(sNameSpace, "GeneXus") != 0) {
110+
oWriter.writeAttribute("xmlns", "GeneXus");
111+
}
112+
oWriter.writeElement("OrderedBy", GXutil.trim(GXutil.str(gxTv_SdtGridState_Orderedby, 4, 0)));
113+
if (GXutil.strcmp(sNameSpace, "GeneXus") != 0) {
114+
oWriter.writeAttribute("xmlns", "GeneXus");
115+
}
116+
if (gxTv_SdtGridState_Inputvalues != null) {
117+
String sNameSpace1;
118+
if (GXutil.strcmp(sNameSpace, "GeneXus") == 0) {
119+
sNameSpace1 = "[*:nosend]" + "GeneXus";
120+
} else {
121+
sNameSpace1 = "GeneXus";
122+
}
123+
gxTv_SdtGridState_Inputvalues.writexmlcollection(oWriter, "InputValues", sNameSpace1, "InputValuesItem", sNameSpace1);
124+
}
125+
oWriter.writeEndElement();
126+
}
127+
128+
public long getnumericvalue(com.genexus.xml.XMLReader oReader) {
129+
if (GXutil.notNumeric(oReader.getValue())) {
130+
formatError = true;
131+
}
132+
return GXutil.lval(oReader.getValue());
133+
}
134+
135+
public void tojson() {
136+
tojson(true);
137+
}
138+
139+
public void tojson(boolean includeState) {
140+
tojson(includeState, true);
141+
}
142+
143+
public void tojson(boolean includeState,
144+
boolean includeNonInitialized) {
145+
AddObjectProperty("CurrentPage", gxTv_SdtGridState_Currentpage, false, false);
146+
AddObjectProperty("OrderedBy", gxTv_SdtGridState_Orderedby, false, false);
147+
if (gxTv_SdtGridState_Inputvalues != null) {
148+
AddObjectProperty("InputValues", gxTv_SdtGridState_Inputvalues, false, false);
149+
}
150+
}
151+
152+
public int getgxTv_SdtGridState_Currentpage() {
153+
return gxTv_SdtGridState_Currentpage;
154+
}
155+
156+
public void setgxTv_SdtGridState_Currentpage(int value) {
157+
gxTv_SdtGridState_Currentpage = value;
158+
}
159+
160+
public short getgxTv_SdtGridState_Orderedby() {
161+
return gxTv_SdtGridState_Orderedby;
162+
}
163+
164+
public void setgxTv_SdtGridState_Orderedby(short value) {
165+
gxTv_SdtGridState_Orderedby = value;
166+
}
167+
168+
public GXBaseCollection<SdtGridState_InputValuesItem> getgxTv_SdtGridState_Inputvalues() {
169+
if (gxTv_SdtGridState_Inputvalues == null) {
170+
gxTv_SdtGridState_Inputvalues = new GXBaseCollection<SdtGridState_InputValuesItem>(SdtGridState_InputValuesItem.class, "GridState.InputValuesItem", "GeneXus", remoteHandle);
171+
}
172+
gxTv_SdtGridState_Inputvalues_N = (byte) (0);
173+
return gxTv_SdtGridState_Inputvalues;
174+
}
175+
176+
public void setgxTv_SdtGridState_Inputvalues(GXBaseCollection<SdtGridState_InputValuesItem> value) {
177+
gxTv_SdtGridState_Inputvalues_N = (byte) (0);
178+
gxTv_SdtGridState_Inputvalues = value;
179+
}
180+
181+
public void setgxTv_SdtGridState_Inputvalues_SetNull() {
182+
gxTv_SdtGridState_Inputvalues_N = (byte) (1);
183+
gxTv_SdtGridState_Inputvalues = null;
184+
}
185+
186+
public boolean getgxTv_SdtGridState_Inputvalues_IsNull() {
187+
return (gxTv_SdtGridState_Inputvalues == null);
188+
}
189+
190+
public byte getgxTv_SdtGridState_Inputvalues_N() {
191+
return gxTv_SdtGridState_Inputvalues_N;
192+
}
193+
194+
public void initialize(int remoteHandle) {
195+
initialize();
196+
}
197+
198+
public void initialize() {
199+
gxTv_SdtGridState_Inputvalues_N = (byte) (1);
200+
sTagName = "";
201+
}
202+
203+
public SdtGridState Clone() {
204+
return (SdtGridState) (clone());
205+
}
206+
207+
public void setStruct(StructSdtGridState struct) {
208+
setgxTv_SdtGridState_Currentpage(struct.getCurrentpage());
209+
setgxTv_SdtGridState_Orderedby(struct.getOrderedby());
210+
GXBaseCollection<SdtGridState_InputValuesItem> gxTv_SdtGridState_Inputvalues_aux = new GXBaseCollection<SdtGridState_InputValuesItem>(SdtGridState_InputValuesItem.class, "GridState.InputValuesItem", "GeneXus", remoteHandle);
211+
Vector<StructSdtGridState_InputValuesItem> gxTv_SdtGridState_Inputvalues_aux1 = struct.getInputvalues();
212+
if (gxTv_SdtGridState_Inputvalues_aux1 != null) {
213+
for (int i = 0; i < gxTv_SdtGridState_Inputvalues_aux1.size(); i++) {
214+
gxTv_SdtGridState_Inputvalues_aux.add(new SdtGridState_InputValuesItem(gxTv_SdtGridState_Inputvalues_aux1.elementAt(i)));
215+
}
216+
}
217+
setgxTv_SdtGridState_Inputvalues(gxTv_SdtGridState_Inputvalues_aux);
218+
}
219+
220+
public StructSdtGridState getStruct() {
221+
StructSdtGridState struct = new StructSdtGridState();
222+
struct.setCurrentpage(getgxTv_SdtGridState_Currentpage());
223+
struct.setOrderedby(getgxTv_SdtGridState_Orderedby());
224+
struct.setInputvalues(getgxTv_SdtGridState_Inputvalues().getStruct());
225+
return struct;
226+
}
227+
228+
protected byte gxTv_SdtGridState_Inputvalues_N;
229+
protected short gxTv_SdtGridState_Orderedby;
230+
protected short readOk;
231+
protected short nOutParmCount;
232+
protected int gxTv_SdtGridState_Currentpage;
233+
protected String sTagName;
234+
protected boolean formatError;
235+
protected GXBaseCollection<SdtGridState_InputValuesItem> gxTv_SdtGridState_Inputvalues_aux;
236+
protected GXBaseCollection<SdtGridState_InputValuesItem> gxTv_SdtGridState_Inputvalues = null;
237+
}
238+

0 commit comments

Comments
 (0)