Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynobject / DefaultDynObjectSwingManager.java @ 298

History | View | Annotate | Download (4.88 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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
 */
22
package org.gvsig.tools.swing.impl.dynobject;
23

    
24
import org.gvsig.tools.dynobject.DynClass;
25
import org.gvsig.tools.dynobject.DynField;
26
import org.gvsig.tools.dynobject.DynObject;
27
import org.gvsig.tools.dynobject.DynObjectSet;
28
import org.gvsig.tools.exception.BaseException;
29
import org.gvsig.tools.service.AbstractMultiServiceImplManager;
30
import org.gvsig.tools.service.Service;
31
import org.gvsig.tools.service.ServiceException;
32
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
33
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
34
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
35
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
36
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
37
import org.gvsig.tools.swing.api.dynobject.set.JDynObjectSetComponent;
38
import org.gvsig.tools.swing.impl.dynobject.set.DefaultJDynObjectSetComponent;
39
import org.gvsig.tools.swing.spi.DynObjectSwingServiceManager;
40
import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator;
41

    
42
/**
43
 * Default {@link DynObjectSwingManager} implementation.
44
 * 
45
 * @author gvSIG team
46
 */
47
public class DefaultDynObjectSwingManager extends
48
    AbstractMultiServiceImplManager implements DynObjectSwingManager {
49

    
50
    /**
51
     * Empty constructor.
52
     */
53
    public DefaultDynObjectSwingManager() {
54
        super(ToolsSwingServiceLocator.getServiceManager());
55
    }
56

    
57
    public DynObjectModel createDynObjectModel(DynClass dynClass)
58
        throws ServiceException {
59
        return new DefaultDynObjectModel(dynClass, true);
60
    }
61

    
62
    public DynObjectModel createEmptyDynObjectModel(DynClass dynClass)
63
        throws ServiceException {
64
        return new DefaultDynObjectModel(dynClass, false);
65
    }
66

    
67
    public JDynFieldComponent createJDynFieldComponent(ValueField parent)
68
        throws ServiceException {
69
        JDynFieldComponent component;
70
        DynField field = parent.getDynField();
71
        if (field.getElementsType() != null) {
72
            component =
73
                ((DynObjectSwingServiceManager) this.getServiceManager())
74
                    .getJDynFieldComponent(parent, true);
75
        } else {
76
            component =
77
                ((DynObjectSwingServiceManager) this.getServiceManager())
78
                    .getJDynFieldComponent(parent, false);
79
        }
80
        return component;
81
    }
82

    
83
    public JDynObjectComponent createJDynObjectComponent(DynObject dynObject)
84
        throws ServiceException {
85
        return createJDynObjectComponent(dynObject,
86
            createDynObjectModel(dynObject.getDynClass()));
87
    }
88

    
89
    public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
90
        DynObjectModel model) throws ServiceException {
91
        return createJDynObjectComponent(dynObject, model, MODE_FORM);
92
    }
93

    
94
    public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
95
        DynObjectModel model, String mode) throws ServiceException {
96
        DynObject serviceParams =
97
            this.createServiceParameters(getServiceName(dynObject, mode));
98

    
99
        serviceParams.setDynValue(JDynObjectComponent.PARAMETERS.DYNMODEL,
100
            model);
101
        serviceParams.setDynValue(JDynObjectComponent.PARAMETERS.DYNOBJECT,
102
            dynObject);
103

    
104
        return (JDynObjectComponent) this.getService(serviceParams);
105
    }
106

    
107
    public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
108
        String mode) throws ServiceException {
109
        return createJDynObjectComponent(dynObject,
110
            createDynObjectModel(dynObject.getDynClass()));
111
    }
112

    
113
    public JDynObjectSetComponent createJDynObjectSetComponent(
114
        DynObjectSet dynObjectSet) throws BaseException {
115
        return new DefaultJDynObjectSetComponent(dynObjectSet, this);
116
    }
117

    
118
    public Service getService(DynObject serviceParams) throws ServiceException {
119
        return this.getServiceManager().createService(serviceParams);
120
    }
121

    
122
    /**
123
     * @param dynObject
124
     * @param mode
125
     * @return
126
     */
127
    private String getServiceName(DynObject dynObject, String mode) {
128
        return mode;
129
    }
130
}