|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 package com.symbian.smt.gui.editors.svgeditor; |
|
19 |
|
20 import java.net.MalformedURLException; |
|
21 import java.net.URI; |
|
22 |
|
23 import org.eclipse.core.runtime.IProgressMonitor; |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.browser.Browser; |
|
26 import org.eclipse.swt.widgets.Composite; |
|
27 import org.eclipse.ui.IEditorInput; |
|
28 import org.eclipse.ui.IEditorSite; |
|
29 import org.eclipse.ui.IFileEditorInput; |
|
30 import org.eclipse.ui.PartInitException; |
|
31 |
|
32 public class SVGEditor extends org.eclipse.ui.part.EditorPart { |
|
33 |
|
34 public static final String ID = "com.symbian.smt.gui.editors.svgeditor"; //$NON-NLS-1$ |
|
35 |
|
36 private String filename; |
|
37 private Browser browser; |
|
38 |
|
39 @Override |
|
40 public void createPartControl(Composite parent) { |
|
41 browser = new Browser(parent, SWT.NONE); |
|
42 browser.setUrl(filename); |
|
43 } |
|
44 |
|
45 @Override |
|
46 public void doSave(IProgressMonitor monitor) { |
|
47 // The save button is disabled |
|
48 } |
|
49 |
|
50 @Override |
|
51 public void doSaveAs() { |
|
52 // Not implementing at this stage |
|
53 } |
|
54 |
|
55 @Override |
|
56 public void init(IEditorSite site, IEditorInput input) |
|
57 throws PartInitException { |
|
58 try { |
|
59 if (input instanceof IFileEditorInput) { |
|
60 IFileEditorInput file = (IFileEditorInput) input; |
|
61 URI uri = file.getFile().getLocationURI(); |
|
62 filename = uri.toURL().toString(); |
|
63 } |
|
64 } catch (MalformedURLException mue) { |
|
65 throw new PartInitException("Bad URL", mue); |
|
66 } |
|
67 |
|
68 if (!input.exists()) { |
|
69 throw new PartInitException("Input file " + input.getName() |
|
70 + " does not exist"); |
|
71 } |
|
72 |
|
73 setSite(site); |
|
74 setInput(input); |
|
75 setPartName(input.getName()); |
|
76 } |
|
77 |
|
78 @Override |
|
79 public boolean isDirty() { |
|
80 // The user is not able to edit the image |
|
81 return false; |
|
82 } |
|
83 |
|
84 @Override |
|
85 public boolean isSaveAsAllowed() { |
|
86 return false; |
|
87 } |
|
88 |
|
89 public void print() { |
|
90 browser.execute("window.print();"); |
|
91 } |
|
92 |
|
93 public void refresh() { |
|
94 browser.refresh(); |
|
95 } |
|
96 |
|
97 @Override |
|
98 public void setFocus() { |
|
99 // Set the focus to the browser. The editor will not function properly |
|
100 // (won't open files or change tabs) if you don't set the focus to |
|
101 // something |
|
102 |
|
103 browser.setFocus(); |
|
104 } |
|
105 } |