Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / MDIFrame.java @ 42161

History | View | Annotate | Download (67.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami.ui.mdiFrame;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.Dimension;
29
import java.awt.FlowLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ComponentEvent;
34
import java.awt.event.ComponentListener;
35
import java.awt.event.ContainerEvent;
36
import java.awt.event.ContainerListener;
37
import java.awt.event.MouseAdapter;
38
import java.awt.event.MouseEvent;
39
import java.awt.event.WindowAdapter;
40
import java.awt.event.WindowEvent;
41
import java.io.File;
42
import java.util.ArrayList;
43
import java.util.Enumeration;
44
import java.util.HashMap;
45
import java.util.Iterator;
46
import java.util.List;
47
import java.util.Locale;
48
import java.util.Map;
49
import java.util.NoSuchElementException;
50
import java.util.StringTokenizer;
51
import java.util.Vector;
52

    
53
import javax.swing.AbstractButton;
54
import javax.swing.ButtonGroup;
55
import javax.swing.ImageIcon;
56
import javax.swing.JComponent;
57
import javax.swing.JFileChooser;
58
import javax.swing.JFrame;
59
import javax.swing.JMenu;
60
import javax.swing.JMenuBar;
61
import javax.swing.JOptionPane;
62
import javax.swing.JPanel;
63
import javax.swing.JPopupMenu;
64
import javax.swing.JSeparator;
65
import javax.swing.JToolBar;
66
import javax.swing.KeyStroke;
67
import javax.swing.MenuElement;
68
import javax.swing.SwingUtilities;
69
import javax.swing.Timer;
70
import javax.swing.WindowConstants;
71
import javax.swing.filechooser.FileFilter;
72

    
73
import org.gvsig.andami.IconThemeHelper;
74
import org.gvsig.andami.Launcher;
75
import org.gvsig.andami.PluginServices;
76
import org.gvsig.andami.PluginsLocator;
77
import org.gvsig.andami.PluginsManager;
78
import org.gvsig.andami.actioninfo.ActionInfo;
79
import org.gvsig.andami.actioninfo.ActionInfoManager;
80
import org.gvsig.andami.actioninfo.ActionInfoStatusCache;
81
import org.gvsig.andami.messages.Messages;
82
import org.gvsig.andami.plugins.ExtensionDecorator;
83
import org.gvsig.andami.plugins.IExtension;
84
import org.gvsig.andami.plugins.PluginClassLoader;
85
import org.gvsig.andami.plugins.config.generate.ActionTool;
86
import org.gvsig.andami.plugins.config.generate.Label;
87
import org.gvsig.andami.plugins.config.generate.Menu;
88
import org.gvsig.andami.plugins.config.generate.PopupMenu;
89
import org.gvsig.andami.plugins.config.generate.SelectableTool;
90
import org.gvsig.andami.plugins.config.generate.SkinExtensionType;
91
import org.gvsig.andami.plugins.config.generate.ToolBar;
92
import org.gvsig.andami.ui.mdiFrame.TranslatableButtonHelper.TranslatableButton;
93
import org.gvsig.andami.ui.mdiManager.MDIManager;
94
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
95
import org.gvsig.gui.beans.controls.IControl;
96
import org.gvsig.tools.ToolsLocator;
97
import org.gvsig.tools.i18n.I18nManager;
98
import org.gvsig.tools.swing.api.ToolsSwingLocator;
99
import org.gvsig.tools.swing.icontheme.IconTheme;
100
import org.slf4j.Logger;
101
import org.slf4j.LoggerFactory;
102

    
103
/**
104
 * Main application window.
105
 *
106
 * Use Launcher.getMDIFrame to get the instance of this class.
107
 *
108
 * @version $Revision: 39484 $
109
 */
110
@SuppressWarnings("unchecked")
111
public class MDIFrame extends JFrame implements ComponentListener,
112
        ContainerListener, ActionListener, MainFrame {
113

    
114
    private static final long serialVersionUID = -2472484309160847654L;
115

    
116
    private static Logger logger = LoggerFactory.getLogger(MDIFrame.class);
117

    
118
    private static MDIFrame instance = null;
119

    
120
    private MDIManager mdiManager = MDIManagerFactory.createManager();
121

    
122
    /**
123
     * Elementos de la aplicaci?n
124
     */
125
    private JMenuBar menuBar = new JMenuBar();
126

    
127
    /**
128
     * Panel which contains the toolbars
129
     */
130
    private JPanel toolBars = new JPanel();
131

    
132
    /**
133
     * Status bar
134
     */
135
    private NewStatusBar bEstado = null;
136

    
137
    /**
138
     * Asocia los nombres con las barras de herramientas
139
     */
140
    private HashMap toolBarMap = new HashMap();
141

    
142
    /**
143
     * Almacena los grupos de selectableTools
144
     */
145
    private HashMap buttonGroupMap = new HashMap();
146
    /**
147
     * Stores the initially selected tools.
148
     * It contains pairs (String groupName, JToolBarToggleButton button)
149
     */
150
    private HashMap initialSelectedTools = new HashMap();
151

    
152
    /**
153
     * Stores the actionCommand of the selected tool, for each group.
154
     * It contains pairs (String groupName, JToolBarToggleButton button)
155
     */
156
    private Map selectedTool = null;
157
    // this should be the same value defined at plugin-config.xsd
158
    private String defaultGroup = "unico";
159

    
160
    /**
161
     * Asocia los nombres con los popupMenus
162
     */
163
    private HashMap popupMap = new HashMap();
164

    
165
    /**
166
     * Asocia controles con la clase de la extension asociada
167
     */
168
    private List<JComponent> controls = new ArrayList<JComponent>();
169

    
170
    /**
171
     * Asocia la informaci?n sobre las etiquetas que van en la status bar con
172
     * cada extension
173
     */
174
    private HashMap classLabels = new HashMap();
175

    
176
    // private HashMap classControls = new HashMap();
177
    /**
178
     * ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener)
179
     */
180
    private ArrayList progressListeners = new ArrayList();
181

    
182
    /**
183
     * Timer para invocar los enventos de la interfaz anterior
184
     */
185
    private Timer progressTimer = null;
186

    
187
    /**
188
     * Tabla hash que asocia las clases con las extensiones
189
     */
190
    // private Map classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
191
    /**
192
     * ?ltima clase que activ? etiquetas
193
     */
194
    private Class lastLabelClass;
195

    
196
    /**
197
     * Instancia que pone los tooltip en la barra de estado
198
     */
199
    private TooltipListener tooltipListener = new TooltipListener();
200

    
201
    private HashMap infoCodedMenus = new HashMap();
202

    
203
    private String titlePrefix;
204

    
205
    private static final String noIcon = "no-icon";
206

    
207
    private Map<JComponent,IExtension> control2extensions = new HashMap<JComponent, IExtension>();
208

    
209
    private MDIFrame() {
210

    
211
    }
212

    
213
    public static boolean isInitialized() {
214
        return instance!=null ;
215
    }
216

    
217
    public static MDIFrame getInstance() {
218
        if ( instance == null ) {
219
            instance = new MDIFrame();
220
        }
221
        return instance;
222
    }
223

    
224
    /**
225
     * Makes some initialization tasks.
226
     *
227
     * @throws RuntimeException
228
     */
229
    public void init() {
230
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
231
        if ( !SwingUtilities.isEventDispatchThread() ) {
232
            throw new RuntimeException("Not Event Dispatch Thread");
233
        }
234

    
235
        // Se a?aden los listeners del JFrame
236
        this.addWindowListener(new WindowAdapter() {
237

    
238
            @Override
239
            public void windowClosing(WindowEvent e) {
240
                Launcher.closeApplication();
241
            }
242
        });
243
        this.addComponentListener(this);
244
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
245

    
246
        // Se configura la barra de menu
247
        setJMenuBar(menuBar);
248

    
249
        // Se configura el layout del JFrame principal
250
        this.getContentPane().setLayout(new BorderLayout());
251

    
252
        /*
253
         * Se configura y se a?ade el JPanel de las barras de
254
         * herramientas
255
         */
256
        FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
257
        layout.setHgap(0);
258
        layout.setVgap(0);
259
        toolBars.setLayout(layout);
260
        getContentPane().add(toolBars, BorderLayout.PAGE_START);
261

    
262
        // Add the status bar of the application
263
        bEstado = new NewStatusBar();
264
        bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE);
265
        getContentPane().add(bEstado, BorderLayout.SOUTH);
266

    
267
        this.toolBars.addContainerListener(this);
268

    
269

    
270
        /*
271
         * Setting default values. Persistence is read
272
         * afterwards
273
         */
274
        setSize(
275
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
276
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
277
        setLocation(
278
                MainFrame.MAIN_FRAME_POS_DEFAULT[0],
279
                MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
280
        setExtendedState(
281
                MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT);
282

    
283
        mdiManager.init(this);
284
    }
285

    
286
    @Override
287
    public void setTitle(final String title) {
288
        if ( !SwingUtilities.isEventDispatchThread() ) {
289
            SwingUtilities.invokeLater(new Runnable() {
290
                public void run() {
291
                    setTitle(title);
292
                }
293
            });
294
            return;
295
        }
296
        super.setTitle(titlePrefix + " : " + title);
297
    }
298

    
299
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
300
            final ToolBar toolBar, final SelectableTool selectableTool)
301
            throws ClassNotFoundException {
302
        if ( !SwingUtilities.isEventDispatchThread() ) {
303
            try {
304
                SwingUtilities.invokeAndWait(new Runnable() {
305
                    public void run() {
306
                        try {
307
                            addTool(loader, ext, toolBar, selectableTool);
308
                        } catch (ClassNotFoundException ex) {
309
                            logger.warn("??? Eehh????", ex);
310
                        }
311
                    }
312
                });
313
            } catch (Exception ex) {
314
                // Do nothing
315
            }
316
            return;
317
        }
318
        String name = toolBar.getName();
319
        SelectableToolBar jtb = getToolBar(name);
320
        if( selectableTool.getDropDownGroup()!=null ) {
321
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
322
            ActionInfo action = actionManager.getAction(selectableTool.getName());
323
            if( action!=null ) {
324
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(selectableTool.getDropDownGroup());
325
                if( dropDownButton==null ) {
326
                    dropDownButton = new DropDownButton();
327
                    dropDownButton.setName(selectableTool.getDropDownGroup());
328
                    jtb.add(dropDownButton);
329
                    addControl(dropDownButton);
330
                }
331
                dropDownButton.add(actionManager.getTranslated(action));
332
            }
333
            return;
334
        }
335

    
336
        I18nManager i18nManager = ToolsLocator.getI18nManager();
337

    
338
        JToolBarToggleButton btn;
339
        ImageIcon image
340
                = PluginServices.getIconTheme().get(selectableTool.getIcon());
341

    
342
        if ( image != null ) {
343
            btn = new JToolBarToggleButton(selectableTool.getText(), image);
344
        } else {
345
            logger.warn("Unable to find icon '" + selectableTool.getIcon() + "'.");
346
            btn
347
                    = new JToolBarToggleButton(selectableTool.getText(),
348
                            PluginServices.getIconTheme().get(noIcon));
349
        }
350

    
351
        org.gvsig.andami.ui.mdiFrame.ToggleButtonModel buttonModel
352
                = new org.gvsig.andami.ui.mdiFrame.ToggleButtonModel();
353
        btn.setModel(buttonModel);
354
        btn.setMargin(new Insets(0, 0, 0, 0));
355
        btn.addMouseListener(tooltipListener);
356
        btn.addActionListener(this);
357
        btn.setFocusable(false);
358
        btn.setActionCommand(selectableTool.getActionCommand());
359
        btn.setToolTipText(selectableTool.getTooltip());
360
        btn.setEnabled(false);
361
        btn.setVisible(false);
362

    
363
        ButtonGroup group;
364
        if ( buttonGroupMap.containsKey(selectableTool.getGroup()) ) {
365
            group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
366
        } else {
367
            group = new ButtonGroup();
368
            buttonGroupMap.put(selectableTool.getGroup(), group);
369

    
370
        }
371
        jtb.addButton(group, btn);
372
        buttonModel.setGroupName(selectableTool.getGroup());
373

    
374
        if ( selectableTool.getIsDefault() ) {
375
            btn.setSelected(true);
376
            initialSelectedTools.put(selectableTool.getGroup(),
377
                    btn.getActionCommand());
378
        }
379

    
380
        addControl(btn);
381

    
382
        if ( selectableTool.getName() != null ) {
383
            btn.setName(selectableTool.getName());
384
        }
385

    
386
        if ( selectableTool.getTooltip() != null ) {
387
            btn.setToolTip(i18nManager.getTranslation(selectableTool.getTooltip()));
388
            btn.setToolTipKey(selectableTool.getTooltip());
389
        }
390

    
391
        if ( selectableTool.getEnableText() != null ) {
392
            btn.setEnableText(i18nManager.getTranslation(selectableTool.getEnableText()));
393
        }
394

    
395
        if ( selectableTool.getLast() == true ) {
396
            jtb.addSeparator();
397
        }
398
    }
399

    
400
    /**
401
     * Add a button to the toolbar.
402
     *
403
     * @param ext
404
     * Texto del boton, si es null no aparece texto
405
     * @param ext
406
     * Extension asociada al control
407
     * @param toolBar
408
     * Icono del boton, si es null no aparece texto
409
     * @param actionTool
410
     * Tooltip de la barra de herramientas
411
     *
412
     * @throws ClassNotFoundException
413
     * @throws RuntimeException
414
     */
415
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
416
            final ToolBar toolBar, final ActionTool actionTool) throws ClassNotFoundException {
417
        if ( !SwingUtilities.isEventDispatchThread() ) {
418
            try {
419
                SwingUtilities.invokeAndWait(new Runnable() {
420
                    public void run() {
421
                        try {
422
                            addTool(loader, ext, toolBar, actionTool);
423
                        } catch (ClassNotFoundException ex) {
424
                            logger.warn("??? Eehh????", ex);
425
                        }
426
                    }
427
                });
428
            } catch (Exception ex) {
429
                // Do nothing
430
            }
431
            return;
432
        }
433

    
434
        String name = toolBar.getName();
435
        SelectableToolBar jtb = getToolBar(name);
436
        if( actionTool.getDropDownGroup()!=null ) {
437
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
438
            ActionInfo action = actionManager.getAction(actionTool.getName());
439
            if( action!=null ) {
440
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(actionTool.getDropDownGroup());
441
                if( dropDownButton==null ) {
442
                    dropDownButton = new DropDownButton();
443
                    dropDownButton.setName(actionTool.getDropDownGroup());
444
                    jtb.add(dropDownButton);
445
                    addControl(dropDownButton);
446
                }
447
                dropDownButton.add(actionManager.getTranslated(action));
448
            }
449
            return;
450
        }
451

    
452
        I18nManager i18nManager = ToolsLocator.getI18nManager();
453

    
454
        JToolBarButton btn;
455
        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
456

    
457
        if ( image != null ) {
458
            btn = new JToolBarButton(actionTool.getText(), image);
459
        } else {
460
            logger.warn("Unable to find icon '" + actionTool.getIcon() + "'.");
461
            btn
462
                    = new JToolBarButton(actionTool.getText(), PluginServices
463
                            .getIconTheme().get(noIcon));
464
        }
465

    
466
        btn.setMargin(new Insets(0, 0, 0, 0));
467
        btn.addMouseListener(tooltipListener);
468
        btn.addActionListener(this);
469
        btn.setFocusable(false);
470
        btn.setActionCommand(actionTool.getActionCommand());
471
        btn.setEnabled(false);
472
        btn.setVisible(false);
473

    
474

    
475
        jtb.add(btn);
476

    
477
        addControl(btn);
478

    
479
        if ( actionTool.getName() != null ) {
480
            btn.setName(actionTool.getName());
481
        }
482

    
483
        if ( actionTool.getTooltip() != null ) {
484
            btn.setToolTip(i18nManager.getTranslation(actionTool.getTooltip()));
485
            btn.setToolTipKey(actionTool.getTooltip());
486
        }
487

    
488
        if ( actionTool.getEnableText() != null ) {
489
            btn.setEnableText(i18nManager.getTranslation(actionTool.getEnableText()));
490
        }
491

    
492
        if ( actionTool.getLast() == true ) {
493
            jtb.addSeparator();
494
        }
495
    }
496

    
497
    private SelectableToolBar getToolBar(final String toolBarName) {
498
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName);
499
        if ( jtb == null ) {
500
            jtb = new SelectableToolBar(toolBarName);
501
            jtb.setRollover(true);
502
            jtb.setAndamiVisibility(true);
503
            toolBarMap.put(toolBarName, jtb);
504
            toolBars.add(jtb);
505
        }
506
        return jtb;
507
    }
