Revision 1100

View differences:

org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <artifactId>org.gvsig.tools.swing.spi</artifactId>
4
    <packaging>jar</packaging>
5
    <name>org.gvsig.tools.swing.spi</name>
6
    <parent>
7
        <groupId>org.gvsig</groupId>
8
        <artifactId>org.gvsig.tools.swing</artifactId>
9
        <version>3.0.30</version>
10
    </parent>
11
    <dependencies>
12
        <dependency>
13
            <groupId>org.gvsig</groupId>
14
            <artifactId>org.gvsig.tools.swing.api</artifactId>
15
        </dependency>
16
    </dependencies>
17
</project>
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractJDynFieldComponent.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 2
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.swing.spi;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.util.ArrayList;
29
import java.util.List;
30

  
31
import javax.swing.BorderFactory;
32
import javax.swing.Box;
33
import javax.swing.BoxLayout;
34
import javax.swing.JButton;
35
import javax.swing.JPanel;
36

  
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dynobject.DynField;
39
import org.gvsig.tools.dynobject.DynObject;
40
import org.gvsig.tools.service.Manager;
41
import org.gvsig.tools.service.ServiceException;
42
import org.gvsig.tools.swing.api.ToolsSwingLocator;
43
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
44
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
45
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
46
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
47

  
48
/**
49
 * Component which is able to render a {@link DynObject} attribute value.
50
 * 
51
 * @author 2010- C?sar Ordi?ana - gvSIG team
52
 */
