@Override public void run(AnActionButton button) { int row = table.getEditingRow(); int col = table.getEditingColumn(); TableUtil.stopEditing(table); int[] idx = table.getSelectedRows(); Arrays.sort(idx); if (delta > 0) { idx = ArrayUtil.reverseArray(idx); } if (idx.length == 0) return; if (idx[0] + delta < 0) return; if (idx[idx.length - 1] + delta > table.getModel().getRowCount()) return; for (int i = 0; i < idx.length; i++) { tableModel.exchangeRows(idx[i], idx[i] + delta); idx[i] += delta; } TableUtil.selectRows(table, idx); table.requestFocus(); if (row > 0 && col != -1) { table.editCellAt(row - 1, col); } }
public void selectElements(Collection<? extends T> elements) { if (elements.size() == 0) { myTable.clearSelection(); return; } final int[] rows = getElementsRows(elements); TableUtil.selectRows(myTable, rows); TableUtil.scrollSelectionToVisible(myTable); myTable.requestFocus(); }
public void forceInitFromModel() { final int[] selection = myEntryTable.getSelectedRows(); myModel.clear(); myModel.init(); myModel.fireTableDataChanged(); TableUtil.selectRows(myEntryTable, selection); }
@Override public void addItems(List<ClasspathTableItem<?>> toAdd) { for (ClasspathTableItem<?> item : toAdd) { myModel.addRow(item); } TIntArrayList toSelect = new TIntArrayList(); for (int i = myModel.getRowCount() - toAdd.size(); i < myModel.getRowCount(); i++) { toSelect.add(myEntryTable.convertRowIndexToView(i)); } TableUtil.selectRows(myEntryTable, toSelect.toNativeArray()); TableUtil.scrollSelectionToVisible(myEntryTable); final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext(); context .getDaemonAnalyzer() .queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule())); }
@Override protected void selectElement(Object element, String selectedText) { List<UsageNode> data = ((MyModel) getTable().getModel()).getItems(); int i = data.indexOf(element); if (i == -1) return; final int viewRow = getTable().convertRowIndexToView(i); getTable().getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(getTable()); }
private void addInjection(final BaseInjection injection) { final InjInfo info = getDefaultCfgInfo().addInjection(injection); myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); final int index = myInjectionsTable.convertRowIndexToView( myInjectionsTable.getListTableModel().getItems().indexOf(info)); myInjectionsTable.getSelectionModel().setSelectionInterval(index, index); TableUtil.scrollSelectionToVisible(myInjectionsTable); }
public void saveData() { TableUtil.stopEditing(myTable); final int count = myTable.getRowCount(); String[] urls = ArrayUtil.newStringArray(count); for (int row = 0; row < count; row++) { final TableItem item = ((MyTableModel) myTable.getModel()).getTableItemAt(row); urls[row] = item.getUrl(); } getModel().setRootUrls(AnnotationOrderRootType.getInstance(), urls); }
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); }
private void performRemove() { final int selectedRow = myInjectionsTable.getSelectedRow(); if (selectedRow < 0) return; final List<InjInfo> selected = getSelectedInjections(); for (InjInfo info : selected) { if (info.bundled) continue; info.cfgInfo.injectionInfos.remove(info); } myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); final int index = Math.min(myInjectionsTable.getListTableModel().getRowCount() - 1, selectedRow); myInjectionsTable.getSelectionModel().setSelectionInterval(index, index); TableUtil.scrollSelectionToVisible(myInjectionsTable); updateCountLabel(); }
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()); }
@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())); }
private void removeSelectedItems(final List removedRows) { if (removedRows.isEmpty()) { return; } for (final Object removedRow : removedRows) { final ClasspathTableItem<?> item = (ClasspathTableItem<?>) ((Object[]) removedRow)[ClasspathTableModel.ITEM_COLUMN]; final OrderEntry orderEntry = item.getEntry(); if (orderEntry == null) { continue; } getRootModel().removeOrderEntry(orderEntry); } final int[] selectedRows = myEntryTable.getSelectedRows(); myModel.fireTableDataChanged(); TableUtil.selectRows(myEntryTable, selectedRows); final StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myState.getProject()).getContext(); context .getDaemonAnalyzer() .queueUpdate(new ModuleProjectStructureElement(context, getRootModel().getModule())); }
public void stopEditing() { TableUtil.stopEditing(myEntryTable); }
private InjectionsTable(final List<InjInfo> injections) { super(new ListTableModel<InjInfo>(createInjectionColumnInfos(), injections, 1)); setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN); getColumnModel().getColumn(2).setCellRenderer(createLanguageCellRenderer()); getColumnModel().getColumn(1).setCellRenderer(createDisplayNameCellRenderer()); getColumnModel().getColumn(0).setResizable(false); setShowGrid(false); setShowVerticalLines(false); setGridColor(getForeground()); TableUtil.setupCheckboxColumn(getColumnModel().getColumn(0)); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { final int row = rowAtPoint(e.getPoint()); if (row < 0) return false; if (columnAtPoint(e.getPoint()) <= 0) return false; myInjectionsTable.getSelectionModel().setSelectionInterval(row, row); performEditAction(); return true; } }.installOn(this); final String[] maxName = new String[] {""}; ContainerUtil.process( injections, new Processor<InjInfo>() { public boolean process(final InjInfo injection) { String languageId = injection.injection.getInjectedLanguageId(); Language language = InjectedLanguage.findLanguageById(languageId); String displayName = language == null ? languageId : language.getDisplayName(); if (maxName[0].length() < displayName.length()) maxName[0] = displayName; return true; } }); ContainerUtil.process( InjectedLanguage.getAvailableLanguages(), new Processor<Language>() { public boolean process(final Language language) { String displayName = language.getDisplayName(); if (maxName[0].length() < displayName.length()) maxName[0] = displayName; return true; } }); Icon icon = FileTypes.PLAIN_TEXT.getIcon(); int preferred = (int) (new JLabel(maxName[0], icon, SwingConstants.LEFT).getPreferredSize().width * 1.1); getColumnModel().getColumn(2).setMinWidth(preferred); getColumnModel().getColumn(2).setPreferredWidth(preferred); getColumnModel().getColumn(2).setMaxWidth(preferred); new TableViewSpeedSearch<InjInfo>(this) { @Override protected String getItemText(@NotNull InjInfo element) { final BaseInjection injection = element.injection; return injection.getSupportId() + " " + injection.getInjectedLanguageId() + " " + injection.getDisplayName(); } }; }
private void stopTableEditing() { TableUtil.stopEditing(myImportLayoutPanel.getImportLayoutTable()); TableUtil.stopEditing(myPackageTable); }
public void restoreSelection() { if (mySavedSelection != null) { TableUtil.selectRows(myTable, mySavedSelection); mySavedSelection = null; } }