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;
}
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;
}
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);
}
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);
}
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);
}
}
}
Aggregations