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;
 }
 public List<Pair<Module, String>> getAllModules() {
   final int count = myTableModel.getRowCount();
   List<Pair<Module, String>> elements = new ArrayList<Pair<Module, String>>();
   for (int idx = 0; idx < count; idx++) {
     final Module module = myTableModel.getModuleAt(idx);
     elements.add(Pair.create(module, myTableModel.getGenDirName(module)));
   }
   return elements;
 }
 @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;
 }
예제 #6
0
    @Override
    public Component getTableCellEditorComponent(
        JTable table, Object value, boolean isSelected, int row, int column) {
      MyTableModel tableModel = (MyTableModel) table.getModel();
      DefaultComboBoxModel comboModel = new DefaultComboBoxModel();

      for (ValidationResult.Option each : tableModel.getOptions(row)) {
        comboModel.addElement(each);
      }
      ((JComboBox) editorComponent).setModel(comboModel);

      return super.getTableCellEditorComponent(table, value, isSelected, row, column);
    }
 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);
   }
 }
예제 #8
0
 public void actionPerformed(ActionEvent e) {
   VirtualFile[] files = getFiles();
   final MyTableModel tableModel = (MyTableModel) myTable.getModel();
   boolean changes = false;
   for (final VirtualFile file : files) {
     if (file != null) {
       tableModel.addTableItem(new TableItem(file));
       changes = true;
     }
   }
   if (changes) {
     saveData();
     TableUtil.selectRows(myTable, new int[] {tableModel.getRowCount() - 1});
   }
 }
 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;
 }
 private int[] getElementsRows(final Collection<? extends Module> elements) {
   final int[] rows = new int[elements.size()];
   int index = 0;
   for (final Module element : elements) {
     rows[index++] = myTableModel.getElementRow(element);
   }
   return rows;
 }
  public void removeModule(Module element) {
    final int elementRow = myTableModel.getElementRow(element);
    if (elementRow < 0) {
      return; // no such element
    }
    final boolean wasSelected = myTable.getSelectionModel().isSelectedIndex(elementRow);

    myTableModel.removeElement(element);

    if (wasSelected) {
      final int rowCount = myTableModel.getRowCount();
      if (rowCount > 0) {
        selectRow(elementRow % rowCount);
      } else {
        myTable.getSelectionModel().clearSelection();
      }
    }
    myTable.requestFocus();
  }
 public List<Module> getSelectedElements() {
   final List<Module> elements = new ArrayList<Module>();
   final int[] selectedRows = myTable.getSelectedRows();
   for (int selectedRow : selectedRows) {
     if (selectedRow < 0) {
       continue;
     }
     elements.add(myTableModel.getModuleAt(selectedRow));
   }
   return elements;
 }
예제 #13
0
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      Component result =
          super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      if (!isSelected) {
        MyTableModel tableModel = (MyTableModel) table.getModel();
        Color color = table.getBackground();

        switch (tableModel.getKind(row)) {
          case ERROR:
            color = new Color(255, 175, 175);
            break;
          case CONFLICT:
            color = new Color(255, 240, 240);
            break;
        }
        result.setBackground(color);
      }
      return result;
    }
예제 #14
0
 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();
   }
 }
예제 #15
0
        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
          MyTableModel model = (MyTableModel) getModel();
          if (column == 0) {
            // JXTable default renderer doesn't align right
            DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
            renderer.setToolTipText(model.getToolTipText(row));
            renderer.setHorizontalAlignment(JLabel.RIGHT);
            if (model.isExpert(row, column)) {
              renderer.setForeground(Color.GRAY);
            }
            return renderer;
          }

          // code repetition with getCellEditor because of TableCell{Renderer, Editor}
          // non-inheritance
          Class<?> klass = model.getClassAt(row, column);
          PropertyEditorTableAdapter javaBeansRenderer = PropertyEditorTableAdapter.forClass(klass);
          if (javaBeansRenderer != null) {
            return javaBeansRenderer;
          }
          return getDefaultRenderer(klass);
        }
예제 #16
0
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
          MyTableModel model = (MyTableModel) getModel();
          if (column == 0) {
            return null;
          }

          // code repetition with getCellRenderer because of TableCell{Renderer, Editor}
          // non-inheritance
          Class<?> klass = model.getClassAt(row, column);
          PropertyEditorTableAdapter javaBeansEditor = PropertyEditorTableAdapter.forClass(klass);
          if (javaBeansEditor != null) {
            return javaBeansEditor;
          }
          TableCellEditor defaultEditor = getDefaultEditor(klass);
          if (defaultEditor == null) {
            log.warning("No TableCellEditor for " + klass.getName());
          }
          if (defaultEditor instanceof DefaultCellEditor) {
            // default double-click is bad user interaction
            ((DefaultCellEditor) defaultEditor).setClickCountToStart(0);
          }
          return defaultEditor;
        }
 public Module getElementAt(int row) {
   return myTableModel.getModuleAt(row);
 }
 public int getElementCount() {
   return myTableModel.getRowCount();
 }
 public void clear() {
   myTableModel.clear();
 }
 public void setEnabled(boolean enabled) {
   super.setEnabled(enabled);
   myTable.setRowSelectionAllowed(enabled);
   myTableModel.fireTableDataChanged();
 }
 public void sort(Comparator<Module> comparator) {
   myTableModel.sort(comparator);
 }
 @Nullable
 public Module getSelectedElement() {
   final int selectedRow = getSelectedElementRow();
   return selectedRow < 0 ? null : myTableModel.getModuleAt(selectedRow);
 }
 public void setElements(List<T> elements, boolean marked) {
   myTableModel.clear();
   myTableModel.addElements(elements, marked);
 }
 public void markElements(Collection<T> elements) {
   myTableModel.setMarked(getElementsRows(elements), true);
 }
 public void removeAllElements() {
   myTableModel.removeAllElements();
   myTable.getSelectionModel().clearSelection();
 }
 public void addModule(Module element, String dirName) {
   myTableModel.addElement(element, dirName);
   selectRow(myTableModel.getRowCount() - 1);
   myTable.requestFocus();
 }
 public void refresh(Module element) {
   final int row = myTableModel.getElementRow(element);
   if (row >= 0) {
     myTableModel.fireTableRowsUpdated(row, row);
   }
 }
 public void refresh() {
   myTableModel.fireTableDataChanged();
 }
 public void clear() {
   myTableModel.clear();
   myElementToPropertiesMap.clear();
 }
 public T getElementAt(int row) {
   return myTableModel.getElementAt(row);
 }