cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r760792 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/editor/EjbqlQueryScriptsTab.java modeler/editor/EjbqlTabbedView.java swing/components/textpane/JCayenneTextPane.java
Date Wed, 01 Apr 2009 06:54:12 GMT
Author: aadamchik
Date: Wed Apr  1 06:54:12 2009
New Revision: 760792

URL: http://svn.apache.org/viewvc?rev=760792&view=rev
Log:
CAY-1164 Implement EJBQL query support in the Modeler

ErrorsInJCayenneTextPane.txt patch by Olga... still work in progress

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java?rev=760792&r1=760791&r2=760792&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
Wed Apr  1 06:54:12 2009
@@ -71,6 +71,34 @@
             }
 
         });
+
+        scriptArea.getDocument().addDocumentListener(new DocumentListener() {
+
+            public void changedUpdate(DocumentEvent e) {
+            }
+
+            public void insertUpdate(DocumentEvent e) {
+                try {
+                    String text = scriptArea
+                            .getDocument()
+                            .getText(e.getOffset(), 1)
+                            .toString();
+                    if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
+                        getQuery().setEjbqlStatement(scriptArea.getText());
+                        validateEJBQL();
+                    }
+                }
+                catch (BadLocationException e1) {
+                    e1.printStackTrace();
+                }
+            }
+
+            public void removeUpdate(DocumentEvent e) {
+                getQuery().setEjbqlStatement(scriptArea.getText());
+                scriptArea.removeHighlightText();
+                validateEJBQL();
+            }
+        });
         setLayout(new BorderLayout());
         add(scriptArea, BorderLayout.WEST);
         add(scriptArea.scrollPane, BorderLayout.CENTER);
@@ -112,10 +140,10 @@
         if (query == null) {
             return;
         }
-
+        String testTemp = null;
         if (text != null) {
-            text = text.trim();
-            if (text.length() == 0) {
+            testTemp = text.trim();
+            if (testTemp.length() == 0) {
                 text = null;
             }
         }
@@ -148,12 +176,16 @@
                 getQuery(),
                 mediator.getCurrentDataDomain());
         if (positionException != null) {
-
-            scriptArea.setHighlightText(
-                    positionException.getBeginLine(),
-                    positionException.getBeginColumn(),
-                    positionException.getLength());
-
+            if (positionException.getBeginLine() != null
+                    || positionException.getBeginColumn() != null
+                    || positionException.getLength() != null) {
+                
+                scriptArea.setHighlightText(
+                        positionException.getBeginLine(),
+                        positionException.getBeginColumn(),
+                        positionException.getLength(),
+                        positionException.getMessage());
+            }
         }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java?rev=760792&r1=760791&r2=760792&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlTabbedView.java
Wed Apr  1 06:54:12 2009
@@ -48,7 +48,7 @@
         addTab("General", new JScrollPane(mainTab));
 
         this.scriptsTab = new EjbqlQueryScriptsTab(mediator);
-        addTab("EJBQL Scripts", scriptsTab);
+        addTab("EJBQL", scriptsTab);
     }
 
     private void initController() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java?rev=760792&r1=760791&r2=760792&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
Wed Apr  1 06:54:12 2009
@@ -1,14 +1,14 @@
 package org.apache.cayenne.swing.components.textpane;
 
 import java.awt.Color;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Rectangle;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.awt.event.MouseEvent;
 
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
@@ -31,7 +31,9 @@
     protected Highlighter.HighlightPainter painter;
     private JTextPaneScrollable pane;
     public JScrollPane scrollPane;
+
     public boolean repaint;
+
     private static Log logObj = LogFactory.getLog(Main.class);
 
     public void setText(String text) {
@@ -129,9 +131,12 @@
 
             public void insertUpdate(DocumentEvent evt) {
                 try {
-                    removeHighlightText();
-                    if (pane.getText(evt.getOffset(), 1).toString().equals("/")
-                            || pane.getText(evt.getOffset(), 1).toString().equals("*")) {
+                    String text = pane.getText(evt.getOffset(), 1).toString();
+                    if (!(text.equals(" ") || text.equals("\n") || text.equals("\t"))) {
+                        removeHighlightText();
+                    }
+                    if (text.equals("/") || text.equals("*")) {
+                        removeHighlightText();
                         pane.repaint();
                     }
                 }
@@ -141,7 +146,6 @@
             }
 
             public void removeUpdate(DocumentEvent evt) {
-                removeHighlightText();
             }
 
             public void changedUpdate(DocumentEvent evt) {
@@ -156,24 +160,25 @@
         highlighter.addHighlight(lastIndex, endIndex, painter);
     }
 
-    public void setHighlightText(int line, int lastIndex, int size) {
-        int k = 0;
-        try {
-            Matcher matcherTab = Pattern.compile("\t").matcher(
-                    pane.getText(getPosition(line, 0), getPosition(line, lastIndex)));
-            while (matcherTab.find()) {
-                k += 7;
-            }
-        }
-        catch (BadLocationException e1) {
-            logObj.warn("Error: ", e1);
-        }
+    /*
+     * set underlines text in JCayenneTextPane
+     * 
+     * @param int line - starting line for underlined text
+     * 
+     * @param int lastIndex - starting position in line for underlined text
+     * 
+     * @param int size
+     * 
+     * @param String message - text for toolTip, contains the text of the error
+     */
+    
+    public void setHighlightText(int line, int lastIndex, int size, String message) {
         try {
-            int position = getPosition(line, lastIndex-k);
+            int position = getPosition(line, lastIndex);
             int positionEnd = position + size;
             Highlighter highlighter = pane.getHighlighter();
             removeHighlightText(highlighter);
-            highlighter.addHighlight(position, positionEnd, painter);
+            highlighter.addHighlight(position, positionEnd, painter);            
         }
         catch (BadLocationException e) {
             logObj.warn("Error: ", e);



Mime
View raw message