Bug 2070 - added code completion for browser objects (window, navigator, etc) and core WRT objects (widget, device)
authorEugene Ostroukhov <eugeneo@symbian.org>
Wed, 03 Mar 2010 09:56:03 -0800
changeset 216 914d053d42b1
parent 215 c9394af976fe
child 217 27fd31e7f051
Bug 2070 - added code completion for browser objects (window, navigator, etc) and core WRT objects (widget, device)
org.symbian.tools.wrttools/build.properties
org.symbian.tools.wrttools/libraries/core/menu.js
org.symbian.tools.wrttools/libraries/core/widget.js
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtLibInitializer.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtLibraryWizardPage.java
--- a/org.symbian.tools.wrttools/build.properties	Tue Mar 02 17:36:13 2010 -0800
+++ b/org.symbian.tools.wrttools/build.properties	Wed Mar 03 09:56:03 2010 -0800
@@ -6,11 +6,11 @@
                projecttemplates/,\
                licenses/,\
                icons/,\
-               lib/,\
                epl-v10.html,\
                license.html,\
                schema/,\
-               lib/org.bluecove_2.1.1.jar
+               libraries/,\
+               lib/
 # javac 
 javacSource=1.5
 javacTarget=1.5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/libraries/core/menu.js	Wed Mar 03 09:56:03 2010 -0800
