• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Camelcade / Perl5-IDEA / #525521553

27 May 2025 10:24AM UTC coverage: 82.286% (-0.03%) from 82.32%
#525521553

push

github

hurricup
Removed redundant implementations, moved up to the abstract class

1 of 1 new or added line in 1 file covered. (100.0%)

128 existing lines in 30 files now uncovered.

30886 of 37535 relevant lines covered (82.29%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/plugin/core/src/main/java/com/perl5/lang/perl/idea/run/GenericPerlRunConfigurationEditorPanel.java
1
/*
2
 * Copyright 2015-2025 Alexandr Evstigneev
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.perl5.lang.perl.idea.run;
18

19
import com.intellij.execution.CommonProgramRunConfigurationParameters;
20
import com.intellij.execution.ui.CommonProgramParametersPanel;
21
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
22
import com.intellij.openapi.project.Project;
23
import com.intellij.openapi.projectRoots.Sdk;
24
import com.intellij.openapi.projectRoots.impl.PerlSdkTable;
25
import com.intellij.openapi.ui.*;
26
import com.intellij.openapi.util.NlsContexts;
27
import com.intellij.openapi.util.text.StringUtil;
28
import com.intellij.openapi.vfs.LocalFileSystem;
29
import com.intellij.openapi.vfs.VirtualFile;
30
import com.intellij.ui.*;
31
import com.intellij.ui.components.JBCheckBox;
32
import com.intellij.ui.components.fields.ExpandableTextField;
33
import com.intellij.util.ObjectUtils;
34
import com.intellij.util.ui.UIUtil;
35
import com.perl5.PerlBundle;
36
import com.perl5.lang.perl.idea.configuration.settings.sdk.Perl5SdkConfigurable;
37
import com.perl5.lang.perl.idea.configuration.settings.sdk.Perl5SdkManipulator;
38
import com.perl5.lang.perl.idea.configuration.settings.sdk.wrappers.Perl5RealSdkWrapper;
39
import com.perl5.lang.perl.idea.configuration.settings.sdk.wrappers.Perl5SdkWrapper;
40
import net.miginfocom.swing.MigLayout;
41
import org.jetbrains.annotations.NotNull;
42
import org.jetbrains.annotations.Nullable;
43

44
import javax.swing.*;
45
import javax.swing.event.DocumentEvent;
46
import java.awt.*;
47
import java.nio.charset.Charset;
48
import java.util.ArrayList;
49
import java.util.Arrays;
50
import java.util.List;
51

52
import static com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration.PREREQUISITES_JOINER;
53
import static com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration.PREREQUISITES_PARSER;
54

55
public abstract class GenericPerlRunConfigurationEditorPanel<Configuration extends GenericPerlRunConfiguration>
56
  extends CommonProgramParametersPanel implements Perl5SdkManipulator {
57
  private @Nullable Sdk mySdkProxy;
58

59
  private final @NotNull Project myProject;
60

61
  private LabeledComponent<?> myScriptLabeledField;
62
  private JPanel myScriptField;
63

64
  private LabeledComponent<?> myLabeledConsoleCharset;
65
  private ComboBox<String> myConsoleCharset;
66

67
  private LabeledComponent<RawCommandLineEditor> myLabeledPerlArgumentsPanel;
68
  private RawCommandLineEditor myPerlArgumentsPanel;
69

70
  private JBCheckBox myAlternativeSdkCheckbox;
71
  private Perl5SdkConfigurable mySdkConfigurable;
72

73
  private LabeledComponent<ExpandableTextField> myRequiredModulesLabeledField;
74

75
  public GenericPerlRunConfigurationEditorPanel(@NotNull Project project) {
1✔
76
    myProject = project;
1✔
77
    mySdkConfigurable.setProject(project);
1✔
78
  }
1✔
79

80
  @Override
81
  protected void addComponents() {
82
    createLabeledComponents();
1✔
83
    add(myScriptLabeledField);
1✔
84
    super.addComponents();
1✔
85
    getLabeledComponents().forEach(this::add);
1✔
86
    add(createAlternativeSdkPanel());
1✔
87

88
    setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 5, true, false));
1✔
89
    setProgramParametersLabel(getProgramArgumentsLabel());
1✔
90
  }
1✔
91

92
  protected void createLabeledComponents() {
93
    createConsoleEncodingField();
1✔
94
    createPerlArgumentsField();
1✔
95
    createScriptField();
1✔
96
    createPrerequisitesField();
1✔
97
  }
1✔
98

99
  protected void createPrerequisitesField() {
100
    myRequiredModulesLabeledField = createLabeledComponent(
1✔
101
      new ExpandableTextField(PREREQUISITES_PARSER, PREREQUISITES_JOINER),
102
      PerlBundle.message("label.required.modules"),
1✔
103
      PerlBundle.message("tooltip.comma.separated.list.modules.required.to.run.configuration"));
1✔
104
  }
1✔
105

106
  protected static @NotNull <T extends JComponent> LabeledComponent<T> createLabeledComponent(@NotNull T component,
107
                                                                                              @NotNull @NlsContexts.Label String label,
108
                                                                                              @Nullable @NlsContexts.Tooltip String tooltip) {
109
    var labeledComponent = LabeledComponent.create(component, label, BorderLayout.WEST);
1✔
110
    if (tooltip != null) {
1✔
111
      labeledComponent.setToolTipText(tooltip);
1✔
112
      component.setToolTipText(tooltip);
1✔
113
    }
114
    return labeledComponent;
1✔
115
  }
116

117
  protected @NotNull List<LabeledComponent<?>> getLabeledComponents() {
118
    return Arrays.asList(myLabeledPerlArgumentsPanel, myLabeledConsoleCharset, myRequiredModulesLabeledField);
1✔
119
  }
120

121
  protected @NotNull String getProgramArgumentsLabel() {
122
    return PerlBundle.message("perl.run.option.script.arguments");
1✔
123
  }
124

125
  protected void createPerlArgumentsField() {
126
    myPerlArgumentsPanel = new RawCommandLineEditor();
1✔
127
    myLabeledPerlArgumentsPanel = LabeledComponent.create(myPerlArgumentsPanel, PerlBundle.message("perl.run.option.perl.arguments"));
1✔
128
    myLabeledPerlArgumentsPanel.setLabelLocation(BorderLayout.WEST);
1✔
129
    copyDialogCaption(myLabeledPerlArgumentsPanel);
1✔
130
  }
1✔
131

132
  private void createConsoleEncodingField() {
133
    myConsoleCharset = new ComboBox<>(new CollectionComboBoxModel<>(new ArrayList<>(Charset.availableCharsets().keySet())));
1✔
134
    myLabeledConsoleCharset = LabeledComponent.create(myConsoleCharset, PerlBundle.message("perl.run.option.output.encoding"));
1✔
135
    myLabeledConsoleCharset.setLabelLocation(BorderLayout.WEST);
1✔
136
  }
1✔
137

138
  protected @NotNull TextFieldWithBrowseButton createTextFieldForScript() {
139
    TextFieldWithBrowseButton fieldWithBrowseButton = new TextFieldWithBrowseButton();
1✔
140
    fieldWithBrowseButton.addBrowseFolderListener(
1✔
141
      myProject,
142
      FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()
1✔
143
        .withFileFilter(getRunConfigurationProducer()::isOurFile)
1✔
144
        .withTitle(PerlBundle.message("perl.run.config.select.script.header"))
1✔
145
        .withDescription(PerlBundle.message("perl.run.config.select.script.prompt")),
1✔
146
      TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
147
    return fieldWithBrowseButton;
1✔
148
  }
149

150
  protected @NotNull JPanel doCreateScriptField() {
151
    TextFieldWithBrowseButton scriptField = createTextFieldForScript();
1✔
152

153
    scriptField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
1✔
154
      @Override
155
      protected void textChanged(@NotNull DocumentEvent documentEvent) {
156
        VirtualFile file = LocalFileSystem.getInstance().findFileByPath(scriptField.getText());
×
157
        if (file != null) {
×
UNCOV
158
          myConsoleCharset.setSelectedItem(file.getCharset().displayName());
×
159
        }
160
        else {
UNCOV
161
          myConsoleCharset.setSelectedItem(null);
×
162
        }
UNCOV
163
      }
×
164
    });
165
    return scriptField;
1✔
166
  }
167

168
  protected @NotNull String getScriptFieldLabelText() {
169
    return PerlBundle.message("perl.run.option.script");
1✔
170
  }
171

172
  private void createScriptField() {
173
    myScriptField = doCreateScriptField();
1✔
174
    if (!(myScriptField instanceof TextAccessor)) {
1✔
UNCOV
175
      throw new RuntimeException("Script field must be a TextAccessor");
×
176
    }
177
    myScriptLabeledField = LabeledComponent.create(myScriptField, getScriptFieldLabelText());
1✔
178
    myScriptLabeledField.setLabelLocation(BorderLayout.WEST);
1✔
179
  }
1✔
180

181
  private @NotNull JPanel createAlternativeSdkPanel() {
182
    JPanel alternativeSdkPanel = new JPanel(new MigLayout("ins 0, gap 10, fill, flowx"));
1✔
183
    myAlternativeSdkCheckbox = new JBCheckBox();
1✔
184
    mySdkConfigurable = new Perl5SdkConfigurable(this, null);
1✔
185
    alternativeSdkPanel.add(myAlternativeSdkCheckbox, "shrinkx");
1✔
186
    JComponent sdkComponent = mySdkConfigurable.createComponent();
1✔
187
    mySdkConfigurable.setLabelText(PerlBundle.message("perl.run.config.use.alternative.label"));
1✔
188
    alternativeSdkPanel.add(sdkComponent, "growx, pushx");
1✔
189
    myAlternativeSdkCheckbox.addChangeListener(e -> mySdkConfigurable.setEnabled(myAlternativeSdkCheckbox.isSelected()));
1✔
190
    return alternativeSdkPanel;
1✔
191
  }
192

193
  @Override
194
  protected final void setupAnchor() {
195
    super.setupAnchor();
1✔
196
    List<PanelWithAnchor> components = new ArrayList<>(getLabeledComponents());
1✔
197
    components.addFirst(myScriptLabeledField);
1✔
198
    components.addFirst(this);
1✔
199
    myAnchor = UIUtil.mergeComponentsWithAnchor(components);
1✔
200
  }
1✔
201

202
  protected void reset(Configuration runConfiguration) {
203
    ((TextAccessor)myScriptField).setText(runConfiguration.getScriptPath());
1✔
204
    myRequiredModulesLabeledField.getComponent().setText(runConfiguration.getRequiredModules());
1✔
205
    myConsoleCharset.setSelectedItem(runConfiguration.getConsoleCharset());
1✔
206
    myPerlArgumentsPanel.setText(runConfiguration.getPerlArguments());
1✔
207
    myAlternativeSdkCheckbox.setSelected(runConfiguration.isUseAlternativeSdk());
1✔
208
    mySdkConfigurable.setEnabled(runConfiguration.isUseAlternativeSdk());
1✔
209
    mySdkProxy = PerlSdkTable.getInstance().findJdk(runConfiguration.getAlternativeSdkName());
1✔
210
    mySdkConfigurable.reset();
1✔
211
    super.reset(runConfiguration);
1✔
212
  }
1✔
213

214
  protected void applyTo(Configuration runConfiguration) {
215
    runConfiguration.setRequiredModules(myRequiredModulesLabeledField.getComponent().getText());
1✔
216
    runConfiguration.setScriptPath(((TextAccessor)myScriptField).getText());
1✔
217
    runConfiguration.setConsoleCharset(StringUtil.nullize((String)myConsoleCharset.getSelectedItem(), true));
1✔
218
    runConfiguration.setPerlArguments(myPerlArgumentsPanel.getText());
1✔
219
    runConfiguration.setUseAlternativeSdk(myAlternativeSdkCheckbox.isSelected());
1✔
220
    mySdkConfigurable.apply();
1✔
221
    runConfiguration.setAlternativeSdkName(ObjectUtils.doIfNotNull(mySdkProxy, Sdk::getName));
1✔
222
    super.applyTo(runConfiguration);
1✔
223
  }
1✔
224

225
  @Override
226
  public final void reset(@NotNull CommonProgramRunConfigurationParameters configuration) {
UNCOV
227
    throw new RuntimeException("Should not be invoked");
×
228
  }
229

230
  @Override
231
  public final void applyTo(@NotNull CommonProgramRunConfigurationParameters configuration) {
UNCOV
232
    throw new RuntimeException("Should not be invoked");
×
233
  }
234

235
  public void disposeUIResources() {
236
    mySdkConfigurable.disposeUIResources();
1✔
237
  }
1✔
238

239
  @Override
240
  public Perl5SdkWrapper getCurrentSdkWrapper() {
241
    return mySdkProxy == null ? null : new Perl5RealSdkWrapper(mySdkProxy);
1✔
242
  }
243

244
  @Override
245
  public void setSdk(@Nullable Sdk sdk) {
246
    mySdkProxy = sdk;
×
UNCOV
247
  }
×
248

249
  /**
250
   * @return a run configuration producer for the run configuration
251
   */
252
  protected abstract @NotNull GenericPerlRunConfigurationProducer<Configuration> getRunConfigurationProducer();
253
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc