Revision 3129

View differences:

org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.5/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG
2
  Association. This program is free software; you can redistribute it and/or modify
3
  it under the terms of the GNU General Public License as published by the Free Software
4
  Foundation; either version 3 of the License, or (at your option) any later version.
5
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
6
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7
  PURPOSE. See the GNU General Public License for more details. You should have received
8
  a copy of the GNU General Public License along with this program; if not, write to
9
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
10
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
11
  or visit our website www.gvsig.com. -->
12
<assembly>
13
  <id>gvsig-plugin-package</id>
14
  <formats>
15
    <format>zip</format>
16
  </formats>
17
  <baseDirectory>${project.artifactId}</baseDirectory>
18
  <includeBaseDirectory>true</includeBaseDirectory>
19
  <files>
20
    <file>
21
      <source>target/${project.artifactId}-${project.version}.jar</source>
22
      <outputDirectory>lib</outputDirectory>
23
    </file>
24
    <file>
25
      <source>target/package.info</source>
26
    </file>
27
  </files>
28

  
29
  <fileSets>
30
    <fileSet>
31
      <directory>src/main/resources-plugin</directory>
32
      <outputDirectory>.</outputDirectory>
33
    </fileSet>
34
  </fileSets>
35

  
36

  
37
  <dependencySets>
38
    <dependencySet>
39
      <useProjectArtifact>false</useProjectArtifact>
40
      <useTransitiveDependencies>false</useTransitiveDependencies>
41
      <outputDirectory>lib</outputDirectory>
42
      <includes>
43
        <include>org.gvsig:org.gvsig.vcsgis.lib.api</include>
44
        <include>org.gvsig:org.gvsig.vcsgis.lib.impl</include>
45
        <include>org.gvsig:org.gvsig.vcsgis.swing.api</include>
46
        <include>org.gvsig:org.gvsig.vcsgis.swing.impl</include>
47
        <!--<include>org.apache.httpcomponents:httpclient</include>-->
48

  
49
        
50
      </includes>
51
    </dependencySet>
52
  </dependencySets>
53

  
54
</assembly>
55

  
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.5/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.mainplugin/src/main/java/org/gvsig/vcsgis/app/addlayer/AbstractWizardVCSGisView.java
1
package org.gvsig.vcsgis.app.addlayer;
2

  
3
import com.jeta.forms.components.border.TitledBorderLabel;
4
import com.jeta.open.i18n.I18NUtils;
5
import com.jgoodies.forms.layout.CellConstraints;
6
import com.jgoodies.forms.layout.FormLayout;
7
import java.awt.BorderLayout;
8
import java.awt.Color;
9
import java.awt.ComponentOrientation;
10
import java.awt.Container;
11
import java.awt.Dimension;
12
import javax.swing.Box;
13
import javax.swing.ImageIcon;
14
import javax.swing.JButton;
15
import javax.swing.JComboBox;
16
import javax.swing.JFrame;
17
import javax.swing.JLabel;
18
import javax.swing.JList;
19
import javax.swing.JPanel;
20
import javax.swing.JProgressBar;
21
import javax.swing.JScrollPane;
22
import javax.swing.JTextField;
23
import javax.swing.border.EmptyBorder;
24

  
25

  
26
public class AbstractWizardVCSGisView extends JPanel
27
{
28
   TitledBorderLabel lblWorkspace = new TitledBorderLabel();
29
   JButton btnAdvancedProperties = new JButton();
30
   TitledBorderLabel lblTable = new TitledBorderLabel();
31
   TitledBorderLabel lblColumns = new TitledBorderLabel();
32
   JList lstColumns = new JList();
33
   JList lstTables = new JList();
34
   JButton btnDeselectAllColumns = new JButton();
35
   JButton btnSelectAllColumns = new JButton();
36
   JButton btnTablesFilter = new JButton();
37
   JTextField txtTablesFilter = new JTextField();
38
   JButton btnCheckout = new JButton();
39
   JLabel lblName = new JLabel();
40
   JTextField txtName = new JTextField();
41
   JLabel lblIdField = new JLabel();
42
   JComboBox cboIdField = new JComboBox();
43
   JLabel lblGeometryField = new JLabel();
44
   JComboBox cboGeometryField = new JComboBox();
45
   JLabel lblProjection = new JLabel();
46
   JLabel lblFilter = new JLabel();
47
   JTextField txtProjection = new JTextField();
48
   JButton btnProjection = new JButton();
49
   JTextField txtFilter = new JTextField();
50
   JButton btnFilter = new JButton();
51
   JButton btnFilterBookmarks = new JButton();
52
   JButton btnFilterHistory = new JButton();
53
   JComboBox cboWorkspaces = new JComboBox();
54
   JTextField txtRepositoryInfo = new JTextField();
55
   JButton btnInitWorkspace = new JButton();
56
   JButton btnAddWorkspace = new JButton();
57
   JLabel lblStatusTitle = new JLabel();
58
   JProgressBar pbStatus = new JProgressBar();
59
   JLabel lblStatusMessages = new JLabel();
60

  
61
   /**
62
    * Default constructor
63
    */
64
   public AbstractWizardVCSGisView()
65
   {
66
      initializePanel();
67
   }
68

  
69
   /**
70
    * Adds fill components to empty cells in the first row and first column of the grid.
71
    * This ensures that the grid spacing will be the same as shown in the designer.
72
    * @param cols an array of column indices in the first row where fill components should be added.
73
    * @param rows an array of row indices in the first column where fill components should be added.
74
    */
75
   void addFillComponents( Container panel, int[] cols, int[] rows )
76
   {
77
      Dimension filler = new Dimension(10,10);
78

  
79
      boolean filled_cell_11 = false;
80
      CellConstraints cc = new CellConstraints();
81
      if ( cols.length > 0 && rows.length > 0 )
82
      {
83
         if ( cols[0] == 1 && rows[0] == 1 )
84
         {
85
            /** add a rigid area  */
86
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
87
            filled_cell_11 = true;
88
         }
89
      }
90

  
91
      for( int index = 0; index < cols.length; index++ )
92
      {
93
         if ( cols[index] == 1 && filled_cell_11 )
94
         {
95
            continue;
96
         }
97
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
98
      }
99

  
100
      for( int index = 0; index < rows.length; index++ )
101
      {
102
         if ( rows[index] == 1 && filled_cell_11 )
103
         {
104
            continue;
105
         }
106
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
107
      }
108

  
109
   }
110

  
111
   /**
112
    * Helper method to load an image file from the CLASSPATH
113
    * @param imageName the package and name of the file to load relative to the CLASSPATH
114
    * @return an ImageIcon instance with the specified image file
115
    * @throws IllegalArgumentException if the image resource cannot be loaded.
116
    */
117
   public ImageIcon loadImage( String imageName )
118
   {
119
      try
120
      {
121
         ClassLoader classloader = getClass().getClassLoader();
122
         java.net.URL url = classloader.getResource( imageName );
123
         if ( url != null )
124
         {
125
            ImageIcon icon = new ImageIcon( url );
126
            return icon;
127
         }
128
      }
129
      catch( Exception e )
130
      {
131
         e.printStackTrace();
132
      }
133
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
134
   }
135

  
136
   /**
137
    * Method for recalculating the component orientation for 
138
    * right-to-left Locales.
139
    * @param orientation the component orientation to be applied
140
    */
141
   public void applyComponentOrientation( ComponentOrientation orientation )
142
   {
143
      // Not yet implemented...
144
      // I18NUtils.applyComponentOrientation(this, orientation);
145
      super.applyComponentOrientation(orientation);
146
   }
147

  
148
   public JPanel createPanel()
149
   {
150
      JPanel jpanel1 = new JPanel();
151
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:8DLU:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
152
      CellConstraints cc = new CellConstraints();
153
      jpanel1.setLayout(formlayout1);
154

  
155
      lblWorkspace.setName("lblWorkspace");
156
      lblWorkspace.setText("_Workspace");
157
      jpanel1.add(lblWorkspace,cc.xy(2,1));
158

  
159
      btnAdvancedProperties.setActionCommand("_Advanced_properties");
160
      btnAdvancedProperties.setName("btnAdvancedProperties");
161
      btnAdvancedProperties.setText("_Advanced_properties");
162
      jpanel1.add(btnAdvancedProperties,new CellConstraints(2,11,1,1,CellConstraints.RIGHT,CellConstraints.DEFAULT));
163

  
164
      jpanel1.add(createPanel1(),cc.xy(2,6));
165
      jpanel1.add(createPanel5(),cc.xy(2,9));
166
      jpanel1.add(createPanel8(),cc.xy(2,3));
167
      jpanel1.add(createPanel9(),cc.xy(2,12));
168
      addFillComponents(jpanel1,new int[]{ 1,3,4 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13 });
169
      return jpanel1;
170
   }
171

  
172
   public JPanel createPanel1()
173
   {
174
      JPanel jpanel1 = new JPanel();
175
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(0.5),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.5)","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE");
176
      CellConstraints cc = new CellConstraints();
177
      jpanel1.setLayout(formlayout1);
178

  
179
      lblTable.setName("lblTable");
180
      lblTable.setText("choose_table");
181
      jpanel1.add(lblTable,cc.xy(1,1));
182

  
183
      lblColumns.setName("lblColumns");
184
      lblColumns.setText("table_fields");
185
      jpanel1.add(lblColumns,cc.xy(3,1));
186

  
187
      lstColumns.setName("lstColumns");
188
      JScrollPane jscrollpane1 = new JScrollPane();
189
      jscrollpane1.setViewportView(lstColumns);
190
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
191
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
192
      jpanel1.add(jscrollpane1,cc.xywh(3,3,1,3));
193

  
194
      lstTables.setName("lstTables");
195
      JScrollPane jscrollpane2 = new JScrollPane();
196
      jscrollpane2.setViewportView(lstTables);
197
      jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
198
      jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
199
      jpanel1.add(jscrollpane2,cc.xy(1,5));
200

  
201
      jpanel1.add(createPanel2(),cc.xy(3,7));
202
      jpanel1.add(createPanel3(),cc.xy(1,3));
203
      jpanel1.add(createPanel4(),cc.xy(1,7));
204
      addFillComponents(jpanel1,new int[]{ 2 },new int[]{ 2,3,4,6,7 });
205
      return jpanel1;
206
   }
