Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / AbstractDocumentManager.java @ 34114

History | View | Annotate | Download (6.27 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2009 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

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2004-2009 IVER TI
26
*   
27
*/
28

    
29
package org.gvsig.app.project.documents;
30

    
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.Map;
34

    
35
import javax.swing.ImageIcon;
36

    
37
import org.gvsig.andami.PluginServices;
38
import org.gvsig.andami.ui.mdiManager.IWindow;
39
import org.gvsig.app.project.Project;
40
import org.gvsig.app.project.documents.table.TableDocument;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
43
import org.gvsig.tools.persistence.PersistenceManager;
44
import org.gvsig.tools.persistence.PersistentState;
45
import org.gvsig.tools.persistence.exception.PersistenceException;
46

    
47

    
48

    
49
/**
50
 * Factory of ProjectDocument.
51
 *
52
 * @author 2005-         Vicente Caballero
53
 * @author 2009-         Joaquin del Cerro
54
 * 
55
 */
56

    
57
public abstract class AbstractDocumentManager implements DocumentManager {
58

    
59
    /**
60
     * Returns the type of document priority.
61
     *
62
     * This priority is used when order document factories in UI.
63
     * 
64
     * @return Priority.
65
     */
66
    public int getPriority() {
67
        return 10;
68
    }
69

    
70
    /**
71
     * Returns the icon for the type of document.
72
     *
73
     * @return Image.
74
     */
75
    public ImageIcon getIcon() {
76
        return PluginServices.getIconTheme().get("document-icon-sel");
77
    }
78

    
79
    /**
80
     * Returns the icon for the type of document when is selected
81
     *
82
     * @return Image.
83
     */
84
    public ImageIcon getIconSelected() {
85
        return PluginServices.getIconTheme().get("document-icon");
86
    }
87

    
88
    /**
89
     * Returns the title of type of document.
90
     *
91
     * @return String title for type of document
92
     */
93
    public String getTitle() {
94
        return PluginServices.getText(this, "documento");
95
    }
96

    
97
    /**
98
     * Introdece a gui to be able from the characteristics that we want a ProjectDocument
99
     *
100
     * @param project present Project.
101
     *
102
     * @return new ProjectDocument.
103
     */
104
    public AbstractDocument createDocumentByUser() {
105
        return createDocument();
106
    }
107

    
108
    /**
109
     * @see ExtensionBuilder
110
     */
111
    public Object create() {
112
        return this;
113
    }
114

    
115
    /**
116
     * @see ExtensionBuilder
117
     */
118
    public Object create(Object[] args) {
119
        return this;
120
    }
121

    
122
    /**
123
     * @see ExtensionBuilder
124
     */
125
    @SuppressWarnings("rawtypes")
126
    public Object create(Map args) {
127
        return this;
128
    }
129

    
130
    public IWindow getMainWindow(Document doc) {
131
        return getMainWindow(doc, null);
132
    }
133

    
134

    
135
    /**
136
     * Return true if the name exists to another document.
137
     *
138
     * @param project
139
     * @param documentName
140
     *
141
     * @return True if the name exists.
142
     * @deprecated use instead  project.getProjectDocument
143
     */
144
    public boolean existName(Project project, String documentName) {
145
        return project.getDocument(documentName, getTypeName())!=null;
146
    }
147

    
148
    /**
149
     * Return the class or interface for the documents managed by this factory.
150
     * @return The document class;
151
     */
152
    @SuppressWarnings("rawtypes")
153
    abstract protected Class getDocumentClass();
154

    
155
    public Object createFromState(PersistentState state) throws PersistenceException {
156
        Document doc = this.createDocument();
157
        return doc;
158
    }
159

    
160
    public void loadFromState(PersistentState state, Object object) throws PersistenceException {
161
        Document doc = (Document) object;
162
        doc.loadFromState(state);
163
    }
164

    
165
    public void saveToState(PersistentState state, Object obj) throws PersistenceException {
166
        Document doc = (Document) obj;
167
        doc.saveToState(state);
168

    
169
    }
170

    
171
    public boolean manages(Object object) {
172
        return object instanceof TableDocument;
173
    }
174

    
175
    @SuppressWarnings({ "rawtypes", "unchecked" })
176
    public boolean manages(Class theClass) {
177
        return this.getDocumentClass().isAssignableFrom(theClass);
178
    }
179

    
180
    @SuppressWarnings("rawtypes")
181
    public boolean manages(PersistentState state) {
182
        try {
183
            Class theClass;
184
            theClass = (Class) Class.forName(state.getTheClassName());
185
            return manages(theClass);
186
        } catch (ClassNotFoundException e) {
187
            return false;
188
        }
189
    }
190

    
191
    public List<DynStruct> getDefinitions() {
192
        DynStruct definition = this.getDefinition(this.getDocumentClass().getName());
193
        List<DynStruct> definitions = new ArrayList<DynStruct>();
194
        definitions.add(definition);
195
        return definitions;
196
    }
197

    
198
    public String getDomainName() {
199
        return PersistenceManager.DEFAULT_DOMAIN_NAME;
200
    }
201

    
202
    public String getDomainURL() {
203
        return PersistenceManager.DEFAULT_DOMAIN_URL;
204
    }
205

    
206
    @SuppressWarnings({ "unchecked", "rawtypes" })
207
    public List getManagedClasses() {
208
        List classes = new ArrayList();
209
        classes.add(this.getDocumentClass());
210
        return classes;
211
    }
212

    
213
    @SuppressWarnings("rawtypes")
214
    public Class getManagedClass(Object object) {
215
        return this.getDocumentClass();
216
    }
217

    
218
    @SuppressWarnings("rawtypes")
219
    public Class getManagedClass(PersistentState state) {
220
        return this.getDocumentClass();
221
    }
222

    
223
    @SuppressWarnings("rawtypes")
224
    public Class getManagedClass(String name) {
225
        return this.getDocumentClass();
226
    }
227

    
228
    @SuppressWarnings("rawtypes")
229
    public String getManagedClassName(Object object) {
230
        Class clazz = this.getManagedClass(object);
231
        if (clazz != null){
232
            return clazz.getName();
233
        }
234
        return null;
235
    }
236

    
237

    
238
}