Added HTML Wizard. Changed category to Web Runtime(WRT). Sanitized for licenses. Fixed category for WRT files. General cleanup.
authorTasneemS@US-TASNEEMS
Thu, 07 Jan 2010 19:34:37 -0800
changeset 8 683bdcbc3ebd
parent 7 1a02e8a8be9c
child 9 0e34e0f4c80e
child 14 e3d48d24826c
Added HTML Wizard. Changed category to Web Runtime(WRT). Sanitized for licenses. Fixed category for WRT files. General cleanup.
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard$1.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard$2.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$1.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$2.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$3.class
org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage.class
org.symbian.tools.wrttools.jseditors/icons/Thumbs.db
org.symbian.tools.wrttools.jseditors/icons/new_xml.gif
org.symbian.tools.wrttools.jseditors/icons/newjscript_wiz.gif
org.symbian.tools.wrttools.jseditors/plugin.xml
org.symbian.tools.wrttools.jseditors/src/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard.java
org.symbian.tools.wrttools.jseditors/src/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage.java
org.symbian.tools.wrttools/plugin.xml
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard$1.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard$2.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$1.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$2.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage$3.class has changed
Binary file org.symbian.tools.wrttools.jseditors/bin/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage.class has changed
Binary file org.symbian.tools.wrttools.jseditors/icons/Thumbs.db has changed
Binary file org.symbian.tools.wrttools.jseditors/icons/new_xml.gif has changed
Binary file org.symbian.tools.wrttools.jseditors/icons/newjscript_wiz.gif has changed
--- a/org.symbian.tools.wrttools.jseditors/plugin.xml	Thu Jan 07 14:06:06 2010 -0800
+++ b/org.symbian.tools.wrttools.jseditors/plugin.xml	Thu Jan 07 19:34:37 2010 -0800
@@ -3,31 +3,6 @@
 <plugin>
 
    <extension
-         point="org.eclipse.ui.actionSets">
-      <actionSet
-            label="Sample Action Set"
-            visible="false"
-            id="org.symbian.tools.wrttools.jseditors.actionSet">
-         <menu
-               label="Sample &amp;Menu"
-               id="sampleMenu">
-            <separator
-                  name="sampleGroup">
-            </separator>
-         </menu>
-         <action
-               label="&amp;Sample Action"
-               visible="false"
-               icon="icons/sample.gif"
-               class="org.symbian.tools.wrttools.jseditors.actions.SampleAction"
-               tooltip="Hello, Eclipse world"
-               menubarPath="sampleMenu/sampleGroup"
-               toolbarPath="sampleGroup"
-               id="org.symbian.tools.wrttools.jseditors.actions.SampleAction">
-         </action>
-      </actionSet>
-   </extension>
-   <extension
          point="org.eclipse.ui.commands">
       <category
             name="Sample Category"
@@ -237,21 +212,27 @@
    <extension
          point="org.eclipse.ui.newWizards">
       <category
-            name="WRT Wizards"
-            id="org.symbian.tools.wrt.wizards"
-            class="org.symbian.tools.wrt.wizards.WRTProjectWizard">
+            id="org.symbian.tools.wrttools.jseditors.category"
+            name="WRT Files">
       </category>
       <wizard
             name="XML File"
-            icon="icons/sample.gif"
-            category="org.symbian.tools.wrttools.jseditors"
+            icon="icons/new_xml.gif"
+            category="org.symbian.tools.wrttools.jseditors.category"
             class="org.symbian.tools.wrttools.jseditors.wizards.NewXMLWizard"
             id="org.symbian.tools.wrttools.jseditors.wizards.NewXMLWizard">
       </wizard>
+            <wizard
+            name="HTML File"
+            icon="icons/sample.gif"
+            category="org.symbian.tools.wrttools.jseditors.category"
+            class="org.symbian.tools.wrttools.jseditors.wizards.NewHTMLWizard"
+            id="org.symbian.tools.wrttools.jseditors.wizards.NewHTMLWizard">
+      </wizard>
       <wizard
             name="JavaScript File"  
