root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanel.java @ 38441
History | View | Annotate | Download (22.1 KB)
1 | 25773 | jmvivo | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 IVER T.I. S.A. {{Task}}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
||
28 | |||
29 | import java.awt.Component; |
||
30 | import java.awt.GridBagConstraints; |
||
31 | import java.awt.GridBagLayout; |
||
32 | import java.awt.Insets; |
||
33 | import java.awt.event.ActionEvent; |
||
34 | import java.awt.event.ActionListener; |
||
35 | import java.io.File; |
||
36 | import java.util.ArrayList; |
||
37 | import java.util.Iterator; |
||
38 | import java.util.List; |
||
39 | import java.util.prefs.Preferences; |
||
40 | |||
41 | import javax.swing.AbstractListModel; |
||
42 | 36628 | cordinyana | import javax.swing.JButton; |
43 | 25773 | jmvivo | import javax.swing.JList; |
44 | import javax.swing.JPanel; |
||
45 | import javax.swing.JScrollPane; |
||
46 | import javax.swing.ScrollPaneConstants; |
||
47 | import javax.swing.event.ListSelectionEvent; |
||
48 | import javax.swing.event.ListSelectionListener; |
||
49 | import javax.swing.filechooser.FileFilter; |
||
50 | |||
51 | 33662 | cordinyana | import org.slf4j.Logger; |
52 | import org.slf4j.LoggerFactory; |
||
53 | |||
54 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
55 | 38441 | cordinyana | import org.gvsig.andami.messages.Messages; |
56 | 29596 | jpiera | import org.gvsig.andami.messages.NotificationManager; |
57 | 31496 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
58 | import org.gvsig.app.ApplicationManager; |
||
59 | 29596 | jpiera | import org.gvsig.app.gui.WizardPanel; |
60 | 31496 | jjdelcerro | import org.gvsig.app.prepareAction.PrepareContext; |
61 | 25773 | jmvivo | import org.gvsig.fmap.dal.DALLocator; |
62 | import org.gvsig.fmap.dal.DataManager; |
||
63 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
64 | import org.gvsig.fmap.dal.exception.DataException; |
||
65 | import org.gvsig.fmap.dal.exception.FileNotFoundException; |
||
66 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter; |
||
67 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
68 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
69 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
||
70 | 35341 | jpiera | import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
71 | import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectViewer; |
||
72 | 25773 | jmvivo | import org.gvsig.gui.beans.swing.JFileChooser; |
73 | import org.gvsig.tools.dynobject.DynObject; |
||
74 | 33662 | cordinyana | import org.gvsig.tools.service.ServiceException; |
75 | 36628 | cordinyana | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
76 | 25773 | jmvivo | |
77 | /**
|
||
78 | * @author jmvivo
|
||
79 | 36628 | cordinyana | *
|
80 | 25773 | jmvivo | */
|
81 | 25936 | jmvivo | public abstract class FilesystemExplorerWizardPanel extends WizardPanel |
82 | 36628 | cordinyana | implements ActionListener, ListSelectionListener { |
83 | 25773 | jmvivo | |
84 | 36628 | cordinyana | /**
|
85 | 25773 | jmvivo | *
|
86 | */
|
||
87 | 36628 | cordinyana | private static final long serialVersionUID = -3371957786521876903L; |
88 | 25773 | jmvivo | |
89 | 33662 | cordinyana | private static final Logger LOG = LoggerFactory |
90 | .getLogger(FilesystemExplorerWizardPanel.class); |
||
91 | |||
92 | 36628 | cordinyana | public static final String OPEN_LAYER_FILE_CHOOSER_ID = |
93 | "OPEN_LAYER_FILE_CHOOSER_ID";
|
||
94 | 25773 | jmvivo | |
95 | 36628 | cordinyana | protected static final String ADD_COMMAND = "ADD"; |
96 | 37507 | nfrancisco | protected static final String EDIT_COMMAND = "PROPERTIES"; |
97 | 36628 | cordinyana | protected static final String REMOVE_COMMAND = "REMOVE"; |
98 | protected static final String UP_COMMAND = "UP"; |
||
99 | protected static final String DOWN_COMMAND = "DOWN"; |
||
100 | 25773 | jmvivo | |
101 | 36628 | cordinyana | private static String lastPath = null; |
102 | private static MyFileFilter lastFilter = null; |
||
103 | 38441 | cordinyana | private static final String DEFAULT_FILTER = "All_supported"; |
104 | 25773 | jmvivo | |
105 | 36628 | cordinyana | private JList fileList; |
106 | private JScrollPane fileListScroll; |
||
107 | private JPanel buttonsPanel; |
||
108 | private JButton addButton; |
||
109 | 37507 | nfrancisco | private JButton propertiesButton; |
110 | 36628 | cordinyana | private JButton removeButton; |
111 | private JButton upButton; |
||
112 | private JButton downButton; |
||
113 | 25773 | jmvivo | |
114 | 36628 | cordinyana | protected FilesystemServerExplorer explorer;
|
115 | private ArrayList<MyFileFilter> filters; |
||
116 | 25773 | jmvivo | |
117 | 36628 | cordinyana | public void setTabName(String name) { |
118 | super.setTabName(name);
|
||
119 | } |
||
120 | 25773 | jmvivo | |
121 | 36628 | cordinyana | /*
|
122 | * (non-Javadoc)
|
||
123 | *
|
||
124 | * @see com.iver.cit.gvsig.gui.WizardPanel#getParameters()
|
||
125 | */
|
||
126 | @Override
|
||
127 | public DataStoreParameters[] getParameters() { |
||
128 | return ((FilesystemStoreListModel) getFileList().getModel())
|
||
129 | .getParameters(); |
||
130 | } |
||
131 | 25773 | jmvivo | |
132 | 36628 | cordinyana | /*
|
133 | * (non-Javadoc)
|
||
134 | *
|
||
135 | * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
|
||
136 | */
|
||
137 | @Override
|
||
138 | public void initWizard() { |
||
139 | setTabName(PluginServices.getText(this, "Fichero")); |
||
140 | if (lastPath == null) { |
||
141 | Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
||
142 | lastPath = prefs.get("DataFolder", null); |
||
143 | } |
||
144 | 25773 | jmvivo | |
145 | 36628 | cordinyana | DataManager dm = DALLocator.getDataManager(); |
146 | FilesystemServerExplorerParameters param; |
||
147 | try {
|
||
148 | param = |
||
149 | (FilesystemServerExplorerParameters) dm |
||
150 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
151 | param.setInitialpath(lastPath); |
||
152 | explorer = |
||
153 | (FilesystemServerExplorer) dm.openServerExplorer( |
||
154 | FilesystemServerExplorer.NAME, param); |
||
155 | } catch (Exception e) { |
||
156 | throw new RuntimeException(e); |
||
157 | } |
||
158 | 25773 | jmvivo | |
159 | 36628 | cordinyana | int mode = FilesystemServerExplorer.MODE_ALL;
|
160 | this.filters = new ArrayList<MyFileFilter>(); |
||
161 | if (this.getMapCtrl() == null) { |
||
162 | mode = FilesystemServerExplorer.MODE_FEATURE; |
||
163 | } else {
|
||
164 | mode = |
||
165 | FilesystemServerExplorer.MODE_GEOMETRY |
||
166 | | FilesystemServerExplorer.MODE_RASTER; |
||
167 | } |
||
168 | @SuppressWarnings("unchecked") |
||
169 | Iterator<FilesystemFileFilter> iter = explorer.getFilters(mode);
|
||
170 | while (iter.hasNext()) {
|
||
171 | this.filters.add(new MyFileFilter(iter.next())); |
||
172 | } |
||
173 | this.filters.add(new MyFileFilter(explorer.getFilter(mode, |
||
174 | 38441 | cordinyana | Messages.get(DEFAULT_FILTER)))); |
175 | 36628 | cordinyana | initUI(); |
176 | } |
||
177 | 25773 | jmvivo | |
178 | 36628 | cordinyana | private void initUI() { |
179 | this.setLayout(new GridBagLayout()); |
||
180 | GridBagConstraints constr = new GridBagConstraints(); |
||
181 | 25773 | jmvivo | |
182 | 36628 | cordinyana | constr.gridwidth = GridBagConstraints.RELATIVE;
|
183 | constr.gridheight = GridBagConstraints.RELATIVE;
|
||
184 | constr.fill = GridBagConstraints.BOTH;
|
||
185 | constr.anchor = GridBagConstraints.FIRST_LINE_START;
|
||
186 | constr.weightx = 1;
|
||
187 | constr.weighty = 1;
|
||
188 | constr.ipadx = 3;
|
||
189 | constr.ipady = 3;
|
||
190 | 25773 | jmvivo | |
191 | 36628 | cordinyana | this.add(getFileListScroll(), constr);
|
192 | 25773 | jmvivo | |
193 | 36628 | cordinyana | constr.gridwidth = GridBagConstraints.REMAINDER;
|
194 | constr.gridheight = GridBagConstraints.RELATIVE;
|
||
195 | constr.fill = GridBagConstraints.NONE;
|
||
196 | constr.anchor = GridBagConstraints.FIRST_LINE_END;
|
||
197 | constr.weightx = 0;
|
||
198 | constr.weighty = 0;
|
||
199 | this.add(getButtonsPanel(), constr);
|
||
200 | 25773 | jmvivo | |
201 | 36628 | cordinyana | this.updateButtons();
|
202 | 25773 | jmvivo | |
203 | 36628 | cordinyana | } |
204 | 25773 | jmvivo | |
205 | 36628 | cordinyana | protected class FilesystemStoreListModel extends AbstractListModel { |
206 | 25773 | jmvivo | |
207 | 36628 | cordinyana | private static final long serialVersionUID = -726119349962990665L; |
208 | private ArrayList<FilesystemStoreParameters> theList; |
||
209 | 25773 | jmvivo | |
210 | 36628 | cordinyana | public FilesystemStoreListModel() {
|
211 | theList = new ArrayList<FilesystemStoreParameters>(); |
||
212 | } |
||
213 | 25773 | jmvivo | |
214 | 36628 | cordinyana | public DataStoreParameters[] getParameters() { |
215 | return theList.toArray(new DataStoreParameters[0]); |
||
216 | } |
||
217 | 25773 | jmvivo | |
218 | 36628 | cordinyana | public Object getElementAt(int index) { |
219 | return theList.get(index).getFile().getName();
|
||
220 | } |
||
221 | 25773 | jmvivo | |
222 | 36628 | cordinyana | public FilesystemStoreParameters getStoreParameterAt(int index) { |
223 | return theList.get(index);
|
||
224 | } |
||
225 | 25773 | jmvivo | |
226 | 36628 | cordinyana | public int getSize() { |
227 | return theList.size();
|
||
228 | } |
||
229 | 25773 | jmvivo | |
230 | 36628 | cordinyana | public DynObject getDynObjectAt(int index) { |
231 | return (DynObject) theList.get(index);
|
||
232 | } |
||
233 | 25773 | jmvivo | |
234 | 36628 | cordinyana | public void add(DynObject dynObject) { |
235 | this.theList.add((FilesystemStoreParameters) dynObject);
|
||
236 | this.fireIntervalAdded(this, this.theList.size() - 1, |
||
237 | this.theList.size() - 1); |
||
238 | } |
||
239 | 25773 | jmvivo | |
240 | 36628 | cordinyana | public void addAll(List<FilesystemStoreParameters> toAdd) { |
241 | int index0 = this.getSize() - 1; |
||
242 | if (index0 < 0) { |
||
243 | index0 = 0;
|
||
244 | } |
||
245 | this.theList.addAll(toAdd);
|
||
246 | this.fireIntervalAdded(this, index0, this.theList.size() - 1); |
||
247 | } |
||
248 | 25773 | jmvivo | |
249 | 36628 | cordinyana | public void remove(int i) { |
250 | this.theList.remove(i);
|
||
251 | this.fireIntervalRemoved(this, i, i); |
||
252 | 25773 | jmvivo | |
253 | 36628 | cordinyana | } |
254 | 25773 | jmvivo | |
255 | 36628 | cordinyana | public void up(FilesystemStoreParameters item) { |
256 | int curIndex = this.theList.indexOf(item); |
||
257 | if (curIndex < 1) { |
||
258 | return;
|
||
259 | } |
||
260 | this.theList.remove(item);
|
||
261 | this.theList.add(curIndex - 1, item); |
||
262 | this.fireContentsChanged(this, curIndex, curIndex - 1); |
||
263 | } |
||
264 | 25773 | jmvivo | |
265 | 36628 | cordinyana | public void down(FilesystemStoreParameters item) { |
266 | int curIndex = this.theList.indexOf(item); |
||
267 | if (curIndex < 0) { |
||
268 | return;
|
||
269 | } else
|
||
270 | if (curIndex == this.theList.size() - 1) { |
||
271 | return;
|
||
272 | } |
||
273 | this.theList.remove(item);
|
||
274 | this.theList.add(curIndex + 1, item); |
||
275 | this.fireContentsChanged(this, curIndex, curIndex + 1); |
||
276 | } |
||
277 | 25773 | jmvivo | |
278 | 36628 | cordinyana | } |
279 | 25773 | jmvivo | |
280 | 36628 | cordinyana | protected JList getFileList() { |
281 | if (fileList == null) { |
||
282 | fileList = new JList(new FilesystemStoreListModel()); |
||
283 | 25773 | jmvivo | |
284 | 36628 | cordinyana | fileList.addListSelectionListener(this);
|
285 | } |
||
286 | return fileList;
|
||
287 | } |
||
288 | 25773 | jmvivo | |
289 | 36628 | cordinyana | private JScrollPane getFileListScroll() { |
290 | if (fileListScroll == null) { |
||
291 | fileListScroll = new JScrollPane(); |
||
292 | fileListScroll.setViewportView(getFileList()); |
||
293 | fileListScroll |
||
294 | .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
295 | fileListScroll |
||
296 | .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
297 | 25773 | jmvivo | |
298 | 36628 | cordinyana | } |
299 | return fileListScroll;
|
||
300 | } |
||
301 | 25773 | jmvivo | |
302 | 36628 | cordinyana | private Component getButtonsPanel() { |
303 | if (buttonsPanel == null) { |
||
304 | buttonsPanel = new JPanel(); |
||
305 | 25773 | jmvivo | |
306 | 36628 | cordinyana | buttonsPanel.setLayout(new GridBagLayout()); |
307 | 25773 | jmvivo | |
308 | 36628 | cordinyana | GridBagConstraints constr = new GridBagConstraints(); |
309 | 25773 | jmvivo | |
310 | 36628 | cordinyana | constr.anchor = GridBagConstraints.CENTER;
|
311 | constr.fill = GridBagConstraints.NONE;
|
||
312 | constr.ipadx = 3;
|
||
313 | constr.ipady = 3;
|
||
314 | constr.insets = new Insets(3, 3, 3, 3); |
||
315 | constr.gridwidth = GridBagConstraints.REMAINDER;
|
||
316 | 25773 | jmvivo | |
317 | 36628 | cordinyana | buttonsPanel.add(getAddButton(), constr); |
318 | 37507 | nfrancisco | buttonsPanel.add(getPropertiesButton(), constr); |
319 | 36628 | cordinyana | buttonsPanel.add(getRemoveButton(), constr); |
320 | buttonsPanel.add(getUpButton(), constr); |
||
321 | buttonsPanel.add(getDownButton(), constr); |
||
322 | // buttonsPanel.add(new JLabel(), constrLbl);
|
||
323 | } |
||
324 | return buttonsPanel;
|
||
325 | } |
||
326 | 25773 | jmvivo | |
327 | 36628 | cordinyana | private JButton getAddButton() { |
328 | if (addButton == null) { |
||
329 | addButton = |
||
330 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
331 | addButton.setText(getLocalizedText("add"));
|
||
332 | 37507 | nfrancisco | addButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
333 | 36628 | cordinyana | addButton.setActionCommand(ADD_COMMAND); |
334 | addButton.addActionListener(this);
|
||
335 | } |
||
336 | return addButton;
|
||
337 | } |
||
338 | 25773 | jmvivo | |
339 | 37507 | nfrancisco | private JButton getPropertiesButton() { |
340 | if (propertiesButton == null) { |
||
341 | propertiesButton = |
||
342 | 36628 | cordinyana | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
343 | 37507 | nfrancisco | propertiesButton.setText(getLocalizedText("properties"));
|
344 | propertiesButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
||
345 | propertiesButton.setActionCommand(EDIT_COMMAND); |
||
346 | propertiesButton.addActionListener(this);
|
||
347 | 36628 | cordinyana | } |
348 | 37507 | nfrancisco | return propertiesButton;
|
349 | 36628 | cordinyana | } |
350 | 25773 | jmvivo | |
351 | 36628 | cordinyana | private JButton getRemoveButton() { |
352 | if (removeButton == null) { |
||
353 | removeButton = |
||
354 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
355 | removeButton.setText(getLocalizedText("remove"));
|
||
356 | 37507 | nfrancisco | removeButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
357 | 36628 | cordinyana | removeButton.setActionCommand(REMOVE_COMMAND); |
358 | removeButton.addActionListener(this);
|
||
359 | } |
||
360 | return removeButton;
|
||
361 | } |
||
362 | 25773 | jmvivo | |
363 | 36628 | cordinyana | private JButton getUpButton() { |
364 | if (upButton == null) { |
||
365 | upButton = |
||
366 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
367 | upButton.setText(getLocalizedText("up"));
|
||
368 | 37507 | nfrancisco | upButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
369 | 36628 | cordinyana | upButton.setActionCommand(UP_COMMAND); |
370 | upButton.addActionListener(this);
|
||
371 | } |
||
372 | return upButton;
|
||
373 | } |
||
374 | 25773 | jmvivo | |
375 | 36628 | cordinyana | private JButton getDownButton() { |
376 | if (downButton == null) { |
||
377 | downButton = |
||
378 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
379 | downButton.setText(getLocalizedText("down"));
|
||
380 | 37507 | nfrancisco | downButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
381 | 36628 | cordinyana | downButton.setActionCommand(DOWN_COMMAND); |
382 | downButton.addActionListener(this);
|
||
383 | } |
||
384 | return downButton;
|
||
385 | } |
||
386 | 25773 | jmvivo | |
387 | 36628 | cordinyana | private String getLocalizedText(String txt) { |
388 | try {
|
||
389 | return PluginServices.getText(this, txt); |
||
390 | } catch (Exception e) { |
||
391 | return txt;
|
||
392 | } |
||
393 | } |
||
394 | 25773 | jmvivo | |
395 | 36628 | cordinyana | public void actionPerformed(ActionEvent e) { |
396 | String command = e.getActionCommand();
|
||
397 | FilesystemStoreListModel model = |
||
398 | (FilesystemStoreListModel) getFileList().getModel(); |
||
399 | 25773 | jmvivo | |
400 | 36628 | cordinyana | if (command == ADD_COMMAND) {
|
401 | List<FilesystemStoreParameters> toAdd = this.addFiles(); |
||
402 | if (toAdd.isEmpty()) {
|
||
403 | return;
|
||
404 | } |
||
405 | model.addAll(toAdd); |
||
406 | 25773 | jmvivo | |
407 | 36628 | cordinyana | getFileList().setModel(model); |
408 | 25773 | jmvivo | |
409 | 36628 | cordinyana | } else
|
410 | if (command == EDIT_COMMAND) {
|
||
411 | DynObject dynObject = |
||
412 | model.getDynObjectAt(getFileList().getSelectedIndex()); |
||
413 | 25773 | jmvivo | |
414 | 36628 | cordinyana | try {
|
415 | DynObjectEditor editor = new DynObjectEditor(dynObject);
|
||
416 | editor.editObject(true);
|
||
417 | 33662 | cordinyana | } catch (ServiceException ex) {
|
418 | LOG.error( |
||
419 | "Error creating a Swing component for the DynObject: "
|
||
420 | + dynObject, ex); |
||
421 | 36628 | cordinyana | } |
422 | 25773 | jmvivo | |
423 | 36628 | cordinyana | } else
|
424 | if (command == REMOVE_COMMAND) {
|
||
425 | int[] selecteds = getFileList().getSelectedIndices(); |
||
426 | for (int i = selecteds.length - 1; i > -1; i--) { |
||
427 | model.remove(selecteds[i]); |
||
428 | } |
||
429 | getFileList().setSelectedIndex(-1);
|
||
430 | 25773 | jmvivo | |
431 | 36628 | cordinyana | } else
|
432 | if (command == UP_COMMAND) {
|
||
433 | List<FilesystemStoreParameters> items =
|
||
434 | new ArrayList<FilesystemStoreParameters>(); |
||
435 | int[] selecteds = getFileList().getSelectedIndices(); |
||
436 | if (selecteds.length == 0 || selecteds[0] == 0) { |
||
437 | return;
|
||
438 | } |
||
439 | for (int i = 0; i < selecteds.length; i++) { |
||
440 | items.add(model.getStoreParameterAt(selecteds[i])); |
||
441 | selecteds[i]--; |
||
442 | } |
||
443 | Iterator<FilesystemStoreParameters> iter =
|
||
444 | items.iterator(); |
||
445 | while (iter.hasNext()) {
|
||
446 | model.up(iter.next()); |
||
447 | } |
||
448 | getFileList().setSelectedIndices(selecteds); |
||
449 | 25773 | jmvivo | |
450 | 36628 | cordinyana | } else
|
451 | if (command == DOWN_COMMAND) {
|
||
452 | List<FilesystemStoreParameters> items =
|
||
453 | new ArrayList<FilesystemStoreParameters>(); |
||
454 | int[] selecteds = |
||
455 | getFileList().getSelectedIndices(); |
||
456 | if (selecteds.length == 0 |
||
457 | || selecteds[selecteds.length - 1] == model
|
||
458 | .getSize() - 1) {
|
||
459 | return;
|
||
460 | } |
||
461 | for (int i = selecteds.length - 1; i > -1; i--) { |
||
462 | items.add(model |
||
463 | .getStoreParameterAt(selecteds[i])); |
||
464 | selecteds[i]++; |
||
465 | } |
||
466 | Iterator<FilesystemStoreParameters> iter =
|
||
467 | items.iterator(); |
||
468 | while (iter.hasNext()) {
|
||
469 | model.down(iter.next()); |
||
470 | } |
||
471 | getFileList().setSelectedIndices(selecteds); |
||
472 | 25773 | jmvivo | |
473 | 36628 | cordinyana | } else {
|
474 | throw new IllegalArgumentException(command); |
||
475 | } |
||
476 | 25773 | jmvivo | |
477 | 36628 | cordinyana | } |
478 | 25773 | jmvivo | |
479 | 36628 | cordinyana | public List<DynObject> getSelecteds() { |
480 | ArrayList<DynObject> list = new ArrayList<DynObject>(); |
||
481 | JList fList = this.getFileList(); |
||
482 | int[] selecteds = fList.getSelectedIndices(); |
||
483 | FilesystemStoreListModel model = |
||
484 | (FilesystemStoreListModel) fList.getModel(); |
||
485 | 25773 | jmvivo | |
486 | 36628 | cordinyana | for (int index : selecteds) { |
487 | list.add((DynObject) model.getStoreParameterAt(index)); |
||
488 | } |
||
489 | return list;
|
||
490 | } |
||
491 | 25773 | jmvivo | |
492 | 36628 | cordinyana | public void valueChanged(ListSelectionEvent e) { |
493 | this.updateButtons();
|
||
494 | } |
||
495 | 25773 | jmvivo | |
496 | 36628 | cordinyana | public class MyFileFilter extends FileFilter { |
497 | 25773 | jmvivo | |
498 | 36628 | cordinyana | public FilesystemFileFilter filter = null; |
499 | 25773 | jmvivo | |
500 | 36628 | cordinyana | public MyFileFilter(FilesystemFileFilter params) {
|
501 | this.filter = params;
|
||
502 | } |
||
503 | 25773 | jmvivo | |
504 | 36628 | cordinyana | /**
|
505 | * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||
506 | */
|
||
507 | public boolean accept(File f) { |
||
508 | if (f.isDirectory()) {
|
||
509 | return true; |
||
510 | } |
||
511 | return filter.accept(f);
|
||
512 | 25773 | jmvivo | |
513 | 36628 | cordinyana | } |
514 | 25773 | jmvivo | |
515 | 36628 | cordinyana | /**
|
516 | * @see javax.swing.filechooser.FileFilter#getDescription()
|
||
517 | */
|
||
518 | public String getDescription() { |
||
519 | return filter.getDescription();
|
||
520 | } |
||
521 | 25773 | jmvivo | |
522 | 36628 | cordinyana | public String getName() { |
523 | return filter.getDataStoreProviderName();
|
||
524 | } |
||
525 | } |
||
526 | 25773 | jmvivo | |
527 | 36628 | cordinyana | private List<FilesystemStoreParameters> addFiles() { |
528 | this.callStateChanged(true); |
||
529 | JFileChooser fileChooser =
|
||
530 | new JFileChooser(OPEN_LAYER_FILE_CHOOSER_ID, |
||
531 | explorer.getCurrentPath()); |
||
532 | fileChooser.setMultiSelectionEnabled(true);
|
||
533 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
534 | 25773 | jmvivo | |
535 | 36628 | cordinyana | Iterator<MyFileFilter> iter = this.filters.iterator(); |
536 | while (iter.hasNext()) {
|
||
537 | fileChooser.addChoosableFileFilter(iter.next()); |
||
538 | } |
||
539 | 25773 | jmvivo | |
540 | 36628 | cordinyana | if (lastFilter != null && filters.contains(lastFilter)) { |
541 | fileChooser.setFileFilter(lastFilter); |
||
542 | } |
||
543 | 25773 | jmvivo | |
544 | 36628 | cordinyana | int result = fileChooser.showOpenDialog(this); |
545 | 25773 | jmvivo | |
546 | 36628 | cordinyana | List<FilesystemStoreParameters> toAdd =
|
547 | new ArrayList<FilesystemStoreParameters>(); |
||
548 | 26919 | jmvivo | |
549 | 36628 | cordinyana | if (result == JFileChooser.APPROVE_OPTION) { |
550 | lastPath = fileChooser.getCurrentDirectory().getAbsolutePath(); |
||
551 | try {
|
||
552 | explorer.setCurrentPath(fileChooser.getCurrentDirectory()); |
||
553 | } catch (FileNotFoundException e) { |
||
554 | NotificationManager.addError(e); |
||
555 | } |
||
556 | lastFilter = (MyFileFilter) fileChooser.getFileFilter(); |
||
557 | ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
||
558 | PrepareContext context = this.getPrepareDataStoreContext();
|
||
559 | 36767 | nbrodin | List<DataStoreParameters> paramList = new ArrayList<DataStoreParameters>(); |
560 | List<DataStoreParameters> toAddParamList = null; |
||
561 | 36628 | cordinyana | for (File aFile : fileChooser.getSelectedFiles()) { |
562 | try {
|
||
563 | 36767 | nbrodin | DataStoreParameters param = |
564 | 36628 | cordinyana | explorer.createStoreParameters(aFile, lastFilter |
565 | .getDescription().compareTo(DEFAULT_FILTER) == 0
|
||
566 | ? null : lastFilter.getName());
|
||
567 | if (param == null) { |
||
568 | // TODO show warning
|
||
569 | continue;
|
||
570 | } |
||
571 | 29197 | jmvivo | |
572 | 36767 | nbrodin | paramList.add(param); |
573 | |||
574 | 36628 | cordinyana | } catch (DataException e) {
|
575 | NotificationManager.addError(e); |
||
576 | return null; |
||
577 | } |
||
578 | } |
||
579 | 36767 | nbrodin | |
580 | try {
|
||
581 | toAddParamList = |
||
582 | appGvSIGMan.prepareOpenDataStoreParameters(paramList, context); |
||
583 | } catch (Exception e) { |
||
584 | NotificationManager.addError(e); |
||
585 | } |
||
586 | |||
587 | for (int i = 0; i < toAddParamList.size(); i++) { |
||
588 | toAdd.add((FilesystemStoreParameters)toAddParamList.get(i)); |
||
589 | } |
||
590 | 36628 | cordinyana | } |
591 | return toAdd;
|
||
592 | } |
||
593 | 25773 | jmvivo | |
594 | 36628 | cordinyana | protected abstract PrepareContext getPrepareDataStoreContext(); |
595 | 26919 | jmvivo | |
596 | 36628 | cordinyana | private void updateButtons() { |
597 | int selectedIndex = this.getFileList().getSelectedIndex(); |
||
598 | int size = this.getFileList().getModel().getSize(); |
||
599 | int[] selecteds = this.getFileList().getSelectedIndices(); |
||
600 | if (size < 1) { |
||
601 | 37507 | nfrancisco | this.getPropertiesButton().setEnabled(false); |
602 | 36628 | cordinyana | this.getRemoveButton().setEnabled(false); |
603 | this.getUpButton().setEnabled(false); |
||
604 | this.getDownButton().setEnabled(false); |
||
605 | return;
|
||
606 | } else
|
||
607 | if (size == 1) { |
||
608 | this.getUpButton().setEnabled(false); |
||
609 | this.getDownButton().setEnabled(false); |
||
610 | } else {
|
||
611 | this.getUpButton().setEnabled(selectedIndex > 0); |
||
612 | 25799 | jmvivo | |
613 | 36628 | cordinyana | this.getDownButton().setEnabled(
|
614 | selectedIndex > -1
|
||
615 | && selecteds[selecteds.length - 1] < size - 1); |
||
616 | } |
||
617 | 37507 | nfrancisco | this.getPropertiesButton().setEnabled(
|
618 | 36628 | cordinyana | selectedIndex > -1
|
619 | && this.getFileList().getSelectedIndices().length == 1); |
||
620 | this.getRemoveButton().setEnabled(selectedIndex > -1); |
||
621 | } |
||
622 | 25773 | jmvivo | |
623 | 36628 | cordinyana | public void close() { |
624 | if (explorer != null) { |
||
625 | explorer.dispose(); |
||
626 | explorer = null;
|
||
627 | } |
||
628 | if (filters != null) { |
||
629 | filters.clear(); |
||
630 | filters = null;
|
||
631 | } |
||
632 | } |
||
633 | } |