This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit ac4cc3098dedc89478ce834894f12e4638fcf389
Author: alex-byi <alex-...@mail.ru>
AuthorDate: Thu Feb 6 15:48:04 2020 +0300

    Validation spaces in JDBC Driver and DB URL lines in dataNode main window
---
 .../editor/datanode/JDBCDataSourceView.java        |  4 ++
 .../util/JTextFieldWhitespacesValidator.java       | 53 ++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
index 0126991..2447eac 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
@@ -26,6 +26,7 @@ import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.JTextField;
 
+import org.apache.cayenne.modeler.util.JTextFieldWhitespacesValidator;
 import org.apache.cayenne.modeler.util.JTextFieldUndoable;
 
 import com.jgoodies.forms.builder.PanelBuilder;
@@ -54,6 +55,9 @@ public class JDBCDataSourceView extends JPanel {
         syncWithLocal = new JButton("Sync with Local");
         syncWithLocal.setToolTipText("Update from local DataSource");
 
+        driver.addFocusListener(new JTextFieldWhitespacesValidator(driver));
+        url.addFocusListener(new JTextFieldWhitespacesValidator(url));
+
         // assemble
         CellConstraints cc = new CellConstraints();
         FormLayout layout = new FormLayout(
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldWhitespacesValidator.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldWhitespacesValidator.java
new file mode 100644
index 0000000..7eacb89
--- /dev/null
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldWhitespacesValidator.java
@@ -0,0 +1,53 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.util;
+
+import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
+
+
+import javax.swing.JTextField;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+/**
+ * @since 4.2
+ */
+public class JTextFieldWhitespacesValidator implements FocusListener {
+
+    private JTextField jTextField;
+
+    public JTextFieldWhitespacesValidator(JTextField jTextField) {
+        this.jTextField = jTextField;
+    }
+
+    @Override
+    public void focusGained(FocusEvent e) {
+
+    }
+
+    @Override
+    public void focusLost(FocusEvent e) {
+        String text = jTextField.getText();
+        int length = text.length() - text.trim().length();
+        if (length != 0) {
+            jTextField.setBackground(ValidatorDialog.WARNING_COLOR);
+            jTextField.setToolTipText("There are some whitespaces in this 
line");
+        }
+    }
+}

Reply via email to