svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / DataParametersEditor.java @ 25384
History | View | Annotate | Download (5.86 KB)
1 |
/* 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 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
32 |
|
33 |
import java.awt.BorderLayout; |
34 |
import java.util.ArrayList; |
35 |
import java.util.Arrays; |
36 |
import java.util.Iterator; |
37 |
import java.util.List; |
38 |
|
39 |
import javax.swing.JFrame; |
40 |
import javax.swing.JPanel; |
41 |
|
42 |
import org.gvsig.fmap.dal.DALFileLibrary; |
43 |
import org.gvsig.fmap.dal.DALLibrary; |
44 |
import org.gvsig.fmap.dal.DALLocator; |
45 |
import org.gvsig.fmap.dal.DataStoreParameters; |
46 |
import org.gvsig.fmap.dal.store.dbf.DBFLibrary; |
47 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
48 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
49 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
50 |
import org.gvsig.gui.beans.swing.JButton; |
51 |
import org.gvsig.tools.ToolsLibrary; |
52 |
import org.gvsig.tools.dynobject.DynField; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.ui.mdiManager.IWindow; |
56 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
57 |
|
58 |
/**
|
59 |
* @author jmvivo
|
60 |
*
|
61 |
*/
|
62 |
public class DataParametersEditor extends JPanel implements IWindow { |
63 |
|
64 |
public static final int SHOW_ONLY_THIS_PARAMS = 0; |
65 |
public static final int HIDDE_THIS_PARAMS = 1; |
66 |
|
67 |
private DataStoreParameters parameters;
|
68 |
private String[] paramsNamesToShow; |
69 |
private JButton botAcept; |
70 |
private JButton botCancel; |
71 |
private JButton botRestoreDefaults; |
72 |
private JPanel panButtons; |
73 |
private JPanel panParameters; |
74 |
|
75 |
|
76 |
public DataParametersEditor(DataStoreParameters parameters) {
|
77 |
super();
|
78 |
this.parameters = parameters;
|
79 |
this.paramsNamesToShow = null; |
80 |
this.initialize();
|
81 |
} |
82 |
|
83 |
public DataParametersEditor(DataStoreParameters parameters, int mode, |
84 |
String[] paramsNames) { |
85 |
this(parameters);
|
86 |
if (mode == SHOW_ONLY_THIS_PARAMS){
|
87 |
this.paramsNamesToShow= paramsNames;
|
88 |
} else if (mode == HIDDE_THIS_PARAMS){ |
89 |
ArrayList<String> toShow = new ArrayList<String>(); |
90 |
List<DynField> fields = Arrays.asList(parameters.getDynClass() |
91 |
.getDynFields()); |
92 |
List<String> names = Arrays.asList(paramsNames); |
93 |
Iterator<DynField> iter = fields.iterator();
|
94 |
String fieldName;
|
95 |
while (iter.hasNext()) {
|
96 |
fieldName = iter.next().getName(); |
97 |
if (!names.contains(fieldName)) {
|
98 |
toShow.add(fieldName); |
99 |
} |
100 |
} |
101 |
this.paramsNamesToShow = toShow.toArray(new String[] {}); |
102 |
|
103 |
} else{
|
104 |
throw new IllegalArgumentException(); |
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
private void initialize() { |
110 |
this.setLayout(new BorderLayout(3, 3)); |
111 |
this.add(this.getParametersPanel(),BorderLayout.CENTER); |
112 |
this.add(this.getButtonsPanel(), BorderLayout.SOUTH); |
113 |
|
114 |
} |
115 |
|
116 |
private JPanel getButtonsPanel() { |
117 |
if (this.panButtons == null) { |
118 |
this.panButtons = new JPanel(); |
119 |
this.panButtons.setLayout(new BorderLayout(2, 2)); |
120 |
this.panButtons.add(this.getAcceptButton()); |
121 |
this.panButtons.add(this.getCancelButton()); |
122 |
this.panButtons.add(this.getRestoreDefaults()); |
123 |
} |
124 |
return this.panButtons; |
125 |
} |
126 |
|
127 |
private JButton getRestoreDefaults() { |
128 |
if (this.botRestoreDefaults == null) { |
129 |
this.botRestoreDefaults = new JButton(); |
130 |
this.botRestoreDefaults
|
131 |
.setText(getLocalizedText("restoreDefaults"));
|
132 |
} |
133 |
return this.botRestoreDefaults; |
134 |
} |
135 |
|
136 |
private JButton getCancelButton() { |
137 |
if (this.botCancel == null) { |
138 |
this.botCancel = new JButton(); |
139 |
this.botCancel.setText(getLocalizedText("cancel")); |
140 |
} |
141 |
return this.botCancel; |
142 |
} |
143 |
|
144 |
private String getLocalizedText(String txt) { |
145 |
try {
|
146 |
return PluginServices.getText(this, txt); |
147 |
} catch (Exception e) { |
148 |
return txt;
|
149 |
} |
150 |
} |
151 |
|
152 |
private JButton getAcceptButton() { |
153 |
if (this.botAcept == null){ |
154 |
this.botAcept = new JButton(); |
155 |
this.botAcept.setText(getLocalizedText("accept")); |
156 |
} |
157 |
return this.botAcept; |
158 |
} |
159 |
|
160 |
private JPanel getParametersPanel() { |
161 |
if (this.panParameters == null) { |
162 |
// TODO Auto-generated method stub
|
163 |
} |
164 |
return this.panParameters; |
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
169 |
*/
|
170 |
public WindowInfo getWindowInfo() {
|
171 |
// TODO Auto-generated method stub
|
172 |
return null; |
173 |
} |
174 |
|
175 |
/**
|
176 |
* @param args
|
177 |
*/
|
178 |
public static void main(String[] args) { |
179 |
ToolsLibrary toolsLibrary = new ToolsLibrary();
|
180 |
|
181 |
toolsLibrary.initialize(); |
182 |
toolsLibrary.postInitialize(); |
183 |
|
184 |
DALLibrary dalLibrary = new DALLibrary();
|
185 |
dalLibrary.initialize(); |
186 |
dalLibrary.postInitialize(); |
187 |
|
188 |
DALFileLibrary dalFileLibrary = new DALFileLibrary();
|
189 |
dalFileLibrary.initialize(); |
190 |
dalFileLibrary.postInitialize(); |
191 |
|
192 |
DBFLibrary dbfLibrary = new DBFLibrary();
|
193 |
dbfLibrary.initialize(); |
194 |
dbfLibrary.postInitialize(); |
195 |
|
196 |
SHPLibrary shpLibrary = new SHPLibrary();
|
197 |
shpLibrary.initialize(); |
198 |
shpLibrary.postInitialize(); |
199 |
|
200 |
JFrame frame = new JFrame(); |
201 |
|
202 |
SHPStoreParameters params; |
203 |
try {
|
204 |
params = (SHPStoreParameters) DALLocator.getDataManager() |
205 |
.createStoreParameters(SHPStoreProvider.NAME); |
206 |
} catch (Exception e) { |
207 |
e.printStackTrace(); |
208 |
System.exit(-1); |
209 |
return;
|
210 |
} |
211 |
|
212 |
params.setSHPFileName("test.shp");
|
213 |
|
214 |
DataParametersEditor editor = new DataParametersEditor(params);
|
215 |
|
216 |
frame.setLayout(new BorderLayout()); |
217 |
frame.add(editor); |
218 |
|
219 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
220 |
frame.setVisible(true);
|
221 |
} |
222 |
|
223 |
} |