use of com.intellij.util.ui.AbstractTableCellEditor in project intellij-community by JetBrains.
the class CompoundRendererConfigurable method createChildrenListEditor.
private JComponent createChildrenListEditor(JavaDebuggerEditorsProvider editorsProvider) {
final MyTableModel tableModel = new MyTableModel();
myTable = new JBTable(tableModel);
myListChildrenEditor = new XDebuggerExpressionEditor(myProject, editorsProvider, "NamedChildrenConfigurable", null, XExpressionImpl.EMPTY_EXPRESSION, false, false, false);
JComponent editorComponent = myListChildrenEditor.getComponent();
AbstractTableCellEditor editor = new AbstractTableCellEditor() {
@Override
public Object getCellEditorValue() {
return TextWithImportsImpl.fromXExpression(myListChildrenEditor.getExpression());
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
myListChildrenEditor.setExpression(TextWithImportsImpl.toXExpression((TextWithImports) value));
return editorComponent;
}
};
editorComponent.registerKeyboardAction(e -> editor.stopCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
editorComponent.registerKeyboardAction(e -> editor.cancelCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN);
exprColumn.setCellEditor(editor);
exprColumn.setCellRenderer(new DefaultTableCellRenderer() {
@NotNull
@Override
public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final TextWithImports textWithImports = (TextWithImports) value;
final String text = (textWithImports != null) ? textWithImports.getText() : "";
return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
}
});
return ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports(""));
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
int selectedRow = myTable.getSelectedRow();
if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) {
getTableModel().removeRow(selectedRow);
}
}
}).setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsUp(myTable);
}
}).setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsDown(myTable);
}
}).createPanel();
}
use of com.intellij.util.ui.AbstractTableCellEditor in project intellij-community by JetBrains.
the class PerFileConfigurableBase method setupPerFileTable.
private void setupPerFileTable() {
myTable.setEnableAntialiasing(true);
myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
myTable.setRowSelectionAllowed(true);
myTable.setShowGrid(false);
myTable.getColumnModel().setColumnMargin(0);
myTable.getTableHeader().setReorderingAllowed(false);
TableRowSorter<MyModel<T>> sorter = new TableRowSorter<>(myModel);
sorter.setStringConverter(new TableStringConverter() {
final SimpleColoredText text = new SimpleColoredText();
@Override
public String toString(TableModel model, int row, int column) {
text.clear();
Pair<Object, T> pair = myModel.data.get(row);
if (column == 0)
renderTarget(pair.first, text);
else if (pair.second != null)
renderValue(pair.first, pair.second, text);
else
renderDefaultValue(pair.first, text);
return StringUtil.toLowerCase(text.toString());
}
});
sorter.setSortable(0, true);
sorter.setSortable(1, true);
sorter.setSortsOnUpdates(true);
myTable.setRowSorter(sorter);
myTable.getRowSorter().setSortKeys(Collections.singletonList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
new TableSpeedSearch(myTable, o -> keyToString(o));
FontMetrics metrics = myTable.getFontMetrics(myTable.getFont());
int maxValueWidth = 2 * metrics.stringWidth(myTable.getModel().getColumnName(1));
SimpleColoredText text = new SimpleColoredText();
for (T t : getValueVariants(null)) {
text.clear();
renderValue(null, t, text);
maxValueWidth = Math.max(metrics.stringWidth(text.toString()), maxValueWidth);
}
if (maxValueWidth < 300) {
myTable.getColumnModel().getColumn(1).setMinWidth(maxValueWidth);
myTable.getColumnModel().getColumn(1).setMaxWidth(2 * maxValueWidth);
}
myTable.getColumnModel().getColumn(0).setCellRenderer(new ColoredTableCellRenderer() {
@Override
public void acquireState(JTable table, boolean isSelected, boolean hasFocus, int row, int column) {
super.acquireState(table, isSelected, false, row, column);
}
@Override
protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
renderTarget(value, this);
SpeedSearchUtil.applySpeedSearchHighlighting(table, this, false, selected);
}
});
myTable.getColumnModel().getColumn(1).setCellRenderer(new ColoredTableCellRenderer() {
@Override
public void acquireState(JTable table, boolean isSelected, boolean hasFocus, int row, int column) {
super.acquireState(table, isSelected, false, row, column);
}
@Override
protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
Pair<Object, T> p = myModel.data.get(myTable.convertRowIndexToModel(row));
if (p.second != null) {
setTransparentIconBackground(true);
renderValue(p.first, p.second, this);
} else {
renderDefaultValue(p.first, this);
}
}
});
myTable.getColumnModel().getColumn(1).setCellEditor(new AbstractTableCellEditor() {
T editorValue;
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
int modelRow = myTable.convertRowIndexToModel(row);
Pair<Object, T> pair = myModel.data.get(modelRow);
Object target = pair.first;
// (T)value
editorValue = pair.second;
if (!canEditTarget(target, editorValue))
return null;
JPanel panel = createActionPanel(target, new Value<T>() {
@Override
public T get() {
return editorValue;
}
@Override
public void set(T value) {
editorValue = adjustChosenValue(target, value);
}
@Override
public void commit() {
TableUtil.stopEditing(myTable);
selectRows(new int[] { modelRow }, true);
if (Comparing.equal(editorValue, pair.second)) {
// do nothing
} else {
int ret = clearSubdirectoriesOnDemandOrCancel(false, target);
if (ret == Messages.CANCEL) {
myModel.setValueAt(value, modelRow, column);
}
selectRows(new int[] { modelRow }, true);
}
}
}, true);
AbstractButton button = UIUtil.uiTraverser(panel).filter(JButton.class).first();
if (button != null) {
AtomicInteger clickCount = new AtomicInteger();
button.addActionListener(e -> clickCount.incrementAndGet());
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (clickCount.get() == 0 && myTable.getEditorComponent() == panel) {
button.doClick();
}
});
}
return panel;
}
@Override
public Object getCellEditorValue() {
return editorValue;
}
});
}
use of com.intellij.util.ui.AbstractTableCellEditor in project intellij-plugins by JetBrains.
the class CompilerOptionsConfigurable method createValueEditor.
private TableCellEditor createValueEditor() {
return new AbstractTableCellEditor() {
//private CellEditorComponentWithBrowseButton<JTextField> myTextWithBrowse;
//private LocalPathCellEditor myLocalPathCellEditor;
private final JTextField myTextField = new JTextField();
private final TextFieldWithBrowseButton myTextWithBrowse = new TextFieldWithBrowseButton();
private final RepeatableValueEditor myRepeatableValueEditor = new RepeatableValueEditor(myProject);
private final ExtensionAwareFileChooserDescriptor myFileChooserDescriptor = new ExtensionAwareFileChooserDescriptor();
private final JCheckBox myCheckBox = new JCheckBox();
{
myTextWithBrowse.addBrowseFolderListener(null, null, myProject, myFileChooserDescriptor);
myCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
// apply new check box state immediately
TableUtil.stopEditing(myTreeTable);
}
});
}
private Component myCurrentEditor;
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) {
assert value instanceof CompilerOptionInfo;
final CompilerOptionInfo info = (CompilerOptionInfo) value;
final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
final String sdkHome = sdk == null || sdk.getSdkType() == FlexmojosSdkType.getInstance() ? null : sdk.getHomePath();
final String optionValue = sdkHome == null ? getValueAndSource(info).first : getValueAndSource(info).first.replace(CompilerOptionInfo.FLEX_SDK_MACRO, sdkHome);
switch(info.TYPE) {
case Boolean:
myCheckBox.setBackground(table.getBackground());
myCheckBox.setSelected("true".equalsIgnoreCase(optionValue));
myCurrentEditor = myCheckBox;
break;
case List:
myRepeatableValueEditor.setInfoAndValue(info, optionValue);
myCurrentEditor = myRepeatableValueEditor;
break;
case String:
case Int:
case IncludeClasses:
case IncludeFiles:
myTextField.setText(optionValue);
myCurrentEditor = myTextField;
break;
case File:
myFileChooserDescriptor.setAllowedExtensions(info.FILE_EXTENSION);
myTextWithBrowse.setText(FileUtil.toSystemDependentName(optionValue));
myCurrentEditor = myTextWithBrowse;
break;
case Group:
default:
assert false;
}
return myCurrentEditor;
}
public Object getCellEditorValue() {
if (myCurrentEditor == myCheckBox) {
return String.valueOf(myCheckBox.isSelected());
}
if (myCurrentEditor == myTextField) {
return myTextField.getText().trim();
}
if (myCurrentEditor == myTextWithBrowse) {
final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
final String sdkHome = sdk == null || sdk.getSdkType() == FlexmojosSdkType.getInstance() ? null : sdk.getHomePath();
final String path = FileUtil.toSystemIndependentName(myTextWithBrowse.getText().trim());
return sdkHome == null ? path : path.replace(sdkHome, CompilerOptionInfo.FLEX_SDK_MACRO);
}
if (myCurrentEditor == myRepeatableValueEditor) {
final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
final String sdkHome = sdk == null ? null : sdk.getHomePath();
final String value = myRepeatableValueEditor.getValue();
return sdkHome == null ? value : value.replace(sdkHome, CompilerOptionInfo.FLEX_SDK_MACRO);
}
assert false;
return null;
}
};
}
use of com.intellij.util.ui.AbstractTableCellEditor in project intellij-community by JetBrains.
the class ParameterTablePanel method init.
public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
super.init(variableData);
myParameterTypeSelectors = new TypeSelector[getVariableData().length];
for (int i = 0; i < myParameterTypeSelectors.length; i++) {
final VariableData data = variableData[i];
final TypeSelector selector = createSelector(project, data, scopeElements);
myParameterTypeSelectors[i] = selector;
//reverse order
getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
}
myTypeRendererCombo = new ComboBox<>(getVariableData());
myTypeRendererCombo.setOpaque(true);
myTypeRendererCombo.setBorder(null);
myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {
@Override
public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.type.getPresentableText());
}
}
});
final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
typeColumn.setCellEditor(new AbstractTableCellEditor() {
TypeSelector myCurrentSelector;
final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();
final JLabel myTypeLabel = new JLabel();
@Nullable
public Object getCellEditorValue() {
if (myCurrentSelector.getComponent() instanceof JLabel) {
return myCurrentSelector.getSelectedType();
}
return myEditorComponent.getEditorValue();
}
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
myCurrentSelector = myParameterTypeSelectors[row];
if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
PsiType selectedType = myCurrentSelector.getSelectedType();
if (selectedType != null) {
myTypeLabel.setText(selectedType.getPresentableText());
}
return myTypeLabel;
}
myEditorComponent.setCell(table, row, column);
myEditorComponent.setOptions(myCurrentSelector.getTypes());
myEditorComponent.setDefaultValue(getVariableData()[row].type);
myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
return myEditorComponent;
}
});
myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
private final JBComboBoxLabel myLabel = new JBComboBoxLabel();
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value != null) {
myLabel.setText(((PsiType) value).getPresentableText());
myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
if (isSelected) {
myLabel.setSelectionIcon();
} else {
myLabel.setRegularIcon();
}
}
return myLabel;
}
});
}
use of com.intellij.util.ui.AbstractTableCellEditor in project intellij-plugins by JetBrains.
the class FilesToPackageForm method initTable.
private void initTable() {
myFilesToPackageTable = new JBTable();
// otherwise model is not in sync with view
myFilesToPackageTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
myFilesToPackageTable.setPreferredScrollableViewportSize(JBUI.size(400, 150));
myFilesToPackageTable.setRowHeight(new JTextField("Fake").getPreferredSize().height + myFilesToPackageTable.getRowMargin());
myFilesToPackageTable.setModel(new DefaultTableModel() {
public int getColumnCount() {
return Column.values().length;
}
public int getRowCount() {
return myFilesToPackage.size();
}
public String getColumnName(int column) {
return Column.values()[column].getColumnName();
}
public Class<?> getColumnClass(int column) {
return Column.values()[column].getColumnClass();
}
public Object getValueAt(int row, int column) {
return Column.values()[column].getValue(myFilesToPackage.get(row));
}
public void setValueAt(Object aValue, int row, int column) {
Column.values()[column].setValue(myFilesToPackage, row, aValue);
}
});
myFilesToPackageTable.getColumnModel().getColumn(0).setCellEditor(new AbstractTableCellEditor() {
private CellEditorComponentWithBrowseButton<JTextField> myComponent;
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) {
final ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor d = new FileChooserDescriptor(true, true, false, true, false, false);
VirtualFile initialFile = LocalFileSystem.getInstance().findFileByPath((String) getCellEditorValue());
VirtualFile file = FileChooser.chooseFile(d, myProject, initialFile);
if (file != null) {
myComponent.getChildComponent().setText(file.getPresentableUrl());
}
}
};
myComponent = new CellEditorComponentWithBrowseButton<>(new TextFieldWithBrowseButton(listener), this);
myComponent.getChildComponent().setText((String) value);
return myComponent;
}
public Object getCellEditorValue() {
return myComponent.getChildComponent().getText();
}
});
}
Aggregations