[Esbox-commits] r179 - in trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui: . wizards

carolina at garage.maemo.org carolina at garage.maemo.org
Tue Oct 23 23:55:46 EEST 2007


Author: carolina
Date: 2007-10-23 23:55:45 +0300 (Tue, 23 Oct 2007)
New Revision: 179

Added:
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonConfigWizardPage.java
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonMainWizardPage.java
Modified:
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/PythonUIActivator.java
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonCommonProjectWizard.java
   trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java
Log:
Initial import of python wizard

Modified: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/PythonUIActivator.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/PythonUIActivator.java	2007-10-23 19:35:17 UTC (rev 178)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/PythonUIActivator.java	2007-10-23 20:55:45 UTC (rev 179)
@@ -7,10 +7,17 @@
  *
  * 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;
 
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.indt.esbox.core.ErrorLogger;
+import org.indt.esbox.ui.UIActivator;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -56,5 +63,69 @@
 	public static PythonUIActivator getDefault() {
 		return plugin;
 	}
+	
+	/**
+	 * Returns an image descriptor for the image file at the given
+	 * plug-in relative path.
+	 *
+	 * @param path the path
+	 * @return the image descriptor
+	 */
+	public static ImageDescriptor getImageDescriptor(String path) {
+		return AbstractUIPlugin.imageDescriptorFromPlugin("org.indt.esbox.python.ui", path);
+	}
+	
+	/**
+	 * Convenience method for logging CoreExceptions to the plugin log
+	 */
+	public static void log(Exception e) {
+		log(IStatus.ERROR, e.getMessage(), e);
+	}
+	
+	/**
+	 * Log the given exception along with the provided message and severity indicator
+	 */
+	public static void log(int severity, String message, Throwable e) {
+		log(new Status(severity, PLUGIN_ID, 0, message, e));
+	}
+	
+	/**
+	 * Log the given status. Do not use this method for the IStatus from a CoreException.
+	 * Use<code>log(CoreException)</code> instead so the stack trace is not lost.
+	 */
+	public static void log(IStatus status) {
+		getDefault().getLog().log(status);
+	}
+	
+	/**
+	 * Returns the standard display to be used. The method first checks, if
+	 * the thread calling this method has an associated display. If so, this
+	 * display is returned. Otherwise the method returns the default display.
+	 */
+	public static Display getStandardDisplay() {
+		Display display= Display.getCurrent();
+		if (display == null) {
+			display= Display.getDefault();
+		}
+		return display;		
+	}
+	
+	/**
+	 * Return the error logger instance of Core plug-in.
+	 * 
+	 * @return the error logger instance of Core plug-in.
+	 */
+	public ErrorLogger getErrorLogger() {
+		class UIErrorLogger extends ErrorLogger {
 
+			@Override
+			public AbstractUIPlugin getPlugin() {
+				return UIActivator.getDefault();
+			}
+
+		}
+
+		return new UIErrorLogger();
+	}
+
 }

Modified: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonCommonProjectWizard.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonCommonProjectWizard.java	2007-10-23 19:35:17 UTC (rev 178)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonCommonProjectWizard.java	2007-10-23 20:55:45 UTC (rev 179)
@@ -7,6 +7,7 @@
  *
  * 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;
 
@@ -22,10 +23,8 @@
 import org.eclipse.cdt.core.model.CoreModel;
 import org.eclipse.cdt.core.model.ICProject;
 import org.eclipse.cdt.core.model.IPathEntry;
-import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 import org.eclipse.cdt.core.settings.model.ICProjectDescription;
 import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
-import org.eclipse.cdt.core.settings.model.ICSourceEntry;
 import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
 import org.eclipse.cdt.managedbuilder.ui.wizards.CfgHolder;
 import org.eclipse.cdt.ui.CUIPlugin;
@@ -49,9 +48,6 @@
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.wizard.IWizardPage;
@@ -65,9 +61,9 @@
 import org.indt.esbox.core.scratchbox.ScratchboxException;
 import org.indt.esbox.core.scratchbox.ScratchboxFacade;
 import org.indt.esbox.ui.ESboxConfigHandler;
