Revision 109 trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/extension/LayoutMainExtension.java

View differences:

LayoutMainExtension.java
25 25
import java.io.File;
26 26
import java.io.FileInputStream;
27 27
import java.io.FileNotFoundException;
28
import java.io.IOException;
28 29
import java.text.MessageFormat;
29 30
import java.util.prefs.Preferences;
30 31

  
32
import javax.swing.JOptionPane;
33

  
31 34
import org.gvsig.andami.IconThemeHelper;
32 35
import org.gvsig.andami.PluginServices;
33 36
import org.gvsig.andami.messages.NotificationManager;
......
89 92
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameViewDialog;
90 93
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
91 94
import org.gvsig.gui.beans.swing.JFileChooser;
95
import org.gvsig.i18n.Messages;
92 96
import org.gvsig.tools.ToolsLocator;
93 97
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
94 98
import org.gvsig.tools.persistence.PersistenceManager;
......
149 153
        JFileChooser jfc =
150 154
            new JFileChooser(LAYOUT_TEMPLATE_FILECHOOSER_ID, templatesPath);
151 155
        jfc.addChoosableFileFilter(new GenericFileFilter(
152
            LayoutManager.TEMPLATE_FILE_POINTEXT, PluginServices.getText(this,
153
                "_Layout_template")));
156
            LayoutManager.TEMPLATE_FILE_POINTEXT,
157
            Messages.getText("_Layout_template") + " (*"
158
            + LayoutManager.TEMPLATE_FILE_POINTEXT + ")"
159
            ));
154 160

  
155 161
        if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
156 162
            File file = jfc.getSelectedFile();
157
            if (!file.getPath().toLowerCase()
158
                .endsWith(LayoutManager.TEMPLATE_FILE_POINTEXT.toLowerCase())) {
159
                file =
160
                    new File(file.getPath()
161
                        + LayoutManager.TEMPLATE_FILE_POINTEXT);
162
            }
163 163
            try {
164
                if (!file.exists()) {
165
                    /*
166
                     * The user has written a file name instead of clicking on one
167
                     * and it does not exist
168
                     */
169
                    File auxfile = new File(file.getPath() + LayoutManager.TEMPLATE_FILE_POINTEXT);
170
                    if (!auxfile.exists()) {
171
                        /*
172
                         * Not even this one exists: error
173
                         */
174
                        throw new IOException("File does not exist: " + file.getName());
175
                    } else {
176
                        file = auxfile;
177
                    }
178
                }
179

  
164 180
                File xmlFile = new File(file.getAbsolutePath());
165 181
                FileInputStream is = new FileInputStream(xmlFile);
166 182

  
......
171 187
                layout =
172 188
                    (LayoutPanel) persistenceManager.create(persistentState);
173 189

  
174
            } catch (FileNotFoundException e) {
175
                NotificationManager.addError(MessageFormat.format(
176
                    PluginServices.getText(this,
177
                        "_Cant_load_layout_template_{0}"), file.getPath()), e);
178
            } catch (PersistenceException e) {
179
                NotificationManager.addError(MessageFormat.format(
180
                    PluginServices.getText(this,
181
                        "_Cant_load_layout_template_{0}"), file.getPath()), e);
190
            } catch (Exception e) {
191
                
192
                String tit = Messages.getText("_Layout_template");
193
                String msg = null;
194
                
195
                if (e instanceof PersistenceException) {
196
                    msg = Messages.getText("_Bad_format_in_layout_template");
197
                } else {
198
                    msg = Messages.getText("_Cant_load_layout_template");
199
                }
200
                
201
                msg = msg + ": " + file.getPath();
202
                msg = msg + "\n" + e.getMessage();
203
                JOptionPane.showMessageDialog(
204
                    ApplicationLocator.getManager().getRootComponent(),
205
                    msg, tit, JOptionPane.ERROR_MESSAGE);
182 206
            }
207
            
208
            if (layout == null) {
209
                return;
210
            }
183 211

  
184 212
            LayoutDocument layoutDocument =
185 213
                (LayoutDocument) ProjectManager.getInstance().createDocument(

Also available in: Unified diff