Bug 3184 - Reorganize new project wizard
authorEugene Ostroukhov <eugeneo@symbian.org>
Tue, 13 Jul 2010 11:11:00 -0700
changeset 441 85f06000ab13
parent 440 533ef48d3b15
child 442 980aaebb8022
Bug 3184 - Reorganize new project wizard
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardNewProjectCreationPage.java
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java	Tue Jul 13 08:58:31 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java	Tue Jul 13 11:11:00 2010 -0700
@@ -58,18 +58,14 @@
             IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
 
             String projectFieldContents = (String) value;
-            IStatus nameStatus = workspace.validateName(projectFieldContents,
-                    IResource.PROJECT);
+            IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT);
             if (!nameStatus.isOK()) {
                 return nameStatus;
             }
 
-            IProject handle = ResourcesPlugin.getWorkspace().getRoot()
-                    .getProject(projectFieldContents);
+            IProject handle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectFieldContents);
             if (handle.exists()) {
-                return new Status(
-                        IStatus.ERROR,
-                        Activator.PLUGIN_ID,
+                return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                         IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
             }
             return Status.OK_STATUS;
@@ -81,8 +77,7 @@
     private final DataBindingContext bindingContext;
     private final WizardContext context;
 
-    public WRTProjectDetailsWizardPage(WizardContext context,
-            DataBindingContext bindingContext) {
+    public WRTProjectDetailsWizardPage(WizardContext context, DataBindingContext bindingContext) {
         super("WRTApp");
         setImageDescriptor(null);
         setTitle("Application Details");
@@ -96,48 +91,40 @@
 
         initializeDialogUnits(parent);
 
-        PlatformUI.getWorkbench().getHelpSystem()
-                .setHelp(root, IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
+        PlatformUI.getWorkbench().getHelpSystem().setHelp(root, IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
 
         WizardPageSupport.create(this, bindingContext);
         root.setLayout(new GridLayout(2, false));
-        context.createLabel(root, "Application name:");
+        createProjectNameGroup(root);
 
-        context.createText(root, WizardContext.WIDGET_NAME, "application name",
-                bindingContext, null, new RegexpValidator("[^\\w\\. ]",
-                        "Application name cannot contain {0} character", false));
-
-        context.createLabel(root, "");
-        context.createLabel(root,
-                "This will be the application display name on the device");
         context.createLabel(root, "");
         context.createLabel(root, "");
-        context.createLabel(root, "Widget identifier:");
+        context.createLabel(root, "Application identifier:");
 
-        context.createText(root, WizardContext.WIDGET_ID,
-                "applicatoin identifier", bindingContext, null,
-                new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*",
-                        "{0} is not a valid applicatoin ID", true));
+        context.createText(root, WizardContext.WIDGET_ID, "applicatoin identifier", bindingContext, null,
+                new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*", "{0} is not a valid applicatoin ID", true));
         context.createLabel(root, "");
-        context.createLabel(
-                root,
-                "This id should be unique for succesful installation of application on the device");
+        context.createLabel(root, "This id should be unique for succesful installation of application on the device");
+
         context.createLabel(root, "");
         context.createLabel(root, "");
 
-        createProjectNameGroup(root);
+        context.createLabel(root, "Application name:");
+
+        context.createText(root, WizardContext.WIDGET_NAME, "application name", bindingContext, null,
+                new RegexpValidator("[^\\w\\. ]", "Application name cannot contain {0} character", false));
+
+        context.createLabel(root, "");
+        context.createLabel(root, "This will be the application display name on the device");
 
         Composite composite = new Composite(root, SWT.NONE);
         GridLayout gridLayout = new GridLayout(1, false);
         gridLayout.marginWidth = 0;
         composite.setLayout(gridLayout);
-        composite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING,
-                true, true, 2, 1));
+        composite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true, 2, 1));
 
-        locationArea = new ProjectContentsLocationArea(getErrorReporter(),
-                composite);
-        if (context.getProjectName() != null
-                && context.getProjectName().trim().length() > 0) {
+        locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite);
+        if (context.getProjectName() != null && context.getProjectName().trim().length() > 0) {
             locationArea.updateProjectName(context.getProjectName());
         }
 
@@ -161,12 +148,10 @@
     private final void createProjectNameGroup(Composite parent) {
         // new project label
         Label projectLabel = new Label(parent, SWT.NONE);
-        projectLabel
-                .setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
+        projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
         projectLabel.setFont(parent.getFont());
 
-        Text projectNameField = context.createText(parent,
-                WizardContext.PROJECT_NAME, "project name", bindingContext,
+        Text projectNameField = context.createText(parent, WizardContext.PROJECT_NAME, "project name", bindingContext,
                 null, new ProjectNameValidator());
 
         projectNameField.setFont(parent.getFont());
@@ -255,8 +240,7 @@
             return false;
         }
         String projectName = context.getProjectName();
-        IProject project = ResourcesPlugin.getWorkspace().getRoot()
-                .getProject(projectName);
+        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
         locationArea.setExistingProject(project);
 
         String validLocationMessage = locationArea.checkValidLocation();
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java	Tue Jul 13 08:58:31 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java	Tue Jul 13 11:11:00 2010 -0700
@@ -59,7 +59,7 @@
     public static final String PROJECT_NAME = "projectName";
 
     private String cssFile;
-    private String projectName;
+    private String projectName = "";
     private String htmlFile;
     private String jsFile;
     private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(
@@ -97,21 +97,21 @@
     }
 
     public String getProjectName() {
-        return (projectName == null ? getDefaultProjectName() : projectName);
-    }
-
-    private String getDefaultProjectName() {
-        return Util.toProjectName(getWidgetName());
+        return projectName;
     }
 
     public void setProjectName(String projectName) {
         String prev = getProjectName();
-        if (projectName.equals(getDefaultProjectName())) {
-            this.projectName = null;
-        } else {
-            this.projectName = projectName;
+        String prevId = getWidgetId();
+        String prevName = getWidgetName();
+        this.projectName = projectName;
+        propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(), prev);
+        if (widgetName == null) {
+            propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prevName);
+            if (widgetId == null) {
+                propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
+            }
         }
-        propertySupport.firePropertyChange(PROJECT_NAME, projectName, prev);
     }
 
     public String getCssFile() {
@@ -159,7 +159,7 @@
     }
 
     public String getWidgetName() {
-        return widgetName;
+        return widgetName == null ? getProjectName() : widgetName;
     }
 
     public void removePropertyChangeListener(PropertyChangeListener arg0) {
@@ -230,19 +230,18 @@
     }
 
     public void setWidgetName(String widgetName) {
-        String prevPn = getProjectName();
         String prevId = getWidgetId();
         String prev = getWidgetName();
-        this.widgetName = widgetName;
-        propertySupport.firePropertyChange(WIDGET_NAME, widgetName, prev);
+        if (widgetName == getProjectName()) {
+            this.widgetName = null;
+        } else {
+            this.widgetName = widgetName;
+        }
+        propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prev);
         if (widgetId == null) {
             propertySupport
                     .firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
         }
-        if (projectName == null) {
-            propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(),
-                    prevPn);
-        }
     }
 
     public void setExtensions(Map<String, String> extensions) {
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardNewProjectCreationPage.java	Tue Jul 13 08:58:31 2010 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,384 +0,0 @@
-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();
-	}
-}