Revision 1862

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultToolsSwingManager.java
438 438
    }
439 439

  
440 440
    @Override
441
    public void addClearButton(JComboBox combo) {
442
            try {
443
            JTextComponent text = (JTextComponent) combo.getEditor().getEditorComponent();
444
            this.addClearButton(text, null);
445
        } catch(Throwable th) {
446
            // Si no puede a?adir el boton no hace nada.
447
        }
448
    }
449

  
450
    @Override
441 451
    public void addClearButton(final JTextComponent text,  final ActionListener action) {
442 452
        final JButton btnClear = new JButton(getIcon("picker-cleartext"));
443 453
        btnClear.setBorderPainted( false );
......
460 470
        text.addPropertyChangeListener(new PropertyChangeListener() {
461 471
            @Override
462 472
            public void propertyChange(PropertyChangeEvent evt) {
463
                if( evt!=null && evt.getPropertyName().equalsIgnoreCase("enabled") ) {
473
                if( evt==null ) {
474
                    return;
475
                }
476
                if( evt.getPropertyName().equalsIgnoreCase("enabled") ) {
464 477
                    boolean enabled = text.isEnabled();
465 478
                    btnClear.setEnabled(enabled);
479
                } else if( evt.getPropertyName().equalsIgnoreCase("editable") ) {
480
                    boolean editable = text.isEditable();
481
                    btnClear.setEnabled(editable);
466 482
                }
467 483
            }
468 484
        });
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingManager.java
165 165

  
166 166
    public void addClearButton(final JTextComponent text);
167 167

  
168
    public void addClearButton(JComboBox combo);
169
    
168 170
    public SimpleImage createSimpleImage();
169 171
    
170 172
    public SimpleImage createSimpleImage(Object source);
org.gvsig.tools/library/trunk/org.gvsig.tools/pom.xml
178 178
            <dependency>
179 179
                <groupId>commons-codec</groupId>
180 180
                <artifactId>commons-codec</artifactId>
181
                <version>1.6</version>
181
                <version>1.8</version>
182 182
            </dependency>
183 183
            <dependency>
184 184
                <groupId>commons-io</groupId>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.api/src/main/java/org/gvsig/tools/dynform/JDynFormSet.java
101 101
        public boolean isInNewState();
102 102

  
103 103
        public void addAction(Action action);
104
        public void setActionVisible(String action, boolean visible);
105
        public void setActionEnabled(String action, boolean enabled);
106
        public boolean isActionVisible(String action);
107
        public boolean isActionEnabled(String action);
108
        
104 109
	public void addActionToPopupMenu(DataType tipo, String name, Action action);
105 110
	public void addSeparatorToPopupMenu(DataType tipo);
106 111

  
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/AbstractJDynForm.java
46 46
    private DynFormDefinition definition = null;
47 47
    private int layoutMode = USE_PLAIN;
48 48
    private JLabel jlabel_messages = null;
49
    private boolean readOnly = false;
49
    private boolean readOnly = true;
50 50
    private Set listeners = null;
51 51
    private boolean useScrollBars = true;
52 52
    private final Map<String, List<Action>> customActions;
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
177 177
    }
178 178

  
179 179
    protected void fireFieldChangedEvent() {
180
        if( this.isReadOnly() ) {
181
            return;
182
        }
180 183
        Iterator it = this.listeners.iterator();
181 184
        while (it.hasNext()) {
182 185
            JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultJDynForm.java
55 55
import java.util.Collection;
56 56
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
57 57

  
58
@SuppressWarnings({"unchecked", "rawtypes"})
58
@SuppressWarnings({"unchecked", "rawtypes", "UseSpecificCatch"})
59 59
public class DefaultJDynForm extends AbstractJDynForm implements JDynFormFieldListener {
60 60

  
61 61
    private Map components = null;
......
114 114
            if (jfield instanceof AbstractJDynFormField) {
115 115
                ((AbstractJDynFormField) jfield).setForm(this);
116 116
            }
117
            jfield.setReadOnly(fieldDefinition.isReadOnly());
118
            jfield.addListener(this);
119 117
            if (this.isReadOnly()) {
120
                jfield.setReadOnly(this.isReadOnly());
118
                jfield.setReadOnly(true);
119
            } else {
120
                jfield.setReadOnly(fieldDefinition.isReadOnly());
121 121
            }
122
            jfield.addListener(this);
122 123
            builder.append(jfield.getJLabel(), jfield.asJComponent());
123 124

  
124 125
            this.components.put(jfield.getName(), jfield);
......
249 250

  
250 251
    @Override
251 252
    public void setReadOnly(boolean readOnly) {
253
        if( this.isReadOnly() == readOnly ) {
254
            return;
255
        }
252 256
        super.setReadOnly(readOnly);
253 257
        if (this.isContentsInitialized()) {
254 258
            Iterator it = this.getFieldsIterator();
......
294 298
                if (fields[i].getDataType().getType() == DataTypes.LIST) {
295 299
                    try {
296 300
                        if (((DynField_v2) fields[i]).getDynClassOfItems() != null) {
297
                            values.setDynValue(name, new ArrayList<DynObject>());
301
                            values.setDynValue(name, new ArrayList<>());
298 302
                        }
299 303
                    } catch (Exception e) {
300 304
                        logger.warn("Problems initializing the DynObject List", e);
......
402 406
        fireFieldChangeEvent(field);
403 407
    }
404 408

  
409
    @Override
405 410
    public JDynFormField getField(String fieldName) {
406 411
        JDynFormField field = (JDynFormField) this.components.get(fieldName);
407 412
        return field;
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Integer/JDynFormFieldInteger.java
25 25

  
26 26
import javax.swing.JComboBox;
27 27
import javax.swing.JTextField;
28
import org.apache.commons.lang3.StringUtils;
28 29

  
29 30
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList;
30 31
import org.gvsig.tools.dynobject.DynObject;
......
43 44
		Object value = null;
44 45
		if( this.contents instanceof JTextField ) {
45 46
			String s = getJTextField().getText();
46
			if( s.trim().length()==0 ) {
47
			if( StringUtils.isBlank(s) ) {
47 48
				value = this.getDefinition().getDefaultValue();
48 49
			} else {
49 50
				try {
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/String/JDynFormFieldString.java
40 40
		return "";
41 41
	}
42 42

  
43
	public Object getValue() {
44
		Object value = null;
45
		String s = this.getValueFromJComponent();
46
		if( StringUtils.isBlank(s) ) {
47
			Object x = this.getDefinition().getDefaultValue();
48
			if( x != null ) {
49
                            value = x.toString();
50
			}
51
		} else {
52
			value = s;
53
		}
54
		return value;
55
	}
56
	
43
    @Override
44
    public Object getValue() {
45
        Object value = null;
46
        String s = this.getValueFromJComponent();
47
        if (StringUtils.isBlank(s)) {
48
            if (this.assignedValue != null) {
49
                Object x = this.getDefinition().getDefaultValue();
50
                if (x != null) {
51
                    value = x.toString();
52
                }
53
            }
54
        } else {
55
            value = s;
56
        }
57
        return value;
58
    }
59

  
57 60
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Date/JDynFormFieldDate.java
175 175
			}
176 176
		}
177 177
        if (this.contents instanceof JPanel && this.contents.getName().equalsIgnoreCase(DATE_PANEL_NAME)) {
178
            this.getJSpinner().setValue(value);
178
            try {
179
                this.getJSpinner().setValue(value);
180
            } catch(Exception ex) {
181
                
182
            }
179 183
        }
180 184
		this.assignedValue = value;
181 185
	}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Unknow/JDynFormFieldUnknow.java
27 27
import java.awt.event.FocusListener;
28 28

  
29 29
import javax.swing.JTextField;
30
import org.apache.commons.codec.binary.Hex;
30 31

  
31 32
import org.gvsig.tools.dynform.JDynFormField;
32 33
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
......
77 78
				s = value.toString();
78 79
			}
79 80
		} else {
80
			s = value.toString();
81
                    if( value instanceof byte[] ) {
82
                        s = Hex.encodeHexString((byte[]) value);
83
                    } else {
84
                        s = value.toString();
85
                    }
81 86
		}
82 87
		this.getJTextField().setText(s);
83 88
		this.assignedValue = value;
......
100 105
	}
101 106
	
102 107
	public void setReadOnly(boolean readonly) {
103
		this.getJTextField().setEditable(false);;
108
            super.setReadOnly(false);
109
            this.getJTextField().setEditable(false);;
104 110
	}
105 111
	
106 112
	public boolean isReadOnly() {
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformset/subform/SubformJDynFormSet.java
24 24

  
25 25
import java.awt.BorderLayout;
26 26
import java.awt.Color;
27
import java.awt.Component;
27 28
import java.awt.event.MouseAdapter;
28 29
import java.awt.event.MouseEvent;
29 30
import java.util.ArrayList;
......
31 32
import java.util.List;
32 33
import javax.swing.Action;
33 34
import javax.swing.BorderFactory;
35
import javax.swing.BoxLayout;
34 36

  
35 37
import javax.swing.JComponent;
36 38
import javax.swing.JLabel;
......
74 76
        if (this.contents == null) {
75 77
            try {
76 78
                this.initComponents();
79
                if (this.buttonBar != null) {
80
                    this.buttonBar.setReadOnly(this.isReadOnly());
81
                }
82
                if (this.form != null) {
83
                    this.form.setReadOnly(this.isReadOnly());
84
                }
77 85
            } catch (ServiceException e) {
78 86
                throw new RuntimeException(e.getLocalizedMessage(), e);
79 87
            }
......
123 131
        this.contents.setLayout(new BorderLayout());
124 132

  
125 133
        this.form = this.manager.getDynFormManager().createJDynForm(definition);
134
        this.form.setReadOnly(this.isReadOnly());
135
        this.form.setLayoutMode(this.getLayoutMode());
126 136
        this.form.setUseScrollBars(this.getUseScrollBars());
127 137
        this.form.addListener(this);
128 138

  
......
157 167
        this.buttonBar.setActionActive(FormSetButtonBar.ActionSearch, this.allowSearch());
158 168
        this.buttonBar.setActionActive(FormSetButtonBar.ActionClose, this.allowClose());
159 169
        this.buttonBar.setVisible(FormSetButtonBar.ActionCancelNew, false);
160
        this.contents.add(this.buttonBar.asJComponent(), BorderLayout.NORTH);
170
        this.buttonBar.setReadOnly(this.isReadOnly());
161 171
        this.contents.add(this.form.asJComponent(), BorderLayout.CENTER);
162
        this.contents.add(this.getMessagesJLabel(), BorderLayout.SOUTH);
172
        
173
        JPanel p = new JPanel();
174
        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
175
        this.buttonBar.asJComponent().setAlignmentX(Component.LEFT_ALIGNMENT);
176
        this.getMessagesJLabel().setAlignmentX(Component.LEFT_ALIGNMENT);
177
        p.add(this.buttonBar.asJComponent());
178
        p.add(this.getMessagesJLabel());
179
        this.contents.add(p, BorderLayout.SOUTH);
180
        
163 181
        doChangeValues();
164 182
    }
165 183

  
......
218 236

  
219 237
    @Override
220 238
    public void setReadOnly(boolean readOnly) {
239
//        if( this.isReadOnly() == readOnly ) {
240
//            return;
241
//        }
221 242
        super.setReadOnly(readOnly);
222 243
        if (this.buttonBar != null) {
223 244
            this.buttonBar.setReadOnly(readOnly);
......
637 658
            throw new RuntimeException("Can't add action to JDymFormSet", ex);
638 659
        }
639 660
    }
661

  
662
    @Override
663
    public void setActionVisible(String action, boolean visible) {
664
        try {
665
            this.getButtonBar().setVisible(action, visible);
666
        } catch (Exception ex) {
667
            throw new RuntimeException("Can't action visible in JDymFormSet", ex);
668
        }
669
    }
670

  
671
    @Override
672
    public void setActionEnabled(String action, boolean enabled) {
673
        try {
674
            this.getButtonBar().setEnabled(action, enabled);
675
        } catch (Exception ex) {
676
            throw new RuntimeException("Can't action enable in JDymFormSet", ex);
677
        }
678
    }
679

  
680
    @Override
681
    public boolean isActionEnabled(String action) {
682
        try {
683
            return this.getButtonBar().isEnabled(action);
684
        } catch (Exception ex) {
685
            throw new RuntimeException("Can't get action enable in JDymFormSet", ex);
686
        }
687
    }
688

  
689
    @Override
690
    public boolean isActionVisible(String action) {
691
        try {
692
            return this.getButtonBar().isVisible(action);
693
        } catch (Exception ex) {
694
            throw new RuntimeException("Can't get action visible in JDymFormSet", ex);
695
        }
696
    }
697
    
698
    
640 699
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformset/subform/FormSetButtonBar.java
29 29
import java.awt.event.ActionListener;
30 30
import java.net.URL;
31 31
import java.util.ArrayList;
32
import java.util.HashMap;
32 33
import java.util.HashSet;
33 34
import java.util.Iterator;
34 35
import java.util.List;
36
import java.util.Map;
37
import java.util.Objects;
35 38
import java.util.Set;
36 39
import javax.swing.Action;
37 40
import javax.swing.BorderFactory;
......
108 111

  
109 112
    private JPanel othersButtons;
110 113
    private final List<Action> otherActions;
114
    private final Map<String,JButton> otherButtons;
111 115

  
112 116
    private boolean readOnly = false;
113 117

  
......
121 125
        }
122 126
        this.listeners = new HashSet();
123 127
        this.otherActions = new ArrayList<>();
128
        this.otherButtons = new HashMap<>();
124 129
    }
125 130

  
126 131
    @Override
......
394 399
        }
395 400
    }
396 401

  
402
    public void setVisible(String id, boolean visible) {
403
        JButton button = this.otherButtons.get(id);
404
        if( button == null ) {
405
            return;
406
        }
407
        button.setVisible(visible);
408
    }
409
    
410
    public void setEnabled(String id, boolean enabled) {
411
        JButton button = this.otherButtons.get(id);
412
        if( button == null ) {
413
            return;
414
        }
415
        button.setEnabled(enabled);
416
    }
417
    
418
    public boolean isEnabled(String id) {
419
        JButton button = this.otherButtons.get(id);
420
        if( button == null ) {
421
            throw new IllegalArgumentException("Don't exists action '"+id+"'.");
422
        }
423
        return button.isEnabled();
424
    }
425
    
426
    public boolean isVisible(String id) {
427
        JButton button = this.otherButtons.get(id);
428
        if( button == null ) {
429
            throw new IllegalArgumentException("Don't exists action '"+id+"'.");
430
        }
431
        return button.isVisible();
432
    }
433
    
397 434
    public void setCurrent(int current) {
398 435
        this.current = current;
399 436
        updateRecords();
......
427 464

  
428 465
    public void setReadOnly(boolean readOnly) {
429 466
        this.readOnly = readOnly;
430
        for (int i = 0; i < buttons.length; i++) {
431
            if (isActionActive(i) && this.buttons[i] != null) {
432
                this.buttons[i].setEnabled(!readOnly);
433
            }
434
            if (!readOnly) {
435
                updateRecords();
436
            }
437
        }
467
        
468
        this.setEnabled(ActionSave, !readOnly);
469
        this.setEnabled(ActionNew, !readOnly);
470
        this.setEnabled(ActionCancelNew, !readOnly);
471
        this.setEnabled(ActionDelete, !readOnly);
472
        this.setEnabled(ActionSearch, true);
473
        this.setEnabled(ActionClose, true);
474
        
475
        updateRecords();
438 476
    }
439 477

  
440 478
    public void addAction(Action action) {
......
448 486
        button.setFocusPainted(false);
449 487
        button.setContentAreaFilled(false);
450 488
        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
489
        String id = Objects.toString(action.getValue(Action.ACTION_COMMAND_KEY), null);
490
        if( !StringUtils.isEmpty(id) ) {
491
            this.otherButtons.put(id, button);
492
        }
451 493
        this.othersButtons.add(button);
452 494
    }
453 495

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformset/simpletable/SimpleTableJDynFormSet.java
197 197
    public void addAction(Action action) {
198 198
        logger.info("AddAction not implemented over SimpleTableJDynFormSet.");
199 199
    }
200

  
201
    @Override
202
    public void setActionEnabled(String action, boolean enabled) {
203
        logger.info("setActionEnabled not implemented over SimpleTableJDynFormSet.");
204
    }
205

  
206
    @Override
207
    public void setActionVisible(String action, boolean visible) {
208
        logger.info("setActionVisible not implemented over SimpleTableJDynFormSet.");
209
    }
210

  
211
    @Override
212
    public boolean isActionEnabled(String action) {
213
        logger.info("isActionEnabled not implemented over SimpleTableJDynFormSet.");
214
        return true;
215
    }
216

  
217
    @Override
218
    public boolean isActionVisible(String action) {
219
        logger.info("isActionVisible not implemented over SimpleTableJDynFormSet.");
220
        return true;
221
    }
200 222
    
201 223
    public static class DynObjectListTableModel implements TableModel{
202 224
    	
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/pom.xml
44 44
            <artifactId>formsrt</artifactId>
45 45
            <scope>compile</scope>
46 46
        </dependency>
47
        <dependency>
48
            <groupId>commons-codec</groupId>
49
            <artifactId>commons-codec</artifactId>
50
            <scope>compile</scope>
51
        </dependency>
47 52
    </dependencies>
48 53
</project>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynObjectManager.java
802 802
            targetField.copyFrom(sourceField);
803 803
        }
804 804
        try {
805
            for (DynMethod sourceMethod : source.getDynMethods()) {
806
                target.addDynMethod(sourceMethod);
805
            DynMethod[] x = source.getDynMethods();
806
            if( x!=null ) {
807
                for (DynMethod sourceMethod : x) {
808
                    target.addDynMethod(sourceMethod);
809
                }
807 810
            }
808 811
        } catch (DynMethodException ex) {
809 812
        }
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynField.java
161 161
            if( other2.isAvailableValuesCalculated() ) {
162 162
                this.availableValuesMethod = other2.getAvailableValuesMethod();
163 163
            } else {
164
                this.availableValues = other.getAvailableValues().clone();
164
                DynObjectValueItem[] x = other.getAvailableValues();
165
                if( x != null ) {
166
                this.availableValues = x.clone();
167
                }
165 168
            }
166 169
            
167 170
            this.setType(other.getDataType());
168 171
            this.setClassOfValue(other2.getClassOfValue());
169 172
            this.setClassOfValue(other2.getDynClassOfValue());
170 173
            
171
            this.setTypeOfItems(other2.getTypeOfItems());
172
            this.setClassOfItems(other2.getClassOfItems());
173
            this.setClassOfItems(other2.getDynClassOfItems());
174
            this.itemsType.setType(other2.getTypeOfItems());
175
            this.itemsType.setClassOfValue(other2.getClassOfItems());
176
            this.itemsType.setClassOfValue(other2.getDynClassOfItems());
174 177
        }
175 178

  
176 179
    }

Also available in: Unified diff