Search in sources :

Example 1 with GrFinalListener

use of org.jetbrains.plugins.groovy.refactoring.introduce.GrFinalListener in project intellij-community by JetBrains.

the class GrInplaceVariableIntroducer method getComponent.

@Override
protected JComponent getComponent() {
    myCanBeFinalCb = new NonFocusableCheckBox("Declare final");
    myCanBeFinalCb.setSelected(false);
    myCanBeFinalCb.setMnemonic('f');
    final GrFinalListener finalListener = new GrFinalListener(myEditor);
    myCanBeFinalCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new WriteCommandAction(myProject, getCommandName(), getCommandName()) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
                    final GrVariable variable = getVariable();
                    if (variable != null) {
                        finalListener.perform(myCanBeFinalCb.isSelected(), variable);
                    }
                }
            }.execute();
        }
    });
    final JPanel panel = new JPanel(new GridBagLayout());
    panel.setBorder(null);
    if (myCanBeFinalCb != null) {
        panel.add(myCanBeFinalCb, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    }
    panel.add(Box.createVerticalBox(), new GridBagConstraints(0, 2, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    return panel;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) GrFinalListener(org.jetbrains.plugins.groovy.refactoring.introduce.GrFinalListener) ActionEvent(java.awt.event.ActionEvent) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) ActionListener(java.awt.event.ActionListener) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox)

Aggregations

Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 NotNull (org.jetbrains.annotations.NotNull)1 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)1 GrFinalListener (org.jetbrains.plugins.groovy.refactoring.introduce.GrFinalListener)1