Révision 3075

tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMBrowser.java (revision 3075)
40 40
import org.eclipse.swt.browser.ProgressListener;
41 41
import org.eclipse.swt.events.SelectionEvent;
42 42
import org.eclipse.swt.events.SelectionListener;
43
import org.eclipse.swt.graphics.Image;
43 44
import org.eclipse.swt.layout.FormAttachment;
44 45
import org.eclipse.swt.layout.FormData;
45 46
import org.eclipse.swt.layout.FormLayout;
......
107 108
		return webbrowser.getBrowser();
108 109
	}
109 110
	
111
	public void load(String url, String partName) {
112
		this.getBrowser().setUrl(url);
113
		setPartName(partName);
114
	}
115
	
110 116
	@Override
111 117
	public void setPartName(String partName) {
112 118
		super.setPartName(partName);
113 119
	}
114 120
	
121
	@Override
122
	public void setTitleImage(Image titleImage) {
123
		super.setTitleImage(titleImage);
124
	}
125
	
115 126
	/**
116 127
	 * 
117 128
	 * @param wordids2 all the words to highlight
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/OpenBrowser.java (revision 3075)
58 58
/**
59 59
 * Open the internal browser of TXM with a file @ author mdecorde.
60 60
 */
61
@SuppressWarnings("restriction") //$NON-NLS-1$
61
@SuppressWarnings("restriction")
62 62
public class OpenBrowser extends AbstractHandler {
63

  
63
	
64 64
	/** The Constant ID. */
65 65
	public final static String ID = "org.txm.rcp.commands.OpenBrowser"; //$NON-NLS-1$
66

  
66
	
67 67
	/** The lastopenedfile. */
68 68
	public static String lastopenedfile;
69

  
70
	/* (non-Javadoc)
69
	
70
	/*
71
	 * (non-Javadoc)
71 72
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
72 73
	 */
73 74
	@Override
74 75
	public Object execute(ExecutionEvent event) throws ExecutionException {
75

  
76
		
76 77
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
77 78
				.getShell();
78

  
79
		
79 80
		String filename = event
80 81
				.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
81 82
		if (filename != null && !filename.matches("") && !filename.matches(" ")) //$NON-NLS-1$ //$NON-NLS-2$
......
83 84
			openfile(filename);
84 85
			return null;
85 86
		}
86

  
87
		
87 88
		File file = null;
88 89
		ISelection selection = HandlerUtil.getCurrentSelection(event);
89 90
		if (selection != null & selection instanceof IStructuredSelection) {
......
95 96
				}
96 97
			}
97 98
		}
98

  
99
		
99 100
		if (file == null) {
100 101
			FileDialog dialog = new FileDialog(shell, SWT.OPEN);
101 102
			String txmhome = Toolbox.getTxmHomePath();
102 103
			if (LastOpened.getFile(ID) != null) {
103 104
				dialog.setFilterPath(LastOpened.getFolder(ID));
104 105
				dialog.setFileName(LastOpened.getFile(ID));
105
			} else {
106
				dialog.setFilterPath(txmhome); 
107 106
			}
107
			else {
108
				dialog.setFilterPath(txmhome);
109
			}
108 110
			if (dialog.open() != null) {
109 111
				String filepath = dialog.getFilterPath()
110 112
						+ "/" + dialog.getFileName(); //$NON-NLS-1$
......
114 116
					return openfile(filepath);
115 117
				}
116 118
			}
117
		} else {
119
		}
120
		else {
118 121
			if (file.isDirectory()) {
119 122
				FileDialog dialog = new FileDialog(shell, SWT.OPEN);
120 123
				dialog.setFilterPath(file.getAbsolutePath());
......
124 127
				LastOpened.set(ID, dialog.getFilterPath(), dialog.getFileName());
125 128
				lastopenedfile = filepath;
126 129
				return openfile(filepath);
127
			} else
130
			}
131
			else
128 132
				return openfile(file.getAbsolutePath());
129 133
		}
130 134
		return null;
131 135
	}
132

  
136
	
133 137
	/**
134 138
	 * Openfile.
135 139
	 *
......
139 143
	static public TXMBrowser openEdition(String filepath) {
140 144
		return openEdition(filepath, new File(filepath).getName());
141 145
	}
142

  
146
	
143 147
	/**
144 148
	 * Openfile.
145 149
	 *
146 150
	 * @param filepath the filepath
147 151
	 * @return the txm browser
148 152
	 */
