Revision 548

tmp/org.txm.concordance.core/src/org/txm/concordance/core/functions/Concordance.java (revision 548)
45 45
import org.txm.concordance.core.functions.comparators.LineComparator;
46 46
import org.txm.concordance.core.messages.ConcordanceMessages;
47 47
import org.txm.concordance.core.preferences.ConcordancePreferences;
48
import org.txm.core.results.Parameter;
48 49
import org.txm.core.results.TXMParameters;
49 50
import org.txm.core.results.TXMResult;
50 51
import org.txm.searchengine.cqp.AbstractCqiClient;
......
85 86
	protected List<Line> lines;
86 87
	/** The n lines. */
87 88
	protected int nLines;
89
	
88 90
	/** The keyword analysis properties */
91
	@Parameter
89 92
	protected List<Property> pAnalysisKeywordProperties;
90 93
	/** The analysis properties */
94
	@Parameter
91 95
	protected List<Property> pAnalysisLeftProperties;
92 96
	/** The ReferncePattern sort properties	 */
97
	@Parameter
93 98
	protected ReferencePattern pAnalysisRefPattern;
94 99
	/** The right c analysis property. */
100
	@Parameter
95 101
	protected List<Property> pAnalysisRightProperties;
96 102
	/** used to limit context to the matches of the CQL limit query	 */
103
	@Parameter
97 104
	protected String pLimitCQL;
98 105
	/** The left context size. */
106
	@Parameter
99 107
	protected Integer pLeftContextSize;
100 108
	/** The query. */
109
	@Parameter
101 110
	protected Query pQuery;
102 111
	/** The right context size. */
112
	@Parameter
103 113
	protected Integer pRightContextSize;
104 114
	/**	 The top line index shown and the number of lines to show per page */
115
	@Parameter
105 116
	protected Integer pTopIndex, pNLinesPerPage;
106 117
	/** The keyword view properties. */
118
	@Parameter
107 119
	protected List<Property> pViewKeywordProperties;
108 120
	/** The left c view properties. */
121
	@Parameter
109 122
	protected List<Property> pViewLeftProperties;
110 123
	/** The reference pattern. */
124
	@Parameter
111 125
	protected ReferencePattern pViewRefPattern;
112 126
	/** The right c view properties. */
127
	@Parameter
113 128
	protected List<Property> pViewRightProperties;
114 129
	//	/** The view properties. */
115 130
	//	private List<Property> pViewKeywordProperties; // contains all the view properties
......
1054 1069

  
1055 1070
	public void setCQLSeparator(String cql_limit) {
1056 1071
		this.pLimitCQL = cql_limit;
1057
		updateDirty(pLimitCQL, cql_limit);
1072
		//updateDirty(pLimitCQL, cql_limit);
1058 1073
	}
1059 1074

  
1060 1075
	/**
......
1064 1079
	 *            the new analysis property
1065 1080
	 */
1066 1081
	public void setKeywordAnalysisProperties(List<Property> selectedKeywordSortProperty) {
1082
		//updateDirty(pAnalysisKeywordProperties, selectedKeywordSortProperty);
1067 1083
		this.pAnalysisKeywordProperties = selectedKeywordSortProperty;
1068
		updateDirty(pAnalysisKeywordProperties, selectedKeywordSortProperty);
1069 1084
		resetLines();
1070 1085
	}
1071 1086

  
......
1076 1091
	 *            the new analysis property
1077 1092
	 */
1078 1093
	public void setLeftAnalysisProperties(List<Property> selectedLeftSortProperty) {
1094
		//updateDirty(pAnalysisLeftProperties, selectedLeftSortProperty);
1079 1095
		this.pAnalysisLeftProperties = selectedLeftSortProperty;
1080
		updateDirty(pAnalysisLeftProperties, selectedLeftSortProperty);
1081 1096
		resetLines();
1082 1097
	}
1083 1098

  
......
1087 1102
	 * @param size the new context size
1088 1103
	 */
1089 1104
	public void setLeftContextSize(int size) {
1105
		//updateDirty(pLeftContextSize, size);
1090 1106
		this.pLeftContextSize = size;
1091
		updateDirty(pLeftContextSize, size);
1092 1107
		resetLines();
1093 1108
	}
1094 1109

  
......
1219 1234
	 *            the new reference Pattern
1220 1235
	 */
1221 1236
	public void setRefAnalysePattern(ReferencePattern referencePattern) {
1237
		//updateDirty(pAnalysisRefPattern, referencePattern);
1222 1238
		this.pAnalysisRefPattern = referencePattern;
1223
		updateDirty(pAnalysisRefPattern, referencePattern);
1224 1239
		resetLines();
1225 1240
	}
1226 1241

  
......
1231 1246
	 *            the new reference Pattern
