private void refreshTable(final JBTable table, final PackageEntryTable packageTable) {
   AbstractTableModel model = (AbstractTableModel) table.getModel();
   table.createDefaultColumnsFromModel();
   model.fireTableDataChanged();
   ImportLayoutPanel.resizeColumns(
       packageTable, table, myImportLayoutPanel.areStaticImportsEnabled());
 }
Esempio n. 2
0
  private void refreshTable() {
    IDevice[] devices = myDetectedDevicesRef.get();
    myDisplayedDevices = devices;

    final IDevice[] selectedDevices = getSelectedDevices();
    final TIntArrayList selectedRows = new TIntArrayList();
    for (int i = 0; i < devices.length; i++) {
      if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) {
        selectedRows.add(i);
      }
    }

    myProcessSelectionFlag = false;
    myDeviceTable.setModel(new MyDeviceTableModel(devices));
    if (selectedRows.size() == 0 && devices.length > 0) {
      myDeviceTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    for (int selectedRow : selectedRows.toNativeArray()) {
      if (selectedRow < devices.length) {
        myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow);
      }
    }
    fireSelectedDevicesChanged();
    myProcessSelectionFlag = true;
    updatePreviouslySelectedSerials();
  }
 public FocusTracesDialog(Project project, ArrayList<FocusRequestInfo> requests) {
   super(project);
   myRequests = requests;
   setTitle("Focus Traces");
   init();
   final String[][] data = new String[requests.size()][];
   for (int i = 0; i < data.length; i++) {
     final FocusRequestInfo r = requests.get(i);
     data[i] =
         new String[] {
           r.getDate(), String.valueOf(r.isForced()), String.valueOf(r.getComponent())
         };
   }
   myRequestsTable.setModel(new DefaultTableModel(data, COLUMNS));
   final ListSelectionListener selectionListener =
       new ListSelectionListener() {
         @Override
         public void valueChanged(ListSelectionEvent e) {
           final int index = myRequestsTable.getSelectedRow();
           if (-1 < index && index < myRequests.size()) {
             myStacktrace.setText(myRequests.get(index).getStackTrace());
           } else {
             myStacktrace.setText("");
           }
         }
       };
   myRequestsTable.getSelectionModel().addListSelectionListener(selectionListener);
   final TableColumnModel columnModel = myRequestsTable.getColumnModel();
   columnModel.getColumn(0).setMaxWidth(120);
   columnModel.getColumn(1).setMaxWidth(60);
   columnModel.getSelectionModel().addListSelectionListener(selectionListener);
   columnModel.setColumnSelectionAllowed(false);
   myRequestsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   myRequestsTable.changeSelection(0, 0, false, true);
 }
 private void setFixedColumnWidth(final int columnIndex, String sampleText) {
   final TableColumn column =
       myEntryTable.getTableHeader().getColumnModel().getColumn(columnIndex);
   final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
   final int width = fontMetrics.stringWidth(" " + sampleText + " ") + JBUI.scale(4);
   column.setPreferredWidth(width);
   column.setMinWidth(width);
   column.setResizable(false);
 }
 public void selectElements(Collection<? extends Module> elements) {
   if (elements.size() == 0) {
     myTable.clearSelection();
     return;
   }
   final int[] rows = getElementsRows(elements);
   TableUtil.selectRows(myTable, rows);
   TableUtil.scrollSelectionToVisible(myTable);
   myTable.requestFocus();
 }
Esempio n. 6
0
 private void startEditingAtSelection() {
   myTable.editCellAt(myTable.getSelectedRow(), 2);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           if (myTable.isEditing()) {
             myTable.getEditorComponent().requestFocus();
           }
         }
       });
 }
  private int getPrevRow() {
    if (myTable.getSelectedRows().length == 0) return -1;
    int row = myTable.getSelectionModel().getLeadSelectionIndex();

    while (true) {
      if (row <= 0) return -1;
      row--;
      DirDiffElementImpl element = myModel.getElementAt(row);
      if (element == null) return -1;
      if (!element.isSeparator()) break;
    }

    return row;
  }
Esempio n. 8
0
 @Override
 protected void paintComponent(Graphics g) {
   if (myRepaintFreezedCounter.get() > 0) {
     return;
   }
   super.paintComponent(g);
 }
