Bug 2779 - Better naming for Application templates
authorEugene Ostroukhov <eugeneo@symbian.org>
Wed, 09 Jun 2010 14:44:32 -0700
changeset 366 715f288b552a
parent 365 46cd6227d4f4
child 367 f0817aeb2d7e
Bug 2779 - Better naming for Application templates
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/schema/projectTemplates.exsd
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardNewProjectCreationPage.java
--- a/org.symbian.tools.wrttools/plugin.xml	Wed Jun 09 14:22:40 2010 -0700
+++ b/org.symbian.tools.wrttools/plugin.xml	Wed Jun 09 14:44:32 2010 -0700
@@ -38,26 +38,8 @@
  </extension>
 
 <!-- WRT Tool Integration (Package, Validate, Include, Exclude Settings)-->
-        <extension	
+ <extension	
           point="org.eclipse.ui.popupMenus">
-<!--
-      <objectContribution
-      		objectClass="org.eclipse.core.resources.IResource" 
-            id="org.symbian.tools.wrttools.widget.wrttool.deployment.setttings">
-     	 <filter
-         	name="projectNature"
-         	value="org.symbian.tools.wrttools.WidgetProjectNature"/>
-         <action
-               class="org.symbian.tools.wrttools.core.deploy.WrtDeploymentSettingsActionDelegate"
-               icon="icons/deploy_settings.gif"
-               id="org.symbian.tools.wrttools.core.deploy.WrtDeploymentSettingsActionDelegate"
-               label="Deployment Settings for WRT Application"
-			   menubarPath="org.symbian.tools.wrttools.contextMenuGroupMarker">
-         </action>
-      </objectContribution>	 
--->                
-    
-      
       <objectContribution
             objectClass="org.eclipse.core.resources.IResource"            
             id="org.symbian.tools.wrttools.widget.wrttool.packageoptions">
@@ -142,26 +124,28 @@
 	<extension point="org.symbian.tools.wrttools.projectTemplates">
 
       <projectTemplate
-		name="Basic Project"
-        archive="projecttemplates/basic.zip"
-        default-css-name="basic"
-        default-html-name="index"
-        default-js-name="basic"
-        icon="icons/main16.gif"
-        id-pattern="com.{0}.basic.widget">
+            archive="projecttemplates/basic.zip"
+            default-css-name="basic"
+            default-html-name="index"
+            default-js-name="basic"
+            icon="icons/main16.gif"
+            id-pattern="com.{0}.basic.widget"
+            name="Minimal Project"
+            order="4">
 			<description>
 				This wizard generates an empty widget project with a minimal Info.plist, html,css and js.
          </description>
 	  </projectTemplate> 
 
       <projectTemplate
-            name="Advanced Project"
             archive="projecttemplates/helloWithWRTKit.zip"
             default-css-name="HelloWithWRTKit"
             default-html-name="index"
             default-js-name="HelloWithWRTKit"
             icon="icons/WRT_main_16.png"
             id-pattern="com.{0}.helloWithWRTKit.widget"
+            name="Hello World Project"
+            order="1"
             wizard-page-factory="org.symbian.tools.wrttools.wizards.HelloWithWRTKitProjectDetailsWizardPage$Factory">
          <description>
             This wizard generates a basic Hello project with a minimal Info.plist, html,css and js along with WRTKit.
@@ -170,13 +154,14 @@
       </projectTemplate>
 
       <projectTemplate
-            name="Flickr Project"
             archive="projecttemplates/flickr.zip"
             default-css-name="Flickr"
             default-html-name="index"
             default-js-name="Flickr"
             icon="icons/flickr.gif"
             id-pattern="com.{0}.flickr.widget"
+            name="Flickr Project"
+            order="2"
             wizard-page-factory="org.symbian.tools.wrttools.wizards.FlickrProjectDetailsWizardPage$Factory">
          <description>
             This wizard generates an Flickr project with a minimal Info.plist, html,css and js and WRTKit.
@@ -185,13 +170,14 @@
       </projectTemplate>
 
       <projectTemplate
-            name="RSS Reader Project"
             archive="projecttemplates/rssreader.zip"
             default-css-name="RSSReader"
             default-html-name="index"
             default-js-name="RSSReader"
             icon="icons/rss.gif"
             id-pattern="com.{0}.rssreader.widget"
+            name="RSS Reader Project"
+            order="3"
             wizard-page-factory="org.symbian.tools.wrttools.wizards.RssReaderProjectDetailsWizardPage$Factory">
          <description>
             This wizard generates an RSS Reader project with a minimal Info.plist, html,css and js and WRTKit.