207

  
208
   public JPanel createPanel2()
209
   {
210
      JPanel jpanel1 = new JPanel();
211
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
212
      CellConstraints cc = new CellConstraints();
213
      jpanel1.setLayout(formlayout1);
214

  
215
      btnDeselectAllColumns.setActionCommand("Ninguno");
216
      btnDeselectAllColumns.setName("btnDeselectAllColumns");
217
      btnDeselectAllColumns.setOpaque(false);
218
      btnDeselectAllColumns.setText("_None");
219
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
220
      btnDeselectAllColumns.setBorder(emptyborder1);
221
      jpanel1.add(btnDeselectAllColumns,cc.xy(4,1));
222

  
223
      btnSelectAllColumns.setActionCommand("Todos");
224
      btnSelectAllColumns.setName("btnSelectAllColumns");
225
      btnSelectAllColumns.setOpaque(false);
226
      btnSelectAllColumns.setText("_All");
227
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
228
      btnSelectAllColumns.setBorder(emptyborder2);
229
      jpanel1.add(btnSelectAllColumns,cc.xy(2,1));
230

  
231
      addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1 });
232
      return jpanel1;
233
   }
234

  
235
   public JPanel createPanel3()
236
   {
237
      JPanel jpanel1 = new JPanel();
238
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
239
      CellConstraints cc = new CellConstraints();
240
      jpanel1.setLayout(formlayout1);
241

  
242
      btnTablesFilter.setActionCommand("...");
243
      btnTablesFilter.setName("btnTablesFilter");
244
      btnTablesFilter.setText("...");
245
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
246
      btnTablesFilter.setBorder(emptyborder1);
247
      jpanel1.add(btnTablesFilter,cc.xy(3,1));
248

  
249
      txtTablesFilter.setName("txtTablesFilter");
250
      jpanel1.add(txtTablesFilter,cc.xy(1,1));
251

  
252
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
253
      return jpanel1;
254
   }
255

  
256
   public JPanel createPanel4()
257
   {
258
      JPanel jpanel1 = new JPanel();
259
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
260
      CellConstraints cc = new CellConstraints();
261
      jpanel1.setLayout(formlayout1);
262

  
263
      btnCheckout.setActionCommand("...");
264
      btnCheckout.setIcon(loadImage("src/main/resources/org/gvsig/vcsgis/swing/impl/images/vcsgis-checkout.png"));
265
      btnCheckout.setName("btnCheckout");
266
      btnCheckout.setOpaque(false);
267
      btnCheckout.setToolTipText("_Checkout");
268
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
269
      btnCheckout.setBorder(emptyborder1);
270
      jpanel1.add(btnCheckout,cc.xy(2,1));
271

  
272
      addFillComponents(jpanel1,new int[]{ 1 },new int[]{ 1 });
273
      return jpanel1;
274
   }
275

  
276
   public JPanel createPanel5()
277
   {
278
      JPanel jpanel1 = new JPanel();
279
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE");
280
      CellConstraints cc = new CellConstraints();
281
      jpanel1.setLayout(formlayout1);
282

  
283
      lblName.setName("lblName");
284
      lblName.setText("_Name");
285
      jpanel1.add(lblName,cc.xy(1,2));
286

  
287
      txtName.setName("txtName");
288
      jpanel1.add(txtName,cc.xy(3,2));
289

  
290
      lblIdField.setName("lblIdField");
291
      lblIdField.setText("_Id_field");
292
      jpanel1.add(lblIdField,cc.xy(1,4));
293

  
294
      cboIdField.setName("cboIdField");
295
      jpanel1.add(cboIdField,cc.xy(3,4));
296

  
297
      lblGeometryField.setName("lblGeometryField");
298
      lblGeometryField.setText("_Geo_field");
299
      jpanel1.add(lblGeometryField,cc.xy(1,6));
300

  
301
      cboGeometryField.setName("cboGeometryField");
302
      jpanel1.add(cboGeometryField,cc.xy(3,6));
303

  
304
      lblProjection.setName("lblProjection");
305
      lblProjection.setText("_Projection");
306
      jpanel1.add(lblProjection,cc.xy(1,8));
307

  
308
      lblFilter.setName("lblFilter");
309
      lblFilter.setText("_Filter");
310
      jpanel1.add(lblFilter,cc.xy(1,10));
311

  
312
      jpanel1.add(createPanel6(),cc.xy(3,8));
313
      jpanel1.add(createPanel7(),cc.xy(3,10));
314
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,3,5,7,9 });
315
      return jpanel1;
