Search in sources :

Example 6 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class DynamicMethodDialog method setupParameterList.

private void setupParameterList(List<ParamInfo> arguments) {
    final ListTableModel<ParamInfo> dataModel = new ListTableModel<>(new NameColumnInfo(), new TypeColumnInfo());
    dataModel.setItems(arguments);
    myParametersTable.setModel(dataModel);
    if (arguments.isEmpty())
        return;
    String max0 = arguments.get(0).name;
    String max1 = arguments.get(0).type;
    for (ParamInfo argument : arguments) {
        if (argument.name.length() > max0.length())
            max0 = argument.name;
        if (argument.type.length() > max1.length())
            max1 = argument.type;
    }
    final FontMetrics metrics = myParametersTable.getFontMetrics(myParametersTable.getFont());
    final TableColumn column0 = myParametersTable.getColumnModel().getColumn(0);
    column0.setPreferredWidth(metrics.stringWidth(max0 + "  "));
    final TableColumn column1 = myParametersTable.getColumnModel().getColumn(1);
    column1.setPreferredWidth(metrics.stringWidth(max1 + "  "));
}
Also used : ListTableModel(com.intellij.util.ui.ListTableModel) TableColumn(javax.swing.table.TableColumn) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Example 7 with ParamInfo

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo in project intellij-community by JetBrains.

the class DynamicMethodDialog method setupParameterTable.

private void setupParameterTable(final List<ParamInfo> pairs) {
    MySuggestedNameCellEditor suggestedNameCellEditor = new MySuggestedNameCellEditor(QuickfixUtil.getArgumentsNames(pairs));
    myParametersTable.setDefaultEditor(String.class, suggestedNameCellEditor);
    suggestedNameCellEditor.addCellEditorListener(new CellEditorListener() {

        @Override
        public void editingStopped(ChangeEvent e) {
            final int editingColumn = myParametersTable.getSelectedColumn();
            if (editingColumn != 0)
                return;
            final int editingRow = myParametersTable.getSelectedRow();
            if (editingRow < 0 || editingRow >= pairs.size())
                return;
            String newNameValue = ((MySuggestedNameCellEditor) e.getSource()).getCellEditorValue();
            final ParamInfo editingPair = pairs.get(editingRow);
            editingPair.name = newNameValue;
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
        }
    });
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) CellEditorListener(javax.swing.event.CellEditorListener) ParamInfo(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)

Aggregations

ParamInfo (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo)7 ArrayList (java.util.ArrayList)4 PsiType (com.intellij.psi.PsiType)1 ListTableModel (com.intellij.util.ui.ListTableModel)1 CellEditorListener (javax.swing.event.CellEditorListener)1 ChangeEvent (javax.swing.event.ChangeEvent)1 TableColumn (javax.swing.table.TableColumn)1 DynamicElementSettings (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicElementSettings)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1