--- a/org.symbian.tools.wrttools/schema/projectTemplates.exsd	Wed Jun 09 14:22:40 2010 -0700
+++ b/org.symbian.tools.wrttools/schema/projectTemplates.exsd	Wed Jun 09 14:44:32 2010 -0700
@@ -123,6 +123,13 @@
                </appinfo>
             </annotation>
          </attribute>
+         <attribute name="order" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
       </complexType>
    </element>
 
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java	Wed Jun 09 14:22:40 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java	Wed Jun 09 14:44:32 2010 -0700
@@ -167,4 +167,12 @@
         }
         return libraries.toArray(new JSLibrary[libraries.size()]);
     }
+
+    public int getOrder() {
+        String attribute = element.getAttribute("order");
+        if (attribute != null) {
+            return Integer.parseInt(attribute);
+        }
+        return Integer.MAX_VALUE;
+    }
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java	Wed Jun 09 14:22:40 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java	Wed Jun 09 14:44:32 2010 -0700
@@ -31,6 +31,7 @@
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerSorter;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
@@ -41,7 +42,6 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
 import org.symbian.tools.wrttools.core.ProjectTemplate;
 
 public class WRTProjectTemplateWizardPage extends WizardNewProjectCreationPage {
@@ -72,15 +72,14 @@
         setDescription("Select project name and template that will be used to populate");
 	}
 	
