svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / SelectOutputFilePanel.java @ 44469
History | View | Annotate | Download (5.2 KB)
1 | 43925 | jjdelcerro | package org.gvsig.export.swing.impl.panels; |
---|---|---|---|
2 | |||
3 | 44469 | omartinez | import java.awt.event.ActionEvent; |
4 | 43925 | jjdelcerro | import java.io.File; |
5 | 44469 | omartinez | import javax.swing.AbstractAction; |
6 | import javax.swing.Action; |
||
7 | 43925 | jjdelcerro | import javax.swing.JComponent; |
8 | import javax.swing.JOptionPane; |
||
9 | 44408 | jjdelcerro | import javax.swing.JPopupMenu; |
10 | 44469 | omartinez | import org.apache.commons.lang.StringUtils; |
11 | 43925 | jjdelcerro | import org.gvsig.export.ExportParameters; |
12 | 44469 | omartinez | import org.gvsig.export.ExportParametersGeometry; |
13 | import org.gvsig.export.spi.AbstractExportParameters; |
||
14 | 43925 | jjdelcerro | import org.gvsig.export.swing.JExportProcessPanel; |
15 | import org.gvsig.export.swing.spi.ExportPanel; |
||
16 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
17 | import org.gvsig.export.swing.spi.ExportPanelsManager; |
||
18 | 44469 | omartinez | import org.gvsig.expressionevaluator.ExpressionUtils; |
19 | 44408 | jjdelcerro | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
20 | 43925 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
21 | import org.gvsig.tools.i18n.I18nManager; |
||
22 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
23 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
24 | import org.gvsig.tools.swing.api.pickercontroller.FilePickerController; |
||
25 | import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
||
26 | import org.gvsig.tools.util.HasAFile; |
||
27 | |||
28 | /**
|
||
29 | *
|
||
30 | * @author jjdelcerro
|
||
31 | */
|
||
32 | 44386 | omartinez | public class SelectOutputFilePanel |
33 | 43925 | jjdelcerro | extends SelectOutputFilePanelView
|
34 | 44386 | omartinez | implements ExportPanel {
|
35 | 43925 | jjdelcerro | |
36 | private FilePickerController fileController;
|
||
37 | private final HasAFile parameters; |
||
38 | private final JExportProcessPanel processPanel; |
||
39 | 44386 | omartinez | |
40 | 43925 | jjdelcerro | public SelectOutputFilePanel(
|
41 | JExportProcessPanel processPanel, |
||
42 | ExportParameters parameters |
||
43 | 44386 | omartinez | ) { |
44 | 43925 | jjdelcerro | this.processPanel = processPanel;
|
45 | 44386 | omartinez | this.parameters = (HasAFile) parameters;
|
46 | 43925 | jjdelcerro | this.initComponents();
|
47 | } |
||
48 | |||
49 | @Override
|
||
50 | public String getIdPanel() { |
||
51 | return ExportPanelsManager.PANEL_SELECT_OUTPUT_FILE;
|
||
52 | } |
||
53 | |||
54 | @Override
|
||
55 | public String getTitlePanel() { |
||
56 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
57 | 44386 | omartinez | return i18n.getTranslation("Seleccionar_fichero"); |
58 | 43925 | jjdelcerro | } |
59 | |||
60 | @Override
|
||
61 | public boolean validatePanel() throws ExportPanelValidationException { |
||
62 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
63 | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
64 | 44386 | omartinez | if (this.fileController.isEmpty()) { |
65 | 43925 | jjdelcerro | throw new ExportPanelValidationException( |
66 | 44386 | omartinez | i18n.getTranslation("_File_cannot_be_empty"));
|
67 | 43925 | jjdelcerro | } |
68 | File file = this.fileController.get(); |
||
69 | 44469 | omartinez | File newFile = null; |
70 | try {
|
||
71 | newFile = ExpressionUtils.evaluateFilename(file); |
||
72 | } catch (Exception ex) { |
||
73 | throw new ExportPanelValidationException( |
||
74 | i18n.getTranslation("_Evaluated_file_path_is_not_valid"));
|
||
75 | } |
||
76 | if (newFile != null && newFile.exists()) { |
||
77 | 43925 | jjdelcerro | int resp = dialogs.confirmDialog(
|
78 | i18n.getTranslation("fichero_ya_existe_seguro_desea_guardarlo"),
|
||
79 | i18n.getTranslation("guardar"),
|
||
80 | 44386 | omartinez | JOptionPane.YES_NO_OPTION,
|
81 | JOptionPane.QUESTION_MESSAGE,
|
||
82 | 43925 | jjdelcerro | "OverwriteFileOnExport"
|
83 | ); |
||
84 | if (resp == JOptionPane.NO_OPTION) { |
||
85 | return false; |
||
86 | } |
||
87 | } |
||
88 | return true; |
||
89 | } |
||
90 | |||
91 | @Override
|
||
92 | 43968 | jjdelcerro | public void previousPanel() { |
93 | |||
94 | } |
||
95 | |||
96 | @Override
|
||
97 | public void nextPanel() { |
||
98 | 43925 | jjdelcerro | File file = this.fileController.get(); |
99 | this.parameters.setFile(file);
|
||
100 | } |
||
101 | |||
102 | @Override
|
||
103 | public void enterPanel() { |
||
104 | 44386 | omartinez | File file = this.parameters.getFile(); |
105 | if (file != null) { |
||
106 | this.fileController.set(file);
|
||
107 | } |
||
108 | 43925 | jjdelcerro | } |
109 | |||
110 | @Override
|
||
111 | public JComponent asJComponent() { |
||
112 | return this; |
||
113 | } |
||
114 | |||
115 | private void initComponents() { |
||
116 | 44386 | omartinez | File initialPath = null; |
117 | 44469 | omartinez | if (this.parameters.getFile() != null) { |
118 | 44386 | omartinez | initialPath = this.parameters.getFile();
|
119 | } |
||
120 | 43925 | jjdelcerro | this.fileController = ToolsSwingLocator.getToolsSwingManager()
|
121 | 44469 | omartinez | .createFilePickerController(txtFile, |
122 | 44386 | omartinez | btnSelectFile, |
123 | null,
|
||
124 | null, initialPath, true); |
||
125 | 44408 | jjdelcerro | JPopupMenu menu = this.txtFile.getComponentPopupMenu(); |
126 | menu.add(ExpressionEvaluatorSwingLocator.getManager().createJExpressionBuilderAction(this.txtFile));
|
||
127 | 44469 | omartinez | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
128 | Action textUniqueTempLayer;
|
||
129 | textUniqueTempLayer = new AbstractAction(i18nManager.getTranslation("_Temporal_layer_path")) { |
||
130 | @Override
|
||
131 | public void actionPerformed(ActionEvent e) { |
||
132 | if (txtFile.isEditable() && txtFile.isEnabled()) {
|
||
133 | String nameLayer;
|
||
134 | try {
|
||
135 | nameLayer = ((ExportParameters) parameters).getSourceFeatureStore().getName(); |
||
136 | } catch (Exception ex) { |
||
137 | nameLayer = "temp";
|
||
138 | } |
||
139 | txtFile.setText("<%=UNIQUETEMPORARYFILE('" + nameLayer + "')%>"); |
||
140 | } |
||
141 | } |
||
142 | }; |
||
143 | txtFile.getComponentPopupMenu().add(textUniqueTempLayer); |
||
144 | 43925 | jjdelcerro | this.translate();
|
145 | } |
||
146 | 44386 | omartinez | |
147 | 43925 | jjdelcerro | private void translate() { |
148 | ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
||
149 | i18nc.translate(this.lblFile);
|
||
150 | } |
||
151 | } |