1232 1247
	 */
1233 1248
	public void setRefViewPattern(ReferencePattern referencePattern) {
1249
		//updateDirty(pViewRefPattern, referencePattern);
1234 1250
		this.pViewRefPattern = referencePattern;
1235
		updateDirty(pViewRefPattern, referencePattern);
1236 1251
		resetLines();
1237 1252
	}
1238 1253

  
......
1243 1258
	 *            the new analysis property
1244 1259
	 */
1245 1260
	public void setRightAnalysisProperties(List<Property> selectedRightSortProperty) {
1261
		//updateDirty(pAnalysisRightProperties, selectedRightSortProperty);
1246 1262
		this.pAnalysisRightProperties = selectedRightSortProperty;
1247
		updateDirty(pAnalysisRightProperties, selectedRightSortProperty);
1248 1263
		resetLines();
1249 1264
	}
1250 1265

  
......
1255 1270
	 *            the new context size
1256 1271
	 */
1257 1272
	public void setRightContextSize(int size) {
1273
		//updateDirty(pRightContextSize, size);
1258 1274
		this.pRightContextSize = size;
1259
		updateDirty(pRightContextSize, size);
1260 1275
		resetLines();
1261 1276
	}
1262 1277

  
......
1567 1582
	}
1568 1583

  
1569 1584
	public void setLeftViewProperties(List<Property> selectedViewProperties) {
1585
		//updateDirty(pViewLeftProperties, selectedViewProperties);
1570 1586
		this.pViewLeftProperties = selectedViewProperties;
1571
		updateDirty(pViewLeftProperties, selectedViewProperties);
1572 1587
	}
1573 1588

  
1574 1589
	public void setRightViewProperties(List<Property> selectedViewProperties) {
1590
		//updateDirty(pViewRightProperties, selectedViewProperties);
1575 1591
		this.pViewRightProperties = selectedViewProperties;
1576
		updateDirty(pViewRightProperties, selectedViewProperties);
1577 1592
	}
1578 1593

  
1579 1594
	public void setKeywordViewProperties(List<Property> selectedViewProperties) {
1595
		//updateDirty(pViewKeywordProperties, selectedViewProperties);
1580 1596
		this.pViewKeywordProperties = selectedViewProperties;
1581
		updateDirty(pViewKeywordProperties, selectedViewProperties);
1582 1597
	}
1583 1598

  
1584 1599
	public List<Property> getAvailableLeftSortProperties() {
......
1594 1609
	 * @param query the query to set
1595 1610
	 */
1596 1611
	public void setQuery(Query query) {
1612
		//updateDirty(pQuery, query);
1597 1613
		this.pQuery = query;
1598
		updateDirty(pQuery, query);
1599 1614
	}
1600 1615

  
1601 1616
	public void setTopIndex(int i) {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditorPart.java (revision 548)
188 188
	
189 189
	@Override
190 190
	public void doSave(IProgressMonitor monitor) {
191
		// TODO Auto-generated method stub
191
//		if (!getResultData().saveParameters()) { // ?
192
//			
193
//		}
192 194
	}
193 195

  
194 196
	@Override
......
626 628
	
627 629

  
628 630
	/**
629
	 * Gets the parameters compiste.
631
	 * Gets the parameters composite.
630 632
	 * @return the composite that contains the TXMEditorToolBar parameters panels
631 633
	 */
632 634
	public Composite getParametersGroupsComposite() {
......
646 648
		}
647 649
		viewer.getControl().setRedraw(true);
648 650
	}
649
	
650 651
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/ComputeTXMResult.java (revision 548)
18 18
		}
19 19
		
20 20
		TXMEditorPart editor = (TXMEditorPart)page;
21
		editor.getResultData().setDirty(); //TODO: MD: I had to add this to recompute the concordance when the query field has been modified
21
		//editor.getResultData().setDirty(); //TODO: MD: I had to add this to recompute the concordance when the query field has been modified
22 22
		editor.updateResultFromEditor();
23
		editor.updateResultFromEditor();
23 24
		editor.compute(true);
24 25
		
25 26
		return null;
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/editors/vlcplayer/VLCPlayerEditor.java (revision 548)
78 78
	public boolean isResultUsingParent(TXMResult parent) {
79 79
		return false;
80 80
	}
81

  
82
	@Override
83
	public void updateResultFromEditor() {
84
		// nothing to do
85
	}
81 86
}
tmp/org.txm.synopticeditor.rcp/src/org/txm/rcp/synoptic/editor/SynopticEditionEditor.java (revision 548)
852 852
		editionsChooser.setText(StringUtils.join(editionNames, " | ")); //$NON-NLS-1$
853 853
		page_label.setText(""); //$NON-NLS-1$
854 854
	}
855

  
856
	@Override