316
   }
317

  
318
   public JPanel createPanel6()
319
   {
320
      JPanel jpanel1 = new JPanel();
321
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","FILL:DEFAULT:NONE");
322
      CellConstraints cc = new CellConstraints();
323
      jpanel1.setLayout(formlayout1);
324

  
325
      txtProjection.setName("txtProjection");
326
      jpanel1.add(txtProjection,cc.xy(1,1));
327

  
328
      btnProjection.setActionCommand("...");
329
      btnProjection.setName("btnProjection");
330
      btnProjection.setOpaque(false);
331
      btnProjection.setText("...");
332
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
333
      btnProjection.setBorder(emptyborder1);
334
      jpanel1.add(btnProjection,cc.xy(3,1));
335

  
336
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
337
      return jpanel1;
338
   }
339

  
340
   public JPanel createPanel7()
341
   {
342
      JPanel jpanel1 = new JPanel();
343
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
344
      CellConstraints cc = new CellConstraints();
345
      jpanel1.setLayout(formlayout1);
346

  
347
      txtFilter.setName("txtFilter");
348
      jpanel1.add(txtFilter,cc.xy(1,1));
349

  
350
      btnFilter.setActionCommand("...");
351
      btnFilter.setName("btnFilter");
352
      btnFilter.setOpaque(false);
353
      btnFilter.setText("...");
354
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
355
      btnFilter.setBorder(emptyborder1);
356
      jpanel1.add(btnFilter,cc.xy(3,1));
357

  
358
      btnFilterBookmarks.setActionCommand("...");
359
      btnFilterBookmarks.setName("btnFilterBookmarks");
360
      btnFilterBookmarks.setOpaque(false);
361
      btnFilterBookmarks.setText("...");
362
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
363
      btnFilterBookmarks.setBorder(emptyborder2);
364
      jpanel1.add(btnFilterBookmarks,cc.xy(7,1));
365

  
366
      btnFilterHistory.setActionCommand("...");
367
      btnFilterHistory.setName("btnFilterHistory");
368
      btnFilterHistory.setOpaque(false);
369
      btnFilterHistory.setText("...");
370
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
371
      btnFilterHistory.setBorder(emptyborder3);
372
      jpanel1.add(btnFilterHistory,cc.xy(5,1));
373

  
374
      addFillComponents(jpanel1,new int[]{ 2,4,6 },new int[0]);
375
      return jpanel1;
376
   }
377

  
378
   public JPanel createPanel8()
379
   {
380
      JPanel jpanel1 = new JPanel();
381
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE");
382
      CellConstraints cc = new CellConstraints();
383
      jpanel1.setLayout(formlayout1);
384

  
385
      cboWorkspaces.setName("cboWorkspaces");
386
      jpanel1.add(cboWorkspaces,cc.xy(2,1));
387

  
388
      txtRepositoryInfo.setBackground(new Color(236,233,216));
389
      txtRepositoryInfo.setEditable(false);
390
      txtRepositoryInfo.setName("txtRepositoryInfo");
391
      jpanel1.add(txtRepositoryInfo,cc.xy(2,5));
392

  
393
      btnInitWorkspace.setActionCommand("...");
394
      btnInitWorkspace.setIcon(loadImage("src/main/resources/org/gvsig/vcsgis/swing/impl/images/vcsgis-init-workspace.png"));
395
      btnInitWorkspace.setName("btnInitWorkspace");
396
      btnInitWorkspace.setOpaque(false);
397
      btnInitWorkspace.setText("_If_you_cant_find_the_layer_click_here_to_initialize_a_new_workspace");
398
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
399
      btnInitWorkspace.setBorder(emptyborder1);
400
      btnInitWorkspace.setHorizontalTextPosition(JButton.LEFT);
401
      jpanel1.add(btnInitWorkspace,new CellConstraints(2,3,1,1,CellConstraints.RIGHT,CellConstraints.DEFAULT));
402

  
403
      btnAddWorkspace.setActionCommand("...");
404
      btnAddWorkspace.setName("btnAddWorkspace");
405
      btnAddWorkspace.setOpaque(false);
406
      btnAddWorkspace.setText("...");
407
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
408
      btnAddWorkspace.setBorder(emptyborder2);
409
      jpanel1.add(btnAddWorkspace,cc.xy(4,1));
410

  
411
      addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1,2,3,4,5 });
412
      return jpanel1;
413
   }
414

  
415
   public JPanel createPanel9()
416
   {
417
      JPanel jpanel1 = new JPanel();
418
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:MIN(16PX;DEFAULT):NONE,CENTER:MIN(16PX;DEFAULT):NONE,CENTER:MIN(16PX;DEFAULT):NONE");
419
      CellConstraints cc = new CellConstraints();
420
      jpanel1.setLayout(formlayout1);
421

  
422
      lblStatusTitle.setName("lblStatusTitle");
423
      jpanel1.add(lblStatusTitle,cc.xy(1,1));
424

  
425
      pbStatus.setName("pbStatus");
426
      pbStatus.setValue(25);
427
      jpanel1.add(pbStatus,cc.xy(1,2));
428

  
429
      lblStatusMessages.setName("lblStatusMessages");
430
      jpanel1.add(lblStatusMessages,cc.xy(1,3));
431

  
432
      JLabel jlabel1 = new JLabel();
433
      jlabel1.setText(" ");
434
      jpanel1.add(jlabel1,cc.xy(2,1));
435

  
436
      JLabel jlabel2 = new JLabel();
437
      jlabel2.setText(" ");
438
      jpanel1.add(jlabel2,cc.xy(2,2));
439

  
440
      JLabel jlabel3 = new JLabel();
441
      jlabel3.setText(" ");
442
      jpanel1.add(jlabel3,cc.xy(2,3));
443

  
444
      addFillComponents(jpanel1,new int[0],new int[0]);
445
      return jpanel1;
446
   }
447

  
448
   /**
449
    * Initializer
450
    */
451
   protected void initializePanel()
452
   {
453
      setLayout(new BorderLayout());
454
      add(createPanel(), BorderLayout.CENTER);
455
   }
