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 @ 281

History | View | Annotate | Download (4.86 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) throws ServiceException {
68
        JDynFieldComponent component;
69
        DynField field = parent.getDynField();
70
        if (field.getElementsType() != null)
71
            component =
72
                ((DynObjectSwingServiceManager) this.getServiceManager())
73
                    .getJDynFieldComponent(parent, true);
74
        else
75
            component =
76
                ((DynObjectSwingServiceManager) this.getServiceManager())
77
                    .getJDynFieldComponent(parent, false);
78
        return component;
79
    }
80

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

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

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

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

    
102
        return (JDynObjectComponent) this.getService(serviceParams);
103
    }
104

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

    
111
    public Service getService(DynObject serviceParams) throws ServiceException {
112
        return this.getServiceManager().createService(serviceParams);
113
    }
114

    
115
    /**
116
     * @param dynObject
117
     * @param mode
118
     * @return
119
     */
120
    private String getServiceName(DynObject dynObject, String mode) {
121
        return mode;
122
    }
123

    
124
    public JDynObjectSetComponent createJDynObjectSetComponent(
125
        DynObjectSet dynObjectSet) throws BaseException {
126
        return new DefaultJDynObjectSetComponent(dynObjectSet, this);
127
    }
128
}