use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.
the class NlPropertiesGrouper method group.
public List<PTableItem> group(@NotNull List<NlPropertyItem> properties, @NotNull List<NlComponent> components) {
String className = getCommonTagName(components);
List<PTableItem> result = Lists.newArrayListWithExpectedSize(properties.size());
// group theme attributes together
NlPropertyAccumulator themePropertiesAccumulator = new NlPropertyAccumulator("Theme", p -> p != null && (p.getParentStylables().contains("Theme") || p.getName().equalsIgnoreCase("theme")));
// Disable this for now...
//
// group attributes that correspond to this component together
//NlPropertyAccumulator customViewPropertiesAccumulator = null;
//if (className != null) {
// customViewPropertiesAccumulator = new NlPropertyAccumulator(className, p -> p != null && p.getParentStylables().contains(className));
//}
// group margin, padding and layout attributes together
NlPropertyAccumulator paddingPropertiesAccumulator = new NlMarginPropertyAccumulator("Padding", ATTR_PADDING, ATTR_PADDING_LEFT, ATTR_PADDING_RIGHT, ATTR_PADDING_START, ATTR_PADDING_END, ATTR_PADDING_TOP, ATTR_PADDING_BOTTOM);
NlPropertyAccumulator layoutViewPropertiesAccumulator = new NlMarginPropertyAccumulator("Layout_Margin", ATTR_LAYOUT_MARGIN, ATTR_LAYOUT_MARGIN_LEFT, ATTR_LAYOUT_MARGIN_RIGHT, ATTR_LAYOUT_MARGIN_START, ATTR_LAYOUT_MARGIN_END, ATTR_LAYOUT_MARGIN_TOP, ATTR_LAYOUT_MARGIN_BOTTOM);
PropertyNamePrefixAccumulator constraintPropertiesAccumulator = new PropertyNamePrefixAccumulator("Constraints", "layout_constraint");
List<NlPropertyAccumulator> accumulators = Lists.newArrayList(themePropertiesAccumulator, paddingPropertiesAccumulator, layoutViewPropertiesAccumulator, constraintPropertiesAccumulator);
for (NlPropertyItem p : properties) {
boolean added = false;
for (NlPropertyAccumulator accumulator : accumulators) {
added = accumulator.process(p);
if (added) {
break;
}
}
if (!added) {
result.add(p);
}
}
int insertionPoint = findInsertionPoint(result);
for (NlPropertyAccumulator accumulator : accumulators) {
if (accumulator.hasItems()) {
result.add(insertionPoint, accumulator.getGroupNode());
}
}
return result;
}
use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.
the class PNameRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(@NotNull JTable table, @NotNull Object value, boolean isSelected, boolean cellHasFocus, int row, int column) {
myRenderer.clear();
PTable ptable = (PTable) table;
PTableItem item = (PTableItem) value;
myRenderer.getTableCellRendererComponent(table, value, isSelected, cellHasFocus, row, column);
myRenderer.setBackground(isSelected ? UIUtil.getTableSelectionBackground() : table.getBackground());
boolean hoveringOnStar = ptable.isHover(row, column) && hitTestStarIcon(ptable.getHoverPosition().x);
myStarLabel.setIcon(getStar(item.getStarState(), isSelected, hoveringOnStar));
myPanel.setBackground(isSelected ? UIUtil.getTableSelectionBackground() : table.getBackground());
SimpleTextAttributes attr = SimpleTextAttributes.REGULAR_ATTRIBUTES;
SearchUtil.appendFragments(((PTable) table).getSpeedSearch().getEnteredPrefix(), item.getName(), attr.getStyle(), attr.getFgColor(), attr.getBgColor(), myRenderer);
myRenderer.setToolTipText(item.getTooltipText());
return myPanel;
}
use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.
the class NlPropertiesPanel method setFilter.
public void setFilter(@NotNull String filter) {
int selectedRow = myTable.getSelectedRow();
PTableItem selectedItem = myTable.getSelectedItem();
if (filter.isEmpty()) {
myTable.setRowSorter(null);
} else {
myFilter.setPattern(filter);
myRowSorter.setModel(myModel);
myRowSorter.setRowFilter(myFilter);
myRowSorter.setSortKeys(null);
myTable.setRowSorter(myRowSorter);
}
myTable.restoreSelection(selectedRow, selectedItem);
myInspectorPanel.setFilter(filter);
}
use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.
the class NlPropertiesPanel method setItems.
public void setItems(@NotNull List<NlComponent> components, @NotNull Table<String, String, NlPropertyItem> properties, @NotNull NlPropertiesManager propertiesManager) {
myComponents = components;
myProperties = extractPropertiesForTable(properties);
List<PTableItem> groupedProperties;
if (components.isEmpty()) {
groupedProperties = Collections.emptyList();
} else {
List<NlPropertyItem> sortedProperties = new NlPropertiesSorter().sort(myProperties, components);
groupedProperties = new NlPropertiesGrouper().group(sortedProperties, components);
}
if (myTable.isEditing()) {
myTable.removeEditor();
}
int selectedRow = myTable.getSelectedRow();
PTableItem selectedItem = myTable.getSelectedItem();
myModel.setItems(groupedProperties);
if (myTable.getRowCount() > 0) {
myTable.restoreSelection(selectedRow, selectedItem);
}
updateDefaultProperties(propertiesManager);
myInspectorPanel.setComponent(components, properties, propertiesManager);
myTablePanel.setVisible(!groupedProperties.isEmpty());
}
use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.
the class NlPropertiesPanelTest method testFilterChildIsNotAMatch.
public void testFilterChildIsNotAMatch() {
PTableItem item = mock(PTableItem.class);
PTableGroupItem group = mock(PTableGroupItem.class);
when(item.getName()).thenReturn("top");
when(item.getParent()).thenReturn(item);
when(group.getName()).thenReturn("padding");
when(group.getChildren()).thenReturn(ImmutableList.of(item));
when(myEntry.getValue(0)).thenReturn(group);
NlPropertiesPanel.MyFilter filter = new NlPropertiesPanel.MyFilter();
filter.setPattern("bott");
assertFalse(filter.include(myEntry));
}
Aggregations