root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / ProjectDocumentFactory.java @ 11018
History | View | Annotate | Download (5.63 KB)
1 | 7343 | caballero | package com.iver.cit.gvsig.project.documents; |
---|---|---|---|
2 | |||
3 | 7738 | jaume | import java.security.KeyException; |
4 | 9690 | caballero | import java.util.ArrayList; |
5 | 7755 | jmvivo | import java.util.Hashtable; |
6 | 7738 | jaume | import java.util.Map; |
7 | 7343 | caballero | |
8 | 7738 | jaume | import javax.swing.ImageIcon; |
9 | 7343 | caballero | |
10 | 7738 | jaume | import com.iver.andami.PluginServices; |
11 | import com.iver.cit.gvsig.project.Project; |
||
12 | 7755 | jmvivo | import com.iver.cit.gvsig.project.documents.contextMenu.AbstractDocumentContextMenuAction; |
13 | import com.iver.utiles.XMLEntity; |
||
14 | 7343 | caballero | 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 | 8159 | sbayarri | * Returns the load priority of the ProjectDocument.
|
28 | 7343 | caballero | *
|
29 | * @return Priority.
|
||
30 | */
|
||
31 | public int getPriority() { |
||
32 | return 10; |
||
33 | } |
||
34 | 9690 | caballero | |
35 | 8159 | sbayarri | /**
|
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 | 7343 | caballero | |
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 | 9690 | caballero | ProjectDocument.NUMS.put(registerName,new Integer(0)); |
136 | 7343 | caballero | 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 | 9701 | caballero | ProjectDocument.NUMS.put(registerName,new Integer(0)); |
155 | 7343 | caballero | } |
156 | 7755 | jmvivo | |
157 | /**
|
||
158 | * Register an action for the document.
|
||
159 | 9690 | caballero | *
|
160 | 7755 | jmvivo | * This actions will be appears in the context menu of
|
161 | * the project document list.
|
||
162 | 9690 | caballero | *
|
163 | *
|
||
164 | 7755 | jmvivo | * @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 | 9690 | caballero | extensionPoints.add("DocumentActions_"+documentRegisterName, actionName, action);
|
171 | 7755 | jmvivo | } |
172 | /**
|
||
173 | * Try to resolve the documents conflicts before perform an import action
|
||
174 | 9690 | caballero | *
|
175 | 7755 | jmvivo | * @param root the XML document
|
176 | * @param project the project
|
||
177 | 9690 | caballero | * @param conflicts Hashtable
|
178 | 7755 | jmvivo | * - keys: documents register name.
|
179 | 9690 | caballero | * - values: Hashtable
|
180 | * (keys = index of the child in the xml group of the XML,
|
||
181 | 7755 | jmvivo | * values = XMLEntity in conflict)
|
182 | 9690 | caballero | *
|
183 | 7755 | jmvivo | * @return true if all the conflicts are resolved , else false
|
184 | */
|
||
185 | public abstract boolean resolveImportXMLConflicts(XMLEntity root,Project project, Hashtable conflicts); |
||
186 | 9690 | caballero | /**
|
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 | 7343 | caballero | } |