Révision 379
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/link/ReferencerToConc.java (revision 379) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
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.commands.link; |
|
29 |
|
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.eclipse.core.commands.AbstractHandler; |
|
33 |
import org.eclipse.core.commands.ExecutionEvent; |
|
34 |
import org.eclipse.core.commands.ExecutionException; |
|
35 |
import org.eclipse.jface.viewers.ISelection; |
|
36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
37 |
import org.eclipse.osgi.util.NLS; |
|
38 |
import org.eclipse.ui.IWorkbenchPage; |
|
39 |
import org.eclipse.ui.PartInitException; |
|
40 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
41 |
import org.txm.concordance.rcp.editors.ConcordanceEditor; |
|
42 |
import org.txm.concordance.rcp.editors.ConcordanceEditorInput; |
|
43 |
import org.txm.functions.ReferencePattern; |
|
44 |
import org.txm.functions.referencer.Referencer; |
|
45 |
import org.txm.functions.referencer.Referencer.Line; |
|
46 |
import org.txm.rcp.Messages; |
|
47 |
import org.txm.rcp.editors.referencer.ReferencerEditor; |
|
48 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
49 |
import org.txm.searchengine.cqp.corpus.Property; |
|
50 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
51 |
|
|
52 |
// TODO: Auto-generated Javadoc |
|
53 |
/** |
|
54 |
* The Class ReferencerToConc. |
|
55 |
*/ |
|
56 |
public class ReferencerToConc extends AbstractHandler { |
|
57 |
|
|
58 |
/* (non-Javadoc) |
|
59 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
63 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil |
|
64 |
.getActiveWorkbenchWindow(event).getActivePage().getSelection(); |
|
65 |
|
|
66 |
ReferencerEditor refeditor = (ReferencerEditor) HandlerUtil |
|
67 |
.getActiveWorkbenchWindow(event).getActivePage() |
|
68 |
.getActivePart(); |
|
69 |
|
|
70 |
return link(refeditor, selection); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Link. |
|
75 |
* |
|
76 |
* @param refeditor the refeditor |
|
77 |
* @param iSelection the selection |
|
78 |
* @return the object |
|
79 |
*/ |
|
80 |
public static Object link(ReferencerEditor refeditor, ISelection iSelection) |
|
81 |
{ |
|
82 |
IStructuredSelection selection = (IStructuredSelection) iSelection; |
|
83 |
String query = getQuery(selection); |
|
84 |
if (query.length() == 0) |
|
85 |
return null; |
|
86 |
Corpus corpus = refeditor.getCorpus(); |
|
87 |
ConcordanceEditorInput editorInput = new ConcordanceEditorInput( |
|
88 |
corpus, null); |
|
89 |
|
|
90 |
IWorkbenchPage page = refeditor.getEditorSite().getWorkbenchWindow() |
|
91 |
.getActivePage(); |
|
92 |
try { |
|
93 |
ConcordanceEditor conceditor = (ConcordanceEditor) page |
|
94 |
.openEditor(editorInput, |
|
95 |
"ConcordanceEditor"); //$NON-NLS-1$ |
|
96 |
conceditor.setQuery(query); |
|
97 |
ReferencePattern rp = new ReferencePattern(); |
|
98 |
for(Property p : refeditor.getReferencer().getPattern()) |
|
99 |
rp.addProperty(p); |
|
100 |
conceditor.setRefViewPattern(rp); |
|
101 |
conceditor.compute(); |
|
102 |
} catch (PartInitException e) { |
|
103 |
System.err.println(NLS.bind(Messages.GetConcordances_4, e)); |
|
104 |
} |
|
105 |
|
|
106 |
return null; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Gets the query. |
|
111 |
* |
|
112 |
* @param selection the selection |
|
113 |
* @return the query |
|
114 |
*/ |
|
115 |
private static String getQuery(IStructuredSelection selection) { |
|
116 |
String query = ""; //$NON-NLS-1$ |
|
117 |
|
|
118 |
Line fline = (Line) selection.getFirstElement(); |
|
119 |
Referencer ref = fline.getReferencer(); |
|
120 |
int nbToken = 1; |
|
121 |
|
|
122 |
List<Line> lines = selection.toList(); |
|
123 |
|
|
124 |
Property prop = ref.getProperty(); |
|
125 |
for (int t = 0; t < nbToken; t++) |
|
126 |
{ |
|
127 |
query += "["+prop + "=\""; //$NON-NLS-1$ //$NON-NLS-2$ |
|
128 |
|
|
129 |
for (Line line : lines) { |
|
130 |
String s = line.getPropValue(); |
|
131 |
s = Query.addBackSlash(s); |
|
132 |
query += s + "|"; //$NON-NLS-1$ |
|
133 |
} |
|
134 |
query = query.substring(0, query.length() - 1); |
|
135 |
query += "\"] "; //$NON-NLS-1$ |
|
136 |
} |
|
137 |
query = query.substring(0, query.length() - 1); |
|
138 |
return query; |
|
139 |
} |
|
140 |
} |
|
0 | 141 |
Formats disponibles : Unified diff