@@ -0,0 +1,114 @@
+/**
+ * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ */
+
+function Menu() {};
+Menu.prototype = new Object();
+Menu.prototype.menu = new Menu();
+
+/**
+ * Adds a menu item to the top level of the options menu list.
+ * @param {MenuItem}
+ * @return {Void}
+ */
+Menu.prototype.append = function(MenuItem)	{};
+	
+	
+/**
+ * Removes menu item from options menu list. If the 
+ * removed menu item has a cascading submenu in it, 
+ * the submenu will also be removed.
+ * @param {MenuItem}
+ * @return {Void}
+ */
+Menu.prototype.remove = function(MenuItem) {};
+
+/**
+ * Retrieves handle of the menu item instance by its ID 
+ * @param {Integer}
+ * @return {MenuItem}
+ */
+Menu.prototype.getMenuItemById = function(id) {
+	return new MenuItem();
+};
+
+/**
+ * Retrieves handle of the menu item instance by its ID 
+ * @param {String}
+ * @return {MenuItem}
+ */
+Menu.prototype.getMenuItemByName = function(name) {
+	return new MenuItem();
+};
+
+/**
+ * Customizes label and operation associated with right softkey.
+ */
+Menu.prototype.setRightSoftkeyLabel = function(label, callback) {};
+
+/**
+ * Customizes label and operation associated with right softkey.
+ */
+Menu.prototype.setLeftSoftkeyLabel = function(label, callback) {};
+	
+/**
+ * Displays the softkeys.
+ */
+Menu.prototype.showSoftkeys = function() {};
+
+/**
+ * Displays the softkeys.
+ */
+Menu.prototype.hideSoftkeys = function() {};
+
+/**
+ * Removes all items from the options menu pane. This operation 
+ * will also clear all submenus if such exist.
+ */
+Menu.prototype.clear = function() {};
+
+/**
+ * The onShow property of the menu object is an event handler 
+ * for the event of when the options menu is open.
+ */
+Menu.prototype.onShow = new Object();
+
+
+/**
+ * Creates and instantiates an instance of the MenuItem object.
+ */
+function MenuItem(name, id) {};
+MenuItem.prototype = new Object();
+
+
+/**
+ * Adds a child menu item to the parent menu item in the options 
+ * menu list. This results in the creation of a submenu list in 
+ * the menu tree. 
+ */
+MenuItem.prototype.append = function(childMenuItem) {}
+
+
+/**
+ * Removes a child menu item and its children (if any) from the parent menu item.
+ */
+MenuItem.prototype.remove = function(childMenuItem) {}
+
+/**
+ * Call the setDimmed method to show or hide an existing menu item.
+ */
+MenuItem.prototype.setDimmed = function(flag) {}
+
+/**
+ * Event handler for the event when the menu item is selected.
+ */
+MenuItem.prototype.onSelect = new Object();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/libraries/core/widget.js	Wed Mar 03 09:56:03 2010 -0800
@@ -0,0 +1,178 @@
+/**
+ * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Symbian Foundation - initial contribution.
+ * Contributors:
+ */
+
+/**
+ * Property widget
+ * @type Widget
+ * @memberOf Window
+ */
+Window.prototype.widget = new Widget();
+
+/**
+ * Property device
+ * @type Device
+ * @memberOf Window
+ */
+Window.prototype.device = new Device();
+
+/**
+ * Property menu
+ * @type Menu
+ * @memberOf Window
+ */
+Window.prototype.menu = new Menu();
+
+function Widget() {};
+Widget.prototype = new Object();
+Widget.prototype.widget = new Widget();
+
+/**
+ * identifier is a read-only property of the widget object. 
+ * It is the unique string identifier that identifies a widget 
+ * after it has been installed into a device. The string returned 
+ * is the value of the Identifier key defined in the widget 
+ * property list file (info.plist).
+ */
+Widget.prototype.identifier = "";
+
+/**
+ * isrotationsupported is a read-only property that returns a 
+ * Boolean value determining if the device supports landscape and 
+ * portrait screen orientations. If the value is true, the 
+ * device supports both landscape and portrait screen orientations.
+ */
+Widget.prototype.isrotationsupported = new Boolean();
+
+/**
+ * Allows the definition of a function to be called
+ * when a Widget.is displayed
+ * @param {Void}
+ *     onshow()
+ * @return {Void}
+ */
+Widget.prototype.onshow = new Object();
+
+/**
+ * Allows the definition of a function to be called
+ * when a Widget.sent into the background (hidden)
+ * @param {Void}
+ *     onhide()
+ * @return {Void}
+ */
+Widget.prototype.onhide = new Object();
+	
+/**
+ * Launches the browser with the specified url
+ * @param {String} url
+ *     openURL()
+ * @return {Void}
+ */
+Widget.prototype.openURL = function(url){};
+	
+/**
+ * Returns previously stored preference associated with the specified key
+ * @param {String} Key preference value to be fetch
+ *     preferenceForKey()
+ * @return {String} Value
+ */
+Widget.prototype.preferenceForKey = function(key) {return "";};
+	
+	
+/**
+ * Stores the key associated with the specified preference
+ * @param {String} Preference value to be stored
+ * @param {String} Key Preference value associated to
+ *     setPreferenceForKey()
+ * @return {Void}
+ */
+Widget.prototype.setPreferenceForKey = function(preference, key){};
+	
+/**
+ * Toggle between Tabbed navigation mode or Cursor mode
+ * @param {Boolean} Value
+ *     setNavigationEnabled()
+ * @return {Void}
+ */
+Widget.prototype.setNavigationEnabled = function(navigationMode) {};
+
+/**
+ * Toggle between Tabbed navigation mode or Cursor mode
+ * @param {Boolean} Value
+ *     setNavigationType()
+ * @return {Void}
+ */
+Widget.prototype.setNavigationType = function(navigationMode) {};
+	
+/**
+ * Open S0-Application identified by UID along with the specified params
+ * @param {Integer} Uid hexadecimal value to a specified application
+ * @param {String} Value
+ *     openApplication()
+ * @return {Void}
+ */
+Widget.prototype.openApplication = function(Uid, param) {};
+	
+/**
+ * Prepares the Widget.to do transition to specified transitionState
+ * @param {String} Value Transition state
+ *     prepareForTransition()
+ * @return {Void}
+ */
+Widget.prototype.prepareForTransition = function(transitionMode){};
+	
+/**
+ * Does the animation to make the transition between the specified transitionState
+ * @param {Void}
+ *     performTransition()
+ * @return {Void}
+ */
+Widget.prototype.performTransition = function(){};
+	
+/**
+ * Set the preferred screen orientation to landscape.
+ * The display will flip if the phone display orientation
+ * is portrait and the phone supports landscape mode.
+ * @param {Void}
+ *     setDisplayLandscape()
+ * @return {Void}
+ */
+Widget.prototype.setDisplayLandscape = function(){};
+	
+/**
+ * Set the preferred screen orientation to portrait.
+ * The display will flip if the phone display orientation
+ * is landscape and the phone supports portrait mode.
+ * @param {Void}
+ *     setDisplayPortrait()
+ * @return {Void}
+ */
+Widget.prototype.setDisplayPortrait = function(){};
+
+/**
+ * device object. entry point to device service API (SAPI)
+ */
+function Device() {}
+Device.prototype = new Object();
+Device.prototype.device = new Device();
+
+/**
+ * device API public method
+ * 
+ * @method
+ * @param {string} provider Name of service provider, eg, "Service.Calendar"
+ * @param {string} Interface Name of interface, eg, "IDataSource"
+ * @return {Object} service object  
+ */
+Device.prototype.getServiceObject = function(provider, Interface) {
+	return new Object();
+};
\ No newline at end of file
--- a/org.symbian.tools.wrttools/plugin.xml	Tue Mar 02 17:36:13 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml	Wed Mar 03 09:56:03 2010 -0800
@@ -590,6 +590,10 @@
        class="org.symbian.tools.wrttools.core.libraries.WrtKitLibInitializer"
        id="org.symbian.wrtkit">
     </JsGlobalScopeContainerInitializer>
