cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r890469 - in /cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ editor/ undo/ util/
Date Mon, 14 Dec 2009 20:29:47 GMT
Author: andrey
Date: Mon Dec 14 20:28:02 2009
New Revision: 890469

URL: http://svn.apache.org/viewvc?rev=890469&view=rev
Log:
CAY-1191 Undo/Redo support in modeler

Added:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JCayenneTextPaneUndoable.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java
Removed:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JEditTextAreaUndoableAdapter.java
Modified:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java?rev=890469&r1=890468&r2=890469&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
Mon Dec 14 20:28:02 2009
@@ -172,7 +172,6 @@
         };
 
         addTreeSelectionListener(treeSelectionListener);
-        addTreeSelectionListener(mediator.getApplication().getUndoManager());
 
         addMouseListener(new PopupHandler());
 

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java?rev=890469&r1=890468&r2=890469&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
Mon Dec 14 20:28:02 2009
@@ -62,8 +62,6 @@
     private void initView() {
 
         scriptArea = CayenneWidgetFactory.createJEJBQLTextPane();
-        
-        scriptArea.getPane().getDocument().addUndoableEditListener(new JTextFieldUndoListener(scriptArea.getPane()));
          
         scriptArea.getDocument().addDocumentListener(this);
 

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java?rev=890469&r1=890468&r2=890469&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
Mon Dec 14 20:28:02 2009
@@ -18,8 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.undo;
 
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
 import javax.swing.undo.CannotRedoException;
 import javax.swing.undo.CannotUndoException;
 import javax.swing.undo.UndoableEdit;
@@ -28,26 +26,8 @@
 import org.apache.cayenne.modeler.action.RedoAction;
 import org.apache.cayenne.modeler.action.UndoAction;
 import org.apache.cayenne.modeler.util.CayenneAction;
-import org.apache.cayenne.query.EJBQLQuery;
-import org.apache.cayenne.query.SQLTemplate;
 
-public class CayenneUndoManager extends javax.swing.undo.UndoManager implements
-        TreeSelectionListener {
-
-    public void valueChanged(TreeSelectionEvent event) {
-
-        UndoableEdit e = editToBeUndone();
-
-        if (e instanceof TextCompoundEdit) {
-            TextCompoundEdit edit = (TextCompoundEdit) e;
-
-            if (edit.getTargetObject() instanceof SQLTemplate
-                    || edit.getTargetObject() instanceof EJBQLQuery) {
-                trimEdits(edits.size() - 1, edits.size() - 1);
-                updateUI();
-            }
-        }
-    }
+public class CayenneUndoManager extends javax.swing.undo.UndoManager {
 
     private Application application;
 

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java?rev=890469&r1=890468&r2=890469&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java
Mon Dec 14 20:28:02 2009
@@ -38,8 +38,6 @@
 
 import org.apache.cayenne.modeler.ModelerPreferences;
 import org.apache.cayenne.modeler.undo.JComboBoxUndoListener;
-import org.apache.cayenne.modeler.undo.JEditTextAreaUndoableAdapter;
-import org.apache.cayenne.modeler.undo.JTextFieldUndoListener;
 import org.apache.cayenne.modeler.util.combo.AutoCompletion;
 import org.apache.cayenne.modeler.util.combo.ComboBoxCellEditor;
 import org.apache.cayenne.swing.components.textpane.JCayenneTextPane;
@@ -215,14 +213,11 @@
      * Creates and returns a JEdit text component with syntax highlighing
      */
     public static JEditTextArea createJEditTextArea() {
-        JEditTextArea area = new JEditTextArea();
+        JEditTextArea area = new JEditTextAreaUndoable();
         if (OperatingSystem.getOS() == OperatingSystem.MAC_OS_X) {
             area.setInputHandler(new MacInputHandler());
         }
 
-        area.getDocument().addUndoableEditListener(
-                new JTextFieldUndoListener(new JEditTextAreaUndoableAdapter(area)));
-
         return area;
     }
 
@@ -232,7 +227,7 @@
     // }
 
     public static JCayenneTextPane createJEJBQLTextPane() {
-        JCayenneTextPane area = new JCayenneTextPane(new EJBQLSyntaxConstant());
+        JCayenneTextPane area = new JCayenneTextPaneUndoable(new EJBQLSyntaxConstant());
         return area;
     }
 

Added: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JCayenneTextPaneUndoable.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JCayenneTextPaneUndoable.java?rev=890469&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JCayenneTextPaneUndoable.java
(added)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JCayenneTextPaneUndoable.java
Mon Dec 14 20:28:02 2009
@@ -0,0 +1,49 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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 javax.swing.event.UndoableEditListener;
+
+import org.apache.cayenne.modeler.undo.JTextFieldUndoListener;
+import org.apache.cayenne.swing.components.textpane.JCayenneTextPane;
+import org.apache.cayenne.swing.components.textpane.syntax.SyntaxConstant;
+
+class JCayenneTextPaneUndoable extends JCayenneTextPane {
+
+    private UndoableEditListener undoListener;
+
+    JCayenneTextPaneUndoable(SyntaxConstant syntaxConstant) {
+        super(syntaxConstant);
+
+        this.undoListener = new JTextFieldUndoListener(this.getPane());
+        getDocument().addUndoableEditListener(this.undoListener);
+    }
+
+    @Override
+    public void setText(String t) {
+        getDocument().removeUndoableEditListener(this.undoListener);
+
+        try {
+            super.setText(t);
+        }
+        finally {
+            getDocument().addUndoableEditListener(this.undoListener);
+        }
+    }
+}

Added: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java?rev=890469&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java
(added)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java
Mon Dec 14 20:28:02 2009
@@ -0,0 +1,121 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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 java.awt.event.FocusListener;
+
+import javax.swing.JTextField;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.text.Document;
+
+import org.apache.cayenne.modeler.undo.JTextFieldUndoListener;
+import org.syntax.jedit.JEditTextArea;
+
+class JEditTextAreaUndoable extends JEditTextArea {
+
+    private UndoableEditListener undoListener;
+
+    JEditTextAreaUndoable() {
+        this.undoListener = new JTextFieldUndoListener(new JEditTextAreaUndoableAdapter(
+                this));
+
+        this.getDocument().addUndoableEditListener(this.undoListener);
+    }
+
+    @Override
+    public void setText(String t) {
+        this.getDocument().removeUndoableEditListener(this.undoListener);
+        try {
+            super.setText(t);
+        }
+        finally {
+            this.getDocument().addUndoableEditListener(this.undoListener);
+        }
+    }
+
+    private static class JEditTextAreaUndoableAdapter extends JTextField {
+
+        @Override
+        public synchronized void addFocusListener(FocusListener l) {
+            if (textArea != null) {
+                textArea.addFocusListener(l);
+            }
+        }
+
+        private JEditTextArea textArea;
+
+        public JEditTextAreaUndoableAdapter(JEditTextArea scriptArea) {
+            this.textArea = scriptArea;
+        }
+
+        public int getCaretPosition() {
+            if (textArea == null) {
+                return 0;
+            }
+
+            return textArea.getCaretPosition();
+        }
+
+        public Document getDocument() {
+            if (textArea == null) {
+                return null;
+            }
+
+            return textArea.getDocument();
+        }
+
+        public boolean requestFocusInWindow() {
+            if (textArea == null) {
+                return false;
+            }
+
+            return textArea.requestFocusInWindow();
+        }
+
+        public void selectAll() {
+            if (textArea == null) {
+                return;
+            }
+
+            textArea.selectAll();
+        }
+
+        @Override
+        public void setText(String t) {
+            if (textArea == null) {
+                return;
+            }
+
+            textArea.setText(t);
+        }
+
+        public void setCaretPosition(int position) {
+            if (textArea == null) {
+                return;
+            }
+
+            textArea.setCaretPosition(position);
+        }
+
+        @Override
+        public void updateUI() {
+
+        }
+    }
+}

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java?rev=890469&r1=890468&r2=890469&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java
Mon Dec 14 20:28:02 2009
@@ -32,10 +32,8 @@
 import javax.swing.text.JTextComponent;
 
 import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
-import org.apache.cayenne.modeler.undo.JEditTextAreaUndoableAdapter;
 import org.apache.cayenne.modeler.undo.JTextFieldUndoListener;
 import org.apache.cayenne.validation.ValidationException;
-import org.syntax.jedit.JEditTextArea;
 
 /**
  * A validating adapter for JTextComponent. Implement {@link #updateModel(String)}to
@@ -53,10 +51,6 @@
 
     protected JTextComponent textComponent;
 
-    public TextAdapter(JEditTextArea textArea) {
-        this(new JEditTextAreaUndoableAdapter(textArea), true, false, true);
-    }
-
     public TextAdapter(JTextField textField) {
         this(textField, true, false, true);
     }



Mime
View raw message