53
public abstract class AbstractJDynFieldComponent extends AbstractJDynField
54
    implements JDynFieldComponent {
55

  
56
    private static final long serialVersionUID = 7833217085675382320L;
57

  
58
    private final DynObjectSwingManager manager;
59

  
60
    private final List<ValueChangedListener> listeners;
61

  
62
    /**
63
     * Constructor.
64
     * @param writable 
65
     * @param definition 
66
     * 
67
     * @param dynField
68
     *            the field of the {@link DynObject} to render
69
     * @param dynObject
70
     *            the {@link DynObject} with the attribute to render
71
     */
72
	public AbstractJDynFieldComponent(DynField definition, ValueField parent, boolean writable)
73
        throws ServiceException {
74
		super(definition, parent, writable);
75
        listeners = new ArrayList<ValueChangedListener>();
76
        // this.dynObject = dynObject.getDynObject();
77
        manager = ToolsSwingLocator.getDynObjectSwingManager();
78

  
79
        this.init();
80
    }
81

  
82

  
83
    /*
84
     * (non-Javadoc)
85
     * 
86
     * @seeorg.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#
87
     * addValueChangedListener
88
     * (org.gvsig.tools.swing.api.dynobject.ValueChangedListener)
89
     */
90
    @Override
91
    public void addValueChangedListener(ValueChangedListener listener) {
92
        // If it was the first item, we need to
93
        // initialize Component listeners
94
        // add listener to the dynfield set of listeners
95
        listeners.add(listener);
96
        // set supplementary listeners.
97
        this.setJDynFieldComponentListeners();
98
    }
99

  
100
    protected JPanel createBoxLayout(Component component1,
101
        Component component2, Integer marginLeft, Integer marginRight,
102
        JPanel container) {
103
        return this.createBoxRowPanel(container, component1, component2,
104
            marginLeft, marginRight);
105
    }
106

  
107
    /*
108
     * (non-Javadoc)
109
     * 
110
     * @see
111
     * 
112
     * 
113
     * 
114
     * org.gvsig.tools.swing.api.usability.UsabilitySwingManager#createBoxRowPanel
115
     * (javax.swing.JPanel, java.awt.Component, java.awt.Component,
116
     * java.lang.Integer, java.lang.Integer)
117
     */
118
    public JPanel createBoxRowPanel(JPanel panel, Component labelComponent,
119
        Component fieldLabel, Integer marginLeft, Integer marginRight) {
120

  
121
        // Create a panel that uses GridLayout.
122
        JPanel pane = new JPanel();
123
        pane.setLayout(new BoxLayout(pane, BoxLayout.LINE_AXIS));
124
        pane.add(labelComponent);
125
        if (marginLeft != null) {
126
            pane.add(Box.createHorizontalStrut(marginLeft));
127
        }
128

  
129
        if (marginRight != null) {
130
            pane.add(Box.createHorizontalStrut(marginRight));
131
        }
132
        pane.add(fieldLabel, BorderLayout.NORTH);
133
        pane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
134
        return pane;
135
    }
136

  
137
    protected JButton createButton(String text) {
138
        return ToolsSwingLocator.getUsabilitySwingManager().createJToolButton(
139
            this.translate(text));
140
    }
141

  
142
    /*
143
     * (non-Javadoc)
144
     * 
145
     * @seeorg.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#
146
     * raiseValueChangedEvent()
147
     */
148
    @Override
149
    public void fireValueChangedEvent() {
150
        for (ValueChangedListener listener : listeners) {
151
            listener.handleValueChanged(this);
152
        }
153
    }
154

  
155
    public Object getDefaultValue() {
156
        return this.getDynField().getDefaultValue();
157
    }
158

  
159
    protected String getFieldName() {
160
        return this.getDynField().getName();
161
    }
162

  
163
    /*
164
     * (non-Javadoc)
165
     * 
166
     * @see org.gvsig.tools.service.Service#getManager()
167
     */
168
    public Manager getManager() {
169
        return manager;
170
    }
171

  
172
    /**
173
     * @return
174
     */
175
    public abstract Object getValue();
176

  
177
    public boolean isMandatory() {
178
        return this.getDynField().isMandatory();
179
    }
180

  
181
  
182
    /*
183
     * (non-Javadoc)
184
     * 
185
     * @see
186
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isValid()
187
     */
188
    public boolean isValid() {
189
        return this.validate(this.getValue());
190
    }
191

  
192
    /**
193
     * Stores the edited data into the DynObject field.
194
     */
195
    public void saveStatus() {
196
        this.setFieldValue(this.getValue());
197
    }
198

  
199
    /**
200
	 * 
201
	 */
202
    @Override
203
    protected abstract void setJDynFieldComponentListeners();
204

  
205
    protected String translate(String text) {
206
        return ToolsLocator.getI18nManager().getTranslation(text);
207
    }
208
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractSwingServiceFactory.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DynClass;
40
import org.gvsig.tools.service.spi.AbstractServiceFactory;
41

  
42
/**
43
 * 
44
 * The Factory asociated to the swing Tools Service.
45
 * 
46
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
47
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
48
 *         gvSIG Team
49
 * @version $Id$
50
 * 
51
 */
52
public abstract class AbstractSwingServiceFactory extends
53
    AbstractServiceFactory {
54

  
55
    private DynClass dynClassParams;
56
    private DynObjectSwingServiceManager manager;
57

  
58
    /**
59
     * 
60
     * Creates and returns a {@link DynClass} object based on its parameters.
61
     * 
62
     * @return
63
     *         the created {@link DynClass}.
64
     */
65
    protected DynClass getDynClassParams() {
66

  
67
        if (dynClassParams == null) {
68
            dynClassParams =
69
                ToolsLocator.getDynObjectManager().createDynClass(
70
                    this.getFactoryName(), this.getFactoryDescription());
71
        }
72
        return dynClassParams;
73
    }
74

  
75
    /**
76
     * 
77
     * Returns a brief description of this Factory.
78
     * 
79
     * @return
80
     *         the decription String.
81
     */
82

  
83
    public abstract String getFactoryDescription();
84

  
85
    /**
86
     * 
87
     * Returns the factory name.
88
     * 
89
     * @return
90
     *         the factory name String.
91
     */
92
    public abstract String getFactoryName();
93

  
94
    /**
95
     * 
96
     * Returns the factory subType.
97
     * 
98
     * @return
99
     *         the factory subType String.
100
     */
101
    public abstract String getFactorySubType();
102

  
103
    /**
104
     * 
105
     * Returns the factory type
106
     * 
107
     * @return
108
     *         the factory type value. It can be null.
109
     */
110
    public abstract Integer getFactoryType();
111

  
112
    /**
113
     * Returns the current Tools swing service manager.
114
     * 
115
     * @return
116
     *         the {@link DynObjectSwingServiceManager}.
117
     */
118
    protected DynObjectSwingServiceManager getServiceManager() {
119
        if (manager == null) {
120
            manager = ToolsSwingServiceLocator.getServiceManager();
121
        }
122
        return manager;
123

  
124
    }
125

  
126
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/DynObjectSwingServiceManager.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import org.gvsig.tools.service.ServiceException;
39
import org.gvsig.tools.service.spi.ServiceManager;
40
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
41
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
42
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
43

  
44
/**
45
 * 
46
 * Swing Manager Service for {@link JDynObjectComponent}s to get its
47
 * correspondent {@link JDynFieldComponent}s.
48
 * 
49
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
50
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
51
 *         gvSIG Team
52
 * @version $Id$
53
 * 
54
 */
55
public interface DynObjectSwingServiceManager extends ServiceManager {
56

  
57
    public static final String DEFAULT_FACTORY_SUBTYPE = "default";
58

  
59
	/**
60
	 * 
61
	 * Returns a {@link JDynFieldComponent} that best matches with the given
62
	 * {@link ValueField} and type.
63
	 * 
64
	 * @param parent
65
	 *            the {@link ValueField} element.
66
	 * @param type
67
	 *            the current type.
68
	 * @param writable
69
	 * 
70
	 * @return the {@link JDynFieldComponent}.
71
	 * 
72
	 * @throws ServiceException
73
	 */
74
    public JDynFieldComponent getJDynFieldComponent(ValueField parent,
75
			boolean type, boolean writable) throws ServiceException;
76

  
77
    /**
78
     * 
79
     * Returns a {@link JDynFieldComponent}in the form of a JComboBox.
80
     * 
81
     * @param component
82
     *            the single component.
83
     * @param field
84
     *            the ValueField element.
85
     * 
86
     * @return
87
     *         the {@link JDynFieldComponent}.
88
     */
89
    public JDynFieldComponent getJSingleComboBoxDynFieldComponent(
90
        JDynFieldComponent component, ValueField field);
91

  
92
    public String getServiceName(int type, String subType);
93
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractJDynFieldComponentFactory.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import org.gvsig.tools.dataTypes.DataTypes;
39
import org.gvsig.tools.dynobject.DynClass;
40
import org.gvsig.tools.dynobject.DynField;
41
import org.gvsig.tools.dynobject.DynObject;
42
import org.gvsig.tools.dynobject.DynObjectValueItem;
43
import org.gvsig.tools.service.Service;
44
import org.gvsig.tools.service.ServiceException;
45
import org.gvsig.tools.service.spi.ServiceManager;
46
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
47
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
48
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponentFactory;
49
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
50

  
51
/**
52
 * Extends {@link AbstractSwingServiceFactory} and provides with
53
 * 
54
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
55
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
56
 *         gvSIG Team
57
 * @version $Id$
58
 * 
59
 */
60
public abstract class AbstractJDynFieldComponentFactory extends
61
    AbstractSwingServiceFactory implements JDynFieldComponentFactory {
62

  
63
    @Override
64
    protected DynClass createParametersDynClass() {
65

  
66
		DynClass dynClassParams = this.getDynClassParams();
67

  
68
		dynClassParams.addDynFieldObject(JDynFieldComponent.PARAMETERS.PARENT)
69
				.setClassOfValue(ValueField.class).setMandatory(true);
70
		dynClassParams
71
				.addDynFieldObject(JDynFieldComponent.PARAMETERS.DYNFIELD)
72
				.setClassOfValue(DynField.class).setMandatory(true);
73
		dynClassParams.addDynFieldBoolean(
74
				JDynFieldComponent.PARAMETERS.WRITABLE).setMandatory(false);
75
		
76
		return dynClassParams;
77
    }
78

  
79
    /*
80
     * (non-Javadoc)
81
     * 
82
     * @see
83
     * org.gvsig.tools.service.spi.AbstractServiceFactory#doCreate(org.gvsig
84
     * .tools.dynobject.DynObject, org.gvsig.tools.service.spi.ServiceManager)
85
     */
86
    @Override
87
    protected Service doCreate(DynObject parameters,
88
        ServiceManager serviceManager) {
89

  
90
        DynField child =
91
            (DynField) parameters
92
                .getDynValue(JDynFieldComponent.PARAMETERS.DYNFIELD);
93
        ValueField valueField =
94
            (ValueField) parameters
95
                .getDynValue(JDynFieldComponent.PARAMETERS.PARENT);
96

  
97
		Boolean writable = (Boolean) parameters
98
				.getDynValue(JDynObjectComponent.PARAMETERS.WRITABLE);
99
		writable = ( writable == null ? Boolean.TRUE : writable );
100

  
101
        try {
102
			JDynFieldComponent comp = this.createJDynFieldComponent(child, valueField,
103
					writable.booleanValue());
104

  
105
            return this.getSuitableComponent(comp, valueField);
106

  
107
        } catch (ServiceException e) {
108
            // TODO Auto-generated catch block
109
            e.printStackTrace();
110
            return null;
111
        }
112
    }
113

  
114
    /*
115
     * (non-Javadoc)
116
     * 
117
     * @see
118
     * org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
119
     */
120
    @Override
121
    public String getFactoryName() {
122
        return this.getName();
123
    }
124

  
125
    /*
126
     * (non-Javadoc)
127
     * 
128
     * @see
129
     * org.gvsig.tools.swing.spi.AbstractSwingServiceFactory#getFactoryName()
130
     */
131
    @Override
132
    public String getName() {
133
        return this.getServiceManager().getServiceName(this.getFactoryType(),
134
            this.getFactorySubType());
135
    }
136

  
137
    /**
138
     * Checks if it's a container and has available values to render a JComboBox
139
     * object
140
     * instead of the otherwise created JComponent.
141
     * 
142
     * @param component
143
     *            the JDynFieldComponent created beforehand.
144
     * @param field
145
     *            the ValueField object.
146
     * @return
147
     *         the JDynFieldComponent.
148
     */
149

  
150
    private JDynFieldComponent getSuitableComponent(
151
        JDynFieldComponent component, ValueField field) {
152

  
153
		// Checking containers
154
		DynField dynField = field.getDynField();
155
		if ((dynField.getType() == DataTypes.DYNOBJECT)
156
				|| (dynField.getType() == DataTypes.LIST)) {
157
			return component;
158
		}
159

  
160
		// If a simple component has available values it is a combobox
161
		DynObjectValueItem[] values = dynField.getAvailableValues();
162
		if ((values != null) && (values.length > 0)) {
163
            return this.getServiceManager()
164
                .getJSingleComboBoxDynFieldComponent(component, field);
165
        }
166
        return component;
167
    }
168

  
169
    /*
170
     * (non-Javadoc)
171
     * 
172
     * @see org.gvsig.tools.service.spi.ServiceFactory#initialize()
173
     */
174
    public void initialize() {
175
        // do nothing
176
    }
177
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractDynObjectComponent.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import java.awt.Component;
39
import java.util.HashMap;
40
import java.util.Iterator;
41
import java.util.Map;
42

  
43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataTypes;
45
import org.gvsig.tools.dynobject.DynField;
46
import org.gvsig.tools.dynobject.DynObject;
47
import org.gvsig.tools.dynobject.DynObjectManager;
48
import org.gvsig.tools.dynobject.DynStruct;
49
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
50
import org.gvsig.tools.dynobject.exception.DynObjectFieldSubtypeRequiredValueException;
51
import org.gvsig.tools.service.Manager;
52
import org.gvsig.tools.service.ServiceException;
53
import org.gvsig.tools.swing.api.ToolsSwingLocator;
54
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
55
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
56
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
57
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
58
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
59
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
60

  
61
/**
62
 * 
63
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
64
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
65
 *         gvSIG Team
66
 * @version $Id$
67
 * 
68
 */
69
public abstract class AbstractDynObjectComponent implements
70
		JDynObjectComponent, ValueField {
71

  
72
	private static final long serialVersionUID = 4088620749911859250L;
73

  
74
	private DynObject dynObject;
75

  
76
	private DynObjectModel model;
77

  
78
	private DynObjectSwingManager swingManager;
79

  
80
	private DynObjectManager manager;
81

  
82
	private Map<DynObject, Components> components;
83

  
84
	private DynStruct dynField;
85

  
86
	private DynObject oldDynObject;
87

  
88
	/**
89
	 * Constructor.
90
	 * 
91
	 * @param dynObject
92
	 *            the {@link DynObject} to render
93
	 * @param writable
94
	 */
95
	public AbstractDynObjectComponent() {
96
		this.swingManager = ToolsSwingLocator.getDynObjectSwingManager();
97
		this.manager = ToolsLocator.getDynObjectManager();
98
	}
99

  
100
	protected void setDynObject(DynObject dynObject) {
101
		this.oldDynObject = dynObject;
102
		this.dynObject = dynObject;
103
		if (this.dynObject == null) {
104
			this.dynObject = manager.createDynObject(this.getDefinition());
105
		}
106
		if (this.dynObject != null) {
107
			this.dynField = dynObject.getDynClass();
108
		}
109
		try {
110
			checkFields();
111
		} catch (DynObjectFieldSubtypeRequiredValueException e) {
112
			// TODO Auto-generated catch block
113
			e.printStackTrace();
114
		}
115
	}
116

  
117
	private void checkFields()
118
			throws DynObjectFieldSubtypeRequiredValueException {
119
		for (DynField field : dynField.getDynFields()) {
120
			if (field.getType() == DataTypes.DYNOBJECT) {
121
				String dynObjectID = field.getSubtype();
122
				// If subtype is null, the definition of the DynObject has not
123
				// been correctly implemented
124
				if (dynObjectID == null) {
125
					throw new DynObjectFieldSubtypeRequiredValueException(
126
							this.getDefinition(),
127
							field,
128
							"Definition "
129
									+ field.getName()
130
									+ " is not well defined. Subtype should contain its dynObjectID");
131
				}
132
				if (this.dynObject.getDynValue(field.getName()) == null) {
133
					this.dynObject.setDynValue(field.getName(),
134
							manager.createDynObject(manager.get(dynObjectID)));
135
				}
136
			}
137
		}
138
	}
139

  
140
	protected boolean hasDynObject() {
141
		return (this.dynObject != null);
142
	}
143

  
144
	/*
145
	 * (non-Javadoc)
146
	 * 
147
	 * @see
148
	 * org.gvsig.tools.swing.impl.dynobject.JDynbjectComponent#getDynObject()
149
	 */
150
	public DynObject getDynObject() {
151
		return dynObject;
152
	}
153

  
154
	public void setModel(DynObjectModel model) {
155
		this.model = model;
156
	}
157

  
158
	/*
159
	 * (non-Javadoc)
160
	 * 
161
	 * @see org.gvsig.tools.swing.impl.dynobject.JDynbjectComponent#getModel()
162
	 */
163
	public DynObjectModel getModel() {
164
		if (this.model == null) {
165
			createModel();
166
		}
167
		return this.model;
168
	}
169

  
170
	protected void setDynField(DynStruct definition) {
171
		this.dynField = definition;
172
	}
173

  
174
	protected DynStruct getDefinition() {
175
		if (this.dynField != null) {
176
			return this.dynField;
177
		}
178
		if (hasDynObject()) {
179
			return this.getDynObject().getDynClass();
180
		}
181
		return null;
182
	}
183

  
184
	private void createModel() {
185
		try {
186
			this.model = this.swingManager
187
					.createDynObjectModel(getDefinition());
188
		} catch (ServiceException e) {
189
			e.printStackTrace();
190
		}
191
	}
192

  
193
	public class Components extends HashMap<Component, JDynFieldComponent> {
194

  
195
		private Map<Component, JDynFieldComponent> componentField;
196

  
197
		/**
198
		 * Gets the map of all graphic JDynFieldComponents of this
199
		 * JDynObjectComponent.
200
		 * 
201
		 * @return the map containing the graphic Components.
202
		 */
203
		private Map<Component, JDynFieldComponent> getComponents() {
204
			if ((!hasDynObject()) || (componentField == null)) {
205
				componentField = new HashMap<Component, JDynFieldComponent>();
206
			}
207
			return componentField;
208
		}
209

  
210
		/**
211
		 * 
212
		 * Sets all FieldValues of this {@link JDynObjectComponent} to null.
213
		 * 
214
		 */
215
		public void emptyAll() {
216
			Map<Component, JDynFieldComponent> items = this.getComponents();
217
			for (JDynFieldComponent item : items.values())
218
				item.setValue(null);
219
		}
220

  
221
		/**
222
		 * Adds a new JDynFieldComponent to the list.
223
		 * 
224
		 * @param component
225
		 *            the java awt Component
226
		 * @param input
227
		 *            the correspondent JDynFieldComponent object
228
		 */
229
		public void addComponentToList(Component component,
230
				JDynFieldComponent input) {
231
			this.getComponents().put(component, input);
232
		}
233

  
234
		public Iterator<JDynFieldComponent> iterator() {
235
			return this.getComponents().values().iterator();
236
		}
237

  
238
		public void loadComponents(DynObject dynObject) {
239
			if (dynObject != null) {
240
				for (JDynFieldComponent item : getComponents().values())
241
					item.setValue(dynObject.getDynValue(item.getDynField()
242
							.getName()));
243
			} else {
244
				for (JDynFieldComponent item : getComponents().values())
245
					item.setValue(null);
246
			}
247
		}
248
	}
249

  
250
	/*
251
	 * (non-Javadoc)
252
	 * 
253
	 * @see
254
	 * org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getDefaultValue()
255
	 */
256
	public Object getDefaultValue() {
257
		return this.getDynObject();
258
	}
259

  
260
	/**
261
	 * 
262
	 * Returns a {@link JDynFieldComponent} that best matches with the given
263
	 * {@link ValueField} and adds, if any, the given listener to the
264
	 * JDynFieldComponent listeneres.
265
	 * 
266
	 * @param valueItem
267
	 *            the {@link ValueField} element.
268
	 * @param listener
269
	 *            the current {@link ValueChangedListener} to be added to the
270
	 *            JDynFieldComponent listeners.
271
	 * @return the {@link JDynFieldComponent}.
272
	 * 
273
	 * @throws ServiceException
274
	 */
275
	protected JDynFieldComponent getJDynFieldComponent(ValueField valueItem,
276
			ValueChangedListener listener) throws ServiceException {
277
		JDynFieldComponent jfield = ((DynObjectSwingManager) this.getManager())
278
				.createJDynFieldComponent(valueItem);
279
		if (listener != null) {
280
			jfield.addValueChangedListener(listener);
281
			jfield.fireValueChangedEvent();
282
		}
283
		return jfield;
284
	}
285

  
286
	/*
287
	 * (non-Javadoc)
288
	 * 
289
	 * @see org.gvsig.tools.service.Service#getManager()
290
	 */
291
	public Manager getManager() {
292
		return swingManager;
293
	}
294

  
295
	/**
296
	 * Sets all FieldValues of this {@link JDynObjectComponent} to its the
297
	 * current values of the same FieldValues at the {@link DynObject} given as
298
	 * input.
299
	 * 
300
	 * @param value
301
	 */
302
	protected void fillValues(DynObject dynObject) {
303
		this.setDynObject(dynObject);
304
		if (this.getDynObject() != null) {
305
			try {
306
				this.load(dynObject);
307
			} catch (ServiceException e) {
308
				// TODO Auto-generated catch block
309
				e.printStackTrace();
310
			}
311
		}
312
		this.getSelectedComponents().loadComponents(dynObject);
313
	}
314

  
315
	public boolean isValid() {
316
		if (!this.getDynField().isMandatory()) {
317
			return true;
318
		}
319

  
320
		Map<Component, JDynFieldComponent> items = this.getSelectedComponents();
321
		for (JDynFieldComponent item : items.values()) {
322
			if (!item.isValid()) {
323
				return false;
324
			}
325
		}
326
		return true;
327
	}
328

  
329
	public void load(DynObject dynObject) throws ServiceException {
330
		setDynObject(dynObject);
331
		// added to handle labels correctly
332
		addParametersFromModel();
333
	}
334

  
335
	protected abstract void addParametersFromModel() throws ServiceException;
336

  
337
	/**
338
	 * Walks through all JDynFieldComponents to save its current values into
339
	 * their DynObject.
340
	 */
341
	public void saveStatus() {
342
		Iterator<JDynFieldComponent> componentFields = this
343
				.getSelectedComponents().iterator();
344
		JDynFieldComponent comp;
345
		while (componentFields.hasNext()) {
346
			comp = componentFields.next();
347
			comp.saveStatus();
348
		}
349
	}
350

  
351
	protected Components getSelectedComponents() {
352
		return this.getComponents(this.getDynObject());
353
	}
354

  
355
	private Components getComponents(DynObject dynObject) {
356
		if ((this.components == null) || (dynObject == null)) {
357
			this.components = new HashMap<DynObject, Components>();
358
		}
359

  
360
		Components listComponents = this.components.get(dynObject);
361
		if (listComponents == null) {
362
			listComponents = new Components();
363
			this.components.put(dynObject, listComponents);
364
		}
365
		return listComponents;
366
	}
367

  
368
	public void addValueChangedListener(ValueChangedListener listener) {
369
		Iterator<JDynFieldComponent> componentFields = this
370
				.getSelectedComponents().iterator();
371
		JDynFieldComponent comp;
372
		while (componentFields.hasNext()) {
373
			comp = componentFields.next();
374
			comp.addValueChangedListener(listener);
375
		}
376
	}
377

  
378
	public String getValidationMessage() {
379
		try {
380
			this.getDynField().validate(this.getValue());
381
			return "";
382
		} catch (DynFieldValidateException e) {
383
			return e.getLocalizedMessageStack();
384
		}
385
	}
386

  
387
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractJDynField.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import java.util.ArrayList;
39
import java.util.List;
40

  
41
import org.gvsig.tools.dynobject.DynField;
42
import org.gvsig.tools.dynobject.DynObject;
43
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
44
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
45
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
46
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
47

  
48
/**
49
 * 
50
 * This interfaces provides with the logic necessary to create
51
 * JDynFieldComponents. First, the initial values are extracted. Second, the
52
 * user interface components are created.Third, the initial value is set to the
53
 * right component, and last but not least, a fireEventChanged event is raised
54
 * to inform all Listeners that the value has changed. Some additional functions
55
 * related to DynField attributes are also implemented.
56
 * 
57
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
58
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
59
 *         gvSIG Team
60
 * @version $Id$
61
 * 
62
 */
63
public abstract class AbstractJDynField {
64

  
65
    private ValueField parent;
66

  
67
    protected final List<ValueChangedListener> listeners;
68

  
69
    private boolean writable;
70

  
71
    private DynField definition;
72

  
73
	private DynFieldValidateException validateException;
74

  
75
	public AbstractJDynField(DynField definition, ValueField parent, boolean writable) {
76
        this.parent = parent;
77
        this.definition = definition;
78
        listeners = new ArrayList<ValueChangedListener>();
79
        this.writable = writable;
80
    }
81
	
82
	protected boolean isReadOnly(){
83
	    return !writable;
84
	}
85
	
86

  
87
    public DynField getParentDynField() {
88
        return parent.getDynField();
89
    }
90

  
91
    /*
92
     * (non-Javadoc)
93
     * 
94
     * @see org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#
95
     * addValueChangedListener
96
     * (org.gvsig.tools.swing.api.dynobject.ValueChangedListener)
97
     */
98
    public void addValueChangedListener(ValueChangedListener listener) {
99
        // If it was the first item, we need to
100
        // initialize Component listeners
101
        // add listener to the dynfield set of listeners
102
        listeners.add(listener);
103
        // set supplementary listeners.
104
        this.setJDynFieldComponentListeners();
105
    }
106

  
107

  
108
    public String getValidationMessage(){
109
		return this.getValueField().getValidationMessage();
110
    }
111
    
112
    /**
113
     * The {@link JDynFieldComponent} can use this function to add any code
114
     * necessary
115
     * once all swing components have been initialized.
116
     */
117
    protected abstract void afterUI();
118

  
119
    /**
120
     * Then all {@link ValueChangedListener}s are fired to alert them
121
     * to check if the value has changed via the {@link getValue()} function of
122
     * the {@link JDynFieldComponent}.
123
     */
124
    public abstract void fireValueChangedEvent();
125

  
126
    /**
127
     * Gets the default value of the {@link ValueField} object.
128
     * 
129
     * @return
130
     *         the default value of the {@link ValueField} object.
131
     */
132
    public Object getDefaultFieldValue() {
133
        return this.getValueField().getDefaultFieldValue();
134
    }
135

  
136
    /**
137
     * Returns the {@link DynField} being rendered.
138
     * 
139
     * @return the {@link DynField}
140
     */
141
    public DynField getDynField() {
142
        if (definition!=null){
143
            return definition;
144
        }
145
        return getValueField().getDynField();
146
    }
147
    
148
    /*
149
     * (non-Javadoc)
150
     * 
151
     * @see
152
     * 
153
     * 
154
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory
155
     * ()
156
     */
157
    public boolean isMandatory() {
158
        return getDynField().isMandatory();
159
    }
160

  
161

  
162
    /**
163
     * Gets the current value of the {@link ValueField} object.
164
     * 
165
     * @return
166
     *         the current value of the {@link ValueField} object.
167
     */
168
    public Object getFieldValue() {
169
        return this.getValueField().getFieldValue();
170
    }
171

  
172
    /**
173
     * Checks if the {@link ValueField} has an inputed value; if not, then it
174
     * asks
175
     * for its default value.
176
     * 
177
     * @return
178
     *         the initial value of the {@link ValueField}. It can be
179
     *         <b>null</b>.
180
     */
181
    public Object getInitialValue() {
182
        Object value = getFieldValue();
183
        if (value == null) {
184
            value = getDefaultFieldValue();
185
        }
186
        return value;
187
    }
188

  
189
    /**
190
     * Gets the {@link ValueField} object.
191
     * 
192
     * @return
193
     *         the {@link ValueField} object.
194
     */
195
    private ValueField getValueField() {
196
        return this.parent;
197
    }
198

  
199
    /**
200
     * Inits the JDynFieldComponent logic to create its components and check its
201
     * values.
202
     */
203
    protected void init() {
204
        this.initData();
205
        this.initUI();
206
        if (isReadOnly()) {
207
            this.setReadOnly();
208
		}
209
        this.setValue(getInitialValue());
210
        this.afterUI();
211
    }
212

  
213
    /**
214
     * JDynFieldComponents can use this function to initialize any
215
     * data containers before the swing components are created.
216
     */
217
    protected abstract void initData();
218

  
219
    /**
220
     * {@link JDynFieldComponent}s can use this function to initialized any
221
     * swing components to be used afterwards, and specify their
222
     * default settings.
223
     */
224
    protected abstract void initUI();
225

  
226
    /**
227
     * Sets the current value of the {@link JDynFieldComponent} to the
228
     * {@link DynObject} value via the {@link ValueField} object.
229
     * 
230
     */
231
    public void setFieldValue(Object value) {
232
        this.getValueField().setFieldValue(value);
233
    }
234

  
235
    protected abstract void setJDynFieldComponentListeners();
236

  
237
    /**
238
     * The {@link JDynFieldComponent} can use this function to set a <b>non
239
     * null</b> value
240
     * into the correspondent swing component.
241
     * 
242
     * @param value
243
     *            the value to be set into the swing component.
244
     */
245
    protected abstract void setNonNullValue(Object value);
246

  
247
    /**
248
     * The {@link JDynFieldComponent} can use this function to set a <b>null</b>
249
     * value
250
     * into the correspondent swing component.
251
     * 
252
     * @param value
253
     *            the value to be set into the swing component.
254
     */
255
    protected abstract void setNullValue();
256

  
257
    /**
258
     * The {@link JDynFieldComponent} can implement this function to set the
259
     * swing
260
     * components that represent this {@link DynField} to readOnly mode.
261
     */
262
    protected abstract void setReadOnly();
263

  
264
	/**
265
	 * Sets the value to the {@link JDynFieldComponent}. With this logic, it
266
	 * checks first if it is a null value or not. Then all
267
	 * {@link ValueChangedListener}s are fired to alert them to check if the
268
	 * value has changed via the {@link getValue()} function.
269
	 * 
270
	 * @param newValue
271
	 *            the value to be set into the swing component.
272
	 */
273
    public void setValue(Object newValue) {
274
		// oldValue and newValue is null.
275
		if ((this.getValue() == null) && (newValue == null)) {
276
			return;
277
		}
278
		// If there's an oldValue not null and is equal to newValue, do
279
		// Nothing.
280
		if ((this.getValue() != null) && (this.getValue().equals(newValue))) {
281
			return;
282
		}
283
		if (newValue == null) {
284
            setNullValue();
285
        } else {
286
			setNonNullValue(newValue);
287
        }
288
        this.fireValueChangedEvent();
289
    }
290

  
291
	/**
292
	 * @param value
293
	 */
294
	protected boolean validate(Object value) {
295
		try {
296
			this.getDynField().validate(value);
297
			validateException = null;
298
			return true;
299
		} catch (DynFieldValidateException e) {
300
			validateException = e;
301
			return false;
302
		}
303
	}
304

  
305
	/**
306
	 * Gets the current validation exception, if any
307
	 * 
308
	 * @return
309
	 */
310
	protected DynFieldValidateException getValidateException() {
311
		if (validateException == null) {
312
			validate(this.getValue());
313
		}
314
		return validateException;
315
	}
316

  
317
	/**
318
	 * Gets the current value of the component
319
	 * 
320
	 * @return
321
	 */
322
	public abstract Object getValue();
323

  
324
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractDynObjectFactory.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 2
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
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.swing.spi;
37

  
38
import org.gvsig.tools.dataTypes.DataTypes;
39
import org.gvsig.tools.dynobject.DynClass;
40
import org.gvsig.tools.dynobject.DynObject;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.service.Service;
43
import org.gvsig.tools.service.ServiceException;
44
import org.gvsig.tools.service.spi.ServiceManager;
45
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
46
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
47
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponentFactory;
48

  
49
/**
50
 * 
51
 * Swing Factory of the {@link JDynObjectComponent} object.
52
 * 
53
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
54
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
55
 *         gvSIG Team
56
 * @version $Id$
57
 * 
58
 */
59
public abstract class AbstractDynObjectFactory extends
60
    AbstractSwingServiceFactory implements JDynObjectComponentFactory {
61

  
62
    @Override
63
    protected DynClass createParametersDynClass() {
64

  
65
        DynClass dynClassParams = this.getDynClassParams();
66
        dynClassParams.addDynField(JDynObjectComponent.PARAMETERS.DYNOBJECT)
67
            .setType(DataTypes.DYNOBJECT).setMandatory(true);
68
        dynClassParams
69
            .addDynFieldObject(JDynObjectComponent.PARAMETERS.DYNSTRUCT)
70
            .setClassOfValue(DynStruct.class).setMandatory(true);
71
        dynClassParams
72
            .addDynFieldObject(JDynObjectComponent.PARAMETERS.DYNMODEL)
73
            .setClassOfValue(DynObjectModel.class).setMandatory(true);
74
        dynClassParams
75
            .addDynFieldBoolean(JDynObjectComponent.PARAMETERS.WRITABLE)
76
            .setMandatory(false).setDefaultFieldValue(Boolean.FALSE);
77

  
78
        return dynClassParams;
79
    }
80

  
81
    @Override
82
    protected Service doCreate(DynObject parameters,
83
        ServiceManager serviceManager) throws ServiceException {
84

  
85
        DynObjectModel dynModel =
86
            (DynObjectModel) parameters
87
                .getDynValue(JDynObjectComponent.PARAMETERS.DYNMODEL);
88
        DynStruct definition =
89
            (DynStruct) parameters
90
                .getDynValue(JDynObjectComponent.PARAMETERS.DYNSTRUCT);
91
        DynObject currentDynObjectValue =
92
            (DynObject) parameters
93
                .getDynValue(JDynObjectComponent.PARAMETERS.DYNOBJECT);
94
        Boolean writable =
95
            (Boolean) parameters
96
                .getDynValue(JDynObjectComponent.PARAMETERS.WRITABLE);
97
        writable = writable == null ? Boolean.FALSE : writable;
98

  
99
        return this.createJDynObjectComponent(definition,
100
            currentDynObjectValue, dynModel, writable.booleanValue());
101
    }
102

  
103
    public void initialize() {
104
        // Nothing to do
105
    }
106
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.30/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/ToolsSwingServiceLocator.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 2
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,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff