diff options
Diffstat (limited to 'java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java')
-rw-r--r-- | java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java | 139 |
1 files changed, 59 insertions, 80 deletions
diff --git a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java index e570b642b2bd..a4484cccc1fe 100644 --- a/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java +++ b/java/debugger/impl/src/com/intellij/debugger/settings/CompoundRendererConfigurable.java @@ -25,14 +25,10 @@ import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.debugger.ui.DebuggerExpressionTextField; import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.debugger.ui.tree.render.*; -import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.UnnamedConfigurable; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; @@ -41,7 +37,7 @@ import com.intellij.ui.table.JBTable; import com.intellij.util.Function; import com.intellij.util.ui.AbstractTableCellEditor; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.table.AbstractTableModel; @@ -52,57 +48,33 @@ import java.awt.event.*; import java.util.ArrayList; import java.util.List; -/** - * @author Eugene Zhuravlev - * Date: Feb 24, 2005 - */ -public class CompoundRendererConfigurable implements UnnamedConfigurable { +class CompoundRendererConfigurable extends JPanel { private CompoundReferenceRenderer myRenderer; private CompoundReferenceRenderer myOriginalRenderer; private Project myProject; - private ClassNameEditorWithBrowseButton myClassNameField; - private JRadioButton myRbDefaultLabel; - private JRadioButton myRbExpressionLabel; - private JRadioButton myRbDefaultChildrenRenderer; - private JRadioButton myRbExpressionChildrenRenderer; - private JRadioButton myRbListChildrenRenderer; - private DebuggerExpressionTextField myLabelEditor; - private DebuggerExpressionTextField myChildrenEditor; - private DebuggerExpressionTextField myChildrenExpandedEditor; + private final ClassNameEditorWithBrowseButton myClassNameField; + private final JRadioButton myRbDefaultLabel; + private final JRadioButton myRbExpressionLabel; + private final JRadioButton myRbDefaultChildrenRenderer; + private final JRadioButton myRbExpressionChildrenRenderer; + private final JRadioButton myRbListChildrenRenderer; + private final DebuggerExpressionTextField myLabelEditor; + private final DebuggerExpressionTextField myChildrenEditor; + private final DebuggerExpressionTextField myChildrenExpandedEditor; private DebuggerExpressionTextField myListChildrenEditor; - private JComponent myChildrenListEditor; - private JLabel myExpandedLabel; - private JPanel myMainPanel; + private final JLabel myExpandedLabel; private JBTable myTable; @NonNls private static final String EMPTY_PANEL_ID = "EMPTY"; @NonNls private static final String DATA_PANEL_ID = "DATA"; private static final int NAME_TABLE_COLUMN = 0; private static final int EXPRESSION_TABLE_COLUMN = 1; - public CompoundRendererConfigurable(@Nullable Project project) { - myProject = project; - } - - public void setRenderer(NodeRenderer renderer) { - if (renderer instanceof CompoundReferenceRenderer) { - myRenderer = (CompoundReferenceRenderer)renderer; - myOriginalRenderer = (CompoundReferenceRenderer)renderer.clone(); - } - else { - myRenderer = myOriginalRenderer = null; - } - reset(); - } - - public CompoundReferenceRenderer getRenderer() { - return myRenderer; - } + public CompoundRendererConfigurable() { + super(new CardLayout()); - public JComponent createComponent() { if (myProject == null) { myProject = JavaDebuggerSupport.getContextProjectForEditorFieldsInDebuggerConfigurables(); } - final JPanel panel = new JPanel(new GridBagLayout()); myRbDefaultLabel = new JRadioButton(DebuggerBundle.message("label.compound.renderer.configurable.use.default.renderer")); myRbExpressionLabel = new JRadioButton(DebuggerBundle.message("label.compound.renderer.configurable.use.expression")); @@ -121,10 +93,11 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { myLabelEditor = new DebuggerExpressionTextField(myProject, null, "ClassLabelExpression"); myChildrenEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression"); myChildrenExpandedEditor = new DebuggerExpressionTextField(myProject, null, "ClassChildrenExpression"); - myChildrenListEditor = createChildrenListEditor(); + JComponent myChildrenListEditor = createChildrenListEditor(); final ItemListener updateListener = new ItemListener() { - public void itemStateChanged(ItemEvent e) { + @Override + public void itemStateChanged(@NotNull ItemEvent e) { updateEnabledState(); } }; @@ -133,7 +106,8 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { myRbExpressionChildrenRenderer.addItemListener(updateListener); myClassNameField = new ClassNameEditorWithBrowseButton(new ActionListener() { - public void actionPerformed(ActionEvent e) { + @Override + public void actionPerformed(@NotNull ActionEvent e) { PsiClass psiClass = DebuggerUtils.getInstance() .chooseClassDialog(DebuggerBundle.message("title.compound.renderer.configurable.choose.renderer.reference.type"), myProject); if (psiClass != null) { @@ -143,20 +117,14 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { } } }, myProject); - final EditorTextField textField = myClassNameField.getEditorTextField(); - final FocusAdapter updateContextListener = new FocusAdapter() { - public void focusLost(FocusEvent e) { - updateContext(myClassNameField.getText()); - } - }; - textField.addFocusListener(updateContextListener); - Disposer.register(myClassNameField, new Disposable() { + myClassNameField.getEditorTextField().addFocusListener(new FocusAdapter() { @Override - public void dispose() { - textField.removeFocusListener(updateContextListener); + public void focusLost(@NotNull FocusEvent e) { + updateContext(myClassNameField.getText()); } }); + JPanel panel = new JPanel(new GridBagLayout()); panel.add(new JLabel(DebuggerBundle.message("label.compound.renderer.configurable.apply.to")), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); @@ -197,15 +165,28 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { panel.add(myChildrenListEditor, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(4, 30, 0, 0), 0, 0)); + add(new JPanel(), EMPTY_PANEL_ID); + add(panel, DATA_PANEL_ID); + } - myMainPanel = new JPanel(new CardLayout()); - myMainPanel.add(new JPanel(), EMPTY_PANEL_ID); - myMainPanel.add(panel, DATA_PANEL_ID); - return myMainPanel; + public void setRenderer(NodeRenderer renderer) { + if (renderer instanceof CompoundReferenceRenderer) { + myRenderer = (CompoundReferenceRenderer)renderer; + myOriginalRenderer = (CompoundReferenceRenderer)renderer.clone(); + } + else { + myRenderer = myOriginalRenderer = null; + } + reset(); + } + + public CompoundReferenceRenderer getRenderer() { + return myRenderer; } private void updateContext(final String qName) { ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override public void run() { final Project project = myProject; final PsiClass psiClass = project != null ? DebuggerUtils.findClass(qName, project, GlobalSearchScope.allScope(project)) : null; @@ -214,6 +195,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { myChildrenExpandedEditor.setContext(psiClass); myListChildrenEditor.setContext(psiClass); + assert project != null; PsiType type = DebuggerUtils.getType(qName, project); myLabelEditor.setThisType(type); myChildrenEditor.setThisType(type); @@ -251,17 +233,21 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { final TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN); exprColumn.setCellEditor(new AbstractTableCellEditor() { + @Override public Object getCellEditorValue() { return myListChildrenEditor.getText(); } + @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { myListChildrenEditor.setText((TextWithImports)value); return myListChildrenEditor; } }); exprColumn.setCellRenderer(new DefaultTableCellRenderer() { - public Component getTableCellRendererComponent(JTable table, + @NotNull + @Override + public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, @@ -309,7 +295,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { return !DebuggerUtilsEx.externalizableEqual(cloned, myOriginalRenderer); } - public void apply() throws ConfigurationException { + public void apply() { if (myRenderer == null) { return; } @@ -342,7 +328,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { public void reset() { final TextWithImports emptyExpressionFragment = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, ""); - ((CardLayout)myMainPanel.getLayout()).show(myMainPanel, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID); + ((CardLayout)getLayout()).show(this, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID); if (myRenderer == null) { return; } @@ -390,27 +376,11 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { updateContext(className); } - public void disposeUIResources() { - myRenderer = null; - myOriginalRenderer = null; - myLabelEditor.dispose(); - myChildrenEditor.dispose(); - myChildrenExpandedEditor.dispose(); - myListChildrenEditor.dispose(); - Disposer.dispose(myClassNameField); - myLabelEditor = null; - myChildrenEditor = null; - myChildrenExpandedEditor = null; - myListChildrenEditor = null; - myClassNameField = null; - myProject = null; - } - private MyTableModel getTableModel() { return (MyTableModel)myTable.getModel(); } - private final class MyTableModel extends AbstractTableModel { + private static final class MyTableModel extends AbstractTableModel { private final List<Row> myData = new ArrayList<Row>(); public MyTableModel() { @@ -423,18 +393,23 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { } } + @Override public int getColumnCount() { return 2; } + @Override public int getRowCount() { return myData.size(); } + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } + @NotNull + @Override public Class getColumnClass(int columnIndex) { switch (columnIndex) { case NAME_TABLE_COLUMN: @@ -446,6 +421,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { } } + @Override public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex >= getRowCount()) { return null; @@ -461,6 +437,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { } } + @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (rowIndex >= getRowCount()) { return; @@ -476,6 +453,8 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { } } + @NotNull + @Override public String getColumnName(int columnIndex) { switch (columnIndex) { case NAME_TABLE_COLUMN: @@ -513,7 +492,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable { return pairs; } - private final class Row { + private static final class Row { public String name; public TextWithImports value; |