Revision 33290

View differences:

trunk/extensions/extCAD/src/com/iver/cit/gvsig/ExportTo.java
152 152
				writer.initialize(lyrDef);
153 153
			}
154 154

  
155
			 if(writer instanceof ShpWriter) {
156
				 String charSetName = prefs.get("dbf_encoding", DbaseFile.getDefaultCharset().toString());
157
				 if(lyrVect.getSource() instanceof VectorialFileAdapter) {
158
					 ((ShpWriter)writer).loadDbfEncoding(((VectorialFileAdapter)lyrVect.getSource()).getFile().getAbsolutePath(), Charset.forName(charSetName));
159
				 } else {
160
						Object s = lyrVect.getProperty("DBFFile");
161
						if(s != null && s instanceof String)
162
							((ShpWriter)writer).loadDbfEncoding((String)s, Charset.forName(charSetName));
163
				 }
164
			 }
155
			if(writer instanceof ShpWriter) {
156
				String charSetName = prefs.get("dbf_encoding", DbaseFile.getDefaultCharset().toString());
157
				if(lyrVect.getSource() instanceof VectorialFileAdapter) {
158
					((ShpWriter)writer).loadDbfEncoding(((VectorialFileAdapter)lyrVect.getSource()).getFile().getAbsolutePath(), Charset.forName(charSetName));
159
				} else {
160
					Object s = lyrVect.getProperty("DBFFile");
161
					if(s != null && s instanceof String)
162
						((ShpWriter)writer).loadDbfEncoding((String)s, Charset.forName(charSetName));
163
				}
164
			}
165 165

  
166 166
			// Creamos la tabla.
167 167
			writer.preProcess();
