Révision 2562

tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 2562)
272 272
	
273 273
	@Override
274 274
	public boolean canCompute() {
275
		return this.getParent() != null && (this.pProperty != null || (this.pQueries != null && this.pQueries.size() > 0));
275
		return this.getParent() != null && (this.pProperty != null || (this.pQueries != null && this.pQueries != null));
276 276
	}
277 277
	
278 278
	@Override
......
452 452
	 */
453 453
	@SuppressWarnings("unchecked")
454 454
	public List<Part> getParts() {
455
		return (List<Part>) this.getChildren(Part.class);
455
		return this.getChildren(Part.class);
456 456
	}
457 457
	
458 458
	/**
......
686 686
		
687 687
		tmp = this.getStringParameterValue(CQPPreferences.PART_NAMES);
688 688
		if (tmp != null) {
689
			this.pPartNames = Arrays.asList(tmp.split("\t"));
689
			this.pPartNames = new ArrayList<String>(Arrays.asList(tmp.split("\t")));
690 690
		}
691 691
		else {
692 692
			this.pPartNames = null;
......
694 694
		
695 695
		tmp = this.getStringParameterValue(TXMPreferences.QUERIES);
696 696
		if (tmp != null) {
697
			this.pQueries = Arrays.asList(tmp.split("\t"));
697
			this.pQueries = new ArrayList<String>(Arrays.asList(tmp.split("\t")));
698 698
		}
699 699
		else {
700 700
			this.pQueries = null;
......
702 702
		
703 703
		tmp = this.getStringParameterValue(TXMPreferences.VALUES);
704 704
		if (tmp != null) {
705
			this.pValues = Arrays.asList(tmp.split("\t"));
705
			this.pValues = new ArrayList<String>(Arrays.asList(tmp.split("\t")));
706 706
		}
707 707
		else {
708 708
			this.pValues = null;
......
768 768
	public CQPCorpus getCorpus() {
769 769
		return (CQPCorpus) parent;
770 770
	}
771

  
772
	public Object getPartForName(String pName) {
773
		if (pName == null) return null;
774
		
775
		for (Part p : getChildren(Part.class)) {
776
			if (pName.equals(p.getName())) {
777
				return p;
778
			}
779
		}
780
		return null;
781
	}
782

  
783
	public List<String> getQueriesParameter() {
784
		return pQueries;
785
	}
771 786
	
787
	public List<String> getPartNamesParameter() {
788
		return pPartNames;
789
	}
772 790
}
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/ComputePartition.java (revision 2562)
28 28
package org.txm.searchengine.cqp.rcp.handlers.base;
29 29

  
30 30
import java.util.ArrayList;
31
import java.util.List;
31 32

  
32 33
import org.eclipse.core.commands.AbstractHandler;
33 34
import org.eclipse.core.commands.ExecutionEvent;
......
100 101
		Partition part = null;
101 102
		if (firstElement instanceof CQPCorpus) {
102 103
			part = new Partition((CQPCorpus)firstElement);
104
			part.setParameters("", new ArrayList<String>(), new ArrayList<String>());
103 105
		} else if (firstElement instanceof Partition) {
104 106
			part = (Partition)firstElement;
105 107
		}
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/editor/PartitionEditor.java (revision 2562)
1 1
package org.txm.searchengine.cqp.rcp.editor;
2 2

  
3 3
import org.apache.commons.lang.StringUtils;
4
import org.eclipse.jface.layout.GridDataFactory;
5
import org.eclipse.jface.viewers.CellLabelProvider;
6
import org.eclipse.jface.viewers.ISelection;
7
import org.eclipse.jface.viewers.IStructuredSelection;
8
import org.eclipse.jface.viewers.ITreeContentProvider;
9
import org.eclipse.jface.viewers.TableViewer;
10
import org.eclipse.jface.viewers.TableViewerColumn;
11
import org.eclipse.jface.viewers.ViewerCell;
12
import org.eclipse.osgi.util.NLS;
4 13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.KeyEvent;
15
import org.eclipse.swt.events.KeyListener;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
5 20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Event;
6 23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Text;
25
import org.txm.core.preferences.TXMPreferences;
26
import org.txm.core.results.Parameter;
7 27
import org.txm.rcp.editors.TXMEditor;
28
import org.txm.rcp.editors.listeners.ComputeKeyListener;
29
import org.txm.rcp.swt.widget.AssistedQueryWidget;
30
import org.txm.rcp.views.corpora.CorporaView;
31
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
32
import org.txm.searchengine.cqp.corpus.Part;
8 33
import org.txm.searchengine.cqp.corpus.Partition;
9
import org.txm.searchengine.cqp.corpus.Subcorpus;
34
import org.txm.utils.logger.Log;
10 35

  
11 36
public class PartitionEditor extends TXMEditor<Partition> {
12 37

  
13
	Label partitionInfo;
14
	Label partsInfo;
38
	TableViewer partsViewer;
39
	TableViewerColumn nameColumn;
40
	TableViewerColumn queryColumn;
41
	TableViewerColumn sizeColumn;
42
	private Label miniInfoLabel;
15 43
	
44
	@Parameter(key=TXMPreferences.USER_NAME)
45
	private Text nameWidget;
46
	
47
	private Text partNameWidget;
48
	private AssistedQueryWidget queryWidget;
49
	
16 50
	@Override
17 51
	public void _createPartControl() throws Exception {
18
		partitionInfo = new Label(this.getResultArea(), SWT.NONE);
19
		partitionInfo.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
20 52
		
21
		partsInfo = new Label(this.getResultArea(), SWT.NONE);
22
		partitionInfo.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
53
		getResult().compute(false); // ensure Parts are ready
54
		
55
		ComputeKeyListener computeKeyListener = new ComputeKeyListener(this);
56
		
57
		getMainParametersComposite().getLayout().numColumns = 7;
58
		
59
		Label l = new Label(getMainParametersComposite(), SWT.NONE);
60
		l.setText("Name");
61
		l.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
62
		
63
		nameWidget = new Text(getMainParametersComposite(), SWT.BORDER);
64
		nameWidget.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
65
		nameWidget.addModifyListener(new ModifyListener() {
66
			
67
			@Override
68
			public void modifyText(ModifyEvent e) {
69
				getResult().setUserName(nameWidget.getText());
70
				getResult().saveParameter(TXMPreferences.USER_NAME, nameWidget.getText());
71
				
72
				CorporaView.refreshObject(getResult());
73
			}
74
		});
75
		
76
		l = new Label(getMainParametersComposite(), SWT.SEPARATOR | SWT.VERTICAL);
77
		l.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
78
		
79
		miniInfoLabel = new Label(getMainParametersComposite(), SWT.NONE);
80
		miniInfoLabel.setText("Add a part");
81
		miniInfoLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
82
		
83
		partNameWidget = new Text(getMainParametersComposite(), SWT.BORDER);
84
		partNameWidget.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
85
		
86
		// [ (v)]
87
		// queryWidget = new QueryWidget(queryArea, SWT.DROP_DOWN);
88
		queryWidget = new AssistedQueryWidget(getMainParametersComposite(), SWT.DROP_DOWN, getResult().getCorpus());
89
		queryWidget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
90
		queryWidget.addKeyListener(new ComputeKeyListener(this) {
91
			@Override
92
			public void keyPressed(KeyEvent e) {
93
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
94
					try {
95
						if (queryWidget.getQueryString().length() > 0 && onPlusButtonPressed(null, queryWidget.getQueryString())) {
96
							super.keyPressed(e); // recompute only if the query has been added
97
							queryWidget.clearQuery();
98
						} else {
99
							queryWidget.setText(queryWidget.getQueryString());
100
						}
101
					} catch (Exception e1) {
102
						// TODO Auto-generated catch block
103
						e1.printStackTrace();
104
					}
105
				}
106
			}
107
		});
108
		queryWidget.getQueryWidget().addModifyListener(computeKeyListener);
109
		
110
		Button addNewQueryButton = new Button(getMainParametersComposite(), SWT.PUSH);
111
		addNewQueryButton.setText("+");
112
		addNewQueryButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
113
		addNewQueryButton.addSelectionListener(new SelectionListener() {
114
			
115
			@Override
116
			public void widgetSelected(SelectionEvent e) {
117
				try {
118
					if (queryWidget.getQueryString().length() > 0 && onPlusButtonPressed(null, queryWidget.getQueryString())) {
119
						compute(true);
120
						queryWidget.clearQuery();
121
					} else {
122
						queryWidget.setText(queryWidget.getQueryString());
123
					}
124
				} catch (Exception e1) {
125
					// TODO Auto-generated catch block
126
					e1.printStackTrace();
127
				}
128
			}
129
			
130
			@Override
131
			public void widgetDefaultSelected(SelectionEvent e) { }
132
		});
133
		
134
		partsViewer = new TableViewer(this.getResultArea());
135
		partsViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().align(GridData.FILL, GridData.FILL).grab(true, true).create());
136
		partsViewer.getTable().setHeaderVisible(true);
137
		partsViewer.getTable().setLinesVisible(true);
138
		
139
		partsViewer.getTable().addKeyListener(new KeyListener() {
140
			
141
			@Override
142
			public void keyReleased(KeyEvent e) {
143
				if (e.keyCode == SWT.DEL) {
144
					ISelection isel = partsViewer.getSelection();
145
					IStructuredSelection sel = (IStructuredSelection)isel;
146
					Object o = sel.getFirstElement();
147
					if (o != null && o instanceof Part) {
148
						Part p = (Part)o;
149
						p.delete();
150
						partsViewer.setInput(getResult());
151
						try {
152
							updateEditorFromResult(false);
153
						} catch (Exception e1) {
154
							// TODO Auto-generated catch block
155
							e1.printStackTrace();
156
						}
157
					}
158
				}
159
			}
160
			
161
			@Override
162
			public void keyPressed(KeyEvent e) {}
163
		});
164
		
165
		partsViewer.setContentProvider(new ITreeContentProvider() {
166
			
167
			@Override
168
			public Object[] getElements(Object inputElement) {
169
				if (inputElement instanceof Partition) {
170
					return ((Partition)inputElement).getParts().toArray();
171
				}
172
								
173
				return new Object[0];
174
			}
175
			
176
			@Override
177
			public Object[] getChildren(Object parentElement) {
178
				return new Object[0];
179
			}
180
			
181
			@Override
182
			public Object getParent(Object element) {
183
				return getResult();
184
			}
185
			
186
			@Override
187
			public boolean hasChildren(Object element) {
188
				return false;
189
			}
190
		});
191
		
192
		nameColumn = new TableViewerColumn(partsViewer, SWT.NONE);
193
		nameColumn.getColumn().setText("Name");
194
		nameColumn.getColumn().pack();
195
		nameColumn.setLabelProvider(new CellLabelProvider() {
196
			
197
			@Override
198
			public void update(ViewerCell cell) {
199
				Object element = cell.getElement();
200
				
201
				if (element instanceof Part) {
202
					Part part = (Part)element;
203
					cell.setText(part.getName());
204
				} else {
205
					cell.setText("not part");
206
				}
207
			}
208
		});
209
		
210
		queryColumn = new TableViewerColumn(partsViewer, SWT.NONE);
211
		queryColumn.getColumn().setText("Query");
212
		queryColumn.getColumn().pack();
213
		queryColumn.setLabelProvider(new CellLabelProvider() {
214
			
215
			@Override
216
			public void update(ViewerCell cell) {
217
				Object element = cell.getElement();
218
				
219
				if (element instanceof Part) {
220
					Part part = (Part)element;
221
					cell.setText(part.getQuery().toString());
222
				} else {
223
					cell.setText("not part");
224
				}
225
			}
226
		});
227
		
228
		sizeColumn = new TableViewerColumn(partsViewer, SWT.NONE);
229
		sizeColumn.getColumn().setText("Size");
230
		sizeColumn.getColumn().pack();
231
		sizeColumn.setLabelProvider(new CellLabelProvider() {
232
			
233
			@Override
234
			public void update(ViewerCell cell) {
235
				Object element = cell.getElement();
236
				
237
				if (element instanceof Part) {
238
					Part part = (Part)element;
239
					try {
240
						cell.setText(""+part.getSize());
241
					} catch (CqiClientException e) {
242
						// TODO Auto-generated catch block
243
						e.printStackTrace();
244
					}
245
				} else {
246
					cell.setText("not part");
247
				}
248
			}
249
		});
250
		
251
		partsViewer.setInput(getResult());
23 252
	}
24 253

  
254
	/**
255
	 * 
256
	 * @param event
257
	 * @param query
258
	 * @return
259
	 * @throws Exception 
260
	 */
