Révision 3026

tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 3026)
39 39
import org.eclipse.core.commands.ExecutionException;
40 40
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
41 41
import org.eclipse.jface.viewers.IStructuredSelection;
42
import org.eclipse.jface.window.Window;
42 43
import org.eclipse.osgi.util.NLS;
43 44
import org.eclipse.swt.widgets.Shell;
44 45
import org.eclipse.ui.IWorkbenchPart;
......
393 394
	 * @param sEndTime String in "sec.msec" or "hh:mm:ss" format
394 395
	 * @param editor
395 396
	 * @param shell
396
	 * @return
397
	 * @return the media editor or null if an error occurred
397 398
	 */
398 399
	public static Object backToMedia(CQPCorpus corpus, String textid, String sStartTime, String sEndTime, IWorkbenchPart editor, Shell shell) {
399 400
		
......
411 412
		String media_index = commandPreferences.get(BackToMediaPreferences.MEDIA_INDEX_NODE, alternative);
412 413
		
413 414
		try {
414
			
415 415
			Log.fine(MessagesMP.BackToMedia_7 + textid);
416 416
			
417 417
			File binDir = corpus.getProject().getProjectDirectory();
......
448 448
						dialog.setUsername(secured_media_login);
449 449
						dialog.setTitle("You must authenticate to access the media file");
450 450
						dialog.setDetails(NLS.bind(TXMUIMessages.loginToP0, new URL(media_directory).getHost()));
451
						if (dialog.open() == dialog.OK) {
451
						if (dialog.open() == Window.OK) {
452 452
							System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, dialog.getUser());
453 453
							System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword());
454 454
						}
455 455
						else {
456
							System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "");
457
							System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "");
456
							// System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "");
457
							// System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "");
458 458
							return null;
459 459
						}
460 460
					}
......
559 559
			if (path != null) {
560 560
				vlcEditor.setPartName(textid);
561 561
			}
562
			return null;
562
			return vlcEditor;
563 563
			
564 564
		}
565 565
		catch (Exception e2) {
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/editors/imports/sections/AnnotationSection.java (revision 3026)
19 19
public class AnnotationSection extends ImportEditorSection {
20 20
	
21 21
	private static final int SECTION_SIZE = 1;
22
	
22 23
	public static final String DEFAULTNAMESUFFIX = "KR";
23 24
	
24 25
	Text nameText;
25 26
	
26 27
	public AnnotationSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
27
		super(toolkit2, form2, parent, style);
28

  
28
		super(toolkit2, form2, parent, style, "annotation");
29
		
29 30
		this.section.setText("Annotation");
30 31
		TableWrapLayout layout = new TableWrapLayout();
31 32
		layout.makeColumnsEqualWidth = true;
32 33
		this.section.setLayout(layout);
33 34
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
34 35
		this.section.setEnabled(false);
35

  
36
		
36 37
		this.section.addExpansionListener(new ExpansionAdapter() {
38
			
37 39
			@Override
38
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
40
			public void expansionStateChanged(ExpansionEvent e) {
41
				form.layout(true);
42
			}
39 43
		});
40

  
41
		//filesection.setDescription("Select how to find source files");
44
		
45
		// filesection.setDescription("Select how to find source files");
42 46
		Composite sectionClient = toolkit.createComposite(this.section);
43 47
		TableWrapLayout slayout = new TableWrapLayout();
44 48
		slayout.makeColumnsEqualWidth = false;
45 49
		slayout.numColumns = 2;
46 50
		sectionClient.setLayout(slayout);
47 51
		this.section.setClient(sectionClient);
48

  
52
		
49 53
		Label l = toolkit.createLabel(sectionClient, "Knowledge repository name", SWT.WRAP);
50 54
		l.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
51

  
55
		
52 56
		nameText = new Text(sectionClient, SWT.BORDER);
53 57
	}
54

  
58
	
55 59
	@Override
56 60
	public void update(Project project) {
57 61
		if (this.section.isDisposed()) return;
58 62
		if (project == null) return;
59 63
		
60
//		List<String> values = KRAnnotationEngine.getKnowledgeRepositoryNames(project);
61
//		
62
//		String value = project.getName()+DEFAULTNAMESUFFIX;
63
//		if (values.size() > 0) {
64
//			value = values.get(0);
65
//		}
66
//		nameText.setText(value);
64
		// List<String> values = KRAnnotationEngine.getKnowledgeRepositoryNames(project);
65
		//
66
		// String value = project.getName()+DEFAULTNAMESUFFIX;
67
		// if (values.size() > 0) {
68
		// value = values.get(0);
69
		// }
70
		// nameText.setText(value);
67 71
	}
68

  
72
	
69 73
	@Override
70 74
	public boolean save(Project project) {
71 75
		if (!this.section.isDisposed()) {
72 76
			String value = nameText.getText();
73
						
77
			
74 78
			return true;
75 79
		}
76 80
		return false;
77 81
	}
78

  
82
	
79 83
	@Override
80 84
	public boolean checkFields() {
81 85
		return true;
82 86
	}
83

  
87
	
84 88
	@Override
85 89
	public int getSectionSize() {
86 90
		return SECTION_SIZE;
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/pager.groovy (revision 3026)
76 76
	boolean firstWord = true
77 77
	
78 78
	boolean paginate = true
79
	boolean paginateSections = true
79 80
	boolean enableCollapsibles = false;
80 81
	boolean displayLocutors = true;
81 82
	
......
173 174
		this.txtname = txtname;
174 175
		this.wordmax = project.getEditionDefinition("default").getWordsPerPage();
175 176
		this.paginate = project.getEditionDefinition("default").getPaginateEdition()
177
		this.paginateSections = project.getImportParameters().getBoolean("create_section_pages", true)
176 178
		this.enableCollapsibles = project.getEditionDefinition("default").getEnableCollapsibleMetadata();
177 179
		this.displayLocutors = project.getImportParameters().getBoolean("display_locutors", true);
178 180
		
......
422 424
							writer.writeAttribute("id", ""+nbBreak);
423 425
							writer.writeCharacters("\n");
424 426
						
425
							if (paginate) {
427
							if (paginate && paginateSections) {
426 428
								pages << new File(defaultDir, "${txtname}_${nbBreak}.html")
427 429
								indexes << wordid
428 430
							}
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/transcriber/transcriberLoader.groovy (revision 3026)
129 129
		}
130 130
	}
131 131
}
132
File propertyFile = new File(srcDir, "import.properties")//default
133
Properties props = new Properties();
134
//String[] metadatasToKeep;
135
if (propertyFile.exists() && propertyFile.canRead()) {
136
	FileInputStream input = new FileInputStream(propertyFile);
137
	props.load(input);
138
	input.close();
139

  
140
	if (props.getProperty("indexInterviewer") != null)
141
		indexInterviewer = Boolean.parseBoolean(props.get("indexInterviewer").toString());
142
	if (props.getProperty("ignoreTranscriberMetadata") != null)
143
		ignoreTranscriberMetadata = Boolean.parseBoolean(props.get("ignoreTranscriberMetadata").toString());
144
//	if (props.getProperty("metadataList") != null)
145
//		metadatasToKeep = props.get("metadataList").toString().split("|");
146
//	if (props.getProperty("csvHeaderNumber") != null)
147
//		csvHeaderNumber = props.get("csvHeaderNumber").toString().split("|");
148
	//if (props.getProperty("includeComments") != null)
149
	//	includeComments = props.get("includeComments").toString();
150

  
151
	println "import properties: "
152
	println " indexInterviewer: "+indexInterviewer
153
	println " ignoreTranscriberMetadata: "+ignoreTranscriberMetadata
154
//	println " metadataToKeep: "+metadatasToKeep
155
//	println " ignored csvHeaderSize: "+csvHeaderNumber
156
	//println " includeComments: "+includeComments
157
}
158 132

  
159

  
133
// retrieve import specifiq parameters
134
indexInterviewer = project.getImportParameters().getBoolean("indexInterviewer", true)
135
ignoreTranscriberMetadata = project.getImportParameters().getBoolean("ignoreTranscriberMetadata", true)
160 136

  
161

  
162

  
163 137
try {
164 138
	if (!update) {
165 139
		// Apply XSL
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/SegmentTRSInSectionFromMarkerMacro.groovy (revision 3026)
1
package org.txm.macro.transcription
2

  
3
import java.nio.charset.Charset
4

  
5
import java.time.LocalTime
6
import java.time.format.DateTimeFormatter
7
import org.txm.utils.*
8
import org.txm.utils.logger.*
9

  
10
@Field @Option(name="trsDirectory", usage="Dossier qui contient les fichiers TRS", widget="Folder", required=true, def="")
11
File trsDirectory;
12

  
13
@Field @Option(name="newSectionMarker", usage="The marker, spaces included", widget="String", required=true, def=" *#")
14
def newSectionMarker
15

  
16
if (!ParametersDialog.open(this)) return;
17

  
18
if (!trsDirectory.exists()) {
19
	println "$trsDirectory not found"
20
	return
21
}
22

  
23
File outputDirectory = new File(trsDirectory, "out")
24
println "Writing result to $outputDirectory..."
25

  
26
dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_TIME
27
def strTotime(def str) {
28
	if (str.lastIndexOf(":") == -1) {
29
		return null
30
	}
31
	
32
	bonusFrame = Integer.parseInt(str.substring(str.lastIndexOf(":")+1))
33
	//if (str.contains("135475")) println "ERROR $str in $infos -> $bonusFrame"
34
	if (bonusFrame > 25) {
35
		bonusFrame=0;
36
	}
37
	totalFrame = str.substring(0, str.lastIndexOf(":"))
38
	
39
	LocalTime time1 = LocalTime.parse(totalFrame, dateTimeFormatter)
40
	totalFrame = (time1.getHour()*60*60) + (time1.getMinute()*60) + time1.getSecond()
41
	
42
	def ret = totalFrame + (bonusFrame/25)
43
	return ret
44
}
45

  
46
try {
47
	def trsFiles = trsDirectory.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".trs"); } });
