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

History | View | Annotate | Download (23.2 KB)

1 40558 jjdelcerro
/**
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 40435 jjdelcerro
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 44317 jjdelcerro
import java.util.Map;
33 41264 jjdelcerro
import javax.swing.JComponent;
34 40435 jjdelcerro
35
import javax.swing.JFileChooser;
36 41441 jjdelcerro
import javax.swing.SwingUtilities;
37 41442 jjdelcerro
import javax.swing.event.HyperlinkListener;
38 40435 jjdelcerro
import javax.swing.filechooser.FileFilter;
39 42651 jjdelcerro
import javax.swing.tree.TreeModel;
40 40435 jjdelcerro
41
import org.cresques.cts.IProjection;
42
import org.gvsig.about.AboutLocator;
43
import org.gvsig.about.AboutManager;
44 45098 jjdelcerro
import org.gvsig.andami.Arguments;
45 40435 jjdelcerro
import org.gvsig.andami.Launcher;
46
import org.gvsig.andami.PluginServices;
47 41080 jjdelcerro
import org.gvsig.andami.actioninfo.ActionInfo;
48 46010 jjdelcerro
import org.gvsig.andami.ui.ToolsWindowManager;
49 40435 jjdelcerro
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.ApplicationManager;
53
import org.gvsig.app.PreferencesNode;
54
import org.gvsig.app.extension.Version;
55 41441 jjdelcerro
import org.gvsig.app.extension.develtools.InfoPanel;
56 40435 jjdelcerro
import org.gvsig.app.gui.WizardPanel;
57
import org.gvsig.app.prepareAction.PrepareContext;
58
import org.gvsig.app.prepareAction.PrepareContextView;
59
import org.gvsig.app.prepareAction.PrepareDataStore;
60
import org.gvsig.app.prepareAction.PrepareDataStoreParameters;
61
import org.gvsig.app.prepareAction.PrepareLayer;
62
import org.gvsig.app.project.DefaultProject;
63
import org.gvsig.app.project.Project;
64
import org.gvsig.app.project.ProjectManager;
65
import org.gvsig.app.project.documents.Document;
66
import org.gvsig.app.project.documents.gui.IDocumentWindow;
67 41264 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
68 42651 jjdelcerro
import org.gvsig.app.project.documents.view.ViewManager;
69 40435 jjdelcerro
import org.gvsig.fmap.crs.CRSFactory;
70
import org.gvsig.fmap.dal.DALLocator;
71
import org.gvsig.fmap.dal.DataManager;
72
import org.gvsig.fmap.dal.DataStore;
73
import org.gvsig.fmap.dal.DataStoreParameters;
74 45532 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
75 40435 jjdelcerro
import org.gvsig.fmap.geom.GeometryLocator;
76
import org.gvsig.fmap.geom.GeometryManager;
77 45528 jjdelcerro
import org.gvsig.fmap.mapcontext.MapContext;
78 40435 jjdelcerro
import org.gvsig.fmap.mapcontext.MapContextLocator;
79
import org.gvsig.fmap.mapcontext.MapContextManager;
80
import org.gvsig.fmap.mapcontext.layers.FLayer;
81 42651 jjdelcerro
import org.gvsig.fmap.mapcontrol.CompoundLayersTreeModel;
82 45888 jjdelcerro
import org.gvsig.fmap.mapcontrol.CompoundStoresTreeModel;
83 42651 jjdelcerro
import org.gvsig.fmap.mapcontrol.MapControlLocator;
84 40435 jjdelcerro
import org.gvsig.gui.ColorTablesFactory;
85
import org.gvsig.symbology.swing.SymbologySwingLocator;
86
import org.gvsig.tools.ToolsLocator;
87
import org.gvsig.tools.dataTypes.DataTypesManager;
88
import org.gvsig.tools.dispose.DisposableManager;
89
import org.gvsig.tools.dynobject.DynObjectManager;
90
import org.gvsig.tools.extensionpoint.ExtensionPoint;
91
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
92
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
93 44330 jjdelcerro
import org.gvsig.tools.observer.Observer;
94 40435 jjdelcerro
import org.gvsig.tools.persistence.PersistenceManager;
95
import org.gvsig.tools.swing.api.ToolsSwingLocator;
96 46010 jjdelcerro
import org.gvsig.tools.swing.api.windowmanager.Dialog;
97 41441 jjdelcerro
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
98 40435 jjdelcerro
import org.gvsig.tools.swing.icontheme.IconThemeManager;
99 46010 jjdelcerro
import org.gvsig.tools.util.PropertiesSupport;
100 44317 jjdelcerro
import org.gvsig.tools.util.PropertiesSupportHelper;
101 40435 jjdelcerro
import org.slf4j.Logger;
102
import org.slf4j.LoggerFactory;
103
104
105
106
107
/**
108
 * @author jmvivo
109
 *
110
 */