508

    
509
    public void addTool(final ActionInfo action, final String toolBarName, final String dropDownName) {
510
        if ( !SwingUtilities.isEventDispatchThread() ) {
511
            SwingUtilities.invokeLater(new Runnable() {
512
                public void run() {
513
                    addTool(action, toolBarName,dropDownName);
514
                }
515
            });
516
            return;
517
        }
518
        SelectableToolBar jtb = getToolBar(toolBarName);
519
        DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(dropDownName);
520
        if( dropDownButton == null ) {
521
            dropDownButton = new DropDownButton();
522
            jtb.add(dropDownButton);
523
        }
524
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
525
        dropDownButton.add(actionManager.getTranslated(action));
526
    }
527

    
528
    public void addTool(final ActionInfo action, final String toolBarName) {
529
        I18nManager i18nManager = ToolsLocator.getI18nManager();
530

    
531
        if ( !SwingUtilities.isEventDispatchThread() ) {
532
            SwingUtilities.invokeLater(new Runnable() {
533
                public void run() {
534
                    addTool(action, toolBarName);
535
                }
536
            });
537
            return;
538
        }
539
        JToolBarButton btn = new JToolBarButton(action.getIcon());
540
        btn.setMargin(new Insets(0, 0, 0, 0));
541
        btn.addMouseListener(tooltipListener);
542
        btn.addActionListener(this);
543
        btn.setFocusable(false);
544
        btn.setActionCommand(action.getCommand());
545
        btn.setEnabled(false);
546
        btn.setVisible(false);
547
        btn.setName(action.getName());
548
        if ( action.getTooltip() != null ) {
549
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
550
            btn.setToolTipKey(action.getTooltip());
551
        }
552

    
553
        SelectableToolBar jtb = getToolBar(toolBarName);
554
        jtb.add(btn);
555

    
556
        addControl(btn);
557

    
558
    }
