mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
TFS: cosmetics/usability fixes for edit workspace dialog
This commit is contained in:
@@ -15,19 +15,27 @@
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.table.TableView;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.text.Document;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.EventObject;
|
||||
|
||||
public abstract class ChangesTrackingTableView<T> extends TableView<T> {
|
||||
|
||||
private DocumentAdapter myMessageUpdater;
|
||||
private Disposable myEditorListenerDisposable;
|
||||
|
||||
protected abstract void onTextChanged(int row, int column, String value);
|
||||
protected abstract void onCellValueChanged(int row, int column, Object value);
|
||||
|
||||
protected abstract void onEditingStopped();
|
||||
|
||||
@@ -43,21 +51,18 @@ public abstract class ChangesTrackingTableView<T> extends TableView<T> {
|
||||
@Override
|
||||
public boolean editCellAt(final int row, final int column, EventObject e) {
|
||||
if (super.editCellAt(row, column, e)) {
|
||||
assert myMessageUpdater == null;
|
||||
final JTextField textField;
|
||||
if (getEditorComponent() instanceof CellEditorComponentWithBrowseButton) {
|
||||
textField = (JTextField)((CellEditorComponentWithBrowseButton)editorComp).getChildComponent();
|
||||
}
|
||||
else {
|
||||
textField = (JTextField)getEditorComponent();
|
||||
}
|
||||
myMessageUpdater = new DocumentAdapter() {
|
||||
assert myEditorListenerDisposable == null;
|
||||
myEditorListenerDisposable = new Disposable() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
onTextChanged(row, column, textField.getText());
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
textField.getDocument().addDocumentListener(myMessageUpdater);
|
||||
addChangeListener(getEditorComponent(), new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
onCellValueChanged(row, column, getValue(getEditorComponent()));
|
||||
}
|
||||
}, myEditorListenerDisposable);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -65,19 +70,67 @@ public abstract class ChangesTrackingTableView<T> extends TableView<T> {
|
||||
|
||||
@Override
|
||||
public void removeEditor() {
|
||||
if (myMessageUpdater != null) {
|
||||
final JTextField textField;
|
||||
if (getEditorComponent() instanceof CellEditorComponentWithBrowseButton) {
|
||||
textField = (JTextField)((CellEditorComponentWithBrowseButton)editorComp).getChildComponent();
|
||||
}
|
||||
else {
|
||||
textField = (JTextField)getEditorComponent();
|
||||
}
|
||||
textField.getDocument().removeDocumentListener(myMessageUpdater);
|
||||
myMessageUpdater = null;
|
||||
if (myEditorListenerDisposable != null) {
|
||||
Disposer.dispose(myEditorListenerDisposable);
|
||||
myEditorListenerDisposable = null;
|
||||
}
|
||||
|
||||
onEditingStopped();
|
||||
super.removeEditor();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getValue(Component component) {
|
||||
if (component instanceof CellEditorComponentWithBrowseButton) {
|
||||
final JTextField textField = (JTextField)((CellEditorComponentWithBrowseButton)component).getChildComponent();
|
||||
return textField.getText();
|
||||
}
|
||||
else if (component instanceof JTextField) {
|
||||
return ((JTextField)component).getText();
|
||||
}
|
||||
else if (component instanceof JComboBox) {
|
||||
return ((JComboBox)component).getSelectedItem();
|
||||
}
|
||||
throw new UnsupportedOperationException("editor control of type " + component.getClass().getName() + " is not supported");
|
||||
}
|
||||
|
||||
private static void addChangeListener(final Component component, final ChangeListener listener, Disposable parentDisposable) {
|
||||
if (component instanceof CellEditorComponentWithBrowseButton) {
|
||||
addChangeListener(((CellEditorComponentWithBrowseButton)component).getChildComponent(), listener, parentDisposable);
|
||||
}
|
||||
else if (component instanceof JTextField) {
|
||||
final DocumentAdapter documentListener = new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
listener.stateChanged(new ChangeEvent(component));
|
||||
}
|
||||
};
|
||||
final Document document = ((JTextField)component).getDocument();
|
||||
document.addDocumentListener(documentListener);
|
||||
Disposer.register(parentDisposable, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
document.removeDocumentListener(documentListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (component instanceof JComboBox) {
|
||||
final ActionListener comboListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
listener.stateChanged(new ChangeEvent(component));
|
||||
}
|
||||
};
|
||||
((JComboBox)component).addActionListener(comboListener);
|
||||
Disposer.register(parentDisposable, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
((JComboBox)component).removeActionListener(comboListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("editor control of type " + component.getClass().getName() + " is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,16 +53,16 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
String getTitle();
|
||||
}
|
||||
|
||||
private class ColumnInfoWrapper extends ColumnInfo<Item, String> {
|
||||
private final ColumnInfo<Item, String> myDelegate;
|
||||
private class ColumnInfoWrapper extends ColumnInfo<Item, Object> {
|
||||
private final ColumnInfo<Item, Object> myDelegate;
|
||||
|
||||
public ColumnInfoWrapper(ColumnInfo<Item, String> delegate) {
|
||||
public ColumnInfoWrapper(ColumnInfo<Item, Object> delegate) {
|
||||
super(delegate.getName());
|
||||
myDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueOf(Item item) {
|
||||
public Object valueOf(Item item) {
|
||||
return myDelegate.valueOf(item);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Item item, String value) {
|
||||
public void setValue(Item item, Object value) {
|
||||
myDelegate.setValue(item, value);
|
||||
updateMessage(-1, null);
|
||||
}
|
||||
@@ -81,6 +81,11 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
public TableCellEditor getEditor(Item item) {
|
||||
return myDelegate.getEditor(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth(JTable table) {
|
||||
return myDelegate.getWidth(table);
|
||||
}
|
||||
}
|
||||
|
||||
private JPanel myContentPane;
|
||||
@@ -146,10 +151,10 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
|
||||
private void createUIComponents() {
|
||||
myTable = new ChangesTrackingTableView<Item>() {
|
||||
protected void onTextChanged(int row, int column, String value) {
|
||||
protected void onCellValueChanged(int row, int column, Object value) {
|
||||
final Item original = getItems().get(row);
|
||||
Item override = cloneOf(original);
|
||||
final ColumnInfo<Item, String> columnInfo = getTableModel().getColumnInfos()[column];
|
||||
final ColumnInfo<Item, Object> columnInfo = getTableModel().getColumnInfos()[column];
|
||||
columnInfo.setValue(override, value);
|
||||
updateMessage(row, override);
|
||||
}
|
||||
@@ -235,7 +240,7 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
return (ListTableModel<Item>)myTable.getModel();
|
||||
}
|
||||
|
||||
public void setModel(ColumnInfo<Item, String>[] valueColumns, List<Item> items) {
|
||||
public void setModel(ColumnInfo<Item, Object>[] valueColumns, List<Item> items) {
|
||||
ColumnInfo[] columns = new ColumnInfo[valueColumns.length + 1];
|
||||
IconColumn iconColumn = new IconColumn();
|
||||
int maxHeight = iconColumn.getRowHeight();
|
||||
@@ -265,15 +270,7 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
private List<Item> doGetItems() {
|
||||
List<Item> items = new ArrayList<Item>(getTableModel().getItems());
|
||||
if (myTable.isEditing()) {
|
||||
Component c = myTable.getEditorComponent();
|
||||
final JTextField textField;
|
||||
if (c instanceof CellEditorComponentWithBrowseButton) {
|
||||
textField = (JTextField)((CellEditorComponentWithBrowseButton)c).getChildComponent();
|
||||
}
|
||||
else {
|
||||
textField = (JTextField)c;
|
||||
}
|
||||
String value = textField.getText();
|
||||
Object value = ChangesTrackingTableView.getValue(myTable.getEditorComponent());
|
||||
ColumnInfo column = ((ListTableModel)myTable.getModel()).getColumnInfos()[myTable.getEditingColumn()];
|
||||
((ColumnInfoWrapper)column).myDelegate.setValue(items.get(myTable.getEditingRow()), value);
|
||||
}
|
||||
@@ -308,7 +305,11 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
current.set(index, override);
|
||||
}
|
||||
|
||||
Pair<String, Fix> messageAndFix = validate(current, myWarnings);
|
||||
displayMessageAndFix(validate(current, myWarnings));
|
||||
myTable.repaint();
|
||||
}
|
||||
|
||||
protected void displayMessageAndFix(@Nullable Pair<String, Fix> messageAndFix) {
|
||||
if (messageAndFix != null) {
|
||||
myMessageLabel.setText(messageAndFix.first);
|
||||
myMessageLabel.setIcon(WARNING_ICON);
|
||||
@@ -323,7 +324,11 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
myFixLink.setVisible(false);
|
||||
myFixRunnable = null;
|
||||
}
|
||||
myTable.repaint();
|
||||
}
|
||||
|
||||
public void hideMessageLabel() {
|
||||
myMessageLabel.setVisible(false);
|
||||
myFixLink.setVisible(false);
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
@@ -354,5 +359,11 @@ public abstract class ValidatingTableEditor<Item> {
|
||||
return myContentPane;
|
||||
}
|
||||
|
||||
public void setColumnReorderingAllowed(boolean value) {
|
||||
JTableHeader header = myTable.getTableHeader();
|
||||
if (header != null) {
|
||||
header.setReorderingAllowed(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user