added sysout and resources tutorials Change-Id: I82b364230be2b423a6b4482c33bfdcc1ce4d418a
diff --git a/JavaScript Beginner Tutorial/01 Hello world/01 Hello world.js b/JavaScript Beginner Tutorial/01 Hello world/01 Hello world.js index fc48d4d..078c97c 100644 --- a/JavaScript Beginner Tutorial/01 Hello world/01 Hello world.js +++ b/JavaScript Beginner Tutorial/01 Hello world/01 Hello world.js
@@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2014 Christian Pontesegger and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian Pontesegger - initial API and implementation + *******************************************************************************/ + // to run, right click on file in Project Explorer and select "Run As/EASE Script" // output will be printed to the console view print("Hello World"); \ No newline at end of file
diff --git a/JavaScript Beginner Tutorial/01 Hello world/02 Hello World UI.js b/JavaScript Beginner Tutorial/01 Hello world/02 Hello World UI.js index cdbe3e8..808729f 100644 --- a/JavaScript Beginner Tutorial/01 Hello world/02 Hello World UI.js +++ b/JavaScript Beginner Tutorial/01 Hello world/02 Hello World UI.js
@@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2014 Christian Pontesegger and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian Pontesegger - initial API and implementation + *******************************************************************************/ + // load additional UI commands loadModule('/System/UI');
diff --git a/JavaScript Beginner Tutorial/01 Hello world/03 Hello World SysOut.js b/JavaScript Beginner Tutorial/01 Hello world/03 Hello World SysOut.js new file mode 100644 index 0000000..343de70 --- /dev/null +++ b/JavaScript Beginner Tutorial/01 Hello world/03 Hello World SysOut.js
@@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2014 Christian Pontesegger and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian Pontesegger - initial API and implementation + *******************************************************************************/ + +// print to sysout +// to use java classes, use full qualified names +java.lang.System.out.println("Hello World");
diff --git a/JavaScript Beginner Tutorial/02 File IO/01 Resources API.js b/JavaScript Beginner Tutorial/02 File IO/01 Resources API.js new file mode 100644 index 0000000..9e2fd3a --- /dev/null +++ b/JavaScript Beginner Tutorial/02 File IO/01 Resources API.js
@@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2014 Christian Pontesegger and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian Pontesegger - initial API and implementation + *******************************************************************************/ + +// load resources module +loadModule('/System/Resources'); + +// get project instance +var project = getProject("Sample Project"); + +if (!project.exists()) + // project does not exist, create + project = createProject("Sample Project"); + +// create a file within the project +var file = createFile("workspace://Sample Project/License.txt"); + +// write to file, we could use the file variable instead of the location, too +var fileHandle = writeLine("workspace://Sample Project/License.txt", "This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0."); + +// to continue writing, use the handle, as we otherwise would override what we have just written before +writeLine(fileHandle, "It is available at http://www.eclipse.org/legal/epl-v10.html"); + +// open file in editor +loadModule('/System/UI'); +showEditor("workspace://Sample Project/License.txt"); +
diff --git a/JavaScript Beginner Tutorial/02 File IO/02 Operate on OS files.js b/JavaScript Beginner Tutorial/02 File IO/02 Operate on OS files.js new file mode 100644 index 0000000..b3951de --- /dev/null +++ b/JavaScript Beginner Tutorial/02 File IO/02 Operate on OS files.js
@@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2014 Christian Pontesegger and others. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Christian Pontesegger - initial API and implementation + ******************************************************************************/ + +// change location according to your system +const +FILE_LOCATION = "/tmp/testfile.txt"; +// const FILE_LOCATION = "C:\\temp\\testfile.txt"; + +// use plain java API +var file = new java.io.File(FILE_LOCATION); +var writer = new java.io.PrintWriter(file); +writer.println("This is a sample file"); +writer.close(); + +// now append using resources module + +// load resources module +loadModule('/System/Resources'); + +// open in APPEND mode, APPEND is set when loading Resources module +var handle = openFile(FILE_LOCATION, APPEND); +writeFile(handle, "2nd line");