Revision 1317

View differences:

org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultJDynForm.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.tools.dynform.impl;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Component;
27
import java.awt.Dimension;
28
import java.awt.event.MouseAdapter;
29
import java.awt.event.MouseEvent;
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.HashSet;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Set;
37

  
38
import javax.swing.Action;
39
import javax.swing.BorderFactory;
40
import javax.swing.JComponent;
41
import javax.swing.JLabel;
42
import javax.swing.JOptionPane;
43
import javax.swing.JPanel;
44
import javax.swing.JScrollPane;
45
import javax.swing.JTabbedPane;
46
import javax.swing.JViewport;
47

  
48
import org.apache.commons.lang3.StringUtils;
49
import org.gvsig.tools.ToolsLocator;
50
import org.gvsig.tools.dataTypes.CoercionException;
51
import org.gvsig.tools.dataTypes.DataType;
52
import org.gvsig.tools.dataTypes.DataTypes;
53
import org.gvsig.tools.dynform.DynFormDefinition;
54
import org.gvsig.tools.dynform.DynFormFieldDefinition;
55
import org.gvsig.tools.dynform.JDynForm;
56
import org.gvsig.tools.dynform.JDynFormField;
57
import org.gvsig.tools.dynform.JDynFormField.JDynFormFieldListener;
58
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
59
import org.gvsig.tools.dynform.spi.dynformfield.SupportPopupMenu;
60
import org.gvsig.tools.dynobject.DynClass;
61
import org.gvsig.tools.dynobject.DynField;
62
import org.gvsig.tools.dynobject.DynField_v2;
63
import org.gvsig.tools.dynobject.DynObject;
64
import org.gvsig.tools.service.ServiceException;
65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67

  
68
import com.jgoodies.forms.builder.DefaultFormBuilder;
69
import com.jgoodies.forms.layout.FormLayout;
70
import com.jgoodies.forms.layout.RowSpec;
71
import java.util.Collection;
72
import java.util.Map.Entry;
73
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
74

  
75
@SuppressWarnings({"unchecked", "rawtypes"})
76
public class DefaultJDynForm implements JDynForm, JDynFormFieldListener {
77

  
78
    protected static final Logger logger = LoggerFactory
79
            .getLogger(DefaultJDynForm.class);
80

  
81
    private int formWidth = 320;
82
    private int formHeight = 540;
83

  
84
    private DefaultDynFormManager manager = null;
85
    private DynFormDefinition definition = null;
86
    private int layoutMode = USE_PLAIN;
87
    private JComponent contents = null;
88
    private Map components = null;
89
    private JLabel jlabel_messages = null;
90
    private boolean readOnly = false;
91
    private Set listeners = null;
92
    private DynObject values = null;
93
    private boolean useScrollBars = true;
94

  
95
    private Map customActions;
96

  
97
    public DefaultJDynForm(DefaultDynFormManager manager, DynFormDefinition definition) throws ServiceException {
98
        this.manager = manager;
99
        this.definition = definition;
100
        this.components = new HashMap();
101
        this.listeners = new HashSet();
102
        this.customActions = new HashMap<String, List<Action>>();
103
        if (definition.getTags().has("LayoutMode")) {
104
            try {
105
                this.layoutMode = definition.getTags().getInt("LayoutMode");
106
            } catch (CoercionException e) {
107
                // Ignorada
108
            }
109
        }
110
    }
111

  
112
    public DynFormSPIManager getServiceManager() {
113
        return this.manager.getServiceManager();
114
    }
115

  
116
    public JComponent asJComponent() {
117
        if (this.contents == null) {
118
            try {
119
                this.initComponents();
120
            } catch (ServiceException e) {
121
                throw new RuntimeException(e.getLocalizedMessage(), e);
122
            }
123
        }
124
        return this.contents;
125
    }
126

  
127
    public void addListener(JDynFormListener listener) {
128
        this.listeners.add(listener);
129
    }
130

  
131
    public void removeListener(JDynFormListener listener) {
132
        this.listeners.remove(listener);
133
    }
134

  
135
    protected void fireMessageEvent(String message) {
136
        Iterator it = this.listeners.iterator();
137
        while (it.hasNext()) {
138
            JDynFormListener listener = (JDynFormListener) it.next();
139
            try {
140
                listener.message(message);
141
            } catch (Exception ex) {
142
                logger.info("Error calling listener " + listener.toString()
143
                        + "(" + listener.getClass().getName() + ") from "
144
                        + this.toString() + "(" + this.getClass().getName()
145
                        + ").", ex);
146
            }
147
        }
148
    }
149

  
150
    protected void fireFieldChangeEvent(JDynFormField field) {
151
        Iterator it = this.listeners.iterator();
152
        while (it.hasNext()) {
153
            JDynFormListener listener = (JDynFormListener) it.next();
154
            try {
155
                listener.fieldChanged(field);
156
            } catch (Exception ex) {
157
                logger.info("Error calling listener " + listener.toString()
158
                        + "(" + listener.getClass().getName() + ") from "
159
                        + this.toString() + "(" + this.getClass().getName()
160
                        + ").", ex);
161
            }
162
        }
163
    }
164

  
165
    public JLabel getMessagesJLabel() {
166
        if (this.jlabel_messages == null) {
167
            this.jlabel_messages = new JLabel();
168
            this.jlabel_messages.addMouseListener(new MouseAdapter() {
169
                public void mouseClicked(MouseEvent evt) {
170
                    int count = evt.getClickCount();
171
                    if (count == 2) {
172
                        JOptionPane.showMessageDialog(contents, jlabel_messages.getText(), "Status", JOptionPane.INFORMATION_MESSAGE);
173
                    }
174
                }
175
            });
176
        }
177
        return this.jlabel_messages;
178
    }
179

  
180
    public void setShowMessageStatus(boolean showMessageStatus) {
181
        this.getMessagesJLabel().setVisible(showMessageStatus);
182
    }
183

  
184
    public boolean isShowMessageStatus() {
185
        return this.getMessagesJLabel().isVisible();
186
    }
187

  
188
    public void message() {
189
        this.getMessagesJLabel().setText(" ");
190
    }
191

  
192
    public void message(String msg) {
193
        this.getMessagesJLabel().setText(msg);
194
        fireMessageEvent(msg);
195
    }
196

  
197
    private void initComponents() throws ServiceException {
198
        switch (this.layoutMode) {
199
            case USE_PLAIN:
200
            case USE_TREE:
201
            default:
202
                initComponentsPlain();
203
                break;
204
            case USE_TABS:
205
                initComponentsUseTabs();
206
                break;
207
            case USE_SEPARATORS:
208
                initComponentsUseSeparators();
209
                break;
210
        }
211
        if (this.values != null) {
212
            this.setValues(values);
213
        }
214
        message();
215
    }
216

  
217
    private void initComponentsPlain() throws ServiceException {
218
        FormLayout layout = new FormLayout(
219
                "left:pref,  8px,  fill:80dlu:grow", "pref");
220

  
221
        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
222
        builder.setDefaultRowSpec(new RowSpec(
223
                RowSpec.TOP,
224
                builder.getLayout().getRowSpec(1).getSize(),
225
                builder.getLayout().getRowSpec(1).getResizeWeight()));
226

  
227
        List fields = this.definition.getDefinitions();
228
        Iterator it = fields.iterator();
229
        while (it.hasNext()) {
230
            DynFormFieldDefinition fieldDefinition = (DynFormFieldDefinition) it.next();
231
            if (fieldDefinition.isHidden()) {
232
                continue;
233
            }
234
            JDynFormField jfield = getServiceManager().createJDynFormField(fieldDefinition, null);
235
            if( jfield instanceof AbstractJDynFormField ) {
236
                ((AbstractJDynFormField)jfield).setForm(this);
237
            }
238
            jfield.setReadOnly(this.readOnly);
239
            jfield.addListener(this);
240
            if (this.readOnly) {
241
                jfield.setReadOnly(readOnly);
242
            }
243
            builder.append(jfield.getJLabel(), jfield.asJComponent());
244

  
245
            this.components.put(jfield.getName(), jfield);
246
        }
247
        this.contents = addScrollsAndMessageBar(builder.getPanel());
248
    }
249

  
250
    private void initComponentsUseSeparators() throws ServiceException {
251
        List groups = this.definition.getGroups();
252

  
253
        FormLayout layout = new FormLayout(
254
                "left:pref,  8px,  fill:80dlu:grow", "pref");
255

  
256
        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
257
        builder.setDefaultRowSpec(new RowSpec(
258
                RowSpec.TOP,
259
                builder.getLayout().getRowSpec(1).getSize(),
260
                builder.getLayout().getRowSpec(1).getResizeWeight()));
261

  
262
        for (int i = 0; i < groups.size(); i++) {
263
            String group = (String) groups.get(i);
264
            builder.appendSeparator(group);
265
            List fields = this.definition.getDefinitions(group);
266
            Iterator it = fields.iterator();
267
            while (it.hasNext()) {
268
                DynFormFieldDefinition fieldDefinition = (DynFormFieldDefinition) it.next();
269
                if (fieldDefinition.isHidden()) {
270
                    continue;
271
                }
272
                JDynFormField jfield = getServiceManager().createJDynFormField(fieldDefinition, null);
273
                if( jfield instanceof AbstractJDynFormField ) {
274
                    ((AbstractJDynFormField)jfield).setForm(this);
275
                }
276
                jfield.addListener(this);
277
                if (this.readOnly) {
278
                    jfield.setReadOnly(readOnly);
279
                }
280

  
281
                List<Action> customActions = getCustomFields(fieldDefinition.getDataType());
282

  
283
                if (customActions != null && !customActions.isEmpty()) {
284
                    Iterator it2 = customActions.iterator();
285
                    while (it2.hasNext()) {
286
                        Object obj = it2.next();
287
                        if (obj != null) {
288
                            Action act = (Action) obj;
289
                            jfield.addActionToPopupMenu((String) act.getValue(Action.NAME), act);
290
                        } else {
291
                            jfield.addSeparatorToPopupMenu();
292
                        }
293
                    }
294
                }
295

  
296
                builder.append(jfield.getJLabel(), jfield.asJComponent());
297

  
298
                this.components.put(jfield.getName(), jfield);
299
            }
300
        }
301
        this.contents = addScrollsAndMessageBar(builder.getPanel());
302
    }
303

  
304
    private void initComponentsUseTabs() throws ServiceException {
305

  
306
        JTabbedPane tabbedPane = new JTabbedPane();
307
        if (definition.getTags().has("TabPlacement")) {
308
            try {
309
                tabbedPane.setTabPlacement(definition.getTags().getInt("TabPlacement"));
310
            } catch (Exception e) {
311
                // Ignorada
312
            }
313
        }
314
        List groups = this.definition.getGroups();
315

  
316
        for (int i = 0; i < groups.size(); i++) {
317
            String group = (String) groups.get(i);
318

  
319
            FormLayout layout = new FormLayout(
320
                    "left:pref,  8px,  fill:80dlu:grow", "pref");
321

  
322
            DefaultFormBuilder builder = new DefaultFormBuilder(layout);
323
            builder.defaultRowSpec(new RowSpec(
324
                    RowSpec.TOP,
325
                    builder.getLayout().getRowSpec(1).getSize(),
326
                    builder.getLayout().getRowSpec(1).getResizeWeight()));
327

  
328
            List fields = this.definition.getDefinitions(group);
329
            Iterator it = fields.iterator();
330
            while (it.hasNext()) {
331
                DynFormFieldDefinition fieldDefinition = (DynFormFieldDefinition) it.next();
332
                if (fieldDefinition.isHidden()) {
333
                    continue;
334
                }
335
                JDynFormField jfield = getServiceManager().createJDynFormField(fieldDefinition, null);
336
                if( jfield instanceof AbstractJDynFormField ) {
337
                    ((AbstractJDynFormField)jfield).setForm(this);
338
                }
339
                jfield.setReadOnly(this.readOnly);
340
                jfield.addListener(this);
341
                if (this.readOnly) {
342
                    jfield.setReadOnly(readOnly);
343
                }
344

  
345
                builder.append(jfield.getJLabel(), jfield.asJComponent());
346

  
347
                this.components.put(jfield.getName(), jfield);
348
            }
349
            String tablabel = group;
350
            if (StringUtils.isEmpty(tablabel)) {
351
                tablabel = ToolsLocator.getI18nManager().getTranslation("General");
352
            }
353
            tabbedPane.addTab(tablabel, builder.getPanel());
354
        }
355

  
356
        try {
357
            String defaultGroupName = (String) this.definition.getTags().get("defaultGroup", DataTypes.STRING);
358
            List<String> groupsNames = this.definition.getGroups();
359
            int groupIndex = groupsNames.indexOf(defaultGroupName);
360
            if( groupIndex>=0 ) {
361
                tabbedPane.setSelectedIndex(groupIndex);
362
            }
363
        } catch (Exception ex) {
364
            // Ignore errors and don't set a tab by default
365
        }
366

  
367
        this.contents = addScrollsAndMessageBar(tabbedPane);
368
    }
369

  
370
    private List<Action> getCustomFields(DataType dataType) {
371
        return (List<Action>) customActions.get(dataType.getName());
372
    }
373

  
374
    private JPanel addScrollsAndMessageBar(JComponent formPanel) {
375
        formPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
376
        JScrollPane scroll = new JScrollPane(formPanel);
377
        if (useScrollBars) {
378
            scroll.setPreferredSize(new Dimension(formWidth, formHeight));
379
        } else {
380
            scroll.setPreferredSize(formPanel.getPreferredSize());
381
        }
382
        scroll.setBorder(BorderFactory.createEmptyBorder());
383

  
384
        JPanel jpanel = new JPanel();
385
        jpanel.setLayout(new BorderLayout());
386
        jpanel.add(scroll, BorderLayout.CENTER);
387
        jpanel.add(getMessagesJLabel(), BorderLayout.PAGE_END);
388

  
389
        return jpanel;
390
    }
391

  
392
    public int getLayoutMode() {
393
        return this.layoutMode;
394
    }
395

  
396
    public void setLayoutMode(int layoutMode) {
397
        if (layoutMode < 0 || layoutMode > USE_SEPARATORS) {
398
            throw new IllegalArgumentException("layoutMode (" + layoutMode + ") out of range. Valid values are 0 .. " + USE_SEPARATORS + ".");
399
        }
400
        this.layoutMode = layoutMode;
401
    }
402

  
403
    public void setValues(DynObject values) {
404
        /*
405
         * TODO: Probablemente fuese mas acertado recorrer los controles de
406
         * components y a partir de ellos acceder a los valores del DynObject
407
         * recivido. Eso permitiria trabajar mejor con herencia de DynObject.
408
         * Habria que hacer lo mismo con el getValues.
409
         */
410
        if (this.contents == null) {
411
            this.values = values;
412
            return;
413
        }
414
        DynClass def = values.getDynClass();
415
        DynField[] fields = def.getDynFields();
416
        for (int i = 0; i < fields.length; i++) {
417
            String name = fields[i].getName();
418
            if (name == null || name.isEmpty()) {
419
                logger.warn("Field name " + i + " of '" + def.getFullName() + "' is null or empty ");
420
                continue;
421
            }
422
            JDynFormField jfield = (JDynFormField) this.getField(name);
423
            if (jfield == null) {
424
                logger.warn("Can't retrieve form field asociated to the field '" + name + "' of class '" + def.getFullName() + "'.");
425
                continue;
426
            }
427
            if (values.getDynValue(name) == null) {
428
                if (fields[i].getDataType().getType() == DataTypes.LIST) {
429
                    try {
430
                        if (((DynField_v2) fields[i]).getDynClassOfItems() != null) {
431
                            values.setDynValue(name, new ArrayList<DynObject>());
432
                        }
433
                    } catch (Exception e) {
434
                        logger.warn("Problems initializing the DynObject List", e);
435
                    }
436
                }
437
            }
438
            jfield.setValue(values.getDynValue(name));
439
        }
440
    }
441

  
442
    public void getValues(DynObject values) {
443
        if (values == null) {
444
            return;
445
        }
446
        DynField[] fields = values.getDynClass().getDynFields();
447
        for (int i = 0; i < fields.length; i++) {
448
            String name = fields[i].getName();
449
            JDynFormField jfield = (JDynFormField) this.getField(name);
450
            if (jfield != null) {
451
                try {
452
                    Object value = jfield.getValue();
453
                    values.setDynValue(name, value);
454

  
455
                } catch (Exception ex) {
456
                    logger.warn("Can't get value of field '" + name + "'.", ex);
457
                }
458
            }
459
        }
460
    }
461

  
462
    public boolean hasValidValues() {
463
        Iterator it = this.getFieldsIterator();
464
        while (it.hasNext()) {
465
            JDynFormField jfield = (JDynFormField) it.next();
466
            if (!jfield.hasValidValue()) {
467
                return false;
468
            }
469
        }
470

  
471
        return true;
472
    }
473

  
474
    public boolean hasValidValues(List<String> fieldsName) {
475
        if (fieldsName == null) {
476
            fieldsName = new ArrayList<String>();
477
        }
478

  
479
        Iterator it = this.getFieldsIterator();
480
        while (it.hasNext()) {
481
            JDynFormField jfield = (JDynFormField) it.next();
482
            if (!jfield.hasValidValue()) {
483
                fieldsName.add(jfield.getName());
484
            }
485
        }
486

  
487
        if (!fieldsName.isEmpty()) {
488
            return false;
489
        } else {
490
            return true;
491
        }
492
    }
493

  
494
    public boolean isModified() {
495
        Iterator it = this.getFieldsIterator();
496
        while (it.hasNext()) {
497
            JDynFormField jfield = (JDynFormField) it.next();
498
            if (jfield.isModified()) {
499
                return true;
500
            }
501
        }
502
        return false;
503
    }
504

  
505
    public void fieldEnter(JDynFormField field) {
506
        message(field.getDefinition().getDescription());
507
    }
508

  
509
    public void fieldExit(JDynFormField field) {
510
        message();
511
    }
512

  
513
    public void message(JDynFormField field, String message) {
514
        message(message);
515
    }
516

  
517
    public void fieldChanged(JDynFormField field) {
518
        fireFieldChangeEvent(field);
519
    }
520

  
521
    public boolean isReadOnly() {
522
        return readOnly;
523
    }
524

  
525
    public void setReadOnly(boolean readOnly) {
526
        this.readOnly = readOnly;
527
        if (this.contents != null) {
528
            Iterator it = this.getFieldsIterator();
529
            while (it.hasNext()) {
530
                JDynFormField field = (JDynFormField) it.next();
531
                field.setReadOnly(readOnly);
532
            }
533
        }
534
    }
535

  
536
    public int getFormWidth() {
537
        if (this.contents == null) {
538
            return this.formWidth;
539
        } else {
540
            JViewport port = ((JScrollPane) this.asJComponent()).getViewport();
541
            Component comp = (Component) port.getView();
542
            return comp.getWidth();
543
        }
544
    }
545

  
546
    public int getFormHeight() {
547
        if (this.contents == null) {
548
            return this.formHeight;
549
        } else {
550
            JViewport port = ((JScrollPane) this.asJComponent()).getViewport();
551
            Component comp = (Component) port.getView();
552
            return comp.getHeight();
553
        }
554
    }
555

  
556
    public void setFormSize(int width, int height) {
557
        this.formHeight = height;
558
        this.formWidth = width;
559
        if (this.contents != null) {
560
            this.asJComponent().setPreferredSize(new Dimension(width, height));
561
        }
562
    }
563

  
564
    public void addActionToPopupMenu(DataType tipo, String name, Action action) {
565
        if (this.contents == null) {
566
            List<Action> acts = this.getCustomFields(tipo);
567
            action.putValue(Action.NAME, name);
568
            if (acts == null) {
569
                List aux = new ArrayList<Action>();
570
                aux.add(action);
571
                customActions.put(tipo.getName(), aux);
572
            } else {
573
                acts.add(action);
574
            }
575
        } else {
576
            Iterator it = this.components.keySet().iterator();
577
            while (it.hasNext()) {
578
                String key = (String) it.next();
579
                Object obj = this.components.get(key);
580
                if (obj instanceof JDynFormField) {
581
                    JDynFormField field = (JDynFormField) obj;
582
                    if (tipo == field.getDefinition().getDataType()) {
583
                        if (field.asJComponent() instanceof SupportPopupMenu) {
584
                            field.addActionToPopupMenu(
585
                                    name,
586
                                    action);
587
                        }
588
                    }
589
                }
590
            }
591
        }
592
    }
593

  
594
    public void addSeparatorToPopupMenu(DataType tipo) {
595
        if (this.contents == null) {
596
            List<Action> acts = this.getCustomFields(tipo);
597
            if (acts == null) {
598
                List aux = new ArrayList<Action>();
599
                aux.add(null);
600
                customActions.put(tipo.getName(), aux);
601
            } else {
602
                acts.add(null);
603
            }
604
        } else {
605
            Iterator it = this.components.keySet().iterator();
606
            while (it.hasNext()) {
607
                String key = (String) it.next();
608
                Object obj = this.components.get(key);
609
                if (obj instanceof JDynFormField) {
610
                    JDynFormField field = (JDynFormField) obj;
611
                    if (tipo == field.getDefinition().getDataType()) {
612
                        if (field.asJComponent() instanceof SupportPopupMenu) {
613
                            ((SupportPopupMenu) field.asJComponent()).addSeparatorToPopupMenu();
614
                        }
615
                    }
616
                }
617
            }
618
        }
619
    }
620

  
621
    public Object getValue(String fieldName) {
622
        JDynFormField field = (JDynFormField) this.getField(fieldName);
623
        return field.getValue();
624
    }
625

  
626
    public void setValue(String fieldName, Object value) {
627
        JDynFormField field = (JDynFormField) this.getField(fieldName);
628
        try {
629
            value = field.getDefinition().getDataType().coerce(value);
630
        } catch (CoercionException e) {
631
            String msg = "Invalid value '" + ((value == null) ? "(null)" : value.toString()) + "' for field '" + fieldName + "'.";
632
            logger.warn(msg, e);
633
            throw new RuntimeException(msg, e);
634
        }
635
        field.setValue(value);
636
    }
637

  
638
    public JDynFormField getField(String fieldName) {
639
        JDynFormField field = (JDynFormField) this.components.get(fieldName);
640
        return field;
641
    }
642

  
643
    public Iterator getFieldsIterator() {
644
        if (this.contents == null) {
645
            try {
646
                this.initComponents();
647
            } catch (ServiceException e) {
648
                throw new RuntimeException(e.getLocalizedMessage(), e);
649
            }
650
        }
651
        return this.components.values().iterator();
652
    }
653

  
654
    public DynFormDefinition getDefinition() {
655
        return this.definition;
656
    }
657

  
658
    public void setUseScrollBars(boolean usesScrolls) {
659
        this.useScrollBars = usesScrolls;
660
    }
661

  
662
    public boolean getUseScrollBars() {
663
        return useScrollBars;
664
    }
665

  
666
    public void clear() {
667
        Iterator it = this.components.entrySet().iterator();
668
        while( it.hasNext() ) {
669
            Entry entry = (Entry)it.next();
670
            ((JDynFormField)(entry.getValue())).clear();
671
        }
672
    }
673

  
674
    public Collection getShowFields() {
675
        return this.components.values();
676
    }
677

  
678

  
679
}
0 680

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

  
26
import java.util.HashMap;
27
import java.util.List;
28
import java.util.Map;
29

  
30
import org.gvsig.tools.dispose.DisposableIterator;
31
import org.gvsig.tools.dynform.DynFormDefinition;
32
import org.gvsig.tools.dynform.DynFormManager;
33
import org.gvsig.tools.dynform.JDynForm;
34
import org.gvsig.tools.dynform.JDynFormSet;
35
import org.gvsig.tools.dynform.spi.DynFormSPILocator;
36
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
37
import org.gvsig.tools.dynobject.DynField;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.tools.dynobject.DynObjectSet;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.dynobject.DynStruct_v2;
42
import org.gvsig.tools.service.Service;
43
import org.gvsig.tools.service.ServiceException;
44

  
45
@SuppressWarnings({"unchecked", "rawtypes"})
46
public class DefaultDynFormManager implements DynFormManager {
47

  
48
    DynFormSPIManager serviceManager = null;
49

  
50
    private Map definitions = null;
51
    private String defaultJDynFormSetname = "Subform";
52
            
53
    public DefaultDynFormManager() {
54
    }
55

  
56
    public DynFormSPIManager getServiceManager() {
57
        if ( serviceManager == null ) {
58
            serviceManager = DynFormSPILocator.getDynFormSPIManager();
59
        }
60
        return serviceManager;
61
    }
62

  
63
    public Map getDefinitions() {
64
        if ( this.definitions == null ) {
65
            this.definitions = new HashMap();
66
        }
67
        return this.definitions;
68
    }
69

  
70
    public Service getService(DynObject parameters) throws ServiceException {
71
        Service service = this.serviceManager.createService(parameters);
72
        return service;
73
    }
74

  
75
    public DynFormDefinition getDefinition(String name) {
76
        DefaultDynFormDefinition x = null;
77
        x = (DefaultDynFormDefinition) this.getDefinitions().get(name);
78
        if ( x == null ) {
79
            x = new DefaultDynFormDefinition(name, this);
80
            this.getDefinitions().put(x.getName(), x);
81
        }
82
        return x;
83
    }
84

  
85
    public DynFormDefinition getDefinition(DynStruct definition) {
86
        String name = definition.getName();
87
        DefaultDynFormDefinition x = null;
88
        x = (DefaultDynFormDefinition) this.getDefinitions().get(name);
89
        if ( x == null ) {
90
            x = new DefaultDynFormDefinition(name, this);
91
            this.getDefinitions().put(x.getName(), x);
92
            DynField[] fields = definition.getDynFields();
93
            for ( int i = 0; i < fields.length; i++ ) {
94
                x.add(fields[i]);
95
            }
96
        }
97
        if ( definition instanceof DynStruct_v2 ) {
98
            x.getTags().add(((DynStruct_v2) definition).getTags());
99
        }
100
        x.setElementsType(definition);
101
        return x;
102
    }
103

  
104
    public DynFormDefinition getDefinition(DynObject obj) {
105
        return this.getDefinition(obj.getDynClass());
106
    }
107

  
108
    public JDynForm createJDynForm(DynFormDefinition definition) throws ServiceException {
109
        JDynForm x = new DefaultJDynForm(this, definition);
110
        return x;
111
    }
112

  
113
    public JDynForm createJDynForm(DynStruct struct) throws ServiceException {
114
        DynFormDefinition definition = this.getDefinition(struct);
115
        JDynForm x = new DefaultJDynForm(this, definition);
116
        return x;
117
    }
118

  
119
    public JDynForm createJDynForm(DynObject obj) throws ServiceException {
120
        DynFormDefinition definition = this.getDefinition(obj);
121
        JDynForm x = new DefaultJDynForm(this, definition);
122
        x.setValues(obj);
123
        return x;
124
    }
125

  
126
    public JDynFormSet createJDynFormSet(DynFormDefinition definition)
127
            throws ServiceException {
128
        return this.createJDynFormSet(this.defaultJDynFormSetname, definition);
129
    }
130

  
131
    public JDynFormSet createJDynFormSet(DynStruct struct) throws ServiceException {
132
        return this.createJDynFormSet(this.defaultJDynFormSetname, struct);
133
    }
134

  
135
    public JDynFormSet createJDynFormSet(DynObjectSet data)
136
            throws ServiceException {
137
        return this.createJDynFormSet(this.defaultJDynFormSetname, data);
138
    }
139

  
140
    public JDynFormSet createJDynFormSet(List data)
141
            throws ServiceException {
142
        return this.createJDynFormSet(this.defaultJDynFormSetname, data);
143
    }
144

  
145
    public DynObject createServiceParameters(String name)
146
            throws ServiceException {
147
        DynObject params = this.getServiceManager().createServiceParameters(name);
148
        return params;
149
    }
150

  
151
    public JDynFormSet createJDynFormSet(String name, DynFormDefinition definition) throws ServiceException {
152
        DynObject params = this.createServiceParameters(name);
153
        params.setDynValue("definition", definition);
154
        JDynFormSet formset = (JDynFormSet) this.getServiceManager().getService(params);
155
        return formset;
156
    }
157

  
158
    public JDynFormSet createJDynFormSet(String name, DynStruct struct) throws ServiceException {
159
        DynFormDefinition definition = this.getDefinition(struct);
160
        return this.createJDynFormSet(name, definition);
161
    }
162

  
163
    public JDynFormSet createJDynFormSet(String name, List data) throws ServiceException {
164
        if ( data.size() < 1 ) {
165
            throw new IllegalArgumentException("The DynObjectSet not has elements.");
166
        }
167
        DynObject obj = (DynObject) data.get(0);
168
        JDynFormSet formset = this.createJDynFormSet(name, obj.getDynClass());
169
        formset.setValues(data);
170
        return formset;
171
    }
172

  
173
    public JDynFormSet createJDynFormSet(String name, DynObjectSet data) throws ServiceException {
174
        DynObject obj = null;
175
        DisposableIterator it = null;
176
        try {
177
            if ( data.getSize() < 1 ) {
178
                throw new IllegalArgumentException("The DynObjectSet not has elements.");
179
            }
180
            it = data.iterator();
181
            obj = (DynObject) it.next();
182
        } catch (Exception e) {
183
            throw new RuntimeException(e.getLocalizedMessage(), e);
184
        } finally {
185
            if ( it != null ) {
186
                it.dispose();
187
            }
188
        }
189
        JDynFormSet formset = this.createJDynFormSet(name, obj.getDynClass());
190
        formset.setValues(data);
191
        return formset;
192
    }
193

  
194
    public String getDefaultJDynFormSetName() {
195
        return this.defaultJDynFormSetname;
196
    }
197

  
198
    public void setDefaultJDynFormSetName(String name) {
199
        this.defaultJDynFormSetname = name;
200
    }
201
    
202

  
203
}
0 204

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormFieldDefinition.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

  
26
import java.util.Iterator;
27

  
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynform.DynFormFieldDefinition;
30
import org.gvsig.tools.dynobject.DynField;
31
import org.gvsig.tools.dynobject.DynField_v2;
32
import org.gvsig.tools.dynobject.DynObjectManager;
33
import org.gvsig.tools.dynobject.impl.DefaultDynField;
34
import org.gvsig.tools.service.Manager;
35

  
36
public class DefaultDynFormFieldDefinition extends DefaultDynField implements DynFormFieldDefinition {
37

  
38
	private DefaultDynFormManager manager = null;
39
	private String label = null;
40
	private String groups = null;
41
	
42
	public DefaultDynFormFieldDefinition(DefaultDynFormManager manager, DynField definition) {
43
		super(definition.getName(), 
44
			definition.getType(), 
45
			definition.getDefaultValue(),
46
			definition.isPersistent(),
47
			definition.isMandatory());
48
		this.setHidden(definition.isHidden());
49
		this.setReadOnly(definition.isReadOnly());
50
		this.setGroups(definition.getGroup());
51
		this.setDescription(definition.getDescription());
52
		this.setMaxValue(definition.getMaxValue());
53
		this.setMinValue(definition.getMinValue());
54
		this.setOrder(definition.getOder());
55
                this.setSubtype(definition.getSubtype());
56
		
57
		this.setAvailableValues(definition.getAvailableValues());
58
		
59
		this.manager = manager;
60
		DynObjectManager dynManager = ToolsLocator.getDynObjectManager(); 
61
		this.label = (String) dynManager.getAttributeValue(definition, "label");
62
		if(definition instanceof DynField_v2){
63
			this.setClassOfValue(((DynField_v2)definition).getDynClassOfValue());
64
			this.setClassOfValue(((DynField_v2)definition).getClassOfValue());
65
                        if( definition.isContainer() ) {
66
                            this.setClassOfItems(((DynField_v2)definition).getDynClassOfItems());
67
                            this.setClassOfItems(((DynField_v2)definition).getClassOfItems());
68
                            this.setTypeOfItems(((DynField_v2)definition).getTypeOfItems());
69
                        }
70
			this.getTags().add(((DynField_v2)definition).getTags());
71

  
72
		}else{
73
			this.setSubtype(definition.getSubtype());
74
		}
75
	}
76

  
77
	public Manager getManager() {
78
		return this.manager;
79
	}
80

  
81
	public String getLabel() {
82
		return this.label;
83
	}
84

  
85
	public DynField setLabel(String label) {
86
		this.label = label;
87
		return this;
88
	}
89
	
90
	public String getGroup() {
91
		if( this.groups==null ) {
92
			return null;
93
		}
94
		String parts[] = this.groups.split("/");
95
		return parts[0];
96
	}
97

  
98
	public String getSubgroup() {
99
		String parts[] = this.groups.split("/");
100
		if( parts.length<=1 ) {
101
			return null;
102
		}
103
		return parts[1];
104
	}
105

  
106
	public String getGroups() {
107
		return this.groups;
108
	}
109

  
110
	public void setGroups(String groups) {
111
		this.groups = groups;
112
	}
113
}
0 114

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultVisitableSet.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

  
26
import java.util.HashSet;
27
import java.util.Iterator;
28

  
29
import org.gvsig.tools.dynform.AbortActionException;
30
import org.gvsig.tools.dynform.spi.dynformfield.VisitableSet;
31
import org.gvsig.tools.exception.BaseException;
32
import org.gvsig.tools.visitor.Visitor;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

  
36
public class DefaultVisitableSet extends HashSet implements VisitableSet {
37

  
38
	public static final Logger logger = LoggerFactory.getLogger(DefaultVisitableSet.class);
39
	/**
40
	 * 
41
	 */
42
	private static final long serialVersionUID = -5771630108958038764L;
43

  
44
	public void accept(Visitor visitor) throws BaseException {
45
		Iterator it = this.iterator();
46
		while (it.hasNext()) {
47
			Object value = it.next();
48
			try {
49
				visitor.visit(value);
50
			} catch (AbortActionException ex) {
51
				throw ex;
52
			} catch (Exception ex) {
53
				logger.info("Error visiting " + value.toString()
54
						+ "(" + value.getClass().getName() + ") with "
55
						+ visitor.toString() + "(" + visitor.getClass().getName()
56
						+ ").", ex);
57
			}
58
		}
59
	}
60

  
61
}
0 62

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

  
26

  
27
import org.gvsig.tools.dynform.DynFormLibrary;
28
import org.gvsig.tools.dynform.DynFormLocator;
29
import org.gvsig.tools.dynform.spi.DynFormSPILocator;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32

  
33
public class DefaultDynFormLibrary extends AbstractLibrary {
34

  
35
	public void doRegistration() {
36
		super.doRegistration();
37
		registerAsImplementationOf(DynFormLibrary.class);
38
	}
39
	
40
	protected void doInitialize() throws LibraryException {
41
		DynFormLocator.registerDefaultDynFormManager(DefaultDynFormManager.class);
42
		DynFormSPILocator.registerDefaultDynFormSPIManager(DefaultDynFormSPIManager.class);
43
	}
44

  
45
	protected void doPostInitialize() throws LibraryException {
46

  
47
	}
48

  
49
}
0 50

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DynObjectEditor.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 IVER T.I. S.A.   {{Task}}
27
 */
