Revision 3005 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/AbstractJDynFormField.java
AbstractJDynFormField.java | ||
---|---|---|
38 | 38 |
import java.util.Map; |
39 | 39 |
import java.util.Objects; |
40 | 40 |
import java.util.Set; |
41 |
import javax.json.JsonObject; |
|
41 | 42 |
import javax.swing.AbstractButton; |
42 | 43 |
|
43 | 44 |
import javax.swing.Action; |
... | ... | |
698 | 699 |
this.buttonsOfEvents.put(eventName+"_click",button); |
699 | 700 |
return button; |
700 | 701 |
} |
702 |
|
|
703 |
protected JsonObject getEventConfiguration(String name) { |
|
704 |
// Habria que cachear estas configuraciones en el jDynFormField |
|
705 |
JDynForm jform = this.getForm(); |
|
706 |
|
|
707 |
Script script = jform.getScript(); |
|
708 |
if( script == null ) { |
|
709 |
return null; |
|
710 |
} |
|
711 |
String functionName = this.getName()+"_"+name+"_config"; |
|
712 |
try { |
|
713 |
Object x = script.invokeFunction(functionName, new Object[0]); |
|
714 |
return (JsonObject)x; |
|
715 |
} catch (Throwable t) { |
|
716 |
LOGGER.warn("Error calling event '"+functionName+"'",t); |
|
717 |
return null; |
|
718 |
} |
|
719 |
} |
|
701 | 720 |
|
702 | 721 |
protected void setReadOnlyButtonsOfEvents(boolean readonly) { |
703 | 722 |
if( this.buttonsOfEvents==null ) { |
704 | 723 |
return; |
705 | 724 |
} |
706 |
for (AbstractButton button : this.buttonsOfEvents.values()) { |
|
707 |
button.setEnabled(!readonly); |
|
725 |
for (Map.Entry<String, AbstractButton> entry : buttonsOfEvents.entrySet()) { |
|
726 |
String name = entry.getKey(); |
|
727 |
AbstractButton button = entry.getValue(); |
|
728 |
try { |
|
729 |
JsonObject config = this.getEventConfiguration(StringUtils.removeEnd(name, "_click")); |
|
730 |
boolean enabled = config.getBoolean("enabled"); |
|
731 |
button.setEnabled(enabled); |
|
732 |
} catch(Throwable ex) { |
|
733 |
button.setEnabled(!readonly); |
|
734 |
} |
|
708 | 735 |
} |
709 | 736 |
} |
710 | 737 |
} |
Also available in: Unified diff