Search in sources :

Example 1 with TemplatesPanel

use of org.jetbrains.java.generate.view.TemplatesPanel in project intellij-community by JetBrains.

the class GenerateGetterSetterHandlerBase method getHeaderPanel.

protected static JComponent getHeaderPanel(final Project project, final TemplatesManager templatesManager, final String templatesTitle) {
    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel templateChooserLabel = new JLabel(templatesTitle);
    panel.add(templateChooserLabel, BorderLayout.WEST);
    final ComboBox comboBox = new ComboBox();
    templateChooserLabel.setLabelFor(comboBox);
    comboBox.setRenderer(new ListCellRendererWrapper<TemplateResource>() {

        @Override
        public void customize(JList list, TemplateResource value, int index, boolean selected, boolean hasFocus) {
            setText(value.getName());
        }
    });
    final ComponentWithBrowseButton<ComboBox> comboBoxWithBrowseButton = new ComponentWithBrowseButton<>(comboBox, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final TemplatesPanel ui = new TemplatesPanel(project, templatesManager) {

                @Override
                protected boolean onMultipleFields() {
                    return false;
                }

                @Nls
                @Override
                public String getDisplayName() {
                    return StringUtil.capitalizeWords(UIUtil.removeMnemonic(StringUtil.trimEnd(templatesTitle, ":")), true);
                }
            };
            ui.setHint("Visibility is applied according to File | Settings | Editor | Code Style | Java | Code Generation");
            ui.selectNodeInTree(templatesManager.getDefaultTemplate());
            if (ShowSettingsUtil.getInstance().editConfigurable(panel, ui)) {
                setComboboxModel(templatesManager, comboBox);
            }
        }
    });
    setComboboxModel(templatesManager, comboBox);
    comboBox.addActionListener(new ActionListener() {

        public void actionPerformed(@NotNull final ActionEvent M) {
            templatesManager.setDefaultTemplate((TemplateResource) comboBox.getSelectedItem());
        }
    });
    panel.add(comboBoxWithBrowseButton, BorderLayout.CENTER);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) TemplatesPanel(org.jetbrains.java.generate.view.TemplatesPanel) ActionListener(java.awt.event.ActionListener) Nls(org.jetbrains.annotations.Nls) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) TemplateResource(org.jetbrains.java.generate.template.TemplateResource)

Aggregations

ComboBox (com.intellij.openapi.ui.ComboBox)1 ComponentWithBrowseButton (com.intellij.openapi.ui.ComponentWithBrowseButton)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Nls (org.jetbrains.annotations.Nls)1 TemplateResource (org.jetbrains.java.generate.template.TemplateResource)1 TemplatesPanel (org.jetbrains.java.generate.view.TemplatesPanel)1