857
	public void updateResultFromEditor() {
858
		// nothing to do
859
	}
855 860
}
tmp/org.txm.core/src/java/org/txm/core/results/Parameter.java (revision 548)
1
package org.txm.core.results;
2

  
3
import static java.lang.annotation.ElementType.FIELD;
4
import static java.lang.annotation.ElementType.METHOD;
5
import static java.lang.annotation.ElementType.PARAMETER;
6
import static java.lang.annotation.RetentionPolicy.RUNTIME;
7

  
8
import java.lang.annotation.Retention;
9
import java.lang.annotation.Target;
10

  
11
/**
12
 * An annotation to identify The TXMResult parameters
13
 * 
14
 * @author mdecorde
15
 *
16
 */
17
@Retention(RUNTIME)
18
@Target({FIELD,METHOD,PARAMETER})
19
public @interface Parameter {
20
	
21
}
0 22

  
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 548)
2 2

  
3 3
import java.io.File;
4 4
import java.io.IOException;
5
import java.lang.reflect.Field;
5 6
import java.text.DateFormat;
6 7
import java.text.SimpleDateFormat;
7 8
import java.util.ArrayList;
8 9
import java.util.Date;
10
import java.util.HashMap;
9 11
import java.util.UUID;
10 12
import java.util.concurrent.Semaphore;
11 13
import java.util.regex.Pattern;
......
39 41
	/** Editor can use this to test if the result need to be saved */
40 42
	protected boolean hasBeenComputedOnce = false;
41 43
	public boolean getHasBeenComputedOnce() { return hasBeenComputedOnce;}
42
	
44

  
43 45
	/**
44 46
	 * The weight, essentially used for sorting purpose.
45 47
	 */
......
103 105
		this.preferencesNodeQualifier = FrameworkUtil.getBundle(getClass()).getSymbolicName();
104 106

  
105 107
		this.constructorCalled = true; // if not set the compute method will
106
										// always return false
108
		// always return false
107 109
		// FIXME: Debug
108 110
		// System.out.println("TXMResult.TXMResult(): default preferences node qualifier = "
109 111
		// + this.preferencesNodeQualifier + ", class = " + getClass());
......
122 124
		return this.children.size() > 0;
123 125
	}
124 126

  
127
	protected HashMap<String, Object> lastComputeParameters = new HashMap<String, Object>();
128
	protected void updateLastComputeParameters() throws Exception {
129
		Field[] fields = this.getClass().getDeclaredFields();
130
		for (Field f : fields) {
131
			String name = f.getName();
132
			Parameter annotations = f.getAnnotation(Parameter.class);
133
			if (annotations == null) continue;
134
			f.setAccessible(true);
135
			lastComputeParameters.put(name, f.get(this));
136
		}
137
	}
138
	public HashMap<String, Object> getLastComputeParameters() {
139
		return lastComputeParameters;
140
	}
125 141
	/**
142
	 * Update the dirty states by comparing TXMResult @Parameter with previously used parameters in the compute() method.
143
	 * 
144
	 * To work correctly the equals method of the TXMResult parameters must be correctly implemented.
145
	 * 
146
	 * The method is final and don't need to be re-implemented. To ignore this method, don't use the @Parameter annotations
147
	 * 
148
	 * Implement isDirty if you need more test
149
	 * 
150
	 * @return
151
	 * @throws IllegalAccessException 
152
	 * @throws IllegalArgumentException 
153
	 */
154
	public final boolean isDirtyFromHistory() throws Exception {
155
		Class clazz = this.getClass();
156

  
157
		Field[] fields = clazz.getDeclaredFields();
158
		for (Field f : fields) {
159
			String name = f.getName();
160
			Parameter annotations = f.getAnnotation(Parameter.class);
161
			if (annotations == null) continue;
162
			f.setAccessible(true); // not to set accessible to test the field values
163
			Object previousValue = lastComputeParameters.get(name);
164
			Object newValue = f.get(this);
165
			updateDirty(previousValue, newValue);
166
			if (dirty) return dirty; // no need to go further
167
		}
168
		return dirty;
169
	}
170

  
171
	/**
126 172
	 * Gets the dirty states.
127 173
	 * 
128 174
	 * @return
......
146 192
	 * @param newParameter may be null
147 193
	 */
148 194
	protected void updateDirty(Object oldParameter, Object newParameter) {
149
		this.dirty = oldParameter == null || oldParameter.equals(newParameter);
195
		if (oldParameter == null || !oldParameter.equals(newParameter)) {
196
			Log.info("set dirty true : old="+oldParameter+" new="+newParameter);
197
			this.dirty = true;
198
		}
150 199
	}
151 200

  
152
	
