Révision 3105
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMBrowser.java (revision 3105) | ||
---|---|---|
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.editors; |
|
29 |
|
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.eclipse.jface.action.MenuManager; |
|
33 |
import org.eclipse.jface.text.ITextSelection; |
|
34 |
import org.eclipse.jface.viewers.ISelection; |
|
35 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
36 |
import org.eclipse.jface.viewers.ISelectionProvider; |
|
37 |
import org.eclipse.swt.SWT; |
|
38 |
import org.eclipse.swt.browser.Browser; |
|
39 |
import org.eclipse.swt.browser.ProgressEvent; |
|
40 |
import org.eclipse.swt.browser.ProgressListener; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.events.SelectionListener; |
|
43 |
import org.eclipse.swt.graphics.Image; |
|
44 |
import org.eclipse.swt.layout.FormAttachment; |
|
45 |
import org.eclipse.swt.layout.FormData; |
|
46 |
import org.eclipse.swt.layout.FormLayout; |
|
47 |
import org.eclipse.swt.layout.RowData; |
|
48 |
import org.eclipse.swt.layout.RowLayout; |
|
49 |
import org.eclipse.swt.widgets.Button; |
|
50 |
import org.eclipse.swt.widgets.Composite; |
|
51 |
import org.eclipse.swt.widgets.Label; |
|
52 |
import org.eclipse.swt.widgets.Menu; |
|
53 |
import org.eclipse.ui.internal.browser.BrowserViewer; |
|
54 |
import org.eclipse.ui.internal.browser.WebBrowserEditor; |
|
55 |
import org.txm.objects.Edition; |
|
56 |
import org.txm.objects.Page; |
|
57 |
import org.txm.objects.Project; |
|
58 |
import org.txm.objects.Text; |
|
59 |
import org.txm.rcp.IImageKeys; |
|
60 |
import org.txm.rcp.StatusLine; |
|
61 |
import org.txm.rcp.messages.TXMUIMessages; |
|
62 |
|
|
63 |
/** |
|
64 |
* Call the internal browser of RCP specialized for TXM editions. |
|
65 |
* |
|
66 |
* A Text can be set then the user can browse pages and others texts of the same corpus |
|
67 |
* |
|
68 |
* @author mdecorde. |
|
69 |
*/ |
|
70 |
@SuppressWarnings("restriction") |
|
71 |
public class TXMBrowser extends WebBrowserEditor { |
|
72 |
|
|
73 |
/** The Constant ID. */ |
|
74 |
public final static String ID = "org.txm.rcp.editors.TXMBrowser"; //$NON-NLS-1$ |
|
75 |
|
|
76 |
private ProgressListener progresslistener; |
|
77 |
|
|
78 |
private List<String> wordids; |
|
79 |
|
|
80 |
private List<String> lineids; |
|
81 |
|
|
82 |
/** The edition. */ |
|
83 |
Edition edition; |
|
84 |
|
|
85 |
/** The current page. */ |
|
86 |
Page currentPage; |
|
87 |
|
|
88 |
/** The page_label. */ |
|
89 |
Label page_label; |
|
90 |
|
|
91 |
/** The source. */ |
|
92 |
private Object source; |
|
93 |
|
|
94 |
/** |
|
95 |
* Instantiates a new txm browser. |
|
96 |
*/ |
|
97 |
public TXMBrowser() { |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Gets the browser. |
|
103 |
* |
|
104 |
* @return the browser |
|
105 |
*/ |
|
106 |
public Browser getBrowser() { |
|
107 |
BrowserViewer webbrowser = this.webBrowser; |
|
108 |
return webbrowser.getBrowser(); |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public void setPartName(String partName) { |
|
113 |
super.setPartName(partName); |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public void setTitleImage(Image titleImage) { |
|
118 |
super.setTitleImage(titleImage); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* |
|
123 |
* @param wordids2 all the words to highlight |
|
124 |
* @param lineids2 the words to highlight better and to scroll to |
|
125 |
*/ |
|
126 |
public void setWordsIds(List<String> wordids2, List<String> lineids2) { |
|
127 |
this.wordids = wordids2; |
|
128 |
this.lineids = lineids2; |
|
129 |
if (progresslistener != null) |
|
130 |
this.getBrowser().removeProgressListener(progresslistener); |
|
131 |
progresslistener = new ProgressListener() { |
|
132 |
|
|
133 |
@Override |
|
134 |
public void changed(ProgressEvent event) {} |
|
135 |
|
|
136 |
@Override |
|
137 |
public void completed(ProgressEvent event) { |
|
138 |
Page currentpage = getCurrentPage(); |
|
139 |
// System.out.println("Highlight ! "+currentpage.getEdition().getText()+" wordids ="+wordids); |
|
140 |
|
|
141 |
for (String wordid : wordids) { |
|
142 |
String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
143 |
"elt.style.backgroundColor=\"#F9D0D0\";" //$NON-NLS-1$ |
|
144 |
+ |
|
145 |
"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
146 |
"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
147 |
"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
148 |
"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
149 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
150 |
|
|
151 |
getBrowser().execute(highlightscript); |
|
152 |
} |
|
153 |
|
|
154 |
for (String wordid : lineids) { |
|
155 |
String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
156 |
"elt.style.backgroundColor=\"#F9A0A0\";" + //$NON-NLS-1$ |
|
157 |
"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
158 |
"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
159 |
"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
160 |
"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
161 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
162 |
|
|
163 |
getBrowser().execute(highlightscript); |
|
164 |
} |
|
165 |
if (lineids.size() > 0) { |
|
166 |
String script = "try { document.getElementById(\"" + lineids.get(0) + "\").scrollIntoView(true); } catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
167 |
getBrowser().execute(script); |
|
168 |
} |
|
169 |
} |
|
170 |
}; |
|
171 |
getBrowser().addProgressListener(progresslistener); |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Sets the edition. |
|
176 |
* |
|
177 |
* @param edition the new edition |
|
178 |
*/ |
|
179 |
public void setEdition(Edition edition) { |
|
180 |
this.edition = edition; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Make page label. |
|
185 |
* |
|
186 |
* @return the string |
|
187 |
*/ |
|
188 |
public String makePageLabel() { |
|
189 |
return currentPage.getName() |
|
190 |
+ " / " + currentPage.getEdition().getNumPages(); //$NON-NLS-1$ |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Show page. |
|
195 |
* |
|
196 |
* @param page the page |
|
197 |
*/ |
|
198 |
public void showPage(Page page) { |
|
199 |
edition = page.getEdition(); |
|
200 |
currentPage = page; |
|
201 |
this.webBrowser.setURL(currentPage.toURL()); |
|
202 |
page_label.setText(makePageLabel()); |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* First text. |
|
207 |
*/ |
|
208 |
public void firstText() { |
|
209 |
Text current = this.currentPage.getEdition().getText(); |
|
210 |
Project corpus = current.getProject(); |
|
211 |
Text firstText = corpus.getFirstText(); |
|
212 |
|
|
213 |
if (firstText != null) { |
|
214 |
String editionName = corpus.getDefaultEditionName(); |
|
215 |
currentPage = firstText.getEdition(editionName).getFirstPage(); |
|
216 |
if (currentPage == null) { |
|
217 |
StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
218 |
return; |
|
219 |
} |
|
220 |
this.setEdition(firstText.getEdition(editionName)); |
|
221 |
this.webBrowser.setURL(currentPage.toURL()); |
|
222 |
page_label.setText(makePageLabel()); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Last text. |
|
228 |
*/ |
|
229 |
public void lastText() { |
|
230 |
Text current = this.currentPage.getEdition().getText(); |
|
231 |
Project b = current.getProject(); |
|
232 |
Text lastText = b.getLastText(); |
|
233 |
|
|
234 |
if (lastText != null) { |
|
235 |
currentPage = lastText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
236 |
if (currentPage == null) { |
|
237 |
StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
238 |
return; |
|
239 |
} |
|
240 |
this.setEdition(lastText.getEdition(b.getDefaultEditionName())); |
|
241 |
this.webBrowser.setURL(currentPage.toURL()); |
|
242 |
page_label.setText(makePageLabel()); |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
/** |
|
247 |
* First page. |
|
248 |
*/ |
|
249 |
public void firstPage() { |
|
250 |
// System.out.println(Messages.TxmBrowser_1+currentPage); |
|
251 |
currentPage = edition.getFirstPage(); |
|
252 |
this.webBrowser.setURL(currentPage.toURL()); |
|
253 |
page_label.setText(makePageLabel()); |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* Last page. |
|
258 |
*/ |
|
259 |
public void lastPage() { |
|
260 |
// System.out.println(Messages.TxmBrowser_2+currentPage); |
|
261 |
|
|
262 |
if (currentPage != null && currentPage.getFile().equals(edition.getLastPage().getFile())) |
|
263 |
return; |
|
264 |
currentPage = edition.getLastPage(); |
|
265 |
this.webBrowser.setURL(currentPage.toURL()); |
|
266 |
page_label.setText(makePageLabel()); |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Previous page. |
|
271 |
*/ |
|
272 |
public void previousPage() { |
|
273 |
// System.out.println(Messages.TxmBrowser_3+currentPage); |
|
274 |
if (currentPage != null) { |
|
275 |
Page previous = edition.getPreviousPage(currentPage); |
|
276 |
if (previous == currentPage) { |
|
277 |
previousText(true); |
|
278 |
} |
|
279 |
else { |
|
280 |
currentPage = previous; |
|
281 |
this.webBrowser.setURL(currentPage.toURL()); |
|
282 |
} |
|
283 |
} |
|
284 |
else |
|
285 |
firstPage(); |
|
286 |
page_label.setText(makePageLabel()); |
|
287 |
} |
|
288 |
|
|
289 |
/** |
|
290 |
* Next page. |
|
291 |
*/ |
|
292 |
public void nextPage() { |
|
293 |
// System.out.println(Messages.TxmBrowser_4+currentPage); |
|
294 |
if (currentPage != null) { |
|
295 |
Page next = edition.getNextPage(currentPage); |
|
296 |
if (currentPage == next) { |
|
297 |
nextText(); |
|
298 |
} |
|
299 |
else { |
|
300 |
currentPage = next; |
|
301 |
this.webBrowser.setURL(currentPage.toURL()); |
|
302 |
} |
|
303 |
|
|
304 |
} |
|
305 |
else |
|
306 |
firstPage(); |
|
307 |
page_label.setText(makePageLabel()); |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Previous text. |
|
312 |
* |
|
313 |
* @param fromNextText |
|
314 |
*/ |
|
315 |
public void previousText(boolean fromNextText) { |
|
316 |
|
|
317 |
Text current = this.currentPage.getEdition().getText(); |
|
318 |
Project corpus = current.getProject(); |
|
319 |
Text previousText = corpus.getPreviousText(current); |
|
320 |
|
|
321 |
if (previousText != null) { |
|
322 |
String editionName = corpus.getDefaultEditionName(); |
|
323 |
if (fromNextText) { |
|
324 |
currentPage = previousText.getEdition(editionName).getLastPage(); |
|
325 |
} |
|
326 |
else { |
|
327 |
currentPage = previousText.getEdition(editionName).getFirstPage(); |
|
328 |
} |
|
329 |
if (currentPage == null) { |
|
330 |
StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
331 |
return; |
|
332 |
} |
|
333 |
this.setEdition(previousText.getEdition(editionName)); |
|
334 |
this.webBrowser.setURL(currentPage.toURL()); |
|
335 |
page_label.setText(makePageLabel()); |
|
336 |
} |
|
337 |
// System.out.println("Previous texts "+previousText); |
|
338 |
} |
|
339 |
|
|
340 |
/** |
|
341 |
* Next text. |
|
342 |
*/ |
|
343 |
public void nextText() { |
|
344 |
Text current = this.currentPage.getEdition().getText(); |
|
345 |
Project b = current.getProject(); |
|
346 |
Text nextText = b.getNextText(current); |
|
347 |
|
|
348 |
if (nextText != null) { |
|
349 |
currentPage = nextText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
350 |
if (currentPage == null) { |
|
351 |
StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
352 |
return; |
|
353 |
} |
|
354 |
this.setEdition(nextText.getEdition(b.getDefaultEditionName())); |
|
355 |
this.webBrowser.setURL(currentPage.toURL()); |
|
356 |
page_label.setText(makePageLabel()); |
|
357 |
} |
|
358 |
// System.out.println("Next texts "+nextText); |
|
359 |
} |
|
360 |
|
|
361 |
/* |
|
362 |
* (non-Javadoc) |
|
363 |
* @see org.eclipse.ui.internal.browser.WebBrowserEditor#createPartControl(org.eclipse.swt.widgets.Composite) |
|
364 |
*/ |
|
365 |
@Override |
|
366 |
public void createPartControl(Composite parent) { |
|
367 |
try { |
|
368 |
super.createPartControl(parent); |
|
369 |
} |
|
370 |
catch (Exception e) { |
|
371 |
System.err.println(TXMUIMessages.couldNotLaunchTheInternalWebBrowserYouMustSetThatParameterInThePreferencesMenuColonGeneralSupWebNavigator); |
|
372 |
return; |
|
373 |
} |
|
374 |
|
|
375 |
RowLayout navigLayout = new RowLayout(SWT.HORIZONTAL); |
|
376 |
navigLayout.justify = true; |
|
377 |
Composite panneau = new Composite(parent, SWT.NONE); |
|
378 |
panneau.setLayout(navigLayout); |
|
379 |
|
|
380 |
RowLayout subLayout = new RowLayout(SWT.HORIZONTAL); |
|
381 |
subLayout.pack = true; |
|
382 |
subLayout.center = true; |
|
383 |
subLayout.marginBottom = subLayout.marginHeight = 0; |
|
384 |
subLayout.marginTop = subLayout.marginWidth = 0; |
|
385 |
Composite subPanneau = new Composite(panneau, SWT.NONE); |
|
386 |
subPanneau.setLayout(subLayout); |
|
387 |
subPanneau.setLayoutData(new RowData(450, 22)); |
|
388 |
|
|
389 |
Button firstText = new Button(subPanneau, SWT.FLAT); |
|
390 |
Button previousText = new Button(subPanneau, SWT.FLAT); |
|
391 |
Button first = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
392 |
Button previous = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
393 |
page_label = new Label(subPanneau, SWT.NONE); |
|
394 |
Button next = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
395 |
Button last = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
396 |
Button nextText = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
397 |
Button lastText = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
398 |
|
|
399 |
// set sizes |
|
400 |
page_label.setLayoutData(new RowData(50, 20)); |
|
401 |
firstText.setLayoutData(new RowData(30, 20)); |
|
402 |
first.setLayoutData(new RowData(30, 20)); |
|
403 |
previous.setLayoutData(new RowData(30, 20)); |
|
404 |
next.setLayoutData(new RowData(30, 20)); |
|
405 |
last.setLayoutData(new RowData(30, 20)); |
|
406 |
nextText.setLayoutData(new RowData(30, 20)); |
|
407 |
previousText.setLayoutData(new RowData(30, 20)); |
|
408 |
lastText.setLayoutData(new RowData(30, 20)); |
|
409 |
|
|
410 |
|
|
411 |
// set labels |
|
412 |
page_label.setText(""); //$NON-NLS-1$ |
|
413 |
firstText.setImage(IImageKeys.getImage(IImageKeys.CTRLREWINDSTART)); |
|
414 |
firstText.setToolTipText("|<<"); |
|
415 |
previousText.setImage(IImageKeys.getImage(IImageKeys.CTRLREWIND)); |
|
416 |
previousText.setToolTipText(TXMUIMessages.previousText); |
|
417 |
first.setImage(IImageKeys.getImage(IImageKeys.CTRLSTART)); |
|
418 |
first.setToolTipText(TXMUIMessages.common_beginning); |
|
419 |
previous.setImage(IImageKeys.getImage(IImageKeys.CTRLREVERSE)); |
|
420 |
previous.setToolTipText(TXMUIMessages.previousPage); |
|
421 |
next.setImage(IImageKeys.getImage(IImageKeys.CTRLPLAY)); |
|
422 |
next.setToolTipText(TXMUIMessages.nextPage); |
|
423 |
last.setImage(IImageKeys.getImage(IImageKeys.CTRLEND)); |
|
424 |
last.setToolTipText(TXMUIMessages.common_end); |
|
425 |
nextText.setImage(IImageKeys.getImage(IImageKeys.CTRLFASTFORWARD)); |
|
426 |
nextText.setToolTipText(TXMUIMessages.nextText); |
|
427 |
lastText.setImage(IImageKeys.getImage(IImageKeys.CTRLFASTFORWARDEND)); |
|
428 |
lastText.setToolTipText(">>|"); |
|
429 |
|
|
430 |
|
|
431 |
// set listeners |
|
432 |
first.addSelectionListener(new SelectionListener() { |
|
433 |
|
|
434 |
@Override |
|
435 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
436 |
firstPage(); |
|
437 |
} |
|
438 |
|
|
439 |
@Override |
|
440 |
public void widgetSelected(SelectionEvent e) { |
|
441 |
firstPage(); |
|
442 |
} |
|
443 |
}); |
|
444 |
previous.addSelectionListener(new SelectionListener() { |
|
445 |
|
|
446 |
@Override |
|
447 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
448 |
previousPage(); |
|
449 |
} |
|
450 |
|
|
451 |
@Override |
|
452 |
public void widgetSelected(SelectionEvent e) { |
|
453 |
previousPage(); |
|
454 |
} |
|
455 |
}); |
|
456 |
next.addSelectionListener(new SelectionListener() { |
|
457 |
|
|
458 |
@Override |
|
459 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
460 |
nextPage(); |
|
461 |
} |
|
462 |
|
|
463 |
@Override |
|
464 |
public void widgetSelected(SelectionEvent e) { |
|
465 |
nextPage(); |
|
466 |
} |
|
467 |
}); |
|
468 |
last.addSelectionListener(new SelectionListener() { |
|
469 |
|
|
470 |
@Override |
|
471 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
472 |
lastPage(); |
|
473 |
} |
|
474 |
|
|
475 |
@Override |
|
476 |
public void widgetSelected(SelectionEvent e) { |
|
477 |
lastPage(); |
|
478 |
} |
|
479 |
}); |
|
480 |
nextText.addSelectionListener(new SelectionListener() { |
|
481 |
|
|
482 |
@Override |
|
483 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
484 |
nextText(); |
|
485 |
} |
|
486 |
|
|
487 |
@Override |
|
488 |
public void widgetSelected(SelectionEvent e) { |
|
489 |
nextText(); |
|
490 |
} |
|
491 |
}); |
|
492 |
// set listeners |
|
493 |
previousText.addSelectionListener(new SelectionListener() { |
|
494 |
|
|
495 |
@Override |
|
496 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
497 |
previousText(false); |
|
498 |
} |
|
499 |
|
|
500 |
@Override |
|
501 |
public void widgetSelected(SelectionEvent e) { |
|
502 |
previousText(false); |
|
503 |
} |
|
504 |
}); |
|
505 |
lastText.addSelectionListener(new SelectionListener() { |
|
506 |
|
|
507 |
@Override |
|
508 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
509 |
lastText(); |
|
510 |
} |
|
511 |
|
|
512 |
@Override |
|
513 |
public void widgetSelected(SelectionEvent e) { |
|
514 |
lastText(); |
|
515 |
} |
|
516 |
}); |
|
517 |
// set listeners |
|
518 |
firstText.addSelectionListener(new SelectionListener() { |
|
519 |
|
|
520 |
@Override |
|
521 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
522 |
firstText(); |
|
523 |
} |
|
524 |
|
|
525 |
@Override |
|
526 |
public void widgetSelected(SelectionEvent e) { |
|
527 |
firstText(); |
|
528 |
} |
|
529 |
}); |
|
530 |
|
|
531 |
subPanneau.pack(); |
|
532 |
panneau.pack(); |
|
533 |
|
|
534 |
FormLayout parentLayout = new FormLayout(); |
|
535 |
|
|
536 |
FormData datatop = new FormData(); |
|
537 |
datatop.top = new FormAttachment(0, 0); |
|
538 |
datatop.left = new FormAttachment(0, 0); |
|
539 |
datatop.right = new FormAttachment(100, 0); |
|
540 |
datatop.bottom = new FormAttachment(panneau, 0); |
|
541 |
webBrowser.setLayoutData(datatop); |
|
542 |
|
|
543 |
FormData databottom = new FormData(200, 30); |
|
544 |
databottom.bottom = new FormAttachment(100, 0); |
|
545 |
databottom.left = new FormAttachment(30, -100); |
|
546 |
databottom.right = new FormAttachment(80, 100); |
|
547 |
panneau.setLayoutData(databottom); |
|
548 |
|
|
549 |
parent.setLayout(parentLayout); |
|
550 |
parent.pack(); |
|
551 |
|
|
552 |
MenuManager menuManager = new MenuManager(); |
|
553 |
Menu menu = menuManager.createContextMenu(getBrowser()); |
|
554 |
|
|
555 |
// Set the MenuManager |
|
556 |
getBrowser().setMenu(menu); |
|
557 |
ISelectionProvider selProvider = new ISelectionProvider() { |
|
558 |
|
|
559 |
@Override |
|
560 |
public void setSelection(ISelection selection) {} |
|
561 |
|
|
562 |
@Override |
|
563 |
public void removeSelectionChangedListener(ISelectionChangedListener listener) {} |
|
564 |
|
|
565 |
@Override |
|
566 |
public ISelection getSelection() { |
|
567 |
ITextSelection sel = new ITextSelection() { |
|
568 |
|
|
569 |
@Override |
|
570 |
public boolean isEmpty() { |
|
571 |
return false; |
|
572 |
} |
|
573 |
|
|
574 |
@Override |
|
575 |
public String getText() { |
|
576 |
return getTextSelection(); |
|
577 |
} |
|
578 |
|
|
579 |
@Override |
|
580 |
public int getStartLine() { |
|
581 |
return 0; |
|
582 |
} |
|
583 |
|
|
584 |
@Override |
|
585 |
public int getOffset() { |
|
586 |
return 0; |
|
587 |
} |
|
588 |
|
|
589 |
@Override |
|
590 |
public int getLength() { |
|
591 |
return 0; |
|
592 |
} |
|
593 |
|
|
594 |
@Override |
|
595 |
public int getEndLine() { |
|
596 |
return 0; |
|
597 |
} |
|
598 |
}; |
|
599 |
return sel; |
|
600 |
} |
|
601 |
|
|
602 |
@Override |
|
603 |
public void addSelectionChangedListener(ISelectionChangedListener listener) {} |
|
604 |
}; |
|
605 |
getSite().registerContextMenu(menuManager, selProvider); |
|
606 |
getSite().setSelectionProvider(selProvider); |
|
607 |
|
|
608 |
// System.out.println("Browser menu: "+getBrowser().getMenu()); |
|
609 |
} |
|
610 |
|
|
611 |
static String SCRIPT01 = "var html = \"\";" + |
|
612 |
"if (typeof window.getSelection != \"undefined\") {" + // modern Web browsers |
|
613 |
"var sel = window.getSelection();" + |
|
614 |
"if (sel.rangeCount) {" + |
|
615 |
"var container = document.createElement(\"div\");" + |
|
616 |
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {" + |
|
617 |
"container.appendChild(sel.getRangeAt(i).cloneContents());" + |
|
618 |
"}" + |
|
619 |
"html = container.innerHTML;" + |
|
620 |
"}" + |
|
621 |
"} else if (typeof document.selection != \"undefined\") {" + // for IE < 11 |
|
622 |
"if (document.selection.type == \"Text\") {" + |
|
623 |
"html = document.selection.createRange().htmlText;" + |
|
624 |
"}" + |
|
625 |
"}" + |
|
626 |
"return html"; |
|
627 |
|
|
628 |
// return the span@id of the current selection |
|
629 |
static String SCRIPT02 = "function getChildren(node) {\n" |
|
630 |
+ "if (node.children != \"undefined\")\n" |
|
631 |
+ " return node.children;\n" |
|
632 |
+ "else \n" |
|
633 |
+ "return node.ChildNodes;\n" |
|
634 |
+ "}\n" |
|
635 |
+ "findSpans = function findSpans(c, a) {\n" + |
|
636 |
" for (var i = 0 ; i < c.length ; i++) {\n" + |
|
637 |
" if (c.item(i).tagName == \"SPAN\") {\n" + |
|
638 |
" var id = c.item(i).getAttribute(\"id\")\n" + |
|
639 |
" if (id.indexOf(\"w_\") == 0)\n" + |
|
640 |
" a.push(id);\n" + |
|
641 |
" } else if (c.item(i).nodeType == 1) {\n" + |
|
642 |
" findSpans(c.item(i).children, a);\n" + |
|
643 |
" }\n" + |
|
644 |
" }\n" + |
|
645 |
"}\n" + |
|
646 |
" var all = [];" + |
|
647 |
" var sel = window.getSelection();" + |
|
648 |
" if (sel.rangeCount == 0){" + |
|
649 |
" return all;" + |
|
650 |
" }" + |
|
651 |
"\n" + |
|
652 |
" var range = sel.getRangeAt(0);" + |
|
653 |
" var frag = range.cloneContents();alert(frag);alert(frag.children);" + |
|
654 |
" findSpans(frag.children, all);" + |
|
655 |
" return all;"; |
|
656 |
|
|
657 |
public String getTextSelectionDOM() { |
|
658 |
return ((String) getBrowser().evaluate(SCRIPT01)); |
|
659 |
} |
|
660 |
|
|
661 |
public Object getWordIDsSelection() { |
|
662 |
System.out.println("WORDS IDS " + getBrowser().evaluate(SCRIPT02)); |
|
663 |
return getBrowser().evaluate(SCRIPT02); |
|
664 |
} |
|
665 |
|
|
666 |
public String getTextSelection() { |
|
667 |
System.out.println("DOM=" + getTextSelectionDOM()); |
|
668 |
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", ""); |
|
669 |
System.out.println("STR=" + rez); |
|
670 |
return rez; |
|
671 |
} |
|
672 |
|
|
673 |
/** |
|
674 |
* Gets the current page. |
|
675 |
* |
|
676 |
* @return the current page |
|
677 |
*/ |
|
678 |
public Page getCurrentPage() { |
|
679 |
return currentPage; |
|
680 |
} |
|
681 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMWebBrowserEditor.java (revision 3105) | ||
---|---|---|
1 |
package org.txm.rcp.editors; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
|
|
6 |
import org.eclipse.core.commands.Command; |
|
7 |
import org.eclipse.core.commands.IParameter; |
|
8 |
import org.eclipse.core.commands.Parameterization; |
|
9 |
import org.eclipse.core.commands.ParameterizedCommand; |
|
10 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
11 |
import org.eclipse.swt.SWT; |
|
12 |
import org.eclipse.swt.browser.Browser; |
|
13 |
import org.eclipse.swt.browser.BrowserFunction; |
|
14 |
import org.eclipse.swt.events.SelectionListener; |
|
15 |
import org.eclipse.swt.graphics.Image; |
|
16 |
import org.eclipse.swt.widgets.Composite; |
|
17 |
import org.eclipse.swt.widgets.ToolBar; |
|
18 |
import org.eclipse.swt.widgets.ToolItem; |
|
19 |
import org.eclipse.ui.IWorkbenchWindow; |
|
20 |
import org.eclipse.ui.PlatformUI; |
|
21 |
import org.eclipse.ui.commands.ICommandService; |
|
22 |
import org.eclipse.ui.handlers.IHandlerService; |
|
23 |
import org.eclipse.ui.internal.browser.BrowserViewer; |
|
24 |
import org.eclipse.ui.internal.browser.ImageResource; |
|
25 |
import org.eclipse.ui.internal.browser.Messages; |
|
26 |
import org.eclipse.ui.internal.browser.WebBrowserEditor; |
|
27 |
import org.eclipse.ui.internal.browser.WebBrowserEditorInput; |
|
28 |
|
|
29 |
@SuppressWarnings("restriction") |
|
30 |
public class TXMWebBrowserEditor extends WebBrowserEditor { |
|
31 |
|
|
32 |
public static final String WEB_BROWSER_EDITOR_ID = "org.txm.rcp.editors.TXMWebBrowserEditor"; //$NON-NLS-1$ |
|
33 |
|
|
34 |
@Override |
|
35 |
public void setTitleImage(Image img) { |
|
36 |
super.setTitleImage(img); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public void setTitle(String title) { |
|
41 |
super.setTitle(title); |
|
42 |
} |
|
43 |
|
|
44 |
public void setTitleTooltip(String tooltip) { |
|
45 |
super.setTitleToolTip(tooltip); |
|
46 |
} |
|
47 |
|
|
48 |
public void focus() { |
|
49 |
webBrowser.getBrowser().forceFocus(); |
|
50 |
} |
|
51 |
|
|
52 |
public BrowserViewer getWebBrowserViewer() { |
|
53 |
return webBrowser; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public void createPartControl(Composite parent) { |
|
58 |
|
|
59 |
super.createPartControl(parent); |
|
60 |
|
|
61 |
// createToolbar(parent); |
|
62 |
|
|
63 |
new CommandLink(this.webBrowser.getBrowser()); |
|
64 |
} |
|
65 |
|
|
66 |
ToolItem back; |
|
67 |
|
|
68 |
ToolItem forward; |
|
69 |
|
|
70 |
|
|
71 |
// Called by JavaScript |
|
72 |
public class CommandLink extends BrowserFunction { |
|
73 |
|
|
74 |
String data = ""; |
|
75 |
|
|
76 |
Browser browser; |
|
77 |
|
|
78 |
CommandLink(Browser browser) { |
|
79 |
super(browser, "txmcommand"); |
|
80 |
this.browser = browser; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public Object function(Object[] arguments) { |
|
85 |
if (arguments.length == 0) return null; |
|
86 |
|
|
87 |
HashMap<String, String> params = new HashMap<>(); |
|
88 |
for (int i = 0; i < arguments.length; i += 2) { |
|
89 |
params.put(arguments[i].toString(), arguments[i + 1].toString()); |
|
90 |
} |
|
91 |
|
|
92 |
String id = params.get("id"); |
|
93 |
if (id != null) { |
|
94 |
params.remove("id"); |
|
95 |
// System.out.println("CALLING CMD with id="+id+" and parameters="+params); |
|
96 |
// get the command from plugin.xml |
|
97 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
98 |
ICommandService cmdService = window.getService(ICommandService.class); |
|
99 |
Command cmd = cmdService.getCommand(id); |
|
100 |
|
|
101 |
// get the parameter |
|
102 |
ArrayList<Parameterization> parameters = new ArrayList<>(); |
|
103 |
for (String k : params.keySet()) { |
|
104 |
try { |
|
105 |
IParameter iparam = cmd.getParameter(k); |
|
106 |
Parameterization p = new Parameterization(iparam, params.get(k)); |
|
107 |
parameters.add(p); |
|
108 |
} |
|
109 |
catch (NotDefinedException e) { |
|
110 |
System.out.println("warning: unknown parameter id=" + k); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
// build the parameterized command |
|
115 |
ParameterizedCommand pc = new ParameterizedCommand(cmd, parameters.toArray(new Parameterization[parameters.size()])); |
|
116 |
|
|
117 |
// execute the command |
|
118 |
IHandlerService handlerService = window.getService(IHandlerService.class); |
|
119 |
try { |
|
120 |
handlerService.executeCommand(pc, null); |
|
121 |
} |
|
122 |
catch (Exception e) { |
|
123 |
e.printStackTrace(); |
|
124 |
} |
|
125 |
} |
|
126 |
else { |
|
127 |
System.out.println("Cannot call txmcommand without 'id' parameter: " + params); |
|
128 |
} |
|
129 |
return arguments; |
|
130 |
} |
|
131 |
} |
|
132 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditorToolBar.java (revision 3105) | ||
---|---|---|
55 | 55 |
|
56 | 56 |
private ToolBarManager manager; |
57 | 57 |
|
58 |
private DropDownCheckToolItem openCloseButton; |
|
59 |
|
|
58 | 60 |
/** |
59 | 61 |
* |
60 | 62 |
* The parent layout must be a GridLayout. |
... | ... | |
196 | 198 |
public Group installAlternativesGroup(final String groupTitle, String buttonToolTip, String openIconFilePath, String closeIconFilePath, boolean showGroup, |
197 | 199 |
SelectionListener selectionListener, List<String> modes, List<SelectionListener> modeSelectionListeners) { |
198 | 200 |
|
199 |
final DropDownCheckToolItem openCloseButton = new DropDownCheckToolItem(this, buttonToolTip, openIconFilePath, closeIconFilePath);
|
|
201 |
openCloseButton = new DropDownCheckToolItem(this, buttonToolTip, openIconFilePath, closeIconFilePath); |
|
200 | 202 |
|
201 | 203 |
openCloseButton.addSelectionListener(new SelectionListener() { |
202 | 204 |
|
... | ... | |
348 | 350 |
|
349 | 351 |
return groups.get(id).isVisible(); |
350 | 352 |
} |
353 |
|
|
354 |
public DropDownCheckToolItem getOpenCloseButton() { |
|
355 |
return openCloseButton; |
|
356 |
} |
|
351 | 357 |
} |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 3105) | ||
---|---|---|
761 | 761 |
|
762 | 762 |
@Override |
763 | 763 |
public final void setFocus() { |
764 |
if (this.parent.isDisposed()) return; // avoid SWTException |
|
764 | 765 |
|
765 | 766 |
this.parent.setFocus(); |
766 | 767 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMBrowserEditor.java (revision 3105) | ||
---|---|---|
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.editors; |
|
29 |
|
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.eclipse.jface.action.MenuManager; |
|
33 |
import org.eclipse.jface.text.ITextSelection; |
|
34 |
import org.eclipse.jface.viewers.ISelection; |
|
35 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
36 |
import org.eclipse.jface.viewers.ISelectionProvider; |
|
37 |
import org.eclipse.swt.SWT; |
|
38 |
import org.eclipse.swt.browser.Browser; |
|
39 |
import org.eclipse.swt.browser.ProgressEvent; |
|
40 |
import org.eclipse.swt.browser.ProgressListener; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
42 |
import org.eclipse.swt.events.SelectionListener; |
|
43 |
import org.eclipse.swt.graphics.Image; |
|
44 |
import org.eclipse.swt.layout.FormAttachment; |
|
45 |
import org.eclipse.swt.layout.FormData; |
|
46 |
import org.eclipse.swt.layout.FormLayout; |
|
47 |
import org.eclipse.swt.layout.RowData; |
|
48 |
import org.eclipse.swt.layout.RowLayout; |
|
49 |
import org.eclipse.swt.widgets.Button; |
|
50 |
import org.eclipse.swt.widgets.Composite; |
|
51 |
import org.eclipse.swt.widgets.Label; |
|
52 |
import org.eclipse.swt.widgets.Menu; |
|
53 |
import org.eclipse.ui.internal.browser.BrowserViewer; |
|
54 |
import org.eclipse.ui.internal.browser.WebBrowserEditor; |
|
55 |
import org.txm.objects.Edition; |
|
56 |
import org.txm.objects.Page; |
|
57 |
import org.txm.objects.Project; |
|
58 |
import org.txm.objects.Text; |
|
59 |
import org.txm.rcp.IImageKeys; |
|
60 |
import org.txm.rcp.StatusLine; |
|
61 |
import org.txm.rcp.messages.TXMUIMessages; |
|
62 |
|
|
63 |
/** |
|
64 |
* Call the internal browser of RCP specialized for TXM editions. |
|
65 |
* |
|
66 |
* A Text can be set then the user can browse pages and others texts of the same corpus |
|
67 |
* |
|
68 |
* @author mdecorde. |
|
69 |
*/ |
|
70 |
@SuppressWarnings("restriction") |
|
71 |
public class TXMBrowserEditor extends WebBrowserEditor { |
|
72 |
|
|
73 |
/** The Constant ID. */ |
|
74 |
public final static String ID = "org.txm.rcp.editors.TXMBrowser"; //$NON-NLS-1$ |
|
75 |
|
|
76 |
private ProgressListener progresslistener; |
|
77 |
|
|
78 |
private List<String> wordids; |
|
79 |
|
|
80 |
private List<String> lineids; |
|
81 |
|
|
82 |
/** The edition. */ |
|
83 |
Edition edition; |
|
84 |
|
|
85 |
/** The current page. */ |
|
86 |
Page currentPage; |
|
87 |
|
|
88 |
/** The page_label. */ |
|
89 |
Label page_label; |
|
90 |
|
|
91 |
/** |
|
92 |
* Instantiates a new txm browser. |
|
93 |
*/ |
|
94 |
public TXMBrowserEditor() { |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Gets the browser. |
|
100 |
* |
|
101 |
* @return the browser |
|
102 |
*/ |
|
103 |
public Browser getBrowser() { |
|
104 |
BrowserViewer webbrowser = this.webBrowser; |
|
105 |
return webbrowser.getBrowser(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public void setPartName(String partName) { |
|
110 |
super.setPartName(partName); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void setTitleImage(Image titleImage) { |
|
115 |
super.setTitleImage(titleImage); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* |
|
120 |
* @param wordids2 all the words to highlight |
|
121 |
* @param lineids2 the words to highlight better and to scroll to |
|
122 |
*/ |
|
123 |
public void setWordsIds(List<String> wordids2, List<String> lineids2) { |
|
124 |
this.wordids = wordids2; |
|
125 |
this.lineids = lineids2; |
|
126 |
if (progresslistener != null) |
|
127 |
this.getBrowser().removeProgressListener(progresslistener); |
|
128 |
progresslistener = new ProgressListener() { |
|
129 |
|
|
130 |
@Override |
|
131 |
public void changed(ProgressEvent event) {} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void completed(ProgressEvent event) { |
|
135 |
Page currentpage = getCurrentPage(); |
|
136 |
// System.out.println("Highlight ! "+currentpage.getEdition().getText()+" wordids ="+wordids); |
|
137 |
|
|
138 |
for (String wordid : wordids) { |
|
139 |
String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
140 |
"elt.style.backgroundColor=\"#F9D0D0\";" //$NON-NLS-1$ |
|
141 |
+ |
|
142 |
"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
143 |
"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
144 |
"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
145 |
"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
146 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
147 |
|
|
148 |
getBrowser().execute(highlightscript); |
|
149 |
} |
|
150 |
|
|
151 |
for (String wordid : lineids) { |
|
152 |
String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
153 |
"elt.style.backgroundColor=\"#F9A0A0\";" + //$NON-NLS-1$ |
|
154 |
"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
155 |
"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
156 |
"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
157 |
"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
158 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
159 |
|
|
160 |
getBrowser().execute(highlightscript); |
|
161 |
} |
|
162 |
if (lineids.size() > 0) { |
|
163 |
String script = "try { document.getElementById(\"" + lineids.get(0) + "\").scrollIntoView(true); } catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
164 |
getBrowser().execute(script); |
|
165 |
} |
|
166 |
} |
|
167 |
}; |
|
168 |
getBrowser().addProgressListener(progresslistener); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Sets the edition. |
|
173 |
* |
|
174 |
* @param edition the new edition |
|
175 |
*/ |
|
176 |
public void setEdition(Edition edition) { |
|
177 |
this.edition = edition; |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Make page label. |
|
182 |
* |
|
183 |
* @return the string |
|
184 |
*/ |
|
185 |
public String makePageLabel() { |
|
186 |
return currentPage.getName() |
|
187 |
+ " / " + currentPage.getEdition().getNumPages(); //$NON-NLS-1$ |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Show page. |
|
192 |
* |
|
193 |
* @param page the page |
|
194 |
*/ |
|
195 |
public void showPage(Page page) { |
|
196 |
edition = page.getEdition(); |
|
197 |
currentPage = page; |
|
198 |
this.webBrowser.setURL(currentPage.toURL()); |
|
199 |
page_label.setText(makePageLabel()); |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* First text. |
|
204 |
*/ |
|
205 |
public void firstText() { |
|
206 |
Text current = this.currentPage.getEdition().getText(); |
|
207 |
Project corpus = current.getProject(); |
|
208 |
Text firstText = corpus.getFirstText(); |
|
209 |
|
|
210 |
if (firstText != null) { |
|
211 |
String editionName = corpus.getDefaultEditionName(); |
|
212 |
currentPage = firstText.getEdition(editionName).getFirstPage(); |
|
213 |
if (currentPage == null) { |
|
214 |
StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
215 |
return; |
|
216 |
} |
|
217 |
this.setEdition(firstText.getEdition(editionName)); |
|
218 |
this.webBrowser.setURL(currentPage.toURL()); |
|
219 |
page_label.setText(makePageLabel()); |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Last text. |
|
225 |
*/ |
|
226 |
public void lastText() { |
|
227 |
Text current = this.currentPage.getEdition().getText(); |
|
228 |
Project b = current.getProject(); |
|
229 |
Text lastText = b.getLastText(); |
|
230 |
|
|
231 |
if (lastText != null) { |
|
232 |
currentPage = lastText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
233 |
if (currentPage == null) { |
|
234 |
StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
235 |
return; |
|
236 |
} |
|
237 |
this.setEdition(lastText.getEdition(b.getDefaultEditionName())); |
|
238 |
this.webBrowser.setURL(currentPage.toURL()); |
|
239 |
page_label.setText(makePageLabel()); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* First page. |
|
245 |
*/ |
|
246 |
public void firstPage() { |
|
247 |
// System.out.println(Messages.TxmBrowser_1+currentPage); |
|
248 |
currentPage = edition.getFirstPage(); |
|
249 |
this.webBrowser.setURL(currentPage.toURL()); |
|
250 |
page_label.setText(makePageLabel()); |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Last page. |
|
255 |
*/ |
|
256 |
public void lastPage() { |
|
257 |
// System.out.println(Messages.TxmBrowser_2+currentPage); |
|
258 |
|
|
259 |
if (currentPage != null && currentPage.getFile().equals(edition.getLastPage().getFile())) |
|
260 |
return; |
|
261 |
currentPage = edition.getLastPage(); |
|
262 |
this.webBrowser.setURL(currentPage.toURL()); |
|
263 |
page_label.setText(makePageLabel()); |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* Previous page. |
|
268 |
*/ |
|
269 |
public void previousPage() { |
|
270 |
// System.out.println(Messages.TxmBrowser_3+currentPage); |
|
271 |
if (currentPage != null) { |
|
272 |
Page previous = edition.getPreviousPage(currentPage); |
|
273 |
if (previous == currentPage) { |
|
274 |
previousText(true); |
|
275 |
} |
|
276 |
else { |
|
277 |
currentPage = previous; |
|
278 |
this.webBrowser.setURL(currentPage.toURL()); |
|
279 |
} |
|
280 |
} |
|
281 |
else |
|
282 |
firstPage(); |
|
283 |
page_label.setText(makePageLabel()); |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* Next page. |
|
288 |
*/ |
|
289 |
public void nextPage() { |
|
290 |
// System.out.println(Messages.TxmBrowser_4+currentPage); |
|
291 |
if (currentPage != null) { |
|
292 |
Page next = edition.getNextPage(currentPage); |
|
293 |
if (currentPage == next) { |
|
294 |
nextText(); |
|
295 |
} |
|
296 |
else { |
|
297 |
currentPage = next; |
|
298 |
this.webBrowser.setURL(currentPage.toURL()); |
|
299 |
} |
|
300 |
|
|
301 |
} |
|
302 |
else |
|
303 |
firstPage(); |
|
304 |
page_label.setText(makePageLabel()); |
|
305 |
} |
|
306 |
|
|
307 |
/** |
|
308 |
* Previous text. |
|
309 |
* |
|
310 |
* @param fromNextText |
|
311 |
*/ |
|
312 |
public void previousText(boolean fromNextText) { |
|
313 |
|
|
314 |
Text current = this.currentPage.getEdition().getText(); |
|
315 |
Project corpus = current.getProject(); |
|
316 |
Text previousText = corpus.getPreviousText(current); |
|
317 |
|
|
318 |
if (previousText != null) { |
|
319 |
String editionName = corpus.getDefaultEditionName(); |
|
320 |
if (fromNextText) { |
|
321 |
currentPage = previousText.getEdition(editionName).getLastPage(); |
|
322 |
} |
|
323 |
else { |
|
324 |
currentPage = previousText.getEdition(editionName).getFirstPage(); |
|
325 |
} |
|
326 |
if (currentPage == null) { |
|
327 |
StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
328 |
return; |
|
329 |
} |
|
330 |
this.setEdition(previousText.getEdition(editionName)); |
|
331 |
this.webBrowser.setURL(currentPage.toURL()); |
|
332 |
page_label.setText(makePageLabel()); |
|
333 |
} |
|
334 |
// System.out.println("Previous texts "+previousText); |
|
335 |
} |
|
336 |
|
|
337 |
/** |
|
338 |
* Next text. |
|
339 |
*/ |
|
340 |
public void nextText() { |
|
341 |
Text current = this.currentPage.getEdition().getText(); |
|
342 |
Project b = current.getProject(); |
|
343 |
Text nextText = b.getNextText(current); |
|
344 |
|
|
345 |
if (nextText != null) { |
|
346 |
currentPage = nextText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
347 |
if (currentPage == null) { |
|
348 |
StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
349 |
return; |
|
350 |
} |
|
351 |
this.setEdition(nextText.getEdition(b.getDefaultEditionName())); |
|
352 |
this.webBrowser.setURL(currentPage.toURL()); |
|
353 |
page_label.setText(makePageLabel()); |
|
354 |
} |
|
355 |
// System.out.println("Next texts "+nextText); |
|
356 |
} |
|
357 |
|
|
358 |
/* |
|
359 |
* (non-Javadoc) |
|
360 |
* @see org.eclipse.ui.internal.browser.WebBrowserEditor#createPartControl(org.eclipse.swt.widgets.Composite) |
|
361 |
*/ |
|
362 |
@Override |
|
363 |
public void createPartControl(Composite parent) { |
|
364 |
try { |
|
365 |
super.createPartControl(parent); |
|
366 |
} |
|
367 |
catch (Exception e) { |
|
368 |
System.err.println(TXMUIMessages.couldNotLaunchTheInternalWebBrowserYouMustSetThatParameterInThePreferencesMenuColonGeneralSupWebNavigator); |
|
369 |
return; |
|
370 |
} |
|
371 |
|
|
372 |
RowLayout navigLayout = new RowLayout(SWT.HORIZONTAL); |
|
373 |
navigLayout.justify = true; |
|
374 |
Composite panneau = new Composite(parent, SWT.NONE); |
|
375 |
panneau.setLayout(navigLayout); |
|
376 |
|
|
377 |
RowLayout subLayout = new RowLayout(SWT.HORIZONTAL); |
|
378 |
subLayout.pack = true; |
|
379 |
subLayout.center = true; |
|
380 |
subLayout.marginBottom = subLayout.marginHeight = 0; |
|
381 |
subLayout.marginTop = subLayout.marginWidth = 0; |
|
382 |
Composite subPanneau = new Composite(panneau, SWT.NONE); |
|
383 |
subPanneau.setLayout(subLayout); |
|
384 |
subPanneau.setLayoutData(new RowData(450, 22)); |
|
385 |
|
|
386 |
Button firstText = new Button(subPanneau, SWT.FLAT); |
|
387 |
Button previousText = new Button(subPanneau, SWT.FLAT); |
|
388 |
Button first = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
389 |
Button previous = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
390 |
page_label = new Label(subPanneau, SWT.NONE); |
|
391 |
Button next = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
392 |
Button last = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
393 |
Button nextText = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
394 |
Button lastText = new Button(subPanneau, SWT.FLAT | SWT.PUSH); |
|
395 |
|
|
396 |
// set sizes |
|
397 |
page_label.setLayoutData(new RowData(50, 20)); |
|
398 |
firstText.setLayoutData(new RowData(30, 20)); |
|
399 |
first.setLayoutData(new RowData(30, 20)); |
|
400 |
previous.setLayoutData(new RowData(30, 20)); |
|
401 |
next.setLayoutData(new RowData(30, 20)); |
|
402 |
last.setLayoutData(new RowData(30, 20)); |
|
403 |
nextText.setLayoutData(new RowData(30, 20)); |
|
404 |
previousText.setLayoutData(new RowData(30, 20)); |
|
405 |
lastText.setLayoutData(new RowData(30, 20)); |
|
406 |
|
|
407 |
|
|
408 |
// set labels |
|
409 |
page_label.setText(""); //$NON-NLS-1$ |
|
410 |
firstText.setImage(IImageKeys.getImage(IImageKeys.CTRLREWINDSTART)); |
|
411 |
firstText.setToolTipText("|<<"); |
|
412 |
previousText.setImage(IImageKeys.getImage(IImageKeys.CTRLREWIND)); |
|
413 |
previousText.setToolTipText(TXMUIMessages.previousText); |
|
414 |
first.setImage(IImageKeys.getImage(IImageKeys.CTRLSTART)); |
|
415 |
first.setToolTipText(TXMUIMessages.common_beginning); |
|
416 |
previous.setImage(IImageKeys.getImage(IImageKeys.CTRLREVERSE)); |
|
417 |
previous.setToolTipText(TXMUIMessages.previousPage); |
|
418 |
next.setImage(IImageKeys.getImage(IImageKeys.CTRLPLAY)); |
|
419 |
next.setToolTipText(TXMUIMessages.nextPage); |
|
420 |
last.setImage(IImageKeys.getImage(IImageKeys.CTRLEND)); |
|
421 |
last.setToolTipText(TXMUIMessages.common_end); |
|
422 |
nextText.setImage(IImageKeys.getImage(IImageKeys.CTRLFASTFORWARD)); |
|
423 |
nextText.setToolTipText(TXMUIMessages.nextText); |
|
424 |
lastText.setImage(IImageKeys.getImage(IImageKeys.CTRLFASTFORWARDEND)); |
|
425 |
lastText.setToolTipText(">>|"); |
|
426 |
|
|
427 |
|
|
428 |
// set listeners |
|
429 |
first.addSelectionListener(new SelectionListener() { |
|
430 |
|
|
431 |
@Override |
|
432 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
433 |
firstPage(); |
|
434 |
} |
|
435 |
|
|
436 |
@Override |
|
437 |
public void widgetSelected(SelectionEvent e) { |
|
438 |
firstPage(); |
|
439 |
} |
|
440 |
}); |
|
441 |
previous.addSelectionListener(new SelectionListener() { |
|
442 |
|
|
443 |
@Override |
|
444 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
445 |
previousPage(); |
|
446 |
} |
|
447 |
|
|
448 |
@Override |
|
449 |
public void widgetSelected(SelectionEvent e) { |
|
450 |
previousPage(); |
|
451 |
} |
|
452 |
}); |
|
453 |
next.addSelectionListener(new SelectionListener() { |
|
454 |
|
|
455 |
@Override |
|
456 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
457 |
nextPage(); |
|
458 |
} |
|
459 |
|
|
460 |
@Override |
|
461 |
public void widgetSelected(SelectionEvent e) { |
|
462 |
nextPage(); |
|
463 |
} |
|
464 |
}); |
|
465 |
last.addSelectionListener(new SelectionListener() { |
|
466 |
|
|
467 |
@Override |
|
468 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
469 |
lastPage(); |
|
470 |
} |
|
471 |
|
|
472 |
@Override |
|
473 |
public void widgetSelected(SelectionEvent e) { |
|
474 |
lastPage(); |
|
475 |
} |
|
476 |
}); |
|
477 |
nextText.addSelectionListener(new SelectionListener() { |
|
478 |
|
|
479 |
@Override |
|
480 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
481 |
nextText(); |
|
482 |
} |
|
483 |
|
|
484 |
@Override |
|
485 |
public void widgetSelected(SelectionEvent e) { |
|
486 |
nextText(); |
|
487 |
} |
|
488 |
}); |
|
489 |
// set listeners |
|
490 |
previousText.addSelectionListener(new SelectionListener() { |
|
491 |
|
|
492 |
@Override |
|
493 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
494 |
previousText(false); |
|
495 |
} |
|
496 |
|
|
497 |
@Override |
|
498 |
public void widgetSelected(SelectionEvent e) { |
|
499 |
previousText(false); |
|
500 |
} |
|
501 |
}); |
|
502 |
lastText.addSelectionListener(new SelectionListener() { |
|
503 |
|
|
504 |
@Override |
|
505 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
506 |
lastText(); |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public void widgetSelected(SelectionEvent e) { |
|
511 |
lastText(); |
|
512 |
} |
|
513 |
}); |
|
514 |
// set listeners |
|
515 |
firstText.addSelectionListener(new SelectionListener() { |
|
516 |
|
|
517 |
@Override |
|
518 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
519 |
firstText(); |
|
520 |
} |
|
521 |
|
|
522 |
@Override |
|
523 |
public void widgetSelected(SelectionEvent e) { |
|
524 |
firstText(); |
|
525 |
} |
|
526 |
}); |
|
527 |
|
|
528 |
subPanneau.pack(); |
|
529 |
panneau.pack(); |
|
530 |
|
|
531 |
FormLayout parentLayout = new FormLayout(); |
|
532 |
|
|
533 |
FormData datatop = new FormData(); |
|
534 |
datatop.top = new FormAttachment(0, 0); |
|
535 |
datatop.left = new FormAttachment(0, 0); |
|
536 |
datatop.right = new FormAttachment(100, 0); |
|
537 |
datatop.bottom = new FormAttachment(panneau, 0); |
|
538 |
webBrowser.setLayoutData(datatop); |
|
539 |
|
|
540 |
FormData databottom = new FormData(200, 30); |
|
541 |
databottom.bottom = new FormAttachment(100, 0); |
|
542 |
databottom.left = new FormAttachment(30, -100); |
|
543 |
databottom.right = new FormAttachment(80, 100); |
|
544 |
panneau.setLayoutData(databottom); |
|
545 |
|
|
546 |
parent.setLayout(parentLayout); |
|
547 |
parent.pack(); |
|
548 |
|
|
549 |
MenuManager menuManager = new MenuManager(); |
|
550 |
Menu menu = menuManager.createContextMenu(getBrowser()); |
|
551 |
|
|
552 |
// Set the MenuManager |
|
553 |
getBrowser().setMenu(menu); |
|
554 |
ISelectionProvider selProvider = new ISelectionProvider() { |
|
555 |
|
|
556 |
@Override |
|
557 |
public void setSelection(ISelection selection) {} |
|
558 |
|
|
559 |
@Override |
|
560 |
public void removeSelectionChangedListener(ISelectionChangedListener listener) {} |
|
561 |
|
|
562 |
@Override |
|
563 |
public ISelection getSelection() { |
|
564 |
ITextSelection sel = new ITextSelection() { |
|
565 |
|
|
566 |
@Override |
|
567 |
public boolean isEmpty() { |
|
568 |
return false; |
|
569 |
} |
|
570 |
|
|
571 |
@Override |
|
572 |
public String getText() { |
|
573 |
return getTextSelection(); |
|
574 |
} |
|
575 |
|
|
576 |
@Override |
|
577 |
public int getStartLine() { |
|
578 |
return 0; |
|
579 |
} |
|
580 |
|
|
581 |
@Override |
|
582 |
public int getOffset() { |
|
583 |
return 0; |
|
584 |
} |
|
585 |
|
|
586 |
@Override |
|
587 |
public int getLength() { |
|
588 |
return 0; |
|
589 |
} |
|
590 |
|
|
591 |
@Override |
|
592 |
public int getEndLine() { |
|
593 |
return 0; |
|
594 |
} |
|
595 |
}; |
|
596 |
return sel; |
|
597 |
} |
|
598 |
|
|
599 |
@Override |
|
600 |
public void addSelectionChangedListener(ISelectionChangedListener listener) {} |
|
601 |
}; |
|
602 |
getSite().registerContextMenu(menuManager, selProvider); |
|
603 |
getSite().setSelectionProvider(selProvider); |
|
604 |
|
|
605 |
// System.out.println("Browser menu: "+getBrowser().getMenu()); |
|
606 |
} |
|
607 |
|
|
608 |
static String SCRIPT01 = "var html = \"\";" + |
|
609 |
"if (typeof window.getSelection != \"undefined\") {" + // modern Web browsers |
|
610 |
"var sel = window.getSelection();" + |
|
611 |
"if (sel.rangeCount) {" + |
|
612 |
"var container = document.createElement(\"div\");" + |
|
613 |
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {" + |
|
614 |
"container.appendChild(sel.getRangeAt(i).cloneContents());" + |
|
615 |
"}" + |
|
616 |
"html = container.innerHTML;" + |
|
617 |
"}" + |
|
618 |
"} else if (typeof document.selection != \"undefined\") {" + // for IE < 11 |
|
619 |
"if (document.selection.type == \"Text\") {" + |
|
620 |
"html = document.selection.createRange().htmlText;" + |
|
621 |
"}" + |
|
622 |
"}" + |
|
623 |
"return html"; |
|
624 |
|
|
625 |
// return the span@id of the current selection |
|
626 |
static String SCRIPT02 = "function getChildren(node) {\n" |
|
627 |
+ "if (node.children != \"undefined\")\n" |
|
628 |
+ " return node.children;\n" |
|
629 |
+ "else \n" |
|
630 |
+ "return node.ChildNodes;\n" |
Formats disponibles : Unified diff