[Esbox-commits] r180 - in trunk/org.indt.esbox.python.ui: . META-INF icons src/org/indt/esbox/python/ui/wizards

carolina at garage.maemo.org carolina at garage.maemo.org
Thu Oct 25 22:19:27 EEST 2007


Author: carolina
Date: 2007-10-25 22:19:26 +0300 (Thu, 25 Oct 2007)
New Revision: 180

Added:
   trunk/org.indt.esbox.python.ui/icons/
   trunk/org.indt.esbox.python.ui/icons/maemo_project.png
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectNature.java
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/NewPythonProjectWizardPage.java
Modified:
   trunk/org.indt.esbox.python.ui/META-INF/MANIFEST.MF
Log:
Fixing some details on Python Wizard

Modified: trunk/org.indt.esbox.python.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.indt.esbox.python.ui/META-INF/MANIFEST.MF	2007-10-23 20:55:45 UTC (rev 179)
+++ trunk/org.indt.esbox.python.ui/META-INF/MANIFEST.MF	2007-10-25 19:19:26 UTC (rev 180)
@@ -19,6 +19,8 @@
  com.jcraft.jsch,
  org.eclipse.cdt.managedbuilder.xlc.ui;resolution:=optional,
  org.eclipse.cdt.make.ui,
- org.indt.esbox.ui
+ org.indt.esbox.ui,
+ org.python.pydev,
+ org.python.pydev.core
 Eclipse-LazyStart: true
 Bundle-Localization: plugin

Added: trunk/org.indt.esbox.python.ui/icons/maemo_project.png
===================================================================
(Binary files differ)


Property changes on: trunk/org.indt.esbox.python.ui/icons/maemo_project.png
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectNature.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectNature.java	                        (rev 0)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectNature.java	2007-10-25 19:19:26 UTC (rev 180)
@@ -0,0 +1,300 @@
+package org.indt.esbox.python.ui.wizards;
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * 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:
+ *    Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *    Paulo Romulo (paulo at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *    Carolina Nogueira (carolina at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
+import org.indt.esbox.core.CoreActivator;
+import org.indt.esbox.python.ui.PythonUIActivator;
+
+
+public class ESboxPythonProjectNature implements IProjectNature {
+
+	private IProject project;
+	
+	private static ESboxPythonProjectNature instance;
+	
+	
+	
+	/*
+	 * id of ESbox Python Project
+	 * org.indt.esbox.core.esboxPythonNature
+	 */
+	public final String ESBOX_PYTHON_NATURE_ID = CoreActivator.getUniqueIdentifier() + ".esboxPythonNature";
+	
+	public  final String DEFAULT_PRIVATE_KEY_FILE = System.getProperty("user.home") + File.separator + ".ssh" + File.separator + "id_dsa";
+	
+    /**
+     * constant that stores the name of the python version we are using for the project with this nature
+     */
+    private QualifiedName projectSessionLocation = null;
+    
+    private QualifiedName projectConnection = null;
+    
+    private QualifiedName projectRemotePath = null;
+    
+    private QualifiedName projectPrivateKeyFile = null;
+    
+    private QualifiedName customizedLocation = null;
+    
+    private ESboxPythonProjectNature() {}
+    
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static  ESboxPythonProjectNature getDefault() {
+		return instance;
+	}	
+    
+    public synchronized QualifiedName getProjectSessionNameQualifiedName() {
+        if(projectSessionLocation == null){
+            //we need to do this because the plugin ID may not be known on '' time
+        	projectSessionLocation = new QualifiedName(CoreActivator.PLUGIN_ID, "ESBOX_PYTHON_PROJECT_SESSION_NAME");
+        }
+        return projectSessionLocation;
+    }
+    
+    public synchronized QualifiedName getProjectConnectionQualifiedName() {
+        if(projectConnection == null){
+            //we need to do this because the plugin ID may not be known on '' time
+        	projectConnection = new QualifiedName(CoreActivator.PLUGIN_ID, "ESBOX_PYTHON_PROJECT_CONNECTION");
+        }
+        return projectConnection;
+    }
+    
+    public synchronized QualifiedName getProjectRemotePathQualifiedName() {
+        if(projectRemotePath == null){
+            //we need to do this because the plugin ID may not be known on '' time
+        	projectRemotePath = new QualifiedName(CoreActivator.PLUGIN_ID, "ESBOX_PYTHON_PROJECT_REMOTE_PATH");
+        }
+        return projectRemotePath;
+    }
+    
+    public synchronized QualifiedName getPrivateKeyFileQualifiedName() {
+        if(projectPrivateKeyFile == null){
+            //we need to do this because the plugin ID may not be known on '' time
+        	projectPrivateKeyFile = new QualifiedName(CoreActivator.PLUGIN_ID, "ESBOX_PYTHON_PROJECT_PRIVATE_KEY_FILE");
+        }
+        return projectPrivateKeyFile;
+    }
+    
+    public synchronized QualifiedName getCustomizedLocationQualifiedName() {
+        if(customizedLocation == null){
+            //we need to do this because the plugin ID may not be known on '' time
+        	customizedLocation = new QualifiedName(CoreActivator.PLUGIN_ID, "ESBOXPYTHON_PROJECT_CUSTOMIZED_LOCATION");
+        }
+        return customizedLocation;
+    }
+    
+    /**
+	 * Adds the ESbox Python project nature to a given project.
+	 * @param _project the project to add the nature.
+	 * @param _monitor a progress monitor to indicate the duration of the operation,
+	 *            or <code>null</code> if progress reporting is not required.
+	 * @throws CoreException if something goes wrong.
+	 */
+	public void addESboxPythonNature(final IProject _project, final String _location, final IProgressMonitor _monitor) throws CoreException {
+		ESboxPythonProjectNature.getDefault().addNature(_project, ESBOX_PYTHON_NATURE_ID, _monitor, _location);		
+	}
+
+	/** 
+	 * Removes the ESbox Python project nature to a given project.
+	 * @param project the project to add the nature.
+	 * @param mon a progress monitor to indicate the duration of the operation,
+	 *            or <code>null</code> if progress reporting is not required.
+	 * @throws CoreException if something goes wrong.
+	 */
+	public void removeESboxPythonNature(IProject project, IProgressMonitor mon) throws CoreException {
+		removeNature(project, ESBOX_PYTHON_NATURE_ID, mon);
+	}
+
+	/**
+	 * Utility method for adding a nature to a project.
+	 * 
+	 * @param proj
+	 *            the project to add the nature
+	 * @param _natureId
+	 *            the id of the nature to assign to the project
+	 * @param _monitor
+	 *            a progress monitor to indicate the duration of the operation,
+	 *            or <code>null</code> if progress reporting is not required.
+	 *  
+	 */
+	public void addNature(final IProject _project,
+			final String _natureId, final IProgressMonitor _monitor,
+			final String _location) throws CoreException {
+		
+		IProjectDescription description = _project.getDescription(); 
+		if (description.hasNature(_natureId)){
+			return;
+		}
+		String[] ids 	= description.getNatureIds();
+		String[] newIds = new String[ids.length + 1];
+		System.arraycopy(ids, 0, newIds, 0, ids.length);
+		newIds[ids.length] = _natureId;
+		description.setNatureIds(newIds);
+		_project.setDescription(description, null);
+		
+		ESboxPythonProjectNature.getDefault().setProjectPrivateKeyFile(_project, DEFAULT_PRIVATE_KEY_FILE);
+		ESboxPythonProjectNature.getDefault().setProjectSessionLocation(_project, _location);
+		ESboxPythonProjectNature.getDefault().setCustomizedLocation(_project, false);
+	}
+
+	/**
+	 * Utility method for removing a project nature from a project.
+	 * 
+	 * @param proj
+	 *            the project to remove the nature from
+	 * @param natureId
+	 *            the nature id to remove
+	 * @param monitor
+	 *            a progress monitor to indicate the duration of the operation,
+	 *            or <code>null</code> if progress reporting is not required.
+	 */
+	public void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
+		IProjectDescription description = project.getDescription();
+		if (!description.hasNature(natureId))
+			return;
+		String[] ids = description.getNatureIds();
+		for (int i = 0; i < ids.length; ++i) {
+			if (ids[i].equals(natureId)) {
+				String[] newIds = new String[ids.length - 1];
+				System.arraycopy(ids, 0, newIds, 0, i);
+				System.arraycopy(ids, i + 1, newIds, i, ids.length - i - 1);
+				description.setNatureIds(newIds);
+				project.setDescription(description, null);
+			}
+		}
+		
+		setProjectRemotePath(project, null);
+		setProjectSessionLocation(project, null);	
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.resources.IProjectNature#configure()
+	 */
+	public void configure() throws CoreException {
+		// TODO Auto-generated method stub
+
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.resources.IProjectNature#deconfigure()
+	 */
+	public void deconfigure() throws CoreException {
+		// TODO Auto-generated method stub
+
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.resources.IProjectNature#getProject()
+	 */
+	public IProject getProject() {
+		return project;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
+	 */
+	public void setProject(IProject project) {
+		this.project = project;
+	}
+	
+	/**
+	 * 
+	 * @param project
+	 * @return
+	 */
+	public boolean isESboxPythonProject(IProject project) {		
+	    if(project != null && project.isOpen()){
+	    	try {	        	
+	            IProjectNature n = project.getNature(ESBOX_PYTHON_NATURE_ID);	            
+		        if(n instanceof ESboxPythonProjectNature){
+		            return true;
+		        }
+		    } catch (CoreException e) {
+		        PythonUIActivator.getDefault().log(e);
+		    }
+	    }	   
+	    return false;
+	}
+	
+	public String getProjectSessionLocation(IProject project) throws CoreException {
+		return project.getPersistentProperty(getDefault().getProjectSessionNameQualifiedName());
+	}
+	
+	public void setProjectSessionLocation(IProject project, String location) throws CoreException {		
+//		Connection previousConnection = getProjectConnection(project);
+//		if((previousConnection != null) && previousConnection.isEstablished())
+//			previousConnection.close();
+//		previousConnection = null;
+//		project.setPersistentProperty(getProjectSessionNameQualifiedName(),location);
+//		if(location == null) {
+//			setProjectConnection(project, null);
+//			return;
+//		}
+//		SessionLocation sessionLocation = null;
+//		try { 
+//			sessionLocation = (SessionLocation) KnownSessions.getInstance().getSession(location);			
+//			setProjectConnection(project, sessionLocation.openConnection(new NullProgressMonitor()));
+//		} catch(SSHException e) {
+//			setProjectConnection(project,null);
+//			CoreActivator.getDefault().showError(e, "Error", "Cannot open SSH session to host " + sessionLocation.toString());			
+//		}		
+	}
+	
+//	public  Connection getProjectConnection(IProject project) throws CoreException {
+//		return (Connection)project.getSessionProperty(getProjectConnectionQualifiedName());
+//	}
+//	
+//	public  void setProjectConnection(IProject project, Connection connection) throws CoreException {		
+//		project.setSessionProperty(getProjectConnectionQualifiedName(),connection);
+//	}
+	
+	public String getProjectRemotePath(IProject project) throws CoreException {		
+		return project.getPersistentProperty(getDefault().getProjectRemotePathQualifiedName());
+	}
+	
+	public void setProjectRemotePath(IProject project, String remotePath) throws CoreException {		
+		project.setPersistentProperty(getDefault().getProjectRemotePathQualifiedName(),remotePath);
+	}
+	
+	public String getProjectPrivateKeyFile(IProject project) throws CoreException {		
+		return project.getPersistentProperty(getDefault().getPrivateKeyFileQualifiedName());
+	}
+	
+	public void setProjectPrivateKeyFile(IProject project, String privateKeyFileName) throws CoreException {		
+		project.setPersistentProperty(getDefault().getPrivateKeyFileQualifiedName(),privateKeyFileName);
+	}
+
+	public void setCustomizedLocation(final IProject _project, final boolean _customizedLocation) throws CoreException {
+		_project.setPersistentProperty(getDefault().getCustomizedLocationQualifiedName(), Boolean.toString(_customizedLocation));
+	}
+
+	public boolean getCustomizedLocation(final IProject _project) throws CoreException {
+		String result = _project.getPersistentProperty(getDefault().getCustomizedLocationQualifiedName());
+		if (result != null) {
+			return Boolean.parseBoolean(result);
+		} else { // When the plug-in is upgraded from versions before 0.1.2
+			return true;	
+		}
+	}
+
+}

Added: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/NewPythonProjectWizardPage.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/NewPythonProjectWizardPage.java	                        (rev 0)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/NewPythonProjectWizardPage.java	2007-10-25 19:19:26 UTC (rev 180)
@@ -0,0 +1,710 @@
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * 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:
+ *    Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *     Carolina Nogueira de Souza (carolina at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.python.ui.wizards;
+
+import java.util.List;
+
+import org.eclipse.cdt.internal.ui.CPluginImages;
+import org.eclipse.cdt.ui.newui.UIMessages;
+import org.eclipse.cdt.ui.templateengine.Template;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+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.core.runtime.Platform;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleAdapter;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+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.DirectoryDialog;
+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.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+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.IDEResourceInfoUtils;
+import org.indt.esbox.core.maemosdk.MaemoSDKEngine;
+import org.indt.esbox.core.maemosdk.MaemoSDKInfo;
+import org.indt.esbox.core.platform.PlatformEngine;
+import org.indt.esbox.core.platform.PlatformInfo;
+import org.indt.esbox.ui.ESboxConfigHandler;
+import org.indt.esbox.ui.UIActivator;
+import org.indt.esbox.ui.wizards.ESboxProjectContentsArea;
+import org.indt.esbox.ui.wizards.ESboxProjectContentsArea.IErrorMessageReporter;
+
+/**
+ * @author Raul Fernandes Herbster - raulherbster at embedded dot ufcg dot com dot br
+ *
+ */
+public class NewPythonProjectWizardPage extends WizardPage {
+
+	// Whether to use default or custom project location
+	private boolean useDefaults = true;
+
+	// initial value stores
+	private String initialProjectFieldValue;
+	private IPath initialLocationFieldValue;
+
+	// the value the user has entered
+	private String customLocationFieldValue;
+
+	// widgets
+	private Tree treeProjectTypes;
+	private Tree treePlatform;
+	private Tree treeSDK;
+	private Text projectNameField;
+	private Text locationPathField;
+	private Label locationLabel;
+	private Button browseButton;    
+	private Button checkSrcFolder;    
+	private boolean checkSrcFolderSelected = true;
+
+	private ESboxConfigHandler esboxHandler;
+	private ESboxProjectContentsArea locationArea;   
+
+	private static final Image IMG_CATEGORY = CPluginImages.get(CPluginImages.IMG_OBJS_SEARCHFOLDER);
+	private static final Image IMG_ITEM = CPluginImages.get(CPluginImages.IMG_OBJS_VARIABLE);
+	private static final Image IMG_MAEMO_SDK = CPluginImages.get(CPluginImages.IMG_OBJS_LIBRARY);
+	private static final Image IMG_PLATFORM = CPluginImages.get(CPluginImages.IMG_VIEW_BUILD);
+
+	private static final String AUTOMAKE_PROJECT_TYPE = UIActivator.PLUGIN_ID + ".projectType.automake";
+	private static final String MAKEFILE_PROJECT_TYPE = UIActivator.PLUGIN_ID + ".projectType.makefile";
+	private static final String CPP_PROJECT_TYPE = UIActivator.PLUGIN_ID + ".projectType.cpp";
+	
+
+	private static final String HELP_CTX = "org.eclipse.ui.ide.new_project_wizard_page_context"; //$NON-NLS-1$
+
+	private Listener nameModifyListener = new Listener() {
+		public void handleEvent(Event e) {
+			setLocationForSelection();
+			setPageComplete(validatePage());
+		}
+	};
+
+	private Listener locationModifyListener = new Listener() {
+		public void handleEvent(Event e) {
+			setPageComplete(validatePage());
+		}
+	};
+
+	// 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 NewPythonProjectWizardPage(String pageName) {
+		super(pageName);
+		setPageComplete(false);
+		initialLocationFieldValue = Platform.getLocation();
+		customLocationFieldValue = ""; //$NON-NLS-1$
+	}
+
+	/* (non-Javadoc)
+	 * Method declared on IWizardPage
+	 */
+	public boolean canFlipToNextPage() {
+		// Already know there is a next page...
+		return isPageComplete();
+	}
+
+	/* (non-Javadoc)
+	 * Method declared on IDialogPage.
+	 */
+	public void createControl(Composite parente) {
+		Composite composite = new Composite(parente, SWT.NULL);
+		composite.setLayout(new GridLayout());
+		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+		composite.setFont(parente.getFont());
+
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
+				IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
+		createOptions(composite);
+		validatePage();
+
+		// Show description on opening
+		setErrorMessage(null);
+		setMessage(null);
+		setControl(composite);
+	}
+
+
+	private void createOptions(Composite parent) {
+
+		Composite composite = new Composite(parent, SWT.NULL);
+		composite.setFont(parent.getFont());
+
+		initializeDialogUnits(parent);
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, HELP_CTX);
+
+		composite.setLayout(new GridLayout());
+		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+		createProjectNameGroup(composite);
+		locationArea = new ESboxProjectContentsArea(getErrorReporter(), composite);
+		if(initialProjectFieldValue != null) {
+			locationArea.updateProjectName(initialProjectFieldValue);
+		}
+
+		// Scale the button based on the rest of the dialog
+		setButtonLayoutData(locationArea.getBrowseButton());
+
+		createDynamicGroup(composite); 
+	}
+
+	private void createDynamicGroup(Composite parent) {
+		Composite c = new Composite(parent, SWT.NONE);
+		c.setFont(parent.getFont());
+		c.setLayoutData(new GridData(GridData.FILL_BOTH));
+		c.setLayout(new GridLayout(2, true));    	
+
+		createLeftSide(c);
+
+		createRigthSide(c);     
+	}
+
+	private void createLeftSide(Composite parent) {
+		Composite left = new Composite(parent, SWT.NONE);
+		left.setLayoutData(new GridData(GridData.FILL_BOTH));
+		left.setLayout(new GridLayout());
+
+		Label l1 = new Label(left, SWT.NONE);
+		l1.setText(UIMessages.getString("CMainWizardPage.0")); //$NON-NLS-1$
+		l1.setFont(parent.getFont());
+		l1.setLayoutData(new GridData(GridData.BEGINNING));
+
+		treeProjectTypes = new Tree(left, SWT.SINGLE | SWT.BORDER);
+		treeProjectTypes.setLayoutData(new GridData(GridData.FILL_BOTH));
+		treeProjectTypes.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				TreeItem[] ti = treeProjectTypes.getSelection();
+				if (ti.length > 0)
+					esboxHandler.setTemplate((Template)ti[0].getData());
+				setPageComplete(validatePage());
+			}});
+		treeProjectTypes.getAccessible().addAccessibleListener(
+				new AccessibleAdapter() {                       
+					public void getName(AccessibleEvent e) {
+						e.result = UIMessages.getString("CMainWizardPage.0"); //$NON-NLS-1$
+					}
+				}
+		);
+
+		fillProjectTypeTree();
+	}
+
+    private void createRigthSide(Composite parent) {
+        Composite right = new Composite(parent, SWT.NONE);
+        right.setLayoutData(new GridData(GridData.FILL_BOTH));
+        right.setLayout(new GridLayout());
+        
+        Label l2 = new Label(right, SWT.NONE);
+        l2.setText("Platforms:"); 
+        l2.setFont(parent.getFont());
+        l2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+                
+        treePlatform = new Tree(right, SWT.SINGLE | SWT.BORDER);        
+        treePlatform.setLayoutData(new GridData(GridData.FILL_BOTH));
+        treePlatform.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				TreeItem[] ti = treePlatform.getSelection();
+				if (ti.length > 0)
+					esboxHandler.setPlatformInfo((PlatformInfo)ti[0].getData());
+				setPageComplete(validatePage());
+			}});
+        
+        fillTreePlatform();
+        
+        Label l3 = new Label(right, SWT.NONE);
+        l3.setText("SDKs:"); 
+        l3.setFont(parent.getFont());
+        l3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+                
+        treeSDK = new Tree(right, SWT.SINGLE | SWT.BORDER);
+        treeSDK.setLayoutData(new GridData(GridData.FILL_BOTH));
+        treeSDK.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				TreeItem[] ti = treeSDK.getSelection();
+				if (ti.length > 0)
+					esboxHandler.setSdkInfo((MaemoSDKInfo)ti[0].getData());
+				setPageComplete(validatePage());
+			}});
+        
+        fillTreeMaemoSDK();
+    }
+
+	private void fillProjectTypeTree() {
+		TreeItem tipExe = new TreeItem(treeProjectTypes, SWT.NONE);
+		tipExe.setText("Automake Projects");
+		tipExe.setImage(IMG_CATEGORY); 
+
+		TreeItem tipMake = new TreeItem(treeProjectTypes, SWT.NONE);
+		tipMake.setText("Makefile Projects");
+		tipMake.setImage(IMG_CATEGORY); 
+
+		TreeItem tipCpp = new TreeItem(treeProjectTypes, SWT.NONE);
+		tipCpp.setText("C++ Hildon Projects");
+		tipCpp.setImage(IMG_CATEGORY); 
+
+		Template[] templates = UIActivator.getDefault().getTemplates();
+		for (int i = 0; i < templates.length; i++) {    		
+			Template template = templates[i];
+			if (isESboxTemplate(template.getTemplateInfo().getTemplateId())) {
+				String projectType = template.getTemplateInfo().getProjectType();
+				TreeItem tip = null;
+				if (projectType.equals(AUTOMAKE_PROJECT_TYPE)) {
+					tip = new TreeItem(tipExe, SWT.NONE);	    		
+				} else if (projectType.equals(MAKEFILE_PROJECT_TYPE)) {
+					tip = new TreeItem(tipMake, SWT.NONE);	
+				} else if (projectType.equals(CPP_PROJECT_TYPE)) {
+					tip = new TreeItem(tipCpp, SWT.NONE);	
+				}
+				tip.setText(template.getLabel());
+				tip.setData(template);
+				tip.setImage(IMG_ITEM); 			
+			}
+		}    	
+	}
+	
+	private void fillTreePlatform() {
+		List platforms = PlatformEngine.getInstance().getPlatforms();	
+		for (Object object : platforms) {
+			PlatformInfo platformInfo = (PlatformInfo)object;
+			TreeItem ti = new TreeItem(treePlatform, SWT.NONE);
+			ti.setText(platformInfo.toString());
+			ti.setData(platformInfo);
+			ti.setImage(IMG_PLATFORM);    		
+		}   	
+
+	}
+
+	private void fillTreeMaemoSDK() {
+		List maemoSDKs = MaemoSDKEngine.getInstance().getMaemoSDKS();	
+		for (Object object : maemoSDKs) {
+			MaemoSDKInfo maemoSDKInfo = (MaemoSDKInfo)object;
+			TreeItem ti = new TreeItem(treeSDK, SWT.NONE);
+			ti.setText(maemoSDKInfo.toString());
+			ti.setData(maemoSDKInfo);
+			ti.setImage(IMG_MAEMO_SDK);    		
+		}   	
+
+	}
+	
+    private boolean isESboxTemplate(String template) {
+    	return template.startsWith(UIActivator.PLUGIN_ID);
+    }
+
+
+	/**
+	 * Get an error reporter for the receiver.
+	 * @return IErrorMessageReporter
+	 */
+	private IErrorMessageReporter getErrorReporter() {
+		return new IErrorMessageReporter(){
+			public void reportError(String errorMessage) {
+				setErrorMessage(errorMessage);
+				boolean valid = errorMessage == null;
+				if(valid) valid = validatePage();
+				setPageComplete(valid);
+			}
+		};
+	}
+
+
+	private final void createProjectProperties(Composite parent) {
+		Font font = parent.getFont();
+		// project specification group
+		Composite projectGroup = new Composite(parent, SWT.NONE);
+		GridLayout layout = new GridLayout();
+		layout.numColumns = 3;
+		projectGroup.setLayout(layout);
+		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		projectGroup.setFont(font);
+
+		checkSrcFolder = new Button(projectGroup , SWT.CHECK);
+		checkSrcFolder.setText("Cr&eate default 'src' folder");
+		checkSrcFolder.setSelection(true);
+		checkSrcFolder.setFont(font);
+		checkSrcFolder.addSelectionListener( new SelectionAdapter() {
+			public void widgetDefaultSelected(SelectionEvent e) {
+				if(e.widget == checkSrcFolder){
+					checkSrcFolderSelected = checkSrcFolder.getSelection();
+				}					
+			}        	
+		});
+
+		GridData labelData = new GridData();
+		labelData.horizontalSpan = 3;
+		checkSrcFolder.setLayoutData(labelData);
+	}
+
+	/**
+	 * Creates the project location specification controls.
+	 *
+	 * @param parent the parent composite
+	 */
+	private final void createProjectLocationGroup(Composite parent) {
+		Font font = parent.getFont();
+		// project specification group
+		Composite projectGroup = new Composite(parent, SWT.NONE);
+		GridLayout layout = new GridLayout();
+		layout.numColumns = 3;
+		projectGroup.setLayout(layout);
+		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		projectGroup.setFont(font);
+
+		final Button useDefaultsButton = new Button(projectGroup, SWT.CHECK
+				| SWT.RIGHT);
+		useDefaultsButton.setText(IDEWorkbenchMessages.ProjectLocationSelectionDialog_useDefaultLabel);
+		useDefaultsButton.setSelection(useDefaults);
+		useDefaultsButton.setFont(font);
+
+		GridData buttonData = new GridData();
+		buttonData.horizontalSpan = 3;
+		useDefaultsButton.setLayoutData(buttonData);
+
+		createUserSpecifiedProjectLocationGroup(projectGroup, !useDefaults);
+
+		SelectionListener listener = new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				useDefaults = useDefaultsButton.getSelection();
+				browseButton.setEnabled(!useDefaults);
+				locationPathField.setEnabled(!useDefaults);
+				locationLabel.setEnabled(!useDefaults);
+				if (useDefaults) {
+					customLocationFieldValue = locationPathField.getText();
+					setLocationForSelection();
+				} else {
+					locationPathField.setText(customLocationFieldValue);
+				}
+			}
+		};
+		useDefaultsButton.addSelectionListener(listener);
+	}
+
+	/**
+	 * Creates the project name specification controls.
+	 *
+	 * @param parent the parent composite
+	 */
+	private final void createProjectNameGroup(Composite parent) {
+		Font font = parent.getFont();
+		// 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.setFont(font);
+		projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
+
+		// 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(font);
+
+		// 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);
+	}
+
+	/**
+	 * Creates the project location specification controls.
+	 *
+	 * @param projectGroup the parent composite
+	 * @param enabled the initial enabled state of the widgets created
+	 */
+	private void createUserSpecifiedProjectLocationGroup(
+			Composite projectGroup, boolean enabled) {
+		Font font = projectGroup.getFont();
+		// location label
+		locationLabel = new Label(projectGroup, SWT.NONE);
+		locationLabel.setFont(font);
+		locationLabel.setText(IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationLabel);
+		locationLabel.setEnabled(enabled);
+
+		// project location entry field
+		locationPathField = new Text(projectGroup, SWT.BORDER);
+		GridData data = new GridData(GridData.FILL_HORIZONTAL);
+		data.widthHint = SIZING_TEXT_FIELD_WIDTH;
+		locationPathField.setLayoutData(data);
+		locationPathField.setFont(font);
+		locationPathField.setEnabled(enabled);
+
+		// browse button
+		browseButton = new Button(projectGroup, SWT.PUSH);
+		browseButton.setFont(font);
+		browseButton.setText(IDEWorkbenchMessages.ProjectLocationSelectionDialog_browseLabel);
+		browseButton.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent event) {
+				handleLocationBrowseButtonPressed();
+			}
+		});
+
+		browseButton.setEnabled(enabled);
+
+		// Set the initial value first before listener
+		// to avoid handling an event during the creation.
+		if (initialLocationFieldValue != null) {
+			locationPathField.setText(initialLocationFieldValue.toOSString());
+		}
+		locationPathField.addListener(SWT.Modify, locationModifyListener);
+	}
+
+	/**
+	 * Returns the current project location path as entered by 
+	 * the user, or its anticipated initial value.
+	 *
+	 * @return the project location path, its anticipated initial value, or <code>null</code>
+	 *   if no project location path is known
+	 */
+	protected IPath getLocationPath() {
+		if (useDefaults) {
+			return initialLocationFieldValue;
+		}
+
+		return new Path(getProjectLocationFieldValue());
+	}
+
+	/**
+	 * Creates a project resource handle for the current project name field value.
+	 * <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
+	 */
+	protected 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
+	 */
+	protected 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 IDEResourceInfoUtils.EMPTY_STRING;
+		} 
+		return projectNameField.getText().trim();
+	}
+
+	/**
+	 * Returns the value of the project location field
+	 * with leading and trailing spaces removed.
+	 * 
+	 * @return the project location directory in the field
+	 */
+	private String getProjectLocationFieldValue() {
+		if (locationPathField == null) {
+			return IDEResourceInfoUtils.EMPTY_STRING;
+		} 
+		return locationPathField.getText().trim();
+	}
+
+	/**
+	 *	Open an appropriate directory browser
+	 */
+	private void handleLocationBrowseButtonPressed() {
+		DirectoryDialog dialog = new DirectoryDialog(locationPathField
+				.getShell());
+		dialog.setMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel);
+
+		String dirName = getProjectLocationFieldValue();
+		if (dirName.length() > 0) { 
+			if (IDEResourceInfoUtils.exists(dirName)) {
+				dialog.setFilterPath(new Path(dirName).toOSString());
+			}
+		}
+
+		String selectedDirectory = dialog.open();
+		if (selectedDirectory != null) {
+			customLocationFieldValue = selectedDirectory;
+			locationPathField.setText(customLocationFieldValue);
+		}
+	}
+
+	/**
+	 * Returns whether the currently specified project
+	 * content directory points to an exising project
+	 */
+	private boolean isExistingProjectLocation() {
+		IPath path = getLocationPath();
+		path = path.append(IProjectDescription.DESCRIPTION_FILE_NAME);
+		return path.toFile().exists();
+	}
+
+	/**
+	 * 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.
+	 * 
+	 * @param name initial project name for this page
+	 */
+	/* package */void setInitialProjectName(String name) {
+		if (name == null) {
+			initialProjectFieldValue = null;
+		} else {
+			initialProjectFieldValue = name.trim();
+		}
+	}
+
+	/**
+	 * Set the location to the default location if we are set to useDefaults.
+	 */
+	private void setLocationForSelection() {
+		if (useDefaults) {
+			IPath defaultPath = Platform.getLocation().append(
+					getProjectNameFieldValue());
+			locationPathField.setText(defaultPath.toOSString());
+		}
+	}
+
+	/**
+	 * 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
+	 */
+	private 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;
+		}
+
+		String locationFieldContents = getProjectLocationFieldValue();
+
+		if (locationFieldContents.equals("")) { //$NON-NLS-1$
+			setErrorMessage(null);
+			setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty);
+			return false;
+		}
+
+		IPath path = new Path(""); //$NON-NLS-1$
+		if (!path.isValidPath(locationFieldContents)) {
+			setErrorMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError);
+			return false;
+		}
+		if (!useDefaults
+				&& Platform.getLocation().isPrefixOf(
+						new Path(locationFieldContents))) {
+			//IDEWorkbenchMessages.WizardNewProjectCreationPage_defaultLocationError
+			setErrorMessage("Project contents cannot be inside workspace directory");
+			return false;
+		}
+
+		if (getProjectHandle().exists()) {
+			setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
+			return false;
+		}
+
+		if (isExistingProjectLocation()) {
+			//IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationExistsMessage
+			setErrorMessage("Another project exists at the specified content directory.");
+			return false;
+		}
+
+		setErrorMessage(null);
+		setMessage(null);
+		return true;
+	}
+
+	/*
+	 * see @DialogPage.setVisible(boolean)
+	 */
+	public void setVisible(boolean visible) {
+		super.setVisible(visible);
+		if (visible) {
+			projectNameField.setFocus();
+		}
+	}
+
+	/**
+	 * 
+	 * @return
+	 */
+	public boolean shouldCreatSourceFolder() {
+		return checkSrcFolderSelected;
+	}
+
+	public void widgetDefaultSelected(SelectionEvent e) {
+		if(e.widget == checkSrcFolder){
+			checkSrcFolderSelected = checkSrcFolder.getSelection();
+		}		
+	}
+
+	public void widgetSelected(SelectionEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+}
\ No newline at end of file



More information about the Esbox-commits mailing list