Esempio n. 9
0
 public void forceInitFromModel() {
   final int[] selection = myEntryTable.getSelectedRows();
   myModel.clear();
   myModel.init();
   myModel.fireTableDataChanged();
   TableUtil.selectRows(myEntryTable, selection);
 }
  private void doEdit() {
    final OrderEntry entry = getSelectedEntry();
    if (!(entry instanceof LibraryOrderEntry)) return;

    final Library library = ((LibraryOrderEntry) entry).getLibrary();
    if (library == null) {
      return;
    }
    final LibraryTable table = library.getTable();
    final String tableLevel =
        table != null ? table.getTableLevel() : LibraryTableImplUtil.MODULE_LEVEL;
    final LibraryTablePresentation presentation =
        LibraryEditingUtil.getLibraryTablePresentation(getProject(), tableLevel);
    final LibraryTableModifiableModelProvider provider = getModifiableModelProvider(tableLevel);
    EditExistingLibraryDialog dialog =
        EditExistingLibraryDialog.createDialog(
            this,
            provider,
            library,
            myState.getProject(),
            presentation,
            getStructureConfigurableContext());
    dialog.setContextModule(getRootModel().getModule());
    dialog.show();
    myEntryTable.repaint();
    ModuleStructureConfigurable.getInstance(myState.getProject()).getTree().repaint();
  }
 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 reset(CodeStyleSettings settings) {
    myCbUseFQClassNames.setSelected(settings.USE_FQ_CLASS_NAMES);
    myCbUseSingleClassImports.setSelected(settings.USE_SINGLE_CLASS_IMPORTS);
    myCbInsertInnerClassImports.setSelected(settings.INSERT_INNER_CLASS_IMPORTS);
    myClassCountField.setText(Integer.toString(settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND));
    myNamesCountField.setText(Integer.toString(settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND));

    myImportLayoutPanel.getImportLayoutList().copyFrom(settings.IMPORT_LAYOUT_TABLE);
    myPackageList.copyFrom(settings.PACKAGES_TO_USE_IMPORT_ON_DEMAND);
    myFqnInJavadocOption.reset(settings);

    myImportLayoutPanel
        .getCbLayoutStaticImportsSeparately()
        .setSelected(settings.LAYOUT_STATIC_IMPORTS_SEPARATELY);

    final JBTable importLayoutTable = myImportLayoutPanel.getImportLayoutTable();
    AbstractTableModel model = (AbstractTableModel) importLayoutTable.getModel();
    model.fireTableDataChanged();

    model = (AbstractTableModel) myPackageTable.getModel();
    model.fireTableDataChanged();

    if (importLayoutTable.getRowCount() > 0) {
      importLayoutTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    if (myPackageTable.getRowCount() > 0) {
      myPackageTable.getSelectionModel().setSelectionInterval(0, 0);
    }
  }
 public void refresh() {
   columnNames.clear();
   rows.clear();
   fireTableStructureChanged();
   table.setPaintBusy(true);
   RetrieveColumnNamesWorker worker =
       new RetrieveColumnNamesWorker(client, versionUrl, sObjectName);
   worker.execute();
 }
  private void updateEnabledState() {
    myLabelEditor.setEnabled(myRbExpressionLabel.isSelected());

    final boolean isChildrenExpression = myRbExpressionChildrenRenderer.isSelected();
    myChildrenExpandedEditor.setEnabled(isChildrenExpression);
    myExpandedLabel.setEnabled(isChildrenExpression);
    myChildrenEditor.setEnabled(isChildrenExpression);
    myTable.setEnabled(myRbListChildrenRenderer.isSelected());
  }
 @Override
 public void runClasspathPanelAction(Runnable action) {
   try {
     disableModelUpdate();
     action.run();
   } finally {
     enableModelUpdate();
     myEntryTable.requestFocus();
   }
 }
  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();
  }
