cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [3/4] cayenne git commit: Minor code cleanup + release notes
Date Fri, 30 Jun 2017 15:06:19 GMT
Minor code cleanup + release notes


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/244bb456
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/244bb456
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/244bb456

Branch: refs/heads/master
Commit: 244bb45695381a88faccd0be419954cf971bedb8
Parents: 8712d98
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri Jun 30 18:05:29 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri Jun 30 18:05:29 2017 +0300

----------------------------------------------------------------------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  3 +
 .../modeler/editor/EjbqlQueryScriptsTab.java    | 33 +++-----
 .../modeler/editor/SQLTemplateScriptsTab.java   | 88 +++++++++-----------
 .../components/textpane/JCayenneTextPane.java   | 22 +++++
 4 files changed, 76 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/244bb456/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 53d9574..4496ea4 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -17,6 +17,9 @@ CAY-2329 Update project dependencies
 
 Bug Fixes:
 
+CAY-2318 Modeler: Query. Exception after Undo clicking
+CAY-2319 Modeler: Embeddable > Attributes. Undo does not cancel pasted objects
+CAY-2323 Modeler: Graph. No warning while saving the image with existing name
 
 
 ----------------------------------

http://git-wip-us.apache.org/repos/asf/cayenne/blob/244bb456/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
index 25c6094..9f56474 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
@@ -41,9 +41,13 @@ import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.swing.components.textpane.JCayenneTextPane;
 import org.apache.cayenne.swing.components.textpane.syntax.EJBQLSyntaxConstant;
 import org.apache.cayenne.util.Util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener {
 
+    private static final Logger logger = LoggerFactory.getLogger(EjbqlQueryScriptsTab.class);
+
     protected ProjectController mediator;
     protected JCayenneTextPane scriptArea;
     private boolean updateDisabled;
@@ -55,17 +59,7 @@ public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener
{
     }
 
     void displayScript() {
-        EJBQLQueryDescriptor query = getQuery();
-        Document document = scriptArea.getDocument();;
-        String text = query.getEjbql();
-        try {
-            if(!document.getText(0, document.getLength()).equals(query.getEjbql())) {
-                document.remove(0, document.getLength());
-                document.insertString(0, text, null);
-            }
-        } catch (BadLocationException e) {
-            e.printStackTrace();
-        }
+        scriptArea.setDocumentTextDirect(getQuery().getEjbql());
         updateDisabled = false;
     }
 
@@ -82,21 +76,16 @@ public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener
{
                 try {
                     String text = scriptArea.getDocument().getText(e.getOffset(), 1);
                     if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
-                        getQuery().setEjbql(scriptArea.getText());
+                        getQuery().setEjbql(scriptArea.getDocumentTextDirect());
                         validateEJBQL();
                     }
-                } catch (BadLocationException e1) {
-                    e1.printStackTrace();
+                } catch (BadLocationException ex) {
+                    logger.warn("Error reading document", ex);
                 }
             }
 
             public void removeUpdate(DocumentEvent e) {
-                try {
-                    String text = scriptArea.getDocument().getText(0,scriptArea.getDocument().getLength());
-                    getQuery().setEjbql(text);
-                } catch (BadLocationException e1) {
-                    e1.printStackTrace();
-                }
+                getQuery().setEjbql(scriptArea.getDocumentTextDirect());
                 validateEJBQL();
             }
         });
