[Esbox-commits] r39 - trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences

pauloromulo at garage.maemo.org pauloromulo at garage.maemo.org
Tue Oct 2 23:47:59 EEST 2007


Author: pauloromulo
Date: 2007-10-02 23:47:59 +0300 (Tue, 02 Oct 2007)
New Revision: 39

Modified:
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxXServerPreferencePage.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java
Log:
configuring the default preferences settings and storing the current preferences settings

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java	2007-10-02 20:25:51 UTC (rev 38)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java	2007-10-02 20:47:59 UTC (rev 39)
@@ -13,6 +13,7 @@
 
 import org.eclipse.jface.preference.BooleanFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.StringFieldEditor;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IWorkbench;
@@ -24,101 +25,31 @@
 
 	public static final String GAZPACHO_COMMAND = "gazpachoCommandPreference";
 	public static final String USE_X_HOST = "useXhostcommand";
-	public static final String X_HOST_CMD = "Xhostcommand";
-
-	private static String[][] sbPreferenceFiles;
+	public static final String X_HOST_CMD = "Xhostcommand";	
 	
 	private BooleanFieldEditor feUseXhostCmd = null; 
 	private StringFieldEditor feXhostCmd = null; 
+	private StringFieldEditor feGazpachoCmd = null;	 
 
-	private Composite oParent = null;
-
 	public ESBoxGazpachoPreferencePage() {
-		super(GRID);
-		try{		
+		super(GRID);				
 		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
-		setDescription("Preferences for Running Glade User Interface Editor:");	
-		}catch (Throwable t) {
-			t.printStackTrace();
-		}
+		setDescription("Preferences for Running Gazpacho User Interface Editor:");		
 	}
 
 	/**
-	 * Method read default preferences from selected file and store
-	 * default valus for preference store.
-	 */
-//	public static void storeDefaultPrefsFromFile() {
-//		// Object preferences which does not die if Eclipse is restarted
-//		Preferences prefs = Preferences.userNodeForPackage(SbPreferencePage.class);
-//		// check out default filenumber
-//		int filenum = prefs.getInt("filenumber", 0);
-//
-//		String filename = SbCoreHelper.findCorePluginPath() + "preferences/" +sbPreferenceFiles[filenum][0];
-//		// read file to string
-//		String file = SbCoreHelper.readFileToString(filename);		
-//		// replace USER with real username
-//		file = file.replaceAll("USER", System.getProperty("user.name"));
-//		// get preference store
-//		SbCorePlugin plugin = SbCorePlugin.getDefault();
-//		IPreferenceStore store = plugin.getPreferenceStore();
-//
-//		// save all default values from file to preference store
-//		store.setDefault(GazpachoPreferencePage.GAZPACHO_COMMAND, findValue(file, "GAZPACHO_COMMAND"));
-//		store.setDefault(GazpachoPreferencePage.USE_X_HOST, findValue(file, "USE_X_HOST"));
-//		store.setDefault(GazpachoPreferencePage.X_HOST_CMD, findValue(file, "X_HOST_CMD"));
-//
-//	}
-
-	/**
-	 * Method find param text from param file and returns string
-	 * that include all after =-mark on that line. If text or =-mark
-	 * doesn't find return an empty string.
-	 * 
-	 * @param file
-	 * @param text
-	 * @return
-	 */
-//	private static String findValue(String file, String text) {
-//		
-//		// find param tex from file
-//		int value = file.indexOf(text);
-//		// and next line feed after value
-//		int value2 = file.indexOf("\n", value);
-//		// if does not find return an empty string
-//		if(value == -1 || value2 == -1) {
-//			return new String("");
-//		}
-//		String temp = file.substring(value, value2);
-//		// check if =-mark exist
-//		String rv = "";
-//		
-//		if(temp.indexOf("=") != -1) {
-//			rv = temp.substring(temp.indexOf("=") + 1);
-//		}	
-//			
-//		return rv;		
-//	}
-
-	/**
 	 * Creates the field editors. Field editors are abstractions of the common
 	 * GUI blocks needed to manipulate various types of preferences. Each field
 	 * editor knows how to save and restore itself.
 	 */
 	public void createFieldEditors() {
-		try{
-		oParent = getFieldEditorParent();
-		addField(new StringFieldEditor(GAZPACHO_COMMAND,
+		Composite oParent = getFieldEditorParent();
+		
+		feGazpachoCmd =
+			new StringFieldEditor(GAZPACHO_COMMAND,
 				"The command to start the Gazpacho:",
-				oParent));
+				oParent);	
 		
-	/*	ComboFieldEditor comboEditor= new ComboFieldEditor(
-				"sbDefaultFilePreference",
-				"Resolution for starting Gazpacho",
-				sbGazpachosettings,
-				getFieldEditorParent());
-		addField(comboEditor);
-		*/
-		
 		feUseXhostCmd = 
 			new BooleanFieldEditor(USE_X_HOST,
 				"Use x-host command starting Gazpacho in Maemo",
@@ -129,12 +60,19 @@
 				"The syntax for starting Xhost:",
 				oParent); 
 	
+		addField(feGazpachoCmd);
 		addField(feUseXhostCmd);
 		addField(feXhostCmd);
-		}catch (Throwable t) {
-			t.printStackTrace();
-		}
+		
+		initializeValues();
 	}