456

  
457

  
458
}
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.5/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.mainplugin/src/main/java/org/gvsig/vcsgis/app/addlayer/AbstractWizardVCSGis.java
1
package org.gvsig.vcsgis.app.addlayer;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Cursor;
5
import java.awt.Dimension;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ItemEvent;
8
import java.net.URL;
9
import java.util.ArrayList;
10
import java.util.Collection;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import javax.swing.ComboBoxModel;
15
import javax.swing.DefaultComboBoxModel;
16
import javax.swing.DefaultListModel;
17
import javax.swing.DefaultListSelectionModel;
18
import javax.swing.ImageIcon;
19
import javax.swing.JOptionPane;
20
import javax.swing.ListModel;
21
import javax.swing.ListSelectionModel;
22
import javax.swing.SwingUtilities;
23
import javax.swing.event.ChangeEvent;
24
import javax.swing.event.ListSelectionEvent;
25
import org.apache.commons.io.FilenameUtils;
26
import org.apache.commons.lang3.StringUtils;
27
import org.cresques.cts.IProjection;
28
import org.gvsig.app.gui.WizardPanel;
29
import org.gvsig.expressionevaluator.Expression;
30
import org.gvsig.expressionevaluator.ExpressionUtils;
31
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
32
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
33
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.DataTypes;
38
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
43
import org.gvsig.fmap.dal.swing.DALSwingLocator;
44
import org.gvsig.fmap.dal.swing.DataSwingManager;
45
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel;
46
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.i18n.I18nManager;
49
import org.gvsig.tools.swing.api.FilteredListController;
50
import org.gvsig.tools.swing.api.JListWithCheckbox;
51
import org.gvsig.tools.swing.api.ToolsSwingLocator;
52
import org.gvsig.tools.swing.api.ToolsSwingManager;
53
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
54
import org.gvsig.tools.swing.api.task.TaskStatusController;
55
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
56
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
57
import org.gvsig.tools.swing.api.windowmanager.Dialog;
58
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
59
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
60
import org.gvsig.tools.swing.icontheme.IconTheme;
61
import org.gvsig.tools.util.LabeledValue;
62
import org.gvsig.tools.util.LabeledValueImpl;
63
import org.gvsig.vcsgis.lib.VCSGisEntity;
64
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
65
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
66
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity;
67
import org.gvsig.vcsgis.swing.VCSGisJInitWorkspace;
68
import org.gvsig.vcsgis.swing.VCSGisSwingLocator;
69
import org.gvsig.vcsgis.swing.VCSGisSwingManager;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

  
73
/**
74
 *
75
 * @author jjdelcerro
76
 */
77
@SuppressWarnings("UseSpecificCatch")
78
public abstract class AbstractWizardVCSGis extends WizardPanel {
79

  
80
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWizardVCSGis.class);
81

  
82
    protected class TableInfo extends LabeledValueImpl<JDBCStoreParameters> {
83

  
84
        private final ListSelectionModel columnChecksModel;
85
        private FeatureType featureType;
86
        private int geomFieldSelected = -1;
87
        private int idFieldSelected = -1;
88
        private ComboBoxModel<String> idFieldComboModel;
89
        private ComboBoxModel<String> geomFieldComboModel;
90
        private List<FeatureAttributeDescriptor> attributeDescriptors;
91
        private ListModel<LabeledValue<FeatureAttributeDescriptor>> columnsListModel;
92
        private Expression filter;
93
        private IProjection projection;
94
        private boolean selected;
95
        private String documentName;
96

  
97
        public TableInfo(JDBCStoreParameters parameters) {
98
            super(getLabelForTable(parameters), parameters);
99
            this.columnChecksModel = new DefaultListSelectionModel();
100
            this.selected = false;
101
            this.documentName = parameters.getTable();
102
            this.projection = parameters.getCRS();
103
        }
104

  
105
        public String getDocumentName() {
106
            return this.documentName;
107
        }
108

  
109
        public void setDocumentName(String name) {
110
            this.documentName = name;
111
        }
112

  
113
        public boolean isSelected() {
114
            return selected;
115
        }
116

  
117
        public void setSelected(boolean selected) {
118
            this.selected = selected;
119
        }
120

  
121
        public ListSelectionModel getColumnChecksModel() {
122
            return this.columnChecksModel;
123
        }
124

  
125
        public JDBCStoreParameters getParameters() {
126
            JDBCStoreParameters p = this.getValue();
127
            StringBuilder fields = new StringBuilder();
128
            List<FeatureAttributeDescriptor> attributes = this.getAttributeDescriptors();
129
            boolean allSelected = true;
130
            for (int i = 0; i < attributes.size(); i++) {
131
                if (this.columnChecksModel.isSelectedIndex(i)) {
132
                    if (fields.length() > 0) {
133
                        fields.append(",");
134
                    }
135
                    fields.append(attributes.get(i).getName());
136
                    
137
                } else {
138
                    allSelected = false;
139
                }
140
            }
141
            if( !allSelected ) {
142
                p.setFields(fields.toString());
143
            }
144
            p.setPkFields(this.getFieldId());
145
            p.setCRS(this.getProjection());
146
            p.setDefaultGeometryField(this.getGeomField());
147
            if (!ExpressionUtils.isEmpty(this.filter)) {
148
                p.setBaseFilter(this.filter.toString());
149
            } else {
150
                p.setBaseFilter(null);
151
            }
152
            return p;
153
        }
154

  
155
        public void setProjection(IProjection projection) {
156
            this.projection = projection;
157
        }
158

  
159
        public IProjection getProjection() {
160
            return projection;
161
        }
162

  
163
        public String getFieldId() {
164
            if (this.idFieldSelected < 0) {
165
                return null;
166
            }
167
            return this.idFieldComboModel.getElementAt(this.idFieldSelected);
168
        }
169

  
170
        public String getGeomField() {
171
            if (this.geomFieldSelected < 0) {
172
                return null;
173
            }
174
            return this.geomFieldComboModel.getElementAt(this.geomFieldSelected);
175
        }
176

  
177
        public FeatureType getFeatureType() {
178
            if (this.featureType == null) {
179
                DataManager dataManager = DALLocator.getDataManager();
180
                try {
181
                    JDBCStoreParameters params = this.getValue();
182
                    FeatureStore store = (FeatureStore) dataManager.openStore(
183
                            params.getDataStoreName(),
184
                            params
185
                    );
186
                    this.featureType = store.getDefaultFeatureType();
187
                } catch (Exception ex) {
188
                    LOGGER.trace("Can't get feature type.",ex); // To allow set break points
189
                }
190
            }
191
            return this.featureType;
192
        }
193

  
194
        public ComboBoxModel getGeomFieldComboModel() {
195
            if (this.geomFieldComboModel == null) {
196
                DefaultComboBoxModel<String> geomModel = new DefaultComboBoxModel<>();
197
                geomModel.addElement(" ");
198
                int geomIndex = -1;
199
                int n = 1;
200
                for (FeatureAttributeDescriptor attr : this.getAttributeDescriptors()) {
201
                    if (geomIndex < 0 && attr.getType() == DataTypes.GEOMETRY) {
202
                        geomIndex = n;
203
                    }
204
                    int dataType = attr.getType();
205
                    if (dataType == DataTypes.GEOMETRY
206
                            || dataType == DataTypes.BYTEARRAY
207
                            || dataType == DataTypes.STRING) {
208
                        geomModel.addElement(attr.getName());
209
                        n++;
210
                    }
211
                }
212
                if (geomIndex < 0) {
213
                    geomIndex = 0;
214
                }
215
                this.geomFieldComboModel = geomModel;
216
                this.geomFieldSelected = geomIndex;
217
            }
218
            return this.geomFieldComboModel;
219
        }
220

  
221
        public int getGeomFieldSelected() {
222
            return this.geomFieldSelected;
223
        }
224

  
225
        public ComboBoxModel getIdFieldComboModel() {
226
            if (this.idFieldComboModel == null) {
227
                StringBuilder pkName = new StringBuilder();
228
                for (FeatureAttributeDescriptor attr : this.getAttributeDescriptors()) {
229
                    if (attr.isPrimaryKey()) {
230
                        if (!StringUtils.isBlank(pkName)) {
231
                            pkName.append(",");
232
                        }
233
                        pkName.append(attr.getName());
234
                    }
235
                }
236
                DefaultComboBoxModel<String> idsModel = new DefaultComboBoxModel<>();
237
                idsModel.addElement(" ");
238
                int idsIndex = -1;
239
                int n = 1;
240
                if (!StringUtils.isBlank(pkName) && StringUtils.contains(pkName, "/")) {
241
                    idsModel.addElement(pkName.toString());
242
                    idsIndex = n++;
243
                }
244
                for (FeatureAttributeDescriptor attr : getAttributeDescriptors()) {
245
                    if (idsIndex < 0 && attr.isPrimaryKey()) {
246
                        idsIndex = n;
247
                    }
248
                    idsModel.addElement(attr.getName());
249
                    n++;
250
                }
251
                if (idsIndex < 0) {
252
                    idsIndex = 0;
253
                }
254
                this.idFieldComboModel = idsModel;
255
                this.idFieldSelected = idsIndex;
256
            }
257
            return this.idFieldComboModel;
258
        }
259

  
260
        public List<FeatureAttributeDescriptor> getAttributeDescriptors() {
261
            if (this.attributeDescriptors == null) {
262
                List<FeatureAttributeDescriptor> attrs = new ArrayList<>();
263
                for (FeatureAttributeDescriptor attr : this.getFeatureType()) {
264
                    attrs.add(attr);
265
                }
266
                attrs.sort((FeatureAttributeDescriptor o1, FeatureAttributeDescriptor o2) -> 
267
                        o1.getName().compareTo(o2.getName())
268
                );
269
                this.columnChecksModel.setSelectionInterval(0, attrs.size());
270
                this.attributeDescriptors = attrs;
271
            }
272
            return this.attributeDescriptors;
273
        }
274

  
275
        public ListModel<LabeledValue<FeatureAttributeDescriptor>> getColumnsListModel() {
276
            if (this.columnsListModel == null) {
277
                DefaultListModel<LabeledValue<FeatureAttributeDescriptor>> model = new DefaultListModel<>();
278
                for (FeatureAttributeDescriptor attr : this.getAttributeDescriptors()) {
279
                    model.addElement(new LabeledValueImpl<>(
280
                            attr.getName() + " [" + attr.getDataTypeName() + "]",
281
                            attr
282
                    )
283
                    );
284
                }
285
                this.columnsListModel = model;
286
            }
287
            return this.columnsListModel;
288
        }
289

  
290
        public FeatureAttributeDescriptor getAttributeDescriptor(String attrName) {
291
            return this.getFeatureType().getAttributeDescriptor(attrName);
292
        }
293

  
294
        public int getIdFieldSelected() {
295
            return this.idFieldSelected;
296
        }
297

  
298
        public Expression getFilter() {
299
            return this.filter;
300
        }
301

  
302
        public void setFilter(Expression filter) {
303
            this.filter = filter;
304
        }
305

  
306
        private void setIdFieldSelected(int selectedIndex) {
307
            this.idFieldSelected = selectedIndex;
308
        }
309

  
310
        private void setGeomFieldSelected(int selectedIndex) {
311
            this.geomFieldSelected = selectedIndex;
312
        }
313

  
314
        private boolean hasValidValues() {
315
            if (this.getGeomFieldSelected() < 0 && requireGeometry()) {
316
                return false;
317
            }
318
            JDBCStoreParameters p = this.getParameters();
319
            try {
320
                p.validate();
321
                return true;
322
            } catch (ValidateDataParametersException ex) {
323
                return false;
324
            }
325
        }
326

  
327
    }
