Merge "Show non-framework attributes in simple mode when they\'re available" into studio-1.3-dev automerge: 7925217
automerge: 472e06e
* commit '472e06eae6ae10e99535a2bc031b33796de46a51':
Show non-framework attributes in simple mode when they're available
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 bb6915e..bc73589 100644
--- a/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java
+++ b/android/src/com/android/tools/idea/editors/theme/ThemeEditorComponent.java
@@ -99,7 +99,11 @@
private final Configuration myConfiguration;
private final Module myModule;
private final AndroidThemePreviewPanel myPreviewPanel;
+
private final StyleAttributesFilter myAttributesFilter;
+ private TableRowSorter<AttributesTableModel> myAttributesSorter;
+ private final SimpleModeFilter mySimpleModeFilter;
+
private final AttributesPanel myPanel = new AttributesPanel();
private final ThemeEditorTable myAttributesTable = myPanel.getAttributesTable();
@@ -120,6 +124,7 @@
};
private ThemeEditorStyle mySelectedTheme;
private MessageBusConnection myMessageBusConnection;
+ private AttributesTableModel myModel;
public ThemeEditorComponent(final Configuration configuration, final Module module) {
this.myConfiguration = configuration;
@@ -218,6 +223,7 @@
updateUiParameters();
myAttributesFilter = new StyleAttributesFilter();
+ mySimpleModeFilter = new SimpleModeFilter();
myPanel.getBackButton().addActionListener(new ActionListener() {
@Override
@@ -236,9 +242,8 @@
myAttributesTable.clearSelection();
myPanel.getPalette().clearSelection();
- myAttributesFilter.setFilterEnabled(!myPanel.isAdvancedMode());
- myAttributesFilter.setAttributesFilter(myAttributesFilter.ATTRIBUTES_DEFAULT_FILTER);
+ configureFilter();
((TableRowSorter)myAttributesTable.getRowSorter()).sort();
myAttributesTable.updateRowHeights();
@@ -319,6 +324,16 @@
});
}
+ private void configureFilter() {
+ if (myPanel.isAdvancedMode()) {
+ myAttributesFilter.setFilterEnabled(false);
+ myAttributesSorter.setRowFilter(myAttributesFilter);
+ } else {
+ mySimpleModeFilter.configure(myModel.getDefinedAttributes());
+ myAttributesSorter.setRowFilter(mySimpleModeFilter);
+ }
+ }
+
/**
* Launches dialog to create a new theme based on selected one.
* @return whether creation of new theme succeeded.
@@ -615,10 +630,10 @@
myConfiguration.setTheme(selectedTheme.getName());
assert myConfiguration.getResourceResolver() != null; // ResourceResolver is only null if no theme was set.
- final AttributesTableModel model = new AttributesTableModel(selectedStyle, getSelectedAttrGroup(), myConfiguration, myModule.getProject());
- model.setGoToDefinitionListener(myClickListener);
+ myModel = new AttributesTableModel(selectedStyle, getSelectedAttrGroup(), myConfiguration, myModule.getProject());
+ myModel.setGoToDefinitionListener(myClickListener);
- model.addThemePropertyChangedListener(new AttributesTableModel.ThemePropertyChangedListener() {
+ myModel.addThemePropertyChangedListener(new AttributesTableModel.ThemePropertyChangedListener() {
@Override
public void attributeChangedOnReadOnlyTheme(final EditedStyleItem attribute, final String newValue) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@@ -630,7 +645,7 @@
}
});
- model.addTableModelListener(new TableModelListener() {
+ myModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.UPDATE) {
@@ -653,9 +668,8 @@
});
myAttributesTable.setRowSorter(null); // Clean any previous row sorters.
- TableRowSorter<AttributesTableModel> sorter = new TableRowSorter<AttributesTableModel>(model);
- sorter.setRowFilter(myAttributesFilter);
- myPanel.setAdvancedMode(!myAttributesFilter.myIsFilterEnabled);
+ myAttributesSorter = new TableRowSorter<AttributesTableModel>(myModel);
+ configureFilter();
ActionListener listener = new ActionListener() {
@Override
@@ -664,12 +678,12 @@
}
};
- myAttributesTable.setModel(model);
- myAttributesTable.setRowSorter(sorter);
+ myAttributesTable.setModel(myModel);
+ myAttributesTable.setRowSorter(myAttributesSorter);
myAttributesTable.updateRowHeights();
- model.parentAttribute.setGotoDefinitionCallback(listener);
+ myModel.parentAttribute.setGotoDefinitionCallback(listener);
- myPanel.getPalette().setModel(new AttributesModelColorPaletteModel(myConfiguration, model));
+ myPanel.getPalette().setModel(new AttributesModelColorPaletteModel(myConfiguration, myModel));
myPanel.getPalette().addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
@@ -699,7 +713,7 @@
});
//We calling this to trigger tableChanged, which will calculate row heights and rePaint myPreviewPanel
- model.fireTableStructureChanged();
+ myModel.fireTableStructureChanged();
}
@Override
@@ -710,33 +724,41 @@
super.dispose();
}
- class StyleAttributesFilter extends RowFilter<AttributesTableModel, Integer> {
- // TODO: This is just a random list of attributes. Replace with a possibly dynamic list of simple attributes.
+ class SimpleModeFilter extends AttributesFilter {
public final Set<String> ATTRIBUTES_DEFAULT_FILTER = ImmutableSet
- .of("android:colorPrimary",
- "android:colorPrimaryDark",
- "android:colorAccent",
- "android:colorForeground",
- "android:textColorPrimary",
- "android:textColorSecondary",
- "android:textColorPrimaryInverse",
- "android:textColorSecondaryInverse",
- "android:colorBackground",
- "android:windowBackground",
- "android:navigationBarColor");
- private boolean myIsFilterEnabled = true;
- private Set<String> filterAttributes = ATTRIBUTES_DEFAULT_FILTER;
+ .of("colorPrimary",
+ "colorPrimaryDark",
+ "colorAccent",
+ "colorForeground",
+ "textColorPrimary",
+ "textColorSecondary",
+ "textColorPrimaryInverse",
+ "textColorSecondaryInverse",
+ "colorBackground",
+ "windowBackground",
+ "navigationBarColor");
- public void setFilterEnabled(boolean enabled) {
- this.myIsFilterEnabled = enabled;
+ public SimpleModeFilter() {
+ myIsFilterEnabled = true;
+ filterAttributes = new HashSet<String>();
}
- /**
- * Set the attribute names we want to display.
- */
- public void setAttributesFilter(@NotNull Set<String> attributeNames) {
- filterAttributes = ImmutableSet.copyOf(attributeNames);
+ public void configure(final Set<String> availableAttributes) {
+ filterAttributes.clear();
+
+ for (final String candidate : ATTRIBUTES_DEFAULT_FILTER) {
+ if (availableAttributes.contains(candidate)) {
+ filterAttributes.add(candidate);
+ } else {
+ filterAttributes.add(SdkConstants.ANDROID_NS_NAME_PREFIX + candidate);
+ }
+ }
}
+ }
+
+ abstract class AttributesFilter extends RowFilter<AttributesTableModel, Integer> {
+ boolean myIsFilterEnabled;
+ Set<String> filterAttributes;
@Override
public boolean include(Entry<? extends AttributesTableModel, ? extends Integer> entry) {
@@ -772,6 +794,24 @@
}
}
+ class StyleAttributesFilter extends AttributesFilter {
+ public StyleAttributesFilter() {
+ myIsFilterEnabled = true;
+ filterAttributes = Collections.emptySet();
+ }
+
+ public void setFilterEnabled(boolean enabled) {
+ this.myIsFilterEnabled = enabled;
+ }
+
+ /**
+ * Set the attribute names we want to display.
+ */
+ public void setAttributesFilter(@NotNull Set<String> attributeNames) {
+ filterAttributes = ImmutableSet.copyOf(attributeNames);
+ }
+ }
+
@Override
public void setUI(PanelUI ui) {
super.setUI(ui);
diff --git a/android/src/com/android/tools/idea/editors/theme/attributes/AttributesTableModel.java b/android/src/com/android/tools/idea/editors/theme/attributes/AttributesTableModel.java
index 593db54..5ff9daa 100644
--- a/android/src/com/android/tools/idea/editors/theme/attributes/AttributesTableModel.java
+++ b/android/src/com/android/tools/idea/editors/theme/attributes/AttributesTableModel.java
@@ -46,6 +46,7 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -125,6 +126,16 @@
myThemePropertyChangedListeners.add(listener);
}
+ public ImmutableSet<String> getDefinedAttributes() {
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+
+ for (EditedStyleItem item : myAttributes) {
+ builder.add(item.getQualifiedName());
+ }
+
+ return builder.build();
+ }
+
public AttributesTableModel(@NotNull ThemeEditorStyle selectedStyle,
@NotNull AttributesGrouper.GroupBy groupBy,
@NotNull Configuration configuration,