public void setTemplate(FileTemplate template, URL defaultDescription) {
   myDefaultDescriptionUrl = defaultDescription;
   myTemplate = template;
   if (myMainPanel != null) {
     reset();
     myNameField.selectAll();
     myExtensionField.selectAll();
   }
 }
 @Override
 public boolean isModified() {
   if (myModified) {
     return true;
   }
   String name = (myTemplate == null) ? "" : myTemplate.getName();
   String extension = (myTemplate == null) ? "" : myTemplate.getExtension();
   if (!Comparing.equal(name, myNameField.getText())) {
     return true;
   }
   if (!Comparing.equal(extension, myExtensionField.getText())) {
     return true;
   }
   if (myTemplate != null) {
     if (myTemplate.isReformatCode() != myAdjustBox.isSelected()) {
       return true;
     }
   }
   return false;
 }
 @Override
 public void apply() throws ConfigurationException {
   if (myTemplate != null) {
     myTemplate.setText(myTemplateEditor.getDocument().getText());
     String name = myNameField.getText();
     String extension = myExtensionField.getText();
     int lastDotIndex = extension.lastIndexOf(".");
     if (lastDotIndex >= 0) {
       name += extension.substring(0, lastDotIndex + 1);
       extension = extension.substring(lastDotIndex + 1);
     }
     if (name.length() == 0 || !isValidFilename(name + "." + extension)) {
       throw new ConfigurationException(
           IdeBundle.message("error.invalid.template.file.name.or.extension"));
     }
     myTemplate.setName(name);
     myTemplate.setExtension(extension);
     myTemplate.setReformatCode(myAdjustBox.isSelected());
   }
   myModified = false;
 }
  @Override
  public void reset() {
    final String text = (myTemplate == null) ? "" : myTemplate.getText();
    String name = (myTemplate == null) ? "" : myTemplate.getName();
    String extension = (myTemplate == null) ? "" : myTemplate.getExtension();
    String description = (myTemplate == null) ? "" : myTemplate.getDescription();

    if ((description.length() == 0) && (myDefaultDescriptionUrl != null)) {
      try {
        description = UrlUtil.loadText(myDefaultDescriptionUrl);
      } catch (IOException e) {
        LOG.error(e);
      }
    }

    EditorFactory.getInstance().releaseEditor(myTemplateEditor);
    myFile = createFile(text, name);
    myTemplateEditor = createEditor();

    boolean adjust = (myTemplate != null) && myTemplate.isReformatCode();
    myNameField.setText(name);
    myExtensionField.setText(extension);
    myAdjustBox.setSelected(adjust);
    String desc = description.length() > 0 ? description : EMPTY_HTML;

    // [myakovlev] do not delete these stupid lines! Or you get Exception!
    myDescriptionComponent.setContentType(CONTENT_TYPE_PLAIN);
    myDescriptionComponent.setEditable(true);
    myDescriptionComponent.setText(desc);
    myDescriptionComponent.setContentType(UIUtil.HTML_MIME);
    myDescriptionComponent.setText(desc);
    myDescriptionComponent.setCaretPosition(0);
    myDescriptionComponent.setEditable(false);

    myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description));

    myNameField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
    myExtensionField.setEditable((myTemplate != null) && (!myTemplate.isDefault()));
    myModified = false;
  }
 public void focusToExtensionField() {
   myExtensionField.selectAll();
   myExtensionField.requestFocus();
 }
 public void focusToNameField() {
   myNameField.selectAll();
   myNameField.requestFocus();
 }
 public String getExtensionValue() {
   return myExtensionField.getText();
 }
 public String getNameValue() {
   return myNameField.getText();
 }
  @Override
  public JComponent createComponent() {
    myMainPanel = new JPanel(new GridBagLayout());
    myNameField = new JTextField();
    myExtensionField = new JTextField();
    mySplitter = new Splitter(true, 0.4f);

    myTemplateEditor = createEditor();

    myDescriptionComponent = new JEditorPane(UIUtil.HTML_MIME, EMPTY_HTML);
    myDescriptionComponent.setEditable(false);

    myAdjustBox = new JCheckBox(IdeBundle.message("checkbox.reformat.according.to.style"));
    myTopPanel = new JPanel(new GridBagLayout());

    myDescriptionPanel = new JPanel(new GridBagLayout());
    myDescriptionPanel.add(
        SeparatorFactory.createSeparator(IdeBundle.message("label.description"), null),
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 2, 0),
            0,
            0));
    myDescriptionPanel.add(
        ScrollPaneFactory.createScrollPane(myDescriptionComponent),
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(2, 0, 0, 0),
            0,
            0));

    myMainPanel.add(
        myTopPanel,
        new GridBagConstraints(
            0,
            0,
            4,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 2, 0),
            0,
            0));
    myMainPanel.add(
        myAdjustBox,
        new GridBagConstraints(
            0,
            1,
            4,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(2, 0, 2, 0),
            0,
            0));
    myMainPanel.add(
        mySplitter,
        new GridBagConstraints(
            0,
            2,
            4,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(2, 0, 0, 0),
            0,
            0));

    mySplitter.setSecondComponent(myDescriptionPanel);
    setShowInternalMessage(null);

    myNameField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onNameChanged();
          }
        });
    myExtensionField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onNameChanged();
          }
        });
    myMainPanel.setPreferredSize(new Dimension(400, 300));
    return myMainPanel;
  }
 public void setShowInternalMessage(String message) {
   if (message == null) {
     myTopPanel.removeAll();
     myTopPanel.add(
         new JLabel(IdeBundle.message("label.name")),
         new GridBagConstraints(
             0,
             0,
             1,
             1,
             0.0,
             0.0,
             GridBagConstraints.CENTER,
             GridBagConstraints.NONE,
             new Insets(0, 0, 0, 2),
             0,
             0));
     myTopPanel.add(
         myNameField,
         new GridBagConstraints(
             1,
             0,
             1,
             1,
             1.0,
             0.0,
             GridBagConstraints.CENTER,
             GridBagConstraints.HORIZONTAL,
             new Insets(0, 2, 0, 2),
             0,
             0));
     myTopPanel.add(
         new JLabel(IdeBundle.message("label.extension")),
         new GridBagConstraints(
             2,
             0,
             1,
             1,
             0.0,
             0.0,
             GridBagConstraints.CENTER,
             GridBagConstraints.NONE,
             new Insets(0, 2, 0, 2),
             0,
             0));
     myTopPanel.add(
         myExtensionField,
         new GridBagConstraints(
             3,
             0,
             1,
             1,
             .3,
             0.0,
             GridBagConstraints.CENTER,
             GridBagConstraints.HORIZONTAL,
             new Insets(0, 2, 0, 0),
             0,
             0));
     myExtensionField.setColumns(7);
   } else {
     myTopPanel.removeAll();
     myTopPanel.add(
         new JLabel(message),
         new GridBagConstraints(
             0,
             0,
             4,
             1,
             1.0,
             0.0,
             GridBagConstraints.WEST,
             GridBagConstraints.HORIZONTAL,
             new Insets(0, 0, 0, 0),
             0,
             0));
     myTopPanel.add(
         Box.createVerticalStrut(myNameField.getPreferredSize().height),
         new GridBagConstraints(
             4,
             0,
             1,
             1,
             0.0,
             0.0,
             GridBagConstraints.WEST,
             GridBagConstraints.HORIZONTAL,
             new Insets(0, 0, 0, 0),
             0,
             0));
   }
   myMainPanel.revalidate();
   myTopPanel.repaint();
 }