cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r689322 - in /cayenne/main/trunk: docs/doc/src/main/resources/RELEASE-NOTES.txt framework/cayenne-modeler/pom.xml framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
Date Wed, 27 Aug 2008 01:19:51 GMT
Author: kmenard
Date: Tue Aug 26 18:19:50 2008
New Revision: 689322

URL: http://svn.apache.org/viewvc?rev=689322&view=rev
Log:
Fixed CAY-892: CM Usability: JEdit Syntax to all TextAreas

Patch by Andrey Razumovsky (and apologies for not giving proper attribution in previous commit
messages).

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-modeler/pom.xml
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=689322&r1=689321&r2=689322&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Tue Aug 26 18:19:50 2008
@@ -19,6 +19,7 @@
 CAY-436 In modeler, change default object relationship delete rule
 CAY-794 Abstract object entities
 CAY-888 CM Usability: Object Select Query Improvements
+CAY-892 CM Usability: JEdit Syntax to all TextAreas
 CAY-894 CM Usability: Welcome screen
 CAY-911 CM Usability: JComboBox Autocompletion
 CAY-1056 Detection of the project file changes on disk.

Modified: cayenne/main/trunk/framework/cayenne-modeler/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/pom.xml?rev=689322&r1=689321&r2=689322&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/pom.xml (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/pom.xml Tue Aug 26 18:19:50 2008
@@ -16,10 +16,7 @@
 	KIND, either express or implied.  See the License for the
 	specific language governing permissions and limitations
 	under the License.   
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+--><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
 	<modelVersion>4.0.0</modelVersion>
 
@@ -114,7 +111,13 @@
 			<groupId>mockrunner</groupId>
 			<artifactId>mockrunner</artifactId>
 		</dependency>
-	</dependencies>
+		
+	  	<dependency>
+      		<groupId>net.sf.jedit-syntax</groupId>
+      		<artifactId>jedit-syntax</artifactId>
+      		<version>2.2.2</version>
+    	</dependency>
+  </dependencies>
 
 	<build>
 		<plugins>
@@ -164,4 +167,4 @@
 		</plugins>
 
 	</build>
-</project>
+</project>
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java?rev=689322&r1=689321&r2=689322&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SQLTemplateScriptsTab.java
Tue Aug 26 18:19:50 2008
@@ -33,9 +33,9 @@
 import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
 import javax.swing.ListSelectionModel;
 import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.text.BadLocationException;
@@ -44,10 +44,15 @@
 import org.apache.cayenne.map.event.QueryEvent;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.util.DbAdapterInfo;
-import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.util.Util;
+import org.syntax.jedit.JEditTextArea;
+import org.syntax.jedit.KeywordMap;
+import org.syntax.jedit.tokenmarker.PLSQLTokenMarker;
+import org.syntax.jedit.tokenmarker.SQLTokenMarker;
+import org.syntax.jedit.tokenmarker.Token;
+import org.syntax.jedit.tokenmarker.TokenMarker;
 
 import com.jgoodies.forms.builder.PanelBuilder;
 import com.jgoodies.forms.layout.CellConstraints;
@@ -58,14 +63,51 @@
  * 
  * @author Andrus Adamchik
  */
-public class SQLTemplateScriptsTab extends JPanel {
+public class SQLTemplateScriptsTab extends JPanel implements DocumentListener {
 
     private static final String DEFAULT_LABEL = "Default";
+    
+    /**
+     * JEdit marker for SQL Template
+     */
+    private static final TokenMarker SQL_TEMPLATE_MARKER;
+    static {
+        KeywordMap map = PLSQLTokenMarker.getKeywordMap();
+        
+        //adding more keywords
+        map.add("FIRST", Token.KEYWORD1);
+        map.add("LIMIT", Token.KEYWORD1);
+        map.add("OFFSET", Token.KEYWORD1);
+        map.add("TOP", Token.KEYWORD1);
+        
+        //adding velocity template highlighing
+        map.add("#bind", Token.KEYWORD2);
+        map.add("#bindEqual", Token.KEYWORD2);
+        map.add("#bindNotEqual", Token.KEYWORD2);
+        map.add("#bindObjectEqual", Token.KEYWORD2);
+        map.add("#bindObjectNotEqual", Token.KEYWORD2);
+        map.add("#chain", Token.KEYWORD2);
+        map.add("#chunk", Token.KEYWORD2);
+        map.add("#end", Token.KEYWORD2);
+        map.add("#result", Token.KEYWORD2);
+        
+        SQL_TEMPLATE_MARKER = new SQLTokenMarker(map);
+    }
 
     protected ProjectController mediator;
 
     protected JList scripts;
-    protected TextAdapter script;
+    
+    /**
+     * JEdit text component for highlighing SQL syntax (see CAY-892)
+     */
+    protected JEditTextArea scriptArea;
+    
+    /**
+     * Indication that no update should be fired
+     */
+    private boolean updateDisabled;
+    
     protected ListSelectionListener scriptRefreshHandler;
 
     public SQLTemplateScriptsTab(ProjectController mediator) {
@@ -96,14 +138,11 @@
         Collections.sort(keys);
         keys.add(0, DEFAULT_LABEL);
         scripts.setModel(new DefaultComboBoxModel(keys.toArray()));
-
-        script = new TextAdapter(new JTextArea(15, 30)) {
-
-            protected void updateModel(String text) {
-                setSQL(text);
-            }
-        };
-
+        
+        scriptArea = new JEditTextArea();
+        scriptArea.setTokenMarker(SQL_TEMPLATE_MARKER);
+        scriptArea.getDocument().addDocumentListener(this);
+        
         // assemble
         CellConstraints cc = new CellConstraints();
         PanelBuilder builder = new PanelBuilder(new FormLayout(
@@ -115,7 +154,7 @@
                 scripts,
                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cc.xy(1, 2));
-        builder.add(new JScrollPane(script.getComponent()), cc.xy(3, 2));
+        builder.add(new JScrollPane(scriptArea), cc.xy(3, 2));
 
         setLayout(new BorderLayout());
         add(builder.getPanel(), BorderLayout.CENTER);
@@ -135,7 +174,7 @@
         displayScript();
         scripts.addListSelectionListener(scriptRefreshHandler);
 
-        script.getComponent().setEnabled(true);
+        scriptArea.setEnabled(true);
         setVisible(true);
     }
 
@@ -183,20 +222,22 @@
         String text = (key.equals(DEFAULT_LABEL)) ? query.getDefaultTemplate() : query
                 .getCustomTemplate(key);
 
-        script.setText(text);
+        updateDisabled = true;
+        scriptArea.setText(text);
+        updateDisabled = false;
     }
 
     void disableEditor() {
-        script.setText(null);
-        script.getComponent().setEnabled(false);
-        script.getComponent().setEditable(false);
-        script.getComponent().setBackground(getBackground());
+        scriptArea.setText(null);
+        scriptArea.setEnabled(false);
+        scriptArea.setEditable(false);
+        scriptArea.setBackground(getBackground());
     }
 
     void enableEditor() {
-        script.getComponent().setEnabled(true);
-        script.getComponent().setEditable(true);
-        script.getComponent().setBackground(Color.WHITE);
+        scriptArea.setEnabled(true);
+        scriptArea.setEditable(true);
+        scriptArea.setBackground(Color.WHITE);
     }
 
     void setSQL(DocumentEvent e) {
@@ -247,6 +288,20 @@
             }
         }
     }
+    
+    public void insertUpdate(DocumentEvent e) {
+        changedUpdate(e);
+    }
+
+    public void removeUpdate(DocumentEvent e) {
+        changedUpdate(e);
+    }
+    
+    public void changedUpdate(DocumentEvent e) {
+        if (!updateDisabled) {
+            setSQL(e);
+        }
+    }
 
     final class DbAdapterListRenderer extends DefaultListCellRenderer {
 



Mime
View raw message