@@ -173,8 +162,8 @@ public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener
{
         Document doc = e.getDocument();
         try {
             setEJBQL(doc.getText(0, doc.getLength()));
-        } catch (BadLocationException e1) {
-            e1.printStackTrace();
+        } catch (BadLocationException ex) {
+            logger.warn("Error reading document", ex);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/244bb456/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
index dc41c57..90f8451 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
@@ -31,6 +31,8 @@ import org.apache.cayenne.modeler.util.JUndoableCayenneTextPane;
 import org.apache.cayenne.swing.components.textpane.JCayenneTextPane;
 import org.apache.cayenne.swing.components.textpane.syntax.SQLSyntaxConstants;
 import org.apache.cayenne.util.Util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.DefaultListCellRenderer;
@@ -60,11 +62,12 @@ import java.util.Map;
 public class SQLTemplateScriptsTab extends JPanel {
 
     private static final String DEFAULT_LABEL = "Default";
+    private static final Logger logger = LoggerFactory.getLogger(SQLTemplateScriptsTab.class);
 
     protected ProjectController mediator;
 
-    protected JList scripts;
-    protected List keys;
+    protected JList<String> scripts;
+    protected List<String> keys;
     protected PanelBuilder builder;
     protected CellConstraints cc;
     protected JCayenneTextPane textPane;
@@ -89,15 +92,15 @@ public class SQLTemplateScriptsTab extends JPanel {
             }
         };
 
-        scripts = new JList();
+        scripts = new JList<>();
         scripts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         scripts.setCellRenderer(new DbAdapterListRenderer(DbAdapterInfo.getStandardAdapterLabels()));
 
-        keys = new ArrayList(DbAdapterInfo.getStandardAdapters().length + 1);
+        keys = new ArrayList<>(DbAdapterInfo.getStandardAdapters().length + 1);
         keys.addAll(Arrays.asList(DbAdapterInfo.getStandardAdapters()));
         Collections.sort(keys);
         keys.add(0, DEFAULT_LABEL);
-        scripts.setModel(new DefaultComboBoxModel(keys.toArray()));
+        scripts.setModel(new DefaultComboBoxModel<>(keys.toArray(new String[0])));
 
         // assemble
         cc = new CellConstraints();
@@ -174,18 +177,16 @@ public class SQLTemplateScriptsTab extends JPanel {
             return;
         }
 
-        String key = (String) scripts.getSelectedValue();
+        String key = scripts.getSelectedValue();
         if (key == null) {
             return;
         }
 
-        boolean exist = true;
+        boolean exist = false;
         for (JCayenneTextPane textPane: panes) {
             if (textPane.getName().equals(key)) {
                 exist = true;
                 break;
-            } else {
-                exist = false;
             }
         }
 
@@ -202,15 +203,7 @@ public class SQLTemplateScriptsTab extends JPanel {
 
         for (final JCayenneTextPane textPane: panes) {
             if (key.equals(textPane.getName())) {
-                Document document = textPane.getDocument();
-                try {
-                    if(!document.getText(0, document.getLength()).equals(text)) {
-                        document.remove(0, document.getLength());
-                        document.insertString(0, text, null);
-                    }
-                } catch (BadLocationException e) {
-                    e.printStackTrace();
-                }
+                textPane.setDocumentTextDirect(text);
                 textPane.getPane().setVisible(true);
                 textPane.getPane().setEditable(true);
             } else {
@@ -221,45 +214,44 @@ public class SQLTemplateScriptsTab extends JPanel {
     }
 
     void setSQL(DocumentEvent e, String key) {
-        Document doc = e.getDocument();
+        if (key == null) {
+            return;
+        }
 
-        try {
-            String text = doc.getText(0, doc.getLength());
+        SQLTemplateDescriptor query = getQuery();
+        if (query == null) {
+            return;
+        }
 
-            SQLTemplateDescriptor query = getQuery();
+        Document doc = e.getDocument();
+        String text = null;
 
-            if (query == null) {
-                return;
-            }
+        try {
+            text = doc.getText(0, doc.getLength());
+        } catch (BadLocationException ex) {
+            logger.warn("Error reading document", ex);
+        }
 
-            if (key == null) {
-                return;
+        if (text != null) {
+            text = text.trim();
+            if (text.length() == 0) {
+                text = null;
             }
+        }
 
-            if (text != null) {
-                text = text.trim();
-                if (text.length() == 0) {
-                    text = null;
-                }
+        // Compare the value before modifying the query - text pane
+        // will call "verify" even if no changes have occured....
+        if (key.equals(DEFAULT_LABEL)) {
+            if (!Util.nullSafeEquals(text, query.getSql())) {
+                query.setSql(text);
+                mediator.fireQueryEvent(new QueryEvent(this, query));
             }
-
-            // Compare the value before modifying the query - text pane
-            // will call "verify" even if no changes have occured....
-            if (key.equals(DEFAULT_LABEL)) {
-                if (!Util.nullSafeEquals(text, query.getSql())) {
-                    query.setSql(text);
-                    mediator.fireQueryEvent(new QueryEvent(this, query));
-                }
-            } else {
-                if (!Util.nullSafeEquals(text, query.getAdapterSql().get(key))) {
-                    query.getAdapterSql().put(key, text);
-                    mediator.fireQueryEvent(new QueryEvent(this, query));
-                }
+        } else {
+            if (!Util.nullSafeEquals(text, query.getAdapterSql().get(key))) {
+                query.getAdapterSql().put(key, text);
+                mediator.fireQueryEvent(new QueryEvent(this, query));
             }
         }
-        catch (BadLocationException e1) {
-            e1.printStackTrace();
-        }
     }
 
     final class CustomListener implements DocumentListener{

http://git-wip-us.apache.org/repos/asf/cayenne/blob/244bb456/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
index 9c9b44b..30ca3bc 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
@@ -331,6 +331,28 @@ public class JCayenneTextPane extends JPanel {
         return pane.getDocument();
     }
 
+    public void setDocumentTextDirect(String text) {
+        Document document = getDocument();
+        try {
+            if(!document.getText(0, document.getLength()).equals(text)) {
+                document.remove(0, document.getLength());
+                document.insertString(0, text, null);
+            }
+        } catch (BadLocationException ex) {
+            logObj.warn("Error reading document", ex);
+        }
+    }
+
+    public String getDocumentTextDirect() {
+        Document document = getDocument();
+        try {
+            return document.getText(0, document.getLength());
+        } catch (BadLocationException ex) {
+            logObj.warn("Error reading document", ex);
+            return null;
+        }
+    }
+
     class JTextPaneScrollable extends JTextPane {
 
         JTextPaneScrollable(EditorKit editorKit) {


Mime
View raw message