public void setAllElementsMarked(boolean marked) { final int[] rows = new int[myTableModel.getRowCount()]; for (int idx = 0; idx < rows.length; idx++) { rows[idx] = idx; } myTableModel.setMarked(rows, marked); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Color color = UIUtil.getTableFocusCellBackground(); Component component; T t = (T) value; try { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground()); component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setText(t != null ? getItemText(t) : ""); if (component instanceof JLabel) { ((JLabel) component).setBorder(noFocusBorder); } } finally { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } final MyTableModel model = (MyTableModel) table.getModel(); component.setEnabled( ElementsChooser.this.isEnabled() && (myColorUnmarkedElements ? model.isElementMarked(row) : true)); final ElementProperties properties = myElementToPropertiesMap.get(t); if (component instanceof JLabel) { final Icon icon = properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null; JLabel label = (JLabel) component; label.setIcon(icon); label.setDisabledIcon(icon); } component.setForeground( properties != null && properties.getColor() != null ? properties.getColor() : (isSelected ? table.getSelectionForeground() : table.getForeground())); return component; }
protected DefaultTableModel createModel() { final MyTableModel tableModel = new MyTableModel(); final String[] urls = getModel().getRootUrls(AnnotationOrderRootType.getInstance()); for (String javadocUrl : urls) { tableModel.addTableItem(new TableItem(javadocUrl)); } return tableModel; }
@NotNull public List<T> getMarkedElements() { final int count = myTableModel.getRowCount(); List<T> elements = new ArrayList<T>(); for (int idx = 0; idx < count; idx++) { final T element = myTableModel.getElementAt(idx); if (myTableModel.isElementMarked(idx)) { elements.add(element); } } return elements; }
public void moveElement(T element, int newRow) { final int elementRow = myTableModel.getElementRow(element); if (elementRow < 0 || elementRow == newRow || newRow < 0 || newRow >= myTableModel.getRowCount()) { return; } final boolean wasSelected = myTable.getSelectionModel().isSelectedIndex(elementRow); myTableModel.changeElementRow(element, newRow); if (wasSelected) { selectRow(newRow); } }
private int[] getElementsRows(final Collection<? extends T> elements) { final int[] rows = new int[elements.size()]; int index = 0; for (final T element : elements) { rows[index++] = myTable.convertRowIndexToView(myTableModel.getElementRow(element)); } return rows; }
public void removeElement(T element) { final int elementRow = myTableModel.getElementRow(element); if (elementRow < 0) { return; // no such element } final boolean wasSelected = myTable.getSelectionModel().isSelectedIndex(elementRow); myTableModel.removeElement(element); myElementToPropertiesMap.remove(element); if (wasSelected) { final int rowCount = myTableModel.getRowCount(); if (rowCount > 0) { selectRow(elementRow % rowCount); } else { myTable.getSelectionModel().clearSelection(); } } myTable.requestFocus(); }
@NotNull public List<T> getSelectedElements() { final List<T> elements = new ArrayList<T>(); final int[] selectedRows = myTable.getSelectedRows(); for (int selectedRow : selectedRows) { if (selectedRow < 0) { continue; } elements.add(myTableModel.getElementAt(selectedRow)); } return elements; }
private void restoreDefaults() { final int r = Messages.showYesNoDialog( myContent, "Are you sure you want to revert registry settings to default values?", "Revert To Defaults", Messages.getQuestionIcon()); if (r == 0) { Registry.getInstance().restoreDefaults(); myModel.fireChanged(); revaliateActions(); } }
public void refresh(T element) { final int row = myTableModel.getElementRow(element); if (row >= 0) { myTableModel.fireTableRowsUpdated(row, row); } }
public int getElementCount() { return myTableModel.getRowCount(); }
public T getElementAt(int row) { return myTableModel.getElementAt(row); }
/** * Check if element is marked * * @param element an element to test * @return true if element is marked */ public boolean isElementMarked(T element) { final int elementRow = myTableModel.getElementRow(element); return myTableModel.isElementMarked(elementRow); }
public void clear() { myTableModel.clear(); myElementToPropertiesMap.clear(); }
public void sort(Comparator<T> comparator) { myTableModel.sort(comparator); }
public void setEnabled(boolean enabled) { super.setEnabled(enabled); myTable.setRowSelectionAllowed(enabled); myTableModel.fireTableDataChanged(); }
public void markElements(Collection<T> elements) { myTableModel.setMarked(getElementsRows(elements), true); }
/** * Check if element is marked * * @param element an element to test * @param marked a new value of mark. */ public void setElementMarked(T element, boolean marked) { final int elementRow = myTableModel.getElementRow(element); myTableModel.setMarked(elementRow, marked); }
public void removeAllElements() { myTableModel.removeAllElements(); myTable.getSelectionModel().clearSelection(); }
public void refresh() { myTableModel.fireTableDataChanged(); }
@Nullable public T getSelectedElement() { final int selectedRow = getSelectedElementRow(); return selectedRow < 0 ? null : myTableModel.getElementAt(selectedRow); }
public void setElements(List<T> elements, boolean marked) { myTableModel.clear(); myTableModel.addElements(elements, marked); }
public void addElement(T element, final boolean isMarked, ElementProperties elementProperties) { myTableModel.addElement(element, isMarked); myElementToPropertiesMap.put(element, elementProperties); selectRow(myTableModel.getRowCount() - 1); myTable.requestFocus(); }