+    <JsGlobalScopeContainerInitializer
+       class="org.symbian.tools.wrttools.core.libraries.WrtLibInitializer"
+       id="org.symbian.wrt">
+    </JsGlobalScopeContainerInitializer>
  </extension>
  <extension
         point="org.eclipse.wst.jsdt.ui.JsGlobalScopeContainerPage">
@@ -598,6 +602,11 @@
             class="org.symbian.tools.wrttools.wizards.WrtKitLibraryWizardPage"
             id="org.symbian.wrtkit">
     </JsGlobalScopeContainerPage>    
+    <JsGlobalScopeContainerPage
+            name="WebRuntime Toolkit"
+            class="org.symbian.tools.wrttools.wizards.WrtLibraryWizardPage"
+            id="org.symbian.wrt">
+    </JsGlobalScopeContainerPage>    
   </extension>
  <extension
        id="org.symbian.tools.wrttools.core.plistvalidator"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/libraries/WrtLibInitializer.java	Wed Mar 03 09:56:03 2010 -0800
@@ -0,0 +1,110 @@
+package org.symbian.tools.wrttools.core.libraries;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.jsdt.core.IJavaScriptProject;
+import org.eclipse.wst.jsdt.core.JsGlobalScopeContainerInitializer;
+import org.eclipse.wst.jsdt.core.compiler.libraries.LibraryLocation;
+import org.osgi.framework.Bundle;
+import org.symbian.tools.wrttools.Activator;
+
+public class WrtLibInitializer extends JsGlobalScopeContainerInitializer {
+
+    public static class WrtLocation implements LibraryLocation {
+        private static final WrtLocation LOCATION = new WrtLocation();
+		
+		public char[][] getLibraryFileNames() {
+			return convert(getFiles());
+		}
+
+		private char[][] convert(String[] files) {
+			final Set<char[]> set = new HashSet<char[]>();
+			for (String string : files) {
+				if (string.endsWith(".js")) {
+					set.add(string.toCharArray());
+				}
+			}
+			return set.toArray(new char[set.size()][]);
+		}
+
+		public IPath getLibraryPathInPlugin() {
+            return new Path("/libraries/core");
+		}
+		
+        public static WrtLocation getInstance() {
+			return LOCATION;
+		}
+		
+		public String[] getFiles() {
+			Bundle bundle = Activator.getDefault().getBundle();
+			String path = getLibraryPathInPlugin().toString();
+
+			final Set<String> set = getEntries(bundle, path);
+			return set.toArray(new String[set.size()]);
+		}
+
+		@SuppressWarnings("unchecked")
+		private Set<String> getEntries(Bundle bundle, String p) {
+			final Set<String> set = new TreeSet<String>();
+			Enumeration entries = bundle.getEntryPaths(p);
+			while (entries.hasMoreElements()) {
+				String path = (String) entries.nextElement();
+				if (path.endsWith("/")) {
+					set.addAll(getEntries(bundle, path));
+				} else {
+					set.add(path.substring(getLibraryPathInPlugin().toString().length()));
+				}
+			}
+			return set;
+		}
+
+		public String getLibraryPath(String name) {
+			System.out.println(name);
+			return null;
+		}
+
+		public String getLibraryPath(char[] name) {
+			Bundle bundle = Activator.getDefault().getBundle();
+			URL url = FileLocator.find(bundle, getLibraryPathInPlugin().append(new String(name)), null);
+			try {
+				URL fileURL = FileLocator.toFileURL(url);
+				return fileURL.getPath();
+			} catch (IOException e) {
+				Activator.log(e);
+			}
+			return null;
+		}
+
+		public IPath getWorkingLibPath() {
+			System.out.println();
+			return null;
+		}
+	}
+
+	public LibraryLocation getLibraryLocation() {
+        return WrtLocation.getInstance();
+	}
+
+	@Override
+	public String getDescription() {
+        return "WebRuntime Toolkit Support Library";
+	}
+	
+	@Override
+	public String getDescription(IPath containerPath, IJavaScriptProject project) {
+		return containerPath.lastSegment();
+	}
+
+    @Override
+    public String[] containerSuperTypes() {
+        return new String[] { "Window" };
+    }
+}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Tue Mar 02 17:36:13 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Wed Mar 03 09:56:03 2010 -0800
@@ -63,11 +63,16 @@
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
 import org.eclipse.ui.part.ISetSelectionTarget;