48
	
49
	if (trsFiles.size() == 0) {
50
		println "No TRS file to process in $trsDirectory"
51
		return;
52
	}
53
	
54
	ConsoleProgressBar cpb = new ConsoleProgressBar(sectionGroupsToInsert.keySet().size())
55
	for (File trsFile : trsFiles) {
56
		cpb.tick()
57

  
58
		// Open input file
59
		def slurper = new groovy.util.XmlParser(false, true, true);
60
		slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) // allow DTD declaration
61
		slurper.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "all"); // allow to read DTD from local file
62
		def trs = slurper.parse(trsFile.toURI().toString())
63
		def trsEpisodes = trs.Episode // 1
64
		if (trsEpisodes.size() > 1) {
65
			println "Error: multiple Episode node in $trsFile"
66
			continue
67
		}
68
		def trsEpisode = trsEpisodes[0]
69
		def trsSections =  trs.Episode.Section // 1
70
		if (trsSections.size() > 1) {
71
			println "multiple Section node in $trsFile"
72
			continue
73
		}
74
		def trsSection = trsSections[0]
75
		
76
		def turns = trsSection.Turn
77
		def newSections = []
78
		def iSection = 0;
79
		def currentSection = null
80
		def currentNode = null
81
		
82
		for (def turn : turns) {
83
			def start = Float.parseFloat(turn.@startTime)
84
			def end = Float.parseFloat(turn.@endTime)
85
			
86
			def found = null
87
			for (int i = iSection ; i < sections.size() ; i++) {
88
				if (end < sections[i][0]) { // Turn is before section
89
					
90
				} else if (sections[i][1] < start) { // Turn is before section
91
					
92
				} else {
93
					found = sections[i]
94
					iSection = i
95
					break // stop searching and set iSection to accelerate next search
96
				}
97
			}
98
			
99
			if (found == null) {
100
				if (currentSection != null || currentNode == null) {
101
					currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":turn.@startTime, "endTime":"", "synchronized":"false"] )
102
					currentSection = null;
103
				}
104
			} else {
105
				if (found != currentSection) {
106
					if (currentNode != null && currentNode.@synchronized == "false") {
107
						def tmp = currentNode.Turn
108
						currentNode.@endTime = tmp[-1].@endTime
109
					}
110
					
111
					currentSection = found
112
					currentNode = new Node(trsEpisode, "Section", currentSection[2])
113
				}
114
			}
115
			trsSection.remove(turn)
116
			currentNode.append(turn)
117
		}
118
		
119
		//remove the initial section
120
		trsEpisode.remove(trsSection)
121
		
122
		outputDirectory.mkdir()
123
		File outfile = new File(outputDirectory, trsFile.getName())
124
		outfile.withWriter("UTF-8") { writer ->
125
			writer.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE Trans SYSTEM "trans-14.dtd">\n')
126
			def printer = new groovy.util.XmlNodePrinter(new PrintWriter(writer))
127
			printer.setPreserveWhitespace(true)
128
			printer.print(trs)
129
		}
130
	}
131
	cpb.done()
132
	reader.close()
133
	println "Done."
134
	
135
} catch(Exception e) {
136
	println "Error: "+e
137
	Log.printStackTrace(e)
138
}
tmp/org.txm.core/src/java/org/txm/importer/ImportFileManager.java (revision 3026)
1
package org.txm.importer;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.io.UnsupportedEncodingException;
7
import java.util.LinkedHashMap;
8

  
9
import javax.xml.parsers.ParserConfigurationException;
10

  
11
import org.txm.utils.logger.Log;
12
import org.txm.utils.xml.DomUtils;
13
import org.w3c.dom.Document;
14
import org.w3c.dom.Element;
15
import org.w3c.dom.NodeList;
16
import org.xml.sax.SAXException;
17

  
18
/**
19
 * Read and save a import parameter file
20
 * 
21
 * The file is read to fill the ImportFormEditor > CorpusPage widgets
22
 * 
23
 * @author mdecorde
24
 *
25
 */