328

  
329
    private WizardVCSGisViewExtended view;
330
    private PickerController<VCSGisWorkspace> workspacePicker;
331
    private PickerController<IProjection> pickerProjection;
332
    private ExpressionPickerController pickerFilter;
333
    private JListWithCheckbox lwcTables;
334
    private JListWithCheckbox lwcColumns;
335
    protected Map<String, TableInfo> tablesInfo = null;
336
    protected FilteredListController tablesFilterController;
337
    private boolean processing;
338
    private TaskStatusController taskStatusController;
339
    
340
    public AbstractWizardVCSGis() {
341
        initComponents();
342
    }
343

  
344
    private void initComponents() {
345
        DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
346
        ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
347
        ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager();
348
        VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
349

  
350
        this.view = new WizardVCSGisViewExtended();
351
        
352
        TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager();
353
        
354
        this.taskStatusController = taskStatusManager.createTaskStatusController(
355
                this.view.lblStatusTitle,
356
                this.view.lblStatusMessages,
357
                this.view.pbStatus
358
        );
359
        this.taskStatusController.setShowCancelButton(false);
360
        this.taskStatusController.setShowRemoveTaskButton(false);
361
        this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
362

  
363
        toolsSwingManager.translate(this.view.btnDeselectAllColumns);
364
        toolsSwingManager.translate(this.view.btnSelectAllColumns);
365
        toolsSwingManager.translate(this.view.lblColumns);
366
        toolsSwingManager.translate(this.view.lblWorkspace);
367
        toolsSwingManager.translate(this.view.lblFilter);
368
        toolsSwingManager.translate(this.view.lblGeometryField);
369
        toolsSwingManager.translate(this.view.lblIdField);
370
        toolsSwingManager.translate(this.view.lblName);
371
        toolsSwingManager.translate(this.view.lblProjection);
372
        toolsSwingManager.translate(this.view.lblTable);
373
        toolsSwingManager.translate(this.view.cboWorkspaces);
374
        toolsSwingManager.translate(this.view.btnAddWorkspace);
375
        toolsSwingManager.translate(this.view.btnCheckout);
376
        toolsSwingManager.translate(this.view.btnAdvancedProperties);
377
        toolsSwingManager.translate(this.view.btnInitWorkspace);
378
        this.view.btnInitWorkspace.setText(toHTML(this.view.btnInitWorkspace.getText()));
379
        toolsSwingManager.translate(this.view.txtRepositoryInfo);
380

  
381
        toolsSwingManager.addClearButton(this.view.txtName);
382
        toolsSwingManager.setDefaultPopupMenu(this.view.txtName);
383
        
384
        this.view.btnInitWorkspace.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
385
        this.view.btnAddWorkspace.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
386
        this.view.btnSelectAllColumns.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
387
        this.view.btnDeselectAllColumns.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
388
        this.view.btnProjection.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
389
        this.view.btnFilter.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
390
        this.view.btnFilterBookmarks.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
391
        this.view.btnFilterHistory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
392
        this.view.btnAdvancedProperties.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
393
        this.view.btnAdvancedProperties.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
394

  
395
        
396
        
397

  
398
        this.lwcTables = toolsSwingManager.createJListWithCheckbox(
399
                this.view.lstTables
400
        );
401
        this.lwcColumns = toolsSwingManager.createJListWithCheckbox(
402
                this.view.lstColumns
403
        );
404
        
405
        this.workspacePicker = swingManager.createWorkspacePickerController(
406
            this.view.cboWorkspaces,
407
            this.view.btnAddWorkspace
408
        );
409

  
410
        this.workspacePicker.addChangeListener((ChangeEvent e) -> {
411
            doChangeWorkspace();
412
            setEditableTables(true);
413
        });
414

  
415
        
416
        this.pickerProjection = dataSwingManager.createProjectionPickerController(
417
                this.view.txtProjection,
418
                this.view.btnProjection
419
        );
420
        
421
        this.pickerFilter = expressionSwingManager.createExpressionPickerController(
422
                this.view.txtFilter,
423
                this.view.btnFilter,
424
                this.view.btnFilterBookmarks,
425
                this.view.btnFilterHistory
426
        );
427
        this.lwcTables.addListSelectionListener((ListSelectionEvent e) -> {
428
            doChangeTableSelected();
429
        });
430
        this.lwcTables.addChecksListener((ListSelectionEvent e) -> {
431
            doChangeTableSelected();
432
        });
433
        this.view.cboGeometryField.addItemListener((ItemEvent e) -> {
434
            if (e.getStateChange() == ItemEvent.SELECTED) {
435
                doChangeGeometryField();
436
            }
437
        });
438
        this.view.btnDeselectAllColumns.addActionListener((ActionEvent e) -> {
439
            doDeselectAllColumns();
440
        });
441
        this.view.btnSelectAllColumns.addActionListener((ActionEvent e) -> {
442
            doSelectAllColumns();
443
        });
444
        this.view.btnAdvancedProperties.addActionListener((ActionEvent e) -> {
445
            doShowAdvancedProperties();
446
        });
447
        this.view.btnInitWorkspace.addActionListener((ActionEvent e) -> {
448
            doShowInitWorkspace();
449
        });
450

  
451
        this.view.btnCheckout.addActionListener((ActionEvent e) -> {
452
            doCheckout();
453
        });
454

  
455
        
456
        
457
        this.tablesFilterController = toolsSwingManager.createFilteredListController(
458
                this.view.lstTables, 
459
                this.view.txtTablesFilter, 
460
                this.view.btnTablesFilter
461
        );
462

  
463
        this.clearTables();
464
        this.setEditableTables(false);
465

  
466
        this.setLayout(new BorderLayout());
467
        this.add(this.view, BorderLayout.CENTER);
468
        this.setPreferredSize(new Dimension(500, 400));
469
        doUpdateComponents();
470
    }