-import org.indt.esbox.ui.UIActivator;
-import org.indt.esbox.ui.wizards.ESboxConfigWizardPage;
-import org.indt.esbox.ui.wizards.ESboxMainWizardPage;
+import org.indt.esbox.python.ui.PythonUIActivator;
+import org.indt.esbox.python.ui.wizards.ESboxPythonConfigWizardPage;
+import org.indt.esbox.python.ui.wizards.ESboxPythonMainWizardPage;
 
 /**
  * Based on {@link org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard}. This class had to be modified
@@ -86,8 +82,8 @@
 	
 	protected IConfigurationElement fConfigElement;
 	protected CfgHolder[] cfgs = new CfgHolder[0];
-	protected ESboxMainWizardPage fMainPage;
-	protected ESboxConfigWizardPage configPage;
+	protected ESboxPythonMainWizardPage fMainPage;
+	protected ESboxPythonConfigWizardPage configPage;
 	
 	protected IProject newProject;
 	private String wz_title;
@@ -129,7 +125,7 @@
 	 * @see org.eclipse.jface.wizard.Wizard#addPages()
 	 */
 	public void addPages() {
-		fMainPage= new ESboxMainWizardPage(CUIPlugin.getResourceString(PREFIX));		
+		fMainPage= new ESboxPythonMainWizardPage(CUIPlugin.getResourceString(PREFIX));		
 		fMainPage.setTitle(wz_title);
 		fMainPage.setDescription(wz_desc);
 		esboxHandler = fMainPage.getHandler();
@@ -355,7 +351,7 @@
 	 */
 	public IWizardPage getNextPage(IWizardPage page) {
 		if (page == fMainPage) {
-			configPage = new ESboxConfigWizardPage(esboxHandler);
+			configPage = new ESboxPythonConfigWizardPage(esboxHandler);
 			configPage.setWizard(this);
 			
 			Template template = fMainPage.getHandler().getTemplate();				
@@ -363,7 +359,7 @@
 			
 			for (int i = 0; i < templatePages.length; i++) {
 				IWizardPage templatePage = templatePages[i];
-				templatePage.setImageDescriptor(UIActivator.getImageDescriptor("./icons/new_maemo_prj_wiz.gif"));
+				templatePage.setImageDescriptor(PythonUIActivator.getImageDescriptor("./icons/new_maemo_prj_wiz.gif"));
 				this.addPage(templatePage);
 			}
 			this.addPage(configPage);
@@ -437,7 +433,7 @@
 					createScratchboxTarget();
 			}
 		} catch (ScratchboxException e) {
-			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			ErrorLogger errorLogger = PythonUIActivator.getDefault().getErrorLogger();
 			errorLogger.logAndShowError("Scratchbox error", e);
 			clearProject();
 		}

Added: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonConfigWizardPage.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonConfigWizardPage.java	                        (rev 0)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonConfigWizardPage.java	2007-10-23 20:55:45 UTC (rev 179)
@@ -0,0 +1,380 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package org.indt.esbox.python.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.cdt.managedbuilder.core.IProjectType;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIImages;
+import org.eclipse.cdt.managedbuilder.ui.wizards.CDTConfigWizardPage;
+import org.eclipse.cdt.managedbuilder.ui.wizards.CfgHolder;
+import org.eclipse.cdt.ui.newui.CDTPrefUtil;
+import org.eclipse.cdt.ui.newui.ProjectContentsArea;
+import org.eclipse.cdt.ui.newui.UIMessages;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+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.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.indt.esbox.core.ErrorLogger;
+import org.indt.esbox.core.scratchbox.ScratchboxException;
+import org.indt.esbox.core.scratchbox.ScratchboxFacade;
+import org.indt.esbox.ui.ESboxConfigHandler;
+import org.indt.esbox.ui.UIActivator;
+import org.indt.esbox.ui.wizards.ESboxCommonProjectWizard;
+import org.indt.esbox.ui.wizards.ESboxProjectContentsArea;
+
+/**
+ * Based on {@link CDTConfigWizardPage}. This class had to be modified because the element
+ * used to store the project location ({@link ProjectContentsArea}) could not be reused and
+ * we had to modify it (see new class {@link ESboxProjectContentsArea}.
+ */
+public class ESboxPythonConfigWizardPage extends WizardPage {
+
+	public static final String PAGE_ID = "org.indt.esbox.ui.wizard.ConfigWizardPage"; //$NON-NLS-1$
+
+	private static final Image IMG = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_BUILD_CONFIG);
+	private static final String TITLE = UIMessages.getString("CConfigWizardPage.0"); //$NON-NLS-1$
+	private static final String MESSAGE = UIMessages.getString("CConfigWizardPage.1"); //$NON-NLS-1$
+	private static final String COMMENT = UIMessages.getString("CConfigWizardPage.12"); //$NON-NLS-1$
+	private static final String EMPTY_STR = "";  //$NON-NLS-1$
+	
+	private Table table;
+	//private CheckboxTableViewer tv;
+	private Label l_projtype;
+	private Label l_chain;
+	private Label l_platform;
+	private Label l_maemoSDK;
+	private Composite parent;
+	private TableColumn column;
+
+	private String propertyId;
+	public boolean isVisible = false;
+	private ESboxConfigHandler esboxHandler;
+	public boolean pagesLoaded = false;
+	
+	/**
+	 * Constructor.
+	 * @param esboxHandler handler of ESbox project configuration.
+	 */
+	public ESboxPythonConfigWizardPage(ESboxConfigHandler esboxHandler) {
+        super(UIMessages.getString("CDTConfigWizardPage.0")); //$NON-NLS-1$
+        setPageComplete(false);
+        setImageDescriptor(UIActivator.getImageDescriptor("./icons/new_maemo_prj_wiz.gif"));
+        setPageComplete(true);
+        this.esboxHandler = esboxHandler;        
+    }
+	
+	/*
+	 public CfgHolder[] getCfgItems(boolean getDefault) {
+		CfgHolder[] its;
+		if (getDefault || table == null)  
+			its = getDefaultCfgs(esboxHandler);
+		else {
+			ArrayList out = new ArrayList(table.getItemCount());
+			TableItem[] tis = table.getItems();
+			for (int i=0; i < tis.length; i++) {
+				if (tis[i].getChecked())
+					out.add(tis[i].getData()); 
+			}
+			its = (CfgHolder[])out.toArray(new CfgHolder[out.size()]);
+		}
+		return its;
+	}
+	*/
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+	 */
+	public void createControl(Composite p) {
+		parent = new Composite(p, SWT.NONE);
+		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
+		parent.setLayout(new GridLayout(3, false));
+		
+		setupLabel(parent, UIMessages.getString("CConfigWizardPage.4"), 1, GridData.BEGINNING); //$NON-NLS-1$
+		l_projtype = setupLabel(parent, EMPTY_STR, 2, GridData.FILL_HORIZONTAL);
+		setupLabel(parent, UIMessages.getString("CConfigWizardPage.5"), 1, GridData.BEGINNING); //$NON-NLS-1$
+		l_chain = setupLabel(parent, EMPTY_STR, 2, GridData.FILL_HORIZONTAL);
+		setupLabel(parent, "Platform:", 1, GridData.BEGINNING); //$NON-NLS-1$
+		l_platform = setupLabel(parent, EMPTY_STR, 2, GridData.FILL_HORIZONTAL);
+		setupLabel(parent, "Maemo SDK:", 1, GridData.BEGINNING); //$NON-NLS-1$
+		l_maemoSDK = setupLabel(parent, EMPTY_STR, 2, GridData.FILL_HORIZONTAL);
+		setupLabel(parent, "Targets: ", 3, GridData.BEGINNING); //$NON-NLS-1$
+		
+		table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+		GridData gd = new GridData(GridData.FILL_BOTH);
+		gd.horizontalSpan = 2;
+		table.setLayoutData(gd);
+		column = new TableColumn(table,SWT.LEFT);
+		table.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				// target selected
+				setErrorMessage(null);
+				setMessage(MESSAGE);
+				esboxHandler.setTargetName(table.getSelection()[0].getText());
+				setPageComplete(true);
+			}
+		});		
+		
+		/*
+		tv = new CheckboxTableViewer(table);
+		tv.setContentProvider(new IStructuredContentProvider() {
+			public Object[] getElements(Object inputElement) {
+				return (Object[])inputElement;
+			}
+			public void dispose() {}
+			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+		});
+		tv.setLabelProvider(new LabelProvider() {
+			public String getText(Object element) {
+				return element == null ? EMPTY_STR : element.toString();
+			}
+			public Image getImage(Object element) { return IMG; }
+		});
+		tv.addCheckStateListener(new ICheckStateListener() {
+			public void checkStateChanged(CheckStateChangedEvent event) {
+				setPageComplete(isCustomPageComplete());
+				update();
+			}});
+		*/
+		Composite c = new Composite(parent, SWT.NONE);
+		c.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+		c.setLayout(new GridLayout(1, false));
+
+		/*
+		Button b1 = new Button(c, SWT.PUSH);
+		b1.setText(UIMessages.getString("CConfigWizardPage.7")); //$NON-NLS-1$
+		b1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		b1.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) { 
+				tv.setAllChecked(true);
+				setPageComplete(isCustomPageComplete());
+				update();
+			}});
+
+		Button b2 = new Button(c, SWT.PUSH);
+		b2.setText(UIMessages.getString("CConfigWizardPage.8")); //$NON-NLS-1$
+		b2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		b2.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				tv.setAllChecked(false);
+				setPageComplete(isCustomPageComplete());
+				update();
+			}});
+		*/
+
+		// dummy placeholder
+		new Label(c, 0).setLayoutData(new GridData(GridData.FILL_BOTH));
+		
+		Button b3 = new Button(c, SWT.PUSH);
+		b3.setText(UIMessages.getString("CConfigWizardPage.13")); //$NON-NLS-1$
+		b3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		b3.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				advancedDialog();
+			}});
+		
+		Group gr = new Group(parent, SWT.NONE);
+		gd = new GridData(GridData.FILL_HORIZONTAL);
+		gd.horizontalSpan = 3;
+		gr.setLayoutData(gd);
+		gr.setLayout(new FillLayout());
+		Label lb = new Label(gr, SWT.NONE);
+		lb.setText(COMMENT);
+	}
+
+	/**
+	 * 
+	 * @param handler
+	 * @return
+	 */
+	static public CfgHolder[] getDefaultCfgs(ESboxConfigHandler handler) {
+		IToolChain tc = handler.getESboxToolChain();		 
+		ArrayList out = new ArrayList(2);
+		IProjectType pt = handler.getProjectType();
+		CfgHolder[] cfgs = null;
+		
+		if (pt != null) 
+			cfgs = CfgHolder.cfgs2items(ManagedBuildManager.getExtensionConfigurations(tc, pt));
+		else {
+			cfgs = new CfgHolder[1];
+			cfgs[0] = new CfgHolder(tc, null);	
+		}
+					
+		for (int j=0; j<cfgs.length; j++) {
+			if (cfgs[j].isSystem() || !cfgs[j].isSupported()) continue;
+			out.add(cfgs[j]);
+		}
+		
+		return (CfgHolder[])out.toArray(new CfgHolder[out.size()]);
+	}
+	
+    /**
+     * 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
+     */
+    public boolean isCustomPageComplete() {
+    	if (!isVisible) return true;
+    	
+		if (table.getItemCount() == 0) {
+			String message = UIMessages.getString("CConfigWizardPage.10");
+			setErrorMessage(message); //$NON-NLS-1$
+			setMessage(message);
+			return false;
+		}
+		/*
+		if (tv.getCheckedElements().length == 0) {
+			errorMessage = UIMessages.getString("CConfigWizardPage.11"); //$NON-NLS-1$
+			message = errorMessage; 
+			return false;
+		}
+		
+		setErrorMessage(null); //$NON-NLS-1$
+		setMessage(MESSAGE);
+		
+		*/
+        return true;
+    }
+
+    /**
+     * Set the visibility of this wizard page.
+     */
+    public void setVisible(boolean visible) {
+    	isVisible = visible;
+		if (visible && esboxHandler != null) {
+			/*
+			tv.setInput(CfgHolder.unique(getDefaultCfgs(esboxHandler)));
+			tv.setAllChecked(false);
+			*/
+			initTable();
+			
+			l_projtype.setText(esboxHandler.getTemplate().getLabel());
+			l_chain.setText(esboxHandler.getESboxToolChain().getName());
+			l_platform.setText(esboxHandler.getPlatformInfo().getName());
+			l_maemoSDK.setText(esboxHandler.getSdkInfo().toString());
+			setPageComplete(isCustomPageComplete());
+		}
+		parent.setVisible(visible);
+		if (visible) update();
+    }
+    
+    private void initTable() {
+    	if (table.getItems().length > 0)
+    		return;
+    	List<String> targets = null;
+		String projectTargetName = "";
+		try {
+			targets = ScratchboxFacade.getInstance().getTargets();
+			projectTargetName = esboxHandler.createTargetName();
+		} catch (ScratchboxException e) {
+			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			errorLogger.logAndShowError("Scratchbox error", e);
+		} catch (Exception e) {			
+			e.printStackTrace();
+		}
+		TableItem line = null;
+		//sorts the target list
+		Object[] targetsName = targets.toArray();		
+		Arrays.sort(targetsName);
+		int projectTargetIndex = -1;
+		for (int i = 0; i < targetsName.length; i++) {
+			//sets the values of the lines			
+			String element = (String)targetsName[i];			
+			line = new TableItem(table, SWT.NONE);			
+			line.setText(element);
+			if (element.equals(projectTargetName)) {
+				projectTargetIndex = i;
+			}
+		}		
+		if (projectTargetIndex < 0) {
+			String localMessage = "There is no suitable target for your project. Please, select an target for your project";
+			setErrorMessage(localMessage);
+			setMessage(localMessage);
+			setPageComplete(false);
+			projectTargetIndex = 0;
+		}
+		column.pack();
+		table.setSelection(projectTargetIndex);
+		esboxHandler.setTargetName(table.getSelection()[0].getText());
+    }
+
+    	//------------------------
+    private Label setupLabel(Composite c, String name, int span, int mode) {
+		Label l = new Label(c, SWT.NONE);
+		l.setText(name);
+		GridData gd = new GridData(mode);
+		gd.horizontalSpan = span;
+		l.setLayoutData(gd);
+		Composite p = l.getParent();
+		l.setFont(p.getFont());
+		return l;
+	}
+
+	public String getName() { return TITLE; }
+	public Control getControl() { return parent; }
+	public String getTitle()   { return TITLE; }
+	
+		@Override
+	public boolean isPageComplete() {
+		return super.isPageComplete() && (getErrorMessage() == null);
+	}
+
+
+	protected void update() {
+		getWizard().getContainer().updateButtons();
+		getWizard().getContainer().updateMessage();
+		getWizard().getContainer().updateTitleBar();
+	}
+	
+	/**
+	 * Edit properties
+	 */
+	private void advancedDialog() {
+		if (getWizard() instanceof ESboxCommonProjectWizard) {
+			ESboxCommonProjectWizard nmWizard = (ESboxCommonProjectWizard)getWizard();
+			IProject newProject = nmWizard.getProject(true, false);
+			if (newProject != null) {
+				boolean oldManage = CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOMNG);
+				// disable manage configurations button
+				CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOMNG, true);
+				try {
+					PreferencesUtil.createPropertyDialogOn(getWizard().getContainer().getShell(), newProject, propertyId, null, null).open();
+				} finally {
+					CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOMNG, oldManage);
+				}
+			}
+		}
+	}
+	
+}

