Révision 3350

TXM/trunk/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Union.java (revision 3350)
81 81
			return null;
82 82
		}
83 83
		else if (list.size() != 1) {
84
			Log.info("Substraction need a selection of 1 corpus");
84
			Log.info("Union need a selection of 1 corpus");
85 85
			return null;
86 86
		}
87 87
		Object firstElement = list.get(0);
TXM/trunk/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Complementary.java (revision 3350)
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.searchengine.cqp.rcp.handlers.base;
29

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

  
33
import org.eclipse.core.commands.AbstractHandler;
34
import org.eclipse.core.commands.ExecutionEvent;
35
import org.eclipse.core.commands.ExecutionException;
36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.IStatus;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.jface.viewers.IStructuredSelection;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.handlers.HandlerUtil;
44
import org.txm.rcp.JobsTimer;
45
import org.txm.rcp.messages.TXMUIMessages;
46
import org.txm.rcp.swt.dialog.TextDialog;
47
import org.txm.rcp.utils.JobHandler;
48
import org.txm.rcp.views.corpora.CorporaView;
49
import org.txm.searchengine.cqp.AbstractCqiClient;
50
import org.txm.searchengine.cqp.CQPSearchEngine;
51
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages;
52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53
import org.txm.searchengine.cqp.corpus.Subcorpus;
54
import org.txm.searchengine.cqp.rcp.dialogs.SetOperationsDialog;
55
import org.txm.utils.logger.Log;
56

  
57
// TODO: Auto-generated Javadoc
58
/**
59
 * Command which creates a subcorpus from a Corpus @ author mdecorde.
60
 */
61
public class Complementary extends AbstractHandler {
62
	
63
	/** The selection. */
64
	private IStructuredSelection selection;
65
	
66
	/*
67
	 * (non-Javadoc)
68
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
69
	 */
70
	@Override
71
	public Object execute(ExecutionEvent event) throws ExecutionException {
72
		
73
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
74
		if (selection == null) {
75
			System.out.println(TXMUIMessages.noSelectionForColon + HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActiveEditor());
76
			return null;
77
		}
78
		List list = selection.toList();
79
		if (list.size() == 0) {
80
			Log.info("No corpus selected");
81
			return null;
82
		}
83
		else if (list.size() != 1) {
84
			Log.info("Complementary need a selection of 1 corpus");
85
			return null;
86
		}
87
		Object firstElement = list.get(0);
88
		// Object secondElement = list.get(1);
89
		
90
		if (!(firstElement instanceof CQPCorpus)) {
91
			System.out.println(TXMUIMessages.selectionIsNotACorpusColon + firstElement);
92
			return null;
93
		}
94
		
95
		// if (!(secondElement instanceof CQPCorpus)) {
96
		// System.out.println(TXMUIMessages.selectionIsNotACorpusColon+secondElement);
97
		// return null;
98
		// }
99
		
100
		final CQPCorpus corpus = (CQPCorpus) firstElement;
101
		try {
102
			corpus.compute(false);
103
		}
104
		catch (InterruptedException e2) {
105
			// TODO Auto-generated catch block
106
			e2.printStackTrace();
107
			return null;
108
		}
109
		// final CQPCorpus corpus2 = (CQPCorpus) secondElement;
110
		// corpus2.compute(false);
111
		
112
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
113
		final SetOperationsDialog d = new SetOperationsDialog(shell, "COMPL", corpus);
114
		int code = d.open();
115
		if (code == Window.OK) {
116
			JobHandler jobhandler = new JobHandler(NLS.bind(
117
					TXMUIMessages.creatingASubcorpusOnP0, corpus.getName())) {
118
				
119
				@Override
120
				protected IStatus run(IProgressMonitor monitor) {
121
					this.runInit(monitor);
122
					JobsTimer.start();
123
					try {
124
						monitor.beginTask(TXMUIMessages.creatingASubcorpusInTheSearchEngine, 100);
125
						Subcorpus subcorpus = null;
126
						String name = d.getName();
127
						if (name.length() == 0) {
128
							name = d.getDefaultName();
129
						}
130
						
131
						AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
132
						
133
						String cqpid = "S" + Subcorpus.getNextSubcorpusCounter();
134
						CQPCorpus[] order = d.getCorpusOrder();
135
						order[1].compute(false);
136
						String query = cqpid + "=join " + order[0].getQualifiedCqpId() + " " + order[1].getQualifiedCqpId() + ";";
137
						System.out.println("QUERY=" + query);
138
						cqi.query(query);
139
						
140
						if (cqi.subCorpusSize(order[0].getMainCorpus() + ":" + cqpid) == 0) {
141
							Log.info("The created subcorpus was empty. Aborting.");
142
							return Status.CANCEL_STATUS;
143
						}
144
						
145
						subcorpus = corpus.getCorpusParent().createSubcorpus(name, cqpid);
146
						
147
						if (subcorpus == null) {
148
							monitor.done();
149
							Log.warning(TXMUIMessages.errorColonSubcorpusWasNotCreated);
150
							return Status.CANCEL_STATUS;
151
						}
152
						
153
						System.out.println(NLS.bind(TXMUIMessages.doneColonP0Created, subcorpus.getName()));
154
						monitor.worked(50);
155
						
156
						monitor.subTask(TXMUIMessages.refreshingCorpora);
157
						final Subcorpus subcorpus2 = subcorpus;
158
						syncExec(new Runnable() {
159
							
160
							@Override
161
							public void run() {
162
								CorporaView.refresh();
163
								CorporaView.expand(subcorpus2.getParent());
164
							}
165
						});
166
						
167
						monitor.worked(100);
168
					}
169
					catch (ThreadDeath td) {
170
						return Status.CANCEL_STATUS;
171
					}
172
					catch (Exception e) {
173
						org.txm.utils.logger.Log.printStackTrace(e);
174
						Log.severe(e.toString());
175
						
176
						try {
177
							System.out.println(NLS.bind(CQPSearchEngineCoreMessages.lastCQPErrorColon, CQPSearchEngine.getCqiClient().getLastCQPError()));
178
						}
179
						catch (Exception e1) {
180
							System.out.println(TXMUIMessages.failedToGetLastCQPErrorColon + e1);
181
							org.txm.utils.logger.Log.printStackTrace(e1);
182
						}
183
					}
184
					finally {
185
						monitor.done();
186
						JobsTimer.stopAndPrint();
187
					}
188
					return Status.OK_STATUS;
189
				}
190
			};
191
			jobhandler.startJob();
192
		}
193
		return null;
194
	}
195
}
0 196

  
TXM/trunk/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/handlers/base/Intersection.java (revision 3350)
81 81
			return null;