+	
+	private void initializeValues() {
+		IPreferenceStore store = getPreferenceStore();		
+		store.setDefault(GAZPACHO_COMMAND, "/usr/bin/gazpacho");
+		store.setDefault(USE_X_HOST, true);
+		store.setDefault(X_HOST_CMD, "DISPLAY=:0");
+	}
 
 	public void init(IWorkbench workbench) {
 		// Nothing to do

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxXServerPreferencePage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxXServerPreferencePage.java	2007-10-02 20:25:51 UTC (rev 38)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxXServerPreferencePage.java	2007-10-02 20:47:59 UTC (rev 39)
@@ -37,8 +37,7 @@
 	private boolean textHasChanged;
 	
 	public ESBoxXServerPreferencePage() {
-		super(GRID);
-		System.out.println("XPreferencePage");
+		super(GRID);		
 		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
 		setDescription("Preferences for Running Graphical Programs inside Scratchbox:");
 		textHasChanged = false;
@@ -51,9 +50,6 @@
 	 * editor knows how to save and restore itself.
 	 */
 	public void createFieldEditors() {
-//		System.out.println("createFieldEditors");
-//		System.out.println("getFieldEditorParent() = ");
-//		System.out.println(getFieldEditorParent());
 		xServerSyntax = new StringFieldEditorWithListener(SB_DISPLAY_SERVER,
 				"The syntax for starting X-server:", getFieldEditorParent());
 		//adds listener for hiding and showing the text
@@ -98,6 +94,7 @@
 	  	hideScriptextfield(syntaxforstartingX);
 	  	return ret;
 	}
+	
 	/**
 	 * Handles the keypressing
 	 * @param e
@@ -143,49 +140,4 @@
 		// Nothing to do
 	}
 
-
-	
-//	@Override
-//	/**
-//	 * also saves the script
-//	 */
-//	protected void performApply() {
-//		super.performApply();
-//		if (textHasChanged){
-//			SaveText();
-//		}
-//	}
-
-//	@Override
-//	public boolean performOk() {
-//		if (textHasChanged){
-//			SaveText();
-//		}
-//		return super.performOk();
-//		
-//		
-//	}
-
-//	private void SaveText() {
-//		textHasChanged = false;
-//		String filename = scriptlabel.getText();
-//		if (!filename.endsWith(".sh")){
-//			return;
-//		} else {
-//			//case script starts with dot replace filename with string without .
-//			if (filename.indexOf(".") == 0){
-//				filename = filename.substring(1);
-//			}
-//			File file = new File(filename);
-//			//System.out.println("content of: " + file);
-//			if (file.exists()){
-//				String filecontent = textview.getText();
-//				SbCoreHelper.writeContentToFile(filecontent, file);
-//				System.out.println("file " + file + " saved");
-//			} else {
-//				System.out.println("file " + file + " does not exist, cannot save");
-//			}
-//		}		
-//	}
-
 }

Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java	2007-10-02 20:25:51 UTC (rev 38)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java	2007-10-02 20:47:59 UTC (rev 39)
@@ -12,11 +12,7 @@
 package org.indt.esbox.ui.preferences;
 
 
-import java.util.prefs.Preferences;
-
-import org.eclipse.cdt.debug.internal.ui.preferences.ComboFieldEditor;
 import org.eclipse.jface.preference.DirectoryFieldEditor;
-import org.eclipse.jface.preference.FieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.jface.preference.StringFieldEditor;
 import org.eclipse.swt.widgets.Composite;
@@ -28,7 +24,7 @@
 public class ScratchboxPreferencesPage extends FieldEditorPreferencePage implements
 	IWorkbenchPreferencePage {
 
-	public static final String SB_DEFAULT_FILE = "sbDefaultFilePreference"; //$NON-NLS-1$
+	//public static final String SB_DEFAULT_FILE = "sbDefaultFilePreference"; //$NON-NLS-1$
 	
 	public static final String SB_ROOT = "sbPathPreference"; //$NON-NLS-1$
 
@@ -40,7 +36,7 @@
 
 	public static final String SB_TARGET_LIST_CMD = "sbTargetListPreference"; //$NON-NLS-1$
 
-	private static String[][] sbPreferenceFiles = { {"name1", "value1"}, {"name2", "value2"} };
+	//private static String[][] sbPreferenceFiles = { {"name1", "value1"}, {"name2", "value2"} };
 	
 	public ScratchboxPreferencesPage() {
 		super(GRID);
@@ -57,15 +53,7 @@
 	 * GUI blocks needed to manipulate various types of preferences. Each field
 	 * editor knows how to save and restore itself.
 	 */
-	public void createFieldEditors() {	
-		try{
-		OwnComboFieldEditor comboEditor= new OwnComboFieldEditor(
-			SB_DEFAULT_FILE,
-			"Version of default preference values:",
-			sbPreferenceFiles,
-			getFieldEditorParent());
-		addField(comboEditor);
-		
+	public void createFieldEditors() {		
 		addField(new DirectoryFieldEditor(SB_ROOT, "Sandbox Root Directory:",
 				getFieldEditorParent()));
 
@@ -80,88 +68,10 @@
 				getFieldEditorParent()));
 		addField(new GDBServerSelectionEditor(SB_GDB_SERVER,
 				"Starting GDB server inside Scratchbox:",
-				getFieldEditorParent()));
-		}catch(Throwable t){
-			t.printStackTrace();
-		}
+				getFieldEditorParent()));		
 	}
 