Esempio n. 17
0
  private void resetSelection(@NotNull String[] selectedSerials) {
    MyDeviceTableModel model = (MyDeviceTableModel) myDeviceTable.getModel();
    Set<String> selectedSerialsSet = new HashSet<String>();
    Collections.addAll(selectedSerialsSet, selectedSerials);
    IDevice[] myDevices = model.myDevices;
    ListSelectionModel selectionModel = myDeviceTable.getSelectionModel();
    boolean cleared = false;

    for (int i = 0, n = myDevices.length; i < n; i++) {
      String serialNumber = myDevices[i].getSerialNumber();
      if (selectedSerialsSet.contains(serialNumber)) {
        if (!cleared) {
          selectionModel.clearSelection();
          cleared = true;
        }
        selectionModel.addSelectionInterval(i, i);
      }
    }
  }
 @Override
 public void setModel(@NotNull TableModel model) {
   super.setModel(model);
   // initialize sizes once, when the real model is set (not from the constructor).
   if (!myColumnsSizeInitialized && !(model instanceof DefaultTableModel)) {
     myColumnsSizeInitialized = true;
     setColumnPreferredSize();
     setAutoCreateColumnsFromModel(
         false); // otherwise sizes are recalculated after each TableColumn re-initialization
   }
 }
 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;
 }
Esempio n. 20
0
 private void changeOperationForSelection() {
   for (int row : myTable.getSelectedRows()) {
     if (row != -1) {
       final DirDiffElementImpl element = myModel.getElementAt(row);
       if (element != null) {
         element.setNextOperation();
         myModel.fireTableRowsUpdated(row, row);
       }
     }
   }
 }
Esempio n. 21
0
 @Override
 public void setModel(@NotNull TableModel model) {
   super.setModel(model);
   // initialize sizes once, when the real non-empty model is set
   if (!myColumnsSizeInitialized && model.getRowCount() > 0) {
     myColumnsSizeInitialized = true;
     setColumnPreferredSize();
     setAutoCreateColumnsFromModel(
         false); // otherwise sizes are recalculated after each TableColumn re-initialization
   }
 }
 public void selectOrderEntry(@NotNull OrderEntry entry) {
   for (int row = 0; row < myModel.getRowCount(); row++) {
     final OrderEntry orderEntry = getItemAt(row).getEntry();
     if (orderEntry != null
         && entry.getPresentableName().equals(orderEntry.getPresentableName())) {
       myEntryTable.getSelectionModel().setSelectionInterval(row, row);
       TableUtil.scrollSelectionToVisible(myEntryTable);
     }
   }
   IdeFocusManager.getInstance(myState.getProject()).requestFocus(myEntryTable, true);
 }
Esempio n. 23
0
 private void updateButtons() {
   final int[] selectedRows = myEntryTable.getSelectedRows();
   boolean removeButtonEnabled = true;
   int minRow = myEntryTable.getRowCount() + 1;
   int maxRow = -1;
   for (final int selectedRow : selectedRows) {
     minRow = Math.min(minRow, selectedRow);
     maxRow = Math.max(maxRow, selectedRow);
     final ClasspathTableItem<?> item = myModel.getItemAt(selectedRow);
     if (!item.isRemovable()) {
       removeButtonEnabled = false;
     }
   }
   if (myRemoveButton != null) {
     myRemoveButton.setEnabled(removeButtonEnabled && selectedRows.length > 0);
   }
   ClasspathTableItem<?> selectedItem =
       selectedRows.length == 1 ? myModel.getItemAt(selectedRows[0]) : null;
   myEditButton.setEnabled(selectedItem != null && selectedItem.isEditable());
 }
  private void createParametersPanel() {
    myParameterModel = new GrParameterTableModel(myMethod, this, myProject);
    myParameterModel.addTableModelListener(
        new TableModelListener() {
          public void tableChanged(TableModelEvent e) {
            updateSignature();
          }
        });
    myParameterTable = new JBTable(myParameterModel);
    myParameterTable.setPreferredScrollableViewportSize(
        new Dimension(550, myParameterTable.getRowHeight() * 8));

    myParameterButtonPanel =
        EditableRowTable.createButtonsTable(myParameterTable, myParameterModel, true);

    myParameterTable.setCellSelectionEnabled(true);
    final TableColumnModel columnModel = myParameterTable.getColumnModel();
    columnModel.getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    columnModel.getColumn(1).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));
    columnModel.getColumn(2).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));
    columnModel.getColumn(3).setCellRenderer(new GrCodeFragmentTableCellRenderer(myProject));

    columnModel.getColumn(0).setCellEditor(new JavaCodeFragmentTableCellEditor(myProject));
    columnModel.getColumn(1).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));
    columnModel.getColumn(2).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));
    columnModel.getColumn(3).setCellEditor(new GrCodeFragmentTableCellEditor(myProject));

    if (myParameterModel.getRowCount() > 0) {
      myParameterTable.setRowSelectionInterval(0, 0);
      myParameterTable.setColumnSelectionInterval(0, 0);
    }
  }
  private void createExceptionsPanel() {
    myExceptionTableModel = new ExceptionsTableModel(myMethod);
    myExceptionTableModel.setTypeInfos(myMethod);
    myExceptionTableModel.addTableModelListener(
        new TableModelListener() {
          public void tableChanged(TableModelEvent e) {
            updateSignature();
          }
        });
    myExceptionsTable = new JBTable(myExceptionTableModel);
    myExceptionsTable.setPreferredScrollableViewportSize(
        new Dimension(200, myExceptionsTable.getRowHeight() * 8));

    myExceptionsButtonPanel = ToolbarDecorator.createDecorator(myExceptionsTable).createPanel();

    myExceptionsTable
        .getColumnModel()
        .getColumn(0)
        .setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    myExceptionsTable
        .getColumnModel()
        .getColumn(0)
        .setCellEditor(new JavaCodeFragmentTableCellEditor(myProject));

    if (myExceptionTableModel.getRowCount() > 0) {
      myExceptionsTable.setRowSelectionInterval(0, 0);
      myExceptionsTable.setColumnSelectionInterval(0, 0);
    }
  }
