Add dynamic property and method refactored
authorMaxim.Medvedev <maxim.medvedev@jetbrains.com>
Tue, 31 Jan 2012 16:46:18 +0000 (20:46 +0400)
committerMaxim.Medvedev <maxim.medvedev@jetbrains.com>
Wed, 1 Feb 2012 12:00:22 +0000 (16:00 +0400)
plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.form
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicDialog.java
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicMethodDialog.java
plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/dynamic/ui/DynamicPropertyDialog.java

index d74bd47847b80c12f635f88aee17b6ac538f963c..cdcb7b56953b4d3380f91143060587e29ad759ec 100644 (file)
@@ -215,8 +215,8 @@ add.dynamic.method=Add Dynamic Method
 dynamic.type=Type
 dynamic.name=Name
 dynamic.properties.table.name=Method arguments
-dynamic.method.return.type=Return type
-dynamic.method.property.type=Property type
+dynamic.method.return.type=Return &type:
+dynamic.method.property.type=Property &type:
 are.you.sure.to.delete.dynamic.property=Are you sure to delete ''{0}''?
 dynamic.property.deletion=Deletion Dynamic Property
 are.you.sure.to.delete.elements=Are you sure to delete ''{0}'' elements?
index 33a7a8bb7748e3ed00d5b47b784f01c8320c0d37..3b311408ebdd8b9e6af1c383ee4feb9621879d3c 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicDialog">
-  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
       <xy x="20" y="20" width="348" height="254"/>
@@ -8,84 +8,84 @@
     <properties/>
     <border type="none"/>
     <children>
-      <component id="397c0" class="javax.swing.JComboBox" binding="myClassComboBox">
-        <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties/>
-      </component>
-      <component id="7e6fc" class="javax.swing.JLabel" binding="myClassLabel">
-        <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="397c0"/>
-          <text resource-bundle="org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle" key="dynamic.property.dialog.class"/>
-        </properties>
-      </component>
-      <component id="dd0ba" class="javax.swing.JLabel" binding="myTypeLabel">
+      <component id="b438c" class="javax.swing.JCheckBox" binding="myStaticCheckBox">
         <constraints>
-          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <labelFor value="1d610"/>
-          <text value="&amp;Type:"/>
+          <text value="&amp;Static"/>
         </properties>
       </component>
-      <component id="1d610" class="javax.swing.JComboBox" binding="myTypeComboBox">
+      <grid id="28596" binding="myTablePane" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
-          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
-      </component>
-      <grid id="96a1d" binding="myTypeStatusPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <border type="none"/>
+        <children>
+          <scrollpane id="fb260" class="com.intellij.ui.components.JBScrollPane">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+            <border type="none"/>
+            <children>
+              <component id="57525" class="com.intellij.ui.table.JBTable" binding="myParametersTable">
+                <constraints/>
+                <properties>
+                  <autoResizeMode value="4"/>
+                  <background swing-color="ArrowButton.background"/>
+                  <enabled value="true"/>
+                  <preferredScrollableViewportSize width="450" height="50"/>
+                  <showHorizontalLines value="true"/>
+                  <showVerticalLines value="true"/>
+                </properties>
+              </component>
+            </children>
+          </scrollpane>
+        </children>
+      </grid>
+      <grid id="6d607" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
-          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
         <border type="none"/>
         <children>
-          <component id="728db" class="javax.swing.JLabel" binding="myTypeStatusLabel">
+          <component id="7e6fc" class="javax.swing.JLabel">
             <constraints>
               <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
-              <enabled value="true"/>
-              <horizontalTextPosition value="2"/>
-              <text value=""/>
+              <labelFor value="397c0"/>
+              <text resource-bundle="org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle" key="dynamic.property.dialog.class"/>
             </properties>
           </component>
+          <component id="397c0" class="javax.swing.JComboBox" binding="myClassComboBox">
+            <constraints>
+              <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+          </component>
+          <component id="dd0ba" class="javax.swing.JLabel" binding="myTypeLabel">
+            <constraints>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <labelFor value="1d610"/>
+              <text value="&amp;Type:"/>
+            </properties>
+          </component>
+          <component id="1d610" class="javax.swing.JComboBox" binding="myTypeComboBox">
+            <constraints>
+              <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+          </component>
         </children>
       </grid>
-      <component id="ab9db" class="javax.swing.JLabel" binding="myTableLabel">
-        <constraints>
-          <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text value="Label"/>
-        </properties>
-      </component>
-      <component id="63583" class="com.intellij.ui.table.JBTable" binding="myParametersTable">
-        <constraints>
-          <grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <autoResizeMode value="4"/>
-          <background swing-color="ArrowButton.background"/>
-          <enabled value="true"/>
-          <showHorizontalLines value="true"/>
-          <showVerticalLines value="true"/>
-        </properties>
-      </component>
-      <component id="b438c" class="javax.swing.JCheckBox" binding="myStaticCheckBox">
-        <constraints>
-          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text value="&amp;Static"/>
-        </properties>
-      </component>
     </children>
   </grid>
 </form>
index 7773766b80b5a61ef2e40bd02b0b1bcd7365327f..0b652fa9d229f89195186e5fa820b1c0e4159a4a 100644 (file)
@@ -22,18 +22,15 @@ import com.intellij.openapi.command.undo.UndoManager;
 import com.intellij.openapi.command.undo.UnexpectedUndoException;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.event.DocumentEvent;
-import com.intellij.openapi.editor.event.DocumentListener;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.IconLoader;
 import com.intellij.psi.*;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.search.ProjectScope;
 import com.intellij.ui.EditorComboBoxEditor;
-import com.intellij.ui.EditorTextField;
-import com.intellij.ui.components.JBScrollPane;
+import com.intellij.ui.IdeBorderFactory;
+import com.intellij.ui.table.JBTable;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.GroovyBundle;
@@ -52,11 +49,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUt
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 
 import javax.swing.*;