28

  
29
/**
30
 *
31
 */
32
package org.gvsig.tools.dynform.impl;
33

  
34
import java.awt.BorderLayout;
35
import java.awt.Component;
36
import java.awt.Dimension;
37
import java.awt.GridBagConstraints;
38
import java.awt.GridBagLayout;
39
import java.awt.Insets;
40
import java.awt.event.ActionEvent;
41
import java.awt.event.ActionListener;
42

  
43
import javax.swing.JButton;
44
import javax.swing.JLabel;
45
import javax.swing.JPanel;
46

  
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynform.DynFormLocator;
49
import org.gvsig.tools.dynform.JDynForm;
50
import org.gvsig.tools.dynobject.DynObject;
51
import org.gvsig.tools.i18n.I18nManager;
52
import org.gvsig.tools.service.ServiceException;
53
import org.gvsig.tools.swing.api.ToolsSwingLocator;
54
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
55
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
57

  
58
/**
59
 * Editor for a store parameters.
60
 * 
61
 * @author gvSIG Team
62
 * @version $Id$
63
 */
64
public class DynObjectEditor extends JPanel implements ActionListener {
65

  
66
    private static final long serialVersionUID = 23898787077741411L;
67

  
68
    private static final Logger LOG = LoggerFactory
69
        .getLogger(DynObjectEditor.class);
70

  
71
    private String title;
72

  
73
    private JButton botAcept;
74
    private JButton botCancel;
75
    private JButton botRestoreDefaults;
76
    private JPanel panButtons;
77
    private I18nManager i18nManager;
78

  
79
//    private boolean modal;
80

  
81
    private JDynForm form = null;
82
    private DynObject data = null;
83

  
84
    public DynObjectEditor(DynObject parameters, boolean showDefaultsButton)
85
        throws ServiceException {
86
    	this.i18nManager = ToolsLocator.getI18nManager();
87
    	this.data = parameters;
88
    	this.form = DynFormLocator.getDynFormManager().createJDynForm(this.data);
89
    	this.form.setLayoutMode(this.form.USE_TABS);
90
    	this.setLayout(new BorderLayout());
91
        this.add(this.form.asJComponent(), BorderLayout.CENTER);
92
        this.add(getButtonsPanel(showDefaultsButton), BorderLayout.SOUTH);
93
        this.setPreferredSize(new Dimension(500,250));
94
        String s = this.data.getDynClass().getDescription();
95
        if( s==null || s.length()==0 ) {
96
        	s = this.data.getDynClass().getName();
97
        }
98
        this.setTitle(s);
99
    }
100
    
101
    public DynObjectEditor(DynObject parameters) throws ServiceException {
102
        this(parameters, false);
103
    }
104

  
105
    private JPanel getButtonsPanel(boolean add_defaults_button) {
106
        if (this.panButtons == null) {
107
            this.panButtons = new JPanel();
108
            this.panButtons.setLayout(new GridBagLayout());
109
            GridBagConstraints constr = new GridBagConstraints();
110
            constr.anchor = GridBagConstraints.LAST_LINE_END;
111
            constr.fill = GridBagConstraints.HORIZONTAL;
112
            constr.weightx = 1;
113
            constr.weighty = 0;
114
            this.panButtons.add(new JLabel(), constr);
115

  
116
            constr = this.getDefaultParametersConstraints();
117
            constr.fill = GridBagConstraints.NONE;
118
            constr.weightx = 0;
119
            constr.weighty = 0;
120

  
121
            this.panButtons.add(this.getAcceptButton(), constr);
122
            this.panButtons.add(this.getCancelButton(), constr);
123
            if (add_defaults_button) {
124
                this.panButtons.add(this.getRestoreDefaults(), constr);
125
            }
126
        }
127
        return this.panButtons;
128
    }
129

  
130
    private GridBagConstraints getDefaultParametersConstraints() {
131
        GridBagConstraints constr = new GridBagConstraints();
132
        constr.insets = new Insets(2, 2, 2, 2);
133
        constr.ipadx = 2;
134
        constr.ipady = 2;
135
        constr.anchor = GridBagConstraints.PAGE_START;
136
        return constr;
137

  
138
    }
139

  
140
    private JButton getRestoreDefaults() {
141
        if (this.botRestoreDefaults == null) {
142
            this.botRestoreDefaults =
143
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
144
                    i18nManager.getTranslation("restoreDefaults"));
145
            this.botRestoreDefaults.addActionListener(this);
146
        }
147
        return this.botRestoreDefaults;
148
    }
