gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources-plugin / scripting / lib / gvsig2_1_0 / table.py @ 447
History | View | Annotate | Download (5.7 KB)
1 |
|
---|---|
2 |
|
3 |
__docformat__ = "restructuredtext en"
|
4 |
|
5 |
|
6 |
from org.gvsig.app.project.documents.table import TableDocument as JTableDocument |
7 |
|
8 |
|
9 |
class DataTable(object): |
10 |
"""
|
11 |
This is the base class to TableDocument_ and LayerVectorial_
|
12 |
|
13 |
.. _TableDocument : FIXME_URL
|
14 |
.. _LayerVectorial : FIXME_URL
|
15 |
"""
|
16 |
|
17 |
@staticmethod
|
18 |
def features(self, filter = None, sortby="", asc=True): |
19 |
"""
|
20 |
Return a set of features
|
21 |
|
22 |
Opcionalmente puede especificarse una expresion de filtrado,
|
23 |
los campos por los que se quiere que se ordene y si este
|
24 |
orden es ascendente o descendente.
|
25 |
|
26 |
:paramters:
|
27 |
filter : string
|
28 |
es una expresion que deben cumplir los registros de la tabla a devolver.
|
29 |
sortby : string
|
30 |
es una lista de nombres de campos de la tabla por los que queremos que
|
31 |
se ordene separados por comas.
|
32 |
asc : boolean
|
33 |
True para ordenar de forma ascendente, que es el valor por defecto,
|
34 |
False para ordenar descendentemete.
|
35 |
|
36 |
:return:
|
37 |
the set of features.
|
38 |
:returntype:
|
39 |
FeatureSet_
|
40 |
.. _FeatureSet : FIXME_URL
|
41 |
"""
|
42 |
return self.getFeatureStore().features(filter, sortby, asc) |
43 |
|
44 |
@staticmethod
|
45 |
def __iter__(self): |
46 |
"""
|
47 |
Return an iterator over all features of the table.
|
48 |
|
49 |
:return:
|
50 |
the set of features.
|
51 |
:returntype:
|
52 |
FeatureSet_
|
53 |
.. _FeatureSet : FIXME_URL
|
54 |
"""
|
55 |
return self.getFeatureStore().features() |
56 |
|
57 |
@staticmethod
|
58 |
def __len__(self): |
59 |
"""
|
60 |
Return the number of elements of the table
|
61 |
|
62 |
:return:
|
63 |
the number of elements
|
64 |
:returntype:
|
65 |
int
|
66 |
"""
|
67 |
return len(self.getFeatureStore()) |
68 |
|
69 |
@staticmethod
|
70 |
def edit(self): |
71 |
"""
|
72 |
Set the data table in edition mode
|
73 |
"""
|
74 |
self.getFeatureStore().edit()
|
75 |
|
76 |
@staticmethod
|
77 |
def append(self, *valuesList, **values): |
78 |
"""
|
79 |
Creates a new feature.
|
80 |
|
81 |
Creates a new feature from given values and insert it in the feature set.
|
82 |
|
83 |
This method can receibe as parameters a list of pair name=value where name
|
84 |
is the name of an attribute of the feature and value the value of this attribute.
|
85 |
|
86 |
Alternativement can receibe a list of values that can be asigned to the attributes
|
87 |
of the feature in sequential order.
|
88 |
|
89 |
The changes are delayed until the method commit is invoked.
|
90 |
If calling the method abort the changes arent discarded.
|
91 |
|
92 |
"""
|
93 |
self.getFeatureStore().append(*valuesList, **values)
|
94 |
|
95 |
@staticmethod
|
96 |
def updateSchema(self, schema): |
97 |
"""
|
98 |
Updates the schema of the DataTable.
|
99 |
"""
|
100 |
self.getFeatureStore().update(schema)
|
101 |
|
102 |
@staticmethod
|
103 |
def update(self, feature): |
104 |
"""
|
105 |
Updates the feature in the DataTable.
|
106 |
|
107 |
If the feature exists in the DataTable this is updated with the
|
108 |
values of the feature pased as parameter.
|
109 |
|
110 |
The feature changes are delayed until the method commit is invoked.
|
111 |
If calling the method abort the changes arent discarded.
|
112 |
|
113 |
:Parameters:
|
114 |
feature : EditableFeature_
|
115 |
the feature to be updated.
|
116 |
"""
|
117 |
self.getFeatureStore().update(feature)
|
118 |
|
119 |
@staticmethod
|
120 |
def getSchema(self): |
121 |
"""
|
122 |
Returns schema of the DataTable.
|
123 |
|
124 |
The schema of the DataTable constains information about the columns of
|
125 |
the DataTable, name, type, mandatory...
|
126 |
"""
|
127 |
return self.getFeatureStore().getSchema() |
128 |
|
129 |
@staticmethod
|
130 |
def commit(self): |
131 |
"""
|
132 |
Saves all changes pending in the DataTable.
|
133 |
"""
|
134 |
self.getFeatureStore().commit()
|
135 |
|
136 |
@staticmethod
|
137 |
def abort(self): |
138 |
"""
|
139 |
Discard all pending changes in the DataTable.
|
140 |
"""
|
141 |
self.getFeatureStore().abort()
|
142 |
|
143 |
@staticmethod
|
144 |
def getSelection(self): |
145 |
"""
|
146 |
Returns features selected set
|
147 |
"""
|
148 |
return self.getFeatureStore().getFeatureSelection() |
149 |
|
150 |
@staticmethod
|
151 |
def select(self, selection): |
152 |
"""
|
153 |
Inserts features in the features selection set
|
154 |
"""
|
155 |
self.getSelection().select(selection)
|
156 |
|
157 |
@staticmethod
|
158 |
def deselect(self, selection): |
159 |
"""
|
160 |
Remove features in the features selection set
|
161 |
"""
|
162 |
self.getSelection().deselect(selection)
|
163 |
|
164 |
@staticmethod
|
165 |
def isSelected(feature): |
166 |
"""Returns True if given feature is selected"""
|
167 |
self.getSelection().isSelect(feature)
|
168 |
|
169 |
|
170 |
class TableDocument(JTableDocument, DataTable): |
171 |
"""
|
172 |
Represents gvSIG view document
|
173 |
|
174 |
Extends the `java TableDocument`_
|
175 |
|
176 |
.. _`java TableDocument` : FIXME_URL
|
177 |
"""
|
178 |
|
179 |
@staticmethod
|
180 |
def getFeatureStore(self): |
181 |
"""
|
182 |
Returns the FeatureStore_ associted to this TableDocument.
|
183 |
|
184 |
:return:
|
185 |
The FeatureStore_ associated to the TableDocument
|
186 |
:returntype:
|
187 |
FeatureStore_
|
188 |
.. _FeatureStore : FIXME_URL
|
189 |
"""
|
190 |
return self.getStore() |
191 |
|
192 |
|
193 |
@staticmethod
|
194 |
def __call__(self): |
195 |
"""
|
196 |
Return the java object represented by this object.
|
197 |
|
198 |
This method is for compatibility with scripting API of gvSIG 2.0
|
199 |
|
200 |
:ReturnType:
|
201 |
TableDocument
|
202 |
:deprecated:
|
203 |
With gvSIG 2.1 the call this method isn't necesary
|
204 |
|
205 |
"""
|
206 |
return self |
207 |
|
208 |
|
209 |
|
210 |
#
|
211 |
# Inject new methods in the class JTableDocument
|
212 |
#
|
213 |
JTableDocument.getFeatureStore = TableDocument.getFeatureStore |
214 |
JTableDocument.__call__ = DataTable.__iter__ |
215 |
JTableDocument.__len__ = DataTable.__len__ |
216 |
JTableDocument.__call__ = TableDocument.__call__ |
217 |
JTableDocument.features = DataTable.features |
218 |
JTableDocument.edit = DataTable.edit |
219 |
JTableDocument.append = DataTable.append |
220 |
JTableDocument.updateSchema = DataTable.updateSchema |
221 |
JTableDocument.update = DataTable.update |
222 |
JTableDocument.getSchema = DataTable.getSchema |
223 |
JTableDocument.commit = DataTable.commit |
224 |
JTableDocument.abort = DataTable.abort |
225 |
JTableDocument.getSelection = DataTable.getSelection |
226 |
JTableDocument.select = DataTable.select |
227 |
JTableDocument.deselect = DataTable.deselect |
228 |
JTableDocument.isSelected = DataTable.isSelected |
229 |
|