svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / searchpanel / DefaultSearchParameters.java @ 44834
History | View | Annotate | Download (4.99 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
7 |
|
8 |
import java.io.ByteArrayOutputStream; |
9 |
import java.util.ArrayList; |
10 |
import java.util.HashMap; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
import javax.json.Json; |
14 |
import javax.json.JsonObject; |
15 |
import javax.json.JsonObjectBuilder; |
16 |
import javax.json.JsonWriter; |
17 |
import org.gvsig.expressionevaluator.Expression; |
18 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
19 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
20 |
import org.gvsig.tools.ToolsLocator; |
21 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
22 |
import org.gvsig.tools.dynobject.DynStruct; |
23 |
import org.gvsig.tools.persistence.PersistenceManager; |
24 |
import org.gvsig.tools.persistence.PersistentState; |
25 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
26 |
|
27 |
/**
|
28 |
*
|
29 |
* @author jjdelcerro
|
30 |
*/
|
31 |
public class DefaultSearchParameters implements SearchParameters, Cloneable { |
32 |
|
33 |
private List<String> resultColumnNames; |
34 |
private FeatureQuery query;
|
35 |
public String name; |
36 |
private Map<String, JsonObject> values; |
37 |
|
38 |
public DefaultSearchParameters() {
|
39 |
this.resultColumnNames = new ArrayList<>(); |
40 |
this.query = null; |
41 |
this.values = new HashMap<>(); |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public List<String> getResultColumnNames() { |
46 |
return this.resultColumnNames; |
47 |
} |
48 |
|
49 |
public List<String> getGroupByColumns() { |
50 |
return this.query.getGroupByColumns(); |
51 |
} |
52 |
|
53 |
public Map<String, String> getAggregateFunctions() { |
54 |
return this.query.getAggregateFunctions(); |
55 |
} |
56 |
|
57 |
public void setQuery(FeatureQuery query) { |
58 |
this.query = query;
|
59 |
} |
60 |
|
61 |
public void setFilter(Expression exp) { |
62 |
this.query.setFilter(exp);
|
63 |
} |
64 |
|
65 |
public FeatureQuery getQuery() {
|
66 |
return this.query; |
67 |
} |
68 |
|
69 |
void setResultColumnNames(List<String> selectedNames) { |
70 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public Map<String, JsonObject> getValues() { |
75 |
return this.values; |
76 |
} |
77 |
|
78 |
public static void registerPersistence() { |
79 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
80 |
if (manager.getDefinition("SearchParameters") == null) { |
81 |
DynStruct definition = manager.addDefinition(DefaultSearchParameters.class, |
82 |
"DefaultSearchParameters", "DefaultSearchParameters persistence definition", null, null); |
83 |
definition.addDynFieldList("resultColumnNames").setClassOfItems(String.class); |
84 |
definition.addDynFieldMap("values").setClassOfItems(JsonObject.class);
|
85 |
definition.addDynFieldObject("query").setClassOfValue(FeatureQuery.class).setMandatory(false); |
86 |
definition.addDynFieldString("name").setClassOfValue(String.class); |
87 |
} |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public void saveToState(PersistentState state) throws PersistenceException { |
92 |
state.set("resultColumnNames", this.resultColumnNames); |
93 |
// state.set("values", this.values);
|
94 |
state.set("query", this.query); |
95 |
state.set("name", this.name); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void loadFromState(PersistentState state) throws PersistenceException { |
100 |
this.resultColumnNames = state.getList("resultColumnNames"); |
101 |
// this.values = (JsonObject) state.get("searchJsonValues");
|
102 |
this.values = new HashMap<>(); |
103 |
this.query = (FeatureQuery) state.get("query"); |
104 |
this.name = state.getString("name"); |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public String toString() { |
109 |
if (this.query != null && this.query.getExpressionFilter() != null) { |
110 |
return this.query.getExpressionFilter().getPhrase(); |
111 |
} else {
|
112 |
return this.getName(); |
113 |
|
114 |
} |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public Object clone() throws CloneNotSupportedException { |
119 |
DefaultSearchParameters clone = (DefaultSearchParameters) super.clone();
|
120 |
clone.query = this.query.getCopy();
|
121 |
clone.resultColumnNames = new ArrayList(this.resultColumnNames); |
122 |
HashMap<String, JsonObject> cloneValues = new HashMap<String, JsonObject>(this.values); |
123 |
clone.values = cloneValues; |
124 |
return clone;
|
125 |
} |
126 |
public DefaultSearchParameters getCopy() {
|
127 |
try {
|
128 |
return (DefaultSearchParameters) this.clone(); |
129 |
} catch (CloneNotSupportedException ex) { |
130 |
return null; |
131 |
} |
132 |
} |
133 |
|
134 |
public JsonObjectBuilder getValuesBuilder() {
|
135 |
return Json.createObjectBuilder();
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void copyFrom(SearchParameters params) { |
140 |
this.resultColumnNames = params.getResultColumnNames();
|
141 |
this.query = params.getQuery().getCopy();
|
142 |
this.name = params.getName();
|
143 |
this.values = params.getValues();
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public String getName() { |
148 |
return this.name; |
149 |
} |
150 |
|
151 |
@Override
|
152 |
public void setName(String name) { |
153 |
this.name= name;
|
154 |
} |
155 |
} |