[Esbox-commits] r128 - in trunk/org.indt.esbox.ui: . META-INF src/org/indt/esbox/ui src/org/indt/esbox/ui/actions src/org/indt/esbox/ui/dialogs src/org/indt/esbox/ui/env src/org/indt/esbox/ui/preferences src/org/indt/esbox/ui/properties src/org/indt/esbox/ui/wizards

raul at garage.maemo.org raul at garage.maemo.org
Mon Oct 15 02:26:50 EEST 2007


Author: raul
Date: 2007-10-15 02:26:49 +0300 (Mon, 15 Oct 2007)
New Revision: 128

Added:
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/env/
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/env/ESboxEnvironmentTab.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxEnvPreferencePage.java
Modified:
   trunk/org.indt.esbox.ui/META-INF/MANIFEST.MF
   trunk/org.indt.esbox.ui/plugin.xml
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/UIActivator.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/ConfigureAction.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/CreateDebianPackageAction.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/GenerateConfigureAction.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/MaemoMenuDialog.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/XMenuDialog.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/properties/ESBoxTargetPropertyPage.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/wizards/DeployDebianPackageWizard.java
Log:


Modified: trunk/org.indt.esbox.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.indt.esbox.ui/META-INF/MANIFEST.MF	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/META-INF/MANIFEST.MF	2007-10-14 23:26:49 UTC (rev 128)
@@ -12,30 +12,11 @@
  org.eclipse.core.resources,
  org.indt.esbox.core,
  org.eclipse.ui.ide,
- org.eclipse.cdt.debug.ui,
  org.eclipse.cdt.managedbuilder.core,
  org.eclipse.cdt.managedbuilder.ui,
  org.eclipse.core.filesystem,
  org.eclipse.cdt.managedbuilder.gnu.ui,
- org.eclipse.cdt.make.ui,
- com.jcraft.jsch,
- org.eclipse.cdt,
- org.eclipse.cdt.debug.core,
- org.eclipse.cdt.debug.mi.core,
- org.eclipse.cdt.debug.mi.ui,
- org.eclipse.cdt.launch,
- org.eclipse.cdt.managedbuilder.xlc.ui,
- org.eclipse.cdt.refactoring,
- org.eclipse.cdt.sdk,
- org.eclipse.cdt.source,
- org.eclipse.cdt.core.parser.c99,
- org.eclipse.cdt.core.parser.upc,
- org.eclipse.cdt.debug.gdbjtag,
- org.eclipse.cdt.debug.gdbjtag.core,
- org.eclipse.cdt.debug.gdbjtag.ui,
- org.eclipse.cdt.doc.isv,
- org.eclipse.cdt.doc.user,
- org.eclipse.cdt.errorparsers.xlc
+ com.jcraft.jsch
 Eclipse-LazyStart: true
 Export-Package: org.indt.esbox.ui,
  org.indt.esbox.ui.wizards

Modified: trunk/org.indt.esbox.ui/plugin.xml
===================================================================
--- trunk/org.indt.esbox.ui/plugin.xml	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/plugin.xml	2007-10-14 23:26:49 UTC (rev 128)
@@ -41,12 +41,6 @@
             class="org.indt.esbox.ui.properties.ESBoxTargetPropertyPage"
             id="org.indt.esbox.ui.esboxProjectPropertyPage.targets">
       </page>
-      <page
-            category="org.indt.esbox.ui.esboxProjectPropertyPage"
-            class="org.indt.esbox.ui.properties.ESBoxenvPropertyPage"
-            id="org.indt.esbox.ui.esboxProjectPropertyPage.environment"
-            name="Environment">
-      </page>   
    </extension>
       <extension
          point="org.eclipse.ui.preferencePages">
@@ -66,6 +60,12 @@
             category="org.indt.esbox.ui.esboxPreferencePage"
             class="org.indt.esbox.ui.preferences.ESBoxGazpachoPreferencePage"
             id="org.indt.esbox.ui.esboxPreferencePage.gazpacho">
+      </page>
+      <page
+            category="org.indt.esbox.ui.esboxPreferencePage"
+            class="org.indt.esbox.ui.preferences.ESboxEnvPreferencePage"
+            id="org.indt.esbox.ui.esboxPreferencePage.env"
+            name="Environment">
       </page>      
    </extension>
    <extension