Added: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonMainWizardPage.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonMainWizardPage.java	                        (rev 0)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonMainWizardPage.java	2007-10-23 20:55:45 UTC (rev 179)
@@ -0,0 +1,558 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package org.indt.esbox.python.ui.wizards;
+
+import java.io.File;
+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.cdt.ui.wizards.EntryDescriptor;
+import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
+import org.eclipse.cdt.ui.wizards.IWizardWithMemory;
+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.DialogPage;
+import org.eclipse.jface.wizard.IWizardPage;
+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.graphics.Image;
+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.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+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;
+
+/**
+ * 
+ */
+public class ESboxPythonMainWizardPage extends WizardPage implements IWizardItemsListListener {
+
+	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";
+	
+	public static final String PAGE_ID = "org.indt.esbox.ui.wizard.ProjectWizardPage"; //$NON-NLS-1$
+	public static final String DESC = "EntryDescriptor"; //$NON-NLS-1$ 
+	private static final String HELP_CTX = "org.eclipse.ui.ide.new_project_wizard_page_context"; //$NON-NLS-1$
+	
+    // constants
+    private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
+    // initial value stores
+    private String initialProjectFieldValue;
+
+    // widgets
+    private Text projectNameField;
+    private Tree treeProjectTypes;
+    private Tree treePlatform;
+    private Tree treeSDK;
+
+    private ESboxConfigHandler esboxHandler;
+	private ESboxProjectContentsArea locationArea;   
+
+    /**
+     * Creates a new project creation wizard page.
+     *
+     * @param pageName the name of this page
+     */
+    public ESboxPythonMainWizardPage(String pageName) {
+        super(pageName);
+        setPageComplete(false);        
+        setImageDescriptor(UIActivator.getImageDescriptor("./icons/new_maemo_prj_wiz.gif"));
+        esboxHandler = new ESboxConfigHandler();
+    }
+
+    /** (non-Javadoc)
+     * Method declared on IDialogPage.
+     */
+    public void createControl(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); 
+		
+		setPageComplete(validatePage());
+        // Show description on opening
+        setErrorMessage(null);
+        setMessage(null);
+        setControl(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 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 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 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 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 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);
+			}
+		};
+	}
+	    
+    /**
+     * 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(UIMessages.getString("CMainWizardPage.8")); //$NON-NLS-1$
+        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, new Listener() {
+	        public void handleEvent(Event e) {
+		    	locationArea.updateProjectName(getProjectNameFieldValue());
+	            setPageComplete(validatePage());
+	        }
+	    });
+    }
+
+    /**
+     * 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
+     */
+    private 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();
+    }
+
+    public IPath getProjectLocation() {
+    	return new Path(locationArea.getProjectLocation());
+    }
+
+    public String getProjectLocationPath() {
+    	return locationArea.getProjectLocation();
+    }
+
+    /**
+     * 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());
+			}
+        }
+    }
+
+    /**
+     * 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 = ResourcesPlugin.getWorkspace();
+		setMessage(null);
+
+        String projectFieldContents = getProjectNameFieldValue();
+        if (projectFieldContents.length() == 0) {
+            setErrorMessage(UIMessages.getString("CMainWizardPage.9")); //$NON-NLS-1$
+            return false;
+        }
+
+        IStatus nameStatus = workspace.validateName(projectFieldContents,
+                IResource.PROJECT);
+        if (!nameStatus.isOK()) {
+            setErrorMessage(nameStatus.getMessage());
+            return false;
+        }
+
+        boolean bad = true; // should we treat existing project as error
+        
+        IProject handle = getProjectHandle();
+        
+        if (handle.exists()) {
+        	if (getWizard() instanceof IWizardWithMemory) {
+        		IWizardWithMemory w = (IWizardWithMemory)getWizard();
+        		if (w.getLastProjectName() != null && w.getLastProjectName().equals(getProjectName()))
+        			bad = false;
+        	}
+        	if (bad) { 
+        		setErrorMessage(UIMessages.getString("CMainWizardPage.10")); //$NON-NLS-1$
+        	    return false;
+        	}
+        }
+
+        if (bad) { // skip this check if project already created 
+        	IPath p = getProjectLocation();
+        	if (p == null) {
+        		p = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+        		p = p.append(getProjectName());
+        	}
+        	File f = p.toFile();
+        	if (f.exists()) {
+        		if (f.isDirectory()) {
+        			setMessage(UIMessages.getString("CMainWizardPage.7"), DialogPage.WARNING); //$NON-NLS-1$
+	        		return true;
+        		} else {
+        			setErrorMessage(UIMessages.getString("CMainWizardPage.6")); //$NON-NLS-1$
+	        		return false;
+        		}
+        	}
+        }
+        
+        if (!locationArea.isDefault()) {
+            IStatus locationStatus = workspace.validateProjectLocationURI(handle,
+                    locationArea.getProjectLocationURI());
+            if (!locationStatus.isOK()) {
+                setErrorMessage(locationStatus.getMessage());
+                return false;
+            }
+        }
+
+        if (treeProjectTypes.getItemCount() == 0) {
+        	setErrorMessage(UIMessages.getString("CMainWizardPage.3")); //$NON-NLS-1$
+        	return false;
+        }        
+        
+        if (treePlatform.getItemCount() == 0) {
+        	setErrorMessage("No platforms available. Project cannot be created"); 
+        	return false;
+        }
+        
+        if (treeSDK.getItemCount() == 0) {
+        	setErrorMessage("No Maemo SDKs available. Project cannot be created");
+        	return false;
+        }
+        
+
+		TreeItem[] tis = treeProjectTypes.getSelection();
+		if (tis == null || tis.length == 0) {
+        	setErrorMessage("No project type selected");
+        	return false;
+		}
+		
+		tis = treePlatform.getSelection();
+		if (tis == null || tis.length == 0) {
+        	setErrorMessage("No platform selected");
+        	return false;
+		}
+		
+		tis = treeSDK.getSelection();
+		if (tis == null || tis.length == 0) {
+        	setErrorMessage("No Maemo SDK selected");
+        	return false;
+		}		
+                             
+        setErrorMessage(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();
+    }
+
+	public static EntryDescriptor getDescriptor(Tree _tree) {		
+		TreeItem[] sel = _tree.getSelection();
+		if (sel == null || sel.length == 0) 
+			return null;
+		else
+			return (EntryDescriptor)sel[0].getData(DESC);
+	}
+	
+	public void toolChainListChanged(int count) {
+		setPageComplete(validatePage());
+	}
+
+	public boolean isCurrent() { return isCurrentPage(); }
+	
+	private static Image calcImage(EntryDescriptor ed) {
+		if (ed.getImage() != null) return ed.getImage();
+		if (ed.isCategory()) return IMG_CATEGORY;
+		return IMG_ITEM;
+	}
+	
+	public ESboxConfigHandler getHandler() {
+		return esboxHandler; 
+	}
+	
+	@Override
+	public IWizardPage getNextPage() {
+		// TODO Auto-generated method stub
+		return super.getNextPage();
+	}
+	
+
+}

Modified: trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java
===================================================================
--- trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java	2007-10-23 19:35:17 UTC (rev 178)
+++ trunk/org.indt.esbox.python.ui/src/org/indt/esbox/python/ui/wizards/ESboxPythonProjectWizard.java	2007-10-23 20:55:45 UTC (rev 179)
@@ -7,16 +7,15 @@
  *
  * 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 org.eclipse.cdt.core.CProjectNature;
-import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.indt.esbox.core.ESboxProjectNature;
-import org.indt.esbox.ui.UIActivator;
 import org.indt.esbox.ui.wizards.ESboxCommonProjectWizard;
 
 /**



More information about the Esbox-commits mailing list