26
public class ImportFileManager {
27
	
28
	Document doc;
29
	
30
	File importFile;
31
	
32
	/**
33
	 * one map per import section
34
	 */
35
	LinkedHashMap<String, LinkedHashMap<String, String>> sections = new LinkedHashMap<>();
36
	
37
	public ImportFileManager(File importFile) {
38
		this.importFile = importFile;
39
	}
40
	
41
	public LinkedHashMap<String, LinkedHashMap<String, String>> getSections() {
42
		return sections;
43
	}
44
	
45
	public LinkedHashMap<String, String> getSection(String name) {
46
		if (name == null) return null;
47
		return sections.get(name);
48
	}
49
	
50
	public String load() {
51
		try {
52
			doc = DomUtils.load(importFile);
53
			
54
			String name = doc.getDocumentElement().getLocalName();
55
			if (!"import".equals(name)) {
56
				return "Not a  import parameter file: " + importFile;
57
			}
58
			String version = doc.getDocumentElement().getAttribute("version");
59
			if ("0.7.9".equals(version)) {
60
				loadFrom079();
61
			}
62
			else if ("0.8.2".equals(version)) {
63
				genericLoad();
64
			}
65
			else {
66
				return "Wrong import parameter file version: " + importFile + ": " + version;
67
			}
68
			return "";
69
		}
70
		catch (ParserConfigurationException | SAXException | IOException e) {
71
			e.printStackTrace();
72
			return e.getMessage();
73
		}
74
	}
75
	
76
	/**
77
	 * simple reading of all section parameters are stored in a section element with parameter elements (@key + text)
78
	 */
79
	private void genericLoad() {
80
		sections.clear();
81
		
82
		NodeList sectionList = doc.getElementsByTagName("section");
83
		for (int i = 0; i < sectionList.getLength(); i++) {
84
			Element section = (Element) sectionList.item(i);
85
			String name = section.getAttribute("name");
86
			if (name == null || name.length() == 0) {
87
				Log.warning("Load import 0.8.2 parameters: section with no name");
88
				continue;
89
			}
90
			if (sections.containsKey(name)) {
91
				Log.warning("Load import 0.8.2 parameters: duplicated section with name:" + name);
92
				continue;
93
			}
94
			
95
			LinkedHashMap<String, String> sectionParameters = new LinkedHashMap<>();
96
			sections.put(name, sectionParameters);
97
			NodeList parameterList = doc.getElementsByTagName("parameter");
98
			for (int j = 0; j < parameterList.getLength(); j++) {
99
				Element parameter = (Element) parameterList.item(j);
100
				String name2 = parameter.getAttribute("name");
101
				if (name2 == null || name2.length() == 0) {
102
					Log.warning("Load import 0.8.2 parameters: parameter with no name in section: " + name);
103
					continue;
104
				}
105
				if (sectionParameters.containsKey(name2)) {
106
					Log.warning("Load import 0.8.2 parameters: duplicated parameter with name:" + name2 + " in section: " + name);
107
					continue;
108
				}
109
				
110
				sectionParameters.put(name2, parameter.getTextContent());
111
			}
112
		}
113
	}
114
	
115
	private void loadFrom079() {
116
		sections.clear();
117
		
118
		Element corporaElement = (Element) doc.getElementsByTagName("corpora").item(0);
119
		Element corpusElement = (Element) corporaElement.getElementsByTagName("corpus").item(0);
120
		Element tokenizerElement = (Element) corpusElement.getElementsByTagName("tokenizer").item(0);
121
		Element pattributesElement = (Element) corpusElement.getElementsByTagName("pattributes").item(0);
122
		Element sattributesElement = (Element) corpusElement.getElementsByTagName("sattributes").item(0);
123
		Element uisElement = (Element) corpusElement.getElementsByTagName("uis").item(0);
124
		Element editionsElement = (Element) corpusElement.getElementsByTagName("editions").item(0);
125
		Element queriesElement = (Element) corpusElement.getElementsByTagName("queries").item(0);
126
		Element preBuildElement = (Element) corpusElement.getElementsByTagName("preBuild").item(0);
127
		Element xsltElement = (Element) corpusElement.getElementsByTagName("xslt").item(0);
128
		
129
		LinkedHashMap<String, String> section = new LinkedHashMap<>();
130
		section.put("src", corporaElement.getAttribute("rootDir"));
131
		section.put("desc", corporaElement.getAttribute("desc"));
132
		section.put("script", corporaElement.getAttribute("script"));
133
		section.put("date", corporaElement.getAttribute("date"));
134
		section.put("author", corporaElement.getAttribute("author"));
135
		section.put("author", corpusElement.getAttribute("name"));
136
		sections.put("src", section);
137
		
138
		section = new LinkedHashMap<>();
139
		section.put("annotate", corpusElement.getAttribute("annotate"));
140
		section.put("selected_lang", corpusElement.getAttribute("lang"));
141
		sections.put("lang", section);
142
		
143
		section = new LinkedHashMap<>();
144
		section.put("word_element", corpusElement.getAttribute("annotate"));
145
		section.put("tokenize", "" + (tokenizerElement.getAttribute("skip") != "true"));
146
		NodeList paramList = tokenizerElement.getElementsByTagName("param");
147
		for (int p = 0; p < paramList.getLength(); p++) {
148
			String pn = paramList.item(p).getAttributes().getNamedItem("name").getNodeValue();
149
			if (pn.equals("whitespaces")) {
150
				section.put("whitespaces", paramList.item(p).getTextContent());
151
			}
152
			else if (pn.equals("regPunct")) {
153
				section.put("regPunct", paramList.item(p).getTextContent());
154
			}
155
			else if (pn.equals("punct_strong")) {
156
				section.put("punct_strong", paramList.item(p).getTextContent());
157
			}
158
			else if (pn.equals("regElision")) {
159
				section.put("regElision", paramList.item(p).getTextContent());
160
			}
161
		}
162
		sections.put("tokenizer", section);
163
		
164
		section = new LinkedHashMap<>();
165
		section.put("font", corpusElement.getAttribute("font"));
166
		sections.put("font", section);
167
		
168
		section = new LinkedHashMap<>();
169
		NodeList editionList = editionsElement.getElementsByTagName("edition");
170
		for (int e = 0; e < editionList.getLength(); e++) {
171
			Element editionElement = (Element) editionList.item(e);
172
			if ("default".equals(editionElement.getAttribute("name"))) {
173
				section.put("build_default", editionElement.getAttribute("build_edition"));
174
				section.put("page_break_tag", editionElement.getAttribute("page_break_tag"));
175
				section.put("words_per_page", editionElement.getAttribute("words_per_page"));
176
			}
177
			else if ("facs".equals(editionElement.getAttribute("name"))) {
178
				section.put("build_facs", editionElement.getAttribute("build_edition"));
179
			}
180
		}
181
		section.put("default", editionsElement.getAttribute("default"));
182
		sections.put("editions", section);
183
		
184
		section = new LinkedHashMap<>();
185
		sections.put("commands", section);
186
		
187
		section = new LinkedHashMap<>();
188
		sections.put("commands", section);
189
		
190
		section = new LinkedHashMap<>();
191
		sections.put("textualplans", section);
192
		
193
		section = new LinkedHashMap<>();
194
		sections.put("options", section);
195
	}
196
	
197
	public String save() {
198
		try {
199
			if (doc == null) {
200
				return "Import parameter not loaded";
201
			}
202
			DomUtils.save(doc, importFile);
203
			return "";
204
		}
205
		catch (UnsupportedEncodingException | FileNotFoundException e) {
206
			e.printStackTrace();
207
			return e.getMessage();
208
		}
209
	}
210
}
0 211

  
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 3026)
458 458
	 */
