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         // TODO Auto-generated constructor stub
00054     }
00055 
00056     /* (non-Javadoc)
00057      * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
00058      */
00059     //@Override
00060     public void doSave(IProgressMonitor monitor) {
00061         // TODO Auto-generated method stub
00062 
00063     }
00064 
00065     /* (non-Javadoc)
00066      * @see org.eclipse.ui.part.EditorPart#doSaveAs()
00067      */
00068     //@Override
00069     public void doSaveAs() {
00070         // TODO Auto-generated method stub
00071 
00072     }
00073 
00074     
00075     /* (non-Javadoc)
00076      * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
00077      */
00078     //@Override
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     /* (non-Javadoc)
00105      * @see org.eclipse.ui.part.EditorPart#isDirty()
00106      */
00107     //@Override
00108     public boolean isDirty() {
00109         // TODO Auto-generated method stub
00110         return false;
00111     }
00112 
00113     /* (non-Javadoc)
00114      * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
00115      */
00116     //@Override
00117     public boolean isSaveAsAllowed() {
00118         // TODO Auto-generated method stub
00119         return false;
00120     }
00121 
00122     /* (non-Javadoc)
00123      * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
00124      */
00125     public boolean isSaveOnCloseNeeded() {
00126         return false;
00127     }
00128     
00129     /* (non-Javadoc)
00130      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
00131      */
00132     //@Override
00133     public void createPartControl(Composite parent) {
00134         try {
00135             // attempt to instantiate browser widget
00136             browser = new Browser(parent, SWT.BORDER);
00137             // set the property
00138             browser.setData(HTMLEditor.ID, this);
00139             // display the URL
00140             GridDataFactory.fillDefaults().grab(true, true).applyTo(browser);
00141 
00142             browser.setUrl(sURI);
00143 
00144         } catch (SWTError e) {
00145             // if the platform doesn't support pluggable browser,
00146             //   then we show error message
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         // display the original source of the HTML file (debugging purpose)
00152         this.setContentDescription(sURI);
00153         // set the title of the editor
00154         this.setPartName(this.getEditorInput().getName());
00155         
00156         // set the layout: the browser has to be expanded as much as possible
00157         GridLayoutFactory.fillDefaults().numColumns(1).generateLayout(parent);
00158     }
00159 
00160     /* (non-Javadoc)
00161      * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
00162      */
00163     //@Override
00164     public void setFocus() {
00165         this.browser.setFocus();
00166     }
00167     
00168 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1