@@ -282,5 +282,13 @@
 		<builder builderID="org.indt.esbox.core.esboxMakeBuilder" 
 				 id="MakeTargetBuilder"/>
 	</extension>
+ <extension
+       point="org.eclipse.cdt.ui.cPropertyTab">
+    <tab
+          class="org.indt.esbox.ui.env.ESboxEnvironmentTab"
+          name="Environment"
+          parent="org.indt.esbox.ui.preferences.ESboxEnvPreferencePage">
+    </tab>
+ </extension>
 	
-</plugin>
\ No newline at end of file
+</plugin>

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/UIActivator.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/UIActivator.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/UIActivator.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -16,7 +16,9 @@
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.indt.esbox.core.ErrorLogger;
+import org.indt.esbox.core.env.ESboxEnvironmentVariableManager;
 import org.osgi.framework.BundleContext;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
 import org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin;
 
 /**
@@ -121,4 +123,8 @@
 		return resourceBundle;
 	}
 	
+	public IEnvironmentVariableManager getBuildEnvironmentManager() {
+		return ESboxEnvironmentVariableManager.getDefault();
+	}
+	
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/ConfigureAction.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/ConfigureAction.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/ConfigureAction.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -18,7 +18,7 @@
 	 */
 	public void run(IAction action) {
 		IProject project = (IProject)extractSelection();
-		ESboxScriptLauncher.runConfigure(project.getLocation());
+		ESboxScriptLauncher.getInstance().runConfigure(project.getLocation());
 	}
 
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/CreateDebianPackageAction.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/CreateDebianPackageAction.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/CreateDebianPackageAction.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -19,7 +19,7 @@
 
 	public void run(IAction action) {
 		IProject project = (IProject)extractSelection();
-		ESboxScriptLauncher.MakeDeb(project.getLocation());		
+		ESboxScriptLauncher.getInstance().makeDebianPackage(project.getLocation());		
 	}
 
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/GenerateConfigureAction.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/GenerateConfigureAction.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/actions/GenerateConfigureAction.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -18,6 +18,6 @@
 	 */
 	public void run(IAction action) {
 		IProject project = (IProject)extractSelection();
-		ESboxScriptLauncher.runAutogen(project.getLocation());
+		ESboxScriptLauncher.getInstance().runAutogen(project.getLocation());
 	}
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/MaemoMenuDialog.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/MaemoMenuDialog.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/MaemoMenuDialog.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -111,7 +111,16 @@
 	 */
 	protected void restartClicked() {
 		try {
+			if (!ESboxScriptLauncher.getInstance().isXServerStarted())
+				throw new ScratchboxException("Cannot restart Maemo. Start X Server first");
+			
+			if (!ESboxScriptLauncher.getInstance().isMaemoStarted())
+				throw new ScratchboxException("Maemo was not started. It cannot be restarted");
+			
 			ScratchboxFacade.getInstance().killProcess();
+			
+			ESboxScriptLauncher.getInstance().setMaemoStarted(false);
+			
 			ScratchboxFacade.getInstance().startMaemoCommand();
 		} catch (ScratchboxException e) {
 			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
@@ -124,8 +133,13 @@
 	 */
 	protected void stopClicked() {
 		try {
+			if (!ESboxScriptLauncher.getInstance().isXServerStarted())
+				throw new ScratchboxException("Cannot stop Maemo. Start X Server first");
+			
+			if (!ESboxScriptLauncher.getInstance().isMaemoStarted())
+				throw new ScratchboxException("Maemo was not started. It cannot be stopped");
+			
 			ScratchboxFacade.getInstance().killProcess();
-			ESboxScriptLauncher.killProcess("/usr/bin/maemo-launcher --daemon --send-app-died --booster gtk");
 		} catch (ScratchboxException e) {
 			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
 			errorLogger.logAndShowError("Scratchbox error", e);

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/XMenuDialog.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/XMenuDialog.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/dialogs/XMenuDialog.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -25,6 +25,9 @@
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
 import org.indt.esbox.core.ESboxScriptLauncher;
+import org.indt.esbox.core.ErrorLogger;
+import org.indt.esbox.core.scratchbox.ScratchboxException;
+import org.indt.esbox.ui.UIActivator;
 
 /**
  * @author reijula
@@ -65,7 +68,7 @@
 		//shell for creating menu
 		Shell parent = window.getShell();
 		
-		launcher = new ESboxScriptLauncher();
+		launcher = ESboxScriptLauncher.getInstance();
 		//toolbar pulldownmenu ->
 		pulldownmenu = new Menu(parent);
 		
@@ -96,11 +99,10 @@
 	protected void startClicked() {
 		try {
 			launcher.startX();
+		} catch (Exception e){
+			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			errorLogger.logAndShowError("Scratchbox error", e);
 		}
-		catch (Exception e){
-			System.out.println("Error starting X , wait failed\n"+
-					"Error " + e.getMessage());
-		}
 		
 	}
 	
@@ -109,7 +111,12 @@
 	 * Stop X, from sbdt.core
 	 */
 	protected void stopClicked() {
-		launcher.stopX();
+		try {
+			launcher.stopX();
+		} catch (ScratchboxException e) {
+			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			errorLogger.logAndShowError("Scratchbox error", e);
+		}
 	}
 
 	/* (non-Javadoc)

Added: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/env/ESboxEnvironmentTab.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/env/ESboxEnvironmentTab.java	                        (rev 0)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/env/ESboxEnvironmentTab.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -0,0 +1,469 @@
+/*******************************************************************************
+ * 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.ui.env;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.cdt.core.envvar.IContributedEnvironment;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICResourceDescription;
+import org.eclipse.cdt.internal.core.envvar.UserDefinedEnvironmentSupplier;
+import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
+import org.eclipse.cdt.ui.newui.CDTListComparator;
+import org.eclipse.cdt.ui.newui.EnvDialog;
+import org.eclipse.cdt.ui.newui.PrefPage_Abstract;
+import org.eclipse.cdt.ui.newui.UIMessages;
+import org.eclipse.cdt.utils.envvar.StorableEnvironment;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.TextProcessor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+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.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.indt.esbox.core.env.ESboxEnvironmentVariableManager;
+import org.indt.esbox.core.env.ESboxStorableEnvironment;
+import org.indt.esbox.core.env.ScratchboxEnvironmentReader;
+import org.indt.esbox.ui.UIActivator;
+
+/**
+ *
+ */
+public class ESboxEnvironmentTab extends AbstractCPropertyTab {
+	private static final String PREFIX = "EnvironmentBlock";	//$NON-NLS-1$
+	private static final String LABEL = PREFIX + ".label";	//$NON-NLS-1$
+	private static final String VALUE_UNDEF = LABEL + ".value.undef";	//$NON-NLS-1$
+	private static final String SEMI = ";"; //$NON-NLS-1$
+	private static final String LBR = " ["; //$NON-NLS-1$
+	private static final String RBR = "]"; //$NON-NLS-1$
+	private static final UserDefinedEnvironmentSupplier fUserSupplier = ESboxEnvironmentVariableManager.fUserSupplier;
+	
+
+	private Table table;
+	private TableViewer tv;
+	private ArrayList data = new ArrayList();
+	private Button b1, b2;
+	
+	private static final IContributedEnvironment ce = UIActivator.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
+	private ICConfigurationDescription cfgd = null;
+	private ESboxStorableEnvironment vars = null;
+
+	private class TabData {
+		IEnvironmentVariable var;
+		boolean changed;
+		TabData(IEnvironmentVariable _var, boolean _changed) {
+			var = _var;
+			changed = _changed;
+		}
+	}
+	
+	private class EnvironmentLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider , ITableFontProvider, IColorProvider{
+		public EnvironmentLabelProvider(boolean user){
+		}
+		public Image getImage(Object element) {
+			return null; // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_INFO);
+		}
+		public String getText(Object element) {
+			return getColumnText(element, 0);
+		}
+		public Image getColumnImage(Object element, int columnIndex) {
+			return null;
+		}
+		public String getColumnText(Object element, int columnIndex) {
+			TabData td = (TabData)element;
+			switch(columnIndex){
+			case 0:
+				return td.var.getName();
+			case 1:
+				if(td.var.getOperation() == IEnvironmentVariable.ENVVAR_REMOVE)
+					return UIMessages.getString(VALUE_UNDEF);
+				return td.var.getValue();
+			}
+			return EMPTY_STR;
+		}
+
+		public Font getFont(Object element) {
+			return getFont(element, 0);
+		}
+
+		public Font getFont(Object element, int columnIndex) {
+			TabData td = (TabData)element;
+			Font f = null;
+			if (cfgd == null || ce.isUserVariable(cfgd, td.var))
+				f = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
+
+			switch(columnIndex){
+			case 0:
+				break;
+			case 1:
+				if(td.var.getOperation() == IEnvironmentVariable.ENVVAR_REMOVE)
+					f = JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT);
+				break;
+			}
+			return f;
+		}
+		
+	    /* (non-Javadoc)
+	     * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
+	     */
+	    public Color getForeground(Object element){
+			return null;
+	    }
+		public Color getBackground(Object element){
+			return null;
+	    }
+	}
+	
+	public void createControls(Composite parent) {
+		super.createControls(parent);
+		usercomp.setLayout(new GridLayout(1, false));
+		Label l1 = new Label(usercomp, SWT.LEFT);
+		l1.setText("Scratchbox environment variables to set"); //$NON-NLS-1$
+		l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		table = new Table(usercomp, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.FULL_SELECTION);
+		table.setHeaderVisible(true);
+		table.setLinesVisible(true);
+		table.addSelectionListener(new SelectionListener() {
+			public void widgetSelected(SelectionEvent e) {
+				updateButtons();
+			}
+			public void widgetDefaultSelected(SelectionEvent e) {
+	    		if (buttonIsEnabled(2) && table.getSelectionIndex() != -1)
+    				buttonPressed(2);
+			}});
+		
+		tv = new TableViewer(table);
+		tv.setContentProvider(new IStructuredContentProvider() {
+
+			public Object[] getElements(Object inputElement) {
+				if (inputElement != null && inputElement instanceof ArrayList) {
+					ArrayList ar = (ArrayList)inputElement;
+					return ar.toArray(new TabData[0]);
+				}
+				return null;
+			}
+			public void dispose() {}
+			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+			});
+		tv.setLabelProvider(new EnvironmentLabelProvider(true));
+		// add headers
+		TableColumn tc = new TableColumn(table, SWT.LEFT);
+		tc.setText(UIMessages.getString("EnvironmentTab.1")); //$NON-NLS-1$
+		tc.setWidth(200);
+		tc = new TableColumn(table, SWT.LEFT);
+		tc.setText(UIMessages.getString("EnvironmentTab.2")); //$NON-NLS-1$
+		tc.setWidth(200);
+		                      
+	    table.setLayoutData(new GridData(GridData.FILL_BOTH));
+	    
+	    b1 = new Button(usercomp, SWT.RADIO);
+	    b1.setText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$
+	    b1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+	    b1.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				if (cfgd != null)
+					ce.setAppendEnvironment(true, cfgd);
+				else
+					vars.setAppendContributedEnvironment(true);
+				updateData();
+			}});
+
+	    b2 = new Button(usercomp, SWT.RADIO);
+	    b2.setText(UIMessages.getString("EnvironmentTab.4")); //$NON-NLS-1$
+	    b2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+	    b2.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				if (cfgd != null)
+					ce.setAppendEnvironment(false, cfgd);
+				else
+					vars.setAppendContributedEnvironment(false);
+				updateData();
+			}});
+	    
+	    initButtons(new String[] {UIMessages.getString("EnvironmentTab.5"),UIMessages.getString("EnvironmentTab.6"),UIMessages.getString("EnvironmentTab.7"),UIMessages.getString("EnvironmentTab.8"),UIMessages.getString("EnvironmentTab.9")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+	}
+
+	public void buttonPressed(int i) {
+		IEnvironmentVariable var = null;
+		EnvDialog dlg;
+		int n = table.getSelectionIndex();
+		int[] idx;
+		switch (i) {
+		case 0:
+			dlg = new EnvDialog(usercomp.getShell(), var, UIMessages.getString("EnvironmentTab.10"), true, cfgd); //$NON-NLS-1$
+			if (dlg.open() == Window.OK) {
+				if (dlg.t1.trim().length() > 0) {
+					ICConfigurationDescription[] cfgs;
+					if (dlg.toAll)
+						cfgs = page.getCfgsEditable();
+					else 
+						cfgs = new ICConfigurationDescription[] {cfgd};
+					if (cfgd == null)
+						vars.createVariable(dlg.t1.trim(), dlg.t2.trim(), 
+								IEnvironmentVariable.ENVVAR_APPEND,	SEMI);
+					else	
+						for (int x=0; x<cfgs.length; x++) { 
+							ce.addVariable(dlg.t1.trim(), dlg.t2.trim(), 
+							IEnvironmentVariable.ENVVAR_APPEND, 
+							SEMI, cfgs[x]);
+					}
+					updateData();
+				}
+			}
+			break;
+		case 1: // select
+			handleEnvSelectButtonSelected();
+			updateData();
+			break;
+		case 2: // edit
+			if (n == -1) return;
+			var = ((TabData)tv.getElementAt(n)).var;
+			dlg = new EnvDialog(usercomp.getShell(), var, UIMessages.getString("EnvironmentTab.11"), false, cfgd); //$NON-NLS-1$
+			if (dlg.open() == Window.OK) {
+				if (cfgd != null)
+					ce.addVariable(	dlg.t1.trim(), dlg.t2.trim(), 
+						IEnvironmentVariable.ENVVAR_REPLACE, 
+						var.getDelimiter(), cfgd);
+				else
+					vars.createVariable(dlg.t1.trim(), dlg.t2.trim(),
+						IEnvironmentVariable.ENVVAR_REPLACE, var.getDelimiter());
+				updateData();
+			}
+			break;
+		case 3: // remove
+			if (n == -1) return;
+			idx = table.getSelectionIndices();
+			for (int j=0; j<idx.length; j++) {
+				var = ((TabData)tv.getElementAt(idx[j])).var;
+				if (cfgd == null) 
+					vars.deleteVariable(var.getName());
+				else
+					ce.removeVariable(var.getName(), cfgd);
+			}
+			updateData();
+			break;
+		case 4: // Undefine
+			if (n == -1) return;
+			idx = table.getSelectionIndices();
+			for (int j=0; j<idx.length; j++) {
+				var = ((TabData)tv.getElementAt(idx[j])).var;
+				if (cfgd == null)
+					vars.createVariable(
+							var.getName(), 
+							null, 
+							IEnvironmentVariable.ENVVAR_REMOVE, 
+							var.getDelimiter());
+				else 
+					ce.addVariable(
+						var.getName(), 
+						null, 
+						IEnvironmentVariable.ENVVAR_REMOVE, 
+						var.getDelimiter(), cfgd);
+			}
+			updateData();
+			break;
+		}
+		updateButtons();
+	}
+	
+	public void updateButtons() {
+		if (table == null || table.isDisposed()) return;
+		
+		int pos = table.getSelectionIndex();
+		buttonSetEnabled(2, pos != -1);
+		buttonSetEnabled(3, pos != -1);
+		buttonSetEnabled(4, pos != -1);
+	}
+
+	public void updateData(ICResourceDescription _cfgd) {
+		// null means preference configuration 
+		cfgd = (_cfgd != null) ? _cfgd.getConfiguration() : null;
+		if (cfgd == null && vars == null)
+			vars = convertToESboxStorable(fUserSupplier.getWorkspaceEnvironmentCopy());
+		updateData();
+	}
+	
+	private ESboxStorableEnvironment convertToESboxStorable(StorableEnvironment env) {
+		return new ESboxStorableEnvironment(env.getVariables(),env.isReadOnly());
+	}
+	
+	private void updateData() {
+		IEnvironmentVariable[] _vars = null;
+		if (cfgd != null) {
+			b1.setSelection(ce.appendEnvironment(cfgd));
+			b2.setSelection(!ce.appendEnvironment(cfgd));
+			 _vars = ce.getVariables(cfgd);
+		} else {
+			b1.setSelection(vars.appendContributedEnvironment());
+			b2.setSelection(!vars.appendContributedEnvironment());
+			_vars = vars.getVariables() ;
+		}
+		data.clear();
+		if (_vars != null) {
+			for (int i=0; i<_vars.length; i++) {
+				data.add(new TabData(_vars[i], false));
+			}
+		}
+		tv.setInput(data);
+		updateButtons();
+	}
+
+	public void performApply(ICResourceDescription _src, ICResourceDescription _dst) {
+		ICConfigurationDescription src = _src.getConfiguration();
+		ICConfigurationDescription dst = _dst.getConfiguration();
+		
+		ce.setAppendEnvironment(ce.appendEnvironment(src), dst);
+		IEnvironmentVariable[] v = ce.getVariables(dst);
+		for (int i=0; i<v.length; i++) ce.removeVariable(v[i].getName(), dst);
+		v = ce.getVariables(src);
+		for (int i=0; i<v.length; i++) {
+			if (ce.isUserVariable(src, v[i]))
+					ce.addVariable(v[i].getName(), v[i].getValue(), 
+							v[i].getOperation(), v[i].getDelimiter(), dst);
+		}
+	}
+
+	/**
+	 * 
+	 */
+	private class MyListSelectionDialog extends ListSelectionDialog {
+		public boolean toAll = false;
+	    public MyListSelectionDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider) {
+	        super(parentShell, input, contentProvider, new LabelProvider() {}, UIMessages.getString("EnvironmentTab.12")); //$NON-NLS-1$
+	    }
+	    protected Control createDialogArea(Composite parent) {
+	    	Composite composite = (Composite) super.createDialogArea(parent);
+	    	Button b = new Button(composite, SWT.CHECK);
+	    	b.setText(UIMessages.getString("EnvironmentTab.13")); //$NON-NLS-1$
+	    	b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+	    	if (cfgd == null)
+	    		b.setVisible(false);
+	    	else
+	    		b.addSelectionListener(new SelectionAdapter() {
+	    			public void widgetSelected(SelectionEvent e) {
+	    				toAll = ((Button)e.widget).getSelection();
+	    			}});
+	    	return composite;
+	    }
+	}
+	
+	private void handleEnvSelectButtonSelected() {
+		// get Environment Variables from the OS
+		Map v = ScratchboxEnvironmentReader.getInstance().getEnvVars();
+		MyListSelectionDialog dialog = new MyListSelectionDialog(usercomp.getShell(), v, createSelectionDialogContentProvider());
+		
+		dialog.setTitle(UIMessages.getString("EnvironmentTab.14")); //$NON-NLS-1$
+		if (dialog.open() == Window.OK) {
+			Object[] selected = dialog.getResult();
+			ICConfigurationDescription[] cfgs;
+			if (dialog.toAll)
+				cfgs = page.getCfgsEditable();
+			else 
+				cfgs = new ICConfigurationDescription[] {cfgd};
+			
+			for (int i = 0; i < selected.length; i++) {
+				String name = (String)selected[i];
+				String value = EMPTY_STR;
+				int x = name.indexOf(LBR);
+				if (x >= 0) {
+					value = name.substring(x + 2, name.length() - 1);
+					name = name.substring(0, x);
+				}
+				
+				if (cfgd == null) 
+					vars.createVariable(name, value); 
+				else
+					for (int y=0; y<cfgs.length; y++) { 
+						ce.addVariable(
+								name, value, 
+								IEnvironmentVariable.ENVVAR_APPEND, 
+								SEMI, cfgs[y]);
+				}
+			}
+		}
+	}
+	
+	private IStructuredContentProvider createSelectionDialogContentProvider() {
+		return new IStructuredContentProvider() {
+
+			public Object[] getElements(Object inputElement) {
+				String[] els = null;
+				if (inputElement instanceof Map) {
+					Map m = (Map)inputElement;
+					els = new String[m.size()];  
+					int index = 0;
+					for (Iterator iterator = m.keySet().iterator(); iterator.hasNext(); index++) {
+						String k = (String)iterator.next();
+						els[index] = TextProcessor.process(k + LBR + (String)m.get(k) + RBR);  
+					}
+				}
+				Arrays.sort(els, CDTListComparator.getInstance());
+				return els;
+			}
+			public void dispose() {}
+			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+		};
+	}
+	// This page can be displayed for project only
+	public boolean canBeVisible() {
+		return page.isForProject() || page.isForPrefs();
+	}
+
+	protected void performOK() {
+		if (vars != null) {
+			if (setWorkspaceEnvironment(vars))
+				if (page instanceof PrefPage_Abstract)
+					PrefPage_Abstract.isChanged = true;
+		}
+		vars = null;
+		super.performOK();
+	}
+	
+	private boolean setWorkspaceEnvironment(ESboxStorableEnvironment env) {		
+		return fUserSupplier.setWorkspaceEnvironment(new StorableEnvironment(env.getVariables(),env.isReadOnly()));
+	}
+	
+	protected void performCancel() {
+		vars = null;
+		super.performCancel();
+	}
+	
+	protected void performDefaults() {
+		ce.restoreDefaults(cfgd); // both for proj & prefs
+		vars = null;
+		updateData();
+	}
+}

