Revision 202 org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/algorithm/DefaultParametersPanel.java
DefaultParametersPanel.java | ||
---|---|---|
94 | 94 |
/** |
95 | 95 |
* A panel to introduce parameters for a geoalgorithm, created automatically based on the parameters needed by that geoalgorithm |
96 | 96 |
* If no additional panel is provided for an algorithm, SEXTANTE will use this panel as the default one. |
97 |
*
|
|
97 |
* |
|
98 | 98 |
* @author volaya |
99 |
*
|
|
99 |
* |
|
100 | 100 |
*/ |
101 | 101 |
public class DefaultParametersPanel |
102 | 102 |
extends |
... | ... | |
399 | 399 |
|
400 | 400 |
boolean bAddNotSetField = false; |
401 | 401 |
int i, j; |
402 |
int iShapeType; |
|
403 | 402 |
String sParameterName; |
404 | 403 |
final ArrayList childComboBoxIndex = new ArrayList(); |
405 | 404 |
Parameter parameter; |
... | ... | |
414 | 413 |
parameter = parameters.getParameter(i); |
415 | 414 |
if (parameter instanceof ParameterVectorLayer) { |
416 | 415 |
try { |
417 |
iShapeType = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeType();
|
|
416 |
int[] shapeTypes = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeTypes();
|
|
418 | 417 |
//check for table fields that depend on this vector layer |
419 | 418 |
sParameterName = parameter.getParameterName(); |
420 | 419 |
childComboBoxIndex.clear(); |
... | ... | |
426 | 425 |
sParameterName)) { |
427 | 426 |
m_iCurrentRow++; |
428 | 427 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
429 |
comboBox = getVectorLayerFieldSelectionComboBox(iShapeType);
|
|
428 |
comboBox = getVectorLayerFieldSelectionComboBox(shapeTypes);
|
|
430 | 429 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
431 | 430 |
m_ComboBox.add(comboBox); |
432 | 431 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow)); |
... | ... | |
444 | 443 |
} |
445 | 444 |
// add vector layer |
446 | 445 |
try { |
447 |
iShapeType = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeType(); |
|
446 |
AdditionalInfoVectorLayer parameterAdditionalInfo = (AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo(); |
|
447 |
// iShapeType = parameterAdditionalInfo.getShapeType(); |
|
448 |
int[] shapeTypes = parameterAdditionalInfo.getShapeTypes(); |
|
449 |
|
|
448 | 450 |
if (((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getIsMandatory()) { |
449 | 451 |
bAddNotSetField = false; |
450 | 452 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow - childComboBoxIndex.size(), false); |
... | ... | |
454 | 456 |
addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"), |
455 | 457 |
m_iCurrentRow - childComboBoxIndex.size(), false); |
456 | 458 |
} |
457 |
comboBox = getVectorLayerSelectionComboBox(iShapeType, childComboBoxIndex, bAddNotSetField);
|
|
459 |
comboBox = getVectorLayerSelectionComboBox(shapeTypes, childComboBoxIndex, bAddNotSetField);
|
|
458 | 460 |
if (bAddNotSetField) { |
459 | 461 |
comboBox.setSelectedIndex(0); |
460 | 462 |
} |
... | ... | |
1120 | 1122 |
|
1121 | 1123 |
} |
1122 | 1124 |
|
1125 |
protected JComboBox<ObjectAndDescription> getVectorLayerSelectionComboBox(int[] shapeTypes, final List childComboBoxes, |
|
1126 |
final boolean bAddNotSetField) { |
|
1123 | 1127 |
|
1128 |
int i; |
|
1129 |
|
|
1130 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
|
1131 |
for (i = 0; i < childsArray.length; i++) { |
|
1132 |
childsArray[i] = (Integer) childComboBoxes.get(i); |
|
1133 |
} |
|
1134 |
|
|
1135 |
List<IVectorLayer> layers = getVectorLayers(shapeTypes); |
|
1136 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.size()]; |
|
1137 |
for (i = 0; i < layers.size(); i++) { |
|
1138 |
oad[i] = new ObjectAndDescription(layers.get(i).getName(), layers.get(i)); |
|
1139 |
} |
|
1140 |
final JComboBox cb = new JComboBox(oad); |
|
1141 |
|
|
1142 |
if (bAddNotSetField) { |
|
1143 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
|
1144 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
|
1145 |
} |
|
1146 |
|
|
1147 |
cb.addItemListener(new java.awt.event.ItemListener() { |
|
1148 |
|
|
1149 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
|
1150 |
int i; |
|
1151 |
int iIndex; |
|
1152 |
String sNames[] = null; |
|
1153 |
DefaultComboBoxModel defaultModel; |
|
1154 |
for (i = 0; i < childsArray.length; i++) { |
|
1155 |
iIndex = (childsArray[i]).intValue(); |
|
1156 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem(); |
|
1157 |
final IVectorLayer layer = (IVectorLayer) ob.getObject(); |
|
1158 |
if (layer != null) { |
|
1159 |
sNames = getVectorLayerFieldNames(layer); |
|
1160 |
if (sNames != null) { |
|
1161 |
defaultModel = new DefaultComboBoxModel(sNames); |
|
1162 |
((JComboBox) m_ComboBox.get(iIndex)).setModel(defaultModel); |
|
1163 |
} |
|
1164 |
} |
|
1165 |
} |
|
1166 |
} |
|
1167 |
}); |
|
1168 |
|
|
1169 |
return cb; |
|
1170 |
|
|
1171 |
} |
|
1172 |
|
|
1173 |
|
|
1174 |
/** |
|
1175 |
* @param shapeTypes |
|
1176 |
* @return |
|
1177 |
*/ |
|
1178 |
private List<IVectorLayer> getVectorLayers(int[] shapeTypes) { |
|
1179 |
List<IVectorLayer> layers = new ArrayList<IVectorLayer>(); |
|
1180 |
for (int j = 0; j < shapeTypes.length; j++) { |
|
1181 |
IVectorLayer[] layersPerType = SextanteGUI.getInputFactory().getVectorLayers(shapeTypes[j]); |
|
1182 |
for (int k = 0; k < layersPerType.length; k++) { |
|
1183 |
layers.add(layersPerType[k]); |
|
1184 |
}; |
|
1185 |
} |
|
1186 |
return layers; |
|
1187 |
} |
|
1188 |
|
|
1124 | 1189 |
protected JComboBox getTableSelectionComboBox(final ArrayList childComboBoxes, |
1125 | 1190 |
final boolean bAddNotSetField) { |
1126 | 1191 |
|
... | ... | |
1220 | 1285 |
|
1221 | 1286 |
} |
1222 | 1287 |
|
1288 |
protected JComboBox getVectorLayerFieldSelectionComboBox(final int[] shapeTypes) { |
|
1223 | 1289 |
|
1290 |
List<IVectorLayer> layers = getVectorLayers(shapeTypes); |
|
1291 |
|
|
1292 |
if (layers.size() > 0) { |
|
1293 |
final JComboBox comboBox = new JComboBox(); |
|
1294 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers.get(0))); |
|
1295 |
comboBox.setModel(defaultModel); |
|
1296 |
return comboBox; |
|
1297 |
} |
|
1298 |
else { |
|
1299 |
return new JComboBox(); |
|
1300 |
} |
|
1301 |
|
|
1302 |
} |
|
1303 |
|
|
1304 |
|
|
1224 | 1305 |
protected String[] getTableFieldNames(final ITable table) { |
1225 | 1306 |
|
1226 | 1307 |
return table.getFieldNames(); |
Also available in: Unified diff