82 82
		}
83 83
		else if (list.size() != 1) {
84
			Log.info("Substraction need a selection of 1 corpus");
84
			Log.info("Intersection need a selection of 1 corpus");
85 85
			return null;
86 86
		}
87 87
		Object firstElement = list.get(0);
TXM/trunk/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/dialogs/SetOperationsDialog.java (revision 3350)
1 1
package org.txm.searchengine.cqp.rcp.dialogs;
2 2

  
3 3

  
4
import java.util.ArrayList;
4 5
import java.util.Arrays;
5 6
import java.util.HashMap;
6 7
import java.util.List;
......
143 144
				if (inputElement == null) return new Object[0];
144 145
				
145 146
				if (inputElement instanceof CQPCorpus) {
146
					return ((CQPCorpus)inputElement).getSubcorpora().toArray();
147
					List<Subcorpus> c = ((CQPCorpus)inputElement).getSubcorpora();
148
					ArrayList<Subcorpus> corpora = new ArrayList<Subcorpus>(c);
149
					corpora.remove(corpus[0]);
150
					return corpora.toArray();
147 151
				}
148 152
				return null;
149 153
			}
......
173 177

  
174 178
		nameColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
175 179
		nameColumn.getColumn().setText("Availables Subcorpus");
176
		nameColumn.getColumn().pack();
180
		nameColumn.getColumn().setWidth(150);
177 181
		nameColumn.setLabelProvider(new CellLabelProvider() {
178 182
			@Override
179 183
			public void update(ViewerCell cell) {
......
212 216
	public String getDefaultName() {
213 217
		String s = "[select a subcorpus in the list]";
214 218
		if (corpus[1] != null) {
215
			s = corpus[1].getName();
219
			s = corpus[1].getSimpleName();
216 220
		}
217
		previousDefaultName = NLS.bind(symbols.get(operation), corpus[0].getName(), s);
221
		previousDefaultName = NLS.bind(symbols.get(operation), corpus[0].getSimpleName(), s);
218 222
		return previousDefaultName;
219 223
	}
220 224

  
TXM/trunk/org.txm.searchengine.cqp.rcp/plugin.xml (revision 3350)
186 186
               </or>
187 187
            </visibleWhen>
188 188
         </command>
189
         <command
190
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Substraction"
191
               label="Substract"
192
               style="push">
193
            <visibleWhen
194
                  checkEnabled="false">
195
               <reference
196
                     definitionId="OneSubCorpusSelected">
197
               </reference>
198
            </visibleWhen>
199
         </command>
200
         <command
201
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Intersection"
202
               label="Intersect"
203
               style="push">
204
            <visibleWhen
205
                  checkEnabled="false">
206
               <reference
207
                     definitionId="OneSubCorpusSelected">
208
               </reference>
209
            </visibleWhen>
210
         </command>
211
         <command
212
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Union"
213
               label="Add"
214
               style="push">
215
            <visibleWhen
216
                  checkEnabled="false">
217
               <reference
218
                     definitionId="OneSubCorpusSelected">
219
               </reference>
220
            </visibleWhen>
221
         </command>
189 222
      </menuContribution>
190 223
      <menuContribution
191 224
            locationURI="menu:menu.file.export?after=menu.file.export.begin">
......
228 261
         </command>
229 262
         <command
230 263
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Substraction"
231
               label="MINUS"
264
               label="Substract"
232 265
               style="push">
233 266
            <visibleWhen
234 267
                  checkEnabled="false">
......
239 272
         </command>
240 273
         <command
241 274
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Intersection"
242
               label="INTER"
275
               label="Intersect"
243 276
               style="push">
244 277
            <visibleWhen
245 278
                  checkEnabled="false">
......
250 283
         </command>
251 284
         <command
252 285
               commandId="org.txm.searchengine.cqp.rcp.handlers.base.Union"
253
               label="UNION"
286
               label="Add"
254 287
               style="push">
255 288
            <visibleWhen
256 289
                  checkEnabled="false">

Formats disponibles : Unified diff