Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.core / src / main / java / es / unex / sextante / parameters / ParameterTableFilter.java @ 315

History | View | Annotate | Download (6.74 KB)

1
package es.unex.sextante.parameters;
2

    
3
import java.awt.geom.Point2D;
4
import java.io.IOException;
5
import java.util.ArrayList;
6

    
7
import org.kxml2.io.KXmlParser;
8
import org.kxml2.io.KXmlSerializer;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

    
12
import es.unex.sextante.additionalInfo.AdditionalInfo;
13
import es.unex.sextante.additionalInfo.AdditionalInfoTableFilter;
14
import es.unex.sextante.dataObjects.I3DRasterLayer;
15
import es.unex.sextante.dataObjects.IRasterLayer;
16
import es.unex.sextante.dataObjects.ITable;
17
import es.unex.sextante.dataObjects.IVectorLayer;
18
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException;
19
import es.unex.sextante.exceptions.NullParameterValueException;
20
import es.unex.sextante.exceptions.WrongParameterTypeException;
21

    
22
/**
23
 * A parameter representing a field in a table or in the attributes table of a vector layer
24
 * 
25
 * @author volaya
26
 * 
27
 */
28
public class ParameterTableFilter
29
         extends
30
            Parameter {
31

    
32
   private static final String PARENT    = "parent";
33
   private static final String MANDATORY = "mandatory";
34

    
35

    
36
   @Override
37
   public String getParameterTypeName() {
38

    
39
      return "Table Filter";
40

    
41
   }
42

    
43

    
44
   @Override
45
   public IRasterLayer getParameterValueAsRasterLayer() throws WrongParameterTypeException {
46

    
47
      throw new WrongParameterTypeException();
48

    
49
   }
50

    
51

    
52
   @Override
53
   public I3DRasterLayer getParameterValueAs3DRasterLayer() throws WrongParameterTypeException {
54

    
55
      throw new WrongParameterTypeException();
56

    
57
   }
58

    
59

    
60
   @Override
61
   public ITable getParameterValueAsTable() throws WrongParameterTypeException {
62

    
63
      throw new WrongParameterTypeException();
64

    
65
   }
66

    
67

    
68
   @Override
69
   public IVectorLayer getParameterValueAsVectorLayer() throws WrongParameterTypeException {
70

    
71
      throw new WrongParameterTypeException();
72

    
73
   }
74

    
75

    
76
   public ArrayList getParameterValueAsMultipleRasterLayer() throws WrongParameterTypeException {
77

    
78
      throw new WrongParameterTypeException();
79

    
80
   }
81

    
82

    
83
   public ArrayList getParameterValueAsMultipleVectorLayer() throws WrongParameterTypeException {
84

    
85
      throw new WrongParameterTypeException();
86

    
87
   }
88

    
89

    
90
   public ArrayList getParameterValueAsMultipleTable() throws WrongParameterTypeException {
91

    
92
      throw new WrongParameterTypeException();
93

    
94
   }
95

    
96

    
97
   @Override
98
   public int getParameterValueAsInt() throws WrongParameterTypeException, NullParameterValueException {
99

    
100
      if (m_ParameterValue != null) {
101
         return ((Integer) m_ParameterValue).intValue();
102
      }
103
      throw new NullParameterValueException();
104

    
105
   }
106

    
107

    
108
   @Override
109
   public double getParameterValueAsDouble() throws WrongParameterTypeException {
110

    
111
      throw new WrongParameterTypeException();
112

    
113
   }
114

    
115

    
116
   @Override
117
   public boolean getParameterValueAsBoolean() throws WrongParameterTypeException {
118

    
119
      throw new WrongParameterTypeException();
120

    
121
   }
122

    
123

    
124
   @Override
125
   public String getParameterValueAsString() throws WrongParameterTypeException, NullParameterValueException {
126
      if (m_ParameterValue!=null) {
127
        return m_ParameterValue.toString();
128
      } else {
129
          return "";
130
      }
131

    
132
   }
133

    
134

    
135
   @Override
136
   public Point2D getParameterValueAsPoint() throws WrongParameterTypeException {
137

    
138
      throw new WrongParameterTypeException();
139

    
140
   }
141

    
142

    
143
   @Override
144
   public boolean setParameterAdditionalInfo(final AdditionalInfo additionalInfo) {
145

    
146
      if (additionalInfo instanceof AdditionalInfoTableFilter) {
147
         m_ParameterAdditionalInfo = additionalInfo;
148
         return true;
149
      }
150
      else {
151
         return false;
152
      }
153

    
154
   }
155

    
156

    
157
   @Override
158
   public boolean setParameterValue(final Object value) {
159
      try {
160
          m_ParameterValue = value;
161
      } catch (Exception ex) {
162
       return false;
163
   }
164
      return true;
165
   }
166

    
167

    
168
   @Override
169
   public Class getParameterClass() {
170

    
171
      return Integer.class;
172

    
173
   }
174

    
175

    
176
   @Override
177
   protected void serializeAttributes(final KXmlSerializer serializer) throws NullParameterAdditionalInfoException, IOException {
178

    
179
      final AdditionalInfoTableFilter aitf = (AdditionalInfoTableFilter) m_ParameterAdditionalInfo;
180
      if (aitf != null) {
181
         serializer.text("\n");
182
         serializer.text("\t\t\t");
183
         serializer.startTag(null, ATTRIBUTE);
184
         serializer.attribute(null, NAME, PARENT);
185
         serializer.attribute(null, VALUE, aitf.getParentParameterName());
186
         serializer.endTag(null, ATTRIBUTE);
187
         serializer.text("\n");
188
         serializer.text("\t\t\t");
189
         serializer.startTag(null, ATTRIBUTE);
190
         serializer.attribute(null, NAME, MANDATORY);
191
         serializer.attribute(null, VALUE, Boolean.valueOf(aitf.getIsMandatory()).toString());
192
         serializer.endTag(null, ATTRIBUTE);
193
      }
194
      else {
195
         throw new NullParameterAdditionalInfoException();
196
      }
197

    
198
   }
199

    
200

    
201
   public static Parameter deserialize(final KXmlParser parser) throws XmlPullParserException, IOException {
202

    
203
      String sParent = null;
204
      boolean bMandatory = true;
205

    
206
      int tag = parser.nextTag();
207

    
208
      boolean bOver = false;
209
      while (!bOver) {
210
         switch (tag) {
211
            case XmlPullParser.START_TAG:
212
               if (parser.getName().compareTo(ATTRIBUTE) == 0) {
213
                  final String sName = parser.getAttributeValue("", NAME);
214
                  if (sName.compareTo(PARENT) == 0) {
215
                     sParent = parser.getAttributeValue("", VALUE);
216
                  }
217
                  else if (sName.compareTo(PARENT) == 0) {
218
                     final String sMandatory = parser.getAttributeValue("", VALUE);
219
                     bMandatory = Boolean.parseBoolean(sMandatory);
220
                  }
221
               }
222
               break;
223
            case XmlPullParser.END_TAG:
224
               if (parser.getName().compareTo(INPUT) == 0) {
225
                  bOver = true;
226
               }
227
               break;
228
            case XmlPullParser.TEXT:
229
               break;
230
         }
231

    
232
         if (!bOver) {
233
            tag = parser.next();
234
         }
235

    
236
      }
237

    
238
      final ParameterTableField param = new ParameterTableField();
239
      final AdditionalInfoTableFilter ai = new AdditionalInfoTableFilter(sParent, bMandatory);
240
      param.setParameterAdditionalInfo(ai);
241

    
242
      return param;
243

    
244
   }
245

    
246

    
247
   @Override
248
   public String getCommandLineParameter() {
249

    
250
      //final Integer i = (Integer) m_ParameterValue;
251
      if (m_ParameterValue!=null) {
252
        return "\"" + (String) m_ParameterValue + "\"";
253
      } else {
254
          return "";
255
      }
256

    
257
   }
258

    
259

    
260
   @Override
261
   public boolean isParameterValueCorrect() {
262

    
263
      return m_ParameterValue != null;
264

    
265
   }
266

    
267
}