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

Camelcade / Perl5-IDEA / #525521576

05 Jun 2025 06:17AM UTC coverage: 82.298% (-0.02%) from 82.318%
#525521576

push

github

hurricup
Localized strings and improved annotations

26 of 41 new or added lines in 19 files covered. (63.41%)

22 existing lines in 6 files now uncovered.

30837 of 37470 relevant lines covered (82.3%)

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.Nls;
42
import org.jetbrains.annotations.NotNull;
43
import org.jetbrains.annotations.Nullable;
44

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

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

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

60
  private final @NotNull Project myProject;
61

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

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

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

71
  private JBCheckBox myAlternativeSdkCheckbox;
72
  private Perl5SdkConfigurable mySdkConfigurable;
73

74
  private LabeledComponent<ExpandableTextField> myRequiredModulesLabeledField;
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

250
  /**
251
   * @return a run configuration producer for the run configuration
252
   */
253
  protected abstract @NotNull GenericPerlRunConfigurationProducer<? extends Configuration> getRunConfigurationProducer();
254
}
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