261
	public boolean onPlusButtonPressed(Event event, String query) throws Exception {
262
		System.out.println("Add part: "+query);
263
		String pName = partNameWidget.getText().trim();
264
		if (pName.length() == 0) {
265
			Log.warning("no part name set.");
266
			return false;
267
		}
268
		if (query.length() == 0) {
269
			Log.warning("no part query set.");
270
			return false;
271
		}
272
		if (getResult().getPartForName(pName) != null) {
273
			Log.warning(NLS.bind("A part with the '{0}' name already exists.", pName));
274
			return false;
275
		}
276
		
277
		Part p = new Part(getResult(), pName, queryWidget.getQueryString());
278
		if (p.compute()) { // the part is OK, update the partition parameters
279
			getResult().getQueriesParameter().add(query);
280
			getResult().getPartNamesParameter().add(pName);
281
			compute(false);
282
			
283
			updateEditorFromResult(false);
284
		} else {
285
			Log.warning("Can't compute the part with query: "+query);
286
			p.delete();
287
		}
288
		
289
		return false;
290
	}
291
	
25 292
	@Override
26 293
	public void updateResultFromEditor() {
27 294
		// nothing to do
......
29 296

  
30 297
	@Override
31 298
	public void updateEditorFromResult(boolean update) throws Exception {
32
		partitionInfo.setText(getResult().getDetails());
33
		partsInfo.setText(StringUtils.join(getResult().getParts(), "\n"));
299
		partsViewer.setInput(getResult());
34 300
	}
35 301
}
tmp/org.txm.searchengine.cqp.rcp/plugin.xml (revision 2562)
181 181
               style="push">
182 182
            <visibleWhen
183 183
                  checkEnabled="false">
184
               <reference
185
                     definitionId="OneCorpusSelected">
186
               </reference>
184
               <or>
185
                  <reference
186
                        definitionId="OneCorpusSelected">
187
                  </reference>
188
                  <reference
189
                        definitionId="OnePartitionSelected">
190
                  </reference>
191
               </or>
187 192
            </visibleWhen>
188 193
         </command>
189 194
      </menuContribution>

Formats disponibles : Unified diff