From 709b85ad8c3ec3791534aa78b5dfb3a4689bdc57 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 16 Apr 2012 06:58:15 -0700 Subject: Fix botched refactoring Change-Id: I02fcbfd6db7338c125a2e57ca39fc6e849d1a6b0 --- .../editors/layout/gre/ClientRulesEngine.java | 51 +--------------------- .../eclipse/adt/internal/ui/ResourceChooser.java | 51 +++++++++++++++++++++- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ClientRulesEngine.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ClientRulesEngine.java index 9c73e1c..e08bfc1 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ClientRulesEngine.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gre/ClientRulesEngine.java @@ -248,56 +248,9 @@ class ClientRulesEngine implements IClientRulesEngine { private String displayResourceInput(String resourceTypeName, String currentValue, IInputValidator validator) { - GraphicalEditorPart graphicalEditor = mRulesEngine.getEditor(); - AndroidXmlEditor editor = graphicalEditor.getEditorDelegate().getEditor(); - IProject project = editor.getProject(); ResourceType type = ResourceType.getEnum(resourceTypeName); - if (project != null) { - // get the resource repository for this project and the system resources. - ResourceRepository projectRepository = ResourceManager.getInstance() - .getProjectResources(project); - Shell shell = AdtPlugin.getDisplay().getActiveShell(); - if (shell == null) { - return null; - } - - AndroidTargetData data = editor.getTargetData(); - ResourceRepository systemRepository = data.getFrameworkResources(); - - // open a resource chooser dialog for specified resource type. - ResourceChooser dlg = new ResourceChooser(project, type, projectRepository, - systemRepository, shell); - dlg.setPreviewHelper(new ResourcePreviewHelper(dlg, graphicalEditor)); - - // When editing Strings, allow editing the value text directly. When we - // get inline editing support (where values entered directly into the - // textual widget are translated automatically into a resource) this can - // go away. - if (resourceTypeName.equals(ResourceType.STRING.getName())) { - dlg.setResourceResolver(graphicalEditor.getResourceResolver()); - dlg.setShowValueText(true); - } else if (resourceTypeName.equals(ResourceType.DIMEN.getName()) - || resourceTypeName.equals(ResourceType.INTEGER.getName())) { - dlg.setResourceResolver(graphicalEditor.getResourceResolver()); - } - - if (validator != null) { - // Ensure wide enough to accommodate validator error message - dlg.setSize(85, 10); - dlg.setInputValidator(validator); - } - - dlg.setCurrentResource(currentValue); - - int result = dlg.open(); - if (result == ResourceChooser.CLEAR_RETURN_CODE) { - return ""; //$NON-NLS-1$ - } else if (result == Window.OK) { - return dlg.getCurrentResource(); - } - } - - return null; + GraphicalEditorPart graphicalEditor = mRulesEngine.getEditor(); + return ResourceChooser.chooseResource(graphicalEditor, type, currentValue, validator); } @Override diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourceChooser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourceChooser.java index 202e1cf..7b90633 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourceChooser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourceChooser.java @@ -28,11 +28,14 @@ import com.android.ide.common.resources.ResourceResolver; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.internal.assetstudio.OpenCreateAssetSetWizardAction; +import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart; import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringRefactoring; import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringWizard; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator; +import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager; +import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.resources.ResourceType; import com.android.util.Pair; @@ -790,6 +793,52 @@ public class ResourceChooser extends AbstractElementListSelectionDialog implemen @NonNull GraphicalEditorPart graphicalEditor, @NonNull ResourceType type, String currentValue, IInputValidator validator) { - return ResourceChooser.chooseResource(graphicalEditor, type, currentValue, validator); + AndroidXmlEditor editor = graphicalEditor.getEditorDelegate().getEditor(); + IProject project = editor.getProject(); + if (project != null) { + // get the resource repository for this project and the system resources. + ResourceRepository projectRepository = ResourceManager.getInstance() + .getProjectResources(project); + Shell shell = AdtPlugin.getDisplay().getActiveShell(); + if (shell == null) { + return null; + } + + AndroidTargetData data = editor.getTargetData(); + ResourceRepository systemRepository = data.getFrameworkResources(); + + // open a resource chooser dialog for specified resource type. + ResourceChooser dlg = new ResourceChooser(project, type, projectRepository, + systemRepository, shell); + dlg.setPreviewHelper(new ResourcePreviewHelper(dlg, graphicalEditor)); + + // When editing Strings, allow editing the value text directly. When we + // get inline editing support (where values entered directly into the + // textual widget are translated automatically into a resource) this can + // go away. + if (type == ResourceType.STRING) { + dlg.setResourceResolver(graphicalEditor.getResourceResolver()); + dlg.setShowValueText(true); + } else if (type == ResourceType.DIMEN || type == ResourceType.INTEGER) { + dlg.setResourceResolver(graphicalEditor.getResourceResolver()); + } + + if (validator != null) { + // Ensure wide enough to accommodate validator error message + dlg.setSize(85, 10); + dlg.setInputValidator(validator); + } + + dlg.setCurrentResource(currentValue); + + int result = dlg.open(); + if (result == ResourceChooser.CLEAR_RETURN_CODE) { + return ""; //$NON-NLS-1$ + } else if (result == Window.OK) { + return dlg.getCurrentResource(); + } + } + + return null; } } -- cgit v1.1