public MainStep()

in flex/src/com/intellij/lang/javascript/ui/newclass/MainStep.java [142:324]


  public MainStep(WizardModel model, final Project project,
                  final @Nullable String initialClassName,
                  final boolean isClassNameEditable,
                  final String packageName,
                  final @Nullable JSClass baseClassifier,
                  final boolean baseClassEditable,
                  final String templateName,
                  final PsiElement context,
                  final @NlsContexts.DialogTitle String superclassChooserTitle,
                  Supplier<List<FileTemplate>> applicableTemplatesProvider) {
    super(null);
    myModel = model;
    myProject = project;
    myPackageNameInitial = packageName;
    myBaseClassifier = baseClassifier;
    myContext = context;
    mySuperclassChooserTitle = superclassChooserTitle;
    myApplicableTemplatesProvider = applicableTemplatesProvider;

    createUIComponents();

    myPanel = new JPanel(new GridBagLayout());

    myNameLabel = new JLabel();
    setLabelTextAndMnemonic(myNameLabel, JavaScriptBundle.message("create.class.name.label"));
    Insets insets = new Insets(0, 0, 5, 0);
    myPanel.add(myNameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
                                                    GridBagConstraints.HORIZONTAL, insets, 0, 0));

    myClassNameTextField = new JTextField();
    myClassNameTextField.setMinimumSize(new Dimension(300, myClassNameTextField.getMinimumSize().height));
    myPanel.add(myClassNameTextField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0, GridBagConstraints.SOUTH,
                                                             GridBagConstraints.HORIZONTAL, insets, 0, 0));
    myNameLabel.setLabelFor(myClassNameTextField);

    myUpDownHint = new JLabel();
    myPanel.add(myUpDownHint, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,
                                                     GridBagConstraints.HORIZONTAL, new Insets(0, 10, 5, 5), 0, 0));

    final JLabel packageLabel = new JLabel();
    setLabelTextAndMnemonic(packageLabel, JavaScriptBundle.message("create.class.package.label"));
    myPanel.add(packageLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
                                                     GridBagConstraints.HORIZONTAL, insets, 0, 0));
    myPanel.add(myPackageCombo, new GridBagConstraints(1, 1, 2, 1, 1.0, 0, GridBagConstraints.SOUTH,
                                                       GridBagConstraints.HORIZONTAL, insets, 0, 0));

    JLabel templateLabel = new JLabel();
    setLabelTextAndMnemonic(templateLabel, JavaScriptBundle.message("create.class.template.label"));
    myPanel.add(templateLabel, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
                                                      GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    myTemplateComboWithBrowse = new ComboboxWithBrowseButton();
    myPanel.add(myTemplateComboWithBrowse, new GridBagConstraints(1, 2, 2, 1, 1.0, 0, GridBagConstraints.SOUTH,
                                                                  GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    templateLabel.setLabelFor(myTemplateComboWithBrowse.getChildComponent());

    mySpacer = new JPanel();
    myPanel.add(mySpacer, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST,
                                                 GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

    mySuperClassLabel = new JLabel();
    setLabelTextAndMnemonic(mySuperClassLabel, JavaScriptBundle.message("create.class.superclass.label"));
    myPanel.add(mySuperClassLabel, new GridBagConstraints(0, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
                                                          GridBagConstraints.HORIZONTAL, insets, 0, 0));
    myPanel.add(mySuperClassField, new GridBagConstraints(1, 4, 2, 1, 1.0, 0, GridBagConstraints.SOUTH,
                                                          GridBagConstraints.HORIZONTAL, insets, 0, 0));

    myInterfacesLabel = new JLabel();
    setLabelTextAndMnemonic(myInterfacesLabel, JavaScriptBundle.message("create.class.interfaces.label"));
    myNameLabel.setMinimumSize(mySuperClassLabel.getMinimumSize());
    myPanel.add(myInterfacesLabel, new GridBagConstraints(0, 5, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
                                                          GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    myInterfacesPanel = new JPanel(new BorderLayout());
    myPanel.add(myInterfacesPanel, new GridBagConstraints(1, 5, 2, 1, 1.0, 1.0, GridBagConstraints.WEST,
                                                          GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    myPlaceholderPanel = new JPanel();
    myPanel.add(myPlaceholderPanel, new GridBagConstraints(1, 6, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH,
                                                           GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    // call of createUIComponents() is placed here by UI Designer instrumenter (before first method call which is setTitle())
    // myModule is initialized in createUIComponents() because it is used there
    // myModule = ModuleUtil.findModuleForPsiElement(context);

    UserActivityWatcher w = new UserActivityWatcher();
    w.register(myPanel);

    myClassNameTextField.setEditable(isClassNameEditable);

    myInterfacesListModel = new SortedListModel<>(StringUtil::naturalCompare);
    final String baseInterfaceFqn;
    if (myBaseClassifier != null && myBaseClassifier.isInterface()) {
      myInterfacesListModel.add(baseInterfaceFqn = myBaseClassifier.getQualifiedName());
    }
    else {
      baseInterfaceFqn = null;
    }

    myInterfacesList = new JBList(myInterfacesListModel);
    if (baseInterfaceFqn != null) {
      myInterfacesList.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(final JList list,
                                                      final Object value,
                                                      final int index,
                                                      final boolean isSelected,
                                                      final boolean cellHasFocus) {
          JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected,
                                                                    cellHasFocus);
          if (baseInterfaceFqn.equals(value)) {
            label.setForeground(UIUtil.getLabelDisabledForeground());
          }
          else {
            label.setForeground(UIUtil.getLabelForeground());
          }
          return label;
        }
      });
    }
    myInterfacesList.disableEmptyText();
    JPanel p = ToolbarDecorator.createDecorator(myInterfacesList).setAddAction(anActionButton -> {
      String chooserTitle = JavaScriptBundle.message("choose.super.interface.title");
      if (DumbService.getInstance(project).isDumb()) {
        Messages.showWarningDialog(JavaScriptBundle.message("class.chooser.not.available.in.dumb.mode"), chooserTitle);
        return;
      }
      JSClassChooserDialog chooser =
        new JSClassChooserDialog(project, chooserTitle, getSuperclassScope(), null,
                                 jsClass -> jsClass.isInterface() && myInterfacesListModel.indexOf(jsClass.getQualifiedName()) == -1);
      if (chooser.showDialog()) {
        JSClass selected = chooser.getSelectedClass();
        if (selected != null) {
          myInterfacesListModel.add(selected.getQualifiedName());
        }
      }
    }).setMoveUpAction(null).setMoveDownAction(null).
      setRemoveActionUpdater(e -> myBaseClassifier == null ||
                              !myBaseClassifier.isInterface() ||
                              !ArrayUtil.contains(myBaseClassifier.getQualifiedName(), myInterfacesList.getSelectedValues())).setVisibleRowCount(2).createPanel();
    myInterfacesPanel.add(p, BorderLayout.CENTER);
    myInterfacesLabel.setLabelFor(myInterfacesList);
    p.setMinimumSize(p.getPreferredSize());
    initUpDownHint();

    fillTemplates(templateName);

    packageLabel.setLabelFor(myPackageCombo.getChildComponent());
    packageLabel.setPreferredSize(mySuperClassLabel.getPreferredSize());

    mySuperClassLabel.setLabelFor(mySuperClassField);
    mySuperClassLabel.setText(JavaScriptBundle.message("superclass.label.text"));
    if (!baseClassEditable && myBaseClassifier != null && !myBaseClassifier.isInterface()) {
      mySuperClassLabel.setEnabled(false);
      mySuperClassField.setEnabled(false);
      mySuperClassField.setText(myBaseClassifier.getQualifiedName());
    }

    myTemplateComboWithBrowse.addActionListener(e -> {
      FileTemplate template = (FileTemplate)myTemplateComboWithBrowse.getComboBox().getSelectedItem();
      final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
      util.editConfigurable(project, new AllFileTemplatesConfigurable(myProject));
      fillTemplates(template.getName());
      updateOnTemplateChange();
      fireStateChanged();
    });

    myTemplateComboWithBrowse.getComboBox().setRenderer(SimpleListCellRenderer.<FileTemplate>create(
      (label, value, index) -> {
      if (value != null) {
        label.setText(ActionScriptCreateClassOrInterfaceFix.getTemplateShortName(value.getName()));
        label.setIcon(ActionScriptCreateClassOrInterfaceFix.getTemplateIcon(value));
      }
    }));

    // need to register this listener *after* user activity watcher
    myTemplateComboWithBrowse.getComboBox().addItemListener(e -> updateOnTemplateChange());

    myClassNameTextField.setText(initialClassName);
    //myPackageCombo.getButton().setPreferredSize(myTemplateComboWithBrowse.getButton().getPreferredSize());

    myResizeDispatcher = EventDispatcher.create(ChangeListener.class);
    updateOnTemplateChange();
    w.addUserActivityListener(this::fireStateChanged);
  }