From 596f3b8d91c839d9bbf30caed04e6955b864842b Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 28 Sep 2009 17:53:47 -0700 Subject: [PATCH] Fix NPE when opening new layout file. When adding the parsing of the device XML files, I mostly tested with a layout file already opened when Eclipse launched. Well it turns out there's a slightly different code path when opening a file *after* Eclipse has launched. The load of the device UI in the config selected caused a rendering before the XML model was loaded which ended up in an NPE in the recomputeLayout method. Additionnally, I hadn't finalized the code for the GLE2, so this brings it in line with the GLE1. Change-Id: Ic86de6e91ca13793aceecb5706bc963edddb9241 --- .../editors/layout/GraphicalEditorPart.java | 6 ++++-- .../editors/layout/GraphicalLayoutEditor.java | 6 +++--- .../editors/layout/IGraphicalLayoutEditor.java | 2 +- .../adt/internal/editors/layout/LayoutEditor.java | 2 +- .../configuration/ConfigurationComposite.java | 13 ++++++++----- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java index 4953f7e79..ef0db5ab7 100755 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java @@ -679,6 +679,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE // enable the create button if the current and edited config are not equals mConfigComposite.setEnabledCreate( mEditedConfig.equals(mConfigComposite.getCurrentConfig()) == false); + + reloadConfigurationUi(false /*notifyListener*/); } public Clipboard getClipboard() { @@ -967,7 +969,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE } } - public void reloadConfigurationUi() { + public void reloadConfigurationUi(boolean notifyListener) { // enable the clipping button if it's supported. Sdk currentSdk = Sdk.getCurrent(); if (currentSdk != null) { @@ -975,7 +977,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE AndroidTargetData data = currentSdk.getTargetData(target); if (data != null) { LayoutBridge bridge = data.getLayoutBridge(); - mConfigComposite.reloadDevices(); + mConfigComposite.reloadDevices(notifyListener); mConfigComposite.setClippingSupport(bridge.apiLevel >= 4); } } diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalLayoutEditor.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalLayoutEditor.java index 6d210a802..f3fd97a98 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalLayoutEditor.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalLayoutEditor.java @@ -548,7 +548,7 @@ public class GraphicalLayoutEditor extends GraphicalEditorWithPalette mConfigComposite.setEnabledCreate( mEditedConfig.equals(mConfigComposite.getCurrentConfig()) == false); - reloadConfigurationUi(); + reloadConfigurationUi(false /*notifyListener*/); } public Rectangle getBounds() { @@ -730,7 +730,7 @@ public class GraphicalLayoutEditor extends GraphicalEditorWithPalette PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData()); } - public void reloadConfigurationUi() { + public void reloadConfigurationUi(boolean notifyListener) { // enable the clipping button if it's supported. Sdk currentSdk = Sdk.getCurrent(); if (currentSdk != null) { @@ -738,7 +738,7 @@ public class GraphicalLayoutEditor extends GraphicalEditorWithPalette AndroidTargetData data = currentSdk.getTargetData(target); if (data != null) { LayoutBridge bridge = data.getLayoutBridge(); - mConfigComposite.reloadDevices(); + mConfigComposite.reloadDevices(notifyListener); mConfigComposite.setClippingSupport(bridge.apiLevel >= 4); } } diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java index 664edcb5f..5816af65b 100755 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java @@ -82,6 +82,6 @@ import org.eclipse.ui.IEditorPart; abstract Clipboard getClipboard(); - abstract void reloadConfigurationUi(); + abstract void reloadConfigurationUi(boolean notifyListener); } diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java index ca11fc7bb..99670d818 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java @@ -410,7 +410,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa if (mGraphicalEditor != null) { mGraphicalEditor.reloadEditor(); mGraphicalEditor.reloadPalette(); - mGraphicalEditor.reloadConfigurationUi(); + mGraphicalEditor.reloadConfigurationUi(true /*notify listener */); mGraphicalEditor.recomputeLayout(); } } diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java index 1cd301ccd..969050a0a 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java @@ -150,7 +150,7 @@ public class ConfigurationComposite extends Composite { mDeviceList.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - onDeviceChange(); + onDeviceChange(true /* recomputeLayout*/); } }); @@ -451,11 +451,12 @@ public class ConfigurationComposite extends Composite { /** * Reloads the list of {@link DeviceConfiguration} from the {@link Sdk}. + * @param notifyListener */ - public void reloadDevices() { + public void reloadDevices(boolean notifyListener) { mDevices = Sdk.getCurrent().getLayoutDevices(); initUiWithDevices(); - onDeviceChange(); + onDeviceChange(notifyListener); } /** @@ -508,7 +509,7 @@ public class ConfigurationComposite extends Composite { } } - private void onDeviceChange() { + private void onDeviceChange(boolean recomputeLayout) { int deviceIndex = mDeviceList.getSelectionIndex(); DeviceConfiguration device = mDevices.get(deviceIndex); @@ -525,7 +526,9 @@ public class ConfigurationComposite extends Composite { mDeviceConfigs.setEnabled(false); } - onDeviceConfigChange(); + if (recomputeLayout) { + onDeviceConfigChange(); + } } private void onDeviceConfigChange() {