+import org.eclipse.wst.jsdt.core.IIncludePathEntry;
+import org.eclipse.wst.jsdt.core.IJavaScriptProject;
 import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.core.LibrarySuperType;
+import org.eclipse.wst.jsdt.internal.core.JavaProject;
 import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
 import org.eclipse.wst.validation.ValidationFramework;
 import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.WidgetProjectNature;
+import org.symbian.tools.wrttools.wizards.WrtLibraryWizardPage;
 
 @SuppressWarnings("restriction")
 public class ProjectUtils {
@@ -236,7 +241,7 @@
 	public static IProject createWrtProject(String name, URI uri,
 			IProgressMonitor monitor) throws CoreException {
 		uri = isDefaultProjectLocation(uri) ? null : uri;
-		monitor.beginTask("Create project resources", 20);
+        monitor.beginTask("Create project resources", 25);
 		IWorkspace workspace = ResourcesPlugin.getWorkspace();
 		IProject project = workspace.getRoot().getProject(name);
 		BuildPathsBlock.createProject(project, uri, new SubProgressMonitor(
@@ -249,9 +254,19 @@
 				ValidationFramework.getDefault().getProjectSettings(project),
 				true);
 
-		// TODO: Build path, super type, etc.
-		// BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType,
-		// monitor)
+        IJavaScriptProject jsProject = JavaScriptCore.create(project);
+        final IIncludePathEntry[] includepath = jsProject.getRawIncludepath();
+        final IIncludePathEntry[] newIncludePath = new IIncludePathEntry[includepath.length + 1];
+
+        System.arraycopy(includepath, 0, newIncludePath, 0, includepath.length);
+        newIncludePath[includepath.length] = JavaScriptCore.newContainerEntry(new Path(
+                WrtLibraryWizardPage.CONTAINER_ID));
+
+        jsProject.setRawIncludepath(newIncludePath, new SubProgressMonitor(monitor, 5));
+
+        LibrarySuperType superType = new LibrarySuperType(new Path(WrtLibraryWizardPage.CONTAINER_ID), jsProject,
+                "Window");
+        ((JavaProject) jsProject).setCommonSuperType(superType);
 
 		addWrtNature(project);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtLibraryWizardPage.java	Wed Mar 03 09:56:03 2010 -0800
@@ -0,0 +1,61 @@
+package org.symbian.tools.wrttools.wizards;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.jsdt.core.IIncludePathEntry;
+import org.eclipse.wst.jsdt.core.IJavaScriptProject;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.wst.jsdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.wst.jsdt.ui.wizards.IJsGlobalScopeContainerPage;
+import org.eclipse.wst.jsdt.ui.wizards.IJsGlobalScopeContainerPageExtension;
+import org.eclipse.wst.jsdt.ui.wizards.IJsGlobalScopeContainerPageExtension2;
+import org.eclipse.wst.jsdt.ui.wizards.NewElementWizardPage;
+
+@SuppressWarnings("restriction")
+public class WrtLibraryWizardPage extends NewElementWizardPage implements IJsGlobalScopeContainerPage,
+        IJsGlobalScopeContainerPageExtension, IJsGlobalScopeContainerPageExtension2 {
+
+    public static final String CONTAINER_ID = "org.symbian.wrt";
+
+    public WrtLibraryWizardPage() {
+        super("WrtLib");
+        setTitle("WebRuntime Toolkit JavaScript Library");
+    }
+
+    public boolean finish() {
+        return true;
+    }
+
+    public IIncludePathEntry getSelection() {
+        System.out.println("Unimplemented method:BaseLibraryWizardPage.getSelection");
+        return null;
+    }
+
+    public void setSelection(IIncludePathEntry containerEntry) {
+    }
+
+    public void createControl(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NONE);
+        composite.setFont(parent.getFont());
+        DialogField field = new DialogField();
+
+        field.setLabelText("Symbian WebRuntime Toolkit support was added to your project");
+        LayoutUtil.doDefaultLayout(composite, new DialogField[] { field }, false, SWT.DEFAULT, SWT.DEFAULT);
+        Dialog.applyDialogFont(composite);
+        setControl(composite);
+        setDescription("Symbian WebRuntime Toolkit Support");
+    }
+
+    public void initialize(IJavaScriptProject project, IIncludePathEntry[] currentEntries) {
+        // nothing to initialize
+    }
+
+    public IIncludePathEntry[] getNewContainers() {
+        IIncludePathEntry library = JavaScriptCore.newContainerEntry(new Path(CONTAINER_ID));
+        return new IIncludePathEntry[] { library };
+    }
+
+}