[Esbox-commits] r34 - in trunk/org.indt.esbox.ui: . src/org/indt/esbox/ui/preferences

pauloromulo at garage.maemo.org pauloromulo at garage.maemo.org
Tue Oct 2 01:49:35 EEST 2007


Author: pauloromulo
Date: 2007-10-02 01:49:35 +0300 (Tue, 02 Oct 2007)
New Revision: 34

Added:
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxTargetPreferencesPage.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/StringFieldEditorWithListener.java
Modified:
   trunk/org.indt.esbox.ui/plugin.xml
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java
   trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java
Log:
The preferences page front-end has been created. Based on Laika and old ESBox implementations. Some errors are occurring yet. 

Modified: trunk/org.indt.esbox.ui/plugin.xml
===================================================================
--- trunk/org.indt.esbox.ui/plugin.xml	2007-10-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/plugin.xml	2007-10-01 22:49:35 UTC (rev 34)
@@ -123,5 +123,31 @@
          </action>
       </actionSet>
    </extension>
+      <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            name="Scratchbox Preferences"
+            class="org.indt.esbox.ui.preferences.ScratchboxPreferencesPage"
+            id="sbpreferencepage">
+      </page>
+      <page
+            name="Target"
+            category="sbpreferencepage"
+            class="org.indt.esbox.ui.preferences.ESBoxTargetPreferencesPage"
+            id="sbpreferencepage.targets">
+      </page>   
+      <page
+            name="X Server"
+            category="sbpreferencepage"
+            class="org.indt.esbox.ui.preferences.ESBoxXServerPreferencePage"
+            id="sbpreferencepage.xserver">
+      </page>   
+      <page
+            name="Gazpacho"
+            category="sbpreferencepage"
+            class="org.indt.esbox.ui.preferences.ESBoxGazpachoPreferencePage"
+            id="sbpreferencepage.gazpacho">
+      </page>      
+   </extension>
 
 </plugin>

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-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxGazpachoPreferencePage.java	2007-10-01 22:49:35 UTC (rev 34)
@@ -35,8 +35,12 @@
 
 	public ESBoxGazpachoPreferencePage() {
 		super(GRID);
+		try{		
 		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
-		setDescription("Preferences for Running Glade User Interface Editor:");		
+		setDescription("Preferences for Running Glade User Interface Editor:");	
+		}catch (Throwable t) {
+			t.printStackTrace();
+		}
 	}
 
 	/**
@@ -101,6 +105,7 @@
 	 * editor knows how to save and restore itself.
 	 */
 	public void createFieldEditors() {
+		try{
 		oParent = getFieldEditorParent();
 		addField(new StringFieldEditor(GAZPACHO_COMMAND,
 				"The command to start the Gazpacho:",
@@ -126,7 +131,9 @@
 	
 		addField(feUseXhostCmd);
 		addField(feXhostCmd);
-		
+		}catch (Throwable t) {
+			t.printStackTrace();
+		}
 	}
 
 	public void init(IWorkbench workbench) {

Added: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxTargetPreferencesPage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxTargetPreferencesPage.java	2007-10-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxTargetPreferencesPage.java	2007-10-01 22:49:35 UTC (rev 34)
@@ -0,0 +1,351 @@
+package org.indt.esbox.ui.preferences;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.cdt.internal.ui.util.PixelConverter;
+import org.eclipse.cdt.internal.ui.util.SWTUtil;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.indt.esbox.core.CoreActivator;
+
+
+public class ESBoxTargetPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage{
+
+	protected Table table;
+	
+	protected TableColumn column;
+	
+	protected Button buttonNew;
+		
+	protected Button buttonRemove;
+	
+	/**
+	 * Constructs a new TargetPreferencePage.
+	 */
+	public ESBoxTargetPreferencesPage() {
+		setTitle("Scratchbox Targets");
+		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
+	}
+	
+	/*
+	 *  (non-Javadoc)
+	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+	 */
+	protected Control createContents(final Composite parent) {		
+		final String END_OF_LINE = System.getProperty("line.separator"); //$NON-NLS-1$
+		Composite labelPane = new Composite(parent, SWT.NONE);
+		labelPane.setLayout(new GridLayout());
+		labelPane.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		
+		Label information = new Label(labelPane, SWT.NONE);
+		information
+		.setText("Add, remove or edit targets definition" + END_OF_LINE + "The checked target will be used by default to cross-compile your application."); //$NON-NLS-1$ //$NON-NLS-2$
+		Label separator = new Label(labelPane, SWT.HORIZONTAL);
+		Label label = new Label(labelPane, SWT.NONE);
+		label.setText("Targets");
+		
+		Composite control = new Composite(parent, SWT.NONE);
+		GridLayout controlLayout = new GridLayout(2, false);
+		
+		controlLayout.marginHeight = 0;
+		controlLayout.marginWidth = 0;
+		
+		control.setLayout(controlLayout);
+		control.setLayoutData(new GridData(GridData.FILL_BOTH
+				| GridData.GRAB_VERTICAL));
+		
+		// Create the table viewer for file associations
+		
+		Composite tablePane = new Composite(control, SWT.NONE);
+		GridLayout tablePaneLayout = new GridLayout();
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+		
+		tablePaneLayout.marginHeight = 0;
+		tablePaneLayout.marginWidth = 0;
+		
+		tablePane.setLayout(tablePaneLayout);
+		tablePane.setLayoutData(gridData);
+		
+		table = new Table(tablePane, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.CHECK );
+		
+		TableLayout tblLayout = new TableLayout();
+		gridData = new GridData(GridData.FILL_BOTH);
+		gridData.grabExcessHorizontalSpace = true;
+		gridData.grabExcessVerticalSpace = true;
+		gridData.heightHint = SWTUtil.getTableHeightHint(table, 8);
+		gridData.widthHint = new PixelConverter(parent)
+		.convertWidthInCharsToPixels(60);
+				
+		table.setLayout(tblLayout);
+		table.setLayoutData(gridData);
+		table.setHeaderVisible(false);
+		table.setLinesVisible(true);		
+		//adds a selection listener. This listener guarantees that just one item is checked (and also selected).
+		table.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {			
+				TableItem item = table.getSelection()[0];
+				item.setChecked(true);
+				Preferences preferences = CoreActivator.getDefault().getPluginPreferences();				
+				//the target HOST cant be removed!!
+				if(item.getText().trim().equals("target"))//preferences.getDefaultString(ESboxPreferenceConstants.SBOX_TARGET)))
+					buttonRemove.setEnabled(false);
+				else
+					buttonRemove.setEnabled(true);
+				TableItem[] tableItems = table.getItems();
+				for (int i = 0; i < tableItems.length; i++) {
+					if( !item.equals(tableItems[i]) )
+						tableItems[i].setChecked(false);
+				}
+			}
+		});		
+		
+		column = new TableColumn(table,SWT.LEFT);
+		
+		// Create the button pane
+		
+		Composite buttonPane = new Composite(control, SWT.NONE);
+		GridLayout buttonPaneLayout = new GridLayout();
+		
+		buttonPaneLayout.marginHeight = 0;
+		buttonPaneLayout.marginWidth = 0;
+		
+		buttonPane.setLayout(buttonPaneLayout);
+		buttonPane
+		.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+		
+		// New button		
+		buttonNew = new Button(buttonPane, SWT.PUSH);
+		buttonNew.setText("New");
+		
+		gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.widthHint = SWTUtil.getButtonWidthHint(buttonNew);
+		gridData.heightHint = SWTUtil.getButtonHeigthHint(buttonNew);
+		buttonNew.setLayoutData(gridData);
+		
+		buttonNew.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(Event e) {
+				//displayTargetWizard(parent);
+				System.out.println("TODO: handle events");
+			}
+		});
+		
+		// Remove button		
+		buttonRemove = new Button(buttonPane, SWT.PUSH);
+		buttonRemove.setText("Remove");
+		
+		gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.widthHint = SWTUtil.getButtonWidthHint(buttonRemove);
+		gridData.heightHint = SWTUtil.getButtonHeigthHint(buttonRemove);
+		buttonRemove.setLayoutData(gridData);
+		buttonRemove.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(Event e) {
+				//removeTarget();
+				System.out.println("TODO: handle events");
+			}
+		});
+		
+		initTable();
+		
+		return control;
+	}
+	
+	/*
+	 *  (non-Javadoc)
+	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+	 */
+	public void init(IWorkbench workbench) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	/**
+	 * Inicializes the content of the targets table. It gets all the
+	 * targets from a list provided by TargetManager.
+	 */
+	private void initTable() {
+		table.setRedraw(false);
+		List<String> targets = null;
+		try {
+			targets = getTargets();
+		} catch (Exception e) {			
+			//TODO
+			e.printStackTrace();
+		}
+		TableItem line = null;
+		//sorts the target list
+		Object[] targetsName = targets.toArray();		
+		Arrays.sort(targetsName);
+		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);
+		}		
+		column.pack();
+		table.setRedraw(true); //redraw the table so the modifications can be seen.
+		Preferences preferences = CoreActivator.getDefault().getPluginPreferences();
+		String targetName = "target";//preferences.getString(ESboxPreferenceConstants.SBOX_TARGET);
+		//set the checked value to the one stored at preference store.
+		setSelectedTarget(targetName);
+	}
+	
+	private List<String> getTargets() throws IOException {//ESboxCoreException {
+//		List<ITarget> targetsList = TargetManager.getInstance().getTargets();
+//		List<String> targetsName = new ArrayList<String>();
+//		for (ITarget target : targetsList) {
+//			targetsName.add(target.getName());
+//		}
+//		return targetsName;
+		return new ArrayList<String>();
+	}
+	
+	/**
+	 * Sets the selected target to the specified value.
+	 * @param targetName the target to be selected.
+	 */
+	private void setSelectedTarget(String targetName) {	
+		Preferences preferences = CoreActivator.getDefault().getPluginPreferences();
+		TableItem[] items = table.getItems();
+		for (int i = 0; i < items.length; i++) {
+			if(items[i].getText().equals(targetName)) {
+				items[i].setChecked(true);
+				table.setSelection(i);			
+				// do not allow HOST target be removed.
+				boolean enabled = ! targetName.trim().equals("target");//preferences.getDefaultString(ESboxPreferenceConstants.SBOX_TARGET));
+				buttonRemove.setEnabled(enabled);
+			} else {
+				items[i].setChecked(false);
+			}
+		}
+	}
+	
+	/**
+	 * Displays the target wizard, so that the user can create new targets.
+	 * @param composite the parent composite.
+	 */
+//	private void displayTargetWizard(Composite composite) {
+//		NewTargetWizard targetWizard = new NewTargetWizard();		
+//		WizardDialog dlg = new WizardDialog(composite.getShell(),
+//				targetWizard);
+//		dlg.open();
+//	}
+		
+	/**
+	 * Remove the target selected. After removing the target, the default target is checked (and selected).
+	 */
+//	private void removeTarget() {		
+//		TableItem item = table.getSelection()[0];
+//		String targetRemoved = item.getText();
+//		try {
+//			TargetManager.getInstance().removeTarget(targetRemoved);			
+//		} catch (Exception e) {
+//			//TODO
+//			e.printStackTrace();
+//		}			
+//	}	
+		
+	/*
+	 *  (non-Javadoc)
+	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
+	 */
+//	public boolean performOk() {		
+//		Preferences preferences = CoreActivator.getDefault().getPluginPreferences();
+//		String target = getSelectValue();
+//		if(target == null)
+//			target = preferences.getDefaultString(ESboxPreferenceConstants.SBOX_TARGET);
+//		try {
+//			TargetManager.getInstance().selectTarget(target);
+//		} catch (Exception e) {
+//			//TODO
+//			e.printStackTrace();
+//		}		
+//		getPreferenceStore().setValue(ESboxPreferenceConstants.SBOX_TARGET,getSelectValue());
+//		return super.performOk();
+//	}
+	
+//	@Override
+//	protected void performDefaults() {
+//		Preferences preferences = CoreActivator.getDefault().getPluginPreferences();				
+//		setSelectedTarget(preferences.getDefaultString(ESboxPreferenceConstants.SBOX_TARGET));
+//		super.performDefaults();
+//	}
+		
+	/**
+	 * Returns the selected value of the table.
+	 * @return the selected value of the table.
+	 */
+//	public String getSelectValue() {
+//		TableItem item[] = table.getSelection();
+//		if(item.length > 0)
+//			return item[0].getText();
+//		else
+//			return null;
+//	}
+	
+	/*
+	 *  (non-Javadoc)
+	 * @see br.edu.ufcg.dee.omapsdk.properties.target.wizard.TargetWizardListener#targetAdded()
+	 */
+//	public void targetAdded() {		
+//		table.removeAll();		
+//		initTable();
+//		refreshTargetView();
+//	}
+
+	/*
+	 *  (non-Javadoc)
+	 * @see dee.nokia.esbox.plugin.ui.internal.wizard.targets.TargetListener#targetRemoved()
+	 */
+//	public void targetRemoved() {
+//		try {
+//			table.remove(table.getSelectionIndex());		
+//		} catch (Exception e){
+//			//System.out.println("Preference page not open, can't get table");
+//		}
+//		
+//		try {
+//			Preferences preferences = CoreActivator.getDefault().getPluginPreferences();
+//			setSelectedTarget(preferences.getDefaultString(ESboxPreferenceConstants.SBOX_TARGET));
+//		
+//		} catch (Exception e){ 
+//			//System.out.println("Preference page not open, can't get table, setting defaut");
+//		}
+//		
+//		refreshTargetView();
+//	}
+	
+//	private void refreshTargetView(){
+//		try{
+//			TreeViewer viewer = (TreeViewer)TargetsView.getViewer();
+//			viewer.setContentProvider(new TargetsViewContentProvider(TargetsView.getTargetsView()));
+//			viewer.refresh();
+//		}
+//		catch (Exception e) {
+//			//System.out.println("View Target not open, can't refresh it");
+//		}
+//	}
+
+}

