Statistics
| Revision:

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 @ 47686

History | View | Annotate | Download (26.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.nio.charset.Charset;
30
import java.util.ArrayList;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
34
import javax.swing.JComponent;
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.lang3.StringUtils;
41
import org.apache.commons.lang3.tuple.ImmutablePair;
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.ToolsWindowManager;
50
import org.gvsig.andami.ui.mdiFrame.MainFrame;
51
import org.gvsig.andami.ui.mdiManager.IWindow;
52
import org.gvsig.andami.ui.mdiManager.MDIManager;
53
import org.gvsig.app.ApplicationManager;
54
import org.gvsig.app.JavaPreferencesNode;
55
import org.gvsig.app.PreferencesNode;
56
import org.gvsig.app.extension.Version;
57
import org.gvsig.app.extension.develtools.InfoPanel;
58
import org.gvsig.app.gui.WizardPanel;
59
import org.gvsig.app.prepareAction.PrepareContext;
60
import org.gvsig.app.prepareAction.PrepareContextView;
61
import org.gvsig.app.prepareAction.PrepareDataStore;
62
import org.gvsig.app.prepareAction.PrepareDataStoreParameters;
63
import org.gvsig.app.prepareAction.PrepareLayer;
64
import org.gvsig.app.project.DefaultProject;
65
import org.gvsig.app.project.Project;
66
import org.gvsig.app.project.ProjectManager;
67
import org.gvsig.app.project.documents.Document;
68
import org.gvsig.app.project.documents.gui.IDocumentWindow;
69
import org.gvsig.app.project.documents.view.ViewDocument;
70
import org.gvsig.app.project.documents.view.ViewManager;
71
import org.gvsig.fmap.crs.CRSFactory;
72
import org.gvsig.fmap.dal.DALLocator;
73
import org.gvsig.fmap.dal.DataManager;
74
import org.gvsig.fmap.dal.DataStore;
75
import org.gvsig.fmap.dal.DataStoreParameters;
76
import org.gvsig.fmap.dal.exception.DataException;
77
import org.gvsig.fmap.dal.feature.FeatureStore;
78
import org.gvsig.fmap.geom.GeometryLocator;
79
import org.gvsig.fmap.geom.GeometryManager;
80
import org.gvsig.fmap.mapcontext.MapContext;
81
import org.gvsig.fmap.mapcontext.MapContextLocator;
82
import org.gvsig.fmap.mapcontext.MapContextManager;
83
import org.gvsig.fmap.mapcontext.layers.FLayer;
84
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
85
import org.gvsig.fmap.mapcontrol.CompoundLayersTreeModel;
86
import org.gvsig.fmap.mapcontrol.CompoundStoresTreeModel;
87
import org.gvsig.fmap.mapcontrol.MapControlLocator;
88
import org.gvsig.gui.ColorTablesFactory;
89
import org.gvsig.symbology.swing.SymbologySwingLocator;
90
import org.gvsig.tools.ToolsLocator;
91
import org.gvsig.tools.dataTypes.DataTypesManager;
92
import org.gvsig.tools.dispose.DisposableManager;
93
import org.gvsig.tools.dynobject.DynObjectManager;
94
import org.gvsig.tools.extensionpoint.ExtensionPoint;
95
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
96
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
97
import org.gvsig.tools.i18n.I18nManager;
98
import org.gvsig.tools.observer.Observer;
99
import org.gvsig.tools.persistence.PersistenceManager;
100
import org.gvsig.tools.swing.api.ToolsSwingLocator;
101
import org.gvsig.tools.swing.api.windowmanager.Dialog;
102
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
103
import org.gvsig.tools.swing.icontheme.IconThemeManager;
104
import org.gvsig.tools.util.PropertiesSupport;
105
import org.gvsig.tools.util.PropertiesSupportHelper;
106
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
108

    
109

    
110

    
111

    
112
/**
113
 * @author jmvivo
114
 *
115
 */
116
public class DefaultApplicationManager implements ApplicationManager {
117

    
118
    @SuppressWarnings("unused")
119
        private static Logger logger = LoggerFactory.getLogger(DefaultApplicationManager.class);
120
    
121
        private static final String EPNAME_PREPARE_OPEN_DATASTORE = "org.gvsig.datastore.open.prepare"; //"PrepareOpenDataStore";
122
        private static final String EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS = "org.gvsig.datastoreparameters.open.prepare"; //"PrepareOpenDataStoreParameters";
123
        private static final String EPNAME_PREPARE_OPEN_LAYER = "org.gvsig.layer.open.prepare"; // "PrepareOpenLayer";
124

    
125
        private static final String EPNAME_ADD_TABLE_WIZARD = "AddLayerWizard";
126

    
127
        private ExtensionPointManager epManager;
128

    
129
    private Version version;
130
    private PropertiesSupportHelper psh;
131

    
132
    public DefaultApplicationManager() {
133
        this.psh = new PropertiesSupportHelper();
134
        
135
        epManager = ToolsLocator.getExtensionPointManager();
136
        epManager.add(EPNAME_PREPARE_OPEN_DATASTORE,
137
                "Actions to do when open a DataStore");
138
        epManager.add(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS,
139
                "Actions to do before open a DataStore with parameters");
140
        epManager.add(EPNAME_PREPARE_OPEN_LAYER,
141
                "Actions to do after create a Layer");
142
        epManager.add(EPNAME_ADD_TABLE_WIZARD,
143
                "Wizards to add new document table");
144

    
145
        try {
146
            version = new Version();
147
        } catch(Exception ex) {
148
            logger.warn("Can't locate application version.");
149
        }
150
    }
151

    
152
        /* (non-Javadoc)
153
         * @see org.gvsig.appGvSigManager#pepareOpenDataSource(org.gvsig.fmap.dal.DataStore)
154
         */
155
        @SuppressWarnings("unchecked")
156
        public DataStore pepareOpenDataSource(DataStore store,
157
                        PrepareContext context) throws Exception {
158
                ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE);
159
                if (ep.getCount() == 0) {
160
                        return store;
161
                }
162
                DataStore result = store;
163
                Iterator<ExtensionPoint.Extension> iter = ep.iterator();
164
                PrepareDataStore prepare;
165
                while (iter.hasNext()) {
166
                        prepare = (PrepareDataStore) iter.next().create();
167
                        result = prepare.prepare(store, context);
168
                }
169
                return result;
170
        }
171

    
172
        /* (non-Javadoc)
173
         * @see org.gvsig.appGvSigManager#prepareOpenDataStoreParameters(org.gvsig.fmap.dal.DataStoreParameters)
174
         */
175
        @SuppressWarnings("unchecked")
176
        public DataStoreParameters prepareOpenDataStoreParameters(
177
                        DataStoreParameters storeParameters, PrepareContext context)
178
                        throws Exception {
179

    
180
                ExtensionPoint ep = epManager
181
                                .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
182
                if (ep.getCount() == 0) {
183
                        return storeParameters;
184
                }
185
                DataStoreParameters result = storeParameters;
186
                Iterator<ExtensionPoint.Extension> iter = ep.iterator();
187
                PrepareDataStoreParameters prepare;
188
                while (iter.hasNext()) {
189
                        prepare = (PrepareDataStoreParameters) iter.next().create();
190
                        result = prepare.prepare(storeParameters, context);
191
                }
192

    
193
                return result;
194
        }
195
        
196
        /*
197
         * (non-Javadoc)
198
         * @see org.gvsig.app.ApplicationManager#prepareOpenDataStoreParameters(java.util.List, org.gvsig.app.prepareAction.PrepareContext)
199
         */
200
        @SuppressWarnings("unchecked")
201
        public List<DataStoreParameters> prepareOpenDataStoreParameters(
202
                        List<DataStoreParameters> storeParameters, PrepareContext context)
203
                        throws Exception {
204

    
205
                ExtensionPoint ep = epManager
206
                                .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
207
                if (ep.getCount() == 0) {
208
                        return storeParameters;
209
                }
210
                
211
                List<DataStoreParameters> result = new ArrayList<DataStoreParameters>();
212
                
213
                Iterator<ExtensionPoint.Extension> iter = ep.iterator();
214
                List<PrepareDataStoreParameters> prepareList = new ArrayList<PrepareDataStoreParameters>();
215
                while (iter.hasNext()) {
216
                        prepareList.add((PrepareDataStoreParameters) iter.next().create());
217
                }
218
                
219
                for (int i = 0; i < storeParameters.size(); i++) {
220
                        DataStoreParameters param = storeParameters.get(i);
221
                        for (int j = 0; j < prepareList.size(); j++) {
222
                                prepareList.get(j).pre(param, context);
223
                        }
224
                }
225
                
226
                for (int i = 0; i < storeParameters.size(); i++) {
227
                        DataStoreParameters param = storeParameters.get(i);
228
                        if(param != null) {
229
                                for (int j = 0; j < prepareList.size(); j++) {
230
                                        param = prepareList.get(j).prepare(param, context);
231
                                        if(param == null)
232
                                                break;
233
                                }
234
                                if(param != null)
235
                                        result.add(param);
236
                        }
237
                }
238
                
239
                for (int i = 0; i < storeParameters.size(); i++) {
240
                        DataStoreParameters param = storeParameters.get(i);
241
                        for (int j = 0; j < prepareList.size(); j++) {
242
                                prepareList.get(j).post(param, context);
243
                        }
244
                }
245

    
246
                return result;
247
        }
248

    
249
        public void registerPrepareOpenDataStore(PrepareDataStore action) {
250
                ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_DATASTORE);
251
                ep.append(action.getName(), action.getDescription(), action);
252
        }
