Revision 44338 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultForeingKey.java
DefaultForeingKey.java | ||
---|---|---|
130 | 130 |
} |
131 | 131 |
|
132 | 132 |
private boolean foreingKey; |
133 |
private boolean selectable;
|
|
133 |
private boolean closedList;
|
|
134 | 134 |
private String labelFormula; |
135 | 135 |
private String tableName; |
136 | 136 |
private String codeName; |
137 |
private DynObjectValueItem[] availableValues; |
|
137 | 138 |
|
138 | 139 |
private FeatureAttributeDescriptor descriptor; |
139 | 140 |
|
... | ... | |
146 | 147 |
} |
147 | 148 |
|
148 | 149 |
@Override |
149 |
public boolean isSelectable() {
|
|
150 |
return this.selectable;
|
|
150 |
public boolean isClosedList() {
|
|
151 |
return this.closedList;
|
|
151 | 152 |
} |
152 | 153 |
|
153 | 154 |
@Override |
154 |
public void setSelectable(boolean selectable) {
|
|
155 |
this.selectable = selectable;
|
|
155 |
public void setClosedList(boolean selectable) {
|
|
156 |
this.closedList = selectable;
|
|
156 | 157 |
} |
157 | 158 |
|
158 | 159 |
@Override |
... | ... | |
198 | 199 |
@Override |
199 | 200 |
public boolean isEmpty() { |
200 | 201 |
if (!this.foreingKey |
201 |
&& !this.selectable
|
|
202 |
&& !this.closedList
|
|
202 | 203 |
&& StringUtils.isBlank(this.tableName) |
203 | 204 |
&& StringUtils.isBlank(this.codeName) |
204 | 205 |
&& StringUtils.isBlank(this.labelFormula)) { |
... | ... | |
210 | 211 |
@Override |
211 | 212 |
public void clean() { |
212 | 213 |
this.foreingKey = false; |
213 |
this.selectable = false;
|
|
214 |
this.closedList = false;
|
|
214 | 215 |
this.tableName = null; |
215 | 216 |
this.codeName = null; |
216 | 217 |
this.labelFormula = null; |
... | ... | |
383 | 384 |
|
384 | 385 |
@Override |
385 | 386 |
public DynObjectValueItem[] getAvailableValues(ContextForeingKey context) { |
386 |
if (!this.isSelectable()) {
|
|
387 |
if (!this.isClosedList()) {
|
|
387 | 388 |
return null; |
388 | 389 |
} |
389 |
context = createLocalContextIfNull(context); |
|
390 |
try { |
|
391 |
Expression labelExpression = context.getLabelExpression(); |
|
392 |
FeatureStore store = context.getFeatureStore(); |
|
393 |
if (store == null) { |
|
394 |
return null; |
|
395 |
} |
|
396 |
|
|
397 |
int count = (int) store.getFeatureCount(); |
|
398 |
DynObjectValueItem[] values = new DynObjectValueItem[Math.min(count, MAX_AVAILABLE_VALUES)]; |
|
399 |
int n = 0; |
|
400 |
for (Feature feature : store.getFeatureSet()) { |
|
401 |
Object code = feature.get(codeName); |
|
402 |
Object value; |
|
403 |
if (labelExpression == null) { |
|
404 |
value = code; |
|
405 |
} else { |
|
406 |
context.getFeatureSymbolTable().setFeature(feature); |
|
407 |
value = labelExpression.execute(context.getSymbolTable()); |
|
390 |
if( this.availableValues == null ) { |
|
391 |
context = createLocalContextIfNull(context); |
|
392 |
try { |
|
393 |
Expression labelExpression = context.getLabelExpression(); |
|
394 |
FeatureStore store = context.getFeatureStore(); |
|
395 |
if (store == null) { |
|
396 |
return null; |
|
408 | 397 |
} |
409 |
values[n++] = new DynObjectValueItem(code, Objects.toString(value, Objects.toString(code, "##ERROR##"))); |
|
410 |
if( n>=MAX_AVAILABLE_VALUES ) { |
|
411 |
break; |
|
398 |
int count = (int) store.getFeatureCount(); |
|
399 |
DynObjectValueItem[] values = new DynObjectValueItem[Math.min(count, MAX_AVAILABLE_VALUES)]; |
|
400 |
int n = 0; |
|
401 |
for (Feature feature : store.getFeatureSet()) { |
|
402 |
Object code = feature.get(codeName); |
|
403 |
Object value; |
|
404 |
if (labelExpression == null) { |
|
405 |
value = code; |
|
406 |
} else { |
|
407 |
context.getFeatureSymbolTable().setFeature(feature); |
|
408 |
value = labelExpression.execute(context.getSymbolTable()); |
|
409 |
} |
|
410 |
values[n++] = new DynObjectValueItem(code, Objects.toString(value, Objects.toString(code, "##ERROR##"))); |
|
411 |
if( n>=MAX_AVAILABLE_VALUES ) { |
|
412 |
break; |
|
413 |
} |
|
412 | 414 |
} |
415 |
this.availableValues = values; |
|
416 |
} catch (Exception ex) { |
|
417 |
LOGGER.warn("Can't get values from table '" + tableName + "' of field.", ex); |
|
418 |
} finally { |
|
419 |
disposeIfLocalContext(context); |
|
413 | 420 |
} |
414 |
return values; |
|
415 |
} catch (Exception ex) { |
|
416 |
LOGGER.warn("Can't get values from table '" + tableName + "' of field.", ex); |
|
417 |
} finally { |
|
418 |
disposeIfLocalContext(context); |
|
419 | 421 |
} |
420 |
return null;
|
|
422 |
return this.availableValues;
|
|
421 | 423 |
} |
424 |
|
|
425 |
public String getLabelForValue(Object value) { |
|
426 |
DynObjectValueItem[] values = this.getAvailableValues(null); |
|
427 |
if( values != null ) { |
|
428 |
for (DynObjectValueItem value1 : values) { |
|
429 |
if( Objects.equals(value, value1.getValue()) ) { |
|
430 |
return value1.getLabel(); |
|
431 |
} |
|
432 |
} |
|
433 |
} |
|
434 |
return Objects.toString(value, "##ERROR##"); |
|
435 |
} |
|
422 | 436 |
|
423 | 437 |
@Override |
424 | 438 |
public void loadFromState(PersistentState state) |
425 | 439 |
throws PersistenceException { |
426 | 440 |
foreingKey = state.getBoolean("foreingKey"); |
427 |
selectable = state.getBoolean("selectable");
|
|
441 |
closedList = state.getBoolean("selectable");
|
|
428 | 442 |
labelFormula = state.getString("labelFormula"); |
429 | 443 |
codeName = state.getString("codeName"); |
430 | 444 |
tableName = state.getString("tableName"); |
... | ... | |
433 | 447 |
@Override |
434 | 448 |
public void saveToState(PersistentState state) throws PersistenceException { |
435 | 449 |
state.set("foreingKey", foreingKey); |
436 |
state.set("selectable", selectable);
|
|
450 |
state.set("selectable", closedList);
|
|
437 | 451 |
state.set("labelFormula", labelFormula); |
438 | 452 |
state.set("codeName", codeName); |
439 | 453 |
state.set("tableName", tableName); |
Also available in: Unified diff