Author: yradtsevich
Date: 2012-04-01 06:26:24 -0400 (Sun, 01 Apr 2012)
New Revision: 39953
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/META-INF/MANIFEST.MF
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/src/org/jboss/tools/vpe/browsersim/eclipse/callbacks/ViewSourceCallback.java
Log:
https://issues.jboss.org/browse/JBIDE-11179 : BrowserSim - add a view source option
- added support of VPE
- NPE fixes
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/META-INF/MANIFEST.MF
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/META-INF/MANIFEST.MF 2012-04-01
10:06:20 UTC (rev 39952)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/META-INF/MANIFEST.MF 2012-04-01
10:26:24 UTC (rev 39953)
@@ -12,7 +12,11 @@
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.ui.browser,
- org.eclipse.core.filesystem
+ org.eclipse.core.filesystem,
+ org.jboss.tools.jst.jsp;bundle-version="3.3.0";resolution:=optional,
+ org.eclipse.wst.sse.ui;resolution:=optional,
+ org.jboss.tools.common.text.ext;bundle-version="3.3.0";resolution:=optional,
+ org.jboss.tools.jst.web;bundle-version="3.3.0";resolution:=optional
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: JBoss by Red Hat
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/src/org/jboss/tools/vpe/browsersim/eclipse/callbacks/ViewSourceCallback.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/src/org/jboss/tools/vpe/browsersim/eclipse/callbacks/ViewSourceCallback.java 2012-04-01
10:06:20 UTC (rev 39952)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.eclipse/src/org/jboss/tools/vpe/browsersim/eclipse/callbacks/ViewSourceCallback.java 2012-04-01
10:26:24 UTC (rev 39953)
@@ -23,13 +23,16 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.vpe.browsersim.eclipse.util.BrowserSimLauncher;
import org.jboss.tools.vpe.browsersim.eclipse.util.TransparentReader;
@@ -85,7 +88,7 @@
IStorage storage = new StringStorage("", // see the long comment below to
know why an empty storage is created
"view-source.html"); // .html extension is needed to enable code
highlighting in the WTP HTML editor
IStorageEditorInput input = new StringInput(storage, name, toolTip);
- ITextEditor editor = (ITextEditor) page.openEditor(input, editorId);
+ IEditorPart editor = page.openEditor(input, editorId);
/* We change content of the editor AFTER the editor is created
* as a workaround for the following WTP bug.
@@ -94,9 +97,37 @@
* is created and freezes UI.
* See
http://www.eclipse.org/forums/index.php/m/639937/
*/
- IDocument document =
editor.getDocumentProvider().getDocument(editor.getEditorInput());
- document.set(content);
- editor.doSave(null); // reset resource-changed marker
+ IDocument doc = null;
+
+ // this checking is needed to do not load jst.jsp plug-ins if it is unnecessary
+ if ("org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor".equals(editorId)) {
+ try {
+ if (editor instanceof JSPMultiPageEditor) {
+ JSPMultiPageEditor multiPageEditor = (JSPMultiPageEditor) editor;
+ doc = multiPageEditor.getSourceEditor().getTextViewer().getDocument();
+ }
+ } catch (NoClassDefFoundError e1) {
+ // this is OK - there are some optional dependencies
+ }
+ }
+
+ if (doc == null) {
+ ITextEditor textEditor = null;
+ if (editor instanceof ITextEditor) {
+ textEditor = (ITextEditor) editor;
+ } else {
+ textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
+ }
+
+ if (textEditor != null) {
+ doc = textEditor.getDocumentProvider().getDocument(input);
+ }
+ }
+
+ if (doc != null) {
+ doc.set(content);
+ editor.doSave(null); // reset resource-changed marker
+ }
} catch (PartInitException e) {
// TODO: log exception
}