253

    
254
        public void registerPrepareOpenDataStoreParameters(
255
                        PrepareDataStoreParameters action) {
256
                ExtensionPoint ep = epManager
257
                                .get(EPNAME_PREPARE_OPEN_DATASTOREPARAMETERS);
258
                ep.append(action.getName(), action.getDescription(), action);
259

    
260

    
261
        }
262

    
263
        @SuppressWarnings("unchecked")
264
        public FLayer prepareOpenLayer(FLayer layer,
265
                        PrepareContextView context)
266
                        throws Exception {
267

    
268
                ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER);
269

    
270
                if (ep.getCount() == 0) {
271
                        return layer;
272
                }
273
                FLayer result = layer;
274
                Iterator<ExtensionPoint.Extension> iter = ep.iterator();
275
                PrepareLayer prepare;
276
                while (iter.hasNext()) {
277
                        prepare = (PrepareLayer) iter.next().create();
278
                        result = prepare.prepare(result, context);
279
                }
280

    
281
                return result;
282

    
283
        }
284

    
285
        public void registerPrepareOpenLayer(PrepareLayer action) {
286
                ExtensionPoint ep = epManager.get(EPNAME_PREPARE_OPEN_LAYER);
287
                ep.append(action.getName(), action.getDescription(), action);
288
        }