559

    
560
    /**
561
     * Creates the needed menu structure to add the menu to the bar.
562
     * Returns the father which must hold the menu which was
563
     * provided as parameter.
564
     *
565
     * Crea la estructura de menus necesaria para a?adir el menu a la barra.
566
     * Devuelve el padre del cual debe colgar el menu que se pasa como
567
     * parametro.
568
     *
569
     * @param menu
570
     * The Menu whose support is going to be added
571
     * @param loader
572
     * The plugin's class loader
573
     *
574
     * @return The proper father for the menu which was provided as parameter
575
     */
576
    private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) {
577
        return createMenuAncestors(menu.getText());
578
    }
579

    
580
    private JMenu createMenuAncestors(String text) {
581
        I18nManager i18nManager = ToolsLocator.getI18nManager();
582

    
583
        MenuElement menuPadre = null;
584

    
585
        String[] menues = text.split("/");
586
        List menuList = new ArrayList();
587
        menuList.add(menues[0]);
588
        menuPadre = getMenu(menuList, menuBar);
589

    
590
        JMenu padre = null;
591

    
592
        if ( menuPadre == null ) {
593
            padre = new JMenuTraslatable(i18nManager.getTranslation(menues[0]));
594
            ((JMenuTraslatable) padre).setTextKey(menues[0]);
595
            padre.setName(menues[0]);
596
            addControl(padre);
597
            menuBar.add(padre);
598
        } else if ( menuPadre instanceof JMenu ) {
599
            padre = (JMenu) menuPadre;
600
        } else {
601
            logger.warn("Error creating menu. Ancestor does not exist (" + text + ").");
602
            return null;
603
        }
604

    
605
        // Se crea el resto de menus
606
        ArrayList temp = new ArrayList();
607

    
608
        for ( int i = 1; i < (menues.length - 1); i++ ) {
609
            temp.add(menues[i]);
610
        }
611

    
612
        menuPadre = createMenus(temp, padre);
613

    
614
        return (JMenu) menuPadre;
615
    }
616

    
617
    /**
618
     * A?ade la informacion del menu al framework.
619
     * Debido a que los men?es se
620
     * pueden introducir en un orden determinado por el usuario, pero los
621
     * plugins se instalan en un orden arbitrario, primero se almacena la
622
     * informacion de todos los menus para luego ordenarlos y posteriormente
623
     * a?adirlos al interfaz
624
     *
625
     * @param loader
626
     * Posicion del menu. Se ordena por este campo
627
     * @param ext
628
     * Array con los nombres de los padres del menu
629
     * @param menu
630
     * Texto del menu
631
     *
632
     * @throws ClassNotFoundException
633
     * @throws RuntimeException
634
     */
635
    public void addMenu(final PluginClassLoader loader, final SkinExtensionType ext,
636
            final Menu menu) throws ClassNotFoundException {
637
        if ( !SwingUtilities.isEventDispatchThread() ) {
638
            try {
639
                SwingUtilities.invokeAndWait(new Runnable() {
640
                    public void run() {
641
                        try {
642
                            addMenu(loader, ext, menu);
643
                        } catch (ClassNotFoundException ex) {
644
                            logger.warn("??? Eehh????", ex);
645
                        }
646
                    }
647
                });
648
            } catch (Exception ex) {
649
                // Do nothing
650
            }
651
            return;
652
        }
653
        JMenu menuPadre = createMenuAncestors(menu, loader);
654

    
655
        if ( menu.getIs_separator() ) {
656
            menuPadre.addSeparator();
657
            return;
658
        }
659

    
660
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
661
        nuevoMenu.addMouseListener(tooltipListener);
662
        menuPadre.add(nuevoMenu);
663
        addControl(nuevoMenu);
664

    
665
    }
666

    
667
    public void addMenu(final ActionInfo action, final String text) {
668
        if ( !SwingUtilities.isEventDispatchThread() ) {
669
            SwingUtilities.invokeLater(new Runnable() {
670
                public void run() {
671
                    addMenu(action, text);
672
                }
673
            });
674
            return;
675
        }
676
        JMenu menuPadre = createMenuAncestors(text);
677
        JMenuItem nuevoMenu = createJMenuItem(action, text);
678
        nuevoMenu.addMouseListener(tooltipListener);
679
        menuPadre.add(nuevoMenu);
680
        Class<? extends IExtension> classExtension = action.getExtension().getClass();
681
        addControl(nuevoMenu);
682
    }
683

    
684
    /**
685
     * Dado lista de nombres de menu, encuentra el menu
686
     *
687
     * @param nombres
688
     * @param padre
689
     * @return
690
     */
691
    private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) {
692
        if ( parent instanceof javax.swing.JMenu ) {
693
            javax.swing.JMenu parentItem = (javax.swing.JMenu) parent;
694

    
695
            for ( int i = 0; i < parentItem.getMenuComponentCount(); i++ ) {
696

    
697
                String item_name = parentItem.getMenuComponent(i).getName();
698
                if ( ((item_name != null) && (item_name.compareTo((String) nombres.get(0)) == 0))
699
                        || /*
700
                         * We also accept "leaf menus" with no name
701
                         * (Project manager, View-1, View-2, etc)
702
                         */ lastMenuItemWithoutName(parentItem.getMenuComponent(i), nombres) ) {
703

    
704
                    nombres.remove(0);
705
                    if ( nombres.isEmpty() ) {
706
                        if ( parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem ) {
707
                            return (javax.swing.JMenuItem) parentItem
708
                                    .getMenuComponent(i);
709
                        } else {
710
                            logger.error(PluginServices.getText(this,
711
                                    "Menu_type_not_supported_")
712
                                    + " "
713
                                    + parentItem.getMenuComponent(i).getClass()
714
                                    .getName());
715
                            return null;
716
                        }
717
                    } else {
718
                        return getMenu(nombres,
719
                                (MenuElement) parentItem.getMenuComponent(i));
720
                    }
721
                }
722
            }
723
        } else if ( parent instanceof JMenuBar ) {
724
            javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent;
725

    
726
            for ( int i = 0; i < parentItem.getMenuCount(); i++ ) {
727
                if ( (parentItem.getMenu(i).getName() != null // not a
728
                        // JToolBar.Separator
729
                        )
730
                        && (parentItem.getMenu(i).getName()
731
                        .compareTo((String) nombres.get(0)) == 0) ) {
732
                    nombres.remove(0);
733
                    if ( nombres.isEmpty() ) {
734
                        if ( parentItem.getMenu(i) instanceof javax.swing.JMenuItem ) {
735
                            return parentItem.getMenu(i);
736
                        } else {
737
                            logger.error(PluginServices.getText(this,
738
                                    "Menu_type_not_supported_")
739
                                    + " "
740
                                    + parentItem.getMenu(i).getClass()
741
                                    .getName());
742
                            return null;
743
                        }
744
                    } else {
745
                        return getMenu(nombres, parentItem.getMenu(i));
746
                    }
747
                }
748
            }
749
        } else {
750
            logger.error(PluginServices.getText(this,
751
                    "Menu_type_not_supported_")
752
                    + " "
753
                    + parent.getClass().getName() + " " + parent.toString());
754
        }
755
        return null;
756
    }
