aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-07-12 16:26:17 -0700
committerTor Norbye <tnorbye@google.com>2012-07-12 16:26:17 -0700
commitd9bb464102d2e99fa3f22d4e6de996ce123070c3 (patch)
tree33c0cb5d7c4fd54690fa0688544ec23cada0539a
parent0d8f973905a4925e00eb9e32887c192b2148b29f (diff)
downloadsdk-d9bb464102d2e99fa3f22d4e6de996ce123070c3.zip
sdk-d9bb464102d2e99fa3f22d4e6de996ce123070c3.tar.gz
sdk-d9bb464102d2e99fa3f22d4e6de996ce123070c3.tar.bz2
Make the flag property editor editable
For "enum" properties (such as layout_width) we were using the WindowBuilder combobox to let the user pick which of the enumeration values to use. However, the enum values in Android often allow not just the enumeration values, but other values too; for example, while layout_width's enum values are match_parent and wrap_content, you can also specify 42dp. This changeset changes the property editor to use a similar property editor to the one used for flag values; a free-form text field along with field completion offering the available enum values. (We can't simply just modify the property editor for enums to have an editable combobox, since that property editor is a custom SWT component which doesn't support editing.) Change-Id: I1bff568233b4727d80ffbe7c17742177c6596381
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/EnumValueCompleter.java56
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/FlagValueCompleter.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/PropertyFactory.java9
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java8
4 files changed, 71 insertions, 4 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/EnumValueCompleter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/EnumValueCompleter.java
new file mode 100644
index 0000000..4746a72
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/EnumValueCompleter.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.ide.eclipse.adt.internal.editors.layout.properties;
+
+import com.android.ide.eclipse.adt.AdtUtils;
+
+import org.eclipse.jface.fieldassist.ContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Text value completion for the given enum property */
+class EnumValueCompleter implements IContentProposalProvider {
+ protected final XmlProperty mProperty;
+ private String[] mValues;
+
+ EnumValueCompleter(XmlProperty property, String[] values) {
+ mProperty = property;
+ mValues = values;
+ }
+
+ @Override
+ public IContentProposal[] getProposals(String contents, int position) {
+ List<IContentProposal> proposals = new ArrayList<IContentProposal>(mValues.length);
+ String prefix = contents;
+
+ for (String value : mValues) {
+ if (AdtUtils.startsWithIgnoreCase(value, prefix)) {
+ proposals.add(new ContentProposal(value));
+ }
+ }
+
+ for (String value : mValues) {
+ if (!AdtUtils.startsWithIgnoreCase(value, prefix)) {
+ proposals.add(new ContentProposal(value));
+ }
+ }
+
+ return proposals.toArray(new IContentProposal[proposals.size()]);
+ }
+} \ No newline at end of file
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/FlagValueCompleter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/FlagValueCompleter.java
index d3707a5..6958e0f 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/FlagValueCompleter.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/FlagValueCompleter.java
@@ -24,7 +24,7 @@ import org.eclipse.jface.fieldassist.IContentProposalProvider;
import java.util.ArrayList;
import java.util.List;
-/** Resource value completion for the given property */
+/** Text value completion for the given flag property */
class FlagValueCompleter implements IContentProposalProvider {
protected final XmlProperty mProperty;
private String[] mValues;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/PropertyFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/PropertyFactory.java
index e160079..68a4c07 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/PropertyFactory.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/PropertyFactory.java
@@ -182,7 +182,14 @@ public class PropertyFactory {
if (formats.contains(Format.BOOLEAN)) {
editor = BooleanXmlPropertyEditor.INSTANCE;
} else if (formats.contains(Format.ENUM)) {
- editor = EnumXmlPropertyEditor.INSTANCE;
+ // We deliberately don't use EnumXmlPropertyEditor.INSTANCE here,
+ // since some attributes (such as layout_width) can have not just one
+ // of the enum values but custom values such as "42dp" as well. And
+ // furthermore, we don't even bother limiting this to formats.size()==1,
+ // since the editing experience with the enum property editor is
+ // more limited than the text editor plus enum completer anyway
+ // (for example, you can't type to filter the values, and clearing
+ // the value is harder.)
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java
index 6591575..d3985a9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlProperty.java
@@ -141,7 +141,7 @@ class XmlProperty extends Property {
if (formats.contains(Format.FLAG)) {
return adapter.cast(new FlagValueCompleter(this, info.getFlagValues()));
} else if (formats.contains(Format.ENUM)) {
- return adapter.cast(new FlagValueCompleter(this, info.getEnumValues()));
+ return adapter.cast(new EnumValueCompleter(this, info.getEnumValues()));
}
}
// Fallback: complete values on resource values
@@ -202,7 +202,11 @@ class XmlProperty extends Property {
Object viewObject = getFactory().getCurrentViewObject();
if (viewObject != null) {
- ViewHierarchy views = getGraphicalEditor().getCanvasControl().getViewHierarchy();
+ GraphicalEditorPart graphicalEditor = getGraphicalEditor();
+ if (graphicalEditor == null) {
+ return null;
+ }
+ ViewHierarchy views = graphicalEditor.getCanvasControl().getViewHierarchy();
Map<String, String> defaultProperties = views.getDefaultProperties(viewObject);
if (defaultProperties != null) {
return defaultProperties.get(name);