svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / imp / DefaultApplicationManager.java @ 45739
History | View | Annotate | Download (21.8 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 |
|
25 |
package org.gvsig.app.imp; |
26 |
|
27 |
import java.awt.Component; |
28 |
import java.io.File; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Iterator; |
31 |
import java.util.List; |
32 |
import java.util.Map; |
33 |
import javax.swing.JComponent; |
34 |
|
35 |
import javax.swing.JFileChooser; |
36 |
import javax.swing.SwingUtilities; |
37 |
import javax.swing.event.HyperlinkListener; |
38 |
import javax.swing.filechooser.FileFilter; |
39 |
import javax.swing.tree.TreeModel; |
40 |
import org.apache.commons.lang.StringUtils; |
41 |
|
42 |
import org.cresques.cts.IProjection; |
43 |
import org.gvsig.about.AboutLocator; |
44 |
import org.gvsig.about.AboutManager; |
45 |
import org.gvsig.andami.Arguments; |
46 |
import org.gvsig.andami.Launcher; |
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.andami.actioninfo.ActionInfo; |
49 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
50 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
51 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
52 |
import org.gvsig.app.ApplicationLocator; |
53 |
import org.gvsig.app.ApplicationManager; |
54 |
import org.gvsig.app.PreferencesNode; |
55 |
import org.gvsig.app.extension.Version; |
56 |
import org.gvsig.app.extension.develtools.InfoPanel; |
57 |
import org.gvsig.app.gui.WizardPanel; |
58 |
import org.gvsig.app.prepareAction.PrepareContext; |
59 |
import org.gvsig.app.prepareAction.PrepareContextView; |
60 |
import org.gvsig.app.prepareAction.PrepareDataStore; |
61 |
import org.gvsig.app.prepareAction.PrepareDataStoreParameters; |
62 |
import org.gvsig.app.prepareAction.PrepareLayer; |
63 |
import org.gvsig.app.project.DefaultProject; |
64 |
import org.gvsig.app.project.Project; |
65 |
import org.gvsig.app.project.ProjectManager; |
66 |
import org.gvsig.app.project.documents.Document; |
67 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
68 |
import org.gvsig.app.project.documents.view.ViewDocument; |
69 |
import org.gvsig.app.project.documents.view.ViewManager; |
70 |
import org.gvsig.fmap.crs.CRSFactory; |
71 |
import org.gvsig.fmap.dal.DALLocator; |
72 |
import org.gvsig.fmap.dal.DataManager; |
73 |
import org.gvsig.fmap.dal.DataStore; |
74 |
import org.gvsig.fmap.dal.DataStoreParameters; |
75 |
import org.gvsig.fmap.dal.exception.DataException; |
76 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
77 |
import org.gvsig.fmap.geom.GeometryLocator; |
78 |
import org.gvsig.fmap.geom.GeometryManager; |
79 |
import org.gvsig.fmap.mapcontext.MapContext; |
80 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
81 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
82 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
83 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
84 |
import org.gvsig.fmap.mapcontrol.CompoundLayersTreeModel; |
85 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
86 |
import org.gvsig.gui.ColorTablesFactory; |
87 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
88 |
import org.gvsig.tools.ToolsLocator; |
89 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
90 |
import org.gvsig.tools.dispose.DisposableManager; |
91 |
import org.gvsig.tools.dynobject.DynObjectManager; |
92 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
93 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
94 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
95 |
import org.gvsig.tools.observer.Observer; |
96 |
import org.gvsig.tools.persistence.PersistenceManager; |
97 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
98 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
99 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
100 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
101 |
import org.slf4j.Logger; |
102 |
import org.slf4j.LoggerFactory; |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
/**
|
108 |
* @author jmvivo
|
109 |
*
|
110 |
*/
|
111 |
public class DefaultApplicationManager implements ApplicationManager { |
112 |
|
113 |
@SuppressWarnings("unused") |
114 |
private static Logger logger = LoggerFactory.getLogger(DefaultApplicationManager.class); |
115 |
|
116 |
private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore"; |
117 |
private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters"; |
118 |
private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer"; |
119 |
|
120 |
private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard"; |
121 |
|
122 |
private ExtensionPointManager epManager;
|
123 |
|
124 |
private Version version;
|
125 |
private PropertiesSupportHelper psh;
|
126 |
|
127 |
public DefaultApplicationManager() {
|
128 |
this.psh = new PropertiesSupportHelper(); |
129 |
|
130 |
epManager = ToolsLocator.getExtensionPointManager(); |
131 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTORE, |
132 |
"Actions to do when open a DataStore");
|
133 |
epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS, |
134 |
"Actions to do before open a DataStore with parameters");
|
135 |
epManager.add(EPNAME_PREPARE_OPEN_LAYER, |
136 |
"Actions to do after create a Layer");
|
137 |
epManager.add(EPNAME_ADD_TABLE_WIZARD, |
138 |
"Wizards to add new document table");
|
139 |
|
140 |
try {
|
141 |
version = new Version();
|
142 |
} catch(Exception ex) { |
143 |
logger.warn("Can't locate application version.");
|
144 |
} |
145 |
} |
146 |
|
147 |
/* (non-Javadoc)
|
148 |
* @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
|
149 |
*/
|
150 |
@SuppressWarnings("unchecked") |
151 |
public DataStore pepareOpenDataSource(DataStore store,
|
152 |
PrepareContext context) throws Exception { |
153 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
154 |
if (ep.getCount() == 0) { |
155 |
return store;
|
156 |
} |
157 |
DataStore result = store; |
158 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
159 |
PrepareDataStore prepare; |
160 |
while (iter.hasNext()) {
|
161 |
prepare = (PrepareDataStore) iter.next().create(); |
162 |
result = prepare.prepare(store, context); |
163 |
} |
164 |
return result;
|
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
|
169 |
*/
|
170 |
@SuppressWarnings("unchecked") |
171 |
public DataStoreParameters prepareOpenDataStoreParameters(
|
172 |
DataStoreParameters storeParameters, PrepareContext context) |
173 |
throws Exception { |
174 |
|
175 |
ExtensionPoint ep = epManager |
176 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
177 |
if (ep.getCount() == 0) { |
178 |
return storeParameters;
|
179 |
} |
180 |
DataStoreParameters result = storeParameters; |
181 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
182 |
PrepareDataStoreParameters prepare; |
183 |
while (iter.hasNext()) {
|
184 |
prepare = (PrepareDataStoreParameters) iter.next().create(); |
185 |
result = prepare.prepare(storeParameters, context); |
186 |
} |
187 |
|
188 |
return result;
|
189 |
} |
190 |
|
191 |
/*
|
192 |
* (non-Javadoc)
|
193 |
* @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
|
194 |
*/
|
195 |
@SuppressWarnings("unchecked") |
196 |
public List<DataStoreParameters> prepareOpenDataStoreParameters( |
197 |
List<DataStoreParameters> storeParameters, PrepareContext context)
|
198 |
throws Exception { |
199 |
|
200 |
ExtensionPoint ep = epManager |
201 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
202 |
if (ep.getCount() == 0) { |
203 |
return storeParameters;
|
204 |
} |
205 |
|
206 |
List<DataStoreParameters> result = new ArrayList<DataStoreParameters>(); |
207 |
|
208 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
209 |
List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>(); |
210 |
while (iter.hasNext()) {
|
211 |
prepareList.add((PrepareDataStoreParameters) iter.next().create()); |
212 |
} |
213 |
|
214 |
for (int i = 0; i < storeParameters.size(); i++) { |
215 |
DataStoreParameters param = storeParameters.get(i); |
216 |
for (int j = 0; j < prepareList.size(); j++) { |
217 |
prepareList.get(j).pre(param, context); |
218 |
} |
219 |
} |
220 |
|
221 |
for (int i = 0; i < storeParameters.size(); i++) { |
222 |
DataStoreParameters param = storeParameters.get(i); |
223 |
if(param != null) { |
224 |
for (int j = 0; j < prepareList.size(); j++) { |
225 |
param = prepareList.get(j).prepare(param, context); |
226 |
if(param == null) |
227 |
break;
|
228 |
} |
229 |
if(param != null) |
230 |
result.add(param); |
231 |
} |
232 |
} |
233 |
|
234 |
for (int i = 0; i < storeParameters.size(); i++) { |
235 |
DataStoreParameters param = storeParameters.get(i); |
236 |
for (int j = 0; j < prepareList.size(); j++) { |
237 |
prepareList.get(j).post(param, context); |
238 |
} |
239 |
} |
240 |
|
241 |
return result;
|
242 |
} |
243 |
|
244 |
public void registerPrepareOpenDataStore(PrepareDataStore action) { |
245 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE); |
246 |
ep.append(action.getName(), action.getDescription(), action); |
247 |
} |
248 |
|
249 |
public void registerPrepareOpenDataStoreParameters( |
250 |
PrepareDataStoreParameters action) { |
251 |
ExtensionPoint ep = epManager |
252 |
.get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS); |
253 |
ep.append(action.getName(), action.getDescription(), action); |
254 |
|
255 |
|
256 |
} |
257 |
|
258 |
@SuppressWarnings("unchecked") |
259 |
public FLayer prepareOpenLayer(FLayer layer,
|
260 |
PrepareContextView context) |
261 |
throws Exception { |
262 |
|
263 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
264 |
|
265 |
if (ep.getCount() == 0) { |
266 |
return layer;
|
267 |
} |
268 |
FLayer result = layer; |
269 |
Iterator<ExtensionPoint.Extension> iter = ep.iterator();
|
270 |
PrepareLayer prepare; |
271 |
while (iter.hasNext()) {
|
272 |
prepare = (PrepareLayer) iter.next().create(); |
273 |
result = prepare.prepare(result, context); |
274 |
} |
275 |
|
276 |
return result;
|
277 |
|
278 |
} |
279 |
|
280 |
public void registerPrepareOpenLayer(PrepareLayer action) { |
281 |
ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER); |
282 |
ep.append(action.getName(), action.getDescription(), action); |
283 |
} |
284 |
|
285 |
public void registerAddTableWizard(String name, String description, |
286 |
Class<? extends WizardPanel> wpClass) { |
287 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
288 |
ep.append(name, description, wpClass); |
289 |
} |
290 |
|
291 |
@SuppressWarnings("unchecked") |
292 |
public List<WizardPanel> getWizardPanels() throws Exception { |
293 |
ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD); |
294 |
List<WizardPanel> result = new ArrayList<WizardPanel>(); |
295 |
Iterator<Extension> iter = ep.iterator();
|
296 |
while (iter.hasNext()) {
|
297 |
result.add((WizardPanel) iter.next().create()); |
298 |
} |
299 |
return result;
|
300 |
} |
301 |
|
302 |
public DataManager getDataManager() {
|
303 |
return DALLocator.getDataManager();
|
304 |
} |
305 |
|
306 |
public GeometryManager getGeometryManager() {
|
307 |
return GeometryLocator.getGeometryManager();
|
308 |
} |
309 |
|
310 |
public PersistenceManager getPersistenceManager() {
|
311 |
return ToolsLocator.getPersistenceManager();
|
312 |
} |
313 |
|
314 |
public DisposableManager getDisposableManager() {
|
315 |
return ToolsLocator.getDisposableManager();
|
316 |
} |
317 |
|
318 |
public DynObjectManager getDynObjectManager() {
|
319 |
return ToolsLocator.getDynObjectManager();
|
320 |
} |
321 |
|
322 |
public ExtensionPointManager getExtensionPointManager() {
|
323 |
return ToolsLocator.getExtensionPointManager();
|
324 |
} |
325 |
|
326 |
public ProjectManager getProjectManager() {
|
327 |
return ProjectManager.getInstance();
|
328 |
} |
329 |
|
330 |
public MDIManager getUIManager() {
|
331 |
return PluginServices.getMDIManager();
|
332 |
} |
333 |
|
334 |
public MapContextManager getMapContextManager() {
|
335 |
return MapContextLocator.getMapContextManager();
|
336 |
} |
337 |
|
338 |
public DataTypesManager getDataTypesManager() {
|
339 |
return ToolsLocator.getDataTypesManager();
|
340 |
} |
341 |
|
342 |
public IProjection getCRS(String code) { |
343 |
return CRSFactory.getCRS(code);
|
344 |
} |
345 |
|
346 |
public IconThemeManager getIconThemeManager() {
|
347 |
return ToolsSwingLocator.getIconThemeManager();
|
348 |
} |
349 |
|
350 |
@Override
|
351 |
public Arguments getArguments() {
|
352 |
return Launcher.getArguments();
|
353 |
} |
354 |
|
355 |
@Override
|
356 |
public String getFromClipboard() { |
357 |
return PluginServices.getFromClipboard();
|
358 |
} |
359 |
|
360 |
@Override
|
361 |
public void putInClipboard(String data) { |
362 |
PluginServices.putInClipboard(data); |
363 |
} |
364 |
|
365 |
public Project getCurrentProject() {
|
366 |
return ProjectManager.getInstance().getCurrentProject();
|
367 |
} |
368 |
|
369 |
@Override
|
370 |
public FLayer getCurrentLayer() {
|
371 |
ViewDocument viewdoc = (ViewDocument) this.getActiveDocument(ViewManager.TYPENAME);
|
372 |
if( viewdoc == null ) { |
373 |
return null; |
374 |
} |
375 |
MapContext mapContext = viewdoc.getMapContext(); |
376 |
return mapContext.getLayers().getFirstActiveLayer();
|
377 |
} |
378 |
|
379 |
public PreferencesNode getPreferences(String node) { |
380 |
if( node.equalsIgnoreCase("project")) { |
381 |
return DefaultProject.getPreferences();
|
382 |
} |
383 |
return new DefaultPreferencesNode(node); |
384 |
} |
385 |
|
386 |
public PreferencesNode getPreferences() {
|
387 |
return new DefaultPreferencesNode(); |
388 |
} |
389 |
|
390 |
public Version getVersion() {
|
391 |
return version;
|
392 |
} |
393 |
|
394 |
@Override
|
395 |
public void close(boolean quietly) { |
396 |
Launcher.closeApplication(quietly); |
397 |
} |
398 |
|
399 |
public AboutManager getAbout() {
|
400 |
AboutManager manager = AboutLocator.getManager(); |
401 |
return manager;
|
402 |
} |
403 |
|
404 |
public ColorTablesFactory getColorTablesFactory() {
|
405 |
return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
|
406 |
} |
407 |
|
408 |
public void registerColorTablesFactory(ColorTablesFactory factory) { |
409 |
SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory); |
410 |
|
411 |
} |
412 |
|
413 |
public IWindow getActiveWindow() {
|
414 |
try {
|
415 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
416 |
return window;
|
417 |
} catch (Exception ex) { |
418 |
return null; |
419 |
} |
420 |
} |
421 |
|
422 |
public Document getActiveDocument() { |
423 |
return this.getActiveDocument((Class<? extends Document>)null); |
424 |
} |
425 |
|
426 |
public Document getActiveDocument(String documentTypeName) { |
427 |
Document document = this.getActiveDocument(); |
428 |
if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) { |
429 |
return document;
|
430 |
} |
431 |
return null; |
432 |
} |
433 |
|
434 |
public Document getActiveDocument(Class<? extends Document> documentClass) { |
435 |
Project project = this.getCurrentProject();
|
436 |
if( project == null ) { |
437 |
return null; |
438 |
} |
439 |
return project.getActiveDocument(documentClass);
|
440 |
} |
441 |
|
442 |
public JComponent getActiveComponent(Class<? extends Document> documentClass) { |
443 |
Document document = this.getActiveDocument(documentClass); |
444 |
if (document == null) { |
445 |
return null; |
446 |
} |
447 |
return document.getMainComponent();
|
448 |
} |
449 |
|
450 |
|
451 |
public IDocumentWindow getDocumentWindow(Document document) { |
452 |
Class<? extends IDocumentWindow> defaultDocumentClass = |
453 |
document.getFactory().getMainWindowClass(); |
454 |
return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document); |
455 |
} |
456 |
|
457 |
public String getLocaleLanguage() { |
458 |
return Launcher.getAndamiConfig().getLocaleLanguage();
|
459 |
} |
460 |
|
461 |
public void messageDialog(String message, String title, int messageType) { |
462 |
MainFrame main = PluginServices.getMainFrame(); |
463 |
main.messageDialog(message, title, messageType); |
464 |
} |
465 |
|
466 |
public void messageDialog(String message, String[] messageArgs, |
467 |
String title, int messageType) { |
468 |
MainFrame main = PluginServices.getMainFrame(); |
469 |
main.messageDialog(message, messageArgs, title, messageType); |
470 |
} |
471 |
|
472 |
@Override
|
473 |
public void messageDialog(String message, String[] messageArgs, String title, int messageType, String msgid) { |
474 |
MainFrame main = PluginServices.getMainFrame(); |
475 |
main.messageDialog(message, messageArgs, title, messageType, msgid); |
476 |
} |
477 |
|
478 |
@Override
|
479 |
public int confirmDialog(String message, String title, int optionType, |
480 |
int messageType) {
|
481 |
MainFrame main = PluginServices.getMainFrame(); |
482 |
return main.confirmDialog(message, title, optionType, messageType);
|
483 |
} |
484 |
|
485 |
@Override
|
486 |
public int confirmDialog(String message, String title, int optionType, |
487 |
int messageType, String msgid) { |
488 |
MainFrame main = PluginServices.getMainFrame(); |
489 |
return main.confirmDialog(message, title, optionType, messageType, msgid);
|
490 |
} |
491 |
|
492 |
public String inputDialog(String message, String title, int messageType, |
493 |
String initialValue) {
|
494 |
MainFrame main = PluginServices.getMainFrame(); |
495 |
return main.inputDialog(message, title, messageType, initialValue);
|
496 |
} |
497 |
|
498 |
public String inputDialog(String message, String title) { |
499 |
MainFrame main = PluginServices.getMainFrame(); |
500 |
return main.inputDialog(message, title);
|
501 |
} |
502 |
|
503 |
public void showDialog(Component contents, String title) { |
504 |
MainFrame main = PluginServices.getMainFrame(); |
505 |
main.showDialog(contents, title); |
506 |
} |
507 |
|
508 |
public Component createComponent(Class<? extends Component> theClass, |
509 |
Object... parameters) {
|
510 |
MainFrame main = PluginServices.getMainFrame(); |
511 |
return main.createComponentWithParams(theClass, parameters);
|
512 |
} |
513 |
|
514 |
public Component createComponentWithParams( |
515 |
Class<? extends Component> theClass, Object[] parameters) { |
516 |
MainFrame main = PluginServices.getMainFrame(); |
517 |
return main.createComponentWithParams(theClass, parameters);
|
518 |
} |
519 |
|
520 |
|
521 |
public File[] showChooserDialog( |
522 |
final String title, |
523 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
524 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
525 |
final boolean multiselection, |
526 |
final File initialPath, |
527 |
final FileFilter filter, |
528 |
final boolean fileHidingEnabled |
529 |
) { |
530 |
MainFrame main = PluginServices.getMainFrame(); |
531 |
return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
|
532 |
} |
533 |
|
534 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
535 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
536 |
} |
537 |
|
538 |
|
539 |
public File[] showOpenFileDialog(String title, File initialPath) { |
540 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
541 |
} |
542 |
|
543 |
|
544 |
public File[] showSaveFileDialog(String title, File initialPath) { |
545 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
546 |
} |
547 |
|
548 |
@Override
|
549 |
public void message(String message, int message_type) { |
550 |
MainFrame main = PluginServices.getMainFrame(); |
551 |
if( main != null) { |
552 |
main.message(message, message_type); |
553 |
} |
554 |
} |
555 |
|
556 |
public String translate(String message, String... args) { |
557 |
return org.gvsig.i18n.Messages.translate(message, args);
|
558 |
} |
559 |
|
560 |
public Component getRootComponent() { |
561 |
return (Component) PluginServices.getMainFrame(); |
562 |
} |
563 |
|
564 |
public void refreshMenusAndToolBars() { |
565 |
PluginServices.getMainFrame().refreshControls(); |
566 |
} |
567 |
|
568 |
public MainFrame getMainFrame() {
|
569 |
return PluginServices.getMainFrame();
|
570 |
} |
571 |
|
572 |
public void addMenu(ActionInfo action, String text) { |
573 |
MainFrame f = this.getMainFrame();
|
574 |
f.addMenu(action,text); |
575 |
} |
576 |
|
577 |
@Override
|
578 |
public void addTool(ActionInfo action, String toolBarName) { |
579 |
MainFrame f = this.getMainFrame();
|
580 |
f.addTool(action,toolBarName); |
581 |
f.refreshControls(); |
582 |
} |
583 |
|
584 |
@Override
|
585 |
public void addSelectableTool(ActionInfo action, String toolBarName) { |
586 |
MainFrame f = this.getMainFrame();
|
587 |
f.addSelectableTool(action,toolBarName,"unico",false); |
588 |
f.refreshControls(); |
589 |
} |
590 |
|
591 |
public void showTextDialog(final WindowManager.MODE mode, final String title, final String htmlText) { |
592 |
this.showTextDialog(mode, title, htmlText, null); |
593 |
} |
594 |
|
595 |
public void showTextDialog(final WindowManager.MODE mode, final String title, final String htmlText, final HyperlinkListener hyperlinkListener) { |
596 |
if (!SwingUtilities.isEventDispatchThread()) { |
597 |
if( mode == WindowManager.MODE.DIALOG ) {
|
598 |
try {
|
599 |
SwingUtilities.invokeAndWait(new Runnable() { |
600 |
public void run() { |
601 |
showTextDialog(mode, title, htmlText,hyperlinkListener); |
602 |
} |
603 |
}); |
604 |
} catch (Exception ex) { |
605 |
logger.warn("Can't show text dialog:\n"+htmlText,ex);
|
606 |
} |
607 |
} else {
|
608 |
SwingUtilities.invokeLater(new Runnable() { |
609 |
public void run() { |
610 |
showTextDialog(mode, title, htmlText,hyperlinkListener); |
611 |
} |
612 |
}); |
613 |
} |
614 |
return;
|
615 |
} |
616 |
InfoPanel.showPanel(title, mode, htmlText,hyperlinkListener); |
617 |
} |
618 |
|
619 |
@Override
|
620 |
public TreeModel createProjectLayersTreeModel() { |
621 |
CompoundLayersTreeModel model = (CompoundLayersTreeModel) MapControlLocator.getMapControlManager().createCompoundLayersTreeModel(); |
622 |
Project project = this.getCurrentProject();
|
623 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
624 |
for (Document view : views) { |
625 |
model.addLayers( ((ViewDocument)view).getMapContext().getLayers() ); |
626 |
} |
627 |
return model;
|
628 |
} |
629 |
|
630 |
@Override
|
631 |
public Object getProperty(String name) { |
632 |
return this.psh.getProperty(name); |
633 |
} |
634 |
|
635 |
@Override
|
636 |
public void setProperty(String name, Object value) { |
637 |
this.psh.setProperty(name, value);
|
638 |
} |
639 |
|
640 |
@Override
|
641 |
public Map<String, Object> getProperties() { |
642 |
return this.psh.getProperties(); |
643 |
} |
644 |
|
645 |
@Override
|
646 |
public void addPropertiesObserver(Observer o) { |
647 |
this.psh.addObserver(o);
|
648 |
} |
649 |
|
650 |
@Override
|
651 |
public void deletePropertiesObserver(Observer o) { |
652 |
this.psh.deleteObserver(o);
|
653 |
} |
654 |
|
655 |
@Override
|
656 |
public void deletePropertiesObservers() { |
657 |
this.psh.deleteObservers();
|
658 |
} |
659 |
|
660 |
@Override
|
661 |
public void refreshDocument(FeatureStore store){ |
662 |
if(store == null){ |
663 |
return;
|
664 |
} |
665 |
ProjectManager projectManager = this.getProjectManager();
|
666 |
Project project = projectManager.getCurrentProject(); |
667 |
for (Document doc : project.getDocuments()) { |
668 |
if( doc.contains(store) ) {
|
669 |
doc.refresh(); |
670 |
} |
671 |
} |
672 |
} |
673 |
|
674 |
} |