289

    
290
        public void registerAddTableWizard(String name, String description,
291
                        Class<? extends WizardPanel> wpClass) {
292
                ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD);
293
                ep.append(name, description, wpClass);
294
        }
295

    
296
        @SuppressWarnings("unchecked")
297
        public List<WizardPanel> getWizardPanels() throws Exception {
298
                ExtensionPoint ep = epManager.get(EPNAME_ADD_TABLE_WIZARD);
299
                List<WizardPanel> result = new ArrayList<WizardPanel>();
300
                Iterator<Extension> iter = ep.iterator();
301
                while (iter.hasNext()) {
302
                        result.add((WizardPanel) iter.next().create());
303
                }
304
                return result;
305
        }
306

    
307
        public DataManager getDataManager() {
308
                return DALLocator.getDataManager();
309
        }
310

    
311
        public GeometryManager getGeometryManager() {
312
                return GeometryLocator.getGeometryManager();
313
        }
314

    
315
        public PersistenceManager getPersistenceManager() {
316
                return ToolsLocator.getPersistenceManager();
317
        }
318

    
319
        public DisposableManager getDisposableManager() {
320
                return ToolsLocator.getDisposableManager();
321
        }
322

    
323
        public DynObjectManager getDynObjectManager() {
324
                return ToolsLocator.getDynObjectManager();
325
        }
