summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-09 22:33:55 +0200
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2009-10-09 22:33:55 +0200
commit4ff6699e5781a4d794960759dad6f9d942f2dd12 (patch)
tree600f288652512a17693152f89c4333627fb5f0b3
parent5a239c58c5d53ad1afcc0def83787e24390c2df9 (diff)
[Core]Fixed some OOo and SDK rows problems
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/gui/OOoConfigPanel.java114
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/gui/rows/AbstractConfigRow.java59
-rwxr-xr-xcore/source/org/openoffice/ide/eclipse/core/gui/rows/ChoiceRow.java2
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/gui/rows/OOoRow.java2
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/gui/rows/SdkRow.java2
5 files changed, 55 insertions, 124 deletions
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/OOoConfigPanel.java b/core/source/org/openoffice/ide/eclipse/core/gui/OOoConfigPanel.java
index f95dc99..8ac88dc 100644
--- a/core/source/org/openoffice/ide/eclipse/core/gui/OOoConfigPanel.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/OOoConfigPanel.java
@@ -30,16 +30,9 @@
************************************************************************/
package org.openoffice.ide.eclipse.core.gui;
-import java.util.Vector;
-
import org.eclipse.swt.widgets.Composite;
import org.openoffice.ide.eclipse.core.gui.rows.OOoRow;
import org.openoffice.ide.eclipse.core.gui.rows.SdkRow;
-import org.openoffice.ide.eclipse.core.model.OOoContainer;
-import org.openoffice.ide.eclipse.core.model.SDKContainer;
-import org.openoffice.ide.eclipse.core.model.config.IConfigListener;
-import org.openoffice.ide.eclipse.core.model.config.IOOo;
-import org.openoffice.ide.eclipse.core.model.config.ISdk;
/**
* Class providing the OOo and SDK configuration rows.
@@ -48,20 +41,9 @@ import org.openoffice.ide.eclipse.core.model.config.ISdk;
*
*/
public class OOoConfigPanel {
-
- private static final String SDK = "__sdk"; //$NON-NLS-1$
- private static final String OOO = "__ooo"; //$NON-NLS-1$
- /**
- * SDK used for the project selection row.
- */
private SdkRow mSdkRow;
-
- /**
- * OOo used for the project selection row.
- */
private OOoRow mOOoRow;
- private ConfigListener mConfigListener;
/**
* Constructor.
@@ -70,19 +52,16 @@ public class OOoConfigPanel {
*/
public OOoConfigPanel ( Composite pParent ) {
- OOoContainer.addListener( mConfigListener );
- SDKContainer.addListener( mConfigListener );
-
- mSdkRow = new SdkRow( pParent, SDK, null );
- mOOoRow = new OOoRow( pParent, OOO, null );
+ mSdkRow = new SdkRow( pParent, new String(), null );
+ mOOoRow = new OOoRow( pParent, new String(), null );
}
/**
* Disposes the object, mainly to unregister the listeners.
*/
public void dispose( ) {
- OOoContainer.removeListener( mConfigListener );
- SDKContainer.removeListener( mConfigListener );
+ mOOoRow.dispose();
+ mSdkRow.dispose();
}
/**
@@ -106,89 +85,4 @@ public class OOoConfigPanel {
}
return oooName;
}
-
- /**
- * Set the SDK names to the SDK list-box.
- */
- private void fillSDKRow () {
-
- if (null != mSdkRow) {
- // Adding the SDK names to the combo box
- String[] sdks = new String[SDKContainer.getSDKCount()];
- Vector<String> sdkKeys = SDKContainer.getSDKKeys();
- for (int i = 0, length = SDKContainer.getSDKCount(); i < length; i++) {
- sdks[i] = sdkKeys.get(i);
- }
-
- mSdkRow.removeAll();
- mSdkRow.addAll(sdks);
- // The default SDK is randomly the first one
- mSdkRow.select(0);
- }
- }
-
- /**
- * Set the OOo names to the OOo list-box.
- */
- private void fillOOoRow() {
-
- if (null != mOOoRow) {
-
- // Adding the OOo names to the combo box
- String[] ooos = new String[OOoContainer.getOOoCount()];
- Vector<String> oooKeys = OOoContainer.getOOoKeys();
- for (int i = 0, length = OOoContainer.getOOoCount(); i < length; i++) {
- ooos[i] = oooKeys.get(i);
- }
-
- mOOoRow.removeAll();
- mOOoRow.addAll(ooos);
- // The default OOo is randomly the first one
- mOOoRow.select(0);
- }
- }
-
- /**
- * Class listening for the OOo and SDK config changes and updating the fields.
- *
- * @author cbosdonnat
- *
- */
- private class ConfigListener implements IConfigListener {
- /**
- * {@inheritDoc}
- */
- public void ConfigAdded(Object pElement) {
- if (pElement instanceof IOOo) {
- fillOOoRow();
- } else {
- fillSDKRow();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void ConfigRemoved(Object pElement) {
-
- if (null == pElement || pElement instanceof IOOo) {
- fillOOoRow();
- }
-
- if (null == pElement || pElement instanceof ISdk) {
- fillSDKRow();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void ConfigUpdated(Object pElement) {
- if (pElement instanceof IOOo) {
- fillOOoRow();
- } else {
- fillSDKRow();
- }
- };
- }
}
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/rows/AbstractConfigRow.java b/core/source/org/openoffice/ide/eclipse/core/gui/rows/AbstractConfigRow.java
index e664c8f..b60692a 100644
--- a/core/source/org/openoffice/ide/eclipse/core/gui/rows/AbstractConfigRow.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/rows/AbstractConfigRow.java
@@ -61,7 +61,7 @@ import org.openoffice.ide.eclipse.core.model.config.IConfigListener;
*/
public abstract class AbstractConfigRow extends ChoiceRow {
- private IConfigListener mConfigListener;
+ private IConfigListener mConfigListener = new ConfigListener();
/**
* Constructor.
@@ -91,7 +91,12 @@ public abstract class AbstractConfigRow extends ChoiceRow {
}
});
- fillRow(pSelection);
+ fillRow( );
+ if ( pSelection != null ) {
+ select( getElementName( pSelection ) );
+ } else {
+ select( 0 );
+ }
}
/**
@@ -128,27 +133,20 @@ public abstract class AbstractConfigRow extends ChoiceRow {
/**
* Computes the name to use to select the given object.
*
- * @param pToSelect the configuration object to select
+ * @param pElement the configuration object for which to get the name
* @return the name to use for the selection
*/
- protected abstract String getSelectionName(Object pToSelect);
+ protected abstract String getElementName(Object pElement);
/**
* Fills the row with the existing values from the configuration.
- *
- * @param pToSelect the configuration object to select
*/
- private void fillRow(Object pToSelect) {
+ private void fillRow( ) {
String[] values = getConfigValues();
removeAll();
addAll(values);
- if (null != pToSelect) {
- select(getSelectionName(pToSelect));
- } else {
- select(0);
- }
}
/**
@@ -209,4 +207,41 @@ public abstract class AbstractConfigRow extends ChoiceRow {
savePreferences();
}
}
+
+ /**
+ * Class listening for the OOo and SDK config changes and updating the fields.
+ *
+ * @author cbosdonnat
+ *
+ */
+ private class ConfigListener implements IConfigListener {
+ /**
+ * {@inheritDoc}
+ */
+ public void ConfigAdded(Object pElement) {
+ fillRow( );
+ select( getElementName( pElement ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void ConfigRemoved(Object pElement) {
+ String value = getValue();
+ fillRow( );
+
+ // Select the previous selection if it hasn't been removed
+ if ( pElement != null && !value.equals( getElementName( pElement ) ) ) {
+ select( value );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void ConfigUpdated(Object pElement) {
+ fillRow( );
+ select( getElementName( pElement ) );
+ };
+ }
}
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/rows/ChoiceRow.java b/core/source/org/openoffice/ide/eclipse/core/gui/rows/ChoiceRow.java
index 769c1f0..51dd38d 100755
--- a/core/source/org/openoffice/ide/eclipse/core/gui/rows/ChoiceRow.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/rows/ChoiceRow.java
@@ -290,6 +290,8 @@ public class ChoiceRow extends LabeledRow {
i++;
}
cField.select(result);
+ mSelected = result;
+ fireFieldChangedEvent( new FieldEvent( mProperty, pValue ) );
}
/**
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/rows/OOoRow.java b/core/source/org/openoffice/ide/eclipse/core/gui/rows/OOoRow.java
index e9f7fd2..7c316b4 100644
--- a/core/source/org/openoffice/ide/eclipse/core/gui/rows/OOoRow.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/rows/OOoRow.java
@@ -115,7 +115,7 @@ public class OOoRow extends AbstractConfigRow {
* {@inheritDoc}
*/
@Override
- protected String getSelectionName(Object pToSelect) {
+ protected String getElementName(Object pToSelect) {
return ((IOOo)pToSelect).getName();
}
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/rows/SdkRow.java b/core/source/org/openoffice/ide/eclipse/core/gui/rows/SdkRow.java
index 9064702..dc74fd2 100644
--- a/core/source/org/openoffice/ide/eclipse/core/gui/rows/SdkRow.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/rows/SdkRow.java
@@ -126,7 +126,7 @@ public class SdkRow extends AbstractConfigRow {
* {@inheritDoc}
*/
@Override
- protected String getSelectionName(Object pToSelect) {
+ protected String getElementName(Object pToSelect) {
return ((ISdk)pToSelect).getId();
}