-    public void createControl(Composite parent) {
-        super.createControl(parent);
-        final Composite root = (Composite) getControl();
+    @Override
+    protected void createChildControls(Composite c) {
 		ProjectTemplate[] allTemplates = ProjectTemplate.getAllTemplates();
 
 		if (allTemplates.length == 1) {
 			context.setTemplate(allTemplates[0]);
 		}
-        Composite composite = new Composite(root, SWT.NONE);
+        Composite composite = new Composite(c, SWT.NONE);
         composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
 		FormLayout layout = new FormLayout();
 		layout.marginWidth = 5;
@@ -88,10 +87,10 @@
 
 		templates = new TableViewer(composite, SWT.BORDER | SWT.SINGLE);
 		FormData templatesData = new FormData();
-        templatesData.top = new FormAttachment(0, 8);
+        templatesData.top = new FormAttachment(0, 0);
 		templatesData.left = new FormAttachment(0, 0);
         templatesData.right = new FormAttachment(40, -2);
-        templatesData.bottom = new FormAttachment(100, 0);
+        templatesData.bottom = new FormAttachment(100, -8);
 		templates.getControl().setLayoutData(templatesData);
 		templates.addSelectionChangedListener(new ISelectionChangedListener() {
 			public void selectionChanged(SelectionChangedEvent event) {
@@ -109,14 +108,20 @@
 		
 		description = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT .READ_ONLY);
 		FormData descriptionData = new FormData();
-        descriptionData.top = new FormAttachment(0, 8);
-		descriptionData.bottom = new FormAttachment(100, 0);
+        descriptionData.top = new FormAttachment(0, 0);
+        descriptionData.bottom = new FormAttachment(100, -8);
         descriptionData.left = new FormAttachment(templates.getControl(), 5);
 		descriptionData.right = new FormAttachment(100, 0);
 		description.setLayoutData(descriptionData);
 		
 		templates.setContentProvider(new ArrayContentProvider());
 		templates.setLabelProvider(new ProjectTemplateLabelProvider());
+        templates.setSorter(new ViewerSorter() {
+            @Override
+            public int category(Object element) {
+                return Integer.valueOf(((ProjectTemplate) element).getOrder());
+            }
+        });
 		templates.setInput(allTemplates);
 		
 		setPageComplete(false);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardNewProjectCreationPage.java	Wed Jun 09 14:44:32 2010 -0700
@@ -0,0 +1,384 @@
+package org.symbian.tools.wrttools.wizards;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.WorkingSetGroup;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
+import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
+import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
+
+/**
+ * Standard main page for a wizard that is creates a project resource.
+ * <p>
+ * This page may be used by clients as-is; it may be also be subclassed to suit.
+ * </p>
+ * <p>
+ * Example usage:
+ * <pre>
+ * mainPage = new WizardNewProjectCreationPage("basicNewProjectPage");
+ * mainPage.setTitle("Project");
+ * mainPage.setDescription("Create a new project resource.");
+ * </pre>
+ * </p>
+ */
+public class WizardNewProjectCreationPage extends WizardPage {
+
+       // initial value stores
+    private String initialProjectFieldValue;
+
+    // widgets
+    Text projectNameField;
+
+    private final Listener nameModifyListener = new Listener() {
+        public void handleEvent(Event e) {
+        	setLocationForSelection();
+            boolean valid = validatePage();
+            setPageComplete(valid);
+                
+        }
+    };
+
+	private ProjectContentsLocationArea locationArea;
+
+	private WorkingSetGroup workingSetGroup;
+
+    // constants
+    private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
+    /**
+     * Creates a new project creation wizard page.
+     *
+     * @param pageName the name of this page
+     */
+    public WizardNewProjectCreationPage(String pageName) {
+    	super(pageName);
+	    setPageComplete(false);
+    }
+
+	/** (non-Javadoc)
+     * Method declared on IDialogPage.
+     */
+    public void createControl(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NULL);
+    
+
+        initializeDialogUnits(parent);
+
+        PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
+                IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
+
+        composite.setLayout(new GridLayout());
+        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        createProjectNameGroup(composite);
+
+        createChildControls(composite);
+
+        locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite);
+        if(initialProjectFieldValue != null) {
+			locationArea.updateProjectName(initialProjectFieldValue);
+		}
+        
+		// Scale the button based on the rest of the dialog
+		setButtonLayoutData(locationArea.getBrowseButton());
+		
+        setPageComplete(validatePage());
+        // Show description on opening
+        setErrorMessage(null);
+        setMessage(null);
+        setControl(composite);
+        Dialog.applyDialogFont(composite);
+    }
+    
+    protected void createChildControls(Composite composite) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+	 * Create a working set group for this page. This method can only be called
+	 * once.
+	 * 
+	 * @param composite
+	 *            the composite in which to create the group
+	 * @param selection
+	 *            the current workbench selection
+	 * @param supportedWorkingSetTypes
+	 *            an array of working set type IDs that will restrict what types
+	 *            of working sets can be chosen in this group
+	 * @return the created group. If this method has been called previously the
+	 *         original group will be returned.
+	 * @since 3.4
+	 */
+	public WorkingSetGroup createWorkingSetGroup(Composite composite,
+			IStructuredSelection selection, String[] supportedWorkingSetTypes) {
+		if (workingSetGroup != null) {
+            return workingSetGroup;
+        }
+		workingSetGroup = new WorkingSetGroup(composite, selection,
+				supportedWorkingSetTypes);
+		return workingSetGroup;
+	}
+    
+    /**
+	 * Get an error reporter for the receiver.
+	 * @return IErrorMessageReporter
+	 */
+	private IErrorMessageReporter getErrorReporter() {
+		return new IErrorMessageReporter(){
+			/* (non-Javadoc)
+			 * @see org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter#reportError(java.lang.String)
+			 */
+			public void reportError(String errorMessage, boolean infoOnly) {
+				if (infoOnly) {
+					setMessage(errorMessage, IStatus.INFO);
+					setErrorMessage(null);
+				} else {
+                    setErrorMessage(errorMessage);
+                }
+				boolean valid = errorMessage == null;
+				if(valid) {
+					valid = validatePage();
+				}
+				
+				setPageComplete(valid);
+			}
+		};
+	}
+
+    /**
+     * Creates the project name specification controls.
+     *
+     * @param parent the parent composite
+     */
+    private final void createProjectNameGroup(Composite parent) {
+        // project specification group
+        Composite projectGroup = new Composite(parent, SWT.NONE);
+        GridLayout layout = new GridLayout();
+        layout.numColumns = 2;
+        projectGroup.setLayout(layout);
+        projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+        // new project label
+        Label projectLabel = new Label(projectGroup, SWT.NONE);
+        projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
+        projectLabel.setFont(parent.getFont());
+
+        // new project name entry field
+        projectNameField = new Text(projectGroup, SWT.BORDER);
+        GridData data = new GridData(GridData.FILL_HORIZONTAL);
+        data.widthHint = SIZING_TEXT_FIELD_WIDTH;
+        projectNameField.setLayoutData(data);
+        projectNameField.setFont(parent.getFont());
+
+        // Set the initial value first before listener
+        // to avoid handling an event during the creation.
+        if (initialProjectFieldValue != null) {
+			projectNameField.setText(initialProjectFieldValue);
+		}
+        projectNameField.addListener(SWT.Modify, nameModifyListener);
+    }
+
+
+    /**
+     * Returns the current project location path as entered by 
+     * the user, or its anticipated initial value.
+     * Note that if the default has been returned the path
+     * in a project description used to create a project
+     * should not be set.
+     *
+     * @return the project location path or its anticipated initial value.
+     */
+    public IPath getLocationPath() {
+        return new Path(locationArea.getProjectLocation());
+    }
+    
+    /**
+    /**
+     * Returns the current project location URI as entered by 
+     * the user, or <code>null</code> if a valid project location
+     * has not been entered.
+     *
+     * @return the project location URI, or <code>null</code>
+     * @since 3.2
+     */
+    public URI getLocationURI() {
+    	return locationArea.getProjectLocationURI();
+    }
+
+    /**
+	 * Creates a project resource handle for the current project name field
+	 * value. The project handle is created relative to the workspace root.
+	 * <p>
+	 * This method does not create the project resource; this is the
+	 * responsibility of <code>IProject::create</code> invoked by the new
+	 * project resource wizard.
+	 * </p>
+	 * 
+	 * @return the new project resource handle
+	 */
+    public IProject getProjectHandle() {
+        return ResourcesPlugin.getWorkspace().getRoot().getProject(
+                getProjectName());
+    }
+
+    /**
+     * Returns the current project name as entered by the user, or its anticipated
+     * initial value.
+     *
+     * @return the project name, its anticipated initial value, or <code>null</code>
+     *   if no project name is known
+     */
+    public String getProjectName() {
+        if (projectNameField == null) {
+			return initialProjectFieldValue;
+		}
+
+        return getProjectNameFieldValue();
+    }
+
+    /**
+     * Returns the value of the project name field
+     * with leading and trailing spaces removed.
+     * 
+     * @return the project name in the field
+     */
+    private String getProjectNameFieldValue() {
+        if (projectNameField == null) {
+			return ""; //$NON-NLS-1$
+		}
+
+        return projectNameField.getText().trim();
+    }
+
+    /**
+     * Sets the initial project name that this page will use when
+     * created. The name is ignored if the createControl(Composite)
+     * method has already been called. Leading and trailing spaces
+     * in the name are ignored.
+     * Providing the name of an existing project will not necessarily 
+     * cause the wizard to warn the user.  Callers of this method 
+     * should first check if the project name passed already exists 
+     * in the workspace.
+     * 
+     * @param name initial project name for this page
+     * 
+     * @see IWorkspace#validateName(String, int)
+     * 
+     */
+    public void setInitialProjectName(String name) {
+        if (name == null) {
+			initialProjectFieldValue = null;
+		} else {
+            initialProjectFieldValue = name.trim();
+            if(locationArea != null) {
+				locationArea.updateProjectName(name.trim());
+			}
+        }
+    }
+
+    /**
+     * Set the location to the default location if we are set to useDefaults.
+     */
+    void setLocationForSelection() {
+    	locationArea.updateProjectName(getProjectNameFieldValue());
+    }
+
+  
+    /**
+     * Returns whether this page's controls currently all contain valid 
+     * values.
+     *
+     * @return <code>true</code> if all controls are valid, and
+     *   <code>false</code> if at least one is invalid
+     */
+    protected boolean validatePage() {
+        IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
+
+        String projectFieldContents = getProjectNameFieldValue();
+        if (projectFieldContents.equals("")) { //$NON-NLS-1$
+            setErrorMessage(null);
+            setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
+            return false;
+        }
+
+        IStatus nameStatus = workspace.validateName(projectFieldContents,
+                IResource.PROJECT);
+        if (!nameStatus.isOK()) {
+            setErrorMessage(nameStatus.getMessage());
+            return false;
+        }
+
+        IProject handle = getProjectHandle();
+        if (handle.exists()) {
+            setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
+            return false;
+        }
+                
+        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+				getProjectNameFieldValue());
+		locationArea.setExistingProject(project);
+		
+		String validLocationMessage = locationArea.checkValidLocation();
+		if (validLocationMessage != null) { // there is no destination location given
+			setErrorMessage(validLocationMessage);
+			return false;
+		}
+
+        setErrorMessage(null);
+        setMessage(null);
+        return true;
+    }
+
+    /*
+     * see @DialogPage.setVisible(boolean)
+     */
+    public void setVisible(boolean visible) {
+        super.setVisible(visible);
+        if (visible) {
+			projectNameField.setFocus();
+		}
+    }
+
+    /**
+     * Returns the useDefaults.
+     * @return boolean
+     */
+    public boolean useDefaults() {
+        return locationArea.isDefault();
+    }
+
+    /**
+	 * Return the selected working sets, if any. If this page is not configured
+	 * to interact with working sets this will be an empty array.
+	 * 
+	 * @return the selected working sets
+	 * @since 3.4
+	 */
+	public IWorkingSet[] getSelectedWorkingSets() {
+		return workingSetGroup == null ? new IWorkingSet[0] : workingSetGroup
+				.getSelectedWorkingSets();
+	}
+}