Révision 3556

TXM/trunk/org.txm.treesearch.rcp/src/org/txm/treesearch/command/SendToTreeSearch.java (revision 3556)
27 27
//
28 28
package org.txm.treesearch.command;
29 29

  
30
import java.io.IOException;
30 31
import java.util.List;
31 32

  
32 33
import org.eclipse.core.commands.ExecutionEvent;
33 34
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.jface.text.TextSelection;
34 36
import org.eclipse.jface.viewers.ISelection;
35 37
import org.eclipse.jface.viewers.StructuredSelection;
36 38
import org.eclipse.ui.handlers.HandlerUtil;
......
44 46
import org.txm.rcp.handlers.BaseAbstractHandler;
45 47
import org.txm.rcp.utils.SWTEditorsUtils;
46 48
import org.txm.searchengine.core.Selection;
49
import org.txm.searchengine.cqp.CQPSearchEngine;
50
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
51
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException;
52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53
import org.txm.searchengine.cqp.corpus.WordProperty;
54
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
55
import org.txm.searchengine.cqp.serverException.CqiServerError;
47 56
import org.txm.treesearch.editor.TreeSearchEditor;
48 57
import org.txm.treesearch.function.TreeSearch;
49 58
import org.txm.treesearch.rcp.Messages;
......
74 83
		if (editor instanceof ConcordanceEditor) {
75 84
			return concordancetoTree(editor, s);
76 85
		} else if (editor instanceof SynopticEditionEditor) {
77
			return editiontoTree(editor, s);
86
			try {
87
				return editiontoTree((SynopticEditionEditor) editor, s);
88
			}
89
			catch (Exception e) {
90
				// TODO Auto-generated catch block
91
				e.printStackTrace();
92
			}
93
		}
94
		
95
		return null;
96
	}
97
	
98
	public Object editiontoTree(SynopticEditionEditor editor, ISelection s) throws Exception {
99
		
100
		if (editor.getEditionPanels().size() == 0) { // broken or no edition
101
			return null;
102
		}
103
		
104
		int kp = -1;
105
		System.out.println("s="+s.getClass()+" "+s);
106

  
107
		String[] words = editor.getEditionPanel(0).getWordSelection();
108
		String word_id = null;
109
		if (words[0] != null && !words[0].isEmpty()) {
110
			word_id = words[0];
111
		
78 112
		} else {
113
			word_id = editor.getEditionPanel(0).getCurrentPage().getWordId();
114
		}
115
		
116
		if (word_id != null) {
117
			WordProperty p_id = editor.getCorpus().getProperty("id");
118
			Selection sel = CQPSearchEngine.getEngine().query(editor.getCorpus(), new CQLQuery("[id=\""+word_id+"\" & _.text_id=\""+editor.getResult().getName()+"\"]"), "TMP", false);
119
			if (sel.getNMatch() > 0) {
120
				kp = sel.getMatches().get(0).getStart();
121
			}
122
		}
123
		
124
		if (kp == -1) {
125
			Log.warning("No word found to show");
79 126
			return null;
80 127
		}
128
		
129
		return toTree(editor, s, kp, editor.getCorpus());
81 130
	}
82 131
	
83
	public Object editiontoTree(ITXMResultEditor<? extends TXMResult> editor, ISelection s) {
84
		System.out.println("Send EDITION TO TREE");
85
		return null;
86
	}
87
	
88 132
	public Object concordancetoTree(ITXMResultEditor<? extends TXMResult> editor, ISelection s) {
89 133
		TXMResult r = editor.getResult();
90 134
		
......
114 158
		}
115 159
		Line l = (Line)o;
116 160
		//TreeSearchSelector selector = ComputeTreeSearch.getSelectorForCorpus(concordance.getCorpus(), "UD");
161
	
162
		int kp = l.getKeywordPosition();
117 163
		
164
		return toTree(editor, s, kp, concordance.getCorpus());
165
	}
166
	
167
	public Object toTree(ITXMResultEditor<? extends TXMResult> editor, ISelection s, int kp, CQPCorpus corpus) {
168
		TXMResult r = editor.getResult();
169
		
170
		//TreeSearchSelector selector = ComputeTreeSearch.getSelectorForCorpus(concordance.getCorpus(), "UD");
171
		
118 172
		TreeSearchEditor leditor = editor.getLinkedEditor(TreeSearchEditor.class);
119 173
		TreeSearch ts = null;
120 174
		if (leditor != null) {
121 175
			ts = leditor.getResult();
122 176
			ts.setQuery(null);
123 177
		} else {
124
			ts = ComputeTreeSearch.getTreeSearchFor(concordance.getCorpus());
178
			ts = ComputeTreeSearch.getTreeSearchFor(corpus);
125 179
			ts.setQuery(null);
126 180
		}
127 181
		//ts.setQuery(concordance.getQuery());
......
129 183
		try {
130 184
			boolean c = ts.compute();
131 185
			Selection sel = ts.getSelection();
132
			int kp = l.getKeywordPosition();
186
			
133 187
//			System.out.println("KP="+kp);
134 188
			if (c &&  sel != null) {
135 189
				int i = 0;

Formats disponibles : Unified diff