Skip to content

Commit 3f1e9f3

Browse files
committed
UI/UX: Set button disabled property when connectionInfo input changed
1 parent 54cf2ab commit 3f1e9f3

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/main/java/root/javafx/CustomView/ConnectionInfoVBox.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public void addNewConnInfo(ActionEvent e) {
173173
dbConnAP.init();
174174
dbConnAP.setInitialValue(new JdbcConnectionInfo());
175175
addConnectionInfoAP(2, dbConnAP);
176+
connTestBtn.setDisable(true);
176177

177178
} else if (childAPClazz == ServerConnectionInfoAnchorPane.class) {
178179
ServerConnectionInfoAnchorPane serverConnAP = new ServerConnectionInfoAnchorPane();
@@ -220,7 +221,6 @@ public void setMenuTitle(String menuTitle, FontAwesomeIcon menuIcon) {
220221
menuIconIV.setIcon(menuIcon);
221222
}
222223

223-
224224
// When connectionInfo index changed, this method always will be invoked.
225225
private void bringFrontConnInfoAnchorPane(long index) {
226226
connInfoIdx = index;
@@ -234,9 +234,15 @@ private void bringFrontConnInfoAnchorPane(long index) {
234234

235235
// Button disabled when there is no active ConnectionInfoAP
236236
if (this.connInfoAPMap.getActiveAPCnt() == 0) {
237-
setButtonsDisable(true);
237+
connTestBtn.setDisable(true);
238+
connInfoRemoveBtn.setDisable(true);
239+
prevConnInfoBtn.setDisable(true);
240+
nextConnInfoBtn.setDisable(true);
238241
} else {
239-
setButtonsDisable(false);
242+
connTestBtn.setDisable(false);
243+
connInfoRemoveBtn.setDisable(false);
244+
prevConnInfoBtn.setDisable(false);
245+
nextConnInfoBtn.setDisable(false);
240246
}
241247

242248
// Index logging
@@ -279,13 +285,6 @@ private void setConnectionBtnIcon(int type) {
279285
}
280286
}
281287

282-
private void setButtonsDisable(boolean disabled) {
283-
this.connTestBtn.setDisable(disabled);
284-
this.connInfoRemoveBtn.setDisable(disabled);
285-
this.prevConnInfoBtn.setDisable(disabled);
286-
this.nextConnInfoBtn.setDisable(disabled);
287-
}
288-
289288
@AllArgsConstructor
290289
@Data
291290
private static class StatefulAP {

src/main/java/root/javafx/CustomView/DBConnectionInfoAnchorPane.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import java.util.regex.Matcher;
55
import java.util.regex.Pattern;
66

7+
import org.apache.commons.lang3.StringUtils;
8+
79
import com.jfoenix.controls.JFXComboBox;
810

911
import javafx.event.Event;
1012
import javafx.event.EventHandler;
1113
import javafx.fxml.FXML;
1214
import javafx.fxml.FXMLLoader;
15+
import javafx.scene.Node;
1316
import javafx.scene.control.PasswordField;
1417
import javafx.scene.control.TextField;
1518
import javafx.scene.layout.AnchorPane;
@@ -113,6 +116,11 @@ public JdbcConnectionInfo getInputValues() {
113116
return jdbc;
114117
}
115118

119+
public boolean isAnyEmptyInput() {
120+
return StringUtils.isAnyEmpty(hostTF.getText(), portTF.getText(), sidTF.getText(), userTF.getText(),
121+
passwordPF.getText(), driverCB.getSelectionModel().getSelectedItem());
122+
}
123+
116124
/**
117125
* 키 입력 또는 콤보박스 선택을 통해 입력된 Database 접속정보를 이용해 URL을 생성하는 이벤트
118126
*
@@ -129,6 +137,8 @@ public DBUrlGenerateEvent(String dbms) {
129137

130138
@Override
131139
public void handle(Event event) {
140+
System.out.println("Fire!");
141+
132142
StringBuffer url = new StringBuffer();
133143
url.append("jdbc:").append(dbms).append(":").append(driverCB.getSelectionModel().getSelectedItem())
134144
.append(":@")
@@ -137,6 +147,28 @@ public void handle(Event event) {
137147
.append(sidTF.getText() == null ? "" : sidTF.getText());
138148

139149
urlTF.setText(url.toString());
150+
151+
if (event == null) {
152+
System.out.println("Event is Null");
153+
return;
154+
}
155+
156+
Node node = (Node) event.getTarget();
157+
Node topParent = null;
158+
while (true) {
159+
if (node.getParent() == null) {
160+
break;
161+
}
162+
node = node.getParent();
163+
topParent = node;
164+
}
165+
166+
if (topParent == null) {
167+
System.out.println("TopParent is Null");
168+
return;
169+
}
170+
171+
topParent.lookup("#connTestBtn").setDisable(isAnyEmptyInput());
140172
}
141173
}
142174
}

src/main/java/root/javafx/CustomView/ServerConnectionInfoAnchorPane.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
import javafx.scene.control.PasswordField;
1010
import javafx.scene.control.TextField;
1111
import javafx.scene.layout.AnchorPane;
12-
import lombok.Data;
13-
import lombok.EqualsAndHashCode;
1412
import root.core.domain.AlertLogCommand;
1513
import root.core.domain.JschConnectionInfo;
1614
import root.core.repository.constracts.PropertyRepository;
1715
import root.core.repository.implement.PropertyRepositoryImpl;
1816

19-
@EqualsAndHashCode(callSuper = false)
20-
@Data
2117
public class ServerConnectionInfoAnchorPane extends AnchorPane {
2218

2319
/* Dependency Injection */

0 commit comments

Comments
 (0)