-	/**
-	 * Method reads all .pref files form coreplugin's preference folder and
-	 * save those filenames to sbPreferenceFiles
-	 */
-//	private static void getSbPreferenceFiles() {
-//		String path = SbCoreHelper.findCorePluginPath();
-//		path = path + "preferences/";
-//		ArrayList temp = SbCoreHelper.getFilesInFolder(path, "pref", path, false);
-//		sbPreferenceFiles = new String[temp.size()][2];
-//
-//		for(int i=0; i<temp.size(); i++) {
-//			sbPreferenceFiles[i][0] = (String)temp.get(i);
-//			sbPreferenceFiles[i][1] = new String(new Integer(i).toString());
-//		}
-//	}
-	
-	/**
-	 * Method read default preferences from selected file and store
-	 * default valus for preference store.
-	 */
-//	public static void storeDefaultPrefsFromFile() {
-//		// Object preferences which does not die if Eclipse is restarted
-//		Preferences prefs = Preferences.userNodeForPackage(ScratchboxPreferencesPage.class);
-//		// check out default filenumber
-//		int filenum = prefs.getInt("filenumber", 0);
-//
-//		//String filename = SbCoreHelper.findCorePluginPath() + "preferences/" +sbPreferenceFiles[filenum][0];
-//		// read file to string
-//		//String file = SbCoreHelper.readFileToString(filename);		
-//		// replace USER with real username
-//		//file = file.replaceAll("USER", System.getProperty("user.name"));
-//			
-//		// get preference store
-//		UIActivator plugin = UIActivator.getDefault();
-//		IPreferenceStore store = plugin.getPreferenceStore();
-//
-//		// save all default values from file to preference store
-////		store.setDefault(ScratchboxPreferencesPage.SB_DEFAULT_FILE, filenum);
-////		store.setDefault(ScratchboxPreferencesPage.SB_ROOT, findValue(file, "SB_ROOT"));
-////		store.setDefault(ScratchboxPreferencesPage.SB_COMMAND, findValue(file, "SB_COMMAND"));
-////		store.setDefault(ScratchboxPreferencesPage.SB_TARGET_LIST_CMD, findValue(file, "SB_TARGET_LIST_CMD"));
-////		store.setDefault(ScratchboxPreferencesPage.SB_TARGET_SELECT_CMD, findValue(file, "SB_TARGET_SELECT_CMD"));
-////		store.setDefault(XPreferencePage.SB_DISPLAY_IP, findValue(file, "SB_DISPLAY_IP"));
-////		store.setDefault(XPreferencePage.SB_DISPLAY_SERVER, findValue(file, "SB_DISPLAY_SERVER"));
-////		store.setDefault(XPreferencePage.SB_DISPLAY_VIEWER, findValue(file, "SB_DISPLAY_VIEWER"));
-////		store.setDefault(ScratchboxPreferencesPage.SB_GDB_SERVER, findValue(file, "SB_GDB_SERVER"));
-////		store.setDefault(XPreferencePage.SB_DISPLAY_SERVER_COMMAND, findValue(file, "SB_DISPLAY_SERVER_COMMAND"));
-//	}
-	
-	/**
-	 * Method find param text from param file and returns string
-	 * that include all after =-mark on that line. If text or =-mark
-	 * doesn't find return an empty string.
-	 * 
-	 * @param file
-	 * @param text
-	 * @return
-	 */
-	private static String findValue(String file, String text) {
-		// find param tex from file
-		int value = file.indexOf(text);
-		// and next line feed after value
-		int value2 = file.indexOf("\n", value);
-		// if does not find return an empty string
-		if(value == -1 || value2 == -1) {
-			return new String("");
-		}
-		String temp = file.substring(value, value2);
-		// check if =-mark exist
-		if(temp.indexOf("=") == -1) {
-			return new String("");
-		}
 		
-		return temp.substring(temp.indexOf("=") + 1);		
-	}
-
 	public void init(IWorkbench workbench) {
 		// Nothing to do
 	}