-import javax.swing.border.Border;
-import javax.swing.event.EventListenerList;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.EventListener;
 import java.util.List;
 
 /**
@@ -64,59 +56,44 @@ import java.util.List;
  * Date: 18.12.2007
  */
 public abstract class DynamicDialog extends DialogWrapper {
+  private static final Logger LOG = Logger.getInstance(DynamicDialog.class);
+
   private JComboBox myClassComboBox;
   private JPanel myPanel;
   private JComboBox myTypeComboBox;
-  private JLabel myClassLabel;
   private JLabel myTypeLabel;
-  private JPanel myTypeStatusPanel;
-  private JLabel myTypeStatusLabel;
-  private JTable myParametersTable;
-  private JLabel myTableLabel;
+  protected JBTable myParametersTable;
   private JCheckBox myStaticCheckBox;
-  private JBScrollPane myTablePane;
+  private JPanel myTablePane;
+
   private final DynamicManager myDynamicManager;
-  private final Project myProject;
-  private final EventListenerList myListenerList = new EventListenerList();
+  protected final Project myProject;
   private final PsiElement myContext;
   private final DynamicElementSettings mySettings;
 
-  private static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ui.DynamicDialog");
-
-  public DynamicDialog(PsiElement context, DynamicElementSettings settings, TypeConstraint[] typeConstraints) {
+  public DynamicDialog(PsiElement context, DynamicElementSettings settings, TypeConstraint[] typeConstraints, boolean isTableVisible) {
     super(context.getProject(), true);
     myProject = context.getProject();
-
-    if (!isTableVisible()) {
-      myParametersTable.setVisible(false);
-      myTableLabel.setVisible(false);
-    }
+    mySettings = settings;
     myContext = context;
-    setTitle(GroovyInspectionBundle.message("dynamic.element"));
     myDynamicManager = DynamicManager.getInstance(myProject);
 
-    init();
-
-    mySettings = settings;
+    if (isTableVisible) {
+      myTablePane.setBorder(IdeBorderFactory.createTitledBorder(GroovyBundle.message("dynamic.properties.table.name")));
+    }
+    else {
+      myTablePane.setVisible(false);
+    }
 
+    setTitle(GroovyInspectionBundle.message("dynamic.element"));
     setUpTypeComboBox(typeConstraints);
     setUpContainingClassComboBox();
-    setUpStatusLabel();
     setUpStaticComboBox();
 
-    myTableLabel.setLabelFor(myParametersTable);
-    setUpTableNameLabel(GroovyBundle.message("dynamic.properties.table.name"));
-
-    final Border border2 = BorderFactory.createLineBorder(Color.BLACK);
-    myParametersTable.setBorder(border2);
-    myParametersTable.setBackground(Color.WHITE);
-
-    myTypeLabel.setLabelFor(myTypeComboBox);
-    myClassLabel.setLabelFor(myClassComboBox);
+    init();
   }
 
   private void setUpStaticComboBox() {
-    myStaticCheckBox.setMnemonic(KeyEvent.VK_S);
     myStaticCheckBox.setSelected(mySettings.isStatic());
   }
 
@@ -124,36 +101,18 @@ public abstract class DynamicDialog extends DialogWrapper {
     return mySettings;
   }
 
-  protected void setUpTableNameLabel(String text) {
-    myTableLabel.setText(text);
-  }
-
-  private void setUpStatusLabel() {
-    if (!isTypeCheckerPanelEnable()) {
-      myTypeStatusPanel.setVisible(false);
-      return;
-    }
-    myTypeStatusLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
-
+  @Override
+  protected ValidationInfo doValidate() {
     final GrTypeElement typeElement = getEnteredTypeName();
     if (typeElement == null) {
-      setStatusTextAndIcon(IconLoader.getIcon("/compiler/warning.png"), GroovyInspectionBundle.message("no.type.specified"));
-      return;
+      return new ValidationInfo(GroovyInspectionBundle.message("no.type.specified"), myTypeComboBox);
     }
 
     final PsiType type = typeElement.getType();
     if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == null) {
-      setStatusTextAndIcon(IconLoader.getIcon("/compiler/warning.png"),
-                           GroovyInspectionBundle.message("unresolved.type.status", type.getPresentableText()));
-      return;
+      return new ValidationInfo(GroovyInspectionBundle.message("unresolved.type.status", type.getPresentableText()), myTypeComboBox);
     }
-    setStatusTextAndIcon(null, "");
-  }
-
-  private void setStatusTextAndIcon(@Nullable final Icon icon, final String text) {
-    myTypeStatusLabel.setIcon(icon);
-    myTypeStatusLabel.setText(text);
-    pack();
+    return null;
   }
 
   private void setUpContainingClassComboBox() {
@@ -174,12 +133,6 @@ public abstract class DynamicDialog extends DialogWrapper {
     for (PsiClass aClass : PsiUtil.iterateSupers(targetClass, true)) {
       myClassComboBox.addItem(aClass.getQualifiedName());
     }
-
-    myPanel.registerKeyboardAction(new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        myClassComboBox.requestFocus();
-      }
-    }, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
   }
 
   @Nullable
@@ -201,70 +154,19 @@ public abstract class DynamicDialog extends DialogWrapper {
     myTypeComboBox.setEditable(true);
     myTypeComboBox.grabFocus();
 
-    addDataChangeListener();
-
-    myTypeComboBox.addItemListener(
-        new ItemListener() {
-          public void itemStateChanged(ItemEvent e) {
-            fireDataChanged();
-          }
-        }
-    );
-
-    myPanel.registerKeyboardAction(new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        myTypeComboBox.requestFocus();
-      }
-    }, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
-
-
-    final EditorTextField editorTextField = (EditorTextField) myTypeComboBox.getEditor().getEditorComponent();
-
-    editorTextField.addDocumentListener(new DocumentListener() {
-      public void beforeDocumentChange(DocumentEvent event) {
-      }
-
-      public void documentChanged(DocumentEvent event) {
-        fireDataChanged();
-      }
-    });
-
     PsiType type = typeConstraints.length == 1 ? typeConstraints[0].getDefaultType() : TypesUtil.getJavaLangObject(myContext);
     myTypeComboBox.getEditor().setItem(createDocument(type.getCanonicalText()));
   }
 
-  protected void addDataChangeListener() {
-    myListenerList.add(DataChangedListener.class, new DataChangedListener());
-  }
-
-  class DataChangedListener implements EventListener {
-    void dataChanged() {
-      updateOkStatus();
-    }
-  }
-
-  protected void updateOkStatus() {
-    GrTypeElement typeElement = getEnteredTypeName();
-    if (typeElement == null) {
-      setOKActionEnabled(false);
-    } else {
-      setOKActionEnabled(true);
-    }
-
-    setUpStatusLabel();
-  }
-
   @Nullable
   public GrTypeElement getEnteredTypeName() {
     final Document typeEditorDocument = getTypeEditorDocument();
 
     if (typeEditorDocument == null) return null;
-
     try {
-      final String typeText = typeEditorDocument.getText();
-
-      return GroovyPsiElementFactory.getInstance(myProject).createTypeElement(typeText);
-    } catch (IncorrectOperationException e) {
+      return GroovyPsiElementFactory.getInstance(myProject).createTypeElement(typeEditorDocument.getText());
+    }
+    catch (IncorrectOperationException e) {
       return null;
     }
   }
@@ -273,17 +175,7 @@ public abstract class DynamicDialog extends DialogWrapper {
   public Document getTypeEditorDocument() {
     final Object item = myTypeComboBox.getEditor().getItem();
 
-    return item instanceof Document ? (Document) item : null;
-
-  }
-
-  protected void fireDataChanged() {
-    Object[] list = myListenerList.getListenerList();
-    for (Object aList : list) {
-      if (aList instanceof DataChangedListener) {
-        ((DataChangedListener) aList).dataChanged();
-      }
-    }
+    return item instanceof Document ? (Document)item : null;
   }
 
   @Nullable
@@ -300,7 +192,8 @@ public abstract class DynamicDialog extends DialogWrapper {
 
     if (typeElement == null) {
       mySettings.setType("java.lang.Object");
-    } else {
+    }
+    else {
       PsiType type = typeElement.getType();
       if (type instanceof PsiPrimitiveType) {
         type = TypesUtil.boxPrimitiveType(type, typeElement.getManager(), ProjectScope.getAllScope(myProject));
@@ -310,7 +203,8 @@ public abstract class DynamicDialog extends DialogWrapper {
 
       if (typeQualifiedName != null) {
         mySettings.setType(typeQualifiedName);
-      } else {
+      }
+      else {
         mySettings.setType(type.getPresentableText());
       }
     }
@@ -326,19 +220,23 @@ public abstract class DynamicDialog extends DialogWrapper {
             if (mySettings.isMethod()) {
               final List<MyPair> myPairList = mySettings.getPairs();
               final String[] argumentsTypes = QuickfixUtil.getArgumentsTypes(myPairList);
-              itemElement = myDynamicManager.findConcreteDynamicMethod(mySettings.getContainingClassName(), mySettings.getName(), argumentsTypes);
-            } else {
+              itemElement =
+                myDynamicManager.findConcreteDynamicMethod(mySettings.getContainingClassName(), mySettings.getName(), argumentsTypes);
+            }
+            else {
               itemElement = myDynamicManager.findConcreteDynamicProperty(mySettings.getContainingClassName(), mySettings.getName());
             }
 
             if (itemElement == null) {
-              Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
+              Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"),
+                                         GroovyInspectionBundle.message("Undo.disable"));
               return;
             }
             final DClassElement classElement = myDynamicManager.getClassElementByItem(itemElement);
 
             if (classElement == null) {
-              Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"), GroovyInspectionBundle.message("Undo.disable"));
+              Messages.showWarningDialog(myProject, GroovyInspectionBundle.message("Cannot.perform.undo.operation"),
+                                         GroovyInspectionBundle.message("Undo.disable"));
               return;
             }
 
@@ -367,7 +265,8 @@ public abstract class DynamicDialog extends DialogWrapper {
   public void addElement(final DynamicElementSettings settings) {
     if (settings.isMethod()) {
       myDynamicManager.addMethod(settings);
-    } else {
+    }
+    else {
       myDynamicManager.addProperty(settings);
     }
 
@@ -384,22 +283,6 @@ public abstract class DynamicDialog extends DialogWrapper {
     return myTypeComboBox;
   }
 
-protected boolean isTableVisible() {
-    return false;
-  }
-
-  public JTable getParametersTable() {
-    return myParametersTable;
-  }
-
-  protected static boolean isTypeCheckerPanelEnable() {
-    return true;
-  }
-
-  public Project getProject() {
-    return myProject;
-  }
-
   protected void setUpTypeLabel(String typeLabelText) {
     myTypeLabel.setText(typeLabelText);
   }
index 23f4687d6b607714ff96817ad806161ea2dec11a..498920707874381bcc972599ac809f45c4610767 100644 (file)
@@ -31,8 +31,6 @@ import org.jetbrains.plugins.groovy.lang.psi.expectedTypes.GroovyExpectedTypesPr
 import javax.swing.*;
 import javax.swing.event.CellEditorListener;
 import javax.swing.event.ChangeEvent;
-import javax.swing.event.TableModelEvent;
-import javax.swing.event.TableModelListener;
 import javax.swing.table.TableColumn;
 import java.awt.*;
 import java.util.EventObject;
@@ -45,7 +43,8 @@ import java.util.List;
 public class DynamicMethodDialog extends DynamicDialog {
 
   public DynamicMethodDialog(GrReferenceExpression referenceExpression) {
-    super(referenceExpression, QuickfixUtil.createSettings(referenceExpression), GroovyExpectedTypesProvider.calculateTypeConstraints((GrExpression)referenceExpression.getParent()));
+    super(referenceExpression, QuickfixUtil.createSettings(referenceExpression),
+          GroovyExpectedTypesProvider.calculateTypeConstraints((GrExpression)referenceExpression.getParent()), true);
     assert getSettings().isMethod();
 
     final List<MyPair> pairs = getSettings().getPairs();
@@ -55,22 +54,17 @@ public class DynamicMethodDialog extends DynamicDialog {
     setUpTypeLabel(GroovyBundle.message("dynamic.method.return.type"));
   }
 
-  protected void setUpTableNameLabel(String text) {
-    super.setUpTableNameLabel(getSettings().getPairs().isEmpty() ? GroovyBundle.message("dynamic.properties.table.no.arguments") : text);
-  }
-
   private void setupParameterTable(final List<MyPair> pairs) {
-    final JTable table = getParametersTable();
 
     MySuggestedNameCellEditor suggestedNameCellEditor = new MySuggestedNameCellEditor(QuickfixUtil.getArgumentsNames(pairs));
-    table.setDefaultEditor(String.class, suggestedNameCellEditor);
+    myParametersTable.setDefaultEditor(String.class, suggestedNameCellEditor);
 
     suggestedNameCellEditor.addCellEditorListener(new CellEditorListener() {
       public void editingStopped(ChangeEvent e) {
-        final int editingColumn = table.getSelectedColumn();
+        final int editingColumn = myParametersTable.getSelectedColumn();
         if (editingColumn != 0) return;
 
-        final int editingRow = table.getSelectedRow();
+        final int editingRow = myParametersTable.getSelectedRow();
         if (editingRow < 0 || editingRow >= pairs.size()) return;
 
         String newNameValue = ((MySuggestedNameCellEditor)e.getSource()).getCellEditorValue();
@@ -84,37 +78,26 @@ public class DynamicMethodDialog extends DynamicDialog {
     });
   }
 
-  protected boolean isTableVisible() {
-    return true;
-  }
-
   private void setupParameterList(List<MyPair> arguments) {
-    final JTable table = getParametersTable();
-
-    //TODO: add header
     final ListTableModel<MyPair> dataModel = new ListTableModel<MyPair>(new NameColumnInfo(), new TypeColumnInfo());
-    dataModel.addTableModelListener(new TableModelListener() {
-      public void tableChanged(TableModelEvent e) {
-        fireDataChanged();
-      }
-    });
     dataModel.setItems(arguments);
-    table.setModel(dataModel);
-    if (!arguments.isEmpty()) {
-      String max0 = arguments.get(0).first;
-      String max1 = arguments.get(0).second;
-      for (MyPair argument : arguments) {
-        if (argument.first.length() > max0.length()) max0 = argument.first;
-        if (argument.second.length() > max1.length()) max1 = argument.second;
-      }
+    myParametersTable.setModel(dataModel);
 
-      final FontMetrics metrics = table.getFontMetrics(table.getFont());
-      final TableColumn column0 = table.getColumnModel().getColumn(0);
-      column0.setPreferredWidth(metrics.stringWidth(max0 + "  "));
+    if (arguments.isEmpty()) return;
 
-      final TableColumn column1 = table.getColumnModel().getColumn(1);
-      column1.setPreferredWidth(metrics.stringWidth(max1 + "  "));
+    String max0 = arguments.get(0).first;
+    String max1 = arguments.get(0).second;
+    for (MyPair argument : arguments) {
+      if (argument.first.length() > max0.length()) max0 = argument.first;
+      if (argument.second.length() > max1.length()) max1 = argument.second;
     }
+
+    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 + "  "));
   }
 
 
@@ -134,7 +117,7 @@ public class DynamicMethodDialog extends DynamicDialog {
     public void setValue(MyPair pair, String value) {
       PsiType type;
       try {
-        type = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(value).getType();
+        type = GroovyPsiElementFactory.getInstance(myProject).createTypeElement(value).getType();
       }
       catch (IncorrectOperationException e) {
         return;
@@ -159,12 +142,6 @@ public class DynamicMethodDialog extends DynamicDialog {
     }
   }
 
-  protected void updateOkStatus() {
-    super.updateOkStatus();
-
-    if (getParametersTable().isEditing()) setOKActionEnabled(false);
-  }
-
   private static class MySuggestedNameCellEditor extends AbstractTableCellEditor {
     JTextField myNameField;
 
index 949e59cc5419c1f118ce47ad3ac7e8c888f90807..32c8373782427958334f1f10dc74a92e6b1804e1 100644 (file)
@@ -31,13 +31,14 @@ public class DynamicPropertyDialog extends DynamicDialog {
 
   public DynamicPropertyDialog(GrReferenceExpression referenceExpression) {
     super(referenceExpression, QuickfixUtil.createSettings(referenceExpression),
-          GroovyExpectedTypesProvider.calculateTypeConstraints(referenceExpression));
+          GroovyExpectedTypesProvider.calculateTypeConstraints(referenceExpression), false);
     setTitle(GroovyBundle.message("add.dynamic.property", referenceExpression.getReferenceName()));
     setUpTypeLabel(GroovyBundle.message("dynamic.method.property.type"));
   }
 
   public DynamicPropertyDialog(GrArgumentLabel label, PsiClass targetClass) {
     super(label, QuickfixUtil.createSettings(label, targetClass),
-          new SupertypeConstraint[]{SupertypeConstraint.create(label.getNamedArgument().getExpression().getType())});
+          new SupertypeConstraint[]{SupertypeConstraint.create(label.getNamedArgument().getExpression().getType())}, false);
+    setUpTypeLabel(GroovyBundle.message("dynamic.method.property.type"));
   }
 }