Revision 44390 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/SelectFormatPanel.java
SelectFormatPanel.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 | 1 |
package org.gvsig.export.swing.impl.panels; |
7 | 2 |
|
8 |
import java.awt.BorderLayout; |
|
9 | 3 |
import java.awt.event.ActionEvent; |
10 | 4 |
import java.awt.event.ActionListener; |
11 |
import java.nio.charset.Charset; |
|
12 | 5 |
import java.util.List; |
13 |
import java.util.Random; |
|
14 | 6 |
import java.util.function.Predicate; |
15 |
import java.util.logging.Level; |
|
16 |
import java.util.logging.Logger; |
|
17 | 7 |
import javax.swing.DefaultListModel; |
18 |
import javax.swing.JButton; |
|
19 | 8 |
import javax.swing.JComponent; |
20 |
import javax.swing.JPanel; |
|
21 | 9 |
import javax.swing.JScrollPane; |
22 |
import javax.swing.border.EmptyBorder; |
|
23 | 10 |
import javax.swing.event.ListSelectionEvent; |
24 | 11 |
import javax.swing.event.ListSelectionListener; |
12 |
import org.apache.commons.lang3.StringUtils; |
|
25 | 13 |
import org.gvsig.export.ExportLocator; |
26 | 14 |
import org.gvsig.export.ExportParameters; |
27 | 15 |
import org.gvsig.export.Filter; |
... | ... | |
30 | 18 |
import org.gvsig.export.swing.spi.ExportPanel; |
31 | 19 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
32 | 20 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
|
34 | 21 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
35 | 22 |
import org.gvsig.tools.bookmarksandhistory.History; |
36 | 23 |
import org.gvsig.tools.i18n.I18nManager; |
37 | 24 |
import org.gvsig.tools.swing.api.ListElement; |
38 | 25 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
26 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
|
27 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE; |
|
28 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE; |
|
39 | 29 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
40 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController.BookmarkEvent; |
|
41 | 30 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
42 | 31 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController.HistoryEvent; |
32 |
import org.slf4j.Logger; |
|
43 | 33 |
import org.slf4j.LoggerFactory; |
44 | 34 |
|
45 | 35 |
/** |
46 | 36 |
* |
47 | 37 |
* @author jjdelcerro |
48 | 38 |
*/ |
39 |
@SuppressWarnings("UseSpecificCatch") |
|
49 | 40 |
public class SelectFormatPanel |
50 | 41 |
extends SelectFormatPanelView |
51 | 42 |
implements ExportPanel { |
52 | 43 |
|
44 |
private static final Logger LOG = LoggerFactory.getLogger(SelectFormatPanel.class); |
|
45 |
|
|
53 | 46 |
private final JExportProcessPanel processPanel; |
54 |
private ExportParameters parameters; |
|
55 | 47 |
private final Filter<ExportServiceFactory> serviceFilter; |
56 | 48 |
private final ActionListener onExitPanel; |
49 |
|
|
50 |
private ExportParameters parameters; |
|
57 | 51 |
private BookmarksController<ExportParameters> bookmarksController; |
58 |
private HistoryController historyController; |
|
59 |
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(SelectFormatPanel.class); |
|
52 |
private HistoryController<ExportParameters> historyController; |
|
60 | 53 |
|
61 | 54 |
public SelectFormatPanel( |
62 | 55 |
JExportProcessPanel processPanel, |
... | ... | |
97 | 90 |
} |
98 | 91 |
}); |
99 | 92 |
|
100 |
Bookmarks<ExportParameters> bookmarks = ExportLocator.getServiceManager().getBookmarks(); |
|
101 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(bookmarks, this.btnBookmark); |
|
102 |
this.bookmarksController.setAllowAddBookmarks(false); |
|
103 |
this.bookmarksController.setFilter(new Predicate<Bookmark<ExportParameters>>() { |
|
93 |
Predicate<ExportParameters> filter = new Predicate<ExportParameters>() { |
|
104 | 94 |
@Override |
105 |
public boolean test(Bookmark<ExportParameters> bookmark) { |
|
106 |
ExportParameters params = bookmark.getValue(); |
|
107 |
if (params == null) { |
|
108 |
return false; |
|
109 |
} |
|
110 |
ExportServiceFactory selectedService = SelectFormatPanel.this.getSelectedService(); |
|
111 |
if (selectedService == null) { |
|
112 |
return true; |
|
113 |
} |
|
114 |
String currentFactory = selectedService.getName(); |
|
115 |
String paramsServiceName = params.getServiceName(); |
|
116 |
return (paramsServiceName == null ? currentFactory == null : paramsServiceName.equals(currentFactory)); |
|
117 |
} |
|
118 |
}); |
|
119 |
this.bookmarksController.addActionListener(new ActionListener() { |
|
120 |
@Override |
|
121 |
public void actionPerformed(ActionEvent e) { |
|
122 |
BookmarkEvent<ExportParameters> b = (BookmarkEvent<ExportParameters>) e; |
|
123 |
if (b.getID() == BookmarksController.ID_GETVALUE) { //e.getActionCommand()) { |
|
124 |
// b.setCurrentValue(SelectFormatPanel.this.parameters.clone()) |
|
125 |
} else if (b.getID() == BookmarksController.ID_SETVALUE) { |
|
126 |
if (b.getCurrentValue() == null) { |
|
127 |
return; |
|
128 |
} |
|
129 |
ExportParameters exportParams = null; |
|
130 |
try { |
|
131 |
exportParams = b.getCurrentValue().clone(); |
|
132 |
} catch (CloneNotSupportedException ex) { |
|
133 |
LOG.error("Not been able to clone export parameters"); |
|
134 |
return; |
|
135 |
} |
|
136 |
setSelectedService(exportParams.getFactory()); |
|
137 |
|
|
138 |
SelectFormatPanel.this.processPanel.getProcess().setParameters(exportParams); |
|
139 |
SelectFormatPanel.this.parameters = exportParams; |
|
140 |
} |
|
141 |
|
|
142 |
} |
|
143 |
}); |
|
144 |
History<ExportParameters> history = ExportLocator.getServiceManager().getHistory(); |
|
145 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(history, this.btnHistory); |
|
146 |
this.historyController.setFilter(new Predicate<ExportParameters>() { |
|
147 |
@Override |
|
148 | 95 |
public boolean test(ExportParameters params) { |
149 | 96 |
if (params == null) { |
150 | 97 |
return false; |
... | ... | |
153 | 100 |
if (selectedService == null) { |
154 | 101 |
return false; |
155 | 102 |
} |
156 |
String currentFactory = selectedService.getName();
|
|
103 |
String selectedServiceName = selectedService.getName();
|
|
157 | 104 |
String paramsServiceName = params.getServiceName(); |
158 |
return (paramsServiceName == null ? currentFactory == null : paramsServiceName.equals(currentFactory));
|
|
105 |
return StringUtils.equals(paramsServiceName,selectedServiceName);
|
|
159 | 106 |
} |
160 |
});
|
|
161 |
this.historyController.addActionListener(new ActionListener() {
|
|
107 |
}; |
|
108 |
ActionListener historyAndBookmarkListener = new ActionListener() {
|
|
162 | 109 |
@Override |
163 | 110 |
public void actionPerformed(ActionEvent e) { |
164 |
HistoryEvent<ExportParameters> he = (HistoryEvent<ExportParameters>) e; |
|
165 |
ExportParameters exportParams = null; |
|
166 |
if (he.getCurrentValue() == null) { |
|
167 |
return; |
|
111 |
ActionEventWithCurrentValue<ExportParameters> b = (ActionEventWithCurrentValue<ExportParameters>) e; |
|
112 |
switch(b.getID()) { |
|
113 |
case ID_GETVALUE: |
|
114 |
// Esta deshabilitado esta opcion |
|
115 |
break; |
|
116 |
case ID_SETVALUE: |
|
117 |
if (b.getCurrentValue() == null) { |
|
118 |
return; |
|
119 |
} |
|
120 |
ExportParameters exportParams; |
|
121 |
try { |
|
122 |
exportParams = b.getCurrentValue().clone(); |
|
123 |
} catch (Exception ex) { |
|
124 |
LOG.warn("Not been able to clone export parameters", ex); |
|
125 |
return; |
|
126 |
} |
|
127 |
setSelectedService(exportParams.getFactory()); |
|
128 |
|
|
129 |
processPanel.getProcess().setParameters(exportParams); |
|
130 |
parameters = exportParams; |
|
131 |
break; |
|
168 | 132 |
} |
169 |
try { |
|
170 |
exportParams = he.getCurrentValue().clone(); |
|
171 |
} catch (CloneNotSupportedException ex) { |
|
172 |
LOG.error("Not been able to clone export parameters"); |
|
173 |
return; |
|
174 |
} |
|
175 |
setSelectedService(exportParams.getFactory()); |
|
176 | 133 |
|
177 |
SelectFormatPanel.this.processPanel.getProcess().setParameters(exportParams); |
|
178 |
SelectFormatPanel.this.parameters = exportParams; |
|
179 |
|
|
180 | 134 |
} |
181 |
} |
|
182 |
); |
|
183 |
|
|
184 |
// this.jpnTabs.setLayout(new BorderLayout()); |
|
185 |
// |
|
186 |
// EmptyBorder emptyborder2x2 = new EmptyBorder(2, 2, 2, 2); |
|
187 |
// bookmarksButton.setBorder(emptyborder2x2); |
|
188 |
// historyButton.setBorder(emptyborder2x2); |
|
189 |
// JPanel subPanel = new JPanel(); |
|
190 |
// subPanel.add(historyButton); |
|
191 |
// subPanel.add(bookmarksButton); |
|
192 |
// this.jpnTabs.add(subPanel, BorderLayout.EAST); |
|
193 |
|
|
135 |
}; |
|
136 |
Bookmarks<ExportParameters> bookmarks = ExportLocator.getManager().getBookmarks(); |
|
137 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(bookmarks, this.btnBookmark); |
|
138 |
this.bookmarksController.setAllowAddBookmarks(false); |
|
139 |
this.bookmarksController.setFilter(filter); |
|
140 |
this.bookmarksController.addActionListener(historyAndBookmarkListener); |
|
141 |
History<ExportParameters> history = ExportLocator.getManager().getHistory(); |
|
142 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(history, this.btnHistory); |
|
143 |
this.historyController.setFilter(filter); |
|
144 |
this.historyController.addActionListener(historyAndBookmarkListener); |
|
194 | 145 |
} |
195 | 146 |
|
196 | 147 |
private void doUpdateDescription() { |
Also available in: Unified diff