149

  
150
    private JButton getCancelButton() {
151
        if (this.botCancel == null) {
152
            this.botCancel =
153
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
154
                		i18nManager.getTranslation("cancel"));
155
            this.botCancel.addActionListener(this);
156
        }
157
        return this.botCancel;
158
    }
159

  
160
    private JButton getAcceptButton() {
161
        if (this.botAcept == null) {
162
            this.botAcept =
163
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
164
                		i18nManager.getTranslation("accept"));
165
            this.botAcept.addActionListener(this);
166
        }
167
        return this.botAcept;
168
    }
169

  
170
    public void actionPerformed(ActionEvent e) {
171
        Component source = (Component) e.getSource();
172
        if (source == this.botAcept) {
173
        	this.form.getValues(this.data);
174
            this.closeWindow();
175
        } else if (source == this.botCancel) {
176
        	this.closeWindow();
177
        } else if (source == this.botRestoreDefaults) {
178
        	this.form.setValues(this.data);
179
        }
180
    }
181

  
182
    protected void closeWindow() {
183
        LOG.debug("Closing window, values edited: ", this.data);
184
        this.setVisible(false);       
185
    }
186

  
187
    public void editObject(boolean modal) {
188
//        this.modal = modal;
189
        
190
        WindowManager wmanager = ToolsSwingLocator.getWindowManager();
191
        
192
        wmanager.showWindow(this,title,WindowManager.MODE.DIALOG);
193

  
194
//        wmanager.showWindow(this, 
195
//                Messages.getText("explorer_parameters"), 
196
//                WindowManager.MODE.DIALOG);
197
    }