Added: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxEnvPreferencePage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxEnvPreferencePage.java	                        (rev 0)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxEnvPreferencePage.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.ui.preferences;
+
+import org.eclipse.cdt.ui.newui.PrefPage_Abstract;
+
+/**
+ * 
+ */
+public class ESboxEnvPreferencePage extends PrefPage_Abstract {
+
+}
\ No newline at end of file

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/properties/ESBoxTargetPropertyPage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/properties/ESBoxTargetPropertyPage.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/properties/ESBoxTargetPropertyPage.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -19,6 +19,8 @@
 
 import org.eclipse.cdt.internal.ui.util.PixelConverter;
 import org.eclipse.cdt.internal.ui.util.SWTUtil;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.Preferences;
 import org.eclipse.jface.viewers.TableLayout;
 import org.eclipse.jface.wizard.WizardDialog;
@@ -37,10 +39,10 @@
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
 import org.eclipse.ui.IWorkbenchPropertyPage;
 import org.eclipse.ui.dialogs.PropertyPage;
 import org.indt.esbox.core.CoreActivator;
+import org.indt.esbox.core.ESboxProjectProperties;
 import org.indt.esbox.core.ErrorLogger;
 import org.indt.esbox.core.scratchbox.ScratchboxException;
 import org.indt.esbox.core.scratchbox.ScratchboxFacade;
