[ooo-build-commit] ooeclipse: Branch 'master' - 2 commits

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Mon Dec 13 13:58:14 PST 2010


 core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPage.java               |  123 +++----
 core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageController.java     |  168 ++++++++++
 core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageControllerTest.java |  133 +++++++
 java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java                   |    7 
 4 files changed, 361 insertions(+), 70 deletions(-)

New commits:
commit 1fcac94289f887be09b5b1e5ee541efe03f4ca9f
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Mon Dec 13 22:57:44 2010 +0100

    [java] tiny code optimization in the export part

diff --git a/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java
index 1bcee19..7b34469 100644
--- a/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java
+++ b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java
@@ -34,8 +34,6 @@ public class JavaExportPageControl {
     private boolean mSaveAntScript;
     private String mSavePath;
     
-    private boolean mSavePathEnabled;
-    
     /**
      * Default constructor.
      */
@@ -49,9 +47,6 @@ public class JavaExportPageControl {
      */
     public void setSaveAntScript( boolean pSave ) {
         mSaveAntScript = pSave;
-        
-        // Don't activate the path field unless the save is selected
-        mSavePathEnabled = pSave;
     }
     
     /**
@@ -79,6 +74,6 @@ public class JavaExportPageControl {
      * @return whether the save path field is enabled
      */
     public boolean isSavePathEnabled( ) {
-        return mSavePathEnabled;
+        return mSaveAntScript;
     }
 }
commit 4f0e3c36c0d5e8334a8184b30df96274379fa1e9
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Mon Dec 13 22:57:24 2010 +0100

    [core] manifest export page is now using a testable controller

diff --git a/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPage.java b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPage.java
index 5440304..3f64c34 100644
--- a/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPage.java
+++ b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPage.java
@@ -43,6 +43,8 @@ import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
@@ -91,6 +93,8 @@ public class ManifestExportPage extends WizardPage {
     private Label mLoadRowLbl;
     private Text mLoadRowTxt;
     private Button mLoadRowBtn;
+    
+    private ManifestExportPageController mController;
 
     /**
      * Constructor.
@@ -100,6 +104,9 @@ public class ManifestExportPage extends WizardPage {
      */
     public ManifestExportPage( String pPageName, IUnoidlProject pProject ) {
         super(pPageName);
+        
+        mController = new ManifestExportPageController();
+        
         setTitle( Messages.getString("ManifestExportPage.Title") ); //$NON-NLS-1$
         setDescription( Messages.getString("ManifestExportPage.Description") ); //$NON-NLS-1$
         
@@ -155,29 +162,12 @@ public class ManifestExportPage extends WizardPage {
      *      existing value
      */
     public void setManifestPath(IFile pFile) {
-        // FIXME Ugly hack due to some bug in the GTK buttons events
-        if ( pFile != null && !pFile.exists() ) {
-            mSaveManifestBtn.setSelection( true );
-            mReuseManifestBtn.setSelection( false );
-            mGenerateManifestBtn.setSelection( true );
-            mSaveRowTxt.setText( pFile.getFullPath().toString() );
-            setSaveRowEnabled( true );
-            setLoadRowEnabled( false );
-        } else if ( pFile != null && pFile.exists() ) {
-            mGenerateManifestBtn.setSelection( false );
-            mReuseManifestBtn.setSelection( true );
-            mSaveManifestBtn.setSelection( false );
-            mLoadRowTxt.setText( pFile.getFullPath().toString() );
-            setLoadRowEnabled( true );
-            setSaveRowEnabled( false );
-        } else {
-            mGenerateManifestBtn.setSelection( true );
-            mReuseManifestBtn.setSelection( false );
-            mSaveManifestBtn.setSelection( true );
-            mSaveRowTxt.setText( new String( ) );
-            setSaveRowEnabled( true );
-            setLoadRowEnabled( false );
-        }
+        
+        mController.setGenerateManifest( true );
+        mController.setSaveManifest( true );
+        mController.setSaveManifestPath( pFile.getFullPath().toString() );
+        
+        updateControls();
     }
     
     /**
@@ -199,33 +189,31 @@ public class ManifestExportPage extends WizardPage {
         reloadLanguagePart();
         
         // Load the default values
-        mGenerateManifestBtn.setSelection( true );
+        updateControls();
     }
 
     /**
-     * Enables the manifest save row.
-     * 
-     * @param pEnabled <code>true</code> to enable all the controls of the row
-     *      <code>false</code> otherwise.
-     */
-    private void setSaveRowEnabled( boolean pEnabled ) {
-        mSaveRowLbl.setEnabled( pEnabled );
-        mSaveRowTxt.setEnabled( pEnabled );
-        mSaveRowBtn.setEnabled( pEnabled );
-    }
-    
-    /**
-     * Enables the manifest load row.
-     * 
-     * @param pEnabled <code>true</code> to enable all the controls of the row
-     *      <code>false</code> otherwise.
+     * Update the controls state and values according to the controller.
      */
-    private void setLoadRowEnabled( boolean pEnabled ) {
-        mLoadRowLbl.setEnabled( pEnabled );
-        mLoadRowTxt.setEnabled( pEnabled );
-        mLoadRowBtn.setEnabled( pEnabled );
+    private void updateControls( ) {
+        mGenerateManifestBtn.setSelection( mController.getGenerateManifest() );
+        
+        mSaveManifestBtn.setSelection( mController.getSaveManifest() );
+        mSaveManifestBtn.setEnabled( mController.isSaveManifestEnabled() );
+        
+        mSaveRowTxt.setText( mController.getSaveManifestPath() );
+        mSaveRowLbl.setEnabled( mController.isSaveManifestPathEnabled() );
+        mSaveRowTxt.setEnabled( mController.isSaveManifestPathEnabled() );
+        mSaveRowBtn.setEnabled( mController.isSaveManifestPathEnabled() );
+        
+        mReuseManifestBtn.setSelection( !mController.getGenerateManifest() );
+        
+        mLoadRowTxt.setText( mController.getLoadManifestPath() );
+        mLoadRowLbl.setEnabled( mController.isLoadManifestPathEnabled() );
+        mLoadRowTxt.setEnabled( mController.isLoadManifestPathEnabled() );
+        mLoadRowBtn.setEnabled( mController.isLoadManifestPathEnabled() );
     }
-    
+
     /**
      * Create the manifest save/reuse options.
      * 
@@ -244,11 +232,8 @@ public class ManifestExportPage extends WizardPage {
         mGenerateManifestBtn.addSelectionListener( new SelectionListener() {
             
             public void widgetSelected(SelectionEvent pE) {
-                boolean selection = mGenerateManifestBtn.getSelection();
-                mSaveManifestBtn.setEnabled( selection );
-                
-                boolean saveSelection = mSaveManifestBtn.getSelection();
-                setSaveRowEnabled( selection && saveSelection );
+                mController.setGenerateManifest( mGenerateManifestBtn.getSelection() );
+                updateControls();
             }
             
             public void widgetDefaultSelected(SelectionEvent pE) {
@@ -271,8 +256,8 @@ public class ManifestExportPage extends WizardPage {
         mReuseManifestBtn.addSelectionListener( new SelectionListener() {
             
             public void widgetSelected(SelectionEvent pE) {
-                boolean enabled = mReuseManifestBtn.getSelection();
-                setLoadRowEnabled( enabled );
+                mController.setGenerateManifest( !mReuseManifestBtn.getSelection() );
+                updateControls();
             }
             
             public void widgetDefaultSelected(SelectionEvent pE) {
@@ -305,8 +290,8 @@ public class ManifestExportPage extends WizardPage {
         mSaveManifestBtn.addSelectionListener( new SelectionListener() {
             
             public void widgetSelected(SelectionEvent pE) {
-                boolean enabled = mSaveManifestBtn.getSelection();
-                setSaveRowEnabled( enabled );
+                mController.setSaveManifest( mSaveManifestBtn.getSelection() );
+                updateControls();
             }
             
             public void widgetDefaultSelected(SelectionEvent pE) {
@@ -320,6 +305,12 @@ public class ManifestExportPage extends WizardPage {
         
         mSaveRowTxt = new Text( pParent, SWT.SINGLE | SWT.BORDER );
         mSaveRowTxt.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        mSaveRowTxt.addModifyListener( new ModifyListener() {
+            
+            public void modifyText(ModifyEvent pE) {
+                mController.setSaveManifestPath( mSaveRowTxt.getText() );
+            }
+        });
         
         mSaveRowBtn = new Button( pParent, SWT.PUSH );
         mSaveRowBtn.setText( Messages.getString("ManifestExportPage.Browse") ); //$NON-NLS-1$
@@ -336,12 +327,11 @@ public class ManifestExportPage extends WizardPage {
                 dlg.setMessage( Messages.getString("ManifestExportPage.SaveDialogMessage") ); //$NON-NLS-1$
                 
                 if ( dlg.open() == Window.OK ) {
-                    mSaveRowTxt.setText( dlg.getResult().toString() );
+                    mController.setSaveManifestPath( dlg.getResult().toString() );
+                    updateControls();
                 }
             }
         });
-        
-        setSaveRowEnabled( false );
     }
     
     /**
@@ -356,6 +346,12 @@ public class ManifestExportPage extends WizardPage {
         
         mLoadRowTxt = new Text( pParent, SWT.SINGLE | SWT.BORDER );
         mLoadRowTxt.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        mLoadRowTxt.addModifyListener( new ModifyListener( ) {
+            
+            public void modifyText(ModifyEvent pE) {
+                mController.setLoadManifestPath( mLoadRowTxt.getText() );
+            }
+        });
         
         mLoadRowBtn = new Button( pParent, SWT.PUSH );
         mLoadRowBtn.setText( Messages.getString("ManifestExportPage.Browse") ); //$NON-NLS-1$
@@ -402,12 +398,11 @@ public class ManifestExportPage extends WizardPage {
                 if ( dlg.open() == Window.OK ) {
                     Object result = dlg.getFirstResult();
                     IFile file = ( IFile )result;
-                    mLoadRowTxt.setText( file.getFullPath().toString() );
+                    mController.setLoadManifestPath( file.getFullPath().toString() );
+                    updateControls();
                 }
             }
         });
-        
-        setLoadRowEnabled( false );
     }
     
     /**
@@ -438,8 +433,8 @@ public class ManifestExportPage extends WizardPage {
      */
     private IFile getReadManifestFile() {
         IFile file = null;
-        if ( mReuseManifestBtn.getSelection() ) {
-            IPath path = new Path( mLoadRowTxt.getText().trim() );
+        if ( !mController.getGenerateManifest() ) {
+            IPath path = new Path( mController.getLoadManifestPath().trim() );
             file = ResourcesPlugin.getWorkspace().getRoot().getFile( path );
         }
         
@@ -451,8 +446,8 @@ public class ManifestExportPage extends WizardPage {
      */
     private IFile getSaveManifestFile() {
         IFile file = null;
-        if ( mGenerateManifestBtn.getSelection() && mSaveManifestBtn.getSelection() ) {
-            IPath path = new Path( mSaveRowTxt.getText().trim() );
+        if ( mController.isSaveManifestPathEnabled() ) {
+            IPath path = new Path( mController.getSaveManifestPath().trim() );
             file = ResourcesPlugin.getWorkspace().getRoot().getFile( path );
         }
         return file;
diff --git a/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageController.java b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageController.java
new file mode 100644
index 0000000..440c8f7
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageController.java
@@ -0,0 +1,168 @@
+/*************************************************************************
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as 
+ * published by the Free Software Foundation, either version 3 of 
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * Copyright: 2010 by Cédric Bosdonnat
+ *
+ * All Rights Reserved.
+ * 
+ ************************************************************************/
+package org.openoffice.ide.eclipse.core.wizards.pages;
+
+/**
+ * Testable controller class for the Manifest export page, this class
+ * implements all the logic ruling the dialog controls.
+ * 
+ * @author Cédric Bosdonnat 
+ *
+ */
+public class ManifestExportPageController {
+
+    /** 
+     * Stores the state of the Generate / Use manifest option.
+     */
+    private boolean mGenerateManifest;
+    
+    /**
+     * Stores the state of the Save manifest check box.
+     */
+    private boolean mSaveManifest;
+    
+    /**
+     * Stores the workspace-relative path to store the manifest to.
+     */
+    private String mSaveManifestPath;
+    
+    /**
+     * Stores the workspace-relative path to read the manifest from.
+     */
+    private String mLoadManifestPath;
+    
+    /**
+     * Default constructor.
+     */
+    public ManifestExportPageController( ) {
+        setGenerateManifest( true );
+        setSaveManifest( false );
+        mSaveManifestPath = new String( );
+        mLoadManifestPath = new String( );
+    }
+    
+    /**
+     * Sets whether to use an existing manifest file or generate a new one (note that
+     * the generated manifest file may or may not be saved).
+     * 
+     * @param pGenerate <code>true</code> to generate a new manifest, <code>false</code>
+     *      to use it.
+     */
+    public void setGenerateManifest( boolean pGenerate ) {
+        mGenerateManifest = pGenerate;
+    }
+    
+    /**
+     * Setting this value has no effect unless the manifest is generated, but setting it to
+     * <code>true</code> will save the manifest to the path returned by {@link #getSaveManifestPath()}.
+     *   
+     * @param pSave <code>true</code> to save the manifest in the workspace,
+     *              <code>false</code> otherwise.
+     */
+    public void setSaveManifest( boolean pSave ) {
+        if ( isSaveManifestEnabled() ) {
+            mSaveManifest = pSave;
+        }
+    }
+    
+    /**
+     * Setting this value has no effect unless {@link #isSaveManifestPathEnabled()}
+     * returns <code>true</code>.
+     * 
+     * @param pPath the workspace-relative path to the manifest file to create.
+     */
+    public void setSaveManifestPath( String pPath ) {
+        if ( isSaveManifestPathEnabled() ) {
+            mSaveManifestPath = pPath;
+        }
+    }
+    
+    /**
+     * Setting this value has no effect unless {@link #isLoadManifestPathEnabled()}
+     * returns <code>true</code>.
+     * 
+     * @param pPath the workspace-relative path to the manifest file to load.
+     */
+    public void setLoadManifestPath( String pPath ) {
+        if ( isLoadManifestPathEnabled() ) {
+            mLoadManifestPath = pPath;
+        }
+    }
+    
+    /**
+     * @return <code>true</code> is the manifest has to be saved, <code>false</code> if it needs
+     *      to be loaded from a file in the workspace.
+     */
+    public boolean getGenerateManifest( ) {
+        return mGenerateManifest;
+    }
+    
+    /**
+     * Note that this value has no effect unless {@link #getGenerateManifest()} returns 
+     * <code>true</code>.
+     * 
+     * @return <code>true</code> is the manifest has to be saved, <code>false</code> otherwise.
+     */
+    public boolean getSaveManifest( ) {
+        return mSaveManifest;
+    }
+    
+    /**
+     * Note that this value has no effect unless {@link #getSaveManifest()} returns <code>true</code>.
+     * 
+     * @return the workspace-relative path to store the manifest to.
+     */
+    public String getSaveManifestPath( ) {
+        return mSaveManifestPath;
+    }
+    
+    /**
+     * Note that this value has no effect unless {@link #getGenerateManifest()} 
+     * returns <code>false</code>.
+     * 
+     * @return the workspace-relative path of the manifest file to load.
+     */
+    public String getLoadManifestPath( ) {
+        return mLoadManifestPath;
+    }
+    
+    /**
+     * @return the state of the save manifest check box.
+     */
+    public boolean isSaveManifestEnabled( ) {
+        return mGenerateManifest;
+    }
+    
+    /**
+     * @return the state of the save path row.
+     */
+    public boolean isSaveManifestPathEnabled( ) {
+        return mGenerateManifest && mSaveManifest;
+    }
+    
+    /**
+     * @return the state of the load path row.
+     */
+    public boolean isLoadManifestPathEnabled( ) {
+        return !mGenerateManifest;
+    }
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageControllerTest.java b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageControllerTest.java
new file mode 100644
index 0000000..6adbc75
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/wizards/pages/ManifestExportPageControllerTest.java
@@ -0,0 +1,133 @@
+/*************************************************************************
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as 
+ * published by the Free Software Foundation, either version 3 of 
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ * 
+ * Copyright: 2010 by Cédric Bosdonnat
+ *
+ * All Rights Reserved.
+ * 
+ ************************************************************************/
+package org.openoffice.ide.eclipse.core.wizards.pages;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for the Manifest export page controller, these tests are
+ * testing the UI behaviour.
+ * 
+ * @author Cédric Bosdonnat
+ *
+ */
+public class ManifestExportPageControllerTest {
+
+    private static final String PATH_VALUE = "value";
+    ManifestExportPageController mTested;
+    
+    /**
+     * Create the controller to test.
+     */
+    @Before
+    public void setup( ) {
+        mTested = new ManifestExportPageController();
+    }
+    
+    /**
+     * Test a selection of the generate manifest check box.
+     */
+    @Test
+    public void testSetGenerateManifest() {
+        mTested.setGenerateManifest( true );
+        assertFalse( "Load path shouldn't be enabled", mTested.isLoadManifestPathEnabled() );
+        assertTrue( "Save manifest box should be enabled", mTested.isSaveManifestEnabled() );
+    }
+    
+    /**
+     * Test a selection of the reuse manifest check box.
+     */
+    @Test
+    public void testSetReuseManifest() {
+        mTested.setGenerateManifest( false );
+        assertTrue( "Load path should be enabled", mTested.isLoadManifestPathEnabled() );
+        assertFalse( "Save manifest box shouldn't be enabled", mTested.isSaveManifestEnabled() );
+    }
+
+    /**
+     * Test when the save manifest check box is selected. 
+     */
+    @Test
+    public void testSetSaveManifest() {
+        mTested.setGenerateManifest( true );
+        mTested.setSaveManifest( true );
+        assertTrue( "save manifest path should be enabled", mTested.isSaveManifestPathEnabled() );
+    }
+    
+    /**
+     * Test when the save manifest check box is unselected.
+     */
+    @Test
+    public void testSetNoSaveManifest() {
+        mTested.setGenerateManifest( true );
+        mTested.setSaveManifest( false );
+        assertFalse( "save manifest path shouldn't be enabled", mTested.isSaveManifestPathEnabled() );
+    }
+
+    /**
+     * Test setting the manifest save path when the field is enabled.
+     */
+    @Test
+    public void testSetSaveManifestPath() {
+        mTested.setGenerateManifest( true );
+        mTested.setSaveManifest( true );
+        
+        mTested.setSaveManifestPath( PATH_VALUE );
+        assertEquals( "the save path should have been set", PATH_VALUE, mTested.getSaveManifestPath() );
+    }
+    
+    /**
+     * Test setting the manifest save path when the field is disabled.
+     */
+    @Test
+    public void testSetManifestPathDisabled() {
+        mTested.setGenerateManifest( false );
+        
+        mTested.setSaveManifestPath( PATH_VALUE );
+        assertNotSame( "the save path shouldn't have been set", PATH_VALUE, mTested.getSaveManifestPath() );        
+    }
+
+    /**
+     * Test setting the manifest load path when the field is enabled.
+     */
+    @Test
+    public void testSetLoadManifestPathEnabled() {
+        mTested.setGenerateManifest( false );
+        
+        mTested.setLoadManifestPath( PATH_VALUE );
+        assertEquals( "the load path should have been set", PATH_VALUE, mTested.getLoadManifestPath() );
+    }
+    
+    /**
+     * Test setting the manifest load path when the field is disabled.
+     */
+    @Test
+    public void testSetLoadManifestPathDisabled() {
+        mTested.setGenerateManifest( true );
+        
+        mTested.setLoadManifestPath( PATH_VALUE );
+        assertNotSame( "the load path shouldn't have been set", PATH_VALUE, mTested.getLoadManifestPath() );
+    }
+}


More information about the ooo-build-commit mailing list