-            icon="icons/sample.gif"
-            category="org.symbian.tools.wrttools.jseditors"
+            icon="icons/newjscript_wiz.gif"
+            category="org.symbian.tools.wrttools.jseditors.category"
             class="org.symbian.tools.wrttools.jseditors.wizards.NewJSWizard"
             id="org.symbian.tools.wrttools.jseditors.wizards.NewJSWizard">
       </wizard>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.jseditors/src/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizard.java	Thu Jan 07 19:34:37 2010 -0800
@@ -0,0 +1,181 @@
+/**
+ * Copyright (c) 2009 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:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.jseditors.wizards;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.operation.*;
+import java.lang.reflect.InvocationTargetException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import java.io.*;
+import org.eclipse.ui.*;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * This is a sample new HTML wizard. Its role is to create a new file 
+ * resource in the provided container. If the container resource
+ * (a folder or a project) is selected in the workspace 
+ * when the wizard is opened, it will accept it as the target
+ * container. The wizard creates one file with the extension
+ * "html". If a sample html editor (also available
+ * as a template) is registered for the same extension, it will
+ * be able to open it.
+ */
+
+public class NewHTMLWizard extends Wizard implements INewWizard {
+	private NewHTMLWizardPage page;
+	private ISelection selection;
+
+	/**
+	 * Constructor for SampleNewWizard.
+	 */
+	public NewHTMLWizard() {
+		super();
+		setNeedsProgressMonitor(true);
+	}
+	
+	/**
+	 * Adding the page to the wizard.
+	 */
+
+	public void addPages() {
+		page = new NewHTMLWizardPage(selection);
+		addPage(page);
+	}
+
+	/**
+	 * This method is called when 'Finish' button is pressed in
+	 * the wizard. We will create an operation and run it
+	 * using wizard as execution context.
+	 */
+	public boolean performFinish() {
+		final String containerName = page.getContainerName();
+		final String fileName = page.getFileName();
+		IRunnableWithProgress op = new IRunnableWithProgress() {
+			public void run(IProgressMonitor monitor) throws InvocationTargetException {
+				try {
+					doFinish(containerName, fileName, monitor);
+				} catch (CoreException e) {
+					throw new InvocationTargetException(e);
+				} finally {
+					monitor.done();
+				}
+			}
+		};
+		try {
+			getContainer().run(true, false, op);
+		} catch (InterruptedException e) {
+			return false;
+		} catch (InvocationTargetException e) {
+			Throwable realException = e.getTargetException();
+			MessageDialog.openError(getShell(), "Error", realException.getMessage());
+			return false;
+		}
+		return true;
+	}
+	
+	/**
+	 * The worker method. It will find the container, create the
+	 * file if missing or just replace its contents, and open
+	 * the editor on the newly created file.
+	 */
+
+	private void doFinish(
+		String containerName,
+		String fileName,
+		IProgressMonitor monitor)
+		throws CoreException {
+		// create a sample file
+		monitor.beginTask("Creating " + fileName, 2);
+		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+		IResource resource = root.findMember(new Path(containerName));
+		if (!resource.exists() || !(resource instanceof IContainer)) {
+			throwCoreException("Container \"" + containerName + "\" does not exist.");
+		}
+		IContainer container = (IContainer) resource;
+		final IFile file = container.getFile(new Path(fileName));
+		try {
+			InputStream stream = openContentStream();
+			if (file.exists()) {
+				file.setContents(stream, true, true, monitor);
+			} else {
+				file.create(stream, true, monitor);
+			}
+			stream.close();
+		} catch (IOException e) {
+		}
+		monitor.worked(1);
+		monitor.setTaskName("Opening file for editing...");
+		getShell().getDisplay().asyncExec(new Runnable() {
+			public void run() {
+				IWorkbenchPage page =
+					PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+				try {
+					IDE.openEditor(page, file, true);
+				} catch (PartInitException e) {
+				}
+			}
+		});
+		monitor.worked(1);
+	}
+	
+	/**
+	 * We will initialize file contents with a sample text.
+	 */
+
+	private InputStream openContentStream() {
+		String contents = 
+		  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" +
+		  "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
+          "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
+          "<head>\n" +
+		  "<title>Sample Widget</title>\n" +
+		  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
+		  "<script language=\"javascript\" type=\"text/javascript\" src=\"basic.js\"></script>\n" +
+		  "<link rel=\"stylesheet\" href=\"basic.css\" type=\"text/css\"/>\n" +
+		  "<meta name=\"Generator\" content=\"Symbian WRT IDE\" />\n" +
+		  "</head>\n" +
+		  "<body onload=\"javascript:init();\">\n" +
+		  "</body>\n</html>";
+	
+		return new ByteArrayInputStream(contents.getBytes());
+	}
+
+	private void throwCoreException(String message) throws CoreException {
+		IStatus status =
+			new Status(IStatus.ERROR, "org.symbian.tools.wrttools.jseditors", IStatus.OK, message, null);
+		throw new CoreException(status);
+	}
+
+	/**
+	 * We will accept the selection in the workbench to see if
+	 * we can initialize from it.
+	 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
+	 */
+	public void init(IWorkbench workbench, IStructuredSelection selection) {
+		this.selection = selection;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools.jseditors/src/org/symbian/tools/wrttools/jseditors/wizards/NewHTMLWizardPage.java	Thu Jan 07 19:34:37 2010 -0800
@@ -0,0 +1,204 @@
+/**
+ * Copyright (c) 2009 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:
+ * Description:
+ * Overview:
+ * Details:
+ * Platforms/Drives/Compatibility:
+ * Assumptions/Requirement/Pre-requisites:
+ * Failures and causes:
+ */
+package org.symbian.tools.wrttools.jseditors.wizards;
+
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * The "New" wizard page allows setting the container for the new file as well
+ * as the file name. The page will only accept file name without the extension
+ * OR with the extension that matches the expected one (html).
+ */
+
+public class NewHTMLWizardPage extends WizardPage {
+	private Text containerText;
+
+	private Text fileText;
+
+	private ISelection selection;
+
+	/**
+	 * Constructor for SampleNewWizardPage.
+	 * 
+	 * @param pageName
+	 */
+	public NewHTMLWizardPage(ISelection selection) {
+		super("wizardPage");
+		setTitle("HTML File");
+		setDescription("This wizard creates a new HTML file with *.html extension that can be opened by an HTML editor.");
+		this.selection = selection;
+	}
+
+	/**
+	 * @see IDialogPage#createControl(Composite)
+	 */
+	public void createControl(Composite parent) {
+		Composite container = new Composite(parent, SWT.NULL);
+		GridLayout layout = new GridLayout();
+		container.setLayout(layout);
+		layout.numColumns = 3;
+		layout.verticalSpacing = 9;
+		Label label = new Label(container, SWT.NULL);
+		label.setText("&Container:");
+
+		containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
+		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+		containerText.setLayoutData(gd);
+		containerText.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				dialogChanged();
+			}
+		});
+
+		Button button = new Button(container, SWT.PUSH);
+		button.setText("Browse...");
+		button.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				handleBrowse();
+			}
+		});
+		label = new Label(container, SWT.NULL);
+		label.setText("&File name:");
+
+		fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
+		gd = new GridData(GridData.FILL_HORIZONTAL);
+		fileText.setLayoutData(gd);
+		fileText.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				dialogChanged();
+			}
+		});
+		initialize();
+		dialogChanged();
+		setControl(container);
+	}
+
+	/**
+	 * Tests if the current workbench selection is a suitable container to use.
+	 */
+
+	private void initialize() {
+		if (selection != null && selection.isEmpty() == false
+				&& selection instanceof IStructuredSelection) {
+			IStructuredSelection ssel = (IStructuredSelection) selection;
+			if (ssel.size() > 1)
+				return;
+			Object obj = ssel.getFirstElement();
+			if (obj instanceof IResource) {
+				IContainer container;
+				if (obj instanceof IContainer)
+					container = (IContainer) obj;
+				else
+					container = ((IResource) obj).getParent();
+				containerText.setText(container.getFullPath().toString());
+			}
+		}
+		fileText.setText("index.html");
+	}
+
+	/**
+	 * Uses the standard container selection dialog to choose the new value for
+	 * the container field.
+	 */
+
+	private void handleBrowse() {
+		ContainerSelectionDialog dialog = new ContainerSelectionDialog(
+				getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
+				"Select new file container");
+		if (dialog.open() == ContainerSelectionDialog.OK) {
+			Object[] result = dialog.getResult();
+			if (result.length == 1) {
+				containerText.setText(((Path) result[0]).toString());
+			}
+		}
+	}
+
+	/**
+	 * Ensures that both text fields are set.
+	 */
+
+	private void dialogChanged() {
+		IResource container = ResourcesPlugin.getWorkspace().getRoot()
+				.findMember(new Path(getContainerName()));
+		String fileName = getFileName();
+
+		if (getContainerName().length() == 0) {
+			updateStatus("File container must be specified");
+			return;
+		}
+		if (container == null
+				|| (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
+			updateStatus("File container must exist");
+			return;
+		}
+		if (!container.isAccessible()) {
+			updateStatus("Project must be writable");
+			return;
+		}
+		if (fileName.length() == 0) {
+			updateStatus("File name must be specified");
+			return;
+		}
+		if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
+			updateStatus("File name must be valid");
+			return;
+		}
+		int dotLoc = fileName.lastIndexOf('.');
+		if (dotLoc != -1) {
+			String ext = fileName.substring(dotLoc + 1);
+			if (ext.equalsIgnoreCase("html") == false) {
+				updateStatus("File extension must be \"html\"");
+				return;
+			}
+		}
+		updateStatus(null);
+	}
+
+	private void updateStatus(String message) {
+		setErrorMessage(message);
+		setPageComplete(message == null);
+	}
+
+	public String getContainerName() {
+		return containerText.getText();
+	}
+
+	public String getFileName() {
+		return fileText.getText();
+	}
+}
--- a/org.symbian.tools.wrttools/plugin.xml	Thu Jan 07 14:06:06 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml	Thu Jan 07 19:34:37 2010 -0800
@@ -55,7 +55,7 @@
          point="org.eclipse.ui.newWizards">
       <category
             id="org.symbian.tools.wrttools.core.category"