326

    
327
        public ExtensionPointManager getExtensionPointManager() {
328
                return ToolsLocator.getExtensionPointManager();
329
        }
330

    
331
        public ProjectManager getProjectManager() {
332
                return ProjectManager.getInstance();
333
        }
334

    
335
        public MDIManager getUIManager() {
336
                return PluginServices.getMDIManager();
337
        }
338

    
339
        public MapContextManager getMapContextManager() {
340
                return MapContextLocator.getMapContextManager();
341
        }
342

    
343
        public DataTypesManager getDataTypesManager() {
344
                return ToolsLocator.getDataTypesManager();
345
        }
346
        
347
        public IProjection getCRS(String code) {
348
                return CRSFactory.getCRS(code);
349
        }
350

    
351
        public IconThemeManager getIconThemeManager() {
352
                return ToolsSwingLocator.getIconThemeManager();
353
        }
354

    
355
        @Override
356
        public Arguments getArguments() {
357
                return Launcher.getArguments();
358
        }
359

    
360
  @Override
361
        public String getFromClipboard() {
362
                return PluginServices.getFromClipboard();
363
        }
364

    
365
  @Override
366
        public void putInClipboard(String data) {
367
                PluginServices.putInClipboard(data);
368
        }
369

    
370
        public Project getCurrentProject() {
371
                return ProjectManager.getInstance().getCurrentProject();
372
        }
373

    
374
    @Override
375
    public FLayer getCurrentLayer() {
376
        ViewDocument viewdoc = (ViewDocument) this.getActiveDocument(ViewManager.TYPENAME);
377
        if( viewdoc == null ) {
378
            return null;
379
        }
380
        MapContext mapContext = viewdoc.getMapContext();
381
        return mapContext.getLayers().getFirstActiveLayer();
382
    }
383
        
384
        public PreferencesNode getPreferences(String node) {
385
                if( node.equalsIgnoreCase("project")) {
386
                        return DefaultProject.getPreferences();
387
                }
388
        if( StringUtils.equalsIgnoreCase(node, "gvsig.foldering")){
389
            return new JavaPreferencesNode(node);
390
        }
391
                return new DefaultPreferencesNode(node);
392
        }
393

    
394
        public PreferencesNode getPreferences() {
395
                return new DefaultPreferencesNode();
396
        }
397

    
398
        public Version getVersion() {
399
        return version;
400
        }
401

    
402
        @Override
403
        public void close(boolean quietly) {
404
            Launcher.closeApplication(quietly);
405
        }
406

    
407
        public AboutManager getAbout() {
408
                AboutManager manager = AboutLocator.getManager();
409
                return manager;
410
        }
411

    
412
        public ColorTablesFactory getColorTablesFactory() {
413
                return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
414
        }
415

    
416
        public void registerColorTablesFactory(ColorTablesFactory factory) {
417
                SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory);
418
                
419
        }
420

    
421
    public IWindow getActiveWindow() {
422
        try {
423
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
424
            return window;
425
        } catch (Exception ex) {
426
            return null;
427
        }
428
    }
429

    
430
    public Document getActiveDocument() {
431
            return this.getActiveDocument((Class<? extends Document>)null);
432
    }
433
    
434
    public Document getActiveDocument(String documentTypeName) {
435
        Document document = this.getActiveDocument();
436
        if( document!= null && document.getTypeName().equalsIgnoreCase(documentTypeName) ) {
437
            return document;
438
        }
439
        return null;
440
    }
441
    
442
    @Override
443
    public Document getActiveDocument(Class<? extends Document> documentClass) {
444
        Project project = this.getCurrentProject();
445
        if( project == null ) {
446
            return null;
447
        }
448
        return project.getActiveDocument(documentClass);
449
    }
450
    
451
    public IWindow getActiveWindow(Class<? extends Document> documentClass) {
452
        Project project = this.getCurrentProject();
453
        if( project == null ) {
454
            return null;
455
        }
456
        return project.getActiveWindow(documentClass);
457
    }
