Révision 1408

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/preferences/PluginPreferencesManager.java (revision 1408)
78 78
	/**
79 79
	 * the XXXPreferences.java preferences keys
80 80
	 */
81
	TreeSet<String> preferenceKeys = new TreeSet<String>();
81
	TreeMap<String, Object> preferenceKeys = new TreeMap<String, Object>();
82 82
	
83 83
	protected TreeMap<String, Object> names = new TreeMap<String, Object>();
84
	
85
	protected TreeMap<String, Object> defaultValues = new TreeMap<String, Object>();
86 84

  
87 85
	/**
88 86
	 * plugin.xml file -> contains eventually keys
......
194 192
							System.out.println("PluginPreferencesManager.PluginPreferencesManager(): messages key: " + line2 + " added.");
195 193
						}
196 194
						//System.out.println("+K='"+key+"'");
197
						preferenceKeys.add(key);
195
						preferenceKeys.put(key, null);
198 196
						names.put(key, name);
199 197
					}
200 198
				} else if (line2.startsWith("preferences.put")) {
......
215 213
						if(debug)	{
216 214
							System.out.println("PluginPreferencesManager.PluginPreferencesManager(): messages key: " + line2 + " added.");
217 215
						}
218
						defaultValues.put(key, value);
216
						preferenceKeys.put(key, value);
219 217
					}
220 218
				}
221 219

  
......
406 404
	}
407 405

  
408 406
	public void put(String key, String defaultValue) {
409
		preferenceKeys.add(key);
410
		defaultValues.put(key, defaultValue);
407
		preferenceKeys.put(key, defaultValue);
411 408
	}
412 409

  
413 410
	public Object getDefaultValue(String key) {
414
		return defaultValues.get(key);
411
		return preferenceKeys.get(key);
415 412
	}
416 413

  
417
	public TreeSet<String> getPreferenceKeys() {
414
	public TreeMap<String, Object> getPreferenceKeys() {
418 415
		return preferenceKeys;
419 416
	}
420 417

  
......
535 532
	public void summary() {
536 533
		String name = getPreferenceClassName();
537 534
		if (name == null || name.length() == 0) return;
538
		System.out.println(name+" "+preferenceKeys.size()+" preferences");
539
//		System.out.println(preferenceKeys);
540
//		System.out.println(names);
541
//		System.out.println(defaultValues);
542
		for (String key : preferenceKeys) {
543
			System.out.println(key+"\t"+names.get(key)+"\t"+defaultValues.get(key));
535
		
536
		for (String key : preferenceKeys.keySet()) {
537
			System.out.println(name+"\t"+key+"\t"+names.get(key)+"\t"+preferenceKeys.get(key));
544 538
		}
545 539
	}
546 540

  
......
601 595
	 */
602 596
	public void renameKey(String oldName, String newName) {
603 597

  
604
		if (!preferenceKeys.contains(oldName)) {
598
		if (!preferenceKeys.containsKey(oldName)) {
605 599
			System.err.println("PluginPreferencesManager.renameKey(): key=" + oldName + " not found, aborting renaming to " + newName + ".");
606 600
			return;
607 601
		}
......
614 608
			return;
615 609
		}
616 610

  
611
		preferenceKeys.put(newName, preferenceKeys.get(oldName));
617 612
		preferenceKeys.remove(oldName);
618
		preferenceKeys.add(newName);
619 613

  
620
		defaultValues.put(newName, defaultValues.get(oldName));
621
		defaultValues.remove(oldName);
622

  
623 614
		//System.out.println("M+ "+oldName+" -> "+newName);
624 615
		keyModifications.put(oldName, newName);
625 616
	}
......
630 621
	 * @param key the local name of the key to remove
631 622
	 */
632 623
	public void removeKey(String key) {
633
		if (!preferenceKeys.contains(key)) {
624
		if (!preferenceKeys.containsKey(key)) {
634 625
			System.err.println("PluginPreferencesManager.removeKey(): key=" + key + " not found, aborting removing.");
635 626
			return;
636 627
		}
637 628

  
638 629
		preferenceKeys.remove(key);
639
		defaultValues.remove(key);
640 630

  
641 631
		keyModifications.remove(key); // if any modifications was done
642 632
	}
......
645 635
		String key = NormalizeKeys.normalize(defaultPreference);
646 636
		String newKey = ""+key;
647 637
		int c = 1;
648
		while (preferenceKeys.contains(newKey)) {
638
		while (preferenceKeys.containsKey(newKey)) {
649 639
			newKey = key+"_"+(c++);
650 640
		}
651 641

  
652
		preferenceKeys.add(newKey);
642
		preferenceKeys.put(newKey, defaultPreference);
653 643
	}
654 644

  
655 645
	/**
......
664 654
		return file2lang;
665 655
	}
666 656

  
667
	public TreeMap<String, Object> getDefaults() {
668
		return defaultValues;
669
	}
670

  
671 657
	/**
672 658
	 * Gets the project root directory.
673 659
	 * @return the projectDirectory
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/preferences/WorkspacePreferencesManager.java (revision 1408)
131 131
			pluginsPreferencesPerProject.put(project, preferences);
132 132

  
133 133
			if (debug) {
134
				System.out.println(project + "=" + preferences.getPreferenceKeys().size() + " preferences and "+preferences.getDefaults().size()+" default values.");
134
				System.out.println(project + "=" + preferences.getPreferenceKeys().size() + " preferences.");
135 135
			}
136 136
			//			}
137 137
		}
......
310 310
	 */
311 311
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
312 312
		WorkspacePreferencesManager wmm = new WorkspacePreferencesManager();
313
		for (PluginPreferencesManager preferences : wmm.getPluginPreferences().values()) {
313
		wmm.summary();
314
		//wmm.saveKeyModificationsInSources();
315
	}
316

  
317
	private void summary() {
318
		System.out.println("CLASS\tVARIABLE\tIDENTIFIER\tDEFAULT VALUE");
319
		ArrayList<File> files = new ArrayList<File>(this.getPluginPreferences().keySet());
320
		Collections.sort(files, new Comparator<File>() {
321

  
322
			@Override
323
			public int compare(File o1, File o2) {
324
				// TODO Auto-generated method stub
325
				return o1.getName().compareTo(o2.getName());
326
			}
327
		});
328
		for (File p : files) {
329
			PluginPreferencesManager preferences = this.getPluginPreferences().get(p);
314 330
			preferences.summary();
315 331
		}
316
		//wmm.saveKeyModificationsInSources();
317 332
	}
318 333
}

Formats disponibles : Unified diff