111 41312 jjdelcerro
public class DefaultApplicationManager implements ApplicationManager {
112 40435 jjdelcerro
113
    @SuppressWarnings("unused")
114 41312 jjdelcerro
        private static Logger logger = LoggerFactory.getLogger(DefaultApplicationManager.class);
115 40435 jjdelcerro
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 44317 jjdelcerro
    private PropertiesSupportHelper psh;
126 40435 jjdelcerro
127 43913 jjdelcerro
    public DefaultApplicationManager() {
128 44317 jjdelcerro
        this.psh = new PropertiesSupportHelper();
129
130 43913 jjdelcerro
        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 40435 jjdelcerro
140 43913 jjdelcerro
        try {
141
            version = new Version();
142
        } catch(Exception ex) {
143
            logger.warn("Can't locate application version.");
144
        }
145
    }
146 40435 jjdelcerro
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 45098 jjdelcerro
        @Override
351
        public Arguments getArguments() {
352
                return Launcher.getArguments();
353 40435 jjdelcerro
        }
354
355 44820 jjdelcerro
  @Override
356 40435 jjdelcerro
        public String getFromClipboard() {
357
                return PluginServices.getFromClipboard();
358
        }
359
360 44820 jjdelcerro
  @Override
361 40435 jjdelcerro
        public void putInClipboard(String data) {
362
                PluginServices.putInClipboard(data);
363
        }
364
365
        public Project getCurrentProject() {
366
                return ProjectManager.getInstance().getCurrentProject();
367
        }
368
369 45528 jjdelcerro
    @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 40435 jjdelcerro
        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 45098 jjdelcerro
394
        @Override
395
        public void close(boolean quietly) {
396
            Launcher.closeApplication(quietly);
397
        }
398
399 40435 jjdelcerro
        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 41264 jjdelcerro
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 40435 jjdelcerro
450 41264 jjdelcerro
451 40435 jjdelcerro
    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 43167 jjdelcerro
        @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 40435 jjdelcerro
        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 43167 jjdelcerro
        @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 40435 jjdelcerro
        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 43913 jjdelcerro
548
        @Override
549
        public void message(String message, int message_type) {
550
                MainFrame main = PluginServices.getMainFrame();
551 45739 jjdelcerro
                if( main != null) {
552
                    main.message(message, message_type);
553
                }
554 43913 jjdelcerro
        }
555 40435 jjdelcerro
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 41080 jjdelcerro
    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 42924 jjdelcerro
        @Override
578 41080 jjdelcerro
        public void addTool(ActionInfo action, String toolBarName) {
579
                MainFrame f = this.getMainFrame();
580
                f.addTool(action,toolBarName);
581
                f.refreshControls();
582
        }
583 42924 jjdelcerro
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 41441 jjdelcerro
        public void showTextDialog(final WindowManager.MODE mode, final String title, final String htmlText) {
592 41442 jjdelcerro
            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 41441 jjdelcerro
            if (!SwingUtilities.isEventDispatchThread()) {
597
                if( mode == WindowManager.MODE.DIALOG ) {
598
                    try {
599
                        SwingUtilities.invokeAndWait(new Runnable() {
600
                            public void run() {
601 41442 jjdelcerro
                                showTextDialog(mode, title, htmlText,hyperlinkListener);
602 41441 jjdelcerro
                            }
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 41442 jjdelcerro
                            showTextDialog(mode, title, htmlText,hyperlinkListener);
611 41441 jjdelcerro
                        }
612
                    });
613
                }
614
                return;
615
            }
616 41442 jjdelcerro
            InfoPanel.showPanel(title, mode, htmlText,hyperlinkListener);
617 41441 jjdelcerro
        }
618
619 42651 jjdelcerro
        @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 44317 jjdelcerro
630
    @Override
631 45888 jjdelcerro
    public TreeModel createProjectStoresTreeModel() {
632
        CompoundStoresTreeModel model = MapControlLocator.getMapControlManager().createCompoundStoresTreeModel();
633
        Project project = this.getCurrentProject();
634
        List<Document> views = project.getDocuments(ViewManager.TYPENAME);
635
        for (Document view : views) {
636
            model.addLayers( ((ViewDocument)view).getMapContext().getLayers() );
637
        }
638
        return model;
639
    }
640
641
    @Override
642 44317 jjdelcerro
    public Object getProperty(String name) {
643
        return this.psh.getProperty(name);
644
    }
645
646
    @Override
647
    public void setProperty(String name, Object value) {
648
        this.psh.setProperty(name, value);
649
    }
650
651
    @Override
652
    public Map<String, Object> getProperties() {
653
        return this.psh.getProperties();
654
    }
655 44330 jjdelcerro
656
    @Override
657
    public void addPropertiesObserver(Observer o) {
658
        this.psh.addObserver(o);
659
    }
660
661
    @Override
662
    public void deletePropertiesObserver(Observer o) {
663
        this.psh.deleteObserver(o);
664
    }
665
666
    @Override
667
    public void deletePropertiesObservers() {
668
        this.psh.deleteObservers();
669
    }
670 45532 jjdelcerro
671
    @Override
672
    public void refreshDocument(FeatureStore store){
673
        if(store == null){
674
            return;
675
        }
676
        ProjectManager projectManager = this.getProjectManager();
677
        Project project = projectManager.getCurrentProject();
678
        for (Document doc : project.getDocuments()) {
679
            if( doc.contains(store) ) {
680
                doc.refresh();
681
            }
682
        }
683
    }
684
685 46010 jjdelcerro
    @Override
686
    public Object get(String key) {
687
        Object value = null;
688
        IWindow[] windows = this.getUIManager().getOrderedWindows();
689
        for (IWindow window : windows) {
690
            String title = window.getWindowInfo().getTitle();
691
            Object component = null;
692
            if( window instanceof PropertiesSupport ) {
693
                component = (JComponent) window;
694
            } else if( window instanceof ToolsWindowManager.Window ) {
695
                component = ((ToolsWindowManager.Window)window).getContents();
696
                if( component instanceof Dialog) {
697
                    component = ((Dialog)component).getContents();
698
                }
699
            }
700
            if( component instanceof PropertiesSupport ) {
701
                value = ((PropertiesSupport)component).getProperty(key);
702
                if( value!=null ) {
703
                    break;
704
                }
705
            }
706
        }
707
        return value;
708
    }
709
710 40435 jjdelcerro
}