149
	static public TXMWebBrowserEditor openfile(String filepath) {
153
	static public TXMBrowser openfile(String filepath) {
150 154
		return openfile(filepath, new File(filepath).getName());
151 155
	}
152

  
156
	
153 157
	static public void openExternalBrowser(String url) {
154 158
		try {
155 159
			PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url));
156
		} catch (Exception e1) {
160
		}
161
		catch (Exception e1) {
157 162
			e1.printStackTrace();
158 163
		}
159 164
	}
160

  
165
	
161 166
	/**
162 167
	 * Open a file given a path in a Web editor.
163 168
	 *
164 169
	 * @param filepath the filepath
165 170
	 * @param editorname the editorname
166
	 * @return the txm browser
171
	 * @return the TXM browser
167 172
	 */
168 173
	public static TXMBrowser openEdition(String filepath, String editorname) {
169 174
		try {
170 175
			// WebBrowserEditorInput editorInput = new WebBrowserEditorInput();
171
			//TODO: is web browser type order useful ?
172
			//System.setProperty("org.eclipse.swt.browser.DefaultType", "ie,mozilla,webkit");
173
			//System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "");
176
			// TODO: is web browser type order useful ?
177
			// System.setProperty("org.eclipse.swt.browser.DefaultType", "ie,mozilla,webkit");
178
			// System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "");
174 179
			WebBrowserEditorInput editorInput;
175 180
			File localfile = new File(filepath);
176 181
			if (localfile.exists())
177
				editorInput = new WebBrowserEditorInput(localfile.toURI()
178
						.toURL(), BrowserViewer.BUTTON_BAR
179
						| BrowserViewer.LOCATION_BAR);
182
				editorInput = new WebBrowserEditorInput(localfile.toURI().toURL(), BrowserViewer.BUTTON_BAR | BrowserViewer.LOCATION_BAR);
180 183
			else
181
				editorInput = new WebBrowserEditorInput(new URL(filepath),
182
						BrowserViewer.BUTTON_BAR | BrowserViewer.LOCATION_BAR);
183
			IWorkbenchWindow window = PlatformUI.getWorkbench()
184
					.getActiveWorkbenchWindow();
184
				editorInput = new WebBrowserEditorInput(new URL(filepath), BrowserViewer.BUTTON_BAR | BrowserViewer.LOCATION_BAR);
185
			
186
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
185 187
			IWorkbenchPage page = window.getActivePage();
186

  
187
			TXMBrowser editor = (TXMBrowser) page.openEditor(editorInput,
188
					TXMBrowser.ID, true);
188
			
189
			TXMBrowser editor = (TXMBrowser) page.openEditor(editorInput, TXMBrowser.ID, true);
189 190
			editor.setPartName(editorname);
190 191
			return editor;
191
		} catch (Exception e) {
192
			Log.severe(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));
193
			System.out.println(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));
194 192
		}
193
		catch (Exception e) {
194
			Log.warning(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));
195
			Log.printStackTrace(e);
196
		}
195 197
		return null;
196 198
	}
197

  
199
	
198 200
	/**
199 201
	 * Openfile.
200 202
	 *
......
202 204
	 * @param editorname the editorname
203 205
	 * @return the txm browser
204 206
	 */
205
	public static TXMWebBrowserEditor openfile(String filepath, String editorname) {
207
	public static TXMBrowser openfile(String filepath, String editorname) {
206 208
		try {
207
			// WebBrowserEditorInput editorInput = new WebBrowserEditorInput();
208
			WebBrowserEditorInput editorInput;
209
			File localfile = new File(filepath);
210
			if (localfile.exists())
211
				editorInput = new WebBrowserEditorInput(localfile.toURI()
212
						.toURL(), BrowserViewer.BUTTON_BAR
213
						| BrowserViewer.LOCATION_BAR);
214
			else
215
				editorInput = new WebBrowserEditorInput(new URL(filepath),
216
						BrowserViewer.BUTTON_BAR | BrowserViewer.LOCATION_BAR);
217

  
218
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
219
			//System.out.println("Window: "+window);
220
			IWorkbenchPage page = window.getActivePage();
221

  
222
			try {
223
				IEditorPart e = page.openEditor(editorInput, TXMWebBrowserEditor.WEB_BROWSER_EDITOR_ID, true);
224
				if (e instanceof TXMWebBrowserEditor) {
225
					TXMWebBrowserEditor editor = (TXMWebBrowserEditor) e;
226
					editor.setTitle(editorname);
227
					return editor;
228
				}
229
			} catch (SWTError e) {
230
				Log.severe("TXM could not open the internal browser: "+e);
231
				Log.printStackTrace(e);
232
			}
233
		} catch (Exception e) {
209
			return openEdition(filepath, editorname);
210
			// // WebBrowserEditorInput editorInput = new WebBrowserEditorInput();
211
			// WebBrowserEditorInput editorInput;
212
			// File localfile = new File(filepath);
213
			// if (localfile.exists())
214
			// editorInput = new WebBrowserEditorInput(localfile.toURI()
215
			// .toURL(), BrowserViewer.BUTTON_BAR
216
			// | BrowserViewer.LOCATION_BAR);
217
			// else
218
			// editorInput = new WebBrowserEditorInput(new URL(filepath),
219
			// BrowserViewer.BUTTON_BAR | BrowserViewer.LOCATION_BAR);
220
			//
221
			// IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
222
			// // System.out.println("Window: "+window);
223
			// IWorkbenchPage page = window.getActivePage();
224
			//
225
			// try {
226
			// IEditorPart e = page.openEditor(editorInput, TXMWebBrowserEditor.WEB_BROWSER_EDITOR_ID, true);
227
			// if (e instanceof TXMWebBrowserEditor) {
228
			// TXMWebBrowserEditor editor = (TXMWebBrowserEditor) e;
229
			// editor.setTitle(editorname);
230
			// return editor;
231
			// }
232
			// }
233
			// catch (SWTError e) {
234
			// Log.severe("TXM could not open the internal browser: " + e);
235
			// Log.printStackTrace(e);
236
			// }
237
		}
238
		catch (Exception e) {
234 239
			Log.severe(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));
235 240
			System.out.println(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));
236 241
		}
237 242
		return null;
238 243
	}
239
}
244
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/BasesView.java (revision 3075)
63 63
import org.txm.rcp.IImageKeys;
64 64
import org.txm.rcp.commands.OpenBrowser;
65 65
import org.txm.rcp.editors.TXMBrowser;
66
import org.txm.rcp.editors.TXMWebBrowserEditor;
66 67
import org.txm.rcp.handlers.files.EditFile;
67 68
import org.txm.rcp.handlers.results.DeleteObject;
68 69
import org.txm.searchengine.cqp.corpus.CQPCorpus;
......
149 150
				else if (selection.getFirstElement() instanceof Edition) {
150 151
					Edition edition = ((Edition) selection.getFirstElement());
151 152
					Page firstpage = edition.getFirstPage();
152
					TXMBrowser editor = OpenBrowser.openEdition(firstpage
153
							.getFile().getAbsolutePath(), edition.getName());
154
					editor.showPage(firstpage);
153
					TXMBrowser editor = OpenBrowser.openEdition(firstpage.getFile().getAbsolutePath(), edition.getName());
154
					// editor.showPage(firstpage);
155 155
				}
156 156
				else if (selection.getFirstElement() instanceof Page) {
157 157
					Page page = ((Page) selection.getFirstElement());
158
					TXMBrowser editor = OpenBrowser.openEdition(page.getFile()
159
							.getAbsolutePath());
160
					editor.showPage(page);
158
					TXMBrowser editor = OpenBrowser.openEdition(page.getFile().getAbsolutePath());
161 159
				}
162 160
			}
163 161
		});
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/SummaryView.java (revision 3075)
59 59
import org.txm.Toolbox;
60 60
import org.txm.objects.Page;
61 61
import org.txm.rcp.commands.OpenBrowser;
62
import org.txm.rcp.editors.TXMBrowser;
63 62
import org.txm.rcp.messages.TXMUIMessages;
64 63
import org.txm.rcp.swt.widget.PropertiesSelector;
65 64
import org.txm.rcp.views.corpora.CorporaView;
......
91 90
	
92 91
	PropertiesSelector<StructuralUnitProperty> propsArea;
93 92
	
94
	/** The attached browser editor. */
95
	protected TXMBrowser attachedBrowserEditor;
96 93
	
97 94
	/** The ID. */
98 95
	public static String ID = SummaryView.class.getName();
......
352 349
				final Summary.TreeNode node = (Summary.TreeNode) first;
353 350
				
354 351
				try {
355
					final Page openedPage = summary.getDefaultEditionPage(node);
356
					if (openedPage != null) {
357
						// System.out.println(page.getFile());
358
						if (attachedBrowserEditor == null || attachedBrowserEditor.isDisposed()) {
359
							attachedBrowserEditor = OpenBrowser
360
									.openEdition(openedPage.getFile()
361
											.getAbsolutePath(), openedPage.getFile().getName());
362
							attachedBrowserEditor.setEdition(openedPage.getEdition());
363
						}
364
						attachedBrowserEditor.showPage(openedPage);
365
					}
366
					else {
367
						System.out.println(TXMUIMessages.noDefaultEditionPageFoundForElementColon + node);
368
					}
352
					// final Page openedPage = summary.getDefaultEditionPage(node);
353
					// if (openedPage != null) {
354
					// // System.out.println(page.getFile());
355
					// if (attachedBrowserEditor == null || attachedBrowserEditor.isDisposed()) {
356
					// attachedBrowserEditor = OpenBrowser
357
					// .openEdition(openedPage.getFile()
358
					// .getAbsolutePath(), openedPage.getFile().getName());
359
					// attachedBrowserEditor.setEdition(openedPage.getEdition());
360
					// }
361
					// attachedBrowserEditor.showPage(openedPage);
362
					// }
363
					// else {
364
					// System.out.println(TXMUIMessages.noDefaultEditionPageFoundForElementColon + node);
365
					// }
366
					//
367
					// if (progresslistener != null) {
368
					// attachedBrowserEditor.getBrowser().removeProgressListener(progresslistener);
369
					// }
370
					// progresslistener = new ProgressListener() {
371
					//
372
					// @Override
373
					// public void changed(ProgressEvent event) {}
374
					//
375
					// @Override
376
					// public void completed(ProgressEvent event) {
377
					// Page currentpage = attachedBrowserEditor.getCurrentPage();
378
					// // System.out.println("Highlight ! "+currentpage.getEdition().getText()+" name ="+openedPage.getEdition().getText());
379
					// if (currentpage != null) {
380
					// if (!(currentpage.getEdition().getText() == openedPage.getEdition().getText())) {
381
					// return;
382
					// }
383
					// }
384
					// String wordid = node.getWordId();
385
					// String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$
386
					// "elt.style.backgroundColor=\"#F9D0D0\";" //$NON-NLS-1$
387
					// +
388
					// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
389
					// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
390
					// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
391
					// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
392
					// "} catch (e) { };"; //$NON-NLS-1$
393
					//
394
					// attachedBrowserEditor.getBrowser().execute(highlightscript);
395
					//
396
					// String script = "try { document.getElementById(\"" + wordid + "\").scrollIntoView(true); } catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$
397
					// attachedBrowserEditor.getBrowser().execute(script);
398
					// }
399
					// };
400
					//
401
					// attachedBrowserEditor.getBrowser().addProgressListener(progresslistener);
402
					//
403
					// IWorkbenchPage attachedPage = attachedBrowserEditor.getEditorSite().getPage();
404
					// attachedPage.activate(attachedBrowserEditor);
369 405
					
370
					if (progresslistener != null) {
371
						attachedBrowserEditor.getBrowser().removeProgressListener(progresslistener);
372
					}
373
					progresslistener = new ProgressListener() {
374
						
375
						@Override
376
						public void changed(ProgressEvent event) {}
377
						
378
						@Override
379
						public void completed(ProgressEvent event) {
380
							Page currentpage = attachedBrowserEditor.getCurrentPage();
381
							// System.out.println("Highlight ! "+currentpage.getEdition().getText()+" name ="+openedPage.getEdition().getText());
382
							if (currentpage != null) {
383
								if (!(currentpage.getEdition().getText() == openedPage.getEdition().getText())) {
384
									return;
385
								}
386
							}
387
							String wordid = node.getWordId();
388
							String highlightscript = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$
389
									"elt.style.backgroundColor=\"#F9D0D0\";" //$NON-NLS-1$
390
									+
391
									"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
392
									"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
393
									"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
394
									"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
395
									"} catch (e) { };"; //$NON-NLS-1$
396
							
397
							attachedBrowserEditor.getBrowser().execute(highlightscript);
398
							
399
							String script = "try { document.getElementById(\"" + wordid + "\").scrollIntoView(true); } catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$
400
							attachedBrowserEditor.getBrowser().execute(script);
401
						}
402
					};
403
					
404
					attachedBrowserEditor.getBrowser().addProgressListener(progresslistener);
405
					
406
					IWorkbenchPage attachedPage = attachedBrowserEditor.getEditorSite().getPage();
407
					attachedPage.activate(attachedBrowserEditor);
408
					
409 406
				}
410 407
				catch (Exception e) {
411 408
					org.txm.utils.logger.Log.printStackTrace(e);

Formats disponibles : Unified diff