Skip to content

Commit f723a9a

Browse files
author
Vitaliy
authored
Merge pull request #77 from vasilii-b/new-module-creation-add-license
Add license select to the new module
2 parents 9dfde00 + e35cd32 commit f723a9a

File tree

6 files changed

+165
-11
lines changed

6 files changed

+165
-11
lines changed

resources/fileTemplates/internal/Magento Module Composer.json.ft

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
},
1010
#end
1111
#if (${LICENSE})
12-
${LICENSE},
12+
"license":
13+
${LICENSE}
14+
,
1315
#end
1416
"autoload": {
1517
"files": [

src/com/magento/idea/magento2plugin/actions/generation/data/ModuleComposerJsonData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.magento.idea.magento2plugin.actions.generation.data;
66

77
import com.intellij.psi.PsiDirectory;
8+
import java.util.List;
89

910
public class ModuleComposerJsonData {
1011
private final String packageName;
@@ -13,21 +14,24 @@ public class ModuleComposerJsonData {
1314
private final String moduleDescription;
1415
private final String composerPackageName;
1516
private final String moduleVersion;
17+
private final List moduleLicense;
1618

1719
public ModuleComposerJsonData(
1820
String packageName,
1921
String moduleName,
2022
PsiDirectory baseDir,
2123
String moduleDescription,
2224
String composerPackageName,
23-
String moduleVersion
25+
String moduleVersion,
26+
List moduleLicense
2427
) {
2528
this.packageName = packageName;
2629
this.moduleName = moduleName;
2730
this.baseDir = baseDir;
2831
this.moduleDescription = moduleDescription;
2932
this.composerPackageName = composerPackageName;
3033
this.moduleVersion = moduleVersion;
34+
this.moduleLicense = moduleLicense;
3135
}
3236

3337
public String getPackageName() {
@@ -53,4 +57,8 @@ public String getComposerPackageName() {
5357
public String getModuleVersion() {
5458
return this.moduleVersion;
5559
}
60+
61+
public List getModuleLicense() {
62+
return this.moduleLicense;
63+
}
5664
}

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
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="297"/>
6+
<xy x="48" y="54" width="462" height="431"/>
77
</constraints>
8-
<properties/>
8+
<properties>
9+
<preferredSize width="350" height="391"/>
10+
</properties>
911
<border type="none"/>
1012
<children>
1113
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -49,7 +51,7 @@
4951
</grid>
5052
</children>
5153
</grid>
52-
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
54+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
5355
<margin top="0" left="0" bottom="0" right="0"/>
5456
<constraints>
5557
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -59,7 +61,7 @@
5961
<children>
6062
<component id="ad3ba" class="javax.swing.JTextField" binding="packageName" default-binding="true">
6163
<constraints>
62-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
64+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
6365
<preferred-size width="150" height="-1"/>
6466
</grid>
6567
</constraints>
@@ -78,7 +80,7 @@
7880
</component>
7981
<component id="e4858" class="javax.swing.JTextField" binding="moduleName">
8082
<constraints>
81-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
83+
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
8284
<preferred-size width="150" height="-1"/>
8385
</grid>
8486
</constraints>
@@ -97,7 +99,7 @@
9799
</component>
98100
<component id="423dc" class="javax.swing.JTextField" binding="moduleVersion">
99101
<constraints>
100-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
102+
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
101103
<preferred-size width="150" height="-1"/>
102104
</grid>
103105
</constraints>
@@ -116,6 +118,47 @@
116118
<text value="Module Version"/>
117119
</properties>
118120
</component>
121+
<component id="c5925" class="javax.swing.JLabel" binding="moduleLicenseLabel">
122+
<constraints>
123+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
124+
</constraints>
125+
<properties>
126+
<text value="License(s)"/>
127+
</properties>
128+
</component>
129+
<component id="26905" class="javax.swing.JTextField" binding="moduleLicenseCustom">
130+
<constraints>
131+
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
132+
<preferred-size width="150" height="-1"/>
133+
</grid>
134+
</constraints>
135+
<properties>
136+
<editable value="true"/>
137+
<enabled value="true"/>
138+
<toolTipText value="Module's Custom License"/>
139+
</properties>
140+
</component>
141+
<scrollpane id="a545e" binding="moduleLicenseScrollPanel">
142+
<constraints>
143+
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
144+
<preferred-size width="150" height="100"/>
145+
<maximum-size width="-1" height="100"/>
146+
</grid>
147+
</constraints>
148+
<properties>
149+
<enabled value="false"/>
150+
</properties>
151+
<border type="none"/>
152+
<children>
153+
<component id="8bae" class="javax.swing.JList" binding="moduleLicense">
154+
<constraints/>
155+
<properties>
156+
<model/>
157+
<toolTipText value="Module's Lincese"/>
158+
</properties>
159+
</component>
160+
</children>
161+
</scrollpane>
119162
</children>
120163
</grid>
121164
<component id="4c5ac" class="javax.swing.JTextArea" binding="moduleDescription">

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

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +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.*;
32+
import java.util.List;
33+
import java.util.Vector;
3034

31-
public class NewMagentoModuleDialog extends AbstractDialog {
35+
public class NewMagentoModuleDialog extends AbstractDialog implements ListSelectionListener {
3236
@NotNull
3337
private final Project project;
3438
@NotNull
@@ -55,6 +59,10 @@ public class NewMagentoModuleDialog extends AbstractDialog {
5559
private JLabel moduleDescriptionLabel;
5660
private JTextField moduleVersion;
5761
private JLabel moduleVersionLabel;
62+
private JList moduleLicense;
63+
private JLabel moduleLicenseLabel;
64+
private JTextField moduleLicenseCustom;
65+
private JScrollPane moduleLicenseScrollPanel;
5866
private String detectedPackageName;
5967

6068
public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
@@ -73,6 +81,10 @@ public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory in
7381
setModal(true);
7482
getRootPane().setDefaultButton(buttonOK);
7583
pushToMiddle();
84+
setLicenses();
85+
86+
moduleLicenseCustom.setToolTipText("Custom License Name");
87+
moduleLicenseCustom.setText("proprietary");
7688

7789
buttonOK.addActionListener(new ActionListener() {
7890
public void actionPerformed(ActionEvent e) {
@@ -137,7 +149,8 @@ private PsiFile generateComposerJson() {
137149
getBaseDir(),
138150
getModuleDescription(),
139151
getComposerPackageName(),
140-
getModuleVersion()
152+
getModuleVersion(),
153+
getModuleLicense()
141154
), project).generate(NewModuleAction.ACTION_NAME);
142155
}
143156

@@ -180,6 +193,18 @@ public String getModuleVersion() {
180193
return this.moduleVersion.getText().trim();
181194
}
182195

196+
public List getModuleLicense() {
197+
List selectedLicenses = this.moduleLicense.getSelectedValuesList();
198+
Package.License customLicense = Package.License.CUSTOM;
199+
200+
if (selectedLicenses.contains(customLicense.getLicenseName())) {
201+
selectedLicenses.remove(customLicense.getLicenseName());
202+
selectedLicenses.add(moduleLicenseCustom.getText());
203+
}
204+
205+
return selectedLicenses;
206+
}
207+
183208
public static void open(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
184209
NewMagentoModuleDialog dialog = new NewMagentoModuleDialog(project, initialBaseDir, file, view, editor);
185210
dialog.pack();
@@ -192,4 +217,37 @@ private String getComposerPackageName() {
192217
.concat("/")
193218
.concat(camelCaseToHyphen.convert(getModuleName()));
194219
}
220+
221+
private void setLicenses() {
222+
Package.License[] licenses = Package.License.values();
223+
Vector<String> licenseNames = new Vector<>(licenses.length);
224+
225+
for (Package.License license: licenses) {
226+
licenseNames.add(license.getLicenseName());
227+
}
228+
229+
moduleLicense.setListData(licenseNames);
230+
moduleLicense.setSelectedIndex(0);
231+
moduleLicense.addListSelectionListener(this);
232+
}
233+
234+
private void handleModuleCustomLicenseInputVisibility () {
235+
boolean isCustomLicenseSelected = false;
236+
237+
for (Object value: moduleLicense.getSelectedValuesList()) {
238+
if (Package.License.CUSTOM.getLicenseName().equals(value.toString())) {
239+
isCustomLicenseSelected = true;
240+
241+
break;
242+
}
243+
}
244+
245+
moduleLicenseCustom.setEnabled(isCustomLicenseSelected);
246+
moduleLicenseCustom.setEditable(isCustomLicenseSelected);
247+
}
248+
249+
@Override
250+
public void valueChanged(ListSelectionEvent listSelectionEvent) {
251+
handleModuleCustomLicenseInputVisibility();
252+
}
195253
}

src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGenerator.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
1414
import org.jetbrains.annotations.NotNull;
1515
import java.util.Properties;
16+
import java.util.List;
1617

1718
public class ModuleComposerJsonGenerator extends FileGenerator {
1819

@@ -38,5 +39,25 @@ protected void fillAttributes(Properties attributes) {
3839
attributes.setProperty("MODULE_DESCRIPTION", moduleComposerJsonData.getModuleDescription());
3940
attributes.setProperty("COMPOSER_PACKAGE_NAME", moduleComposerJsonData.getComposerPackageName());
4041
attributes.setProperty("MODULE_VERSION", moduleComposerJsonData.getModuleVersion());
42+
attributes.setProperty("LICENSE", this.getLicensesString(moduleComposerJsonData.getModuleLicense()));
43+
}
44+
45+
protected String getLicensesString(List licensesList) {
46+
String license = "[\n";
47+
Object[] licenses = licensesList.toArray();
48+
49+
for (int i = 0; i < licenses.length; i++) {
50+
license = license.concat("\"");
51+
license = license.concat(licenses[i].toString());
52+
license = license.concat("\"");
53+
54+
if (licenses.length != (i + 1)) license = license.concat(",");
55+
56+
license = license.concat("\n");
57+
}
58+
59+
license = license.concat("\n]");
60+
61+
return license;
4162
}
4263
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
package com.magento.idea.magento2plugin.magento.packages;
66

7-
import com.magento.idea.magento2plugin.magento.files.Plugin;
7+
import java.util.ArrayList;
88

99
public class Package {
1010
public static String PACKAGES_ROOT = "app/code";
@@ -23,6 +23,28 @@ public static enum Areas {
2323
graphql
2424
}
2525

26+
public static enum License {
27+
CUSTOM("Custom License"),
28+
OSL("Open Software License (OSL)"),
29+
MPL("Mozilla Public License (MPL)"),
30+
MITL("Massachusetts Institute of Technology License (MITL)"),
31+
LGPL("GNU Lesser General Public License (LGPL)"),
32+
GPL("GNU General Public License (GPL)"),
33+
BSDL("Berkeley Software Distribution License (BSDL)"),
34+
ASL("Apache Software License (ASL)"),
35+
AFL("Academic Free License (AFL)");
36+
37+
private String licenseName;
38+
39+
License(String name) {
40+
this.licenseName = name;
41+
}
42+
43+
public String getLicenseName() {
44+
return licenseName;
45+
}
46+
}
47+
2648
public static Package.Areas getAreaByString(String string)
2749
{
2850
for (Package.Areas areas: Package.Areas.values()) {

0 commit comments

Comments
 (0)