summaryrefslogtreecommitdiff
path: root/android/src/com
diff options
context:
space:
mode:
authorDiego Perez <diegoperez@google.com>2015-08-03 13:01:53 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-08-03 13:01:53 +0000
commit74e54a7cbcbd30742bc9200ae03ab2ed20276a26 (patch)
treeadd34a5d76cbec01c88942e373d944deabf477f3 /android/src/com
parent5fc0f1da830ac3289bb2086ca0eee2cb5cda920c (diff)
parent7a498628ebc656ec9514f2e86124fa6aa7136a6a (diff)
downloadidea-74e54a7cbcbd30742bc9200ae03ab2ed20276a26.tar.gz
Merge "Fix simple mode sorting and UI tests" into studio-1.4-dev
Diffstat (limited to 'android/src/com')
-rw-r--r--android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java31
-rw-r--r--android/src/com/android/tools/idea/editors/theme/attributes/AttributesGrouper.java122
-rw-r--r--android/src/com/android/tools/idea/editors/theme/datamodels/EditedStyleItem.java7
3 files changed, 93 insertions, 67 deletions
diff --git a/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java b/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java
index ae60ae82e44..053c3a6a6a2 100644
--- a/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java
+++ b/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java
@@ -50,6 +50,7 @@ import com.android.tools.idea.rendering.ResourceNotificationManager.ResourceChan
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Ordering;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
@@ -84,6 +85,8 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowFilter;
+import javax.swing.RowSorter;
+import javax.swing.SortOrder;
import javax.swing.event.DocumentEvent;
import javax.swing.plaf.PanelUI;
import javax.swing.table.DefaultTableCellRenderer;
@@ -99,6 +102,7 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -113,6 +117,28 @@ public class ThemeEditorComponent extends Splitter {
private static final JBColor PREVIEW_BACKGROUND = new JBColor(new Color(0xFAFAFA), new Color(0x343739));
+ /**
+ * Comparator used for simple mode attribute sorting
+ */
+ private static final Comparator SIMPLE_MODE_COMPARATOR = new Comparator() {
+ @Override
+ public int compare(Object o1, Object o2) {
+ // The parent attribute goes always first
+ if (o1 instanceof String) {
+ return -1;
+ } else if (o2 instanceof String) {
+ return 1;
+ }
+
+ if (o1 instanceof EditedStyleItem && o2 instanceof EditedStyleItem) {
+ return ((EditedStyleItem)o1).compareTo((EditedStyleItem)o2);
+ }
+
+ // Fall-back for other comparisons
+ return Ordering.usingToString().compare(o1, o2);
+ }
+ };
+
public static final float HEADER_FONT_SCALE = 1.3f;
public static final int REGULAR_CELL_PADDING = 4;
public static final int LARGE_CELL_PADDING = 10;
@@ -499,10 +525,12 @@ public class ThemeEditorComponent extends Splitter {
if (myPanel.isAdvancedMode()) {
myAttributesFilter.setFilterEnabled(false);
myAttributesSorter.setRowFilter(myAttributesFilter);
+ myAttributesSorter.setSortKeys(null);
} else {
mySimpleModeFilter.configure(myModel.getDefinedAttributes(), ThemeEditorUtils.isAppCompatTheme(
myThemeEditorContext.getConfiguration()));
myAttributesSorter.setRowFilter(mySimpleModeFilter);
+ myAttributesSorter.setSortKeys(ImmutableList.of(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
}
}
@@ -774,6 +802,9 @@ public class ThemeEditorComponent extends Splitter {
myAttributesTable.setRowSorter(null); // Clean any previous row sorters.
myAttributesSorter = new TableRowSorter<AttributesTableModel>(myModel);
+ // This is only used when the sort keys are set (only set in simple mode).
+ myAttributesSorter.setComparator(0, SIMPLE_MODE_COMPARATOR);
+
configureFilter();
myAttributesTable.setModel(myModel);
diff --git a/android/src/com/android/tools/idea/editors/theme/attributes/AttributesGrouper.java b/android/src/com/android/tools/idea/editors/theme/attributes/AttributesGrouper.java
index bcde2764173..7090222ab3a 100644
--- a/android/src/com/android/tools/idea/editors/theme/attributes/AttributesGrouper.java
+++ b/android/src/com/android/tools/idea/editors/theme/attributes/AttributesGrouper.java
@@ -16,9 +16,17 @@
package com.android.tools.idea.editors.theme.attributes;
import com.android.tools.idea.editors.theme.datamodels.EditedStyleItem;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.TreeMultimap;
import com.intellij.openapi.util.text.StringUtil;
+import org.jetbrains.annotations.NotNull;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
public class AttributesGrouper {
private AttributesGrouper() { }
@@ -28,7 +36,7 @@ public class AttributesGrouper {
TYPE("By Type");
final private String myText;
-
+
GroupBy(String text) {
myText = text;
}
@@ -43,7 +51,13 @@ public class AttributesGrouper {
* Helper data structure to hold information for (temporary) algorithm for splitting attributes
* to labelled group.
*/
- private static class Group {
+ private enum Group {
+ STYLES("Styles", ImmutableList.of("style", "theme")),
+ COLORS("Colors", ImmutableList.of("color")),
+ DRAWABLES("Drawables", ImmutableList.of("drawable")),
+ METRICS("Metrics", ImmutableList.of("size", "width", "height")),
+ OTHER("Everything Else", Collections.<String>emptyList());
+
/**
* Group name, as appears on properties panel
*/
@@ -54,88 +68,61 @@ public class AttributesGrouper {
*/
public final List<String> markers;
- public Group(String name, List<String> markers) {
+ Group(@NotNull String name, @NotNull List<String> markers) {
this.name = name;
this.markers = markers;
}
- public static Group of(String name, String... markers) {
- return new Group(name, Arrays.asList(markers));
+ private static Group getGroupFromName(String name) {
+ for (Group group : Group.values()) {
+ for (final String marker : group.markers) {
+ if (StringUtil.containsIgnoreCase(name, marker)) {
+ return group;
+ }
+ }
+ }
+ return OTHER;
}
}
- private static final List<Group> GROUPS = Arrays.asList(
- Group.of("Styles", "style", "theme"),
- Group.of("Colors", "color"),
- Group.of("Drawables", "drawable"),
- Group.of("Metrics", "size", "width", "height")
- );
- @SuppressWarnings("unchecked")
- public static List<TableLabel> generateLabelsForType(final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
+ @NotNull
+ private static List<TableLabel> generateLabelsForType(@NotNull final List<EditedStyleItem> source, @NotNull final List<EditedStyleItem> sink) {
+ final Multimap<Group, EditedStyleItem> classes = HashMultimap.create();
- final List<EditedStyleItem>[] classes = new List[GROUPS.size() + 1];
- final int otherGroupIndex = GROUPS.size();
-
- for (int i = 0; i < classes.length; i++) {
- classes[i] = new ArrayList<EditedStyleItem>();
- }
-
- outer:
for (final EditedStyleItem item : source) {
final String name = item.getName();
-
- for (int index = 0; index < GROUPS.size(); index++) {
- final Group group = GROUPS.get(index);
- for (final String marker : group.markers) {
- if (StringUtil.containsIgnoreCase(name, marker)) {
- classes[index].add(item);
- continue outer;
- }
- }
- }
-
- // haven't found any group, will put the item into "Other"
- classes[otherGroupIndex].add(item);
+ classes.put(Group.getGroupFromName(name), item);
}
final List<TableLabel> labels = new ArrayList<TableLabel>();
int offset = 0;
- for (int index = 0; index < GROUPS.size(); index++) {
- final Group group = GROUPS.get(index);
- final int size = classes[index].size();
-
- if (size != 0) {
+ for (Group group : Group.values()) {
+ Collection<EditedStyleItem> elements = classes.get(group);
+
+ boolean addHeader = !elements.isEmpty();
+ if (addHeader && group == Group.OTHER) {
+ // Adding "Everything else" label only in case when there are at least one other label,
+ // because having "Everything else" as the only label present looks quite silly
+ addHeader = offset != 0;
+ }
+ if (addHeader) {
labels.add(new TableLabel(group.name, offset));
}
- offset += size;
- }
-
- final int otherGroupSize = classes[otherGroupIndex].size();
- // Adding "Everything else" label only in case when there are at least one other label,
- // because having "Everything else" as the only label present looks quite silly
- if (otherGroupSize != 0 && labels.size() > 0) {
- labels.add(new TableLabel("Everything Else", offset));
- }
+ sink.addAll(elements);
- for (final List<EditedStyleItem> list : classes) {
- for (final EditedStyleItem item : list) {
- sink.add(item);
- }
+ offset += elements.size();
}
return labels;
}
- private static List<TableLabel> generateLabelsForGroup(final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
- Map<String, List<EditedStyleItem>> classes = new TreeMap<String, List<EditedStyleItem>>();
+ static List<TableLabel> generateLabelsForGroup(final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
+ TreeMultimap<String, EditedStyleItem> classes = TreeMultimap.create();
for (EditedStyleItem item : source){
String group = item.getAttrGroup();
- if (!classes.containsKey(group)) {
- classes.put(group, new ArrayList<EditedStyleItem>());
- }
- classes.get(group).add(item);
+ classes.put(group, item);
}
final List<TableLabel> labels = new ArrayList<TableLabel>();
@@ -152,13 +139,16 @@ public class AttributesGrouper {
return labels;
}
- public static List<TableLabel> generateLabels(GroupBy group, final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
- if (group == GroupBy.TYPE) {
- return generateLabelsForType(source, sink);
- }
- else if (group == GroupBy.GROUP) {
- return generateLabelsForGroup(source, sink);
+ @NotNull
+ public static List<TableLabel> generateLabels(@NotNull GroupBy group, final List<EditedStyleItem> source, final List<EditedStyleItem> sink) {
+ switch(group) {
+ case TYPE:
+ return generateLabelsForType(source, sink);
+ case GROUP:
+ return generateLabelsForGroup(source, sink);
+
+ default:
+ throw new IllegalArgumentException();
}
- return null;
}
}
diff --git a/android/src/com/android/tools/idea/editors/theme/datamodels/EditedStyleItem.java b/android/src/com/android/tools/idea/editors/theme/datamodels/EditedStyleItem.java
index be7d89ea8d1..2ae49c99b87 100644
--- a/android/src/com/android/tools/idea/editors/theme/datamodels/EditedStyleItem.java
+++ b/android/src/com/android/tools/idea/editors/theme/datamodels/EditedStyleItem.java
@@ -40,7 +40,7 @@ import java.util.Collections;
* <p/>
* If the attribute is declared locally in multiple resource folders, this class also contains the alternative values for the attribute.
*/
-public class EditedStyleItem {
+public class EditedStyleItem implements Comparable<EditedStyleItem> {
private final static Logger LOG = Logger.getInstance(EditedStyleItem.class);
private final static String DEPRECATED = "deprecated";
@@ -187,4 +187,9 @@ public class EditedStyleItem {
return androidTargetData.isResourcePublic(ResourceType.ATTR.getName(), getName());
}
+
+ @Override
+ public int compareTo(EditedStyleItem that) {
+ return getName().compareTo(that.getName());
+ }
}