Révision 3744
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/preferences/UserPreferencePage.java (revision 3744) | ||
---|---|---|
68 | 68 |
// this.addField(new BooleanFieldEditor(RCPPreferences.AUTO_COMPUTE_ON_EDITOR_OPEN, "Compute when opening its window", BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent())); |
69 | 69 |
|
70 | 70 |
// Auto save each result after computing and auto load them at startup |
71 |
this.addField(new BooleanFieldEditor(TBXPreferences.AUTO_PERSISTENCE_ENABLED, TXMUIMessages.enableAutomaticSaveOfAllResultsPersistence, BooleanFieldEditor.SEPARATE_LABEL, this |
|
72 |
.getFieldEditorParent())); |
|
71 |
this.addField(new BooleanFieldEditor(TBXPreferences.AUTO_PERSISTENCE_ENABLED, TXMUIMessages.enableAutomaticSaveOfAllResultsPersistence, BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent())); |
|
73 | 72 |
|
74 | 73 |
this.addField(new IntegerFieldEditor(RCPPreferences.MAX_NUMBER_OF_COLUMNS, "The maximum number of columns shown in tables", this.getFieldEditorParent())); |
75 | 74 |
|
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditorToolBar.java (revision 3744) | ||
---|---|---|
72 | 72 |
super(parent, style); |
73 | 73 |
|
74 | 74 |
FillLayout layout = new FillLayout(); |
75 |
layout.spacing = 1; |
|
75 | 76 |
this.setLayout(layout); |
76 | 77 |
|
77 | 78 |
this.editorPart = editor; |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedChoiceQueryWidget.java (revision 3744) | ||
---|---|---|
58 | 58 |
* @author mdecorde. |
59 | 59 |
*/ |
60 | 60 |
public class AssistedChoiceQueryWidget extends Composite { |
61 |
|
|
61 |
|
|
62 | 62 |
/** The magicstick button: opens the QueryAssist dialog. */ |
63 | 63 |
protected Button magicstick; |
64 |
|
|
64 |
|
|
65 | 65 |
/** The querywidget. */ |
66 | 66 |
protected QueryWidget querywidget; |
67 |
|
|
67 |
|
|
68 | 68 |
protected QueryAssistDialog d; |
69 |
|
|
69 |
|
|
70 | 70 |
// protected ComboViewer engineCombo; |
71 |
|
|
71 |
|
|
72 | 72 |
protected List<SearchEngine> engines; |
73 |
|
|
73 |
|
|
74 | 74 |
private GridData magcistickGData; |
75 |
|
|
75 |
|
|
76 | 76 |
private Button settingsButton; |
77 |
|
|
77 |
|
|
78 | 78 |
private Label selectedEngineLabel; |
79 |
|
|
79 |
|
|
80 | 80 |
/** |
81 | 81 |
* Instantiates a new assisted query widget. |
82 | 82 |
* |
... | ... | |
87 | 87 |
public AssistedChoiceQueryWidget(Composite parent, int style, final CQPCorpus corpus) { |
88 | 88 |
super(parent, SWT.NONE); |
89 | 89 |
this.setLayout(GLComposite.createDefaultLayout(5)); |
90 |
|
|
90 |
|
|
91 | 91 |
engines = SearchEnginesManager.getAvailableEngines(corpus.getMainCorpus()); |
92 | 92 |
SearchEngine initialEngine = null; |
93 | 93 |
if (engines.size() > 1) { |
94 |
|
|
94 |
|
|
95 | 95 |
// set default engine |
96 | 96 |
String defaultEngineName = SearchEnginePreferences.getInstance().getString(SearchEnginePreferences.DEFAULT_SEARCH_ENGINE); |
97 | 97 |
int iDefault = -1; |
... | ... | |
105 | 105 |
iSuperDefault = i; |
106 | 106 |
} |
107 | 107 |
} |
108 |
|
|
108 |
|
|
109 | 109 |
if (iDefault >= 0) { |
110 | 110 |
initialEngine = engines.get(iDefault); |
111 | 111 |
} |
... | ... | |
116 | 116 |
else { |
117 | 117 |
initialEngine = engines.get(0); |
118 | 118 |
} |
119 |
|
|
119 |
|
|
120 | 120 |
selectedEngineLabel = new Label(this, SWT.NONE); |
121 | 121 |
selectedEngineLabel.setText(""); //$NON-NLS-1$ |
122 | 122 |
GridData gdata = new GridData(GridData.FILL, GridData.CENTER, false, false); |
123 | 123 |
selectedEngineLabel.setLayoutData(gdata); |
124 |
|
|
124 |
|
|
125 | 125 |
if (SearchEnginePreferences.getInstance().getBoolean(SearchEnginePreferences.SHOW_SEARCH_ENGINES)) { |
126 |
|
|
126 | 127 |
settingsButton = new Button(this, SWT.PUSH); |
127 | 128 |
settingsButton.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); |
128 | 129 |
settingsButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_SEARCH_SETTINGS)); |
129 |
settingsButton.setToolTipText(TXMUIMessages.openTheQueryAssistant);
|
|
130 |
settingsButton.setToolTipText("Query options");
|
|
130 | 131 |
settingsButton.addSelectionListener(new SelectionListener() { |
131 |
|
|
132 |
|
|
132 | 133 |
@Override |
133 | 134 |
public void widgetSelected(SelectionEvent e) { |
134 |
ArrayList<String> values = new ArrayList<>(); |
|
135 |
for (SearchEngine se : engines) { |
|
136 |
values.add(se.getName()); |
|
137 |
} |
|
138 |
ComboDialog dialog = new ComboDialog(e.display.getActiveShell(), "Engines", values, querywidget.getSearchEngine().getName()); //$NON-NLS-1$ |
|
135 |
|
|
136 |
QueryOptionsDialog dialog = new QueryOptionsDialog(e.display.getActiveShell(), corpus, engines, querywidget.getSearchEngine().getName()); //$NON-NLS-1$ |
|
139 | 137 |
if (dialog.open() == ComboDialog.OK) { |
140 |
String name = dialog.getSelectedValue(); |
|
141 |
for (SearchEngine se : engines) { |
|
142 |
if (se.getName().equals(name)) { |
|
143 |
changeEngine(se); |
|
144 |
return; |
|
145 |
} |
|
138 |
SearchEngine se = dialog.getSelectedEngine(); |
|
139 |
if (se != null && !se.getName().equals(querywidget.getSearchEngine().getName())) { |
|
140 |
changeEngine(se); |
|
141 |
return; |
|
146 | 142 |
} |
147 | 143 |
} |
148 | 144 |
} |
149 |
|
|
145 |
|
|
150 | 146 |
@Override |
151 | 147 |
public void widgetDefaultSelected(SelectionEvent e) {} |
152 | 148 |
}); |
153 | 149 |
} |
154 |
|
|
150 |
|
|
155 | 151 |
magicstick = new Button(this, SWT.PUSH); |
156 | 152 |
magcistickGData = new GridData(GridData.FILL, GridData.CENTER, false, false); |
157 | 153 |
magicstick.setLayoutData(magcistickGData); |
158 | 154 |
magicstick.setImage(IImageKeys.getImage(IImageKeys.ACTION_ASSISTQUERY)); |
159 | 155 |
magicstick.setToolTipText(TXMUIMessages.openTheQueryAssistant); |
160 | 156 |
magicstick.addSelectionListener(new SelectionListener() { |
161 |
|
|
157 |
|
|
162 | 158 |
@Override |
163 | 159 |
public void widgetSelected(SelectionEvent e) { |
164 | 160 |
d = new QueryAssistDialog(e.display.getActiveShell(), corpus); |
... | ... | |
166 | 162 |
querywidget.setText(d.getQuery()); |
167 | 163 |
} |
168 | 164 |
} |
169 |
|
|
165 |
|
|
170 | 166 |
@Override |
171 | 167 |
public void widgetDefaultSelected(SelectionEvent e) {} |
172 | 168 |
}); |
173 |
|
|
169 |
|
|
174 | 170 |
setMagicEnabled("CQP".equals(initialEngine.getName())); //$NON-NLS-1$ |
175 |
|
|
171 |
|
|
176 | 172 |
querywidget = new QueryWidget(this, style, corpus.getProject(), initialEngine); |
177 | 173 |
querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
178 | 174 |
} |
179 |
|
|
175 |
|
|
180 | 176 |
protected void changeEngine(SearchEngine se) { |
181 | 177 |
querywidget.setSearchEngine(se); |
182 |
|
|
178 |
|
|
183 | 179 |
// GridData gdata = (GridData) querywidget.getLayoutData(); |
184 | 180 |
// gdata.heightHint = -1; |
185 | 181 |
// querywidget.layout(); |
186 | 182 |
// relayout(); |
187 |
|
|
188 |
setMagicEnabled("CQP".equals(se.getName())); //$NON-NLS-1$ |
|
189 |
|
|
183 |
|
|
184 |
setMagicEnabled("CQP".equals(se.getName()) || "CQP".equals(se.getOptionForSearchengine())); //$NON-NLS-1$
|
|
185 |
|
|
190 | 186 |
String defaultEngineName = SearchEnginePreferences.getInstance().getString(SearchEnginePreferences.DEFAULT_SEARCH_ENGINE); |
191 | 187 |
if (defaultEngineName.equals(se.getName())) { |
192 | 188 |
selectedEngineLabel.setText(""); //$NON-NLS-1$ |
193 | 189 |
} |
190 |
else if (se.getOptionNameForSearchengine() != null) { |
|
191 |
selectedEngineLabel.setText(" " + se.getOptionNameForSearchengine() + " "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
192 |
} |
|
194 | 193 |
else { |
195 | 194 |
selectedEngineLabel.setText(" " + se.getName() + " "); //$NON-NLS-1$ //$NON-NLS-2$ |
196 | 195 |
} |
197 | 196 |
selectedEngineLabel.getParent().layout(); |
198 | 197 |
} |
199 |
|
|
198 |
|
|
200 | 199 |
private void setMagicEnabled(boolean b) { |
201 | 200 |
magicstick.setEnabled(b); |
202 |
|
|
201 |
|
|
203 | 202 |
if (b) { |
204 | 203 |
magcistickGData.widthHint = magcistickGData.minimumWidth = SWT.DEFAULT; |
205 | 204 |
} |
... | ... | |
208 | 207 |
} |
209 | 208 |
magicstick.getParent().layout(); |
210 | 209 |
} |
211 |
|
|
210 |
|
|
212 | 211 |
protected void relayout() { |
213 | 212 |
Composite parent = AssistedChoiceQueryWidget.this.getParent(); |
214 | 213 |
// parent.layout(true); |
... | ... | |
228 | 227 |
// parent = parent.getParent(); |
229 | 228 |
// } |
230 | 229 |
} |
231 |
|
|
230 |
|
|
232 | 231 |
@Override |
233 | 232 |
public void setEnabled(boolean b) { |
234 | 233 |
super.setEnabled(b); |
235 | 234 |
querywidget.setEnabled(b); |
236 | 235 |
} |
237 |
|
|
236 |
|
|
238 | 237 |
public void setSearchEngine(SearchEngine engine) { |
239 | 238 |
int i = engines.indexOf(engine); |
240 | 239 |
if (i >= 0) { |
241 | 240 |
changeEngine(engine); |
242 | 241 |
} |
243 | 242 |
} |
244 |
|
|
243 |
|
|
245 | 244 |
public void setSearchEngine(String name) { |
246 | 245 |
for (int i = 0; i < engines.size(); i++) { |
247 | 246 |
if (name.equals(engines.get(i).getName())) { |
... | ... | |
249 | 248 |
} |
250 | 249 |
} |
251 | 250 |
} |
252 |
|
|
251 |
|
|
253 | 252 |
public QueryWidget getQueryWidget() { |
254 | 253 |
return querywidget; |
255 | 254 |
} |
256 |
|
|
255 |
|
|
257 | 256 |
@Override |
258 | 257 |
public boolean setFocus() { |
259 | 258 |
return this.querywidget.setFocus(); |
260 | 259 |
} |
261 |
|
|
260 |
|
|
262 | 261 |
/* |
263 | 262 |
* (non-Javadoc) |
264 | 263 |
* @see org.eclipse.swt.widgets.Control#addKeyListener(org.eclipse.swt.events.KeyListener) |
... | ... | |
268 | 267 |
if (querywidget != null) |
269 | 268 |
this.querywidget.addKeyListener(listener); |
270 | 269 |
} |
271 |
|
|
270 |
|
|
272 | 271 |
/** |
273 | 272 |
* Gets the query string. |
274 | 273 |
* |
... | ... | |
277 | 276 |
public String getQueryString() { |
278 | 277 |
return querywidget.getQueryString(); |
279 | 278 |
} |
280 |
|
|
279 |
|
|
281 | 280 |
/** |
282 | 281 |
* Gets the query string. |
283 | 282 |
* |
... | ... | |
286 | 285 |
public String getRawString() { |
287 | 286 |
return querywidget.getText(); |
288 | 287 |
} |
289 |
|
|
288 |
|
|
290 | 289 |
/** |
291 | 290 |
* Memorize. |
292 | 291 |
*/ |
293 | 292 |
public void memorize() { |
294 | 293 |
querywidget.memorize(); |
295 | 294 |
} |
296 |
|
|
295 |
|
|
297 | 296 |
/** |
298 | 297 |
* Memorize. |
299 | 298 |
* |
... | ... | |
302 | 301 |
public void memorize(String query) { |
303 | 302 |
querywidget.memorize(query); |
304 | 303 |
} |
305 |
|
|
304 |
|
|
306 | 305 |
/** |
307 | 306 |
* Clears the query test. |
308 | 307 |
*/ |
309 | 308 |
public void clearQuery() { |
310 | 309 |
this.querywidget.setText(""); //$NON-NLS-1$ |
311 | 310 |
} |
312 |
|
|
311 |
|
|
313 | 312 |
/** |
314 | 313 |
* Sets the text. |
315 | 314 |
* |
316 | 315 |
* @param query the new text |
317 | 316 |
*/ |
318 | 317 |
public void setText(String query) { |
319 |
|
|
318 |
|
|
320 | 319 |
// if(query.isEmpty()) { |
321 | 320 |
// query = ""; //$NON-NLS-1$ |
322 | 321 |
// } |
323 |
|
|
322 |
|
|
324 | 323 |
// fix the query |
325 | 324 |
// query = query.replaceAll("^\"(.*)\"$","$1"); //$NON-NLS-1$ -> don't work for the '"A" "B"' queries |
326 |
|
|
325 |
|
|
327 | 326 |
querywidget.setText(query); |
328 | 327 |
} |
329 |
|
|
328 |
|
|
330 | 329 |
public IQuery getQuery() { |
331 | 330 |
return this.querywidget.getQuery(); |
332 | 331 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/QueryOptionsDialog.java (revision 3744) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.swt.widget; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.LinkedHashMap; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.eclipse.jface.dialogs.Dialog; |
|
36 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
37 |
import org.eclipse.jface.viewers.ComboViewer; |
|
38 |
import org.eclipse.jface.viewers.ListViewer; |
|
39 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
40 |
import org.eclipse.swt.SWT; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.events.SelectionListener; |
|
43 |
import org.eclipse.swt.layout.GridData; |
|
44 |
import org.eclipse.swt.layout.GridLayout; |
|
45 |
import org.eclipse.swt.widgets.Button; |
|
46 |
import org.eclipse.swt.widgets.Combo; |
|
47 |
import org.eclipse.swt.widgets.Composite; |
|
48 |
import org.eclipse.swt.widgets.Control; |
|
49 |
import org.eclipse.swt.widgets.Group; |
|
50 |
import org.eclipse.swt.widgets.Label; |
|
51 |
import org.eclipse.swt.widgets.Shell; |
|
52 |
import org.txm.rcp.swt.provider.SimpleLabelProvider; |
|
53 |
import org.txm.searchengine.core.SearchEngine; |
|
54 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
55 |
|
|
56 |
/** |
|
57 |
* Set the Query options to use (set the right Query class to use) |
|
58 |
*/ |
|
59 |
public class QueryOptionsDialog extends Dialog { |
|
60 |
|
|
61 |
/** The self. */ |
|
62 |
QueryOptionsDialog self; |
|
63 |
|
|
64 |
/** The main panel. */ |
|
65 |
Composite mainPanel; |
|
66 |
|
|
67 |
/** The parent shell. */ |
|
68 |
Shell parentShell; |
|
69 |
|
|
70 |
/** The values. */ |
|
71 |
ArrayList<SearchEngine> values; |
|
72 |
|
|
73 |
/** The combo. */ |
|
74 |
private ComboViewer combo; |
|
75 |
|
|
76 |
/** The selected index. */ |
|
77 |
private SearchEngine selectedEngine; |
|
78 |
|
|
79 |
/** The default value. */ |
|
80 |
private String defaultValue; |
|
81 |
|
|
82 |
/** The title. */ |
|
83 |
private String title; |
|
84 |
|
|
85 |
CQPCorpus corpus; |
|
86 |
List<SearchEngine> engines; |
|
87 |
|
|
88 |
LinkedHashMap<String, ArrayList<SearchEngine>> options = new LinkedHashMap<String, ArrayList<SearchEngine>>(); |
|
89 |
|
|
90 |
private Label selectOptionsLabel; |
|
91 |
|
|
92 |
private Button noneOption; |
|
93 |
|
|
94 |
private Group optionsGroup; |
|
95 |
|
|
96 |
public QueryOptionsDialog(Shell parentShell, CQPCorpus corpus, List<SearchEngine> engines2, String defaultValue) { |
|
97 |
super(parentShell); |
|
98 |
|
|
99 |
this.corpus = corpus; |
|
100 |
this.engines = engines2; |
|
101 |
this.parentShell = parentShell; |
|
102 |
this.setShellStyle(this.getShellStyle()); |
|
103 |
|
|
104 |
this.values = new ArrayList<SearchEngine>(); |
|
105 |
for (SearchEngine se : engines2) { |
|
106 |
|
|
107 |
if (se.hasIndexes(corpus)) { // show only if corpus has indexes AND if the se is not an option of CQPSearchEngine |
|
108 |
if (se.getOptionForSearchengine() == null) { |
|
109 |
values.add(se); |
|
110 |
} else { |
|
111 |
if (!options.containsKey(se.getOptionForSearchengine())) { |
|
112 |
options.put(se.getOptionForSearchengine(), new ArrayList<SearchEngine>()); |
|
113 |
} |
|
114 |
options.get(se.getOptionForSearchengine()).add(se); |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
this.defaultValue = defaultValue; |
|
119 |
this.title = "Query options"; |
|
120 |
} |
|
121 |
|
|
122 |
/* (non-Javadoc) |
|
123 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
|
124 |
*/ |
|
125 |
@Override |
|
126 |
protected void configureShell(Shell newShell) { |
|
127 |
super.configureShell(newShell); |
|
128 |
newShell.setText(title); |
|
129 |
} |
|
130 |
|
|
131 |
/* (non-Javadoc) |
|
132 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
protected Control createDialogArea(Composite p) { |
|
136 |
//System.out.println(p.getLayout()); |
|
137 |
GridLayout layout = (GridLayout) p.getLayout(); |
|
138 |
layout.verticalSpacing = 5; |
|
139 |
layout.marginBottom = 5; |
|
140 |
layout.marginTop = 5; |
|
141 |
layout.marginLeft = 5; |
|
142 |
layout.marginRight = 5; |
|
143 |
|
|
144 |
Label l = new Label(p, SWT.NONE); |
|
145 |
l.setText("Select between the following engines"); |
|
146 |
l.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1)); |
|
147 |
combo = new ComboViewer(new Combo(p, SWT.READ_ONLY | SWT.SINGLE)); |
|
148 |
combo.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1)); |
|
149 |
//combo.setItems(values.toArray(new String[] {})); |
|
150 |
combo.getCombo().addSelectionListener(new SelectionListener() { |
|
151 |
|
|
152 |
@Override |
|
153 |
public void widgetSelected(SelectionEvent e) { |
|
154 |
updateOptions(); |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
159 |
}); |
|
160 |
|
|
161 |
combo.setLabelProvider(new SimpleLabelProvider() { |
|
162 |
/** |
|
163 |
* The <code>LabelProvider</code> implementation of this |
|
164 |
* <code>ILabelProvider</code> method returns the element's |
|
165 |
* <code>toString</code> string. Subclasses may override. |
|
166 |
*/ |
|
167 |
@Override |
|
168 |
public String getText(Object element) { |
|
169 |
return element == null ? "" : ((SearchEngine)element).getName(); |
|
170 |
} |
|
171 |
|
|
172 |
}); |
|
173 |
combo.setContentProvider(new ArrayContentProvider()); |
|
174 |
combo.setInput(values); |
|
175 |
|
|
176 |
|
|
177 |
optionsGroup = new Group(p, SWT.BORDER); |
|
178 |
optionsGroup.setLayout(new GridLayout(1, true)); |
|
179 |
optionsGroup.setText("Options"); |
|
180 |
optionsGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1)); |
|
181 |
|
|
182 |
noneOption = new Button(optionsGroup, SWT.RADIO); |
|
183 |
|
|
184 |
if (defaultValue != null) { |
|
185 |
selectValue(defaultValue); |
|
186 |
} |
|
187 |
|
|
188 |
updateOptions(); |
|
189 |
|
|
190 |
return p; |
|
191 |
} |
|
192 |
|
|
193 |
public void updateOptions() { |
|
194 |
|
|
195 |
Object o = combo.getStructuredSelection().getFirstElement(); |
|
196 |
if (o == null) { |
|
197 |
return; // nothing to do |
|
198 |
} |
|
199 |
if (o == selectedEngine) { |
|
200 |
return; // nothing to do |
|
201 |
} |
|
202 |
|
|
203 |
for (Control c : optionsGroup.getChildren()) { |
|
204 |
c.dispose(); |
|
205 |
} |
|
206 |
|
|
207 |
noneOption = new Button(optionsGroup, SWT.RADIO); |
|
208 |
noneOption.setText("No option"); |
|
209 |
noneOption.setSelection(true); |
|
210 |
|
|
211 |
selectedEngine = (SearchEngine)o; |
|
212 |
if (options.containsKey(selectedEngine.getName())) { |
|
213 |
for (final SearchEngine se : options.get(selectedEngine.getName())) { |
|
214 |
Button option = new Button(optionsGroup, SWT.RADIO); |
|
215 |
option.setText(se.getOptionNameForSearchengine()+ " : " + se.getOptionDescriptionForSearchengine()); |
|
216 |
if (se.getName().equals(defaultValue)) { |
|
217 |
option.setSelection(true); |
|
218 |
option.addSelectionListener(new SelectionListener() { |
|
219 |
|
|
220 |
@Override |
|
221 |
public void widgetSelected(SelectionEvent e) { |
|
222 |
selectedEngine = se; |
|
223 |
} |
|
224 |
|
|
225 |
@Override |
|
226 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
227 |
}); |
|
228 |
noneOption.setSelection(false); |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
optionsGroup.layout(); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Gets the selected value. |
|
237 |
* |
|
238 |
* @return the selected value |
|
239 |
*/ |
|
240 |
public SearchEngine getSelectedEngine() { |
|
241 |
return selectedEngine; |
|
242 |
} |
|
243 |
|
|
244 |
/** |
|
245 |
* Select value. |
|
246 |
* |
|
247 |
* @param string the string |
|
248 |
*/ |
|
249 |
public void selectValue(String string) { |
|
250 |
for (int i = 0; i < values.size(); i++) |
|
251 |
if (values.get(i).getName().equals(string)) { |
|
252 |
combo.setSelection(new StructuredSelection(values.get(i))); |
|
253 |
break; |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
0 | 257 |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/engines/Engine.java (revision 3744) | ||
---|---|---|
35 | 35 |
|
36 | 36 |
/** |
37 | 37 |
* Starts the engine. |
38 |
* |
|
38 | 39 |
* @param monitor |
39 |
* @return |
|
40 |
* @return true if the engine is well started
|
|
40 | 41 |
* @throws Exception |
41 | 42 |
*/ |
42 | 43 |
public abstract boolean start(IProgressMonitor monitor) throws Exception; |
43 | 44 |
|
44 | 45 |
/** |
45 | 46 |
* Stops the engine. |
46 |
* @return |
|
47 |
* @return true if the engine is stopped
|
|
47 | 48 |
* @throws Exception |
48 | 49 |
*/ |
49 | 50 |
public abstract boolean stop() throws Exception; |
... | ... | |
59 | 60 |
|
60 | 61 |
/** |
61 | 62 |
* Gets description of the engine. |
63 |
* |
|
62 | 64 |
* @return details about the engine (eg. the elements managed) |
63 | 65 |
*/ |
64 | 66 |
public String getDetails(); |
65 | 67 |
|
68 |
/** |
|
69 |
* gives an information name about a result if the engine needs to |
|
70 |
*/ |
|
66 | 71 |
public String hasAdditionalDetailsForResult(TXMResult result); |
67 | 72 |
|
68 | 73 |
public String getAdditionalDetailsForResult(TXMResult result); |
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java (revision 3744) | ||
---|---|---|
51 | 51 |
|
52 | 52 |
this.corpus = getParent(); |
53 | 53 |
|
54 |
String id = corpus.getRootCorpusBuild().getID();
|
|
54 |
String id = corpus.getMainCorpus().getID();
|
|
55 | 55 |
|
56 | 56 |
File tsRegistryDirectory = new File(corpus.getProjectDirectory(), "tiger"); //$NON-NLS-1$ |
57 | 57 |
File configfile = new File(tsRegistryDirectory, "tigersearch.logprop"); //$NON-NLS-1$ |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/function/UDTreeSearch.java (revision 3744) | ||
---|---|---|
121 | 121 |
} |
122 | 122 |
} |
123 | 123 |
|
124 |
|
|
125 |
// if (NT != null && corpus.getProperty(NT) != null) { |
|
126 |
// NTvalues = corpus.getProperty(NT).cpos2Str(positions); |
|
127 |
// } |
|
128 |
HashMap<String, String[]> values = new HashMap<>(); |
|
124 |
HashMap<String, String[]> values = new HashMap<>(); // prepare an array of empty values in case of missing properties |
|
129 | 125 |
String[] emptyvalues = new String[positions.length]; |
130 | 126 |
for (int i = 0 ; i < emptyvalues.length ; i++) { |
131 | 127 |
emptyvalues[i] = "_"; |
132 | 128 |
} |
129 |
|
|
133 | 130 |
for (String p : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
134 | 131 |
|
135 | 132 |
if (corpus.getProperty(prefix+p) != null) { |
136 | 133 |
values.put(prefix+p, corpus.getProperty(prefix+p).cpos2Str(positions)); |
134 |
} else if (p.equals("form")) { // in case the prefix-form properties was not found use the "word" property |
|
135 |
values.put(prefix+p, corpus.getWordProperty().cpos2Str(positions)); |
|
137 | 136 |
} else { // in case the CQP property does not exists, use empty values |
138 | 137 |
values.put(prefix+p, emptyvalues); |
139 | 138 |
} |
... | ... | |
374 | 373 |
|
375 | 374 |
@Override |
376 | 375 |
public boolean hasSubMatchesStrategy() { |
377 |
|
|
376 |
|
|
378 | 377 |
return true; |
379 | 378 |
} |
380 | 379 |
|
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/search/UDSearchEngine.java (revision 3744) | ||
---|---|---|
1 | 1 |
package org.txm.conllu.core.search; |
2 | 2 |
|
3 |
import java.util.Arrays; |
|
4 | 3 |
import java.util.List; |
5 | 4 |
|
6 | 5 |
import org.eclipse.core.runtime.IProgressMonitor; |
7 | 6 |
import org.txm.Toolbox; |
8 | 7 |
import org.txm.conllu.core.function.UDTreeSearch; |
9 |
import org.txm.conllu.core.function.UDTreeSearchSelector; |
|
10 | 8 |
import org.txm.conllu.core.preferences.UDPreferences; |
11 | 9 |
import org.txm.core.engines.EngineType; |
12 | 10 |
import org.txm.core.preferences.TXMPreferences; |
... | ... | |
31 | 29 |
* |
32 | 30 |
*/ |
33 | 31 |
public class UDSearchEngine extends SearchEngine { |
34 |
|
|
32 |
|
|
35 | 33 |
public static final String NAME = "UD"; |
36 |
|
|
34 |
|
|
37 | 35 |
CQPSearchEngine CQI; |
38 | 36 |
|
39 | 37 |
private CQPSearchEngine getCQI() { |
40 |
|
|
38 |
|
|
41 | 39 |
if (CQI == null) { |
42 | 40 |
CQI = CQPSearchEngine.getEngine(); |
43 | 41 |
} |
44 | 42 |
return CQI; |
45 | 43 |
} |
46 |
|
|
44 |
|
|
45 |
public String getOptionForSearchengine() { |
|
46 |
return "CQP"; |
|
47 |
} |
|
48 |
|
|
49 |
public String getOptionNameForSearchengine() { |
|
50 |
return "ud-s"; |
|
51 |
} |
|
52 |
|
|
53 |
public String getOptionDescriptionForSearchengine() { |
|
54 |
return "Work with the ud-s subcorpus of the UD sentences"; |
|
55 |
} |
|
56 |
|
|
47 | 57 |
@Override |
48 | 58 |
public boolean isRunning() { |
49 |
|
|
59 |
|
|
50 | 60 |
return getCQI().isRunning(); |
51 | 61 |
} |
52 | 62 |
|
... | ... | |
68 | 78 |
|
69 | 79 |
@Override |
70 | 80 |
public void notify(TXMResult r, String state) { |
71 |
|
|
81 |
|
|
72 | 82 |
} |
73 | 83 |
|
74 | 84 |
@Override |
... | ... | |
78 | 88 |
|
79 | 89 |
@Override |
80 | 90 |
public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception { |
81 |
|
|
91 |
|
|
82 | 92 |
if (corpus instanceof CQPCorpus) { |
83 | 93 |
CQPCorpus cqpCorpus = (CQPCorpus)corpus; |
84 | 94 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
85 | 95 |
Subcorpus udsentences = getSentenceSubcorpus(cqpCorpus, prefix); |
86 |
|
|
96 |
|
|
87 | 97 |
return getCQI().query(udsentences, query, name, saveQuery); |
88 | 98 |
} |
89 | 99 |
return new EmptySelection(query); |
... | ... | |
97 | 107 |
|
98 | 108 |
@Override |
99 | 109 |
public boolean hasIndexes(CorpusBuild corpus) { |
100 |
return getCQI().hasIndexes(corpus); |
|
110 |
return corpus instanceof CQPCorpus // HAS CQP INDEXES |
|
111 |
&& UDTreeSearch.hasUDProperties((CQPCorpus)corpus); // AND THE ud-id property |
|
101 | 112 |
} |
102 | 113 |
|
103 | 114 |
@Override |
104 | 115 |
public String getValueForProperty(Match match, SearchEngineProperty property) { |
105 |
|
|
116 |
|
|
106 | 117 |
return getCQI().getValueForProperty(match, property); |
107 | 118 |
} |
108 | 119 |
|
109 | 120 |
@Override |
110 | 121 |
public List<String> getValuesForProperty(Match match, SearchEngineProperty property) { |
111 |
|
|
122 |
|
|
112 | 123 |
return getCQI().getValuesForProperty(match, property); |
113 | 124 |
} |
114 | 125 |
|
115 | 126 |
public static SearchEngine getEngine() { |
116 |
|
|
127 |
|
|
117 | 128 |
return (UDSearchEngine) Toolbox.getEngineManager(EngineType.SEARCH).getEngine(UDSearchEngine.NAME); |
118 | 129 |
} |
119 |
|
|
130 |
|
|
120 | 131 |
public static Subcorpus getSentenceSubcorpus(CQPCorpus corpus, String prefix) throws CqiClientException, InterruptedException { |
121 |
|
|
132 |
|
|
122 | 133 |
Subcorpus udSentences = corpus.getSubcorpusByName(corpus.getName()+TXMPreferences.PARENT_NAME_SEPARATOR+"ud-s"); |
123 | 134 |
if (udSentences != null) udSentences.compute(false); |
124 |
|
|
135 |
|
|
125 | 136 |
CQLQuery sentencesQuery = new CQLQuery("["+prefix+"id=\"1\"] ["+prefix+"id !=\"1\"]+ [:"+prefix+"id=\"1|__UNDEF__\":]"); |
126 | 137 |
if (udSentences == null) { // no ud-s subcorpus, create it |
127 | 138 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-s"); |
... | ... | |
131 | 142 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-s"); |
132 | 143 |
udSentences.setVisible(false); |
133 | 144 |
} |
134 |
|
|
145 |
|
|
135 | 146 |
return udSentences; |
136 | 147 |
} |
137 | 148 |
|
... | ... | |
142 | 153 |
} |
143 | 154 |
return null; |
144 | 155 |
} |
145 |
|
|
156 |
|
|
146 | 157 |
public String getAdditionalDetailsForResult(TXMResult result) { |
147 | 158 |
if (result instanceof CQPCorpus) { |
148 | 159 |
CQPCorpus corpus = (CQPCorpus)result; |
149 | 160 |
if (UDTreeSearch.hasUDProperties(corpus)) { |
150 | 161 |
StringBuilder buffer = new StringBuilder(); |
151 |
|
|
162 |
|
|
152 | 163 |
buffer.append("<h3>CoNLLU</h3>\n"); |
153 |
|
|
164 |
|
|
154 | 165 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
155 | 166 |
buffer.append("<p>UD prefix: '"+prefix+"'</p>\n"); |
156 |
|
|
167 |
|
|
157 | 168 |
try { |
158 | 169 |
Subcorpus udSentences = getSentenceSubcorpus(corpus, prefix); |
159 | 170 |
buffer.append("<p>Sentences: "+udSentences.getNMatch()+"</p>\n"); |
... | ... | |
161 | 172 |
// TODO Auto-generated catch block |
162 | 173 |
e.printStackTrace(); |
163 | 174 |
} |
164 |
|
|
175 |
|
|
165 | 176 |
return buffer.toString(); |
166 | 177 |
} |
167 | 178 |
} |
TXM/trunk/bundles/org.txm.searchengine.core/src/org/txm/searchengine/core/SearchEngine.java (revision 3744) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
|
5 |
import org.txm.core.engines.Engine; |
|
6 | 5 |
import org.txm.core.results.TXMResult; |
7 | 6 |
import org.txm.objects.CorpusBuild; |
8 | 7 |
import org.txm.objects.Match; |
9 | 8 |
import org.txm.utils.LogMonitor; |
10 | 9 |
|
11 |
// FIXME: useless class |
|
12 | 10 |
public abstract class SearchEngine implements ISearchEngine { |
13 | 11 |
|
14 | 12 |
public static final String EXTENSION_POINT_ID = SearchEngine.class.getCanonicalName(); |
... | ... | |
35 | 33 |
return this.getClass()+ " "+this.toString(); |
36 | 34 |
} |
37 | 35 |
|
36 |
/** |
|
37 |
* |
|
38 |
* @param enginename |
|
39 |
* @return null OR an option name if this searchengine offer options for another engine |
|
40 |
*/ |
|
41 |
public String getOptionForSearchengine() { |
|
42 |
return null; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
* @param enginename |
|
48 |
* @return null OR an option name if thi searchengine uses the enginename engine |
|
49 |
*/ |
|
50 |
public String getOptionNameForSearchengine() { |
|
51 |
return null; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* |
|
56 |
* @param enginename |
|
57 |
* @return null OR an option description if thi searchengine uses the enginename engine |
|
58 |
*/ |
|
59 |
public String getOptionDescriptionForSearchengine() { |
|
60 |
return null; |
|
61 |
} |
|
62 |
|
|
38 | 63 |
public boolean equals(SearchEngine e) { |
39 | 64 |
|
40 | 65 |
if (e == null) return false; |
Formats disponibles : Unified diff