use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class DelegatingCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
EditedStyleItem item = (value instanceof EditedStyleItem) ? (EditedStyleItem) value : null;
final Component returnedComponent = myDelegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
ConfiguredThemeEditorStyle selectedStyle = ((AttributesTableModel) table.getModel()).getSelectedStyle();
// Displays in bold attributes that are overriding their inherited value
returnedComponent.setFont(selectedStyle.hasItem(item) ? returnedComponent.getFont().deriveFont(Font.BOLD) : returnedComponent.getFont().deriveFont(Font.PLAIN));
returnedComponent.setForeground((item != null && !item.isPublicAttribute()) ? JBColor.LIGHT_GRAY : table.getForeground());
return returnedComponent;
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class DelegatingCellEditor method getTableCellEditorComponent.
@Override
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
final Object stringValue;
final CellSpanModel model = (CellSpanModel) table.getModel();
boolean boldFont = false;
if (value instanceof EditedStyleItem) {
final EditedStyleItem item = (EditedStyleItem) value;
stringValue = ThemeEditorUtils.extractRealValue(item, model.getCellClass(row, column));
ConfiguredThemeEditorStyle selectedStyle = ((AttributesTableModel) table.getModel()).getSelectedStyle();
// Displays in bold attributes that are overriding their inherited value
boldFont = selectedStyle.hasItem(item);
} else {
// Not an EditedStyleItem for theme name and theme parent.
stringValue = value;
}
final Component returnedComponent = myDelegate.getTableCellEditorComponent(table, myConvertValueToString ? stringValue : value, isSelected, row, column);
returnedComponent.setFont(boldFont ? returnedComponent.getFont().deriveFont(Font.BOLD) : returnedComponent.getFont().deriveFont(Font.PLAIN));
return returnedComponent;
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class ThemeAttributeResolverTest method testResolveAllVersion.
/**
* Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
*/
public void testResolveAllVersion() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles.xml", "res/values/styles.xml");
VirtualFile resourceDir = myFile.getParent().getParent();
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
createNewStyle(resourceDir, "ThemeA", "android:Theme", "red", Lists.newArrayList("values-v13", "values-v16"));
createNewStyle(resourceDir, "ThemeB", "ThemeA", "blue", Lists.newArrayList("values-v12"));
createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values-v15"));
// ResourceFolderRepository needs to rescan the files to pick up the changes.
UIUtil.dispatchAllInvocationEvents();
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle style = themeResolver.getTheme("ThemeB");
assertNotNull(style);
Set<String> answer = Sets.newHashSet("-v16:red", "-v15:red", "-v14:blue");
List<EditedStyleItem> items = ThemeAttributeResolver.resolveAll(style, configuration.getConfigurationManager());
boolean foundColorPrimary = false;
for (EditedStyleItem item : items) {
if (item.getName().equals("colorPrimary") && item.getAttrGroup().equals("Other non-theme attributes.")) {
foundColorPrimary = true;
assertEquals(answer.size(), item.getAllConfiguredItems().size());
for (ConfiguredElement<ItemResourceValue> value : item.getAllConfiguredItems()) {
assertTrue(answer.contains(value.getConfiguration().getUniqueKey() + ":" + value.getElement().getValue()));
}
}
}
assertTrue(foundColorPrimary);
}
use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem in project android by JetBrains.
the class ThemeEditorUtilsTest method findAttribute.
@NotNull
private static EditedStyleItem findAttribute(@NotNull final String name, @NotNull Collection<EditedStyleItem> attributes) {
EditedStyleItem item = Iterables.find(attributes, new Predicate<EditedStyleItem>() {
@Override
public boolean apply(@Nullable EditedStyleItem input) {
assert input != null;
return name.equals(input.getQualifiedName());
}
});
assertNotNull(item);
return item;
}
Aggregations