458
    
459

    
460
    public JComponent getActiveComponent(Class<? extends Document> documentClass) {
461
        Document document = this.getActiveDocument(documentClass);
462
        if (document == null) {
463
            return null;
464
        }
465
        return document.getMainComponent();
466
    }
467
    
468
   
469
    public IDocumentWindow getDocumentWindow(Document document) {
470
        Class<? extends IDocumentWindow> defaultDocumentClass =
471
            document.getFactory().getMainWindowClass();
472
        return (IDocumentWindow) this.getUIManager().getSingletonWindow(defaultDocumentClass, document);
473
    }
474

    
475
        public String getLocaleLanguage() {
476
                return Launcher.getAndamiConfig().getLocaleLanguage();
477
        }
478

    
479
        public void messageDialog(String message, String title, int messageType) {
480
                MainFrame main = PluginServices.getMainFrame();
481
                main.messageDialog(message, title, messageType);
482
        }
483

    
484
        public void messageDialog(String message, String[] messageArgs,
485
                        String title, int messageType) {
486
                MainFrame main = PluginServices.getMainFrame();
487
                main.messageDialog(message, messageArgs, title, messageType);
488
        }
489

    
490
        @Override
491
        public void messageDialog(String message, String[] messageArgs, String title, int messageType, String msgid) {
492
                MainFrame main = PluginServices.getMainFrame();
493
                main.messageDialog(message, messageArgs, title, messageType, msgid);
494
        }        
495

    
496
        @Override
497
        public int confirmDialog(String message, String title, int optionType,
498
                        int messageType) {
499
                MainFrame main = PluginServices.getMainFrame();
500
                return main.confirmDialog(message, title, optionType, messageType);
501
        }
502

    
503
        @Override
504
        public int confirmDialog(String message, String title, int optionType,
505
                        int messageType, String msgid) {
506
                MainFrame main = PluginServices.getMainFrame();
507
                return main.confirmDialog(message, title, optionType, messageType, msgid);
508
        }
509

    
510
        public String inputDialog(String message, String title, int messageType,
511
                        String initialValue) {
512
                MainFrame main = PluginServices.getMainFrame();
513
                return main.inputDialog(message, title, messageType, initialValue);
514
        }
515

    
516
        public String inputDialog(String message, String title) {
517
                MainFrame main = PluginServices.getMainFrame();
518
                return main.inputDialog(message, title);
519
        }
520

    
521
        public void showDialog(Component contents, String title) {
522
                MainFrame main = PluginServices.getMainFrame();
523
                main.showDialog(contents, title);
524
        }
525

    
526
        public Component createComponent(Class<? extends Component> theClass,
527
                        Object... parameters) {
528
                MainFrame main = PluginServices.getMainFrame();
529
                return main.createComponentWithParams(theClass, parameters);
530
        }
531

    
532
        public Component createComponentWithParams(
533
                        Class<? extends Component> theClass, Object[] parameters) {
534
                MainFrame main = PluginServices.getMainFrame();
535
                return main.createComponentWithParams(theClass, parameters);
536
        }
537

    
538

    
539
        public File[] showChooserDialog(
540
                        final String title,
541
                        final int type, // SAVE_DIALOG / OPEN_DIALOG
542
                        final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
543
                        final boolean multiselection, 
544
                        final File initialPath,
545
                        final FileFilter filter,
546
                        final boolean fileHidingEnabled
547
                        ) {
548
                MainFrame main = PluginServices.getMainFrame();
549
                return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
550
        }
551
        
552
        public ImmutablePair<File[], Charset> showChooserDialog(
553
                        final String title,
554
                        final int type, // SAVE_DIALOG / OPEN_DIALOG
555
                        final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
556
                        final boolean multiselection, 
557
                        final File initialPath,
558
                        final FileFilter filter,
559
                        final boolean fileHidingEnabled,
560
                        final boolean askCharset
561
                        ) {
562
                MainFrame main = PluginServices.getMainFrame();
563
                return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled, askCharset);
564
        }
565
        