@@ -289,81 +199,8 @@
 					fireStateChanged(IS_VALID, true, false);
 			}
 		}
-	}
+	}	
 	
-	/**
-	 * 
-	 * @author kosola
-	 *
-	 * Class extends ComboFielEditor and loads default preferences from
-	 * file to preferencestore in doStore() method.
-	 */
-	private class OwnComboFieldEditor extends ComboFieldEditor {
-
-		/**
-		 * @param name
-		 * @param labelText
-		 * @param entryNamesAndValues
-		 * @param parent
-		 */
-		public OwnComboFieldEditor(String name, String labelText, String[][] entryNamesAndValues, Composite parent) {
-			super(name, labelText, entryNamesAndValues, parent);
-		}
-		/**
-		 * @see FieldEditor#doStore()
-		 */
-		protected void doStore() {
-			if (fValue == null) {
-				getPreferenceStore().setToDefault(getPreferenceName());
-				return;
-			}
-
-			getPreferenceStore().setValue(getPreferenceName(), fValue);
-		
-			// Object preferences which does not die if Eclipse is restarted
-			Preferences prefs = Preferences.userNodeForPackage(ScratchboxPreferencesPage.class);
-			// save default filenumber
-			prefs.put("filenumber", fValue);
-			
-			// load default preferences from file to preferencestore
-			//storeDefaultPrefsFromFile();
-		}
-		/* (non-Javadoc)
-		 * @see org.eclipse.jface.preference.FieldEditor#fireValueChanged(String, Object, Object)
-		 */
-		protected void fireValueChanged( String property, Object oldValue, Object newValue )
-		{
-			super.fireValueChanged( property, oldValue, newValue );
-			// save changes
-			doStore();
-			// add defaults to view
-			performDefaults();
-		}
-	}
-	
-	
-	
-	
-	
-	
-//	public ScratchboxPreferencesPage() {
-//		super(GRID);
-//		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
-//		setDescription("General Syntaxes for Scratchbox (TODO)");
-//	}
-
-//	@Override
-//	protected void createFieldEditors() {
-//		// TODO Auto-generated method stub
-//		
-//	}
-
-//	public void init(IWorkbench workbench) {
-//		// TODO Auto-generated method stub
-//		
-//	}
-
-	
 }
 
 



More information about the Esbox-commits mailing list