gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.base / src / main / java / org / gvsig / sextante / app / algorithm / base / panel / AlgorithmOutputPanel.java @ 31
History | View | Annotate | Download (5.85 KB)
1 |
package org.gvsig.sextante.app.algorithm.base.panel; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.awt.Insets; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.util.ArrayList; |
10 |
import java.util.Iterator; |
11 |
import java.util.List; |
12 |
|
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JComboBox; |
15 |
import javax.swing.JPanel; |
16 |
|
17 |
import org.gvsig.fmap.dal.DALLocator; |
18 |
import org.gvsig.fmap.dal.DataManager; |
19 |
import org.gvsig.fmap.dal.DataServerExplorer; |
20 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
21 |
import org.gvsig.fmap.dal.DataStoreParameters; |
22 |
import org.gvsig.fmap.dal.exception.DataException; |
23 |
import org.gvsig.fmap.dal.exception.InitializeException; |
24 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
25 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
26 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.DynObjectEditor; |
27 |
import org.gvsig.tools.dynobject.DynObject; |
28 |
|
29 |
import es.unex.sextante.core.GeoAlgorithm; |
30 |
import es.unex.sextante.core.Sextante; |
31 |
import es.unex.sextante.gui.algorithm.IOutputSelection; |
32 |
|
33 |
/**
|
34 |
*
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
36 |
*/
|
37 |
public class AlgorithmOutputPanel extends JPanel implements IOutputSelection, ActionListener { |
38 |
private static final long serialVersionUID = 1L; |
39 |
//private GeoAlgorithm m_Algorithm = null;
|
40 |
private JComboBox cProvider = null; |
41 |
private JComboBox cExplorer = null; |
42 |
private JButton button = null; |
43 |
private ArrayList<DataStoreParameters> listProvider = new ArrayList<DataStoreParameters>(); |
44 |
private ArrayList<DataServerExplorer> listExplorer = new ArrayList<DataServerExplorer>(); |
45 |
private DynObjectEditor editor = null; |
46 |
|
47 |
public AlgorithmOutputPanel() {
|
48 |
super();
|
49 |
initGUI(); |
50 |
loadProviderList(getCProvider(), listProvider); |
51 |
loadExplorerList(getCExplorer(), listExplorer); |
52 |
} |
53 |
|
54 |
public void init(GeoAlgorithm algorithm) { |
55 |
//m_Algorithm = algorithm;
|
56 |
initGUI(); |
57 |
} |
58 |
|
59 |
private void initGUI() { |
60 |
GridBagLayout gbl = new GridBagLayout(); |
61 |
this.setLayout(gbl);
|
62 |
|
63 |
GridBagConstraints gbc = new GridBagConstraints(); |
64 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
65 |
gbc.weightx = 1.0;
|
66 |
gbc.gridx = 0;
|
67 |
gbc.gridy = 0;
|
68 |
gbc.insets = new Insets(0, 2, 0, 0); |
69 |
this.add(getCProvider(), gbc);
|
70 |
|
71 |
gbc.gridx = 1;
|
72 |
this.add(getCExplorer(), gbc);
|
73 |
|
74 |
gbc.fill = GridBagConstraints.NONE;
|
75 |
gbc.weightx = 0;
|
76 |
gbc.gridx = 2;
|
77 |
gbc.insets = new Insets(0, 5, 0, 2); |
78 |
this.add(getButton(), gbc);
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Gets a ComboBox
|
83 |
* @return
|
84 |
*/
|
85 |
public JComboBox getCProvider() { |
86 |
if(cProvider == null) { |
87 |
cProvider = new JComboBox(); |
88 |
cProvider.addActionListener(this);
|
89 |
cProvider.setPreferredSize(new Dimension(0, 18)); |
90 |
} |
91 |
return cProvider;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* Gets a ComboBox
|
96 |
* @return
|
97 |
*/
|
98 |
public JComboBox getCExplorer() { |
99 |
if(cExplorer == null) { |
100 |
cExplorer = new JComboBox(); |
101 |
cExplorer.addActionListener(this);
|
102 |
cExplorer.setPreferredSize(new Dimension(0, 18)); |
103 |
} |
104 |
return cExplorer;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Gets a JButton
|
109 |
* @return
|
110 |
*/
|
111 |
public JButton getButton() { |
112 |
if(button == null) { |
113 |
button = new JButton("..."); |
114 |
button.setPreferredSize(new Dimension(60, 18)); |
115 |
button.addActionListener(this);
|
116 |
} |
117 |
return button;
|
118 |
} |
119 |
|
120 |
@SuppressWarnings("unchecked") |
121 |
private void loadProviderList(JComboBox cProvider, ArrayList<DataStoreParameters> listDSParam) { |
122 |
DataManager manager = DALLocator.getDataManager(); |
123 |
|
124 |
List lProvider = manager.getStoreProviders();
|
125 |
Iterator it = lProvider.iterator();
|
126 |
cProvider.removeAllItems(); |
127 |
listDSParam.clear(); |
128 |
while(it.hasNext()) {
|
129 |
try {
|
130 |
String provider = it.next().toString();
|
131 |
cProvider.addItem(provider); |
132 |
DataStoreParameters param = manager.createStoreParameters(provider); |
133 |
listDSParam.add(param); |
134 |
} catch (InitializeException e1) {
|
135 |
Sextante.addErrorToLog(e1); |
136 |
} catch (ProviderNotRegisteredException e1) {
|
137 |
Sextante.addErrorToLog(e1); |
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
@SuppressWarnings("unchecked") |
143 |
private void loadExplorerList(JComboBox cExplorer, ArrayList<DataServerExplorer> listDSExplorer) { |
144 |
ArrayList<DataServerExplorer> dseList =
|
145 |
getDataServerExplorerListFromProvider((String)getCProvider().getSelectedItem());
|
146 |
|
147 |
if(dseList == null) |
148 |
return;
|
149 |
|
150 |
getCExplorer().removeAllItems(); |
151 |
for (int i = 0; i < dseList.size(); i++) |
152 |
getCExplorer().addItem(dseList.get(i).getName()); |
153 |
} |
154 |
|
155 |
private ArrayList<DataServerExplorer> getDataServerExplorerListFromProvider(String provLabel) { |
156 |
DataManager manager = DALLocator.getDataManager(); |
157 |
List lExplorer = manager.getExplorerProviders();
|
158 |
ArrayList<DataServerExplorer> dseList = new ArrayList<DataServerExplorer>(); |
159 |
|
160 |
Iterator it = lExplorer.iterator();
|
161 |
|
162 |
while(it.hasNext()) {
|
163 |
String explorer = (String)it.next(); |
164 |
|
165 |
DataServerExplorerParameters param; |
166 |
try {
|
167 |
param = manager.createServerExplorerParameters(explorer); |
168 |
DataServerExplorer dsExplorer = manager.createServerExplorer(param); |
169 |
if(dsExplorer.getAddParameters(provLabel) != null) |
170 |
dseList.add(dsExplorer); |
171 |
} catch (Exception e) { |
172 |
continue;
|
173 |
} |
174 |
} |
175 |
return dseList;
|
176 |
} |
177 |
|
178 |
public void actionPerformed(ActionEvent e) { |
179 |
if(e.getSource() == getButton()) {
|
180 |
int index = getCProvider().getSelectedIndex();
|
181 |
|
182 |
editor = new DynObjectEditor(listProvider.get(index),
|
183 |
DynObjectEditor.SHOW_ALL, null, true, false); |
184 |
editor.editObject(true);
|
185 |
} |
186 |
|
187 |
if(e.getSource() == getCProvider()) {
|
188 |
loadExplorerList(getCExplorer(), listExplorer); |
189 |
} |
190 |
} |
191 |
|
192 |
public Object getOutputParameters() { |
193 |
//return "/tmp/prueba";
|
194 |
//int index = getCProvider().getSelectedIndex();
|
195 |
return editor.getParameters();//paramList.get(index); |
196 |
} |
197 |
|
198 |
public void setOutputParameters(Object param) { |
199 |
if(param instanceof DataStoreParameters) |
200 |
editor.setParameters((DynObject)param); |
201 |
} |
202 |
} |