summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2010-12-12 23:45:22 +0100
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2010-12-12 23:45:22 +0100
commitdc18d9ec13a0d2ea4c52255b4c7daef999ff1cad (patch)
treebb8764e9503580983454d8f5611a9a7217779e5f
parentadad909e9a30f984e42ef8cb530cd2ff134c9908 (diff)
[java] Refactored the export page part to use a testable controller
-rw-r--r--java/.classpath1
-rw-r--r--java/build.xml2
-rw-r--r--java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java84
-rw-r--r--java/source/org/openoffice/ide/eclipse/java/export/JavaExportPart.java43
-rw-r--r--java/source/org/openoffice/ide/eclipse/java/test/JavaExportPageControlTest.java64
5 files changed, 176 insertions, 18 deletions
diff --git a/java/.classpath b/java/.classpath
index d154f35..d6914fe 100644
--- a/java/.classpath
+++ b/java/.classpath
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" path="source"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/java/build.xml b/java/build.xml
index 5d666f0..b591473 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -90,7 +90,7 @@
target="1.5" source="1.5"
debug="${debug}"
classpathref="java.dependencies.path"
- excludes="**/unittests/**"/>
+ excludes="**/*Test.*"/>
</target>
<target name="java.plugin" depends="java.version, java.compile" unless="java.nobuild">
diff --git a/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java
new file mode 100644
index 0000000..1bcee19
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPageControl.java
@@ -0,0 +1,84 @@
+/*************************************************************************
+ *
+ * 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.java.export;
+
+/**
+ * Controller object for the fields of the {@link JavaExportPart} view.
+ *
+ * @author Cédric Bosdonnat
+ *
+ */
+public class JavaExportPageControl {
+
+ public static final String DEFAULT_ANT_FILENAME = "build.xml"; //$NON-NLS-1$
+
+ private boolean mSaveAntScript;
+ private String mSavePath;
+
+ private boolean mSavePathEnabled;
+
+ /**
+ * Default constructor.
+ */
+ public JavaExportPageControl() {
+ setSaveAntScript( false );
+ setSavePath( DEFAULT_ANT_FILENAME );
+ }
+
+ /**
+ * @param pSave the state of the save ant script box.
+ */
+ public void setSaveAntScript( boolean pSave ) {
+ mSaveAntScript = pSave;
+
+ // Don't activate the path field unless the save is selected
+ mSavePathEnabled = pSave;
+ }
+
+ /**
+ * @param pPath the path to set in the save field
+ */
+ public void setSavePath( String pPath ) {
+ mSavePath = pPath;
+ }
+
+ /**
+ * @return the state of the save ant script box
+ */
+ public boolean getSaveAntScript( ) {
+ return mSaveAntScript;
+ }
+
+ /**
+ * @return the value of the save path text field
+ */
+ public String getSavePath( ) {
+ return mSavePath;
+ }
+
+ /**
+ * @return whether the save path field is enabled
+ */
+ public boolean isSavePathEnabled( ) {
+ return mSavePathEnabled;
+ }
+}
diff --git a/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPart.java b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPart.java
index 5d7edb9..69fcbb9 100644
--- a/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPart.java
+++ b/java/source/org/openoffice/ide/eclipse/java/export/JavaExportPart.java
@@ -30,8 +30,9 @@
************************************************************************/
package org.openoffice.ide.eclipse.java.export;
-import org.eclipse.core.resources.IFile;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
@@ -53,19 +54,21 @@ import org.openoffice.plugin.core.model.UnoPackage;
*/
public class JavaExportPart extends LanguageExportPart {
- private static final String DEFAULT_ANT_FILENAME = "build.xml"; //$NON-NLS-1$
-
private Button mSaveScripts;
private Composite mNameRow;
private Label mNameRowLbl;
private Text mNameRowTxt;
-
+
+ private JavaExportPageControl mController;
+
/**
* {@inheritDoc}
*/
@Override
public void createControls(Composite pParent) {
+ mController = new JavaExportPageControl();
+
Label titleLbl = new Label( pParent, SWT.NONE );
titleLbl.setText( Messages.getString("JavaExportPart.Title") ); //$NON-NLS-1$
titleLbl.setLayoutData( new GridData( SWT.BEGINNING, SWT.BEGINNING, false, false ) );
@@ -82,15 +85,11 @@ public class JavaExportPart extends LanguageExportPart {
mSaveScripts.addSelectionListener( new SelectionListener() {
public void widgetSelected( SelectionEvent pE ) {
- boolean enabled = mSaveScripts.getSelection();
- mNameRowLbl.setEnabled( enabled );
- mNameRowTxt.setEnabled( enabled );
- IFile file = null;
- if ( enabled ) {
- file = getPage().getProject().getFile( ManifestExportPage.MANIFEST_FILENAME );
- }
- getPage().setManifestPath( file );
+ mController.setSaveAntScript( mSaveScripts.getSelection() );
+
+ mNameRowLbl.setEnabled( mController.isSavePathEnabled() );
+ mNameRowTxt.setEnabled( mController.isSavePathEnabled() );
}
public void widgetDefaultSelected( SelectionEvent pE ) {
@@ -107,12 +106,21 @@ public class JavaExportPart extends LanguageExportPart {
mNameRowLbl = new Label( mNameRow, SWT.NONE );
mNameRowLbl.setLayoutData( new GridData( SWT.BEGINNING, SWT.CENTER, false, false ) );
mNameRowLbl.setText( Messages.getString("JavaExportPart.AntFile") ); //$NON-NLS-1$
- mNameRowLbl.setEnabled( false );
mNameRowTxt = new Text( mNameRow, SWT.BORDER | SWT.SINGLE );
mNameRowTxt.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
- mNameRowTxt.setText( DEFAULT_ANT_FILENAME );
- mNameRowTxt.setEnabled( false );
+ mNameRowTxt.addModifyListener( new ModifyListener() {
+
+ public void modifyText( ModifyEvent pEvent ) {
+ mController.setSavePath( mNameRowTxt.getText() );
+ }
+ });
+
+ // Load the default values
+ mSaveScripts.setSelection( mController.isSavePathEnabled() );
+ mNameRowTxt.setText( mController.getSavePath() );
+ mNameRowTxt.setEnabled( mController.isSavePathEnabled() );
+ mNameRowLbl.setEnabled( mController.isSavePathEnabled() );
}
/**
@@ -131,7 +139,8 @@ public class JavaExportPart extends LanguageExportPart {
*/
@Override
public void doFinish( UnoPackage pModel ) {
- // TODO Auto-generated method stub
-
+ if ( mController.getSaveAntScript() ) {
+ // TODO Generate the build script
+ }
}
}
diff --git a/java/source/org/openoffice/ide/eclipse/java/test/JavaExportPageControlTest.java b/java/source/org/openoffice/ide/eclipse/java/test/JavaExportPageControlTest.java
new file mode 100644
index 0000000..4066f8d
--- /dev/null
+++ b/java/source/org/openoffice/ide/eclipse/java/test/JavaExportPageControlTest.java
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * 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.java.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openoffice.ide.eclipse.java.export.JavaExportPageControl;
+
+/**
+ * Unit test for the Manifest export page part UI controller.
+ *
+ * @author Cedric Bosdonnat
+ *
+ */
+public class JavaExportPageControlTest {
+
+ /**
+ * Ensure that the default values are the ones expected.
+ */
+ @Test
+ public void testDefaults( ) {
+ JavaExportPageControl tested = new JavaExportPageControl();
+ assertFalse( "Save ant script shouldn't be default", tested.getSaveAntScript() );
+ assertFalse( "Save path shouldn't be enabled by default", tested.isSavePathEnabled() );
+ assertEquals( JavaExportPageControl.DEFAULT_ANT_FILENAME, tested.getSavePath() );
+ }
+
+ /**
+ * Test checking and unchecking the Save Ant script box.
+ */
+ @Test
+ public void testSetSaveAntScript() {
+ JavaExportPageControl tested = new JavaExportPageControl();
+
+ tested.setSaveAntScript( true );
+ assertTrue( "Save ant script selection not persisting", tested.getSaveAntScript() );
+ assertTrue( "Save path should be enabled when save ant script is checked", tested.isSavePathEnabled() );
+
+ tested.setSaveAntScript( false );
+ assertFalse( "Save ant script selection not persisting", tested.getSaveAntScript() );
+ assertFalse( "Save path should be disabled after save ant script is unchecked", tested.isSavePathEnabled() );
+ }
+
+}