459 459
	public Object getParameter(String key, boolean propagateToParent) {
460 460
		try {
461
			Field field = this.getField(key);
461
			Field field = BeanParameters.getField(this, key);
462 462
			if (field != null) {
463 463
				field.setAccessible(true);
464 464
				return field.get(this);
......
473 473
		return null;
474 474
	}
475 475
	
476
	
477 476
	/**
478
	 * Gets a member field according to its key.
479
	 * 
480
	 * @param key
481
	 * @return the field if exists otherwise null
482
	 */
483
	public Field getField(String key) {
484
		
485
		Field field = null;
486
		
487
		List<Field> fields = this.getAllFields();
488
		
489
		for (Field f : fields) {
490
			Parameter parameter = f.getAnnotation(Parameter.class);
491
			if (parameter != null && parameter.key().equals(key)) {
492
				field = f;
493
				break;
494
			}
495
		}
496
		
497
		return field;
498
	}
499
	
500
	/**
501
	 * Returns all the member fields of the class instance (from all inherited classes).
502
	 * 
503
	 * @return the list of declared fields
504
	 */
505
	public List<Field> getAllFields() {
506
		
507
		List<Field> fields = new ArrayList<>();
508
		Class<?> clazz = this.getClass();
509
		
510
		while (clazz != Object.class) {
511
			fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
512
			clazz = clazz.getSuperclass();
513
		}
514
		
515
		return fields;
516
	}
517
	
518
	/**
519 477
	 * Stores the parameters of the specified types used for last computing in the specified HashMap.
520 478
	 * 
521 479
	 * @param parameterTypes
......
524 482
	 */
525 483
	protected void updateLastParameters(ArrayList<Integer> parametersTypes, HashMap<String, Object> lastParameters) throws Exception {
526 484
		
527
		List<Field> fields = this.getAllFields();
485
		List<Field> fields = BeanParameters.getAllFields(this);
528 486
		
529 487
		for (Field f : fields) {
530 488
			Parameter parameter = f.getAnnotation(Parameter.class);
......
588 546
	 * @throws Exception
589 547
	 */
590 548
	protected void clearLastParameters(int parameterType) {
591
		List<Field> fields = this.getAllFields();
549
		List<Field> fields = BeanParameters.getAllFields(this);
592 550
		
593 551
		for (Field f : fields) {
594 552
			Parameter parameter = f.getAnnotation(Parameter.class);
......
684 642
		
685 643
		boolean hasParameterChanged = false;
686 644
		
687
		List<Field> fields = this.getAllFields();
645
		List<Field> fields = BeanParameters.getAllFields(this);
688 646
		
689 647
		for (Field f : fields) {
690 648
			Parameter parameter = f.getAnnotation(Parameter.class);
......
770 728
		
771 729
		str.append("Parameters (type = " + parametersType + " / " + Parameter.types[parametersType] + ")\n"); //$NON-NLS-1$
772 730
		
773
		List<Field> fields = this.getAllFields();
731
		List<Field> fields = BeanParameters.getAllFields(this);
774 732
		
775 733
		for (Field f : fields) {
776 734
			Parameter parameter = f.getAnnotation(Parameter.class);
......
1126 1084
			this.lazyName = this.getSimpleName();
1127 1085
		}
1128 1086
		
1129
		List<Field> fields = this.getAllFields();
1087
		List<Field> fields = BeanParameters.getAllFields(this);
1130 1088
		
1131 1089
		for (Field f : fields) {
1132 1090
			Parameter parameter = f.getAnnotation(Parameter.class);
......
1240 1198
	 */
1241 1199
	protected boolean autoLoadParametersFromAnnotations(int parameterType) throws Exception {
1242 1200
		
1243
		List<Field> fields = this.getAllFields();
1201
		List<Field> fields = BeanParameters.getAllFields(this);
1244 1202
		
1245 1203
		for (Field f : fields) {
1246 1204
			
......
1355 1313
	 */
1356 1314
	public boolean setParameter(String key, Object value, boolean propagateToParent) throws Exception {
1357 1315
		
1358
		List<Field> fields = this.getAllFields();
1316
		Field targetField = BeanParameters.getField(this, key);
1359 1317
		
1360
		Field targetField = null;
1361
		
1362
		for (Field f : fields) {
1363
			Parameter parameter = f.getAnnotation(Parameter.class);
1364
			if (parameter == null) {
1365
				continue;
1366
			}
1367
			if (!parameter.key().isEmpty() && parameter.key().equals(key)) {
1368
				targetField = f;
1369
				break;
1370
			}
1371
		}
1372
		
1373 1318
		if (targetField != null) {
1374 1319
			targetField.setAccessible(true);
1375 1320
			targetField.set(this, value);
tmp/org.txm.core/src/java/org/txm/core/results/BeanParameters.java (revision 3026)
1
package org.txm.core.results;
2

  
3
import java.lang.reflect.Field;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.LinkedHashMap;
7
import java.util.List;
8

  
9
/**
10
 * Utility class to read/write values to a bean
11
 * 
12
 * @author mdecorde
13
 *
14
 */
15
public class BeanParameters {
16
	
17
	/**
18
	 * Gets a member field according to its key.
19
	 * 
20
	 * Avoid calling multiple times this method and use getAllFields
21
	 * 
22
	 * @param key
23
	 * @return the field if exists otherwise null
24
	 */
25
	public static Field getField(Object bean, String key) {
26
		if (bean == null) throw new IllegalArgumentException("Object must not be null");
27
		if (key == null) throw new IllegalArgumentException("Parameter key must not be null");
28
		
29
		Field field = null;
30
		
31
		List<Field> fields = getAllFields(bean);
32
		
33
		for (Field f : fields) {
34
			Parameter parameter = f.getAnnotation(Parameter.class);
35
			if (parameter != null && parameter.key().equals(key)) {
36
				field = f;
37
				break;
38
			}
39
		}
40
		
41
		return field;
42
	}
43
	
44
	/**
45
	 * Returns all the member fields of the class instance (from all inherited classes).
46
	 * 
47
	 * @return the list of declared fields with a Parameter annotation
48
	 */
49
	public static LinkedHashMap<String, Field> getFieldsPerName(Object bean) {
50
		LinkedHashMap<String, Field> ret = new LinkedHashMap<>();
51
		for (Field f : getAllFields(bean)) {
52
			Parameter p = f.getAnnotation(Parameter.class);
53
			ret.put(p.key(), f);
54
		}
55
		return ret;
56
	}
57
	
58
	/**
59
	 * Returns all the member fields of the class instance (from all inherited classes).
60
	 * 
61
	 * @return the list of declared fields with a Parameter annotation
62
	 */
63
	public static List<Field> getAllFields(Object bean) {
64
		if (bean == null) throw new IllegalArgumentException("Object must not be null");
65
		
66
		List<Field> fields = new ArrayList<>();
67
		Class<?> clazz = bean.getClass();
68
		
69
		while (clazz != Object.class) {
70
			
71
			for (Field f : Arrays.asList(clazz.getDeclaredFields())) {
72
				Parameter parameter = f.getAnnotation(Parameter.class);
73
				if (parameter == null) {
74
					continue;
75
				}
76
				String key = parameter.key();
77
				if (key.isEmpty()) {
78
					continue; // no preference key defined
79
				}
80
				
81
				f.setAccessible(true);
82
				fields.add(f);
83
			}
84
			
85
			clazz = clazz.getSuperclass();
86
		}
87
		
88
		return fields;
89
	}
90
}
0 91

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editors/imports/sections/AnnotationSection.java (revision 3026)
18 18
public class AnnotationSection extends ImportEditorSection {
19 19
	
20 20
	private static final int SECTION_SIZE = 1;
21
	
21 22
	public static final String DEFAULTNAMESUFFIX = "KR";
22 23
	
23 24
	Text nameText;
24 25
	
25 26
	public AnnotationSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
26
		super(toolkit2, form2, parent, style);
27

  
27
		super(toolkit2, form2, parent, style, "annotation");
28
		
28 29
		this.section.setText("Annotation");
29 30
		TableWrapLayout layout = new TableWrapLayout();
30 31
		layout.makeColumnsEqualWidth = true;
31 32
		this.section.setLayout(layout);
32 33
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
33 34
		this.section.setEnabled(false);
34

  
35
		
35 36
		this.section.addExpansionListener(new ExpansionAdapter() {
37
			
36 38
			@Override
37
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
39
			public void expansionStateChanged(ExpansionEvent e) {
40
				form.layout(true);
41
			}
38 42
		});
39

  
40
		//filesection.setDescription("Select how to find source files");
43
		
44
		// filesection.setDescription("Select how to find source files");
41 45
		Composite sectionClient = toolkit.createComposite(this.section);
42 46
		TableWrapLayout slayout = new TableWrapLayout();
43 47
		slayout.makeColumnsEqualWidth = false;
44 48
		slayout.numColumns = 2;
45 49
		sectionClient.setLayout(slayout);
46 50
		this.section.setClient(sectionClient);
47

  
51
		
48 52
		Label l = toolkit.createLabel(sectionClient, "Knowledge repository name", SWT.WRAP);
49 53
		l.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
50

  
54
		
51 55
		nameText = new Text(sectionClient, SWT.BORDER);
52 56
	}
53

  
57
	
54 58
	@Override
55 59
	public void update(Project project) {
56 60
		if (this.section.isDisposed()) return;
57 61
		if (project == null) return;
58 62
	}
59

  
63
	
60 64
	@Override
61 65
	public boolean save(Project project) {
62 66
		if (!this.section.isDisposed()) {
63 67
			String value = nameText.getText();
64
						
68
			
65 69
			return true;
66 70
		}
67 71
		return false;
68 72
	}
69

  
73
	
70 74
	@Override
71 75
	public boolean checkFields() {
72 76
		return true;
73 77
	}
74

  
78
	
75 79
	@Override
76 80
	public int getSectionSize() {
77 81
		return SECTION_SIZE;
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/TXMResultParametersView.java (revision 3026)
57 57
import org.eclipse.ui.PlatformUI;
58 58
import org.eclipse.ui.part.EditorPart;
59 59
import org.eclipse.ui.part.ViewPart;
60
import org.txm.core.results.BeanParameters;
60 61
import org.txm.core.results.Parameter;
61 62
import org.txm.core.results.TXMResult;
62 63
import org.txm.rcp.IImageKeys;
......
135 136
		TXMEditor reditor = (TXMEditor) editor;
136 137
		final TXMResult result = reditor.getResult();
137 138
		
138
		List<Field> allfields = result.getAllFields();
139
		List<Field> fields = new ArrayList<>();
140
		for (Field f : allfields) {
141
			Parameter parameter = f.getAnnotation(Parameter.class);
142
			if (parameter == null) {
143
				continue;
144
			}
145
			fields.add(f);
146
		}
139
		List<Field> fields = BeanParameters.getAllFields(result);
147 140
		
148 141
		Collections.sort(fields, new Comparator<Field>() {
149 142
			
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/TRSSection.java (revision 3026)
23 23
	
24 24
	Button displayLocutorsButton;
25 25
	
26
	Button indexInterviewerButton;
27
	
28
	Button createPagesForSectionsButton;
29
	
30
	Button indexTranscriberMetadataButton;
31
	
26 32
	/**
27 33
	 * 
28 34
	 * @param toolkit2
......
35 41
	 */
36 42
	public TRSSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
37 43
		
38
		super(toolkit2, form2, parent, style);
44
		super(toolkit2, form2, parent, style, "transcription");
39 45
		
40 46
		this.section.setText(TXMUIMessages.TRSSection_0);
41 47
		TableWrapLayout layout = new TableWrapLayout();
......
65 71
		TableWrapData gdata2 = getButtonLayoutData();
66 72
		gdata2.colspan = 4; // one line
67 73
		displayLocutorsButton.setLayoutData(gdata2);
74
		
75
		// build text edition or not button
76
		indexInterviewerButton = toolkit.createButton(sectionClient, "Index interviewer speech", SWT.CHECK);
77
		gdata2 = getButtonLayoutData();
78
		gdata2.colspan = 4; // one line
79
		indexInterviewerButton.setLayoutData(gdata2);
80
		
81
		// build text edition or not button
82
		createPagesForSectionsButton = toolkit.createButton(sectionClient, "Create pages for sections", SWT.CHECK);
83
		gdata2 = getButtonLayoutData();
84
		gdata2.colspan = 4; // one line
85
		createPagesForSectionsButton.setLayoutData(gdata2);
86
		
87
		// build text edition or not button
88
		indexTranscriberMetadataButton = toolkit.createButton(sectionClient, "Index Transcriber transcription metadata", SWT.CHECK);
89
		gdata2 = getButtonLayoutData();
90
		gdata2.colspan = 4; // one line
91
		indexTranscriberMetadataButton.setLayoutData(gdata2);
68 92
	}
69 93
	
70 94
	@Override
......
74 98
		
75 99
		IEclipsePreferences customNode = project.getImportParameters();
76 100
		displayLocutorsButton.setSelection(customNode.getBoolean("display_locutors", true)); //$NON-NLS-1$
101
		indexInterviewerButton.setSelection(customNode.getBoolean("indexInterviewer", true)); //$NON-NLS-1$
102
		createPagesForSectionsButton.setSelection(customNode.getBoolean("create_section_pages", true)); //$NON-NLS-1$
103
		indexTranscriberMetadataButton.setSelection(customNode.getBoolean("ignoreTranscriberMetadata", true)); //$NON-NLS-1$
77 104
	}
78 105
	
79 106
	@Override
......
82 109
			
83 110
			IEclipsePreferences customNode = project.getImportParameters();
84 111
			customNode.putBoolean("display_locutors", displayLocutorsButton.getSelection()); //$NON-NLS-1$
112
			customNode.putBoolean("indexInterviewer", indexInterviewerButton.getSelection()); //$NON-NLS-1$
113
			customNode.putBoolean("create_section_pages", createPagesForSectionsButton.getSelection()); //$NON-NLS-1$
114
			customNode.putBoolean("ignoreTranscriberMetadata", indexTranscriberMetadataButton.getSelection()); //$NON-NLS-1$
85 115
		}
86 116
		return true;
87 117
	}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/TokenizerSection.java (revision 3026)
51 51
	private HashMap<String, Boolean> moduleParams;
52 52
	
53 53
	public TokenizerSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style, HashMap<String, Boolean> moduleParams) {
54
		super(toolkit2, form2, parent, style);
54
		super(toolkit2, form2, parent, style, "tokenizer");
55 55
		this.moduleParams = moduleParams;
56 56
		this.section.setText(TXMUIMessages.lexicalSegmentation);
57 57
		TableWrapLayout layout = new TableWrapLayout();
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/EditionSection.java (revision 3026)
59 59
	 * @param scriptName temporary parameter to detect if import module is xtzLoader.groovy
60 60
	 */
61 61
	public EditionSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style, HashMap<String, Boolean> moduleParams, String scriptName) {
62
		super(toolkit2, form2, parent, style);
62
		super(toolkit2, form2, parent, style, "edition");
63 63
		
64 64
		this.section.setText(TXMUIMessages.editions);
65 65
		TableWrapLayout layout = new TableWrapLayout();
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/OptionsSection.java (revision 3026)
12 12
import org.txm.objects.Project;
13 13

  
14 14
public class OptionsSection extends ImportEditorSection {
15

  
15
	
16 16
	private static final int SECTION_SIZE = 1;
17
	
17 18
	private Button cleanButton;
18
//	private Button multithreadButton;
19

  
19
	// private Button multithreadButton;
20
	
20 21
	public OptionsSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
21
		super(toolkit2, form2, parent, style);
22

  
22
		super(toolkit2, form2, parent, style, "misc");
23
		
23 24
		this.section.setText("Options");
24 25
		TableWrapLayout layout = new TableWrapLayout();
25 26
		layout.makeColumnsEqualWidth = true;
......
27 28
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
28 29
		this.section.setEnabled(false);
29 30
		this.section.addExpansionListener(new ExpansionAdapter() {
31
			
30 32
			@Override
31
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
33
			public void expansionStateChanged(ExpansionEvent e) {
34
				form.layout(true);
35
			}
32 36
		});
33

  
37
		
34 38
		Composite sectionClient = toolkit.createComposite(this.section);
35 39
		TableWrapLayout slayout = new TableWrapLayout();
36 40
		slayout.makeColumnsEqualWidth = false;
37 41
		slayout.numColumns = 2;
38 42
		sectionClient.setLayout(slayout);
39 43
		this.section.setClient(sectionClient);
40

  
44
		
41 45
		cleanButton = toolkit.createButton(sectionClient, "Remove temporary directories", SWT.CHECK);
42 46
		TableWrapData gdata = getTextGridData();
43 47
		gdata.grabHorizontal = true;
44 48
		gdata.colspan = 2;
45 49
		cleanButton.setLayoutData(gdata);
46 50
		
47
//		multithreadButton = toolkit.createButton(sectionClient, "Experimental multi-threading import", SWT.CHECK);
48
//		gdata = getTextGridData();
49
//		gdata.colspan = 2;
50
//		gdata.grabHorizontal = true;
51
//		multithreadButton.setLayoutData(gdata);
51
		// multithreadButton = toolkit.createButton(sectionClient, "Experimental multi-threading import", SWT.CHECK);
52
		// gdata = getTextGridData();
53
		// gdata.colspan = 2;
54
		// gdata.grabHorizontal = true;
55
		// multithreadButton.setLayoutData(gdata);
52 56
	}
53

  
57
	
54 58
	@Override
55 59
	public void update(Project project) {
56 60
		cleanButton.setSelection(project.getCleanAfterBuild());
57
//		
58
////		value = (String) params.getKeyValueParameters().get(ImportKeys.MULTITHREAD);
59
////		if (value == null) value = "false";
60
////		multithreadButton.setSelection(Boolean.parseBoolean(value));
61
		//
62
		//// value = (String) params.getKeyValueParameters().get(ImportKeys.MULTITHREAD);
63
		//// if (value == null) value = "false";
64
		//// multithreadButton.setSelection(Boolean.parseBoolean(value));
61 65
	}
62

  
66
	
63 67
	@Override
64 68
	public boolean save(Project project) {
65 69
		if (this.section != null && !section.isDisposed()) {
66
//			
70
			//
67 71
			project.setCleanAfterBuild(cleanButton.getSelection());
68
//			
69
////			value = Boolean.toString(multithreadButton.getSelection());
70
////			params.getKeyValueParameters().put(ImportKeys.MULTITHREAD, value);
71
//			return true;
72
			//
73
			//// value = Boolean.toString(multithreadButton.getSelection());
74
			//// params.getKeyValueParameters().put(ImportKeys.MULTITHREAD, value);
75
			// return true;
72 76
		}
73

  
77
		
74 78
		return true;
75 79
	}
76

  
80
	
77 81
	@Override
78 82
	public boolean checkFields() {
79 83
		return true;
80 84
	}
81

  
85
	
82 86
	@Override
83 87
	public int getSectionSize() {
84 88
		return SECTION_SIZE;
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/UISection.java (revision 3026)
23 23
	private Text referencePatternText;
24 24
	
25 25
	public UISection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
26
		super(toolkit2, form2, parent, style);
26
		super(toolkit2, form2, parent, style, "commands");
27 27
		
28 28
		this.section.setText(TXMUIMessages.commands);
29 29
		TableWrapLayout layout = new TableWrapLayout();
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/InfosSection.java (revision 3026)
23 23
public class InfosSection extends ImportEditorSection {
24 24
	
25 25
	private static final int SECTION_SIZE = 2;
26
//	Label corpusNameLabel; // color change if the corpus name is malformed
26
	
27
	// Label corpusNameLabel; // color change if the corpus name is malformed
27 28
	private Text descText;
28 29
	
29 30
	public InfosSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
30
		super(toolkit2, form2, parent, style);
31
		super(toolkit2, form2, parent, style, "infos");
31 32
		
32
		//this = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE);
33
		// this = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE);
33 34
		this.section.setText(TXMUIMessages.description);
34 35
		section.setExpanded(true);
35 36
		
......
37 38
		this.section.setLayout(layout);
38 39
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
39 40
		this.section.setEnabled(false);
40

  
41
		
41 42
		this.section.addExpansionListener(new ExpansionAdapter() {
43
			
42 44
			@Override
43
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
45
			public void expansionStateChanged(ExpansionEvent e) {
46
				form.layout(true);
47
			}
44 48
		});
45

  
49
		
46 50
		Composite sectionClient = toolkit.createComposite(this.section);
47 51
		TableWrapData gdatac = new TableWrapData();
48 52
		gdatac.colspan = 2;
......
52 56
		slayout.numColumns = 1;
53 57
		sectionClient.setLayout(slayout);
54 58
		this.section.setClient(sectionClient);
55

  
56
//		corpusNameLabel = toolkit.createLabel(sectionClient, TXMUIMessages.corpusNameOnlyCapsAndNoDigitAtBeginning, SWT.WRAP);
57
//		TableWrapData gdata = new TableWrapData();
58
//		corpusNameLabel.setLayoutData(gdata);
59
//
59
		
60
		// corpusNameLabel = toolkit.createLabel(sectionClient, TXMUIMessages.corpusNameOnlyCapsAndNoDigitAtBeginning, SWT.WRAP);
61
		// TableWrapData gdata = new TableWrapData();
62
		// corpusNameLabel.setLayoutData(gdata);
63
		//
60 64
		Label label = toolkit.createLabel(sectionClient, TXMUIMessages.completeNameAuthorDateLicenseComment, SWT.WRAP);
61 65
		TableWrapData gdata = new TableWrapData();
62 66
		label.setLayoutData(gdata);
63

  
67
		
64 68
		descText = toolkit.createText(sectionClient, "", SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); //$NON-NLS-1$
65 69
		gdata = new TableWrapData(TableWrapData.FILL, TableWrapData.FILL);
66 70
		gdata.heightHint = 50;
67

  
71
		
68 72
		descText.setLayoutData(gdata);
69 73
	}
70

  
74
	
71 75
	@Override
72 76
	public void update(Project project) {
73
		section.setText(NLS.bind(TXMUIMessages.descriptionOfTheP0CorpusP1, project.getName(), project.getSrcdir())); //$NON-NLS-1$
77
		section.setText(NLS.bind(TXMUIMessages.descriptionOfTheP0CorpusP1, project.getName(), project.getSrcdir()));
74 78
		
75
		String descContent = project.getDescription(); //$NON-NLS-1$
79
		String descContent = project.getDescription();
76 80
		descContent = descContent.replace("<pre><br/>", ""); //$NON-NLS-1$ //$NON-NLS-2$
77 81
		descContent = descContent.replace("</pre>", ""); //$NON-NLS-1$ //$NON-NLS-2$
78 82
		descContent = descContent.replace("<br/>", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
79 83
		
80
		//System.out.println("LOAD DESC WITH: '"+descContent+"'");
81
		descText.setText(descContent); //$NON-NLS-1$
84
		// System.out.println("LOAD DESC WITH: '"+descContent+"'");
85
		descText.setText(descContent);
82 86
	}
83

  
87
	
84 88
	@Override
85 89
	public boolean save(Project project) {
86
		project.setDescription("<pre><br/>"+descText.getText().replace("\n", "<br/>")+"</pre>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
90
		project.setDescription("<pre><br/>" + descText.getText().replace("\n", "<br/>") + "</pre>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
87 91
		
88 92
		return true;
89 93
	}
90

  
94
	
91 95
	@Override
92 96
	public boolean checkFields() {
93
//		corpusNameLabel.setBackground(corpusNameLabel.getParent().getBackground());
97
		// corpusNameLabel.setBackground(corpusNameLabel.getParent().getBackground());
94 98
		return true;
95 99
	}
96

  
100
	
97 101
	@Override
98 102
	public int getSectionSize() {
99 103
		return SECTION_SIZE;
100 104
	}
101
}
105
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/imports/sections/FrontXSLSection.java (revision 3026)
39 39
	private static final String ID = "org.txm.rcp.editors.imports.CorpusPage.xslt"; //$NON-NLS-1$
40 40
	
41 41
	private static final int SECTION_SIZE = 2;
42
	
42 43
	File xsltfile;
44
	
43 45
	Text xsltfileValue;
44

  
45
	String[] xsltparams;//{"val1",1,"val2",2}
46
	
47
	String[] xsltparams;// {"val1",1,"val2",2}
48
	
46 49
	TableViewer xsltParamsViewer;
47 50
	
48 51
	public FrontXSLSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
49
		super(toolkit2, form2, parent, style);
50

  
52
		super(toolkit2, form2, parent, style, "xslt");
53
		
51 54
		this.section.setText(TXMUIMessages.frontXSL);
52 55
		TableWrapLayout layout = new TableWrapLayout();
53 56
		layout.makeColumnsEqualWidth = true;
54 57
		this.section.setLayout(layout);
55 58
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
56 59
		this.section.setEnabled(false);
57

  
60
		
58 61
		this.section.addExpansionListener(new ExpansionAdapter() {
62
			
59 63
			@Override
60
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
64
			public void expansionStateChanged(ExpansionEvent e) {
65
				form.layout(true);
66
			}
61 67
		});
62

  
63
		//filesection.setDescription("Select how to find source files");
68
		
69
		// filesection.setDescription("Select how to find source files");
64 70
		Composite sectionClient = toolkit.createComposite(this.section);
65 71
		TableWrapLayout slayout = new TableWrapLayout();
66 72
		slayout.makeColumnsEqualWidth = false;
67 73
		slayout.numColumns = 4;
68 74
		sectionClient.setLayout(slayout);
69 75
		this.section.setClient(sectionClient);
70

  
71

  
76
		
77
		
72 78
		xsltfileValue = toolkit.createText(sectionClient, "", SWT.BORDER); //$NON-NLS-1$
73 79
		TableWrapData gdata = getTextGridData();
74 80
		xsltfileValue.setLayoutData(gdata);
75

  
81
		
76 82
		Button browseXSLTButton = toolkit.createButton(sectionClient, "...", SWT.PUSH); //$NON-NLS-1$
77 83
		browseXSLTButton.setLayoutData(getButtonLayoutData());
78 84
		browseXSLTButton.addSelectionListener(new SelectionListener() {
85
			
79 86
			@Override
80
			public void widgetDefaultSelected(SelectionEvent e) {
81
			}
82

  
87
			public void widgetDefaultSelected(SelectionEvent e) {}
88
			
83 89
			@Override
84 90
			public void widgetSelected(SelectionEvent e) {
85 91
				FileDialog dialog = new FileDialog(form.getShell(), SWT.OPEN);
86
				String[] extensions = {"*.xsl"}; //$NON-NLS-1$
92
				String[] extensions = { "*.xsl" }; //$NON-NLS-1$
87 93
				dialog.setFilterExtensions(extensions);
88 94
				if (LastOpened.getFile(ID) != null) {
89 95
					dialog.setFilterPath(LastOpened.getFolder(ID));
90 96
					dialog.setFileName(LastOpened.getFile(ID));
91
				} else {
97
				}
98
				else {
92 99
					dialog.setFilterPath(Toolbox.getTxmHomePath());
93 100
				}
94 101
				if (dialog.open() != null) {
......
98 105
				}
99 106
			}
100 107
		});
101

  
108
		
102 109
		Button editXSLTButton = toolkit.createButton(sectionClient, TXMUIMessages.editXSLStylesheet, SWT.PUSH);
103 110
		editXSLTButton.setLayoutData(getButtonLayoutData());
104 111
		editXSLTButton.addSelectionListener(new SelectionListener() {
112
			
105 113
			@Override
106
			public void widgetDefaultSelected(SelectionEvent e) {
107
			}
108

  
114
			public void widgetDefaultSelected(SelectionEvent e) {}
115
			
109 116
			@Override
110 117
			public void widgetSelected(SelectionEvent e) {
111 118
				if (xsltfile != null && xsltfile.exists() && xsltfile.isFile()) {
112 119
					EditFile.openfile(xsltfile.getAbsolutePath());
113 120
				}
114 121
			}
115
		});	
116

  
122
		});
123
		
117 124
		Label l = toolkit.createLabel(sectionClient, ""); // empty cell //$NON-NLS-1$
118 125
		l.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
119

  
126
		
120 127
		Button addButton = toolkit.createButton(sectionClient, TXMUIMessages.addAXsltParameter, SWT.PUSH);
121 128
		addButton.setLayoutData(getButtonLayoutData());
122 129
		addButton.addSelectionListener(new SelectionListener() {
130
			
123 131
			@Override
124
			public void widgetDefaultSelected(SelectionEvent e) {
125
			}
126

  
132
			public void widgetDefaultSelected(SelectionEvent e) {}
133
			
127 134
			@Override
128 135
			public void widgetSelected(SelectionEvent e) {
129 136
				if (project == null) return;
130 137
				
131
				LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
138
				LinkedHashMap<String, String> values = new LinkedHashMap<>();
132 139
				values.put("name", ""); //$NON-NLS-1$ //$NON-NLS-2$
133 140
				values.put("value", "");			 //$NON-NLS-1$ //$NON-NLS-2$
134 141
				MultipleValueDialog dlg = new MultipleValueDialog(form.getShell(), TXMUIMessages.addAXsltParameter, values);
......
137 144
				}
138 145
			}
139 146
		});
140

  
147
		
141 148
		Button removeButton = toolkit.createButton(sectionClient, TXMUIMessages.deleteParameter, SWT.PUSH);
142 149
		TableWrapData td = getButtonLayoutData();
143 150
		td.colspan = 3;
144 151
		removeButton.setLayoutData(td);
145 152
		removeButton.addSelectionListener(new SelectionListener() {
153
			
146 154
			@Override
147
			public void widgetDefaultSelected(SelectionEvent e) {
148
			}
149

  
155
			public void widgetDefaultSelected(SelectionEvent e) {}
156
			
150 157
			@Override
151 158
			public void widgetSelected(SelectionEvent e) {
152 159
				if (project == null) return;
......
159 166
				}
160 167
			}
161 168
		});
162

  
163
		//		l = toolkit.createLabel(sectionClient, ""); // empty cell
164
		//		l.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
165
		//		l = toolkit.createLabel(sectionClient, ""); // empty cell
166
		//		l.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
167

  
169
		
170
		// l = toolkit.createLabel(sectionClient, ""); // empty cell
171
		// l.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
172
		// l = toolkit.createLabel(sectionClient, ""); // empty cell
173
		// l.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE));
174
		
168 175
		Table table = toolkit.createTable(sectionClient, SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.VIRTUAL);
169 176
		xsltParamsViewer = new TableViewer(table);
170 177
		xsltParamsViewer.getTable().addKeyListener(new TableKeyListener(xsltParamsViewer));
......
175 182
		xsltParamsViewer.setContentProvider(new HashMapContentProvider());
176 183
		xsltParamsViewer.getTable().setHeaderVisible(true);
177 184
		xsltParamsViewer.getTable().setLinesVisible(true);
178

  
179
		String[] cols = {"name", "value"}; //$NON-NLS-1$ //$NON-NLS-2$
185
		
186
		String[] cols = { "name", "value" }; //$NON-NLS-1$ //$NON-NLS-2$
180 187
		for (String col : cols) {
181 188
			TableViewerColumn columnViewer = new TableViewerColumn(xsltParamsViewer, SWT.NONE);
182 189
			TableColumn column = columnViewer.getColumn();
......
185 192
			columnViewer.setLabelProvider(new HashMapLabelProvider(col));
186 193
		}
187 194
	}
188

  
195
	
189 196
	@Override
190 197
	public void update(Project project) {
191 198
		if (this.section.isDisposed()) return;
......
197 204
			xsltfileValue.setText(filepath);
198 205
			xsltfile = new File(filepath);
199 206
		}
200

  
207
		
201 208
		xsltParamsViewer.getTable().getParent().layout();
202
		xsltParamsViewer.setInput(project.getXsltParameters()); //$NON-NLS-1$
209
		xsltParamsViewer.setInput(project.getXsltParameters());
203 210
	}
204

  
211
	
205 212
	@Override
206 213
	public boolean save(Project project) {
207 214
		if (xsltfileValue != null && !xsltfileValue.isDisposed())
208
			project.setXslt(xsltfileValue.getText()); //$NON-NLS-1$
209

  
215
			project.setXslt(xsltfileValue.getText());
216
		
210 217
		return true;
211 218
	}
212

  
219
	
213 220
	@Override
214 221
	public boolean checkFields() {
215 222
		return true;
216 223
	}
217

  
224
	
218 225
	@Override
219 226
	public int getSectionSize() {
220 227
		return SECTION_SIZE;
221 228
	}
222
}
229
}
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff