Révision 3104

tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/OpenGraph.java (revision 3104)
38 38
import org.eclipse.swt.widgets.Shell;
39 39
import org.eclipse.ui.IEditorPart;
40 40
import org.eclipse.ui.handlers.HandlerUtil;
41
import org.txm.rcp.IImageKeys;
42
import org.txm.rcp.editors.SVGGraphicEditor;
43
import org.txm.rcp.editors.TXMWebBrowserEditor;
44 41
import org.txm.rcp.messages.TXMUIMessages;
45 42
import org.txm.rcp.swt.dialog.LastOpened;
46 43
import org.txm.rcp.utils.OpenURI;
44

  
47 45
// TODO: Auto-generated Javadoc
48 46
/**
49 47
 * Open the graphics editor. It can open SVN, PNG, etc depending on the Device given.
50 48
 */
51 49

  
52 50
public class OpenGraph extends AbstractHandler {
53

  
51
	
54 52
	private static final String ID = "org.txm.rcp.commands.OpenGraph"; //$NON-NLS-1$
55
	/* (non-Javadoc)
53
	/*
54
	 * (non-Javadoc)
56 55
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
57 56
	 */
57
	
58 58
	@Override
59 59
	public Object execute(ExecutionEvent event) throws ExecutionException {
60 60
		String svgFile = ""; //$NON-NLS-1$
61 61
		File file = null;
62

  
62
		
63 63
		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
64 64
				.getShell();
65

  
65
		
66 66
		if (file == null || file.isDirectory()) {
67 67
			FileDialog dialog = new FileDialog(shell, SWT.OPEN);
68 68
			if (LastOpened.getFile(ID) != null) {
......
74 74
			LastOpened.set(ID, dialog.getFilterPath(), dialog.getFileName());
75 75
			OpenFile(svgFile);
76 76
		}
77

  
77
		
78 78
		return null;
79 79
	}
80

  
80
	
81 81
	/**
82 82
	 * Open file.
83 83
	 *
......
87 87
	public static IEditorPart OpenFile(String filepath) {
88 88
		return OpenFile(filepath, new File(filepath).getName());
89 89
	}
90

  
90
	
91 91
	/**
92 92
	 * Open file.
93 93
	 *
......
97 97
	public static IEditorPart OpenFile(File file) {
98 98
		return OpenFile(file.getAbsolutePath(), file.getName());
99 99
	}
100

  
100
	
101 101
	/**
102 102
	 * Open file.
103 103
	 *
......
117 117
		{
118 118
			return OpenBrowser.openfile(graphfile.getAbsolutePath());
119 119
		}
120
		else
121
		{
120
		else {
122 121
			if (!OpenURI.open(graphfile))
123 122
				System.out.println(NLS.bind(TXMUIMessages.cantOpenGraphicP0, graphfile.getAbsolutePath()));
124 123
			return null;
125 124
		}
126 125
	}
127

  
128
	/**
129
	 * Open file.
130
	 *
131
	 * @param filepath the filepath
132
	 * @param editorname the editorname
133
	 * @param device the device
134
	 * @param image the image
135
	 * @return the i editor part
136
	 */
137
//	@Deprecated
138
	// FIXME: this method is R charts engine dependent. But it seems to no be used so we may remove it
139
//	public static IEditorPart OpenFile(String filepath, String editorname, RDevice device, String image) {
140
//		File graphfile = new File(filepath);
141
//		if (device.equals(RDevice.SVG)) {
142
//			SVGGraphicEditor editor = OpenSVGGraph.OpenSVGFile(filepath, editorname);
143
//			if (image != null && IImageKeys.getImage(image) != null)
144
//				editor.setIcon(IImageKeys.getImage(image));
145
//			return editor;
146
//		} else if (device.equals(RDevice.PNG) || device.equals(RDevice.JPEG)) {
147
//			TXMWebBrowserEditor editor = OpenBrowser.openfile(graphfile.getAbsolutePath(), editorname);
148
//			if (image != null && IImageKeys.getImage(image) != null)
149
//				editor.setTitleImage(IImageKeys.getImage(image));
150
//			return editor;
151
//		} else {
152
//			if (!OpenURI.open(graphfile))
153
//				System.out.println(NLS.bind(Messages.OpenGraph_8, graphfile.getAbsolutePath()));
154
//			return null;
155
//		}
156
//
157
//	}
158

  
159
	/**
160
	 * Open file.
161
	 *
162
	 * @param file the file
163
	 * @param device the device
164
	 * @param name the name
165
	 * @param image the image
166
	 * @return the i editor part
167
	 */
168
//	@Deprecated
169
	// FIXME: this method is R charts engine dependent. But it seems to no be used so we may remove it
170
//	public static IEditorPart OpenFile(File file, RDevice device, String name, String image) {
171
//		return OpenFile(file.getAbsolutePath(), name, device, image);
172
//	}
173

  
174
}
126
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/OpenBrowser.java (revision 3104)
36 36
import org.eclipse.jface.viewers.ISelection;
37 37
import org.eclipse.jface.viewers.IStructuredSelection;
38 38
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.SWTError;
40 39
import org.eclipse.swt.widgets.FileDialog;
41 40
import org.eclipse.swt.widgets.Shell;
42
import org.eclipse.ui.IEditorPart;
43 41
import org.eclipse.ui.IWorkbenchPage;
44 42
import org.eclipse.ui.IWorkbenchWindow;
45 43
import org.eclipse.ui.PlatformUI;
......
47 45
import org.eclipse.ui.internal.browser.BrowserViewer;
48 46
import org.eclipse.ui.internal.browser.WebBrowserEditorInput;
49 47
import org.txm.Toolbox;
50
import org.txm.core.preferences.TBXPreferences;
51
import org.txm.rcp.editors.TXMBrowser;
52
import org.txm.rcp.editors.TXMWebBrowserEditor;
48
import org.txm.rcp.editors.TXMBrowserEditor;
53 49
import org.txm.rcp.messages.TXMUIMessages;
54 50
import org.txm.rcp.swt.dialog.LastOpened;
55 51
import org.txm.utils.logger.Log;
......
140 136
	 * @param filepath the filepath
141 137
	 * @return the txm browser
142 138
	 */
143
	static public TXMBrowser openEdition(String filepath) {
139
	static public TXMBrowserEditor openEdition(String filepath) {
144 140
		return openEdition(filepath, new File(filepath).getName());
145 141
	}
146 142
	
......
150 146
	 * @param filepath the filepath
151 147
	 * @return the txm browser
152 148
	 */
153
	static public TXMBrowser openfile(String filepath) {
149
	static public TXMBrowserEditor openfile(String filepath) {
154 150
		return openfile(filepath, new File(filepath).getName());
155 151
	}
156 152
	
......
170 166
	 * @param editorname the editorname
171 167
	 * @return the TXM browser
172 168
	 */
173
	public static TXMBrowser openEdition(String filepath, String editorname) {
169
	public static TXMBrowserEditor openEdition(String filepath, String editorname) {
174 170
		try {
175 171
			// WebBrowserEditorInput editorInput = new WebBrowserEditorInput();
176 172
			// TODO: is web browser type order useful ?
......
186 182
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
187 183
			IWorkbenchPage page = window.getActivePage();
188 184
			
189
			TXMBrowser editor = (TXMBrowser) page.openEditor(editorInput, TXMBrowser.ID, true);
185
			TXMBrowserEditor editor = (TXMBrowserEditor) page.openEditor(editorInput, TXMBrowserEditor.ID, true);
190 186
			editor.setPartName(editorname);
191 187
			return editor;
192 188
		}
......
204 200
	 * @param editorname the editorname
205 201
	 * @return the txm browser
206 202
	 */
207
	public static TXMBrowser openfile(String filepath, String editorname) {
203
	public static TXMBrowserEditor openfile(String filepath, String editorname) {
208 204
		try {
209 205
			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 206
		}
238 207
		catch (Exception e) {
239 208
			Log.severe(TXMUIMessages.bind(TXMUIMessages.errorWhileOpeningBibliographicRecordP0WithURLEqualsP1, e.toString(), filepath));

Formats disponibles : Unified diff