void restore() { final int newRowCount = myTable.getRowCount(); if (newRowCount == 0) return; int row = Math.min(newRowCount < rowCount ? selectedRow : selectedRow + 1, newRowCount - 1); final DirDiffElementImpl element = getElementAt(row); if (element != null && element.isSeparator()) { if (getElementAt(row +1) != null) { row += 1; } else { row -= 1; } } final DirDiffElementImpl el = getElementAt(row); row = el == null || el.isSeparator() ? 0 : row; myTable.getSelectionModel().setSelectionInterval(row, row); TableUtil.scrollSelectionToVisible(myTable); }
public PluginUpdateInfoPanel() { myPluginsToUpdateLabel.setVisible(true); myPluginsPanel.setVisible(true); final DetectedPluginsPanel foundPluginsPanel = new DetectedPluginsPanel(); foundPluginsPanel.addAll(myUploadedPlugins); TableUtil.ensureSelectionExists(foundPluginsPanel.getEntryTable()); foundPluginsPanel.addStateListener(new DetectedPluginsPanel.Listener() { @Override public void stateChanged() { final Set<String> skipped = foundPluginsPanel.getSkippedPlugins(); final PluginDownloader any = ContainerUtil.find(myUploadedPlugins, new Condition<PluginDownloader>() { @Override public boolean value(PluginDownloader plugin) { return !skipped.contains(plugin.getPluginId()); } }); getOKAction().setEnabled(any != null); } }); myPluginsPanel.add(foundPluginsPanel, BorderLayout.CENTER); configureMessageArea(myMessageArea); }
@Nullable @Override protected JComponent createCenterPanel() { final DetectedPluginsPanel foundPluginsPanel = new DetectedPluginsPanel() { @Override protected Set<String> getSkippedPlugins() { return mySkippedPlugins; } }; for (PluginDownloader uploadedPlugin : myUploadedPlugins) { foundPluginsPanel.add(uploadedPlugin); } TableUtil.ensureSelectionExists(foundPluginsPanel.getEntryTable()); return foundPluginsPanel; }
private void select(@NotNull VirtualFile toSelect, final TreeNode root) { for (int i = 0; i < root.getChildCount(); i++) { TreeNode child = root.getChildAt(i); VirtualFile file = ((FileNode)child).getObject(); if (VfsUtilCore.isAncestor(file, toSelect, false)) { if (Comparing.equal(file, toSelect)) { TreeUtil.selectNode(getTree(), child); getSelectionModel().clearSelection(); addSelectedPath(TreeUtil.getPathFromRoot(child)); TableUtil.scrollSelectionToVisible(this); } else { select(toSelect, child); } return; } } }
public void loadValues(AbstractProperty.AbstractPropertyContainer container) { if (myColumnWidthProperty != null) { BaseTableView.restoreWidth(myColumnWidthProperty.get(container), getComponent().getColumnModel()); } myModel.setItems(myProperty.getModifiableList(container)); if (myModel.isSortable()) { final ColumnInfo[] columnInfos = myModel.getColumnInfos(); int sortByColumn = -1; for (int idx = 0; idx < columnInfos.length; idx++) { ColumnInfo columnInfo = columnInfos[idx]; if (columnInfo.isSortable()) { sortByColumn = idx; break; } } } TableUtil.ensureSelectionExists(getComponent()); }
public AbstractTypeSelectionTable(Collection<M> memberInfos, @Nullable TypeInfoModel<T, M> memberInfoModel) { myTableModel = new MyTableModel<T, M>(this); myTypesInfos = new ArrayList<M>(memberInfos); if (memberInfoModel != null) { myTypeInfoModel = memberInfoModel; } else { myTypeInfoModel = new DefaultTypeInfoModel<T, M>(); } setModel(myTableModel); TableColumnModel model = getColumnModel(); model.getColumn(DISPLAY_NAME_COLUMN).setCellRenderer(new MyTableRenderer<T, M>(this)); TableColumn checkBoxColumn = model.getColumn(CHECKED_COLUMN); TableUtil.setupCheckboxColumn(checkBoxColumn); checkBoxColumn.setCellRenderer(new MyBooleanRenderer<T, M>(this)); setPreferredScrollableViewportSize(new Dimension(400, getRowHeight() * 12)); getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); setShowGrid(false); setIntercellSpacing(new Dimension(0, 0)); new MyEnableDisableAction().register(); new TableSpeedSearch(this); }
public void selectBreakpoints(Breakpoint[] breakpoints) { if (isTreeShowing()) { myTree.selectBreakpoints(breakpoints); } else { final TIntArrayList rows = new TIntArrayList(breakpoints.length); for (Breakpoint breakpoint : breakpoints) { final int index = myTable.getModel().getBreakpointIndex(breakpoint); if (index >= 0) { rows.add(index); } } myTable.getSelectionModel().clearSelection(); TableUtil.selectRows(myTable, rows.toNativeArray()); } }
private AnActionButtonRunnable getRemoveAction(final TableView<XQueryRunVariable> variablesTable) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.stopEditing(variablesTable); final int[] selected = variablesTable.getSelectedRows(); if (selected == null || selected.length == 0) return; for (int i = selected.length - 1; i >= 0; i--) { variablesModel.removeRow(selected[i]); } for (int i = selected.length - 1; i >= 0; i--) { int idx = selected[i]; variablesModel.fireTableRowsDeleted(idx, idx); } int selection = selected[0]; if (selection >= variablesModel.getRowCount()) { selection = variablesModel.getRowCount() - 1; } if (selection >= 0) { variablesTable.setRowSelectionInterval(selection, selection); } variablesTable.requestFocus(); } }; }
@Override protected void processKeyEvent(KeyEvent e){ if (!myProcessCursorKeys) { super.processKeyEvent(e); return; } int keyCode = e.getKeyCode(); final int selColumn = columnModel.getSelectionModel().getAnchorSelectionIndex(); boolean treeHasFocus = selColumn == -1 || selColumn >= 0 && isTreeColumn(selColumn); boolean oneRowSelected = getSelectedRowCount() == 1; if(treeHasFocus && oneRowSelected && ((keyCode == KeyEvent.VK_LEFT) || (keyCode == KeyEvent.VK_RIGHT))){ myTree._processKeyEvent(e); int rowToSelect = ObjectUtil.notNull(myTree.getSelectionRows())[0]; getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect); TableUtil.scrollSelectionToVisible(this); } else{ super.processKeyEvent(e); } }
private void select(@Nonnull VirtualFile toSelect, final TreeNode root) { for (int i = 0; i < root.getChildCount(); i++) { TreeNode child = root.getChildAt(i); VirtualFile file = ((FileNode)child).getObject(); if (VfsUtilCore.isAncestor(file, toSelect, false)) { if (Comparing.equal(file, toSelect)) { TreeUtil.selectNode(getTree(), child); getSelectionModel().clearSelection(); addSelectedPath(TreeUtil.getPathFromRoot(child)); TableUtil.scrollSelectionToVisible(this); } else { select(toSelect, child); } return; } } }
protected void doAction() { TableUtil.stopEditing(myTable); final String className; final String packageName; if (myCreateBuilderClassRadioButton.isSelected()) { className = myNewClassName.getText().trim(); packageName = myPackageTextField.getText().trim(); } else { final String fqName = myExistentClassTF.getText().trim(); className = StringUtil.getShortName(fqName); packageName = StringUtil.getPackageName(fqName); final PsiClass builderClass = JavaPsiFacade.getInstance(myProject).findClass(StringUtil.getQualifiedName(packageName, className), GlobalSearchScope.projectScope(myProject)); if (builderClass != null && !CommonRefactoringUtil.checkReadOnlyStatus(myProject, builderClass)) return; } invokeRefactoring(new ReplaceConstructorWithBuilderProcessor(getProject(), myConstructors, myParametersMap, className, packageName, ((DestinationFolderComboBox)myDestinationCb).selectDirectory(new PackageWrapper(myConstructors[0].getManager(), packageName), false), myCreateBuilderClassRadioButton.isSelected())); }
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(); }
public void selectFirstRow() { if (myElements.size() > 0) { int row = myElements.get(0).isSeparator() ? 1 : 0; if (row < myTable.getRowCount()) { myTable.getSelectionModel().setSelectionInterval(row, row); TableUtil.scrollSelectionToVisible(myTable); } } }
public void stopEditing() { if (!myInStopEditing) { try { myInStopEditing = true; TableUtil.stopEditing(this); } finally { myInStopEditing = false; } } }
/** * Selects row in table * @param rowIndex Row's index */ protected void selectRow(final int rowIndex) { SMRunnerUtil.addToInvokeLater(new Runnable() { public void run() { // updates model myStatisticsTableView.setRowSelectionInterval(rowIndex, rowIndex); // Scroll to visible TableUtil.scrollSelectionToVisible(myStatisticsTableView); } }); }
/** * Selects row in table */ protected void selectRowOf(final SMTestProxy proxy) { SMRunnerUtil.addToInvokeLater(new Runnable() { public void run() { final int indexOf = myTableModel.getIndexOf(proxy); if (indexOf > -1) { final int rowIndex = myStatisticsTableView.convertRowIndexToView(indexOf); myStatisticsTableView.setRowSelectionInterval(rowIndex, rowIndex >= 0 ? rowIndex : 0); // Scroll to visible TableUtil.scrollSelectionToVisible(myStatisticsTableView); } } }); }
private AnAction createFilterByRepositoryAction(final String host) { return new DumbAwareAction(host) { @Override public void actionPerformed(AnActionEvent e) { final String filter = myFilter.getFilter().toLowerCase(Locale.ENGLISH); ((AvailablePluginsTableModel)pluginsModel).setRepository(host, filter); TableUtil.ensureSelectionExists(getPluginTable()); } }; }
public void select(IdeaPluginDescriptor... descriptors) { PluginTableModel tableModel = (PluginTableModel)getModel(); getSelectionModel().clearSelection(); for (int i=0; i<tableModel.getRowCount();i++) { IdeaPluginDescriptor descriptorAt = tableModel.getObjectAt(i); if (ArrayUtil.find(descriptors,descriptorAt) != -1) { final int row = convertRowIndexToView(i); getSelectionModel().addSelectionInterval(row, row); } } TableUtil.scrollSelectionToVisible(this); }
@Override protected JComponent createCenterPanel() { JPanel panel = new JPanel(new GridBagLayout()); JLabel nameLabel = new JLabel(IdeBundle.message("label.todo.filter.name")); panel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 10), 0, 0)); panel.add(myNameField, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); JPanel patternsPanel = new JPanel(new GridBagLayout()); Border border = IdeBorderFactory.createTitledBorder(IdeBundle.message("group.todo.filter.patterns"), false); patternsPanel.setBorder(border); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable); scrollPane.setPreferredSize(new Dimension(550, myTable.getRowHeight() * 10)); patternsPanel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); // Column "Available" TableUtil.setupCheckboxColumn(myTable, 0); // panel.add(patternsPanel, new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); return panel; }
public void methodsSize(int methods) { myTableModel = new DefaultTableModel(methods, 2); myMethodsTable.setModel(myTableModel); TableColumn checkColumn = myMethodsTable.getColumnModel().getColumn(0); TableUtil.setupCheckboxColumn(checkColumn); checkColumn.setCellRenderer(new BooleanTableCellRenderer()); checkColumn.setCellEditor(new DefaultCellEditor(new JCheckBox())); myMethodsTable.getColumnModel().getColumn(1).setHeaderValue("Test method"); checkColumn.setHeaderValue(""); getOKAction().setEnabled(true); }
private void findAndSelect(@NotNull Module module, int columnIndex) { int rowCount = myVariantsTable.getRowCount(); for (int row = 0; row < rowCount; row++) { if (module.equals(myVariantsTable.getValueAt(row, MODULE_COLUMN_INDEX))) { myVariantsTable.getSelectionModel().setSelectionInterval(row, row); myVariantsTable.getColumnModel().getSelectionModel().setSelectionInterval(columnIndex, columnIndex); TableUtil.scrollSelectionToVisible(myVariantsTable); myVariantsTable.requestFocusInWindow(); break; } } }
@Override public boolean importData(TransferHandler.TransferSupport support) { TableModel tableModel = myTable.getModel(); if (!(tableModel instanceof MultiReorderedModel) || !((MultiReorderedModel)tableModel).canMoveRows()) return false; JTable.DropLocation dl = (JTable.DropLocation)support.getDropLocation(); int index = dl.getRow(); int max = tableModel.getRowCount(); if (index < 0 || index > max) { index = max; } myTable.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); try { int[] rows = ((RowsDragInfo)support.getTransferable().getTransferData(myDataFlavor)).myRows; if (rows != null && rows.length > 0) { int dist = 0; for (int row : rows) { if (index > row) { dist++; } } index -= dist; int[] newSelection = ((MultiReorderedModel)tableModel).moveRows(rows, index); TableUtil.selectRows(myTable, newSelection); return true; } } catch (Exception e) { LOG.error("Couldn't move transferred data."); } return false; }
CloudLibraryTable(List<CloudLibrary> libraries) { super(new CloudLibraryTableModel(libraries)); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setDefaultRenderer(CloudLibrary.class, new CloudLibraryRenderer()); setDefaultRenderer(Boolean.class, new BooleanTableCellRenderer()); setDefaultEditor(Boolean.class, new BooleanTableCellEditor()); TableUtil.setupCheckboxColumn(getColumnModel().getColumn(1)); }
public void removeSelectedBreakpoints() { final Breakpoint[] selectedBreakpoints = getSelectedBreakpoints(); if (selectedBreakpoints.length == 0) { return; } final boolean inTreeMode = isTreeShowing(); final int minSelectionIndex; if (inTreeMode) { minSelectionIndex = Math.max(0, myTree.getSelectionModel().getMinSelectionRow()); } else { minSelectionIndex = Math.max(0, myTable.getSelectionModel().getMinSelectionIndex()); } myTree.removeBreakpoints(selectedBreakpoints); myTable.getModel().removeBreakpoints(selectedBreakpoints); myCurrentViewableBreakpoint = null; if (inTreeMode) { if (myTree.getRowCount() > 0) { int rowToSelect = minSelectionIndex >= myTree.getRowCount()? myTree.getRowCount() - 1 : minSelectionIndex; final TreePath path = myTree.getPathForRow(rowToSelect); if (path != null) { TreeUtil.selectPath(myTree, path, true); } } } else { if (myTable.getRowCount() > 0) { // if in table mode and there are items to select int indexToSelect = minSelectionIndex >= myTable.getRowCount()? myTable.getRowCount() - 1 : minSelectionIndex; TableUtil.selectRows(myTable, new int[] {indexToSelect}); } } updateCurrentBreakpointPropertiesPanel(); }
private void initAndShowPopup() { myList.removeAll(); final Rectangle rect = myTable.getCellRect(myRow, myColumn, true); final Point point = new Point(rect.x, rect.y); myList.setModel(JBList.createDefaultListModel(myOptions)); if (myRenderer != null) { myList.setCellRenderer(myRenderer); } JBPopupFactory.getInstance() .createListPopupBuilder(myList) .setItemChoosenCallback(new Runnable() { @Override public void run() { final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen"); for (ActionListener listener : myListeners) { listener.actionPerformed(event); } myValue = myList.getSelectedValue(); TableUtil.stopEditing(myTable); myTable.setValueAt(myValue, myRow, myColumn); // on Mac getCellEditorValue() called before myValue is set. myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow)); // force repaint } }) .setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { TableUtil.stopEditing(myTable); return true; } }) .createPopup() .show(new RelativePoint(myTable, point)); }
protected void initPluginsPanel(final JPanel panel, JPanel pluginsPanel, JEditorPane updateLinkPane) { pluginsPanel.setVisible(myUploadedPlugins != null); if (myUploadedPlugins != null) { final DetectedPluginsPanel foundPluginsPanel = new DetectedPluginsPanel(); foundPluginsPanel.addStateListener(new DetectedPluginsPanel.Listener() { public void stateChanged() { setButtonsText(); } }); for (PluginDownloader uploadedPlugin : myUploadedPlugins) { foundPluginsPanel.add(uploadedPlugin); } TableUtil.ensureSelectionExists(foundPluginsPanel.getEntryTable()); pluginsPanel.add(foundPluginsPanel, BorderLayout.CENTER); } updateLinkPane.setBackground(UIUtil.getPanelBackground()); String css = UIUtil.getCssFontDeclaration(UIUtil.getLabelFont()); if (UIUtil.isUnderDarcula()) { css += "<style>body {background: #" + ColorUtil.toHex(UIUtil.getPanelBackground()) + ";}</style>"; } updateLinkPane.setBorder(IdeBorderFactory.createEmptyBorder()); updateLinkPane.setText(IdeBundle.message("updates.configure.label", css)); updateLinkPane.setEditable(false); LabelTextReplacingUtil.replaceText(panel); if (myEnableLink) { updateLinkPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { final ShowSettingsUtil util = ShowSettingsUtil.getInstance(); UpdateSettingsConfigurable updatesSettings = new UpdateSettingsConfigurable(); updatesSettings.setCheckNowEnabled(false); util.editConfigurable(panel, updatesSettings); } } }); } }
@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()); }
/** * Selects row in table */ protected void selectRowOf(final SMTestProxy proxy) { SMRunnerUtil.addToInvokeLater(new Runnable() { public void run() { final int rowIndex = myTableModel.getIndexOf(proxy); myStatisticsTableView.setRowSelectionInterval(rowIndex, rowIndex >= 0 ? rowIndex : 0); // Scroll to visible TableUtil.scrollSelectionToVisible(myStatisticsTableView); } }); }