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