757

    
758
    /**
759
     * @param menuComponent
760
     * @param nombres
761
     * @return
762
     */
763
    private boolean lastMenuItemWithoutName(Component mc, List names) {
764

    
765
        /*
766
         * names must have 1 string
767
         */
768
        if ( names == null || names.size() != 1 ) {
769
            return false;
770
        }
771
        if ( !(mc instanceof JMenuItem) ) {
772
            return false;
773
        }
774
        JMenuItem jmi = (JMenuItem) mc;
775
        if ( jmi.getName() != null ) {
776
            /*
777
             * Name must be null, so this is a menu leaf
778
             */
779
            return false;
780
        }
781
        if ( jmi.getText() == null ) {
782
            return false;
783
        }
784
        return jmi.getText().compareTo((String) names.get(0)) == 0;
785
    }
786

    
787
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
788

    
789
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
790

    
791
        public JMenuTraslatable(String text) {
792
            super(text);
793
        }
794

    
795
        public void setTextKey(String key) {
796
            this.i18nHelper.setText(key);
797
        }
798

    
799
        public void setToolTipKey(String key) {
800
            this.i18nHelper.setTooltip(key);
801
        }
802

    
803
        public void translate() {
804
            if ( this.i18nHelper.needTranslation() ) {
805
                this.i18nHelper.translate();
806
                this.setText(this.i18nHelper.getText());
807
            }
808
        }
809

    
810
    }
811

    
812
    /**
813
     * Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
814
     * en el par?metro nombres el array {"Search", "References", "Workspace"}
815
     * crear? un men? Search, un submen? del anterior que se llamar?
816
     * References y debajo de ?ste ?ltimo otro menu llamado Workspace
817
     *
818
     * @param nombres
819
     * Array con los nombres de los men?s que se quieren crear
820
     * @param padre
821
     * Menu padre de los men?s creados. Es ?til porque es un
822
     * algoritmo recursivo
823
     *
824
     * @return Devuelve el men? creado. Al final de toda la recursividad,
825
     * devolver? el men? de m?s abajo en la jerarqu?a
826
     *
827
     * @throws RuntimeException
828
     */
829
    private JMenu createMenus(ArrayList nombres, JMenu padre) {
830
        if ( !SwingUtilities.isEventDispatchThread() ) {
831
            logger.warn("Este metodo requiere que se este ejecutando en el hilo de eventos de AWT.");
832
            throw new RuntimeException("No Event Dispatch Thread");
833
        }
834
        I18nManager i18nManager = ToolsLocator.getI18nManager();
835

    
836
        // si no quedan nombres de menu por crear se vuelve: caso base
837
        if ( nombres.isEmpty() ) {
838
            return padre;
839
        }
840

    
841
        // Se busca el menu por si ya existiera para no crearlo otra vez
842
        JMenu buscado = null;
843

    
844
        for ( int i = 0; i < padre.getMenuComponentCount(); i++ ) {
845
            try {
846
                JMenu hijo = (JMenu) padre.getMenuComponent(i);
847

    
848
                if ( hijo.getName().compareTo((String) nombres.get(0)) == 0 ) {
849
                    buscado = hijo;
850
                }
851
            } catch (ClassCastException e) {
852
                /*
853
                 * Se ha encontrado un elemento hoja del arbol de men?es
854
                 */
855
            }
856
        }
857

    
858
        if ( buscado != null ) {
859
            // Si lo hemos encontrado creamos el resto
860
            nombres.remove(0);
861

    
862
            return createMenus(nombres, buscado);
863
        } else {
864
            // Si no lo hemos encontrado se crea el menu, se a?ade al padre
865
            // y se crea el resto
866
            String nombre = (String) nombres.get(0);
867
            JMenuTraslatable menuPadre = new JMenuTraslatable(i18nManager.getTranslation(nombre));
868
            menuPadre.setTextKey(nombre);
869
            menuPadre.setName(nombre);
870
            addControl(menuPadre);
871
            padre.add(menuPadre);
872

    
873
            nombres.remove(0);
874

    
875
            return createMenus(nombres, menuPadre);
876
        }
877
    }
878

    
879
    /**
880
     * M?todo invocado en respuesta a ciertos eventos de la interfaz que
881
     * pueden
882
     * ocultar botones de las barras de herramientas y que redimensiona ?sta
883
     * de manera conveniente para que no se oculte ninguno
884
     */
885
    private void ajustarToolBar() {
886
        int margen = 8;
887
        int numFilas = 1;
888
        double acum = margen;
889

    
890
        int toolHeight = 0;
891

    
892
        for ( int i = 0; i < toolBars.getComponentCount(); i++ ) {
893
            Component c = toolBars.getComponent(i);
894

    
895
            if ( !c.isVisible() ) {
896
                continue;
897
            }
898

    
899
            double width = c.getPreferredSize().getWidth();
900
            acum = acum + width;
901

    
902
            if ( acum > this.getWidth() ) {
903
                numFilas++;
904
                acum = width + margen;
905
            }
906

    
907
            if ( c.getPreferredSize().getHeight() > toolHeight ) {
908
                toolHeight = c.getPreferredSize().height;
909
            }
910
        }
911

    
912
        toolBars.setPreferredSize(new Dimension(this.getWidth(),
913
                (numFilas * toolHeight)));
914

    
915
        toolBars.updateUI();
916
    }
917

    
918
    public void setClassesExtensions(Map<Class<? extends IExtension>, ExtensionDecorator> classesExtensions) {
919
        // Ya no es necesario que se mantenga el Map con las extensiones.
920

    
921
//            Map<Class<? extends IExtension>, ExtensionDecorator> extensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
922
//            for ( Entry<Class<? extends IExtension>, ExtensionDecorator>  entry: classesExtensions.entrySet()) {
923
//                        if( ! (entry.getValue().getExtension() instanceof LibraryExtension) ) {
924
//                                extensions.put(entry.getKey(), entry.getValue());
925
//                        }
926
//                }
927
//        this.classesExtensions = extensions;
928
    }
929

    
930
    /**
931
     * Metodo de callback invocado cuando se selecciona un menu o un boton
932
     * de
933
     * la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
934
     *
935
     * @param e
936
     * Evento producido
937
     */
938
    public void actionPerformed(ActionEvent e) {
939

    
940
        String actionName = "(unknow)";
941
        try {
942
            JComponent control = (JComponent) e.getSource();
943
            actionName = control.getName();
944

    
945
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
946
            ActionInfo action = actionManager.getAction(control.getName());
947
            Object args = null;
948
            if ( control instanceof IControl ) {
949
                args = ((IControl) control).getValue();
950
            }
951
            if ( args == null ) {
952
                action.execute();
953
            } else {
954
                action.execute(args);
955
            }
956
            String actionCommand = e.getActionCommand();
957
            try {
958
                JToolBarToggleButton toggle = (JToolBarToggleButton) control;
959
                ToggleButtonModel model = (ToggleButtonModel) toggle.getModel();
960
                selectedTool.put(model.getGroupName(), actionCommand);
961
            } catch (ClassCastException ex) {
962
            } catch (NullPointerException ex) {
963
            }
964

    
965
        } catch (Throwable ex) {
966
            logger.error("Can't perform action '" + actionName + "'.", ex);
967
        }
968

    
969
        enableControls();
970
        showMemory();
971
    }