Esempio n. 26
0
 private void moveSelectedRows(int increment) {
   if (increment == 0) {
     return;
   }
   if (myEntryTable.isEditing()) {
     myEntryTable.getCellEditor().stopCellEditing();
   }
   final ListSelectionModel selectionModel = myEntryTable.getSelectionModel();
   for (int row = increment < 0 ? 0 : myModel.getRowCount() - 1;
       increment < 0 ? row < myModel.getRowCount() : row >= 0;
       row += increment < 0 ? +1 : -1) {
     if (selectionModel.isSelectedIndex(row)) {
       final int newRow = moveRow(row, increment);
       selectionModel.removeSelectionInterval(row, row);
       selectionModel.addSelectionInterval(newRow, newRow);
     }
   }
   myModel.fireTableRowsUpdated(0, myModel.getRowCount() - 1);
   Rectangle cellRect = myEntryTable.getCellRect(selectionModel.getMinSelectionIndex(), 0, true);
   if (cellRect != null) {
     myEntryTable.scrollRectToVisible(cellRect);
   }
   myEntryTable.repaint();
   myListeners.getMulticaster().entryMoved();
 }
Esempio n. 27
0
 @NotNull
 public IDevice[] getSelectedDevices() {
   int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
   List<IDevice> result = new ArrayList<IDevice>();
   for (int row : rows) {
     if (row >= 0) {
       Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
       final AndroidDebugBridge bridge =
           AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
       if (bridge == null) {
         return EMPTY_DEVICE_ARRAY;
       }
       IDevice[] devices = getFilteredDevices(bridge);
       for (IDevice device : devices) {
         if (device.getSerialNumber().equals(serial.toString())) {
           result.add(device);
           break;
         }
       }
     }
   }
   return result.toArray(new IDevice[result.size()]);
 }
 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);
   }
 }
 public void forceInitFromModel() {
   Set<ClasspathTableItem<?>> oldSelection = new HashSet<ClasspathTableItem<?>>();
   for (int i : myEntryTable.getSelectedRows()) {
     ContainerUtil.addIfNotNull(getItemAt(i), oldSelection);
   }
   myModel.clear();
   myModel.init();
   myModel.fireTableDataChanged();
   TIntArrayList newSelection = new TIntArrayList();
   for (int i = 0; i < myModel.getRowCount(); i++) {
     if (oldSelection.contains(getItemAt(i))) {
       newSelection.add(i);
     }
   }
   TableUtil.selectRows(myEntryTable, newSelection.toNativeArray());
 }
Esempio n. 30
0
  @Override
  public void addItems(List<ClasspathTableItem<?>> toAdd) {
    for (ClasspathTableItem<?> item : toAdd) {
      myModel.addItem(item);
    }
    myModel.fireTableDataChanged();
    final ListSelectionModel selectionModel = myEntryTable.getSelectionModel();
    selectionModel.setSelectionInterval(
        myModel.getRowCount() - toAdd.size(), myModel.getRowCount() - 1);
    TableUtil.scrollSelectionToVisible(myEntryTable);

    final StructureConfigurableContext context =
        ModuleStructureConfigurable.getInstance(myState.getProject()).getContext();
    context
        .getDaemonAnalyzer()
        .queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule()));
  }