471

  
472
    protected abstract boolean requireGeometry();
473

  
474
    protected Collection<TableInfo> getTablesInformation() {
475
        this.updateTableInfoFromUI();
476
        if( this.tablesInfo == null ) {
477
            this.tablesInfo = new HashMap<>();
478
        }
479
        return this.tablesInfo.values();
480
    }
481
    
482
    private void doDeselectAllColumns() {
483
        TableInfo info = this.getCurrentTableInfo();
484
        if (info == null) {
485
            return;
486
        }
487
        info.getColumnChecksModel().clearSelection();
488
    }
489

  
490
    private void doSelectAllColumns() {
491
        TableInfo info = this.getCurrentTableInfo();
492
        if (info == null) {
493
            return;
494
        }
495
        info.getColumnChecksModel().setSelectionInterval(0, info.getAttributeDescriptors().size());
496
    }
497

  
498
    private void doShowAdvancedProperties() {
499
        final TableInfo info = this.getCurrentTableInfo();
500
        if (info == null) {
501
            return;
502
        }
503
        this.fetch(info);
504
        I18nManager i18n = ToolsLocator.getI18nManager();
505
        WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
506
        DataStoreParametersPanelManager paramsPanelManager = DALSwingLocator.getDataStoreParametersPanelManager();
507
        
508
        final DataStoreParametersPanel panel = paramsPanelManager.createDataStoreParametersPanel(info.getParameters());
509
        final Dialog dialog = winmgr.createDialog(
510
                panel.asJComponent(),
511
                i18n.getTranslation("_Connection_parameters"),
512
                null, 
513
                WindowManager_v2.BUTTONS_OK_CANCEL
514
        );
515
        dialog.addActionListener((ActionEvent e) -> {
516
            if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) {
517
                panel.fetchParameters(info.getParameters());
518
            }
519
        });
520
        dialog.show(WindowManager.MODE.DIALOG);
521
    }
522

  
523
    private void clearTables() {
524
        this.lwcTables.setModel(new DefaultListModel());
525
        this.lwcTables.getCheckedModel().clearSelection();
526
        this.clearTableConfig();
527
    }
528

  
529
    private void clearTableConfig() {
530
        this.lwcColumns.setModel(new DefaultListModel());
531
        this.lwcColumns.getCheckedModel().clearSelection();
532
        this.view.txtName.setText("");
533
        this.view.cboGeometryField.setModel(new DefaultComboBoxModel());
534
        this.view.cboIdField.setModel(new DefaultComboBoxModel());
535
        this.pickerProjection.set(null);
536
        this.pickerFilter.set(null);
537
    }
538

  
539
    private void setEditableTables(boolean enable) {
540
        this.view.lstTables.setEnabled(enable);
541
        this.setEditableTableConfig(enable);
542
        this.view.btnDeselectAllColumns.setEnabled(enable);
543
        this.view.btnSelectAllColumns.setEnabled(enable);
544
    }
545

  
546
    private void setEditableTableConfig(boolean enable) {
547
        this.view.lstColumns.setEnabled(enable);
548
        this.view.txtName.setEditable(enable);
549
        this.view.cboGeometryField.setEnabled(enable);
550
        this.view.cboIdField.setEnabled(enable);
551
        this.pickerProjection.setEditable(enable);
552
        this.pickerFilter.setEditable(enable);
553
        this.view.btnAdvancedProperties.setEnabled(enable);
554
    }
555

  
556
    private TableInfo getCurrentTableInfo() {
557
        VCSGisEntity rEntity = getRemoteEntity();
558
        if(rEntity == null){
559
            return null;
560
        }
561
        
562
        TableInfo xx = this.tablesInfo.get(rEntity.getEntityName());
563
        return xx;
564
    }
565

  
566
    private void doChangeGeometryField() {
567
        TableInfo info = this.getCurrentTableInfo();
568
        if (info == null) {
569
            return;
570
        }
571
        String attrName = (String) this.view.cboGeometryField.getSelectedItem();
572
        if (StringUtils.isBlank(attrName)) {
573
            return;
574
        }
575
        FeatureAttributeDescriptor attr = info.getAttributeDescriptor(attrName);
576
        IProjection srs = attr.getSRS();
577
        if (srs == null) {
578
            return;
579
        }
580
        this.pickerProjection.set(srs);
581
    }
582

  
583
    private void doChangeWorkspace() {
584
        if (notInSwingThreadInvokeLater(this::doChangeWorkspace)) {
585
            return;
586
        }
587

  
588
        I18nManager i18n = ToolsLocator.getI18nManager();
589
        VCSGisWorkspace workspace = workspacePicker.get();
590
        this.tablesFilterController.getModel().clear();
591
        if (workspace == null) {
592
            return;
593
        }
594

  
595
        this.view.txtRepositoryInfo.setText(workspace.getRepository().getLabel());
596

  
597
        this.tablesInfo = new HashMap<>();
598
        
599
        //Rellenamos la lista de entidades
600
        Thread task = new Thread(() -> {
601
            try {
602
                processing = true;
603
                doUpdateComponents();
604
                List<VCSGisEntity> repoEntities = workspace.getRepositoryEntities();
605
                doReloadEntitiesList(repoEntities);
606

  
607
            } catch (Exception e) {
608
                LOGGER.warn("_Cant_retrieve_entities_from_repository", e);
609
                ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
610
                dialogs.messageDialog(
611
                        i18n.getTranslation("_Cant_retrieve_entities_from_repository") + "\n" + e.getMessage(),
612
                        i18n.getTranslation("_Add_table"),
613
                        JOptionPane.WARNING_MESSAGE
614
                );
615

  
616
            } finally {
617
                processing = false;
618
                doUpdateComponents();
619
            }
620
        }, "VCSGisAddTable_getRepositoryEntities");
621

  
622
        processing = true;
623
        doUpdateComponents();
624
        task.start();
625
    }