201

  
153 202
	/**
154 203
	 * 
155 204
	 * @param parent
......
436 485
		return null;
437 486
	}
438 487

  
439
	
488

  
440 489
	/**
441 490
	 * Gets the children of all the branch of the specified node in a flat list.
442 491
	 * 
443 492
	 * @return
444 493
	 */
445 494
	synchronized protected ArrayList<TXMResult> getDeepChildren(TXMResult parent) {
446
		
495

  
447 496
		ArrayList<TXMResult> results = new ArrayList<TXMResult>();
448 497
		for (int i = 0; i < parent.getResults().size(); i++) {
449 498
			results.add(parent.getResults().get(i));
......
505 554
			if(parent.getClass().getSimpleName().equals(classSimpleName)) {
506 555
				node = parent;	
507 556
			}
508
			
557

  
509 558
			parent = parent.getParent();
510 559
		} while (parent != null && node == null);
511 560

  
......
519 568
	synchronized public TXMResult getParentMainCorpus() {
520 569
		return this.getFirstParent("MainCorpus"); //$NON-NLS-1$
521 570
	}
522
	
523 571

  
524 572
	/**
525 573
	 * Returns the first parent object that is a SubCorpus, a Corpus or a MainCorpus.
......
527 575
	 * @return
528 576
	 */
529 577
	synchronized public TXMResult getFirstParentCorpus() {
530
		
578

  
531 579
		// FIXME: need to validate/prove this method
532 580
		System.err.println("TXMResult.getFirstCorpusParent(): need to validate/prove this method.");
533
		
581

  
534 582
		TXMResult corpus = this.getFirstParent("Subcorpus"); //$NON-NLS-1$
535 583
		if(corpus == null)	{
536 584
			corpus = this.getFirstParent("Corpus"); //$NON-NLS-1$
......
541 589
		return corpus;
542 590
	}
543 591

  
544
	
545 592
	/**
546 593
	 * Gets the sibling nodes of this node result.
547 594
	 */
......
642 689
	}
643 690

  
644 691
	public static final Pattern filenamePattern = Pattern.compile("[^a-zA-Z0-9\\._-]+"); //$NON-NLS-1$
692
	public static final String UNDERSCORE = "_";
645 693
	/**
646 694
	 * Gets a string representing the result and that can be used as a file
647 695
	 * name.
......
651 699
	// FIXME: to discuss and/or to move in export layer
652 700
	public String getValidFileName() {
653 701
		try {
654
			return filenamePattern.matcher(this.getName()).replaceAll("_"); //$NON-NLS-1$
702
			return filenamePattern.matcher(this.getName()).replaceAll(UNDERSCORE); //$NON-NLS-1$
655 703
		} catch (Exception e) {
656 704
		}
657 705
		return "";
......
809 857
		// FIXME: Debug
810 858
		System.err.println("TXMResult.compute(): computing result of type " + this.getClass() + "...");
811 859

  
860
		if (!this.isDirtyFromHistory()) {
861

  
862
			// FIXME: Debug
863
			System.err.println("TXMResult.compute(): result parameters have not changed computing skipped.");
864

  
865
			return true;
866
		}
867

  
812 868
		if (!this.isDirty()) {
813
			
869

  
814 870
			// FIXME: Debug
815 871
			System.err.println("TXMResult.compute(): result is not dirty, computing skipped.");
816 872

  
817 873
			return true;
818 874
		}
819
		
875

  
820 876
		if (!hasBeenConstructorCalled()) {
821 877
			return false;
822 878
		}
......
829 885
		}
830 886

  
831 887
		if (!_compute(update)) {
832
			
888

  
833 889
			// FIXME: Debug
834 890
			System.err.println("TXMResult.compute(): computing failed.");
835
			
891

  
836 892
			return false;
837 893
		}
838 894

  
895
		updateLastComputeParameters(); // store last used parameters
896

  
839 897
		if (!saveParameters()) {
840 898
			System.out.println("Warning: "+this.getName()+" parameters are not saved.");
841 899
		}
......
885 943
	 * Copies the parameters from the local preference node if exists. Also fills the non existent parameters with the command default preferences.
886 944
	 */
887 945
	//public abstract void loadParameters();
888
	
946

  
889 947
	/**
890 948
	 * 
891 949
	 * @return the array of extensions to show in the FileDialog SWT widget
......
1006 1064
			monitor.subTask(name);
1007 1065
		}
1008 1066
	}
1009
	
1067

  
1010 1068
}
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 548)
957 957
			public void keyPressed(KeyEvent e) {
958 958
				// System.out.println("key pressed : "+e.keyCode);
959 959
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
960
					updateResultFromEditor();
961
					compute(true);
960
					//updateResultFromEditor();
961
					concordance.setQuery(queryWidget.getQuery());
962
					//compute(true);
962 963
				}
963 964
			}
964 965

  

Also available in: Unified diff