Skip to content

Commit 3a43929

Browse files
309: Add declarative schema base dialog with table related fields
1 parent 4472c86 commit 3a43929

File tree

5 files changed

+310
-0
lines changed

5 files changed

+310
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
7171
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7272
<action id="MagentoMessageQueue" class="com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction" />
73+
<action id="NewDbSchema" class="com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction" />
7374
<add-to-group group-id="NewGroup" anchor="last"/>
7475
</group>
7576

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDbSchemaDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class NewDbSchemaAction extends AnAction {
21+
public static final String ACTION_NAME = "Declarative Schema XML";
22+
public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML";
23+
24+
/**
25+
* Constructor.
26+
*/
27+
public NewDbSchemaAction() {
28+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
}
30+
31+
@Override
32+
public void actionPerformed(final @NotNull AnActionEvent event) {
33+
final DataContext dataContext = event.getDataContext();
34+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
35+
if (view == null) {
36+
return;
37+
}
38+
39+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
if (project == null) {
41+
return;
42+
}
43+
44+
final PsiDirectory directory = view.getOrChooseDirectory();
45+
if (directory == null) {
46+
return;
47+
}
48+
NewDbSchemaDialog.open(project, directory);
49+
}
50+
51+
@Override
52+
public boolean isDumbAware() {
53+
return false;
54+
}
55+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewDbSchemaDialog">
3+
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties>
9+
<enabled value="true"/>
10+
<preferredSize width="500" height="400"/>
11+
</properties>
12+
<border type="none"/>
13+
<children>
14+
<grid id="3fa0c" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
15+
<margin top="0" left="0" bottom="0" right="0"/>
16+
<constraints>
17+
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
18+
</constraints>
19+
<properties/>
20+
<border type="none"/>
21+
<children>
22+
<component id="9c6c1" class="javax.swing.JButton" binding="buttonOK">
23+
<constraints>
24+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
25+
</constraints>
26+
<properties>
27+
<enabled value="true"/>
28+
<text value="OK"/>
29+
</properties>
30+
</component>
31+
<hspacer id="8d25d">
32+
<constraints>
33+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
34+
</constraints>
35+
</hspacer>
36+
<component id="5c071" class="javax.swing.JButton" binding="buttonCancel">
37+
<constraints>
38+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
39+
</constraints>
40+
<properties>
41+
<text value="Cancel"/>
42+
</properties>
43+
</component>
44+
</children>
45+
</grid>
46+
<vspacer id="a943b">
47+
<constraints>
48+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
49+
</constraints>
50+
</vspacer>
51+
<grid id="a7920" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
52+
<margin top="0" left="0" bottom="0" right="0"/>
53+
<constraints>
54+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
55+
</constraints>
56+
<properties/>
57+
<border type="none"/>
58+
<children>
59+
<grid id="40126" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
60+
<margin top="0" left="0" bottom="0" right="0"/>
61+
<constraints>
62+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
63+
</constraints>
64+
<properties/>
65+
<border type="none"/>
66+
<children>
67+
<component id="88580" class="javax.swing.JLabel" binding="tableNameLabel">
68+
<constraints>
69+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
70+
</constraints>
71+
<properties>
72+
<labelFor value="37d36"/>
73+
<text value="Name"/>
74+
</properties>
75+
</component>
76+
<component id="37d36" class="javax.swing.JTextField" binding="tableName">
77+
<constraints>
78+
<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">
79+
<preferred-size width="150" height="-1"/>
80+
</grid>
81+
</constraints>
82+
<properties/>
83+
</component>
84+
<component id="545e" class="javax.swing.JLabel" binding="tableResourceLabel">
85+
<constraints>
86+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
87+
</constraints>
88+
<properties>
89+
<text value="Resource"/>
90+
</properties>
91+
</component>
92+
<component id="a42c4" class="javax.swing.JLabel" binding="tableEngineLabel">
93+
<constraints>
94+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
95+
</constraints>
96+
<properties>
97+
<text value="Engine"/>
98+
</properties>
99+
</component>
100+
<component id="d636e" class="javax.swing.JLabel" binding="tableCommentLabel">
101+
<constraints>
102+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
103+
</constraints>
104+
<properties>
105+
<labelFor value="dd0b9"/>
106+
<text value="Comment"/>
107+
</properties>
108+
</component>
109+
<component id="dd0b9" class="javax.swing.JTextField" binding="tableComment">
110+
<constraints>
111+
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
112+
<preferred-size width="150" height="-1"/>
113+
</grid>
114+
</constraints>
115+
<properties/>
116+
</component>
117+
<component id="84dfa" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="tableEngine" custom-create="true">
118+
<constraints>
119+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
120+
</constraints>
121+
<properties/>
122+
</component>
123+
<component id="dc164" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="tableResource" custom-create="true">
124+
<constraints>
125+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
126+
</constraints>
127+
<properties/>
128+
</component>
129+
</children>
130+
</grid>
131+
<vspacer id="a9e81">
132+
<constraints>
133+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
134+
</constraints>
135+
</vspacer>
136+
</children>
137+
</grid>
138+
</children>
139+
</grid>
140+
</form>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.dialog;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction;
11+
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
12+
import org.jetbrains.annotations.NotNull;
13+
import javax.swing.JButton;
14+
import javax.swing.JComponent;
15+
import javax.swing.JLabel;
16+
import javax.swing.JPanel;
17+
import javax.swing.JTextField;
18+
import javax.swing.KeyStroke;
19+
import java.awt.event.KeyEvent;
20+
import java.awt.event.WindowAdapter;
21+
import java.awt.event.WindowEvent;
22+
import java.util.Arrays;
23+
24+
public class NewDbSchemaDialog extends AbstractDialog {
25+
private final Project project;
26+
private final PsiDirectory directory;
27+
private JPanel contentPanel;
28+
private JButton buttonOK;
29+
private JButton buttonCancel;
30+
private JTextField tableName;
31+
private JTextField tableComment;
32+
private JLabel tableNameLabel;
33+
private JLabel tableEngineLabel;
34+
private FilteredComboBox tableEngine;
35+
private JLabel tableResourceLabel;
36+
private FilteredComboBox tableResource;
37+
private JLabel tableCommentLabel;
38+
39+
/**
40+
* Constructor.
41+
*
42+
* @param project Project
43+
* @param directory PsiDirectory
44+
*/
45+
public NewDbSchemaDialog(
46+
final @NotNull Project project,
47+
final @NotNull PsiDirectory directory
48+
) {
49+
super();
50+
this.project = project;
51+
this.directory = directory;
52+
53+
setTitle(NewDbSchemaAction.ACTION_DESCRIPTION);
54+
setContentPane(contentPanel);
55+
setModal(true);
56+
getRootPane().setDefaultButton(buttonOK);
57+
buttonOK.addActionListener(e -> onOK());
58+
buttonCancel.addActionListener(e -> onCancel());
59+
60+
// call onCancel() when cross is clicked
61+
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
62+
addWindowListener(new WindowAdapter() {
63+
@Override
64+
public void windowClosing(final WindowEvent event) {
65+
onCancel();
66+
}
67+
});
68+
69+
// call onCancel() on ESCAPE
70+
contentPanel.registerKeyboardAction(
71+
event -> onCancel(),
72+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
73+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
74+
);
75+
}
76+
77+
/**
78+
* On buttonOK action listener.
79+
*/
80+
private void onOK() {
81+
if (!validateFormFields()) {
82+
return;
83+
}
84+
85+
this.setVisible(false);
86+
}
87+
88+
/**
89+
* Open new declarative schema dialog.
90+
*
91+
* @param project Project
92+
* @param directory PsiDirectory
93+
*/
94+
public static void open(
95+
final @NotNull Project project,
96+
final @NotNull PsiDirectory directory
97+
) {
98+
final NewDbSchemaDialog dialog = new NewDbSchemaDialog(project, directory);
99+
dialog.pack();
100+
dialog.centerDialog(dialog);
101+
dialog.setVisible(true);
102+
}
103+
104+
@SuppressWarnings({"PMD.UnusedPrivateMethod"})
105+
private void createUIComponents() {
106+
tableEngine = new FilteredComboBox(Arrays.asList());
107+
tableResource = new FilteredComboBox(Arrays.asList());
108+
}
109+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/util/HighlightDialogFieldOnErrorUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
16
package com.magento.idea.magento2plugin.actions.generation.dialog.util;
27

38
import java.awt.Color;

0 commit comments

Comments
 (0)