972

    
973
    private String getName(String name, PluginClassLoader loader) {
974
        if ( name.indexOf('.') == -1 ) {
975
            return loader.getPluginName() + "." + name;
976
        } else {
977
            return name;
978
        }
979
    }
980

    
981
    public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
982
        if ( !SwingUtilities.isEventDispatchThread() ) {
983
            throw new RuntimeException("No Event Dispatch Thread");
984
        }
985

    
986
        String name = getName(menu.getName(), loader);
987

    
988
        // Se crea el control popupmenu
989
        JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
990

    
991
        if ( popupMenu == null ) {
992
            popupMenu = new JPopUpMenu(menu.getName());
993
            popupMap.put(name, popupMenu);
994
        }
995

    
996
        Menu[] menues = menu.getMenu();
997
        for ( int i = 0; i < menues.length; i++ ) {
998
            JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
999
            popupMenu.add(nuevoMenu);
1000
        }
1001
    }
1002

    
1003
    private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
1004
        JMenuItem nuevoMenu = null;
1005

    
1006
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1007

    
1008
        String text = menu.getText();
1009
        int n = text.lastIndexOf('/');
1010
        if ( n >= 0 ) {
1011
            text = text.substring(n + 1);
1012
        }
1013
        String translatedText = i18nManager.getTranslation(text);
1014

    
1015
        IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1016
        if ( menu.getIcon() != null ) {
1017
            if ( iconTheme.exists(menu.getIcon()) ) {
1018
                ImageIcon image = iconTheme.get(menu.getIcon());
1019
                nuevoMenu = new JMenuItem(translatedText, image);
1020
            } else {
1021
                nuevoMenu = new JMenuItem(translatedText);
1022
                logger.info("menu icon '" + menu.getIcon() + "' not exists.");
1023
            }
1024
        } else {
1025
            nuevoMenu = new JMenuItem(translatedText);
1026
        }
1027
        nuevoMenu.setTextKey(text);
1028
        nuevoMenu.setName(menu.getName());
1029

    
1030
        if ( menu.getKey() != null ) {
1031
            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
1032
        }
1033

    
1034
        nuevoMenu.setActionCommand(menu.getActionCommand());
1035

    
1036
        if ( menu.getTooltip() != null ) {
1037
            nuevoMenu.setToolTip(i18nManager.getTranslation(menu.getTooltip()));
1038
            nuevoMenu.setToolTipKey(menu.getTooltip());
1039
        }
1040

    
1041
        if ( menu.getEnableText() != null ) {
1042
            nuevoMenu.setEnableText(i18nManager.getTranslation(menu.getEnableText()));
1043
        }
1044

    
1045
        nuevoMenu.setEnabled(true);
1046
        nuevoMenu.setVisible(true);
1047

    
1048
        if ( menu.getName() != null ) {
1049
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1050
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1051
            if ( actionInfo != null ) {
1052
                nuevoMenu.addActionListener(actionInfo);
1053
            }
1054
        }
1055
        return nuevoMenu;
1056
    }
1057

    
1058
    private JMenuItem createJMenuItem(ActionInfo action, String text) {
1059
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1060
        JMenuItem nuevoMenu = null;
1061
        String label = null;
1062

    
1063
        if ( text == null ) {
1064
            label = action.getLabel();
1065
        } else if ( text.contains("/") ) {
1066
            String[] ss = text.split("/");
1067
            label = ss[ss.length - 1];
1068
        } else {
1069
            label = text;
1070
        }
1071
        String translatedText = i18nManager.getTranslation(label);
1072
        if ( action.getIconName() != null ) {
1073
            ImageIcon image = action.getIcon();
1074
            if ( image != null ) {
1075
                nuevoMenu = new JMenuItem(translatedText, image);
1076
            } else {
1077
                nuevoMenu = new JMenuItem(translatedText);
1078
            }
1079
        } else {
1080
            nuevoMenu = new JMenuItem(translatedText);
1081
        }
1082
        nuevoMenu.setName(action.getName());
1083
        KeyStroke key = action.getKeyStroke();
1084
        if ( key != null ) {
1085
            nuevoMenu.setAccelerator(key);
1086
        }
1087
        nuevoMenu.setActionCommand(action.getCommand());
1088
        if ( action.getTooltip() != null ) {
1089
            nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip()));
1090
        }
1091
        nuevoMenu.setEnabled(true);
1092
        nuevoMenu.setVisible(true);
1093
        nuevoMenu.addActionListener(action);
1094
        return nuevoMenu;
1095
    }
1096

    
1097
    /**
1098
     * Muestra u oculta el menu de nombre 'name'
1099
     *
1100
     * @param name
1101
     * Nombre del menu que se quiere mostrar
1102
     * @param x
1103
     * Evento de raton
1104
     * @param y
1105
     * @param c
1106
     */
1107
    private void showPopupMenu(String name, int x, int y, Component c) {
1108
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1109

    
1110
        if ( menu != null ) {
1111
            menu.show(c, x, y);
1112
        }
1113
    }
1114

    
1115
    public void removePopupMenuListener(String name, ActionListener listener) {
1116
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1117

    
1118
        if ( menu != null ) {
1119
            Component[] jmenuitems = menu.getComponents();
1120

    
1121
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1122
                if ( jmenuitems[i] instanceof JMenuItem ) {
1123
                    ((JMenuItem) jmenuitems[i]).removeActionListener(listener);
1124
                }
1125
            }
1126
        }
1127
    }
1128

    
1129
    public void addPopupMenuListener(String popupName, Component c,
1130
            ActionListener listener, PluginClassLoader loader) {
1131
        final String name = getName(popupName, loader);
1132

    
1133
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1134

    
1135
        if ( menu != null ) {
1136
            Component[] jmenuitems = menu.getComponents();
1137

    
1138
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1139
                if ( jmenuitems[i] instanceof JMenuItem ) {
1140
                    ((JMenuItem) jmenuitems[i]).addActionListener(listener);
1141
                }
1142
            }
1143
        }
1144

    
1145
        c.addMouseListener(new MouseAdapter() {
1146

    
1147
            @Override
1148
            public void mousePressed(MouseEvent e) {
1149
                if ( e.isPopupTrigger() ) {
1150
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1151
                }
1152
            }
1153

    
1154
            @Override
1155
            public void mouseReleased(MouseEvent e) {
1156
                if ( e.isPopupTrigger() ) {
1157
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1158
                }
1159
            }
1160
        });
1161
    }
1162

    
1163
    /**
1164
     * Loop on the controls to enable/disable and show/hide them, according to
1165
     * its associated action (ActionInfo)
1166
     *
1167
     * @throws RuntimeException
1168
     */
1169
    public void enableControls() {
1170
        if ( !SwingUtilities.isEventDispatchThread() ) {
1171
            SwingUtilities.invokeLater(new Runnable() {
1172
                public void run() {
1173
                    enableControls();
1174
                }
1175
            });
1176
            return;
1177
        }
1178

    
1179
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1180
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1181

    
1182
        // Enable or disable controls, according to its associated extensions
1183
        Iterator<JComponent> e = controlsIterator();
1184

    
1185
        while ( e.hasNext() ) {
1186
            JComponent control = (JComponent) e.next();
1187
            String actionName = control.getName();
1188
            ActionInfo action = actionManager.getAction(actionName);
1189
            try {
1190
                boolean enabled = false;
1191
                boolean visible = false;
1192

    
1193
                if ( action == null ) {
1194
                    if( control instanceof DropDownButton ) {
1195
                        DropDownButton dropDownButton = (DropDownButton)control;
1196
                        visible = !dropDownButton.isAllHiden();
1197
                        enabled = !dropDownButton.isAllDisabled();
1198
                    } else if( control instanceof JMenuTraslatable ) {
1199
                        enabled = true;
1200
                        visible = true;
1201
                    } else {
1202
                        IExtension extension = this.control2extensions.get(control);
1203
                        if( extension!=null ) {
1204
                            enabled = extension.isEnabled();
1205
                            visible = extension.isVisible();
1206
                        } else {
1207
                            logger.warn("Can't enable/show control '"+control.getClass().getName()+"/"+control.getName()+".");
1208
                            enabled = true;
1209
                            visible = true;
1210
                        }
1211
                    }
1212
                } else {
1213
                    enabled = false;
1214
                    visible = cache.isVisible(action);
1215
                    if ( visible ) {
1216
                        enabled = cache.isEnabled(action);
1217
                    }
1218
                }
1219
                control.setEnabled(enabled);
1220
                control.setVisible(visible);
1221
            } catch (Throwable ex) {
1222
                // Catch exceptins and errors (class not found)
1223
                logger.info("Can't enable/show control '" + actionName + "'.", ex);
1224
                this.message("Can't enable/show control '" + actionName + "'.", JOptionPane.ERROR_MESSAGE);
1225
                try {
1226
                    control.setEnabled(false);
1227
                    control.setVisible(false);
1228
                } catch (Exception ex2) {
1229
                    // Ignore errors
1230
                }
1231
            }
1232
        }
1233

    
1234
        // Loop in the menus to hide the menus that don't have visible children
1235
        for ( int i = 0; i < menuBar.getMenuCount(); i++ ) {
1236
            MenuElement menu = menuBar.getMenu(i);
1237
            hideMenus(menu);
1238
            if ( menu instanceof JMenu ) {
1239
                // hide (ugly) redundant separators and assign keyboard
1240
                // mnemonics
1241
                Component[] comps = ((JMenu) menu).getMenuComponents();
1242
                // mnemonics have to be unique for each top-level menu
1243
                char mnemonics[] = new char[comps.length];
1244
                if ( comps.length > 0 ) {
1245
                    // Set keyboard mnemonic for this top-level entry
1246
                    String text = ((JMenu) menu).getText();
1247
                    char mnemonic = getMnemonic(text, mnemonics);
1248
                    if ( ' ' != mnemonic ) {
1249
                        ((JMenu) menu).setMnemonic(mnemonic);
1250
                        mnemonics[0] = mnemonic;
1251
                    }
1252
                }
1253
                // now go through all entries in this menu, hid
1254
                // separators if necessary and assing remaining mnemonics
1255
                hideSeparatorsAndMakeMnemonics(menu, mnemonics);
1256
            }
1257
        }
1258

    
1259
        // hide the toolbars that don't contain any visible tool
1260
        Iterator it = toolBarMap.values().iterator();
1261

    
1262
        while ( it.hasNext() ) {
1263
            JComponent t = (JComponent) it.next();
1264
            boolean todosOcultos = true;
1265

    
1266
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1267
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1268
                        // don't matter
1269
                        && t.getComponent(i).isVisible() ) {
1270
                    todosOcultos = false;
1271
                }
1272
            }
1273

    
1274
            if ( todosOcultos ) {
1275
                t.setVisible(false);
1276
            } else {
1277
                if ( t instanceof SelectableToolBar ) {
1278
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1279
                } else {
1280
                    t.setVisible(true);
1281
                }
1282
            }
1283
        }
1284

    
1285
        if ( mdiManager != null ) {
1286
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1287

    
1288
            if ( f != null ) {
1289
                if ( lastLabelClass != f.getClass() ) {
1290
                    lastLabelClass = f.getClass();
1291

    
1292
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1293

    
1294
                    if ( lbls != null ) {
1295
                        bEstado.setLabelSet(lbls);
1296
                    }
1297
                }
1298
            }
1299
        }
1300

    
1301
        ajustarToolBar();
1302

    
1303
        showMemory();
1304
    }
1305

    
1306
    public void refreshControls() {
1307
        if ( !SwingUtilities.isEventDispatchThread() ) {
1308
            SwingUtilities.invokeLater(new Runnable() {
1309
                public void run() {
1310
                    refreshControls();
1311
                }
1312
            });
1313
            return;
1314
        }
1315

    
1316
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1317
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1318
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1319

    
1320
        Iterator e = controlsIterator();
1321

    
1322
        while ( e.hasNext() ) {
1323
            JComponent control = (JComponent) e.next();
1324
            if ( control instanceof TranslatableButton ) {
1325
                ((TranslatableButton) control).translate();
1326
            }
1327
            String actionlName = control.getName();
1328
            ActionInfo action = actionManager.getAction(actionlName);
1329
            if ( action != null ) {
1330
                if ( control instanceof AbstractButton ) {
1331
                    AbstractButton button = (AbstractButton) control;
1332
                    if ( control instanceof javax.swing.JMenuItem ) {
1333
                        if ( action.getIconName() != null && action.getIconName().length() > 0 ) {
1334
                            if ( icontheme.exists(action.getIconName()) ) {
1335
                                button.setIcon(action.getIcon());
1336
                            }
1337
                        }
1338
                    } else {
1339
                        button.setIcon(action.getIcon());
1340
                    }
1341
                }
1342
            }
1343
        }
1344
        enableControls();
1345
    }
1346

    
1347
    public void message(String msg, int messageTyoe) {
1348
        this.getStatusBar().message(msg, messageTyoe);
1349
    }
1350

    
1351
    /**
1352
     * Establece la visibilidad de un menu y todos sus descendientes en la
1353
     * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1354
     *
1355
     * @param menu
1356
     * Menu que se quiere visualizar
1357
     *
1358
     * @return Devuelve true si el menu es visible y false en caso contrario
1359
     */
1360
    private boolean hideMenus(MenuElement menu) {
1361
        MenuElement[] submenus = menu.getSubElements();
1362

    
1363
        // Si no tiene hijos se devuelve su visibilidad
1364
        if ( submenus.length == 0 ) {
1365
            return menu.getComponent().isVisible();
1366
        }
1367

    
1368
        /*
1369
         * Si tiene hijos se devuelve true si alg?no de ellos es visible,
1370
         * pero se itera por todos ellos
1371
         */
1372
        boolean visible = false;
1373

    
1374
        for ( int i = 0; i < submenus.length; i++ ) {
1375
            if ( hideMenus(submenus[i]) ) {
1376
                if ( !(menu instanceof JPopupMenu) ) {
1377
                    menu.getComponent().setVisible(true);
1378
                }
1379

    
1380
                visible = true;
1381
            }
1382
        }
1383

    
1384
        if ( visible ) {
1385
            return true;
1386
        }
1387

    
1388
        menu.getComponent().setVisible(false);
1389

    
1390
        return false;
1391
    }
1392

    
1393
    /**
1394
     *
1395
     * Recurse through all menu elements and make sure there are no
1396
     * redundant separators.
1397
     * This method will make sure that a separator only becomes visible
1398
     * if at least one visible non-separator menu entry preceeded it.
1399
     *
1400
     *
1401
     */
1402
    private void hideSeparatorsAndMakeMnemonics(MenuElement menu,
1403
            char[] mnemonics) {
1404
        // flag that indicates whether a separator is to be displayed or not
1405
        boolean allowSeparator;
1406

    
1407
        allowSeparator = false; // separator not allowed as very first menu item
1408
        Component[] comps = ((JMenu) menu).getMenuComponents();
1409
        if ( comps.length < 1 ) {
1410
            // zero-length menu: skip
1411
            return;
1412
        }
1413

    
1414
        for ( int i = 0; i < comps.length; i++ ) {
1415
            if ( comps[i] instanceof JSeparator ) {
1416
                // got a separator: display only if allowed at this position
1417
                if ( allowSeparator == true ) {
1418
                    // look at all successive menu entries to make sure that at
1419
                    // least one
1420
                    // is visible and not a separator (otherwise, this separator
1421
                    // would
1422
                    // be the last visible item in this menu) -- we don't want
1423
                    // that
1424
                    comps[i].setVisible(false);
1425
                    for ( int j = i; j < comps.length; j++ ) {
1426
                        if ( !(comps[j] instanceof JSeparator) ) {
1427
                            if ( comps[j].isVisible() ) {
1428
                                comps[i].setVisible(true); // display separator!
1429
                                break;
1430
                            }
1431
                        }
1432
                    }
1433
                } else {
1434
                    comps[i].setVisible(false);
1435
                }
1436
                allowSeparator = false; // separator is not allowed right after
1437
                // another separator
1438
            } else {
1439
                if ( comps[i] instanceof JMenu ) { // got a submenu: recurse
1440
                    // through it
1441
                    // get number of submenu components
1442
                    Component[] scomps = ((JMenu) comps[i]).getMenuComponents();
1443
                    // make a new, fresh array to hold unique mnemonics for this
1444
                    // submenu
1445
                    char[] smnemonics = new char[scomps.length];
1446
                    hideSeparatorsAndMakeMnemonics(((MenuElement) comps[i]),
1447
                            smnemonics);
1448
                    if ( comps[i].isVisible() ) {
1449
                        allowSeparator = true; // separators are OK after
1450
                        // visible submenus
1451
                        // Set keyboard mnemonic for this submenu
1452
                        String text = ((JMenu) comps[i]).getText();
1453
                        char mnemonic = getMnemonic(text, mnemonics);
1454
                        if ( ' ' != mnemonic ) {
1455
                            ((JMenu) comps[i]).setMnemonic(mnemonic);
1456
                            mnemonics[i] = mnemonic;
1457
                        }
1458
                    }
1459
                } else {
1460
                    if ( comps[i].isVisible() ) {
1461
                        if ( comps[i] instanceof JMenuItem ) {
1462
                            // Set keyboard mnemonic for this menu item
1463
                            String text = ((JMenuItem) comps[i]).getText();
1464
                            char mnemonic = getMnemonic(text, mnemonics);
1465
                            if ( ' ' != mnemonic ) {
1466
                                ((JMenuItem) comps[i]).setMnemonic(mnemonic);
1467
                                mnemonics[i] = mnemonic;
1468
                            }
1469
                        }
1470
                        allowSeparator = true; // separators are OK after
1471
                        // regular, visible entries
1472
                    }
1473
                }
1474
            }
1475
        }
1476
    }
1477

    
1478
    /**
1479
     * Helper functios for assigning a unique mnemomic char from
1480
     * a pool of unassigned onces, stored in the array "mnemomnics"
1481
     */
1482
    private char getMnemonic(String text, char[] mnemonics) {
1483
        if( text==null ) {
1484
            return ' ';
1485
        }
1486
        Vector words = new Vector();
1487
        StringTokenizer t = new StringTokenizer(text);
1488
        int maxsize = 0;
1489

    
1490
        while ( t.hasMoreTokens() ) {
1491
            String word = t.nextToken();
1492
            if ( word.length() > maxsize ) {
1493
                maxsize = word.length();
1494
            }
1495
            words.addElement(word);
1496
        }
1497
        words.trimToSize();
1498

    
1499
        for ( int i = 0; i < maxsize; ++i ) {
1500
            char mnemonic = getMnemonic(words, mnemonics, i);
1501
            if ( ' ' != mnemonic ) {
1502
                return mnemonic;
1503
            }
1504
        }
1505

    
1506
        return ' ';
1507
    }
1508

    
1509
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1510
        int numwords = words.size();
1511

    
1512
        for ( int i = 0; i < numwords; ++i ) {
1513
            String word = (String) words.elementAt(i);
1514
            if ( index >= word.length() ) {
1515
                continue;
1516
            }
1517

    
1518
            char c = word.charAt(index);
1519
            if ( !isMnemonicExists(c, mnemonics) ) {
1520
                /* pick only valid chars */
1521
                if ( (c != ':') && (c != '.') && (c != ',') && (c != ';')
1522
                        && (c != '-') && (c != '+') && (c != '/') && (c != '\\')
1523
                        && (c != '\'') && (c != '\"') && (c != ' ') && (c != '=')
1524
                        && (c != '(') && (c != ')') && (c != '[') && (c != ']')
1525
                        && (c != '{') && (c != '}') && (c != '$') && (c != '*')
1526
                        && (c != '&') && (c != '%') && (c != '!') && (c != '?')
1527
                        && (c != '#') && (c != '~') && (c != '_') ) {
1528
                    return c;
1529
                }
1530
            }
1531
        }
1532
        return ' ';
1533
    }
1534

    
1535
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1536
        int num = mnemonics.length;
1537
        for ( int i = 0; i < num; ++i ) {
1538
            if ( mnemonics[i] == c ) {
1539
                return true;
1540
            }
1541
        }
1542
        return false;
1543
    }
1544

    
1545
    /**
1546
     * Muestra la memoria consumida por el programa
1547
     */
1548
    private void showMemory() {
1549
        Runtime r = Runtime.getRuntime();
1550
        long mem = r.totalMemory() - r.freeMemory();
1551
        logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem
1552
                / 1024 + " KB");
1553
    }
1554

    
1555
    public MDIManager getMDIManager() {
1556
        return mdiManager;
1557
    }
1558

    
1559
    public NewStatusBar getStatusBar() {
1560
        return bEstado;
1561
    }
1562

    
1563
    /**
1564
     * You can use this function to select the appropiate
1565
     * tool inside the toolbars
1566
     */
1567
    public void setSelectedTool(String actionCommand) {
1568
        setSelectedTool(defaultGroup, actionCommand);
1569
    }
1570

    
1571
    /**
1572
     * You can use this function to select the appropiate
1573
     * tool inside the toolbars
1574
     */
1575
    public void setSelectedTool(String groupName, String actionCommand) {
1576
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1577
        if ( group == null ) {
1578
            return;
1579
        }
1580

    
1581
        Enumeration enumeration = group.getElements();
1582
        while ( enumeration.hasMoreElements() ) {
1583
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1584
            if ( button.getActionCommand().equals(actionCommand) ) {
1585
                button.setSelected(true);
1586
            }
1587
        }
1588

    
1589
        selectedTool.put(groupName, actionCommand);
1590
    }
1591

    
1592
    /**
1593
     * You can use this function to select the appropiate
1594
     * tool inside the toolbars
1595
     */
1596
    public void setSelectedTools(Map selectedTools) {
1597
        selectedTool = selectedTools;
1598
        if ( selectedTools == null ) {
1599
            return;
1600
        }
1601
        Iterator groupNames = selectedTools.keySet().iterator();
1602
        while ( groupNames.hasNext() ) {
1603
            try {
1604
                String groupName = (String) groupNames.next();
1605
                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1606
                Enumeration enumeration = group.getElements();
1607
                String actionCommand = (String) selectedTools.get(groupName);
1608
                if ( actionCommand == null ) {
1609
                    continue;
1610
                }
1611
                while ( enumeration.hasMoreElements() ) {
1612
                    AbstractButton button
1613
                            = (AbstractButton) enumeration.nextElement();
1614
                    if ( button.getActionCommand().equals(actionCommand) ) {
1615
                        button.setSelected(true);
1616
                    }
1617
                }
1618
            } catch (ClassCastException ex) {
1619
                logger
1620
                        .error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1621
            }
1622
        }
1623
    }
1624

    
1625
    /**
1626
     * DOCUMENT ME!
1627
     *
1628
     * @param clase
1629
     * @param label
1630
     */
1631
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1632
        classLabels.put(clase, label);
1633
    }
1634

    
1635
    public void removeStatusBarLabels(Class<?> clase) {
1636
        classLabels.remove(clase);
1637
    }
1638

    
1639
    public void addStatusBarControl(Class<?> extensionClass, IControl control) {
1640
        control.addActionListener(this);
1641
        bEstado.addControl(control.getName(), (Component) control);
1642
        if ( control instanceof JComponent ) {
1643
            addControl((JComponent) control);
1644
            PluginsManager pluginsManager = PluginsLocator.getManager();
1645
            IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1646
            this.control2extensions.put((JComponent)control, extension);
1647
        }
1648
    }
1649

    
1650
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1651
        toolBars.add(control);
1652
        addControl(control);
1653

    
1654
        PluginsManager pluginsManager = PluginsLocator.getManager();
1655
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1656
        this.control2extensions.put(control, extension);
1657
    }
1658

    
1659
    public void removeStatusBarControl(String name) {
1660
        Component c = bEstado.removeControl(name);
1661
        if ( c instanceof JComponent ) {
1662
            removeControl((JComponent) c);
1663
        }
1664
    }
1665

    
1666
    public void removeMenu(Menu menu) {
1667
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1668

    
1669
        if ( delete == null ) {
1670
            throw new NoSuchElementException(menu.getText());
1671
        }
1672

    
1673
        delete.getParent().remove(delete);
1674
        infoCodedMenus.remove(menu);
1675
    }
1676

    
1677
    public void addMenu(Menu menu, ActionListener listener,
1678
            PluginClassLoader loader) {
1679
        JMenu menuPadre = createMenuAncestors(menu, loader);
1680

    
1681
        // Se registra y a?aade el menu
1682
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
1683
        nuevoMenu.addMouseListener(tooltipListener);
1684
        if ( listener != null && menu.getName() != null && menu.getName().trim().length() > 0 ) {
1685
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1686
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1687
            if ( actionInfo != null ) {
1688
                nuevoMenu.removeActionListener(actionInfo);
1689
            }
1690
            nuevoMenu.addActionListener(listener);
1691
        } else {
1692
            /*
1693
             * We also add action listener for menu with
1694
             * no name but with text:
1695
             *
1696
             * Window/Project manager
1697
             * Window/View - 1
1698
             * Window/View - 2
1699
             * etc
1700
             */
1701
            if ( listener != null && menu.getText() != null && menu.getText().trim().length() > 0 ) {
1702
                nuevoMenu.addActionListener(listener);
1703
            }
1704

    
1705
        }
1706
        menuPadre.add(nuevoMenu);
1707

    
1708
        infoCodedMenus.put(menu, nuevoMenu);
1709
    }
1710

    
1711
    public void changeMenuName(String[] menu, String newName,
1712
            PluginClassLoader loader) {
1713

    
1714
        ArrayList menuList = new ArrayList();
1715
        for ( int i = 0; i < menu.length; i++ ) {
1716
            menuList.add(menu[i]);
1717
        }
1718

    
1719
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1720
        if ( newMenu == null ) {
1721
            throw new NoSuchMenuException(menu[0]);
1722
        } else {
1723
            newMenu.setText(PluginServices.getText(this, newName));
1724
        }
1725
    }
1726

    
1727
    public void componentHidden(ComponentEvent arg0) {
1728
    }
1729

    
1730
    public void componentMoved(ComponentEvent arg0) {
1731
    }
1732

    
1733
    public void componentResized(ComponentEvent arg0) {
1734
        ajustarToolBar();
1735
    }
1736

    
1737
    public void componentShown(ComponentEvent arg0) {
1738
    }
1739

    
1740
    public void componentAdded(ContainerEvent arg0) {
1741
        ajustarToolBar();
1742
    }
1743

    
1744
    public void componentRemoved(ContainerEvent arg0) {
1745
        ajustarToolBar();
1746
    }
1747

    
1748
    public class TooltipListener extends MouseAdapter {
1749

    
1750
        @Override
1751
        public void mouseEntered(MouseEvent e) {
1752
            JComponent control = (JComponent) e.getSource();
1753
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1754

    
1755
            String texto = null;
1756
            texto = control.getToolTipText();
1757

    
1758
            if ( texto != null ) {
1759
                bEstado.setInfoTextTemporal(texto);
1760
            }
1761
        }
1762

    
1763
        @Override
1764
        public void mouseExited(MouseEvent arg0) {
1765
            bEstado.restaurarTexto();
1766
        }
1767

    
1768
        @Override
1769
        public void mousePressed(MouseEvent e) {
1770
            bEstado.restaurarTexto();
1771
        }
1772
    }
1773

    
1774
    public String getTitlePrefix() {
1775
        return titlePrefix;
1776
    }
1777

    
1778
    public void setTitlePrefix(String titlePrefix) {
1779
        this.titlePrefix = titlePrefix;
1780
    }
1781

    
1782
    public Map getSelectedTools() {
1783
        return selectedTool;
1784
    }
1785

    
1786
    public HashMap getInitialSelectedTools() {
1787
        return initialSelectedTools;
1788
    }
1789

    
1790
    /**
1791
     * Get a previously added JComponent by name.
1792
     * For example you can use it if you need to obtain a JToolBar to
1793
     * add some customized component.
1794
     *
1795
     * @param name
1796
     * @return the JComponent or null if none has been found
1797
     */
1798
    public JComponent getComponentByName(String name) {
1799
        Iterator e = controlsIterator();
1800

    
1801
        while ( e.hasNext() ) {
1802
            JComponent control = (JComponent) e.next();
1803
            String nameCtrl = control.getName();
1804
            if ( nameCtrl != null ) {
1805
                if ( nameCtrl.compareTo(name) == 0 ) {
1806
                    return control;
1807
                }
1808
            }
1809
        }
1810
        Iterator it = toolBarMap.values().iterator();
1811
        while ( it.hasNext() ) {
1812
            JComponent t = (JComponent) it.next();
1813
            String nameCtrl = t.getName();
1814
            if ( nameCtrl != null ) {
1815
                if ( nameCtrl.compareTo(name) == 0 ) {
1816
                    return t;
1817
                }
1818
            }
1819

    
1820
        }
1821

    
1822
        return null;
1823
    }
1824

    
1825
    public SelectableToolBar[] getToolbars() {
1826
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1827
                new SelectableToolBar[0]);
1828
    }
1829

    
1830
    public boolean getToolbarVisibility(String name) {
1831
        JComponent component
1832
                = PluginServices.getMainFrame().getComponentByName(name);
1833
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1834
            SelectableToolBar toolBar = (SelectableToolBar) component;
1835
            return toolBar.getAndamiVisibility();
1836
        }
1837
        return false;
1838
    }
1839

    
1840
    public boolean setToolbarVisibility(String name, boolean visibility) {
1841
        JComponent component
1842
                = PluginServices.getMainFrame().getComponentByName(name);
1843
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1844
            SelectableToolBar toolBar = (SelectableToolBar) component;
1845
            boolean oldVisibility = toolBar.getAndamiVisibility();
1846
            toolBar.setAndamiVisibility(visibility);
1847
            enableControls();
1848
            return oldVisibility;
1849
        }
1850
        return false;
1851
    }
1852

    
1853
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1854
        ArrayList menu = new ArrayList();
1855
        for ( int i = 0; i < menuPath.length; i++ ) {
1856
            menu.add(menuPath[i]);
1857
        }
1858
        return getMenu(menu, menuBar);
1859
    }
1860

    
1861
    public void messageDialog(String message, String title, int messageType) {
1862
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1863
        helper.messageDialog(message, title, messageType);
1864
    }
1865

    
1866
    public void messageDialog(String message, String[] messageArgs,
1867
            String title, int messageType) {
1868
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1869
        helper.messageDialog(message, messageArgs, title, messageType);
1870
    }
1871

    
1872
    public int confirmDialog(String message, String title, int optionType,
1873
            int messageType) {
1874
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1875
        return helper.confirmDialog(message, title, optionType, messageType);
1876
    }
1877

    
1878
    public String inputDialog(String message, String title, int messageType,
1879
            String initialValue) {
1880
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1881
        return helper.inputDialog(message, title, messageType, initialValue);
1882
    }
1883

    
1884
    public String inputDialog(String message, String title) {
1885
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1886
        return helper.inputDialog(message, title);
1887
    }
1888

    
1889
    public void showDialog(Component contents, String title) {
1890
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1891
        helper.showDialog(contents, title);
1892
    }
1893

    
1894
    public Component createComponent(Class<? extends Component> theClass,
1895
            Object... parameters) {
1896
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1897
        return helper.createComponentWithParams(theClass, parameters);
1898
    }
1899

    
1900
    public Component createComponentWithParams(
1901
            Class<? extends Component> theClass, Object[] parameters) {
1902
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1903
        return helper.createComponentWithParams(theClass, parameters);
1904
    }
1905

    
1906
    public File[] showChooserDialog(
1907
            final String title,
1908
            final int type, // SAVE_DIALOG / OPEN_DIALOG
1909
            final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
1910
            final boolean multiselection,
1911
            final File initialPath,
1912
            final FileFilter filter,
1913
            final boolean fileHidingEnabled
1914
    ) {
1915
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1916
        return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
1917
    }
1918

    
1919
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1920
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1921
    }
1922

    
1923
    public File[] showOpenFileDialog(String title, File initialPath) {
1924
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1925
    }
1926

    
1927
    public File[] showSaveFileDialog(String title, File initialPath) {
1928
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1929
    }
1930

    
1931
    private void addControl(JComponent control) {
1932
        controls.add(control);
1933
    }
1934

    
1935
    private void removeControl(JComponent control) {
1936
        controls.remove(control);
1937
    }
1938

    
1939
    private Iterator<JComponent> controlsIterator() {
1940
        return this.controls.iterator();
1941
    }
1942

    
1943
    @Override
1944
    public void setLocale(Locale locale) {
1945
        super.setLocale(locale); //To change body of generated methods, choose Tools | Templates.
1946
        MDIManager mdiManager = MDIManagerFactory.createManager();
1947
        mdiManager.setLocale(locale);
1948
        if ( this.controls != null && !this.controls.isEmpty() ) {
1949
            this.refreshControls();
1950
        }
1951
    }
1952

    
1953
}