566
        public File[] showChooserDialog(
567
                        final String title,
568
                        final int type, // SAVE_DIALOG / OPEN_DIALOG
569
                        final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
570
                        final boolean multiselection, 
571
                        final File initialPath,
572
                        final FileFilter filter,
573
                        final boolean fileHidingEnabled,
574
                        final JComponent accesory
575
                        ) {
576
                MainFrame main = PluginServices.getMainFrame();
577
                return main.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled, accesory);
578
        }
579

    
580
        public File[] showOpenDirectoryDialog(String title, File initialPath) {
581
                return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
582
        }
583

    
584
        
585
        public File[] showOpenFileDialog(String title, File initialPath) {
586
                return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
587
        }
588

    
589
        
590
        public File[] showSaveFileDialog(String title, File initialPath) {
591
                return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
592
        }
593

    
594
        @Override
595
        public void message(String message, int message_type) {
596
                MainFrame main = PluginServices.getMainFrame();
597
                if( main != null) {
598
                    main.message(message, message_type);
599
                }
600
        }        
601
        
602
        public String translate(String message, String... args) {
603
                return org.gvsig.i18n.Messages.translate(message, args);
604
        }
605
        
606
        public Component getRootComponent() {
607
                return (Component) PluginServices.getMainFrame();
608
        }
609

    
610
        public void refreshMenusAndToolBars() {
611
                PluginServices.getMainFrame().refreshControls();
612
        }
613

    
614
    public MainFrame getMainFrame() {
615
        return PluginServices.getMainFrame();
616
    }
617
    
618
        public void addMenu(ActionInfo action, String text) {
619
                MainFrame f = this.getMainFrame();
620
                f.addMenu(action,text);
621
        }
622

    
623
        @Override
624
        public void addTool(ActionInfo action, String toolBarName) {
625
                MainFrame f = this.getMainFrame();
626
                f.addTool(action,toolBarName);
627
                f.refreshControls();
628
        }
629
        
630
        @Override
631
        public void addSelectableTool(ActionInfo action, String toolBarName) {
632
                MainFrame f = this.getMainFrame();
633
                f.addSelectableTool(action,toolBarName,"unico",false);
634
                f.refreshControls();
635
        }
636
                
637
        public void showTextDialog(final WindowManager.MODE mode, final String title, final String htmlText) {
638
            this.showTextDialog(mode, title, htmlText, null);
639
        }
640
        
641
        public void showTextDialog(final WindowManager.MODE mode, final String title, final String htmlText, final HyperlinkListener hyperlinkListener) {
642
            if (!SwingUtilities.isEventDispatchThread()) {
643
                if( mode == WindowManager.MODE.DIALOG ) {
644
                    try {
645
                        SwingUtilities.invokeAndWait(new Runnable() {
646
                            public void run() {
647
                                showTextDialog(mode, title, htmlText,hyperlinkListener);
648
                            }
649
                        });
650
                    } catch (Exception ex) {
651
                        logger.warn("Can't show text dialog:\n"+htmlText,ex);
652
                    }
653
                } else {
654
                    SwingUtilities.invokeLater(new Runnable() {
655
                        public void run() {
656
                            showTextDialog(mode, title, htmlText,hyperlinkListener);
657
                        }
658
                    });
659
                }
660
                return;
661
            }
662
            InfoPanel.showPanel(title, mode, htmlText,hyperlinkListener);
663
        }
664

    
665
        @Override
666
        public TreeModel createProjectLayersTreeModel() {
667
            CompoundLayersTreeModel model = (CompoundLayersTreeModel) MapControlLocator.getMapControlManager().createCompoundLayersTreeModel();
668
            Project project = this.getCurrentProject();
669
            List<Document> views = project.getDocuments(ViewManager.TYPENAME);
670
            for (Document view : views) {
671
                model.addLayers( ((ViewDocument)view).getMapContext().getLayers() );
672
            }
673
            return model;
674
        }
675

    
676
    @Override
