HTMLEditor.java
Go to the documentation of this file.00001
00004 package edu.rice.cs.hpc.viewer.help;
00005
00006 import java.io.IOException;
00007 import java.net.URL;
00008
00009 import org.eclipse.core.runtime.FileLocator;
00010 import org.eclipse.core.runtime.IPath;
00011 import org.eclipse.core.runtime.IProgressMonitor;
00012 import org.eclipse.core.resources.IFile;
00013 import org.eclipse.swt.widgets.Composite;
00014 import org.eclipse.ui.IEditorInput;
00015 import org.eclipse.ui.IEditorSite;
00016 import org.eclipse.ui.PartInitException;
00017 import org.eclipse.ui.part.EditorPart;
00018 import org.eclipse.swt.browser.*;
00019 import org.eclipse.swt.SWTError;
00020 import org.eclipse.swt.SWT;
00021
00022 import org.eclipse.jface.dialogs.MessageDialog;
00023 import org.eclipse.jface.layout.GridDataFactory;
00024 import org.eclipse.jface.layout.GridLayoutFactory;
00025 import org.eclipse.ui.part.FileEditorInput;
00026 import org.osgi.framework.Bundle;
00027
00028 import edu.rice.cs.hpc.viewer.framework.Activator;
00029
00030
00035 public class HTMLEditor extends EditorPart {
00036 public static String ID = "edu.rice.cs.hpc.viewer.util.HTMLEditor";
00037
00038
00042 protected Browser browser;
00046 protected String sURI;
00047 protected String sFilePath;
00048
00052 public HTMLEditor() {
00053
00054 }
00055
00056
00057
00058
00059
00060 public void doSave(IProgressMonitor monitor) {
00061
00062
00063 }
00064
00065
00066
00067
00068
00069 public void doSaveAs() {
00070
00071
00072 }
00073
00074
00075
00076
00077
00078
00079 public void init(IEditorSite site, IEditorInput input)
00080 throws PartInitException {
00081
00082 this.setSite(site);
00083 this.setInput(input);
00084
00085 FileEditorInput objInput = (FileEditorInput) input;
00086 IFile file = objInput.getFile();
00087 if(file != null) {
00088 IPath objPath = file.getFullPath();
00089 Bundle plugin = Activator.getDefault().getBundle();
00090 URL fileInPlugin = FileLocator.find(plugin, objPath, null);
00091
00092 try {
00093 URL pageUrl = FileLocator.toFileURL(fileInPlugin);
00094 this.sFilePath = file.getName();
00095 sURI = pageUrl.toString();
00096 } catch (IOException e) {
00097
00098 e.printStackTrace();
00099 }
00100
00101 }
00102 }
00103
00104
00105
00106
00107
00108 public boolean isDirty() {
00109
00110 return false;
00111 }
00112
00113
00114
00115
00116
00117 public boolean isSaveAsAllowed() {
00118
00119 return false;
00120 }
00121
00122
00123
00124
00125 public boolean isSaveOnCloseNeeded() {
00126 return false;
00127 }
00128
00129
00130
00131
00132
00133 public void createPartControl(Composite parent) {
00134 try {
00135
00136 browser = new Browser(parent, SWT.BORDER);
00137
00138 browser.setData(HTMLEditor.ID, this);
00139
00140 GridDataFactory.fillDefaults().grab(true, true).applyTo(browser);
00141
00142 browser.setUrl(sURI);
00143
00144 } catch (SWTError e) {
00145
00146
00147 MessageDialog.openError(getSite().getShell(), "Unable to display HTML page",
00148 "HPCViewer is unable to open HTML page to display the help file\n"
00149 + "Please refer to the manual in HPCToolkit website (http://hpctoolkit.org)");
00150 }
00151
00152 this.setContentDescription(sURI);
00153
00154 this.setPartName(this.getEditorInput().getName());
00155
00156
00157 GridLayoutFactory.fillDefaults().numColumns(1).generateLayout(parent);
00158 }
00159
00160
00161
00162
00163
00164 public void setFocus() {
00165 this.browser.setFocus();
00166 }
00167
00168 }