org.eclipse.wst.sse.ui,
org.eclipse.jst.pagedesigner,
org.eclipse.wst.html.core,
- org.eclipse.wst.xml.core;bundle-version="1.1.602"
+ org.eclipse.wst.xml.core;bundle-version="1.1.602",
+ org.eclipse.wst.sse.core
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package:
org.eclipse.jst.pagedesigner,
org.eclipse.ui.editors.text,
org.eclipse.ui.texteditor,
+ org.eclipse.wst.common.uriresolver.internal.provisional,
org.eclipse.wst.css.core.internal.provisional.contenttype,
org.eclipse.wst.css.ui,
org.eclipse.wst.html.core.internal.provisional.contenttype,
package org.tizen.web.advanceddeclarationview.ui;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.CharBuffer;
+
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.source.CompositeRuler;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
import org.eclipse.wst.xml.core.internal.document.ElementImpl;
import org.eclipse.wst.xml.core.internal.document.NodeImpl;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
@SuppressWarnings("restriction")
public class HTMLDeclarationPage extends DeclarationPage implements ISelectionListener,
private Color fBackgroundColor;
private RGB fBackgroundColorRGB;
+ private String resourceAbsolutePath;
+
/**
* Internal property change listener for handling changes in the editor's preferences.
if ("src".equalsIgnoreCase(attrImpl.getName())) {
/** External JavaScript file or image file*/
if ("script".equalsIgnoreCase(ownerElement.getTagName())) {
+ resourceAbsolutePath = getAbsolutePath(model, attrImpl.getValue());
mode = MODE_JS_FILE_VIEW;
+
} else if ("img".equalsIgnoreCase(ownerElement.getTagName())) {
+ resourceAbsolutePath = getAbsolutePath(model, attrImpl.getValue());
mode = MODE_IMAGE_VIEW;
} else {
mode = MODE_INVALID_CASE;
if ("link".equalsIgnoreCase(ownerElement.getTagName()) &&
"text/css".equalsIgnoreCase(ownerElement.getAttribute("type")) &&
"stylesheet".equalsIgnoreCase(ownerElement.getAttribute("rel"))) {
+ resourceAbsolutePath = getAbsolutePath(model, attrImpl.getValue());
mode = MODE_CSS_FILE_VIEW;
} else {
mode = MODE_INVALID_CASE;
updateLayout(false);
}
+
+ private String getAbsolutePath(IStructuredModel model, String relPath) {
+ org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
+ return URIResolverPlugin.createResolver().resolve(resolver.getFileBaseLocation(), null, relPath);
+ }
private void displayContents(IWorkbenchPart part, ISelection selection) {
- boolean noContents = false;
switch (mode) {
case MODE_JS_DECLARATION:
case MODE_IMAGE_VIEW:
break;
case MODE_JS_FILE_VIEW:
-
+ displayJSfile();
break;
case MODE_CSS_FILE_VIEW:
-
+ displayCSSfile();
break;
case MODE_INVALID_CASE:
break;
}
}
+ private void displayJSfile() {
+ /** TODO: apply multi-threads */
+ String source = readTextFileToString(resourceAbsolutePath);
+ if (source != null) {
+ IDocument document= new Document(source);
+ JavaScriptPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
+ fSrcViewer.setInput(document);
+
+ } else {
+
+ }
+ }
+
+ private void displayCSSfile() {
+ /** TODO: apply multi-threads */
+ String source = readTextFileToString(resourceAbsolutePath);
+ if (source != null) {
+ fSrcViewer.getDocument().set(source);
+ } else {
+
+ }
+ }
+
/**
* Sets the font for this viewer sustaining selection and scroll position.
*/
public HTMLDeclarationPage(final IViewSite parentViewSite) {
parentSite = parentViewSite;
}
+ /**
+ * Returns contents of a text file as a String
+ * @param filePath
+ * @return Text String or null if error exists
+ */
+ private String readTextFileToString(String filePath) {
+ String returnStr = "";
+ BufferedReader reader = null;
+ CharBuffer cBuf = CharBuffer.allocate(20480);
+
+ if (filePath != null) {
+ try
+ {
+ reader = new BufferedReader(new FileReader(filePath));
+
+ cBuf.clear();
+ while (reader.read(cBuf) >= 0) {
+ cBuf.flip();
+ returnStr = returnStr + cBuf.toString();
+ }
+ } catch (IOException e) {
+ return null;
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+ }
+ return returnStr;
+ }
@Override
public void propertyChange(PropertyChangeEvent event) {