Skip to content

Commit 2a0f4d4

Browse files
author
Vasilii Burlacu
committed
Added the possibility to set custom license name
1 parent f86c358 commit 2a0f4d4

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>
6-
<xy x="48" y="54" width="462" height="381"/>
6+
<xy x="48" y="54" width="462" height="431"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.java

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
import org.jetbrains.annotations.NotNull;
2626
import org.jetbrains.annotations.Nullable;
2727
import javax.swing.*;
28+
import javax.swing.event.ListSelectionEvent;
29+
import javax.swing.event.ListSelectionListener;
2830
import java.awt.*;
2931
import java.awt.event.*;
30-
import java.util.ArrayList;
3132
import java.util.List;
3233
import java.util.Vector;
3334

34-
public class NewMagentoModuleDialog extends AbstractDialog {
35+
public class NewMagentoModuleDialog extends AbstractDialog implements ListSelectionListener {
3536
@NotNull
3637
private final Project project;
3738
@NotNull
@@ -63,7 +64,6 @@ public class NewMagentoModuleDialog extends AbstractDialog {
6364
private JTextField moduleLicenseCustom;
6465
private JScrollPane moduleLicenseScrollPanel;
6566
private String detectedPackageName;
66-
private String[] licensesNames;
6767

6868
public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
6969
this.project = project;
@@ -76,24 +76,15 @@ public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory in
7676
this.camelCaseToHyphen = CamelCaseToHyphen.getInstance();
7777
this.validator = NewMagentoModuleDialogValidator.getInstance(this);
7878
this.navigateToCreatedFile = NavigateToCreatedFile.getInstance();
79-
80-
Package.License[] licenses = Package.License.values();
81-
Vector licenseNames = new Vector<String>(licenses.length);
82-
83-
for (Package.License license: licenses) {
84-
// licensesNames.push(license.getLicenseName());
85-
licenseNames.add(license.getLicenseName());
86-
}
87-
88-
// moduleLicense.setListData(licenses);
89-
moduleLicense.setListData(licenseNames);
90-
moduleLicense.setSelectedIndex(0);
91-
9279
detectPackageName(initialBaseDir);
9380
setContentPane(contentPane);
9481
setModal(true);
9582
getRootPane().setDefaultButton(buttonOK);
9683
pushToMiddle();
84+
setLicenses();
85+
86+
moduleLicenseCustom.setToolTipText("Custom License Name");
87+
moduleLicenseCustom.setText("Custom License Name");
9788

9889
buttonOK.addActionListener(new ActionListener() {
9990
public void actionPerformed(ActionEvent e) {
@@ -202,8 +193,25 @@ public String getModuleVersion() {
202193
return this.moduleVersion.getText().trim();
203194
}
204195

196+
/**
197+
* Retrieve selected licenses name for the module
198+
*
199+
* @return List
200+
*/
205201
public List getModuleLicense() {
206-
return this.moduleLicense.getSelectedValuesList();
202+
List selectedLicenses = this.moduleLicense.getSelectedValuesList();
203+
Package.License customLicense = Package.License.CUSTOM;
204+
205+
/**
206+
* When custom license is selected, the selected label "Custom License"
207+
* must be replaced with the custom license name provided
208+
*/
209+
if (selectedLicenses.contains(customLicense.getLicenseName())) {
210+
selectedLicenses.remove(customLicense.getLicenseName());
211+
selectedLicenses.add(moduleLicenseCustom.getText());
212+
}
213+
214+
return selectedLicenses;
207215
}
208216

209217
public static void open(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
@@ -218,4 +226,43 @@ private String getComposerPackageName() {
218226
.concat("/")
219227
.concat(camelCaseToHyphen.convert(getModuleName()));
220228
}
229+
230+
/**
231+
* Set licenses to select from
232+
*/
233+
private void setLicenses() {
234+
Package.License[] licenses = Package.License.values();
235+
Vector<String> licenseNames = new Vector<>(licenses.length);
236+
237+
for (Package.License license: licenses) {
238+
licenseNames.add(license.getLicenseName());
239+
}
240+
241+
moduleLicense.setListData(licenseNames);
242+
moduleLicense.setSelectedIndex(0);
243+
moduleLicense.addListSelectionListener(this);
244+
}
245+
246+
/**
247+
* Make the Custom Module License input available when custom license is selected
248+
*/
249+
private void handleModuleCustomLicenseInputVisibility () {
250+
boolean isCustomLicenseSelected = false;
251+
252+
for (Object value: moduleLicense.getSelectedValuesList()) {
253+
if (Package.License.CUSTOM.getLicenseName().equals(value.toString())) {
254+
isCustomLicenseSelected = true;
255+
256+
break;
257+
}
258+
}
259+
260+
moduleLicenseCustom.setEnabled(isCustomLicenseSelected);
261+
moduleLicenseCustom.setEditable(isCustomLicenseSelected);
262+
}
263+
264+
@Override
265+
public void valueChanged(ListSelectionEvent listSelectionEvent) {
266+
handleModuleCustomLicenseInputVisibility();
267+
}
221268
}

src/com/magento/idea/magento2plugin/magento/packages/Package.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public static enum License {
3131
GPL("GNU General Public License (GPL)"),
3232
BSDL("Berkeley Software Distribution License (BSDL)"),
3333
ASL("Apache Software License (ASL)"),
34-
AFL("Academic Free License (AFL)");
34+
AFL("Academic Free License (AFL)"),
35+
CUSTOM("Custom License");
3536

3637
private String licenseName;
3738

0 commit comments

Comments
 (0)