@@ -218,38 +220,40 @@
 	private void initTable() {
 		table.setRedraw(false);
 		List<String> targets = null;
-		String currentTarget = "";
+		String projectTarget = "";
 		try {
 			targets = getTargets();
-			currentTarget = ScratchboxFacade.getInstance().getCurrentTarget();
-		} catch (ScratchboxException e) {
+			projectTarget = ESboxProjectProperties.getInstance().getTargetName(getProject());			
+		} catch (Exception 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 currentTargetIndex = -1;
+		int currentProjectTargetIndex = -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(currentTarget)) {
-				currentTargetIndex = i;
+			if (element.equals(projectTarget)) {
+				currentProjectTargetIndex = i;
 			}
 		}		
 		column.pack();
-		table.setSelection(currentTargetIndex);
+		table.setSelection(currentProjectTargetIndex);
 		
 		table.setRedraw(true); //redraw the table so the modifications can be seen.		
 		//set the checked value to the one stored at preference store.
-		setSelectedTarget(currentTarget);
+		setSelectedTarget(projectTarget);
 	}
 	
+	private IProject getProject() {
+		return (IProject)((IResource)getElement().getAdapter(IResource.class));
+	}
+	
 	/**
 	 * Gets the list of the names of targets
 	 * 
@@ -330,4 +334,11 @@
 			return null;
 	}
 	
+	@Override
+	public boolean performOk() {
+		String targetSelected = table.getSelection()[0].getText();
+		ESboxProjectProperties.getInstance().setTargetName(getProject(), targetSelected);
+		return super.performOk();
+	}
+	
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/wizards/DeployDebianPackageWizard.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/wizards/DeployDebianPackageWizard.java	2007-10-14 23:20:25 UTC (rev 127)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/wizards/DeployDebianPackageWizard.java	2007-10-14 23:26:49 UTC (rev 128)
@@ -55,7 +55,7 @@
 	}
 
 	private void createDebianPackage() {
-		ESboxScriptLauncher.MakeDeb(deployPage.getProject().getLocation());
+		ESboxScriptLauncher.getInstance().makeDebianPackage(deployPage.getProject().getLocation());
 	}
 	
 	private void installDebianPackage() {



More information about the Esbox-commits mailing list