198

  
199
    public String getTitle() {
200
        return title;
201
    }
202

  
203
    public void setTitle(String title) {
204
        this.title = title;
205
    }
206
  
207
    public DynObject getParameters() {
208
    	this.form.getValues(this.data);
209
        return this.data;
210
    }
211
}
0 212

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.70/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultZoomDialog.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.Toolkit;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31

  
32
import javax.swing.BorderFactory;
33
import javax.swing.JButton;
34
import javax.swing.JPanel;
35
import javax.swing.JScrollPane;
36

  
37
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextArea;
38
import org.gvsig.tools.dynform.spi.dynformfield.JZoomDialog;
39

  
40
public class DefaultZoomDialog extends JZoomDialog {
41

  
42
	/**
43
	 * 
44
	 */
45
	private static final long serialVersionUID = 7913363575200612492L;
46
	
47
	private String value = null;
48
	private JCustomTextArea text = null; 
49

  
50
	public DefaultZoomDialog(String title, String value) {
51
		super(title);
52
		this.value = value;
53
		initComponents();
54
		
55
	}
56
	
57
	public void setEditable(boolean editable) {
58
		this.text.setEditable(editable);
59
	}
60
	
61
	private void initComponents() {
62

  
63
		JPanel panel = new JPanel();
64
		panel.setLayout(new BorderLayout()); 
65

  
66
		text = new JCustomTextArea(null, false); 
67
		text.setText(value);
68
		text.setLineWrap(true);
69
		JScrollPane scroll = new JScrollPane(text); 
70
		panel.add(scroll, BorderLayout.CENTER); 
71
		panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
72
		
73
		JPanel p = new JPanel();
74
		
75
		JButton close = new JButton("Close");
76
		close.addActionListener(new ActionListener() {
77
			public void actionPerformed(ActionEvent arg0) {
78
				value = text.getText();
79
				setVisible(false);
80
			}
81
		});
82
		
83
		p.setLayout(new BorderLayout());
84
		p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
85
		p.add(close,BorderLayout.LINE_END);
86

  
87
		panel.add(p, BorderLayout.PAGE_END);
88
		
89
		panel.setPreferredSize(new Dimension(600, 250));
90
		
91
	    this.setContentPane(panel);
92

  
93
	    this.center();
94
		this.pack();
95
	}
96
	
97
	public void center() {
98
	    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
99
	    Dimension size = this.getPreferredSize();
100
	    int x = (int) ((dimension.getWidth() - size.getWidth()) / 2);
101
	    int y = (int) ((dimension.getHeight() - size.getHeight()) / 2);
102
	    this.setLocation(x, y);
103
	}
104
	public String getText() {
105
		return this.value;
106
	}
107
}
0 108

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff