Revision 1756 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutExtension.java

View differences:

LayoutExtension.java
116 116
        }
117 117
    }
118 118
    
119
    public static class AccesoryPanelForTemplates extends JPanel {
120

  
121
        @SuppressWarnings("OverridableMethodCallInConstructor")
122
        public AccesoryPanelForTemplates(File projectfile, FileDialogChooser fc) {
123
            I18nManager i18n = ToolsLocator.getI18nManager();
124
            ApplicationManager application = ApplicationLocator.getApplicationManager();
125
            PreferencesNode prefs = application.getPreferences("gvsig.foldering");
126
            String prefsPath = prefs.get(TEMPLATES_FOLDER_PROPERTY_NAME, null);
127

  
128
            BoxLayout l = new BoxLayout(this, BoxLayout.PAGE_AXIS);
129
            this.setLayout(l);
130
            ImageIcon projectIcon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-project-gotofolder");
131
            JButton goToProjectButton = new JButton(projectIcon);
132

  
133
            goToProjectButton.setToolTipText(i18n.getTranslation("_Go_to_folder_project"));
134
            this.add(goToProjectButton);
135
            if(projectfile != null) {
136
                goToProjectButton.addActionListener((ActionEvent e) -> {
137
                    fc.setCurrentDirectory(projectfile.getParentFile());
138
                });
139
                goToProjectButton.setEnabled(true);
140
            } else {
141
                goToProjectButton.setEnabled(false);
142
            }
143
            ImageIcon templatesIcon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-layout-gotodefaulttemplatesfolder");
144
            JButton goToTemplatesButton = new JButton(templatesIcon);
145

  
146
            goToTemplatesButton.setToolTipText(i18n.getTranslation("_Go_to_default_templates_folder"));
147
            this.add(goToTemplatesButton);
148
            goToTemplatesButton.addActionListener((ActionEvent e) -> {
149
                File prefsFile = new File(prefsPath);
150
                if (prefsFile.exists()) {
151
                    fc.setCurrentDirectory(prefsFile);
152
                }
153
            });
154
            goToTemplatesButton.setEnabled(StringUtils.isNotBlank(prefsPath));
155

  
156
        }
157

  
158
    }
159
    
119 160
    private void saveLayout() {
120 161
        I18nManager i18n = ToolsLocator.getI18nManager();
121 162
        layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
......
131 172
        ApplicationManager application = ApplicationLocator.getApplicationManager();
132 173
        PreferencesNode prefs = application.getPreferences("gvsig.foldering");
133 174
        
134
        String prefsPath = prefs.get(TEMPLATES_FOLDER_PROPERTY_NAME, null);
135 175
        File projectfile = application.getCurrentProject().getFile();
136
        JPanel accesory = null;
137
        if(projectfile != null || prefsPath != null) {
138
            accesory = new JPanel();
139
            BoxLayout l = new BoxLayout(accesory, BoxLayout.PAGE_AXIS);
140
            accesory.setLayout(l);
141
        }
142
        if(projectfile != null) {
143
            ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-project-gotofolder");
144
            JButton goToProjectButton = new JButton(icon);
145
            
146
            goToProjectButton.setToolTipText(i18n.getTranslation("_Go_to_folder_project"));
147
            accesory.add(goToProjectButton);
148
            goToProjectButton.addActionListener((ActionEvent e) -> {
149
                fc.setCurrentDirectory(projectfile.getParentFile());
150
            });
151
        }
152
        if(prefsPath != null) {
153
            ImageIcon icon = ToolsSwingLocator.getIconThemeManager().getActive().get("application-layout-gotodefaulttemplatesfolder");
154
            JButton goToTemplatesButton = new JButton(icon);
155
            
156
            goToTemplatesButton.setToolTipText(i18n.getTranslation("_Go_to_default_templates_folder"));
157
            accesory.add(goToTemplatesButton);
158
            goToTemplatesButton.addActionListener((ActionEvent e) -> {
159
                File prefsFile = new File(prefsPath);
160
                if(prefsFile.exists()){
161
                    fc.setCurrentDirectory(prefsFile);
162
                }
163
            });
164
        }
165
        if(accesory != null){
166
            fc.setAccessory(accesory);
167
        }
168 176

  
169
        File folder = null;
170
        folder = manager.getLastPath("_Last_layout_template_folder", new File(""));
177
        JPanel accesory = new AccesoryPanelForTemplates(projectfile, fc);
178
        fc.setAccessory(accesory);
179

  
180
        File folder = manager.getLastPath("_Last_layout_template_folder", new File(""));
171 181
        if(folder == null || StringUtils.isBlank(folder.getPath())) {
172 182
            if(projectfile != null){
173 183
                folder = projectfile.getParentFile();

Also available in: Unified diff