626
    
627
    
628
//    private void doUpdateTables() {
629
//        JDBCServerExplorerParameters connection = this.pickerConnection.get();
630
//        if (connection == null) {
631
//            this.clearTables();
632
//            return;
633
//        }
634
//        DataManager dataManager = DALLocator.getDataManager();
635
//        DataServerExplorer explorer = null;
636
//        try {
637
//            explorer = dataManager.openServerExplorer(
638
//                    connection.getDataStoreName(),
639
//                    connection
640
//            );
641
//            List<TableInfo> parameters = new ArrayList<>();
642
//            for (DataStoreParameters params : explorer.list()) {
643
//                parameters.add(new TableInfo((JDBCStoreParameters) params));
644
//            }
645
//            parameters.sort((TableInfo o1, TableInfo o2) -> 
646
//                    o1.getLabel().compareTo(o2.getLabel())
647
//            );
648
//            this.tablesInfo = new HashMap<>();
649
//            DefaultListModel<TableInfo> model = new DefaultListModel<>();
650
//            for (TableInfo x : parameters) {
651
//                model.addElement(x);
652
//                this.tablesInfo.put(x.getDocumentName(), x);
653
//            }
654
//            this.lwcTables.setModel(model);
655
//            this.lwcTables.getCheckedModel().clearSelection();
656
//        } catch (Exception ex) {
657
//        } finally {
658
//            DisposeUtils.disposeQuietly(explorer);
659
//        }
660
//    }
661

  
662
    private void doChangeTableSelected() {
663
        if( notInSwingThreadInvokeLater(() -> {doChangeTableSelected();}) ) {
664
            return;
665
        }
666

  
667
        VCSGisEntity rEntity = getRemoteEntity();
668
        VCSGisWorkspaceEntity lEntity;
669
        lEntity = getWorkspace().getWorkspaceEntity(rEntity.getEntityName());
670
        if (lEntity == null) {
671
            this.clearTableConfig();
672
            int index = this.lwcTables.getSelectedIndex();
673
            this.lwcTables.getCheckedModel().removeIndexInterval(index, index);
674
        } else {
675
            TableInfo tableInfo = tablesInfo.get(rEntity.getEntityName());
676
            this.updateTableInfoFromUI();
677
            this.put(tableInfo);
678
        }
679
        showMessage("");
680
        doUpdateComponents();
681
    }
682
    
683
    private void updateTableInfoFromUI() {
684
         String previousTableName = this.view.txtName.getText();
685
         if (this.tablesInfo!=null && !this.tablesInfo.isEmpty()) {
686
         TableInfo previousInfo = this.tablesInfo.get(previousTableName);
687
            if (previousInfo != null) {
688
               this.fetch(previousInfo);
689
           }
690
        }
691
    }
692

  
693
    private void put(TableInfo tableInfo) {
694
        this.lwcColumns.setModel(tableInfo.getColumnsListModel());
695
        this.lwcColumns.setCheckedModel(tableInfo.getColumnChecksModel());
696

  
697
        this.view.cboGeometryField.setModel(tableInfo.getGeomFieldComboModel());
698
        this.view.cboGeometryField.setSelectedIndex(tableInfo.getGeomFieldSelected());
699

  
700
        this.view.cboIdField.setModel(tableInfo.getIdFieldComboModel());
701
        this.view.cboIdField.setSelectedIndex(tableInfo.getIdFieldSelected());
702

  
703
        this.pickerProjection.set(tableInfo.getProjection());
704
        this.pickerFilter.set(tableInfo.getFilter());
705
        this.view.txtName.setText(tableInfo.getDocumentName());
706
    }
707

  
708
    private void fetch(TableInfo tableInfo) {
709
        tableInfo.setIdFieldSelected(this.view.cboIdField.getSelectedIndex());
710
        tableInfo.setGeomFieldSelected(this.view.cboGeometryField.getSelectedIndex());
711
        tableInfo.setFilter(this.pickerFilter.get());
712
        tableInfo.setProjection(this.pickerProjection.get());
713
        tableInfo.setDocumentName(this.view.txtName.getText());
714
        int index = this.lwcTables.getSelectedIndex();
715
        tableInfo.setSelected(this.lwcTables.getCheckedModel().isSelectedIndex(index));
716
    }
717

  
718
    @Override
719
    public void initWizard() {
720
        I18nManager i18n = ToolsLocator.getI18nManager();
721
        setTabName(i18n.getTranslation("_VCSGis"));
722
    }
723

  
724
    @Override
725
    public boolean areSettingsValid() {
726
        if(processing){
727
            return false;
728
        }
729
        boolean hasInvalidValues = false;
730
        boolean hasSelectedTables = false;
731
        for (TableInfo tableInfo : this.getTablesInformation() ) {
732
            if (tableInfo.isSelected()) {
733
                hasSelectedTables = true;
734
                if (!tableInfo.hasValidValues()) {
735
                    hasInvalidValues = true;
736
                }
737
            }
738
        }
739
        return hasSelectedTables && !hasInvalidValues;
740
    }
741

  
742
    @Override
743
    public DataStoreParameters[] getParameters() {
744
        int sz = 0;
745
        for (TableInfo tableInfo : this.getTablesInformation() ) {
746
            if( tableInfo.isSelected() ) {
747
                sz++;
748
            }
749
        }
750
        if( sz == 0 ) {
751
            return null;
752
        }
753
        DataStoreParameters[] dbParameters = new DataStoreParameters[sz];
754
        int n = 0;
755
        for (TableInfo tableInfo : this.getTablesInformation() ) {
756
            if( tableInfo.isSelected() ) {
757
                dbParameters[n++] = tableInfo.getParameters();
758
            }
759
        }
760
        return dbParameters;
761
    }
762
    
763
    @Override
764
    public void execute() {
765
        executeWizard();
766
    }
767

  
768
    @Override
769
    public void close() {
770
        
771
    }
772
    
773
    protected void checkFinishable() {
774
        boolean finishable = areSettingsValid();
775
        callStateChanged(finishable);
776
    }
777
    
778
    private static String getLabelForTable(JDBCStoreParameters parameters) {
779
        String schema = parameters.getSchema();
780
        String tableName = parameters.getTable();
781
        if( StringUtils.isBlank(schema) ) {
782
            return tableName;
783
        }
784
        return schema +"."+tableName;
785
    }
786

  
787
    private void doUpdateComponents() {
788
        VCSGisEntity rEntity = getRemoteEntity();
789
        boolean enabled = (rEntity != null);
790
        VCSGisWorkspace ws = getWorkspace();
791
        if(enabled){
792
            VCSGisWorkspaceEntity lEntity;
793
            lEntity = ws.getWorkspaceEntity(rEntity.getEntityName());
794
            if (lEntity == null) {
795
                this.view.btnCheckout.setEnabled(!processing);
796
                this.setEditableTables(false);
797
            } else {
798
                this.view.btnCheckout.setEnabled(false);
799
                this.setEditableTables(!processing);
800
            }
801
        } else {
802
            this.view.btnCheckout.setEnabled(false);
803
            this.setEditableTables(false);
804
        }
805
//        this.lwcTables.setEnabled(!processing);
806
        this.tablesFilterController.setEnabled(!processing && ws != null);
807
        this.workspacePicker.setEnabled(!processing);
808
        this.view.btnInitWorkspace.setEnabled(!processing);
809
        this.view.txtRepositoryInfo.setEnabled(!processing && ws != null);
810
        this.view.btnAdvancedProperties.setEnabled(!processing && enabled);
811
        this.setVisibleStatus(processing);
812
        this.checkFinishable();
813
    }