677
    public TreeModel createProjectStoresTreeModel() {
678
        CompoundStoresTreeModel model = MapControlLocator.getMapControlManager().createCompoundStoresTreeModel();
679
        Project project = this.getCurrentProject();
680
        List<Document> views = project.getDocuments(ViewManager.TYPENAME);
681
        for (Document view : views) {
682
            model.addLayers( ((ViewDocument)view).getMapContext().getLayers() );
683
        }
684
        return model;
685
    }
686

    
687
    @Override
688
    public Object getProperty(String name) {
689
        return this.psh.getProperty(name);
690
    }
691

    
692
    @Override
693
    public void setProperty(String name, Object value) {
694
        this.psh.setProperty(name, value);
695
    }
696

    
697
    @Override
698
    public Map<String, Object> getProperties() {
699
        return this.psh.getProperties();
700
    }
701

    
702
    @Override
703
    public void addPropertiesObserver(Observer o) {
704
        this.psh.addObserver(o);
705
    }
706

    
707
    @Override
708
    public void deletePropertiesObserver(Observer o) {
709
        this.psh.deleteObserver(o);
710
    }
711

    
712
    @Override
713
    public void deletePropertiesObservers() {
714
        this.psh.deleteObservers();
715
    }
716

    
717
    @Override
718
    public void refreshDocument(FeatureStore store) {
719
        if (store == null) {
720
            return;
721
        }
722
        refreshDocument(store.getParameters());
723
    }
724

    
725
    @Override
726
    public void refreshDocument(DataStoreParameters params) {
727
        if (params == null) {
728
            return;
729
        }
730
        if(!SwingUtilities.isEventDispatchThread()){
731
            SwingUtilities.invokeLater(() -> {
732
                refreshDocument(params);
733
            });
734
            return;
735
        }
736
        ProjectManager projectManager = this.getProjectManager();
737
        Project project = projectManager.getCurrentProject();
738
        for (Document doc : project.getDocuments()) {
739
            if (doc.contains(params)) {
740
                if (StringUtils.equals(doc.getTypeName(), ViewManager.TYPENAME)) {
741
                    ViewDocument view = (ViewDocument) doc;
742
                    for (Iterator<FLayer> it = view.deepiterator(); it.hasNext();) {
743
                        FLayer layer = it.next();
744
                        if (layer instanceof SingleLayer) {
745
                            DataStore layerStore = ((SingleLayer) layer).getDataStore();
746
                            if ( layerStore!=null && params.isTheSameStore(layerStore.getParameters())) {
747
                                try {
748
                                    layer.invalidate();
749
                                } catch (Exception ex) {
750
                                    logger.debug("Can't refresh layer "+layerStore.getFullName(), ex);
751
                                }
752
                            }
753
                        }
754
                    }
755
                }
756
                doc.refresh();
757
            }
758
        }
759
    }
760

    
761
    @Override
762
    public Object get(String key) {
763
        Object value = null;
764
        IWindow[] windows = this.getUIManager().getOrderedWindows();
765
        for (IWindow window : windows) {
766
            String title = window.getWindowInfo().getTitle();
767
            Object component = null;
768
            if( window instanceof PropertiesSupport ) {
769
                component = (JComponent) window;
770
            } else if( window instanceof ToolsWindowManager.Window ) {
771
                component = ((ToolsWindowManager.Window)window).getContents();
772
                if( component instanceof Dialog) {
773
                    component = ((Dialog)component).getContents();
774
                }
775
            }
776
            if( component instanceof PropertiesSupport ) {
777
                value = ((PropertiesSupport)component).getProperty(key);
778
                if( value!=null ) {
779
                    break;
780
                }
781
            } 
782
        }
783
        return value;
784
    }
785

    
786
    @Override
787
    public String makeTitle(String base, String docname, String docname2) {
788
        I18nManager i18n = ToolsLocator.getI18nManager();
789
//        if( StringUtils.startsWith(base, "_") ) {
790
            base = i18n.getTranslation(base);
791
//        }
792
        String title = base + ": " + docname;
793
        if( StringUtils.isNotBlank(docname2) && !StringUtils.equals(docname, docname2)) {
794
            title = title + " ("+docname2+")";
795
        }
796
        return title;
797
    }
798

    
799
}