Skip to content

Commit 57ce9f8

Browse files
309: Code refactoring
1 parent 00c9171 commit 57ce9f8

File tree

7 files changed

+88
-71
lines changed

7 files changed

+88
-71
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public List<Map<String, String>> getColumns() {
7777
return new LinkedList<>(columns);
7878
}
7979

80-
public void setColumns(List<Map<String, String>> columns) {
80+
public void setColumns(final List<Map<String, String>> columns) {
8181
this.columns = columns;
8282
}
8383

@@ -87,7 +87,7 @@ public void setColumns(List<Map<String, String>> columns) {
8787
* @return Map
8888
*/
8989
public Map<String, String> getTableAttributesMap() {
90-
final Map<String, String> tableAttributesData = new LinkedHashMap<>();
90+
final Map<String, String> tableAttributesData = new LinkedHashMap<>();//NOPMD
9191
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName());
9292
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource());
9393
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine());

src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlSourceData.java src/com/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
package com.magento.idea.magento2plugin.actions.generation.data;
6+
package com.magento.idea.magento2plugin.actions.generation.data.util;
77

88
import java.util.Arrays;
99
import java.util.LinkedList;
1010
import java.util.List;
1111

12-
public final class DbSchemaXmlSourceData {
12+
public final class DbSchemaXmlSourceDataUtil {
1313
// currently available engines
1414
public static final String TABLE_ENGINE_INNODB = "innodb";
1515
public static final String TABLE_ENGINE_MEMORY = "memory";
@@ -47,7 +47,7 @@ public final class DbSchemaXmlSourceData {
4747
/**
4848
* Denying the possibility to initialize this class.
4949
*/
50-
private DbSchemaXmlSourceData() {}
50+
private DbSchemaXmlSourceDataUtil() {}
5151

5252
/**
5353
* Get source list for available table engines.
@@ -56,8 +56,8 @@ private DbSchemaXmlSourceData() {}
5656
*/
5757
public static List<String> getTableEngineSource() {
5858
return new LinkedList<>(Arrays.asList(
59-
DbSchemaXmlSourceData.TABLE_ENGINE_INNODB,
60-
DbSchemaXmlSourceData.TABLE_ENGINE_MEMORY)
59+
DbSchemaXmlSourceDataUtil.TABLE_ENGINE_INNODB,
60+
DbSchemaXmlSourceDataUtil.TABLE_ENGINE_MEMORY)
6161
);
6262
}
6363

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import com.intellij.psi.PsiDirectory;
1010
import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction;
1111
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlData;
12-
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlSourceData;
1312
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
13+
import com.magento.idea.magento2plugin.actions.generation.data.util.DbSchemaXmlSourceDataUtil;
1414
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
1515
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
1616
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule;
@@ -40,12 +40,12 @@
4040
import javax.swing.KeyStroke;
4141
import org.jetbrains.annotations.NotNull;
4242

43+
@SuppressWarnings({"PMD.TooManyFields", "PMD.LoosePackageCoupling"})
4344
public class NewDbSchemaDialog extends AbstractDialog {
4445
private static final String TABLE_NAME = "Table Name";
4546

4647
private final Project project;
4748
private final String moduleName;
48-
private final PsiDirectory directory;
4949
private JPanel contentPanel;
5050

5151
// Buttons
@@ -94,7 +94,6 @@ public NewDbSchemaDialog(
9494
) {
9595
super();
9696
this.project = project;
97-
this.directory = directory;
9897
moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
9998

10099
setTitle(NewDbSchemaAction.ACTION_DESCRIPTION);
@@ -181,13 +180,16 @@ private void initializeColumnsUiComponentGroup() {
181180
ModuleDbSchemaXml.XML_ATTR_COLUMN_COMMENT
182181
));
183182
// Set default values for columns
184-
final Map<String, String> defaultValues = new HashMap<>();
183+
final Map<String, String> defaultValues = new HashMap<>();//NOPMD
185184
defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, "false");
186185
defaultValues.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, "false");
187186
// Set sources for columns
188-
final Map<String, List<String>> sources = new HashMap<>();
187+
final Map<String, List<String>> sources = new HashMap<>();//NOPMD
189188
final List<String> booleanSource = Arrays.asList("true", "false");
190-
sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE, DbSchemaXmlSourceData.getColumnTypes());
189+
sources.put(
190+
ModuleDbSchemaXml.XML_ATTR_COLUMN_TYPE,
191+
DbSchemaXmlSourceDataUtil.getColumnTypes()
192+
);
191193
sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_UNSIGNED, booleanSource);
192194
sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_NULLABLE, booleanSource);
193195
sources.put(ModuleDbSchemaXml.XML_ATTR_COLUMN_IDENTITY, booleanSource);
@@ -208,12 +210,12 @@ private void initializeColumnsUiComponentGroup() {
208210
*/
209211
private void fillComboBoxes() {
210212
// Table Engine ComboBox defaults.
211-
for (final String engine : DbSchemaXmlSourceData.getTableEngineSource()) {
212-
tableEngine.addItem(new ComboBoxItemData(engine, engine));
213+
for (final String engine : DbSchemaXmlSourceDataUtil.getTableEngineSource()) {
214+
tableEngine.addItem(new ComboBoxItemData(engine, engine));//NOPMD
213215
}
214216
// Table Resource ComboBox defaults.
215-
for (final String resource : DbSchemaXmlSourceData.getTableResourceSource()) {
216-
tableResource.addItem(new ComboBoxItemData(resource, resource));
217+
for (final String resource : DbSchemaXmlSourceDataUtil.getTableResourceSource()) {
218+
tableResource.addItem(new ComboBoxItemData(resource, resource));//NOPMD
217219
}
218220
}
219221

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public DbSchemaXmlGenerator(
5656
}
5757

5858
@Override
59-
@SuppressWarnings({"PMD.NPathComplexity", "PMD.CyclomaticComplexity"})
59+
@SuppressWarnings({"PMD.NPathComplexity", "PMD.CyclomaticComplexity", "PMD.ExcessiveImports"})
6060
public PsiFile generate(final String actionName) {
6161
final XmlFile dbSchemaXmlFile = (XmlFile) findOrCreateDbSchemaXmlUtil.execute(
6262
actionName,

src/com/magento/idea/magento2plugin/magento/files/ModuleDbSchemaXml.java

+27-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import com.intellij.lang.Language;
99
import com.intellij.lang.xml.XMLLanguage;
10-
import com.magento.idea.magento2plugin.actions.generation.data.DbSchemaXmlSourceData;
10+
import com.magento.idea.magento2plugin.actions.generation.data.util.DbSchemaXmlSourceDataUtil;
1111
import java.util.ArrayList;
1212
import java.util.List;
1313

@@ -44,8 +44,8 @@ public class ModuleDbSchemaXml implements ModuleFileInterface {
4444
public static final String XML_ATTR_TYPE_PK = "primary";
4545
public static final String XML_ATTR_REFERENCE_ID_PK = "PRIMARY";
4646
public static final String XML_ATTR_INDEX_TYPE_BTREE = "btree";
47-
public static final String XML_ATTR_INDEX_TYPE_FULLTEXT = "fulltext";
48-
public static final String XML_ATTR_INDEX_TYPE_HASH = "hash";
47+
public static final String XML_ATTR_INDEX_TYPE_FULLTEXT = "fulltext";//NOPMD
48+
public static final String XML_ATTR_INDEX_TYPE_HASH = "hash";//NOPMD
4949

5050
//tags
5151
public static final String XML_TAG_SCHEMA = "schema";
@@ -61,29 +61,30 @@ public class ModuleDbSchemaXml implements ModuleFileInterface {
6161
*
6262
* @return List
6363
*/
64+
@SuppressWarnings("PMD")
6465
public static List<String> getAllowedAttributes(final String columnType) {
65-
List<String> allowedAttributes = new ArrayList<>();
66+
final List<String> allowedAttributes = new ArrayList<>();
6667

6768
switch (columnType) {
68-
case DbSchemaXmlSourceData.COLUMN_TYPE_BLOB:
69-
case DbSchemaXmlSourceData.COLUMN_TYPE_MEDIUMBLOB:
70-
case DbSchemaXmlSourceData.COLUMN_TYPE_LONGBLOB:
71-
case DbSchemaXmlSourceData.COLUMN_TYPE_DATE:
69+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_BLOB:
70+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_MEDIUMBLOB:
71+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_LONGBLOB:
72+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DATE:
7273
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
7374
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
7475
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
7576
break;
76-
case DbSchemaXmlSourceData.COLUMN_TYPE_VARBINARY:
77+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_VARBINARY:
7778
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
7879
allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT);
7980
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
8081
allowedAttributes.add(XML_ATTR_COLUMN_LENGTH);
8182
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
8283
break;
83-
case DbSchemaXmlSourceData.COLUMN_TYPE_TINYINT:
84-
case DbSchemaXmlSourceData.COLUMN_TYPE_SMALLINT:
85-
case DbSchemaXmlSourceData.COLUMN_TYPE_INT:
86-
case DbSchemaXmlSourceData.COLUMN_TYPE_BIGINT:
84+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TINYINT:
85+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_SMALLINT:
86+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_INT:
87+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_BIGINT:
8788
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
8889
allowedAttributes.add(XML_ATTR_COLUMN_PADDING);
8990
allowedAttributes.add(XML_ATTR_COLUMN_UNSIGNED);
@@ -92,9 +93,9 @@ public static List<String> getAllowedAttributes(final String columnType) {
9293
allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT);
9394
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
9495
break;
95-
case DbSchemaXmlSourceData.COLUMN_TYPE_DECIMAL:
96-
case DbSchemaXmlSourceData.COLUMN_TYPE_DOUBLE:
97-
case DbSchemaXmlSourceData.COLUMN_TYPE_FLOAT:
96+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DECIMAL:
97+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DOUBLE:
98+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_FLOAT:
9899
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
99100
allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT);
100101
allowedAttributes.add(XML_ATTR_COLUMN_SCALE);
@@ -103,24 +104,24 @@ public static List<String> getAllowedAttributes(final String columnType) {
103104
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
104105
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
105106
break;
106-
case DbSchemaXmlSourceData.COLUMN_TYPE_VARCHAR:
107-
case DbSchemaXmlSourceData.COLUMN_TYPE_TEXT:
108-
case DbSchemaXmlSourceData.COLUMN_TYPE_MEDIUMTEXT:
109-
case DbSchemaXmlSourceData.COLUMN_TYPE_LONGTEXT:
107+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_VARCHAR:
108+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TEXT:
109+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_MEDIUMTEXT:
110+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_LONGTEXT:
110111
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
111112
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
112113
allowedAttributes.add(XML_ATTR_COLUMN_LENGTH);
113114
allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT);
114115
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
115116
break;
116-
case DbSchemaXmlSourceData.COLUMN_TYPE_BOOLEAN:
117+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_BOOLEAN:
117118
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
118119
allowedAttributes.add(XML_ATTR_COLUMN_DEFAULT);
119120
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
120121
allowedAttributes.add(XML_ATTR_COLUMN_COMMENT);
121122
break;
122-
case DbSchemaXmlSourceData.COLUMN_TYPE_DATETIME:
123-
case DbSchemaXmlSourceData.COLUMN_TYPE_TIMESTAMP:
123+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_DATETIME:
124+
case DbSchemaXmlSourceDataUtil.COLUMN_TYPE_TIMESTAMP:
124125
allowedAttributes.add(XML_ATTR_COLUMN_NAME);
125126
allowedAttributes.add(XML_ATTR_COLUMN_ON_UPDATE);
126127
allowedAttributes.add(XML_ATTR_COLUMN_NULLABLE);
@@ -146,10 +147,10 @@ public static String generateIndexReferenceId(
146147
final String tableName,
147148
final List<String> indexColumnsNames
148149
) {
149-
StringBuilder stringBuilder = new StringBuilder(tableName.toUpperCase());
150+
final StringBuilder stringBuilder = new StringBuilder(tableName.toUpperCase());//NOPMD
150151

151-
for (String indexName : indexColumnsNames) {
152-
stringBuilder.append("_").append(indexName.toUpperCase());
152+
for (final String indexName : indexColumnsNames) {
153+
stringBuilder.append("_").append(indexName.toUpperCase());//NOPMD
153154
}
154155

155156
return stringBuilder.toString();

src/com/magento/idea/magento2plugin/ui/table/ComboBoxCellEditor.java

+32-18
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,44 @@
55

66
package com.magento.idea.magento2plugin.ui.table;
77

8-
import javax.swing.AbstractCellEditor;
9-
import javax.swing.JComboBox;
10-
import javax.swing.JTable;
11-
import javax.swing.table.TableCellEditor;
128
import java.awt.Component;
139
import java.awt.event.ActionEvent;
1410
import java.awt.event.ActionListener;
15-
import java.util.Arrays;
1611
import java.util.List;
17-
import java.util.Vector;
12+
import javax.swing.AbstractCellEditor;
13+
import javax.swing.JComboBox;
14+
import javax.swing.JTable;
15+
import javax.swing.table.TableCellEditor;
1816

1917
public class ComboBoxCellEditor<T> extends AbstractCellEditor
2018
implements TableCellEditor, ActionListener {
2119
private T value;
22-
private List<T> options;
23-
private JComboBox<T> editorComponent;
20+
private final List<T> options;//NOPMD
21+
private final JComboBox<T> editorComponent;
2422
private ActionListener actionListener;
2523

26-
public ComboBoxCellEditor(List<T> options) {
24+
/**
25+
* Constructor.
26+
*
27+
* @param options List
28+
*/
29+
public ComboBoxCellEditor(final List<T> options) {
30+
super();
2731
this.options = options;
2832
editorComponent = new JComboBox();
2933

30-
for (T option : options) {
34+
for (final T option : this.options) {
3135
editorComponent.addItem(option);
3236
}
3337
}
3438

3539
@Override
3640
public Component getTableCellEditorComponent(
37-
JTable table,
38-
Object value,
39-
boolean isSelected,
40-
int row,
41-
int column
41+
final JTable table,
42+
final Object value,
43+
final boolean isSelected,
44+
final int row,
45+
final int column
4246
) {
4347
this.value = (T) value;
4448

@@ -60,8 +64,8 @@ public Object getCellEditorValue() {
6064
}
6165

6266
@Override
63-
public void actionPerformed(ActionEvent event) {
64-
JComboBox<T> comboBox = (JComboBox<T>) event.getSource();
67+
public void actionPerformed(final ActionEvent event) {
68+
final JComboBox<T> comboBox = (JComboBox<T>) event.getSource();
6569
this.value = (T) comboBox.getSelectedItem();
6670

6771
if (actionListener != null) {
@@ -70,11 +74,21 @@ public void actionPerformed(ActionEvent event) {
7074
editorComponent.setPopupVisible(false);
7175
}
7276

77+
/**
78+
* Get component.
79+
*
80+
* @return Component
81+
*/
7382
public Component getComponent() {
7483
return editorComponent;
7584
}
7685

77-
public void addAdditionalActionListener(ActionListener actionListener) {
86+
/**
87+
* Add additional action listener.
88+
*
89+
* @param actionListener ActionListener
90+
*/
91+
public void addAdditionalActionListener(final ActionListener actionListener) {
7892
this.actionListener = actionListener;
7993
}
8094
}

src/com/magento/idea/magento2plugin/ui/table/TableGroupWrapper.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public DefaultTableModel getTableModel() {
7373
* @return List
7474
*/
7575
public List<Map<String, String>> getColumnsData() {
76-
List<Map<String, String>> data = new LinkedList<>();
77-
DefaultTableModel tableModel = getTableModel();
76+
final List<Map<String, String>> data = new LinkedList<>();
77+
final DefaultTableModel tableModel = getTableModel();
7878

7979
for (int row = 0; row < tableModel.getRowCount(); row++) {
80-
Map<String, String> columnValues = new LinkedHashMap<>();
80+
final Map<String, String> columnValues = new LinkedHashMap<>();//NOPMD
8181

8282
for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
8383
columnValues.put(
@@ -121,10 +121,10 @@ private String getTitleForColumn(final String column) {
121121
String title = column.replace("_", " ");
122122

123123
if (title.contains(":")) {
124-
title = title.substring(title.indexOf(":") + 1);
124+
title = title.substring(title.indexOf(':') + 1);
125125
}
126126

127-
return title.substring(0, 1).toUpperCase() + title.substring(1);
127+
return title.substring(0, 1).toUpperCase() + title.substring(1);//NOPMD
128128
}
129129

130130
/**
@@ -159,16 +159,16 @@ private void addNewRowRoutine(
159159
}
160160
if (sources != null && sources.containsKey(columns.get(index))) {
161161
final String column = columns.get(index);
162-
final List<String> source = new LinkedList<>(sources.get(column));
163-
final String[] sourceArray = new String[source.size()];
162+
final List<String> source = new LinkedList<>(sources.get(column));//NOPMD
163+
final String[] sourceArray = new String[source.size()];//NOPMD
164164

165165
for (int sourceIndex = 0; sourceIndex < source.size(); sourceIndex++) {
166166
sourceArray[sourceIndex] = source.get(sourceIndex);
167167
}
168168
final TableColumn currentColumn = table.getColumn(getTitleForColumn(column));
169-
currentColumn.setCellRenderer(new ComboBoxRenderer(sourceArray));
169+
currentColumn.setCellRenderer(new ComboBoxRenderer(sourceArray));//NOPMD
170170
currentColumn.setCellEditor(
171-
new ComboBoxCellEditor<String>(Arrays.asList(sourceArray))
171+
new ComboBoxCellEditor<String>(Arrays.asList(sourceArray))//NOPMD
172172
);
173173

174174
if (columnValuesObjectArray[index].toString().isEmpty()

0 commit comments

Comments
 (0)