21
21
import com .intellij .openapi .ui .ValidationInfo ;
22
22
import com .intellij .openapi .util .text .StringUtil ;
23
23
import com .intellij .ui .PopupBorder ;
24
- import com .intellij .ui .TextFieldWithAutoCompletion ;
25
- import com .intellij .ui .TextFieldWithAutoCompletionListProvider ;
26
24
import com .intellij .ui .components .JBLabel ;
27
- import com .intellij .util . textCompletion . TextFieldWithCompletion ;
25
+ import com .intellij .ui . components . JBTextField ;
28
26
import com .intellij .util .ui .JBUI ;
29
27
import net .miginfocom .swing .MigLayout ;
30
- import org .jetbrains .annotations .NotNull ;
31
28
import org .jetbrains .annotations .Nullable ;
32
29
33
30
import javax .swing .JComponent ;
36
33
import javax .swing .JRootPane ;
37
34
import javax .swing .RootPaneContainer ;
38
35
import javax .swing .SwingConstants ;
39
- import java .awt .MouseInfo ;
40
36
import java .awt .Point ;
41
37
import java .awt .Window ;
42
- import java .awt .event .MouseAdapter ;
43
- import java .awt .event .MouseEvent ;
44
- import java .awt .event .MouseListener ;
45
38
import java .util .Collection ;
46
39
import java .util .function .Supplier ;
47
40
48
- public class CreateActiveProjectDialog extends DialogWrapper {
41
+ import static org .jboss .tools .intellij .openshift .ui .SwingUtils .locationOrMouseLocation ;
42
+
43
+ public class CreateNewProjectDialog extends DialogWrapper {
49
44
50
45
private static final String WIDTH = "300" ;
51
- private final Project project ;
52
- private final String kind ;
53
- private final String currentProject ;
54
46
private final Collection <String > allProjects ;
55
47
private final Point location ;
56
- private TextFieldWithCompletion activeProjectTextField ;
57
-
58
- private String activeProject ;
48
+ private final Project project ;
49
+ private JBTextField newProjectTextField ;
59
50
60
- private boolean createNewProject ;
51
+ private String newProject ;
61
52
62
- public CreateActiveProjectDialog (
53
+ public CreateNewProjectDialog (
63
54
@ Nullable Project project ,
64
- String kind ,
65
- String currentProject ,
66
55
Collection <String > allProjects ,
67
56
Point location ) {
68
57
super (project , false );
69
58
this .project = project ;
70
- this .kind = kind ;
71
- this .currentProject = currentProject ;
72
59
this .allProjects = allProjects ;
73
60
this .location = location ;
74
61
init ();
@@ -83,15 +70,12 @@ protected void init() {
83
70
setOKButtonText ("Create" );
84
71
setBorders (rootPane );
85
72
setLocation (location );
86
- setTitle ("Create Active " + kind );
73
+ setTitle ("Create New Project" );
87
74
}
88
75
89
76
@ Override
90
77
public void setLocation (Point location ) {
91
- if (location == null ) {
92
- location = MouseInfo .getPointerInfo ().getLocation ();
93
- }
94
- super .setLocation (location );
78
+ super .setLocation (locationOrMouseLocation (location ));
95
79
}
96
80
97
81
private void registerShortcuts (JRootPane rootPane ) {
@@ -113,44 +97,20 @@ private void setBorders(JRootPane rootPane) {
113
97
JComponent panel = new JPanel (new MigLayout (
114
98
"flowx, ins 0, gap 0, fillx, filly, hidemode 3" ,
115
99
"[left]10[" + WIDTH +",fill]" ));
116
- JLabel newActiveProjectLabel = new JBLabel ("Create Active " + kind + " :" , SwingConstants .LEFT );
100
+ JLabel newActiveProjectLabel = new JBLabel ("New project :" , SwingConstants .LEFT );
117
101
newActiveProjectLabel .setBorder (JBUI .Borders .empty (10 , 0 ));
118
102
panel .add (newActiveProjectLabel , "left, bottom" );
119
- this .activeProjectTextField = new TextFieldWithAutoCompletion <>(
120
- project , onLookup (allProjects ), false , true , null );
121
- activeProjectTextField .selectAll ();
122
- panel .add (activeProjectTextField , "pushx, growx, wrap" );
103
+ this .newProjectTextField = new JBTextField ();
104
+ newProjectTextField .selectAll ();
105
+ panel .add (newProjectTextField , "pushx, growx, wrap" );
123
106
ComponentValidator activeProjectValidator = new ComponentValidator (myDisposable )
124
107
.withValidator (new ActiveProjectValidator ())
125
- .installOn (activeProjectTextField )
126
- .andRegisterOnDocumentListener (activeProjectTextField );
108
+ .installOn (newProjectTextField )
109
+ .andRegisterOnDocumentListener (newProjectTextField );
127
110
activeProjectValidator .revalidate ();
128
- JLabel createProjectLabel = new JBLabel ("<html>You can <a href=\" \" >create a new project</a> instead.</html>" );
129
- createProjectLabel .setBorder (JBUI .Borders .emptyTop (20 ));
130
- createProjectLabel .addMouseListener (onClicked ());
131
- panel .add (createProjectLabel , "spanx" );
132
111
return panel ;
133
112
}
134
113
135
- private MouseListener onClicked () {
136
- return new MouseAdapter () {
137
-
138
- @ Override
139
- public void mouseReleased (MouseEvent e ) {
140
- CreateActiveProjectDialog .this .createNewProject = true ;
141
- closeImmediately ();
142
- }
143
- };
144
- }
145
-
146
- private TextFieldWithAutoCompletionListProvider <String > onLookup (Collection <String > projects ) {
147
- return new TextFieldWithAutoCompletionListProvider <>(projects ) {
148
- public @ NotNull String getLookupString (@ NotNull String item ) {
149
- return item ;
150
- }
151
- };
152
- }
153
-
154
114
private void closeImmediately () {
155
115
if (isVisible ()) {
156
116
doCancelAction ();
@@ -160,34 +120,30 @@ private void closeImmediately() {
160
120
@ Override
161
121
protected void doOKAction () {
162
122
super .doOKAction ();
163
- this .activeProject = activeProjectTextField .getText ();
164
- }
165
-
166
- public String getActiveProject () {
167
- return activeProject ;
123
+ this .newProject = newProjectTextField .getText ();
168
124
}
169
125
170
- public boolean isCreateNewProject () {
171
- return createNewProject ;
126
+ public String getNewProject () {
127
+ return newProject ;
172
128
}
173
129
174
130
private class ActiveProjectValidator implements Supplier <ValidationInfo > {
175
131
176
132
@ Override
177
133
public ValidationInfo get () {
178
- String activeProject = activeProjectTextField .getText ();
134
+ String activeProject = newProjectTextField .getText ();
179
135
ValidationInfo validation = getValidationInfo (activeProject );
180
136
// update OK button
181
137
setOKActionEnabled (validation .okEnabled );
182
138
return validation ;
183
139
}
184
140
185
- private ValidationInfo getValidationInfo (String project ) {
141
+ private ValidationInfo getValidationInfo (String newProject ) {
186
142
ValidationInfo validation = new ValidationInfo ("" ).withOKEnabled ();
187
- if (StringUtil .isEmptyOrSpaces (project )) {
188
- validation = new ValidationInfo ("Provide active Project " ).forComponent (activeProjectTextField ).asWarning ();
189
- } else if (project . equals ( currentProject )) {
190
- validation = new ValidationInfo ("Choose different Project " ).forComponent (activeProjectTextField ).asWarning ();
143
+ if (StringUtil .isEmptyOrSpaces (newProject )) {
144
+ validation = new ValidationInfo ("Provide project name " ).forComponent (newProjectTextField ).asWarning ();
145
+ } else if (allProjects . contains ( newProject )) {
146
+ validation = new ValidationInfo ("Already exists, choose new name " ).forComponent (newProjectTextField ).asWarning ();
191
147
}
192
148
return validation ;
193
149
}
0 commit comments