814

  
815
    private void doShowInitWorkspace() {
816
        I18nManager i18nManager = ToolsLocator.getI18nManager();
817
        WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
818
        VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
819

  
820
        final VCSGisJInitWorkspace panelInitWorkspace = swingManager.createInitWorkspacePanel();
821
        final Dialog dialogInitWorkspace = winManager.createDialog(
822
                panelInitWorkspace.asJComponent(),
823
                i18nManager.getTranslation("_VCS_Initialize_workspace"),
824
                i18nManager.getTranslation("_VCS_Initialize_workspace"),
825
                WindowManager_v2.BUTTONS_OK_CANCEL
826
        );
827

  
828
        panelInitWorkspace.setDialog(dialogInitWorkspace);
829
        dialogInitWorkspace.setButtonLabel(
830
                WindowManager_v2.BUTTON_OK,
831
                i18nManager.getTranslation("_VCS_Initialize_workspace")
832
        );
833
        dialogInitWorkspace.addActionListener((ActionEvent e) -> {
834
            switch (dialogInitWorkspace.getAction()) {
835
                case WindowManager_v2.BUTTON_OK:
836
                    int r = panelInitWorkspace.initializeWorkspace();
837
                    if (r != 0) {
838
                        String message = "_Cant_initialize_workspace_{0}";
839

  
840
                        StringBuilder compoundMessage = new StringBuilder();
841
                        String[] messageArgs = new String[]{panelInitWorkspace.getWorkspaceName()};
842

  
843
                        compoundMessage.append(i18nManager.getTranslation(
844
                                message,
845
                                messageArgs
846
                        ));
847

  
848
                        ThreadSafeDialogsManager dialogsManager = ToolsSwingLocator.getThreadSafeDialogsManager();
849
                        dialogsManager.messageDialog(
850
                                compoundMessage.toString(),
851
                                i18nManager.getTranslation("_VCS_Initialize_workspace"),
852
                                JOptionPane.WARNING_MESSAGE
853
                        );
854
                    }
855

  
856
                    break;
857

  
858
            }
859
        });
860
        dialogInitWorkspace.show(WindowManager.MODE.DIALOG);
861
    }
862

  
863
    public VCSGisWorkspace getWorkspace() {
864
        return this.workspacePicker.get();
865
    }
866

  
867
    private void doReloadEntitiesList(List<VCSGisEntity> repoEntities) {
868
        if (notInSwingThreadInvokeLater(() -> {doReloadEntitiesList(repoEntities);}) ) {
869
            return;
870
        }
871
        
872
        I18nManager i18n = ToolsLocator.getI18nManager();
873
        VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager();
874
        try {
875
            this.tablesFilterController.getModel().clear();
876
            //Filtramos la entidades del repositorio que tienen geometrĂ­a (si no, no son capas)
877
            for (VCSGisEntity rEntity : repoEntities) {
878
                if(StringUtils.isNotBlank(rEntity.getGeometryFieldName()) || !requireGeometry()){
879
                    VCSGisWorkspaceEntity lEntity = getWorkspace().getWorkspaceEntity(rEntity.getEntityName());
880
                    this.tablesFilterController.getModel().addElement(
881
                            new LabeledValueImpl(
882
                                    swingManager.getHTMLColoredForEntity(lEntity, rEntity.getEntityName()),
883
                                    rEntity
884
                            )
885
                    );
886
                    if (lEntity != null) {
887
                        JDBCStoreParameters parameters = getWorkspace().getExplorer().get(lEntity.getEntityName());
888
                        this.tablesInfo.put(lEntity.getEntityName(), new TableInfo(parameters));
889
                    }
890
                }
891
            }
892
        } catch (Exception e) {
893
            LOGGER.warn("_Cant_update_layers_list", e);
894
            ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
895
            dialogs.messageDialog(
896
                    i18n.getTranslation("_Cant_update_layers_list")+"\n"+e.getMessage(), 
897
                    i18n.getTranslation("_Add_layer"), 
898
                    JOptionPane.WARNING_MESSAGE
899
            );
900
        }
901
    }
902

  
903
    private void doCheckout() {
904
        VCSGisWorkspace workspace = getWorkspace();
905
        if (workspace == null) {
906
            return;
907
        }
908
        ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
909
        I18nManager i18n = ToolsLocator.getI18nManager();
910
        VCSGisEntity rEntity = getRemoteEntity();
911
        VCSGisWorkspaceEntity lEntity = workspace.getWorkspaceEntity(rEntity.getEntityName());
912
        if (lEntity != null) {
913
            return;
914
        }
915
        Thread task = new Thread(() -> {
916
            try {
917
                processing = true;
918
                doUpdateComponents();
919

  
920
                showMessage(i18n.getTranslation("_Checking_out"));
921
                int res = workspace.checkout(rEntity.getEntityName(),
922
                        this.getTaskStatusController().getSimpleTaskStatus()
923
                );
924
                if (res != ERR_OK) {
925
                    LOGGER.warn("_Cant_checkout_table");
926
                    dialogs.messageDialog(
927
                            i18n.getTranslation("_Cant_checkout_table") + "\n" + workspace.getErrorMessage(res),
928
                            i18n.getTranslation("_Add_table"),
929
                            JOptionPane.WARNING_MESSAGE
930
                    );
931
                    return;
932
                }
933
                showMessage(i18n.getTranslation("_Checkout_finished"));
934
                JDBCStoreParameters parameters = getWorkspace().getExplorer().get(rEntity.getEntityName());
935
                this.tablesInfo.put(rEntity.getEntityName(), new TableInfo(parameters));
936
                doChangeTableSelected();
937
            } catch (Exception e) {
938
                LOGGER.warn("_Cant_add_table");
939
                dialogs.messageDialog(
940
                        i18n.getTranslation("_Cant_add_table") + "\n" + e.getMessage(),
941
                        i18n.getTranslation("_Add_table"),
942
                        JOptionPane.WARNING_MESSAGE
943
                );
944
            } finally {
945
                processing = false;
946
                doUpdateComponents();
947
            }
948
        }, "VCSGisAddTableCheckout");
949
        processing = true;
950
        doUpdateComponents();
951
        task.start();
952
    }
953

  
954
    private VCSGisEntity getRemoteEntity() {
955
        LabeledValue<VCSGisEntity> value = (LabeledValue<VCSGisEntity>) this.lwcTables.getSelectedValue();
956
        if(value == null){
957
            return null;
958
        }
959
        return value.getValue();
960
    }
961
    
962
    private void showMessage(String message) {
963
        if( notInSwingThreadInvokeLater(() -> {showMessage(message);}) ) {
964
            return;
965
        }
966
        this.view.lblStatusMessages.setText(message);
967
    }
968
    
969
        public boolean isProcessing() {
970
        return processing;
971
    }
972
    
973
    public void setVisibleStatus(boolean visible) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff