svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / ViewManager.java @ 41121
History | View | Annotate | Download (11.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view; |
25 |
|
26 |
import java.util.Map; |
27 |
|
28 |
import javax.swing.ImageIcon; |
29 |
|
30 |
import org.gvsig.andami.IconThemeHelper; |
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.PluginsLocator; |
33 |
import org.gvsig.andami.actioninfo.ActionInfo; |
34 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
36 |
import org.gvsig.app.project.ProjectManager; |
37 |
import org.gvsig.app.project.documents.AbstractDocument; |
38 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
39 |
import org.gvsig.app.project.documents.Document; |
40 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
41 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
42 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
43 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
44 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
45 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
46 |
import org.gvsig.app.project.documents.view.gui.ViewProperties; |
47 |
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
51 |
import org.gvsig.tools.ToolsLocator; |
52 |
import org.gvsig.tools.dynobject.DynStruct; |
53 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
54 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
56 |
import org.gvsig.tools.persistence.PersistenceManager; |
57 |
import org.slf4j.Logger; |
58 |
import org.slf4j.LoggerFactory; |
59 |
|
60 |
/**
|
61 |
* Factory of View.
|
62 |
*
|
63 |
* @author 2005- Vicente Caballero
|
64 |
* @author 2009- Joaquin del Cerro
|
65 |
*
|
66 |
*/
|
67 |
public class ViewManager extends AbstractDocumentManager { |
68 |
private static final Logger logger = LoggerFactory.getLogger(ViewManager.class); |
69 |
|
70 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME = |
71 |
"DefaultViewDocument";
|
72 |
public static String TYPENAME = "project.document.view2d"; |
73 |
private DynStruct persistenceDefinition;
|
74 |
|
75 |
public ViewManager() {
|
76 |
// Do nothing
|
77 |
} |
78 |
|
79 |
public int getPriority() { |
80 |
return 0; |
81 |
} |
82 |
|
83 |
public ImageIcon getIcon() { |
84 |
return PluginServices.getIconTheme().get("document-view-icon"); |
85 |
} |
86 |
|
87 |
public ImageIcon getIconSelected() { |
88 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
89 |
} |
90 |
|
91 |
public String getTitle() { |
92 |
return PluginServices.getText(this, "Vista"); |
93 |
} |
94 |
|
95 |
public String getTypeName() { |
96 |
return TYPENAME;
|
97 |
} |
98 |
|
99 |
public Class getMainWindowClass() { |
100 |
return DefaultViewPanel.class;
|
101 |
} |
102 |
|
103 |
public AbstractDocument createDocument() { |
104 |
return new DefaultViewDocument(this); |
105 |
} |
106 |
|
107 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
108 |
IDocumentWindow view; |
109 |
|
110 |
view = (IDocumentWindow) PluginServices.getMDIManager().getSingletonWindow(getMainWindowClass(), doc); |
111 |
if( view != null ) { |
112 |
// The view window document is already created, return it.
|
113 |
return view;
|
114 |
} |
115 |
view = this.createDocumentWindow(doc);
|
116 |
if ( layout != null && view != null ) { |
117 |
view.setWindowLayout(layout); |
118 |
} |
119 |
((AbstractDocument) doc).raiseEventCreateWindow(view);
|
120 |
return view;
|
121 |
} |
122 |
|
123 |
public IWindow getPropertiesWindow(Document doc) { |
124 |
return new ViewProperties((DefaultViewDocument) doc); |
125 |
} |
126 |
|
127 |
public void addTOCContextAction(String theAction) { |
128 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
129 |
ActionInfo action = actionManager.getAction(theAction); |
130 |
if( action==null ) { |
131 |
String errmsg = "Action '"+theAction+"' not found"; |
132 |
logger.info(errmsg); |
133 |
throw new RuntimeException(errmsg); |
134 |
} |
135 |
this.addTOCContextAction(action);
|
136 |
} |
137 |
|
138 |
public void addTOCContextAction(ActionInfo action) { |
139 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action)); |
140 |
} |
141 |
|
142 |
class ActionInfoAdapterToContextMenuAction implements IContextMenuAction { |
143 |
ActionInfo action = null;
|
144 |
ActionInfoAdapterToContextMenuAction(ActionInfo action) { |
145 |
this.action = action;
|
146 |
} |
147 |
public boolean isVisible(Object item, Object[] selectedItems) { |
148 |
return this.action.isVisible(); |
149 |
} |
150 |
public boolean isEnabled(Object item, Object[] selectedItems) { |
151 |
return this.action.isEnabled(); |
152 |
} |
153 |
public void execute(Object item, Object[] selectedItems) { |
154 |
this.action.execute(selectedItems);
|
155 |
} |
156 |
public String getGroup() { |
157 |
return null; |
158 |
} |
159 |
public int getGroupOrder() { |
160 |
return 0; |
161 |
} |
162 |
public int getOrder() { |
163 |
return (int) this.action.getPosition(); |
164 |
} |
165 |
public String getText() { |
166 |
return this.action.getLabel(); |
167 |
} |
168 |
public String getDescription() { |
169 |
return this.action.getTooltip(); |
170 |
} |
171 |
} |
172 |
|
173 |
public void addTOCContextAction(String id, IContextMenuAction action) { |
174 |
initializeRegisterTOCActions(); |
175 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
176 |
"View_TocActions", ""); |
177 |
if( action instanceof ExtensionBuilder ) { |
178 |
exPoint.append(id, "", (ExtensionBuilder)action);
|
179 |
return;
|
180 |
} |
181 |
exPoint.append(id, "", new ContextMenuActionAdapterToExtensionBuilder(action)); |
182 |
} |
183 |
|
184 |
class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
185 |
IContextMenuAction menuAction = null;
|
186 |
ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
187 |
this.menuAction = menuAction;
|
188 |
} |
189 |
public Object create() { |
190 |
return this.menuAction; |
191 |
} |
192 |
public Object create(Object[] args) { |
193 |
return this.menuAction; |
194 |
} |
195 |
public Object create(Map args) { |
196 |
return this.menuAction; |
197 |
} |
198 |
} |
199 |
|
200 |
private static void initializeRegisterTOCActions() { |
201 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
202 |
|
203 |
if (!epManager.has("View_TocActions")) { |
204 |
epManager.add( |
205 |
"View_TocActions",
|
206 |
"Context menu options of the TOC " +
|
207 |
" in the view window "+
|
208 |
"(register instances of " +
|
209 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
210 |
); |
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Registers in the points of extension the Factory with alias.
|
216 |
*
|
217 |
*/
|
218 |
public static void register() { |
219 |
ViewManager factory = new ViewManager();
|
220 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
221 |
|
222 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
223 |
manager.registerFactory(factory); |
224 |
|
225 |
initializeRegisterTOCActions(); |
226 |
|
227 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
228 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
229 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
230 |
|
231 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
232 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
233 |
|
234 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
235 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
236 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
237 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
238 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
239 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
240 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-rectangle", ViewManager.class); |
241 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
242 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
243 |
|
244 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
245 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
246 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
247 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
248 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
249 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
250 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
251 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
252 |
IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class); |
253 |
|
254 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
255 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
256 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
257 |
|
258 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
259 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
260 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
261 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
262 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
263 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
264 |
|
265 |
if (factory.persistenceDefinition == null){ |
266 |
factory.persistenceDefinition = manager.addDefinition( |
267 |
ViewDocument.class, |
268 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
269 |
"Default view document persistence definition",
|
270 |
null,
|
271 |
null
|
272 |
); |
273 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
274 |
|
275 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
276 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
277 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
278 |
|
279 |
} |
280 |
|
281 |
|
282 |
} |
283 |
|
284 |
@SuppressWarnings("rawtypes") |
285 |
public DynStruct getDefinition(String className) { |
286 |
|
287 |
if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
288 |
return this.persistenceDefinition; |
289 |
} |
290 |
if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
291 |
return this.persistenceDefinition; |
292 |
} |
293 |
if( this.getDocumentClass().getName().equals(className) ) { |
294 |
return this.persistenceDefinition; |
295 |
} |
296 |
|
297 |
return null; |
298 |
} |
299 |
|
300 |
@SuppressWarnings("rawtypes") |
301 |
protected Class getDocumentClass() { |
302 |
return DefaultViewDocument.class;
|
303 |
} |
304 |
|
305 |
public boolean manages(Object object) { |
306 |
return object instanceof ViewDocument; |
307 |
} |
308 |
} |