Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Denault2014-03-07 16:07:10 +0000
committerPaul Webster2014-03-27 17:44:04 +0000
commitcdaa8501a8c2fdc93485fc43c188e61daa23864d (patch)
tree1b33d43b68a7f08a0874ce448e94a751d4633f6d
parent05ed8e599084850d8c65c86553dd9efa58e1375e (diff)
downloadorg.eclipse.e4.tools-cdaa8501a8c2fdc93485fc43c188e61daa23864d.tar.gz
org.eclipse.e4.tools-cdaa8501a8c2fdc93485fc43c188e61daa23864d.tar.xz
org.eclipse.e4.tools-cdaa8501a8c2fdc93485fc43c188e61daa23864d.zip
Bug 426397 - Provide an eclipse editor based on OrionEditorControlI20140331-2200I20140330-2200I20140329-2200I20140328-2200I20140328-0615I20140327-2200
Added support for JavaScript files OrionEditor. Added and refactored tests. Change-Id: I9334d796d45b8fbd1feb582c4e33884cffb4ee12 Signed-off-by: Leo Denault <ldena023@uottawa.ca>
-rw-r--r--bundles/org.eclipse.e4.tools.orion.text.editor/plugin.xml2
-rwxr-xr-xbundles/org.eclipse.e4.tools.orion.text.editor/src/org/eclipse/e4/tools/orion/text/editor/OrionEditor.java5
-rw-r--r--tests/org.eclipse.e4.tools.orion.text.editor.test/src/org/eclipse/e4/tools/orion/text/editor/test/OrionEditorTest.java129
3 files changed, 92 insertions, 44 deletions
diff --git a/bundles/org.eclipse.e4.tools.orion.text.editor/plugin.xml b/bundles/org.eclipse.e4.tools.orion.text.editor/plugin.xml
index 95d30e04..6123044a 100644
--- a/bundles/org.eclipse.e4.tools.orion.text.editor/plugin.xml
+++ b/bundles/org.eclipse.e4.tools.orion.text.editor/plugin.xml
@@ -7,7 +7,7 @@
class="org.eclipse.e4.tools.orion.text.editor.OrionEditor"
contributorClass="org.eclipse.e4.tools.orion.text.editor.OrionEditorActionBarContributor"
default="true"
- extensions="css,html,htm"
+ extensions="css,html,htm,js"
id="org.eclipse.e4.tools.orion.text.editor"
matchingStrategy="org.eclipse.e4.tools.orion.text.editor.OrionEditorMatchingStrategy"
name="OrionEditor">
diff --git a/bundles/org.eclipse.e4.tools.orion.text.editor/src/org/eclipse/e4/tools/orion/text/editor/OrionEditor.java b/bundles/org.eclipse.e4.tools.orion.text.editor/src/org/eclipse/e4/tools/orion/text/editor/OrionEditor.java
index 03f18dcc..8383cae3 100755
--- a/bundles/org.eclipse.e4.tools.orion.text.editor/src/org/eclipse/e4/tools/orion/text/editor/OrionEditor.java
+++ b/bundles/org.eclipse.e4.tools.orion.text.editor/src/org/eclipse/e4/tools/orion/text/editor/OrionEditor.java
@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.e4.tools.orion.editor.builder.IHTMLBuilder;
import org.eclipse.e4.tools.orion.editor.builder.css.CSSBuilder;
import org.eclipse.e4.tools.orion.editor.builder.html.HTMLBuilder;
+import org.eclipse.e4.tools.orion.editor.builder.js.JSBuilder;
import org.eclipse.e4.tools.orion.editor.swt.IDirtyListener;
import org.eclipse.e4.tools.orion.editor.swt.OrionEditorControl;
import org.eclipse.swt.SWT;
@@ -37,6 +38,7 @@ import org.eclipse.ui.part.FileEditorInput;
public class OrionEditor extends EditorPart implements IDirtyListener {
private static final String CSS_EXTENSION = "css";
+ private static final String JS_EXTENSION = "js";
private OrionEditorControl control;
private IFile source;
@@ -86,6 +88,7 @@ public class OrionEditor extends EditorPart implements IDirtyListener {
setSite(site);
setInput(input);
+ setPartName(input.getName());
FileEditorInput fileInput = ((FileEditorInput) input);
if (fileInput != null) {
@@ -117,6 +120,8 @@ public class OrionEditor extends EditorPart implements IDirtyListener {
if (extension.equals(CSS_EXTENSION)) {
builder = new CSSBuilder("");
+ } else if (extension.equals(JS_EXTENSION)) {
+ builder = new JSBuilder();
}
text = loadFile(source.getContents(), 1024);
diff --git a/tests/org.eclipse.e4.tools.orion.text.editor.test/src/org/eclipse/e4/tools/orion/text/editor/test/OrionEditorTest.java b/tests/org.eclipse.e4.tools.orion.text.editor.test/src/org/eclipse/e4/tools/orion/text/editor/test/OrionEditorTest.java
index 48e2b054..5e60715b 100644
--- a/tests/org.eclipse.e4.tools.orion.text.editor.test/src/org/eclipse/e4/tools/orion/text/editor/test/OrionEditorTest.java
+++ b/tests/org.eclipse.e4.tools.orion.text.editor.test/src/org/eclipse/e4/tools/orion/text/editor/test/OrionEditorTest.java
@@ -17,6 +17,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.e4.tools.orion.editor.builder.css.CSSBuilder;
import org.eclipse.e4.tools.orion.editor.builder.html.HTMLBuilder;
+import org.eclipse.e4.tools.orion.editor.builder.js.JSBuilder;
import org.eclipse.e4.tools.orion.text.editor.OrionEditor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
@@ -59,20 +60,31 @@ public class OrionEditorTest extends UITestCase {
}
}
- public void testOpenEditorForEmptyCssFile() throws Throwable {
- proj = FileUtil.createProject("testOpenEditor");
-
- IFile file = FileUtil.createFile("test.css", proj);
- // Check that the default editor for CSS files is the Orion Editor
+ private IFile createFileAndAssertDefaultEditor(String name)
+ throws Throwable {
+ IFile file = FileUtil.createFile(name, proj);
+ // Check that the default editor for the file is the Orion Editor
assertEquals(ORION_EDITOR_ID, fWorkbench.getEditorRegistry()
.getDefaultEditor(file.getName()).getId());
+ return file;
+ }
- // Then check if the OrionEditor automatically opens for CSS files.
+ private IEditorPart openEditor(IFile file) throws Throwable {
+ // Then check if the OrionEditor automatically opens for the file.
IEditorPart editor = IDE.openEditor(fActivePage, file, true);
assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
assertEquals(fActivePage.getActiveEditor(), editor);
assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
.getDefaultEditor(file.getName()).getId());
+ assertEquals(editor.getTitle(), file.getName());
+ return editor;
+ }
+
+ public void testOpenEditorForEmptyCssFile() throws Throwable {
+ proj = FileUtil.createProject("testOpenEditor");
+
+ IFile file = createFileAndAssertDefaultEditor("test.css");
+ IEditorPart editor = openEditor(file);
// Now make sure that the correct builder is used
OrionEditor orionEditor = (OrionEditor) editor;
@@ -82,23 +94,25 @@ public class OrionEditorTest extends UITestCase {
public void testOpenEditorForEmptyHtmlFile() throws Throwable {
proj = FileUtil.createProject("testOpenEditor");
- IFile file = FileUtil.createFile("test.html", proj);
- // Check that the default editor for CSS files is the Orion Editor
- assertEquals(ORION_EDITOR_ID, fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
-
- // Then check if the OrionEditor automatically opens for CSS files.
- IEditorPart editor = IDE.openEditor(fActivePage, file, true);
- assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
- assertEquals(fActivePage.getActiveEditor(), editor);
- assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
+ IFile file = createFileAndAssertDefaultEditor("test.html");
+ IEditorPart editor = openEditor(file);
// Now make sure that the correct builder is used
OrionEditor orionEditor = (OrionEditor) editor;
assertTrue(orionEditor.getBuilder() instanceof HTMLBuilder);
}
+ public void testOpenEditorForEmptyJSFile() throws Throwable {
+ proj = FileUtil.createProject("testOpenEditor");
+
+ IFile file = createFileAndAssertDefaultEditor("test.js");
+ IEditorPart editor = openEditor(file);
+
+ // Now make sure that the correct builder is used
+ OrionEditor orionEditor = (OrionEditor) editor;
+ assertTrue(orionEditor.getBuilder() instanceof JSBuilder);
+ }
+
public void testOpenEditorForNonEmptyCssFile() throws Throwable {
proj = FileUtil.createProject("testOpenEditor");
String fileContents = ".someClass { background: #000000; }";
@@ -109,12 +123,7 @@ public class OrionEditorTest extends UITestCase {
fileContents.getBytes("UTF-8"));
file.setContents(in, IFile.NONE, null);
- // Make sure that the editor properly opens.
- IEditorPart editor = IDE.openEditor(fActivePage, file, true);
- assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
- assertEquals(fActivePage.getActiveEditor(), editor);
- assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
+ IEditorPart editor = openEditor(file);
// Check that the OrionEditorControl contains the text
// that was in the CSS file.
@@ -134,12 +143,28 @@ public class OrionEditorTest extends UITestCase {
fileContents.getBytes("UTF-8"));
file.setContents(in, IFile.NONE, null);
- // Make sure that the editor properly opens.
- IEditorPart editor = IDE.openEditor(fActivePage, file, true);
- assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
- assertEquals(fActivePage.getActiveEditor(), editor);
- assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
+ IEditorPart editor = openEditor(file);
+
+ // Check that the OrionEditorControl contains the text
+ // that was in the CSS file.
+ OrionEditor orionEditor = (OrionEditor) editor;
+ assertEquals(fileContents, orionEditor.getContents());
+
+ FileUtil.delete(file);
+ }
+
+ public void testOpenEditorForNonEmptyJSFile() throws Throwable {
+ proj = FileUtil.createProject("testOpenEditor");
+ String fileContents = "function doSomething() {var arr=[3,2,1];"
+ + "arr.sort(function(first,second){return first-second;});}";
+
+ // Insert text into the CSS file
+ IFile file = FileUtil.createFile("test.htm", proj);
+ InputStream in = new ByteArrayInputStream(
+ fileContents.getBytes("UTF-8"));
+ file.setContents(in, IFile.NONE, null);
+
+ IEditorPart editor = openEditor(file);
// Check that the OrionEditorControl contains the text
// that was in the CSS file.
@@ -153,15 +178,39 @@ public class OrionEditorTest extends UITestCase {
proj = FileUtil.createProject("testOpenEditor");
String fileContents = ".someClass { background: #000000; }";
- // Insert text into the CSS file
IFile file = FileUtil.createFile("test.css", proj);
+ IEditorPart editor = openEditor(file);
- // Make sure that the editor properly opens.
- IEditorPart editor = IDE.openEditor(fActivePage, file, true);
- assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
- assertEquals(fActivePage.getActiveEditor(), editor);
- assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
+ OrionEditor orionEditor = (OrionEditor) editor;
+ orionEditor.setContents(fileContents);
+ assertTrue(orionEditor.isDirty());
+ editor.doSave(null);
+ assertEquals(fileContents,
+ orionEditor.loadFile(file.getContents(), 1024));
+ }
+
+ public void testSaveHtmlFile() throws Throwable {
+ proj = FileUtil.createProject("testOpenEditor");
+ String fileContents = "<!DOCTYPE html><html><body><h1>Some File</h1></body></html>";
+
+ IFile file = FileUtil.createFile("test.html", proj);
+ IEditorPart editor = openEditor(file);
+
+ OrionEditor orionEditor = (OrionEditor) editor;
+ orionEditor.setContents(fileContents);
+ assertTrue(orionEditor.isDirty());
+ editor.doSave(null);
+ assertEquals(fileContents,
+ orionEditor.loadFile(file.getContents(), 1024));
+ }
+
+ public void testSaveJSFile() throws Throwable {
+ proj = FileUtil.createProject("testOpenEditor");
+ String fileContents = "function doSomething() {var arr=[3,2,1];"
+ + "arr.sort(function(first,second){return first-second;});}";
+
+ IFile file = FileUtil.createFile("test.js", proj);
+ IEditorPart editor = openEditor(file);
OrionEditor orionEditor = (OrionEditor) editor;
orionEditor.setContents(fileContents);
@@ -180,13 +229,7 @@ public class OrionEditorTest extends UITestCase {
throws Throwable {
proj = FileUtil.createProject("testOpenEditor");
IFile file = FileUtil.createFile("test.css", proj);
-
- // Make sure that the editor properly opens.
- IEditorPart editor = IDE.openEditor(fActivePage, file, true);
- assertTrue(ArrayUtil.contains(fActivePage.getEditors(), editor));
- assertEquals(fActivePage.getActiveEditor(), editor);
- assertEquals(editor.getSite().getId(), fWorkbench.getEditorRegistry()
- .getDefaultEditor(file.getName()).getId());
+ IEditorPart editor = openEditor(file);
FileUtil.deleteProject(proj);
proj = null;

Back to the top