Revision 28183 branches/v10/extensions/extNormalization/src/org/gvsig/normalization/gui/NormPanelModel.java

View differences:

NormPanelModel.java
92 92
public class NormPanelModel implements INormPanelModel {
93 93

  
94 94
	private static final Logger log = PluginServices.getLogger();
95
	
95

  
96 96
	private List listeners = new ArrayList();
97 97
	private String fieldToNormalize;
98 98
	private String[] samples;
99 99
	private Patternnormalization pattern;
100 100
	private Table tab;
101 101
	private boolean inNewTable;
102
	private int selectedFieldInList = 0;
103 102
	private int contador = 1;
104 103
	private String[] relateNames;
105 104
	private List fileChains;
......
130 129
	 */
131 130
	private NormPanelModel() {
132 131
		initPattern();
133
	}	
132
	}
134 133

  
135 134
	/**
136 135
	 * This method fills the GUI sample table with the samples
......
155 154
	}
156 155

  
157 156
	/**
158
	 * This method updates the model of the names FieldList
159
	 * 
160
	 * @return list model
161
	 */
162
	public DefaultListModel updateListModel() {
163

  
164
		DefaultListModel dlmodel = new DefaultListModel();
165
		Element[] adr = this.pattern.getArrayElements();
166
		String name = "";
167
		for (int i = 0; i < adr.length; i++) {
168
			name = adr[i].getFieldname();
169
			dlmodel.add(i, name);
170
		}
171
		return dlmodel;
172
	}
173

  
174
	/**
175 157
	 * Run the process of normalization
176 158
	 * 
177 159
	 * @return process ok
......
203 185
			int index = tab.getSelectedFieldIndices().nextSetBit(0);
204 186

  
205 187
			if (!this.inNewTable) {
206
				// ONE TABLEE
207
				log.debug("New fields in the original table");
188
				// ONE TABLE
208 189
				normAction = new TableNormalization(source, index, pattern);
209 190
			} else {
210 191
				// JOINED TABLE
......
289 270

  
290 271
		contador++;
291 272
		int tam = pattern.getElements().size();
292
		Element elem = new Element();
273
		Element eleme = new Element();
293 274

  
294 275
		Fieldseparator fsep = new Fieldseparator();
295 276
		fsep.setSemicolonsep(true);
......
318 299
		} while (!isOkName);
319 300

  
320 301
		// validate the new field name
321
		elem.setFieldname(validateFieldName(nam));
322
		elem.setFieldseparator(fsep);
323
		elem.setInfieldseparators(getDefaultInfieldseparators());
324
		elem.setFieldtype(getDefaultNewFieldType());
325
		elem.setFieldwidth(0);
326
		elem.setImportfield(true);
302
		String vname = validateFieldName(nam);
303
		eleme.setFieldname(vname);
304
		eleme.setFieldseparator(fsep);
305
		eleme.setInfieldseparators(getDefaultInfieldseparators());
306
		eleme.setFieldtype(getDefaultNewFieldType());
307
		eleme.setFieldwidth(0);
308
		eleme.setImportfield(true);
327 309

  
328
		pattern.getElements().add(tam, elem);
310
		List elems = pattern.getElements();
311
		elems.add(tam, eleme);
329 312
	}
330 313

  
331 314
	/**
......
369 352
						null, "save_norm_pattern"), JOptionPane.YES_NO_OPTION);
370 353
				if (n == JOptionPane.YES_OPTION) {
371 354
					writeSaveFile(thefile);
372
					log.debug("overwrite file");
373 355
				} else if (n == JOptionPane.NO_OPTION) {
374
					log.debug("Don't save the file");
375 356
					update("INFO.filenotoverwrite");
376 357
				} else {
377
					log.debug("Don't save the file");
378 358
					update("INFO.filenotsave");
379 359
				}
380 360
			} else {
......
409 389

  
410 390
		if (returnval == JFileChooser.APPROVE_OPTION) {
411 391
			thefile = jfc.getSelectedFile();
412
			log.debug("file to open: " + thefile);
413 392
		} else {
414 393
			update("INFO.noload");
415 394
			return null;
......
425 404
			update("INFO.loadsuccess");
426 405
		} catch (FileNotFoundException e) {
427 406
			pat = null;
428
			update("INFO.filenotfound");
407
			update("ERROR.filenotfound");
429 408
			log.error("File not found", e);
430 409
		} catch (Exception e) {
431 410
			pat = null;
432
			update("INFO.parsingpatternxml");
433

  
411
			update("ERROR.parsingpatternxml");
412
			update("INFO.noformatok");
413
			update("INFO.noload");
434 414
			log.error("ERROR Parsing xml", e);
435 415
		}
436 416

  
......
552 532
	}
553 533

  
554 534
	/**
555
	 * This method gets the position of the selected element in the List of
556
	 * names
557
	 * 
558
	 * @return position in the list
559
	 */
560
	public int getSelectedFieldInList() {
561
		return selectedFieldInList;
562
	}
563

  
564
	/**
565
	 * This method set the position of the selected element in the List
566
	 * 
567
	 * @param selectedFieldInList
568
	 */
569
	public void setSelectedFieldInList(int selectedFieldInList) {
570
		this.selectedFieldInList = selectedFieldInList;
571
	}
572

  
573
	/**
574 535
	 * This method returns the fields names of the original table
575 536
	 * 
576 537
	 * @return list model
......
960 921
	 * @param file
961 922
	 */
962 923
	private void writeSaveFile(File thefile) {
963
		
924

  
964 925
		pattern.setPatternname(thefile.getName());
965 926

  
966 927
		FileWriter writer;
......
968 929
		try {
969 930
			storage = new StorageXML();
970 931
			pattern.getstate(storage);
971
			writer = new FileWriter(thefile);			
932
			writer = new FileWriter(thefile);
972 933
			storage.dump(writer);
973 934
			update("INFO.savesuccess");
974 935
			writer.close();
......
1040 1001
		update(evt);
1041 1002
	}
1042 1003

  
1004
	/**
1005
	 * @return the pattern
1006
	 */
1007
	public Patternnormalization getPattern() {
1008
		return pattern;
1009
	}
1010

  
1043 1011
}

Also available in: Unified diff