Search in sources :

Example 1 with GradleEntityDefinitionValueLocationAware

use of com.android.tools.idea.gradle.editor.entity.GradleEntityDefinitionValueLocationAware 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)

Aggregations

GradleEditorEntity (com.android.tools.idea.gradle.editor.entity.GradleEditorEntity)1 GradleEntityDefinitionValueLocationAware (com.android.tools.idea.gradle.editor.entity.GradleEntityDefinitionValueLocationAware)1 NotNull (org.jetbrains.annotations.NotNull)1