-            name="Symbian WRT">
+            name="Web Runtime(WRT)">
       </category>
       <wizard
             category="org.symbian.tools.wrttools.core.category"
@@ -64,7 +64,7 @@
             hasPages="true"
             icon="icons/main16.gif"
             id="org.symbian.tools.wrttools.core.wrtwidgetwizard"
-            name="WRT Widget"
+            name="Web Runtime Widget"
             project="true">
          <description>
             Creates a new Symbian WRT widget project using one of the provided templates
@@ -90,7 +90,7 @@
          point="org.eclipse.ui.importWizards">
       <category
             id="org.symbian.tools.wrttools.import"
-            name="WRT Tools">
+            name="Web Runtime(WRT)">
       </category>
       <wizard
             category="org.symbian.tools.wrttools.import"
@@ -100,28 +100,6 @@
             name="Aptana IDE WRT Project">
       </wizard>
    </extension>
-
-   
-   <extension
-         id="org.eclipse.wst.xml.ui.ExampleProjectCreationWizardExtension"
-         name="Example Project Creation Wizard"
-         point="org.eclipse.wst.common.ui.exampleProjectCreationWizard"> 
-      <wizard
-           id="org.eclipse.wst.xml.ui.ExampleProjectCreationWizard"
-           banner="icons/newSampleProject_wizbanner.gif">
-         <projectsetup
-               pagetitle="%XMLExampleProjectCreationWizard.pagetitle"
-               name="%XMLExampleProjectCreationWizard.projectname"
-               label="%XMLExampleProjectCreationWizard.label"
-               pagedescription="%XMLExampleProjectCreationWizard.pagedescription"
-               open="readme.html">
-            <import
-                  dest=""
-                  src="org.symbian.tools.wrttools.wizards.examples.FlickrApplication.zip">
-            </import>
-        </projectsetup>
-     </wizard>
-   </extension>
    
    <extension
          point="org.eclipse.ui.popupMenus">
@@ -151,13 +129,6 @@
       </persistent>
    </extension>
    <extension
-         point="org.eclipse.ui.menus">
-      <menuContribution
-            class="org.symbian.tools.wrt.builder.Contribution1"
-            locationURI="menu:org.eclipse.ui.main.menu?after=additions&quot;">
-      </menuContribution>
-   </extension>
-   <extension
          id="org.symbian.tools.wrt.jsProblem"
          name="JSProblem"
          point="org.eclipse.core.resources.markers">