use of javax.swing.table.DefaultTableModel in project intellij-community by JetBrains.
the class FindPopupPanel method findSettingsChanged.
private void findSettingsChanged() {
if (isShowing()) {
ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
}
final ModalityState state = ModalityState.current();
finishPreviousPreviewSearch();
mySearchRescheduleOnCancellationsAlarm.cancelAllRequests();
applyTo(myHelper.getModel(), false);
myHelper.updateFindSettings();
FindModel findInProjectModel = FindManager.getInstance(myProject).getFindInProjectModel();
FindModel copy = new FindModel();
copy.copyFrom(findInProjectModel);
findInProjectModel.copyFrom(myHelper.getModel());
//todo check if we really need to do it now
((FindManagerImpl) FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel());
FindSettings findSettings = FindSettings.getInstance();
myScopeUI.applyTo(findSettings, mySelectedScope);
findSettings.setFileMask(myHelper.getModel().getFileFilter());
ValidationInfo result = getValidationInfo(myHelper.getModel());
final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
final DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
model.addColumn("Usages");
// Use previously shown usage files as hint for faster search and better usage preview performance if pattern length increased
final LinkedHashSet<VirtualFile> filesToScanInitially = new LinkedHashSet<>();
if (myHelper.myPreviousModel != null && myHelper.myPreviousModel.getStringToFind().length() < myHelper.getModel().getStringToFind().length()) {
final DefaultTableModel previousModel = (DefaultTableModel) myResultsPreviewTable.getModel();
for (int i = 0, len = previousModel.getRowCount(); i < len; ++i) {
final UsageInfo2UsageAdapter usage = (UsageInfo2UsageAdapter) previousModel.getValueAt(i, 0);
final VirtualFile file = usage.getFile();
if (file != null)
filesToScanInitially.add(file);
}
}
myHelper.myPreviousModel = myHelper.getModel().clone();
myCodePreviewComponent.setVisible(false);
mySearchTextArea.setInfoText(null);
myResultsPreviewTable.setModel(model);
if (result != null) {
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow") + " (" + result.message + ")");
return;
}
myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
myResultsPreviewTable.getEmptyText().setText("Searching...");
final AtomicInteger resultsCount = new AtomicInteger();
final AtomicInteger resultsFilesCount = new AtomicInteger();
ProgressIndicatorUtils.scheduleWithWriteActionPriority(myResultsPreviewSearchProgress, new ReadTask() {
@Override
public void computeInReadAction(@NotNull ProgressIndicator indicator) {
final UsageViewPresentation presentation = FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/
myHelper.getModel().clone());
final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
final FindUsagesProcessPresentation processPresentation = FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
Ref<VirtualFile> lastUsageFileRef = new Ref<>();
FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> {
final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info);
usage.getPresentation().getIcon();
VirtualFile file = lastUsageFileRef.get();
VirtualFile usageFile = info.getVirtualFile();
if (file == null || !file.equals(usageFile)) {
resultsFilesCount.incrementAndGet();
lastUsageFileRef.set(usageFile);
}
ApplicationManager.getApplication().invokeLater(() -> {
model.addRow(new Object[] { usage });
myCodePreviewComponent.setVisible(true);
if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) {
myResultsPreviewTable.setRowSelectionInterval(0, 0);
}
}, state);
return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE;
}, processPresentation, filesToScanInitially);
boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled();
if (succeeded) {
ApplicationManager.getApplication().invokeLater(() -> {
if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) {
int occurrences = resultsCount.get();
int filesWithOccurrences = resultsFilesCount.get();
if (occurrences == 0)
myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow"));
myCodePreviewComponent.setVisible(occurrences > 0);
StringBuilder info = new StringBuilder();
if (occurrences > 0) {
info.append(Math.min(ShowUsagesAction.USAGES_PAGE_SIZE, occurrences));
boolean foundAllUsages = occurrences < ShowUsagesAction.USAGES_PAGE_SIZE;
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.matches", occurrences));
info.append(" in ");
info.append(filesWithOccurrences);
if (!foundAllUsages) {
info.append("+");
}
info.append(UIBundle.message("message.files", filesWithOccurrences));
}
mySearchTextArea.setInfoText(info.toString());
}
}, state);
}
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {
scheduleResultsUpdate();
}
}
});
}
use of javax.swing.table.DefaultTableModel in project intellij-community by JetBrains.
the class ArrangementGroupingRulesControl method setRules.
public void setRules(@Nullable List<ArrangementGroupingRule> rules) {
for (ArrangementGroupingComponent component : myComponents.values()) {
component.setSelected(false);
}
if (rules == null) {
return;
}
DefaultTableModel model = getModel();
while (model.getRowCount() > 0) {
model.removeRow(model.getRowCount() - 1);
}
final Set<ArrangementSettingsToken> groupingTokens = ContainerUtilRt.newHashSet(myComponents.keySet());
for (ArrangementGroupingRule rule : rules) {
final ArrangementSettingsToken groupingType = rule.getGroupingType();
ArrangementGroupingComponent component = myComponents.get(groupingType);
component.setSelected(true);
component.setOrderType(rule.getOrderType());
model.addRow(new Object[] { component });
groupingTokens.remove(groupingType);
}
List<ArrangementSettingsToken> types = ContainerUtilRt.newArrayList(groupingTokens);
types = mySettingsManager.sort(types);
for (ArrangementSettingsToken type : types) {
model.addRow(new Object[] { myComponents.get(type) });
}
}
use of javax.swing.table.DefaultTableModel in project intellij-community by JetBrains.
the class MoveArrangementGroupingRuleDownAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
ArrangementGroupingRulesControl control = ArrangementGroupingRulesControl.KEY.getData(e.getDataContext());
if (control == null) {
return;
}
int[] rows = control.getSelectedRows();
int row = rows[0];
if (rows.length != 1 || rows[0] == control.getRowCount() - 1) {
return;
}
if (control.isEditing()) {
control.getCellEditor().stopCellEditing();
}
DefaultTableModel model = control.getModel();
Object value = model.getValueAt(row, 0);
model.removeRow(row);
model.insertRow(row + 1, new Object[] { value });
control.getSelectionModel().setSelectionInterval(row + 1, row + 1);
}
use of javax.swing.table.DefaultTableModel in project intellij-community by JetBrains.
the class MoveArrangementGroupingRuleUpAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
ArrangementGroupingRulesControl control = ArrangementGroupingRulesControl.KEY.getData(e.getDataContext());
if (control == null) {
return;
}
int[] rows = control.getSelectedRows();
int row = rows[0];
if (rows.length != 1 || row == 0) {
return;
}
if (control.isEditing()) {
control.getCellEditor().stopCellEditing();
}
DefaultTableModel model = control.getModel();
Object value = model.getValueAt(row, 0);
model.removeRow(row);
model.insertRow(row - 1, new Object[] { value });
control.getSelectionModel().setSelectionInterval(row - 1, row - 1);
}
use of javax.swing.table.DefaultTableModel in project processdash by dtuma.
the class ManuallyEnteredPreferencesList method createList.
@Override
protected void createList(String id, String currentValue) {
Object[][] data = getCurrentData(currentValue);
String settingColumnName = map.getResource(id + ".Setting_Column");
String valueColumnName = map.getResource(id + ".Value_Column");
Object[] columns = { settingColumnName, valueColumnName };
tableModel = new DefaultTableModel(data, columns) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
settingTable = new JTable(tableModel);
settingTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
settingTable.getSelectionModel().addListSelectionListener(this);
JScrollPane listScroller = new JScrollPane(settingTable);
listScroller.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HEIGHT));
this.add(listScroller, BorderLayout.CENTER);
}
Aggregations