Search in sources :

Example 1 with GradleEditorEntity

use of com.android.tools.idea.gradle.editor.entity.GradleEditorEntity in project android by JetBrains.

the class GradleEditorCellComponentImpl method getValue.

@Override
@Nullable
public Object getValue(@NotNull Project project) {
    GradleEditorEntityTableModel model = myTable.getModel();
    if (myUis == null || myRow < 0 || myRow >= model.getRowCount()) {
        return null;
    }
    final GradleEditorEntity entity = (GradleEditorEntity) model.getValueAt(myRow, 0);
    GradleEditorNotificationListener publisher = project.getMessageBus().syncPublisher(GradleEditorNotificationListener.TOPIC);
    publisher.beforeChange();
    try {
        WriteCommandAction.runWriteCommandAction(project, new Runnable() {

            @SuppressWarnings("unchecked")
            @Override
            public void run() {
                for (GradleEditorEntityUi ui : myUis) {
                    ui.flush(entity);
                }
            }
        });
    } finally {
        publisher.afterChange();
    }
    return entity;
}
Also used : GradleEditorNotificationListener(com.android.tools.idea.gradle.editor.GradleEditorNotificationListener) GradleEditorEntity(com.android.tools.idea.gradle.editor.entity.GradleEditorEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GradleEditorEntity

use of com.android.tools.idea.gradle.editor.entity.GradleEditorEntity in project android by JetBrains.

the class GradleEditorCellComponentImpl method bind.

@NotNull
@Override
@SuppressWarnings("unchecked")
public JComponent bind(@NotNull JTable table, @Nullable Object value, @NotNull Project project, int row, int column, boolean editing, boolean selected, boolean focus) {
    myUis = null;
    myRow = -1;
    myEditor = editing;
    if (!(value instanceof GradleEditorEntity)) {
        myLabel.setText(value == null ? "<null>" : value.toString());
        return myLabel;
    }
    GradleEditorEntity entity = (GradleEditorEntity) value;
    GradleEditorEntityUiRegistry registry = ServiceManager.getService(GradleEditorEntityUiRegistry.class);
    myUis = registry.getEntityUis(entity);
    myRow = row;
    JComponent component = null;
    for (GradleEditorEntityUi ui : myUis) {
        component = ui.getComponent(component, table, entity, project, editing, selected, focus, false, row, column);
    }
    myLabel.setText(" ");
    myPayloadWrapper.removeAll();
    if (editing) {
        myToolBarPanel.setVisible(true);
    }
    // Calculate sizes from either renderer or editor components and use their max width.
    assert component != null;
    Dimension size = component.getPreferredSize();
    JComponent component2 = null;
    for (GradleEditorEntityUi ui : myUis) {
        component2 = ui.getComponent(component2, table, entity, project, !editing, selected, focus, true, row, column);
    }
    assert component2 != null;
    Dimension size2 = component2.getPreferredSize();
    myPreferredSize = new Dimension(Math.max(size.width, size2.width), Math.max(size.height, size2.height));
    myHelpButton.setVisible(!Strings.isNullOrEmpty(entity.getHelpId()));
    myNavigateButton.setVisible(entity instanceof GradleEntityDefinitionValueLocationAware && ((GradleEntityDefinitionValueLocationAware) entity).getDefinitionValueLocation() != null);
    myRemoveButton.setVisible(entity.getMetaData().contains(StdGradleEditorEntityMetaData.REMOVABLE));
    myPayloadWrapper.add(component, myConstraints);
    final Color backgroundColor;
    if (entity.getMetaData().contains(StdGradleEditorEntityMetaData.INJECTED)) {
        backgroundColor = GradleEditorUiConstants.INJECTED_BACKGROUND_COLOR;
    } else if (entity.getMetaData().contains(StdGradleEditorEntityMetaData.OUTGOING)) {
        backgroundColor = GradleEditorUiConstants.OUTGOING_BACKGROUND_COLOR;
    } else {
        backgroundColor = GradleEditorUiConstants.BACKGROUND_COLOR;
    }
    List<JPanel> panels = UIUtil.findComponentsOfType(this, JPanel.class);
    for (JPanel panel : panels) {
        panel.setBackground(backgroundColor);
    }
    return this;
}
Also used : GradleEditorEntity(com.android.tools.idea.gradle.editor.entity.GradleEditorEntity) GradleEntityDefinitionValueLocationAware(com.android.tools.idea.gradle.editor.entity.GradleEntityDefinitionValueLocationAware) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GradleEditorEntity

use of com.android.tools.idea.gradle.editor.entity.GradleEditorEntity in project android by JetBrains.

the class GradleEditorEntityTable method isCellEditable.

@Override
public boolean isCellEditable(int row, int column) {
    Object value = getValueAt(row, column);
    if (!(value instanceof GradleEditorEntity)) {
        return false;
    }
    GradleEditorEntity entity = (GradleEditorEntity) value;
    return !entity.getMetaData().contains(StdGradleEditorEntityMetaData.READ_ONLY) && ServiceManager.getService(GradleEditorEntityUiRegistry.class).hasEntityUi(entity);
}
Also used : GradleEditorEntity(com.android.tools.idea.gradle.editor.entity.GradleEditorEntity)

Example 4 with GradleEditorEntity

use of com.android.tools.idea.gradle.editor.entity.GradleEditorEntity in project android by JetBrains.

the class GradleEditorComponent method addUiForGroup.

private void addUiForGroup(@NotNull GradleEditorEntityGroup group) {
    JBPanel panel = new JBPanel(new BorderLayout());
    panel.setBackground(UIUtil.getTableBackground());
    panel.setBorder(IdeBorderFactory.createTitledBorder(group.getName()));
    GradleEditorEntityTable table = new GradleEditorEntityTable(myProject);
    for (GradleEditorEntity entity : group.getEntities()) {
        table.getModel().add(entity);
    }
    panel.add(table);
    addUiForGroup(group.getName(), panel, table);
}
Also used : GradleEditorEntity(com.android.tools.idea.gradle.editor.entity.GradleEditorEntity) JBPanel(com.intellij.ui.components.JBPanel)

Example 5 with GradleEditorEntity

use of com.android.tools.idea.gradle.editor.entity.GradleEditorEntity in project android by JetBrains.

the class GradleEditorEntityTableModel method setData.

public void setData(@NotNull List<GradleEditorEntity> entities) {
    int i = 0;
    int rows = getRowCount();
    for (GradleEditorEntity entity : entities) {
        if (i < rows) {
            setValueAt(entity, i++, 0);
        } else {
            add(entity);
        }
    }
    if (rows > entities.size()) {
        for (int j = rows - 1; j >= entities.size(); j--) {
            removeRow(j);
        }
    }
}
Also used : GradleEditorEntity(com.android.tools.idea.gradle.editor.entity.GradleEditorEntity)

Aggregations

GradleEditorEntity (com.android.tools.idea.gradle.editor.entity.GradleEditorEntity)5 GradleEditorNotificationListener (com.android.tools.idea.gradle.editor.GradleEditorNotificationListener)1 GradleEntityDefinitionValueLocationAware (com.android.tools.idea.gradle.editor.entity.GradleEntityDefinitionValueLocationAware)1 JBPanel (com.intellij.ui.components.JBPanel)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1