Added: 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-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESBoxXServerPreferencePage.java	2007-10-01 22:49:35 UTC (rev 34)
@@ -0,0 +1,191 @@
+package org.indt.esbox.ui.preferences;
+
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferencePage;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.indt.esbox.core.CoreActivator;
+
+public class ESBoxXServerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IPreferencePage {
+	
+	public static final String SB_DISPLAY_IP = "sbDisplayIpPreference"; //$NON-NLS-1$
+
+	public static final String SB_DISPLAY_SERVER = "sbDisplayServerPreference"; //$NON-NLS-1$
+
+	public static final String SB_DISPLAY_VIEWER = "sbDisplayViewerPreference"; //$NON-NLS-1$
+	
+	public static final String SB_DISPLAY_SERVER_COMMAND = "sbDisplayServerCommandPreference"; //$NON-NLS-1$
+	
+	public static final String SB_X_VIEWER_START_CONTENT = "sbXViewerStartContent"; //$NON-NLS-1$
+	
+	protected Text textview = null;
+	
+	protected Label scriptlabel = null;
+	
+	protected StringFieldEditorWithListener xServerSyntax = null;
+
+	private boolean textHasChanged;
+	
+	public ESBoxXServerPreferencePage() {
+		super(GRID);
+		System.out.println("XPreferencePage");
+		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
+		setDescription("Preferences for Running Graphical Programs inside Scratchbox:");
+		textHasChanged = false;
+
+	}
+
+	/**
+	 * 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() {
+//		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
+		xServerSyntax.setNotifyForward(true);
+		xServerSyntax.setXpage(this);
+		xServerSyntax.setFocus();
+		addField(xServerSyntax);
+
+		addField(new BooleanFieldEditor(SB_DISPLAY_SERVER_COMMAND,"Run X-server command inside Scratchbox",getFieldEditorParent()));
+		addField(new StringFieldEditor(SB_DISPLAY_VIEWER,
+				"The syntax for starting viewer:", getFieldEditorParent()));
+		addField(new StringFieldEditor(SB_DISPLAY_IP,
+				"The syntax exporting display's IP and number:",
+				getFieldEditorParent()));
+	}
+	
+
+	/**
+	 * Creates contents at the bottom of the pages. If syntax for starting X is not
+	 * script contents at the bottom of the pages are hided
+	 */
+	public Control createContents(Composite parent) {		
+		Control ret = super.createContents(parent);
+		//here we create content of script if it exists, so it's easy to change
+		String syntaxforstartingX = CoreActivator.getDefault().getPreferenceStore().getString(SB_DISPLAY_SERVER);
+		scriptlabel = new Label(parent, SWT.NONE);
+  		scriptlabel.setText(syntaxforstartingX);
+		scriptlabel.setLayoutData(new GridData(GridData.BEGINNING));
+		
+		textview = new Text(parent,SWT.BORDER | SWT.MULTI |SWT.WRAP);
+	  	//textview.setText(LoadScriptText(syntaxforstartingX));
+	  	//listener for textfield
+	  	textview.addKeyListener(new KeyListener(){
+
+			public void keyPressed(KeyEvent e) {
+				HandletextfieldKeyPressed(e);
+			}
+
+			public void keyReleased(KeyEvent e) {				
+			}});
+	  	textview.setLayoutData(new GridData(GridData.FILL_BOTH));
+	  	hideScriptextfield(syntaxforstartingX);
+	  	return ret;
+	}
+	/**
+	 * Handles the keypressing
+	 * @param e
+	 */
+	protected void HandletextfieldKeyPressed(KeyEvent e) {
+		textHasChanged  = true;		
+	}
+
+	/**
+	 * @param filename
+	 * loads script files text from script file from xServerSyntax
+	 * @return string of script
+	 */
+//	private String LoadScriptText(String filename) {
+//		if (!filename.endsWith(".sh")){
+//			return "";
+//		} else {
+//			//case script starts with dot replace filename with string without .
+//			if (filename.indexOf(".") == 0){
+//				filename = filename.substring(1);
+//			}
+//			//String filecontent = SbCoreHelper.readFileToString(filename);
+//			//System.out.println("content of: " + System.getProperty("user.home") + filename);
+//			return filecontent;
+//		}
+//
+//		
+//	}
+	
+	public void hideScriptextfield(String syntaxforstartingX){
+		if (!syntaxforstartingX.endsWith(".sh")){
+	  		scriptlabel.setVisible(false);
+	  		textview.setVisible(false);
+	  	} else {
+	  		scriptlabel.setVisible(true);
+	  		textview.setVisible(true);
+	  		scriptlabel.setText(syntaxforstartingX);
+	  		//textview.setText(LoadScriptText(syntaxforstartingX));
+	  	}
+	}
+
+	public void init(IWorkbench workbench) {
+		// 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-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ScratchboxPreferencesPage.java	2007-10-01 22:49:35 UTC (rev 34)
@@ -12,31 +12,357 @@
 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;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 import org.indt.esbox.core.CoreActivator;
 
+
 public class ScratchboxPreferencesPage extends FieldEditorPreferencePage implements
 	IWorkbenchPreferencePage {
 
+	public static final String SB_DEFAULT_FILE = "sbDefaultFilePreference"; //$NON-NLS-1$
+	
+	public static final String SB_ROOT = "sbPathPreference"; //$NON-NLS-1$
+
+	public static final String SB_COMMAND = "sbCommandPreference"; //$NON-NLS-1$
+
+	public static final String SB_GDB_SERVER = "sbGDBServerPreference"; //$NON-NLS-1$
+
+	public static final String SB_TARGET_SELECT_CMD = "sbTargetSelectPreference"; //$NON-NLS-1$
+
+	public static final String SB_TARGET_LIST_CMD = "sbTargetListPreference"; //$NON-NLS-1$
+
+	private static String[][] sbPreferenceFiles = { {"name1", "value1"}, {"name2", "value2"} };
+	
 	public ScratchboxPreferencesPage() {
 		super(GRID);
 		setPreferenceStore(CoreActivator.getDefault().getPreferenceStore());
-		setDescription("General Syntaxes for Scratchbox (TODO)");
+		setDescription("General Syntaxes for Scratchbox:");
+		// find all preference files
+		//getSbPreferenceFiles();
+		//storeDefaultPrefsFromFile();
 	}
 
-	@Override
-	protected void createFieldEditors() {
-		// TODO Auto-generated method stub
+
+	/**
+	 * 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{
+		OwnComboFieldEditor comboEditor= new OwnComboFieldEditor(
+			SB_DEFAULT_FILE,
+			"Version of default preference values:",
+			sbPreferenceFiles,
+			getFieldEditorParent());
+		addField(comboEditor);
 		
+		addField(new DirectoryFieldEditor(SB_ROOT, "Sandbox Root Directory:",
+				getFieldEditorParent()));
+
+		addField(new CommandFieldEditor(SB_COMMAND,
+				"Invoking Scratchbox commands:",
+				getFieldEditorParent()));
+
+		addField(new StringFieldEditor(SB_TARGET_LIST_CMD,
+				"Listing build targets:", getFieldEditorParent()));
+		addField(new TargetSelectionEditor(SB_TARGET_SELECT_CMD,
+				"The syntax for choosing a build target:",
+				getFieldEditorParent()));
+		addField(new GDBServerSelectionEditor(SB_GDB_SERVER,
+				"Starting GDB server inside Scratchbox:",
+				getFieldEditorParent()));
+		}catch(Throwable t){
+			t.printStackTrace();
+		}
 	}
 
+	/**
+	 * 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) {
-		// TODO Auto-generated method stub
+		// Nothing to do
+	}
+
+	/**
+	 * @author mattisil, kosola
+	 * 
+	 * A class to check and accept entries for the syntax to invoke commands
+	 * inside the Scratchbox environment.
+	 */
+	private class CommandFieldEditor extends StringFieldEditor {
+		private boolean valid = true;
+
+		public CommandFieldEditor(String name, String title, Composite parent) {
+			super(name, title, parent);
+		}
+
+		public boolean isValid() {
+			String value = getStringValue();
+			if (value.indexOf("${command}") == -1) {
+				valid = false;
+				return valid;
+			}
+			if (value.indexOf("${directory}") == -1) {
+				valid = false;
+				return valid;
+			}
+			if (value.indexOf("${args}") == -1) {
+				valid = false;
+				return valid;
+			}
+			valid = true;
+			return valid;
+		}
+
+		protected void refreshValidState() {
+			boolean wasValid = valid;
+			if (isValid()) {
+				if (!wasValid)
+					fireStateChanged(IS_VALID, false, true);
+			} else {
+				if (wasValid)
+					fireStateChanged(IS_VALID, true, false);
+			}
+		}
+
+	}
+
+	/**
+	 * 
+	 * @author mattisil, kosola
+	 *
+	 * Class handel that in target field is all required commands
+	 */
+	private class TargetSelectionEditor extends StringFieldEditor {
+
+		private boolean valid = true;
+
+		public TargetSelectionEditor(String name, String title, Composite parent) {
+			super(name, title, parent);
+		}
+
+		public boolean isValid() {
+			String value = getStringValue();
+			if (value.indexOf("${target}") == -1) {
+				valid = false;
+				return valid;
+			}
+
+			valid = true;
+			return valid;
+		}
+
+		protected void refreshValidState() {
+			boolean wasValid = valid;
+			if (isValid()) {
+				if (!wasValid)
+					fireStateChanged(IS_VALID, false, true);
+			} else {
+				if (wasValid)
+					fireStateChanged(IS_VALID, true, false);
+			}
+		}
+	}
+	
+
+	/**
+	 * 
+	 * @author kosola
+	 *
+	 * Class handel that in GDB server field are all required commands
+	 */ 
+	private class GDBServerSelectionEditor extends StringFieldEditor {
+
+		private boolean valid = true;
+
+		public GDBServerSelectionEditor(String name, String title,
+				Composite parent) {
+			super(name, title, parent);
+		}
+
+		public boolean isValid() {
+			String value = getStringValue();
+			if (value.length() == 0) {
+				valid = true;
+				return valid;
+
+			}
+			if (value.indexOf("${binary}") == -1) {
+				valid = false;
+				return valid;
+			}
+
+			valid = true;
+			return valid;
+		}
+
+		protected void refreshValidState() {
+			boolean wasValid = valid;
+			if (isValid()) {
+				if (!wasValid)
+					fireStateChanged(IS_VALID, false, true);
+			} else {
+				if (wasValid)
+					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
+//		
+//	}
+
 	
 }
 

Added: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/StringFieldEditorWithListener.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/StringFieldEditorWithListener.java	2007-10-01 13:15:49 UTC (rev 33)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/StringFieldEditorWithListener.java	2007-10-01 22:49:35 UTC (rev 34)
@@ -0,0 +1,45 @@
+package org.indt.esbox.ui.preferences;
+
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.widgets.Composite;
+
+public class StringFieldEditorWithListener extends StringFieldEditor{
+
+	private boolean notifyForward;
+	private ESBoxXServerPreferencePage xpage;
+	
+	public StringFieldEditorWithListener(String sb_display_server, String string, Composite fieldEditorParent) {
+		super(sb_display_server,string,fieldEditorParent);
+		notifyForward = false;
+	}
+
+	@Override
+	protected void valueChanged() {
+		super.valueChanged();
+		
+		if (notifyForward){
+			xpage.hideScriptextfield(this.getStringValue());
+			System.out.println(this.getStringValue());
+		}
+		
+	}
+
+	public boolean isNotifyForward() {
+		return notifyForward;
+	}
+
+	public void setNotifyForward(boolean notifyForward) {
+		this.notifyForward = notifyForward;
+	}
+
+	public ESBoxXServerPreferencePage getXpage() {
+		return xpage;
+	}
+
+	public void setXpage(ESBoxXServerPreferencePage xpage) {
+		this.xpage = xpage;
+	}
+	
+	
+
+}



More information about the Esbox-commits mailing list