Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocumentFactory.java @ 10666

History | View | Annotate | Download (5.63 KB)

1
package com.iver.cit.gvsig.project.documents;
2

    
3
import java.security.KeyException;
4
import java.util.ArrayList;
5
import java.util.Hashtable;
6
import java.util.Map;
7

    
8
import javax.swing.ImageIcon;
9

    
10
import com.iver.andami.PluginServices;
11
import com.iver.cit.gvsig.project.Project;
12
import com.iver.cit.gvsig.project.documents.contextMenu.AbstractDocumentContextMenuAction;
13
import com.iver.utiles.XMLEntity;
14
import com.iver.utiles.extensionPoints.ExtensionPoint;
15
import com.iver.utiles.extensionPoints.ExtensionPoints;
16
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
17
import com.iver.utiles.extensionPoints.IExtensionBuilder;
18

    
19

    
20
/**
21
 * Factory of ProjectDocument.
22
 *
23
 * @author Vicente Caballero Navarro
24
 */
25
public abstract class ProjectDocumentFactory implements IExtensionBuilder {
26
    /**
27
     * Returns the load priority of the ProjectDocument.
28
     *
29
     * @return Priority.
30
     */
31
    public int getPriority() {
32
        return 10;
33
    }
34
    
35
    /**
36
     * Returns the priority of the ProjectDocument in the project window list.
37
     *
38
     * @return Priority.
39
     */
40
    public int getListPriority() {
41
        return 10;
42
    }
43

    
44
    /**
45
     * Returns image of button.
46
     *
47
     * @return Image button.
48
     */
49
    public abstract ImageIcon getButtonIcon();
50

    
51
    /**
52
     * Returns image of selected button.
53
     *
54
     * @return Image button.
55
     */
56
    public abstract ImageIcon getSelectedButtonIcon();
57

    
58
    /**
59
     * Returns the name of ProjectDocument.
60
     *
61
     * @return Name of ProjectDocument.
62
     */
63
    public String getNameType() {
64
        return PluginServices.getText(this, "documento");
65
    }
66

    
67
    /**
68
     * Create a new ProjectDocument.
69
     *
70
     * @param project Opened project.
71
     *
72
     * @return ProjectDocument.
73
     */
74
    public abstract ProjectDocument create(Project project);
75

    
76
    /**
77
     * Introdece a gui to be able from the characteristics that we want a ProjectDocument
78
     *
79
     * @param project present Project.
80
     *
81
     * @return new ProjectDocument.
82
     */
83
    public ProjectDocument createFromGUI(Project project) {
84
        return create(project);
85
    }
86

    
87
    /**
88
     * Returns the name of registration in the point of extension.
89
     *
90
     * @return Name of registration
91
     */
92
    public abstract String getRegisterName();
93

    
94
    /**
95
     * Create a ProjectDocumentFactory.
96
     *
97
     * @return ProjectDocumentFactory.
98
     */
99
    public Object create() {
100
        return this;
101
    }
102

    
103
    /**
104
     * Create a ProjectDocumentFactory.
105
     *
106
     * @param args
107
     *
108
     * @return ProjectDocumentFactory.
109
     */
110
    public Object create(Object[] args) {
111
        return this;
112
    }
113

    
114
    /**
115
     * Create a ProjectDocumentFactory.
116
     *
117
     * @param args
118
     *
119
     * @return ProjectDocumentFactory.
120
     */
121
    public Object create(Map args) {
122
        return this;
123
    }
124

    
125
    /**
126
     * Registers in the points of extension the Factory with alias.
127
     *
128
     * @param registerName Register name.
129
     * @param obj Class of register.
130
     * @param alias Alias.
131
     */
132
    public static void register(String registerName, Object obj, String alias) {
133
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
134
        extensionPoints.add("Documents", registerName, obj);
135
                ProjectDocument.NUMS.put(registerName,new Integer(0));
136
        ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get(
137
                "Documents"));
138

    
139
        try {
140
            extPoint.addAlias(registerName, alias);
141
        } catch (KeyException e) {
142
            e.printStackTrace();
143
        }
144
    }
145

    
146
    /**Registers in the points of extension the Factory
147
     *
148
     * @param registerName Register name.
149
     * @param obj Class of register.
150
     */
151
    public static void register(String registerName, Object obj) {
152
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
153
        extensionPoints.add("Documents", registerName, obj);
154
             ProjectDocument.NUMS.put(registerName,new Integer(0));
155
    }
156

    
157
    /**
158
     * Register an action for the document.
159
     * 
160
     * This actions will be appears in the context menu of
161
     * the project document list.
162
     * 
163
     * 
164
     * @param documentRegisterName
165
     * @param actionName
166
     * @param action
167
     */
168
    public static void registerAction(String documentRegisterName, String actionName, AbstractDocumentContextMenuAction action) {
169
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
170
        extensionPoints.add("DocumentActions_"+documentRegisterName, actionName, action);            
171
    }
172
    /**
173
     * Try to resolve the documents conflicts before perform an import action
174
     * 
175
     * @param root the XML document
176
     * @param project the project
177
     * @param conflicts Hashtable 
178
     *                         - keys: documents register name.
179
     *                         - values: Hashtable 
180
     *                         (keys = index of the child in the xml group of the XML, 
181
     *                         values = XMLEntity in conflict)
182
     *  
183
     * @return true if all the conflicts are resolved , else false
184
     */
185
    public abstract boolean resolveImportXMLConflicts(XMLEntity root,Project project, Hashtable conflicts);
186
         /**
187
    * Return true if the name exists to another document.
188
    *
189
    * @param project
190
    * @param documentName
191
    *
192
    * @return True if the name exists.
193
    */
194
   public boolean existName(Project project, String documentName) {
195
       ArrayList documentList = project.getDocumentsByType(getRegisterName());
196

    
197
       for (int i = 0; i < documentList.size(); i++) {
198
           ProjectDocument pd = (ProjectDocument) documentList.get(i);
199
           String title = pd.getName();
200

    
201
           if (title.compareTo(documentName) == 0) {
202
               return true;
203
           }
204
       }
205

    
206
       return false;
207
   }
208
}