Search in sources :

Example 1 with EditedStyleItem

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;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Project(com.intellij.openapi.project.Project) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Example 2 with EditedStyleItem

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;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 3 with EditedStyleItem

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;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) CellSpanModel(spantable.CellSpanModel) EventObject(java.util.EventObject) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 4 with EditedStyleItem

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 5 with EditedStyleItem

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;
}
Also used : EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)17 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 Configuration (com.android.tools.idea.configurations.Configuration)5 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)4 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)4 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)2 ImmutableList (com.google.common.collect.ImmutableList)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AttributesModelColorPaletteModel (com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel)1 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)1 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)1 AndroidThemePreviewPanel (com.android.tools.idea.editors.theme.preview.AndroidThemePreviewPanel)1 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)1