......
203 203
			} else {
204 204
				int counter = 0;
205 205
				for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet
206
						.nextSetBit(i + 1)) {
206
				.nextSetBit(i + 1)) {
207 207
					if (isCanceled())
208 208
						break;
209 209
					IGeometry geom = va.getShape(i);
......
243 243
			va.stop();
244 244
			if (reader != null && !isCanceled()){
245 245
				int res = JOptionPane.showConfirmDialog(
246
					(JComponent) PluginServices.getMDIManager().getActiveWindow()
247
					, PluginServices.getText(this, "insertar_en_la_vista_la_capa_creada"),
248
					PluginServices.getText(this,"insertar_capa"),
249
					JOptionPane.YES_NO_OPTION);
246
						(JComponent) PluginServices.getMDIManager().getActiveWindow()
247
						, PluginServices.getText(this, "insertar_en_la_vista_la_capa_creada"),
248
						PluginServices.getText(this,"insertar_capa"),
249
						JOptionPane.YES_NO_OPTION);
250 250

  
251 251
				if (res == JOptionPane.YES_OPTION)
252 252
				{
......
305 305
	 */
306 306
	public void execute(String actionCommand) {
307 307
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
308
				.getActiveWindow();
308
		.getActiveWindow();
309 309

  
310 310
		if (f instanceof View) {
311 311
			View vista = (View) f;
......
319 319
					if (actives[i] instanceof FLyrVect) {
320 320
						FLyrVect lv = (FLyrVect) actives[i];
321 321
						int numSelec = lv.getRecordset().getSelection()
322
								.cardinality();
322
						.cardinality();
323 323
						if (numSelec > 0) {
324 324
							int resp = JOptionPane.showConfirmDialog(
325 325
									(Component) PluginServices.getMainFrame(),
326 326
									PluginServices.getText(this,"se_van_a_guardar_") + numSelec
327
											+ PluginServices.getText(this,"features_desea_continuar"),
327
									+ PluginServices.getText(this,"features_desea_continuar"),
328 328
									PluginServices.getText(this,"export_to"), JOptionPane.YES_NO_OPTION);
329 329
							if (resp != JOptionPane.YES_OPTION) {
330 330
								continue;
......
350 350

  
351 351
	public void saveToPostGIS(MapContext mapContext, FLyrVect layer){
352 352
		try {
353
			String tableName = JOptionPane.showInputDialog(PluginServices
354
					.getText(this, "intro_tablename"));
353
			String tableName = null;
354
			boolean tableNameNotFilled = true;
355 355

  
356
			// show the input tableName dialog until user cancel or enter a valid identifier
357
			do {
358
				tableName = JOptionPane.showInputDialog(PluginServices.getText(this, "intro_tablename"));
359
				if (tableName == null) {
360
					return;
361
				}
362
				tableNameNotFilled = (tableName.trim().length() == 0);
363
				if (tableNameNotFilled) {
364
					JOptionPane.showMessageDialog(null,
365
							PluginServices.getText(this,"intro_tablename_blank"),
366
							PluginServices.getText(this,"warning"),
367
							JOptionPane.WARNING_MESSAGE);
368
				}
369
			} while (tableNameNotFilled);
370

  
356 371
			CharSequence seq = "\\/=.:,;??*{}?$%&()@#|!?";
357 372
			for (int i = 0; i < seq.length(); i++) {
358 373
				char c = seq.charAt(i);
......
362 377
				}
363 378
			}
364 379

  
365
			if (tableName == null)
366
				return;
367
			tableName = tableName.toLowerCase();
368

  
369 380
			DlgConnection dlg = new DlgConnection(new String[]{"PostGIS JDBC Driver"});
370 381
			dlg.setModal(true);
371 382
			dlg.setVisible(true);
......
398 409

  
399 410
			FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
400 411
			dbLayerDef.setFieldsDesc(fieldsDescrip);
401
	        // Creamos el driver. OJO: Hay que a?adir el campo ID a la
402
	        // definici?n de campos.
412
			// Creamos el driver. OJO: Hay que a?adir el campo ID a la
413
			// definici?n de campos.
403 414

  
404 415
			if (originalDef != null){
405 416
				dbLayerDef.setFieldID(originalDef.getFieldID());
......
429 440
			// if id field dosen't exist we add it
430 441
			if (findFileByName(fieldsDescrip,dbLayerDef.getFieldID()) == -1)
431 442
			{
432
	        	int numFieldsAnt = fieldsDescrip.length;
433
	        	FieldDescription[] newFields = new FieldDescription[dbLayerDef.getFieldsDesc().length + 1];
434
	            for (int i=0; i < numFieldsAnt; i++)
435
	            {
436
	            	newFields[i] = fieldsDescrip[i];
437
	            }
438
	            newFields[numFieldsAnt] = new FieldDescription();
439
	            newFields[numFieldsAnt].setFieldDecimalCount(0);
440
	            newFields[numFieldsAnt].setFieldType(Types.INTEGER);
441
	            newFields[numFieldsAnt].setFieldLength(7);
442
	            newFields[numFieldsAnt].setFieldName("gid");
443
	            dbLayerDef.setFieldsDesc(newFields);
443
				int numFieldsAnt = fieldsDescrip.length;
444
				FieldDescription[] newFields = new FieldDescription[dbLayerDef.getFieldsDesc().length + 1];
445
				for (int i=0; i < numFieldsAnt; i++)
446
				{
447
					newFields[i] = fieldsDescrip[i];
448
				}
449
				newFields[numFieldsAnt] = new FieldDescription();
450
				newFields[numFieldsAnt].setFieldDecimalCount(0);
451
				newFields[numFieldsAnt].setFieldType(Types.INTEGER);
452
				newFields[numFieldsAnt].setFieldLength(7);
453
				newFields[numFieldsAnt].setFieldName("gid");
454
				dbLayerDef.setFieldsDesc(newFields);
444 455

  
445
	        }
456
			}
446 457

  
447 458
			// all fields to lowerCase
448 459
			FieldDescription field;
......
566 577
		} else {
567 578
			int counter = 0;
568 579
			for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet
569
					.nextSetBit(i + 1)) {
580
			.nextSetBit(i + 1)) {
570 581
				IGeometry geom = va.getShape(i);
571 582

  
572 583
				progress.setProgress(counter++);
......
604 615
				newFile = new File(path);
605 616

  
606 617
				DxfWriter writer = (DxfWriter) LayerFactory.getWM().getWriter(
607
						"DXF Writer");
618
				"DXF Writer");
608 619
				SHPLayerDefinition lyrDef = new SHPLayerDefinition();
609 620
				SelectableDataSource sds = layer.getRecordset();
610 621
				FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
......
663 674
				FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
664 675

  
665 676
				if (layer.getShapeType() == FShape.MULTI) // Exportamos a 3
666
				// ficheros
677
					// ficheros
667 678
				{
668 679
					ShpWriter writer1 = (ShpWriter) LayerFactory.getWM().getWriter(
669 680
					"Shape Writer");
......
724 735
					writeMultiFeatures(mapContext,layer, writers, drivers);
725 736
				} else {
726 737
					ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter(
727
						"Shape Writer");
738
					"Shape Writer");
728 739
					loadEnconding(layer, writer);
729 740
					IndexedShpDriver drv = getOpenShpDriver(newFile);
730 741
					SHPLayerDefinition lyrDef = new SHPLayerDefinition();
......
736 747
					writer.initialize(lyrDef);
737 748
					// CODIGO PARA EXPORTAR UN SHP A UN CHARSET DETERMINADO
738 749
					// ES UTIL PARA QUE UN DBF SE VEA CORRECTAMENTE EN EXCEL, POR EJEMPLO
739
//					Charset resul = (Charset) JOptionPane.showInputDialog((Component)PluginServices.getMDIManager().getActiveWindow(),
740
//								PluginServices.getText(ExportTo.class, "select_charset_for_writing"),
741
//								"Charset", JOptionPane.QUESTION_MESSAGE, null,
742
//								Charset.availableCharsets().values().toArray(),
743
//								writer.getCharsetForWriting().displayName());
744
//					if (resul == null)
745
//						return;
746
//					Charset charset = resul;
747
//					writer.setCharsetForWriting(charset);
750
					//					Charset resul = (Charset) JOptionPane.showInputDialog((Component)PluginServices.getMDIManager().getActiveWindow(),
751
					//								PluginServices.getText(ExportTo.class, "select_charset_for_writing"),
752
					//								"Charset", JOptionPane.QUESTION_MESSAGE, null,
753
					//								Charset.availableCharsets().values().toArray(),
754
					//								writer.getCharsetForWriting().displayName());
755
					//					if (resul == null)
756
					//						return;
757
					//					Charset charset = resul;
758
					//					writer.setCharsetForWriting(charset);
748 759
					writeFeatures(mapContext, layer, writer, drv);
749 760

  
750 761
				}
......
811 822
	 */
812 823
	public boolean isVisible() {
813 824
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
814
				.getActiveWindow();
825
		.getActiveWindow();
815 826

  
816 827
		if (f == null) {
817 828
			return false;
......
823 834
	}
824 835

  
825 836
	private int findFileByName(FieldDescription[] fields, String fieldName){
826
        for (int i=0; i < fields.length; i++)
827
        {
828
        	FieldDescription f = fields[i];
829
        	if (f.getFieldName().equalsIgnoreCase(fieldName))
830
        	{
831
        		return i;
832
        	}
833
        }
837
		for (int i=0; i < fields.length; i++)
838
		{
839
			FieldDescription f = fields[i];
840
			if (f.getFieldName().equalsIgnoreCase(fieldName))
841
			{
842
				return i;
843
			}
844
		}
834 845

  
835 846
		return -1;
836 847

  

Also available in: Unified diff