You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by an...@apache.org on 2009/10/05 20:40:28 UTC
svn commit: r821956 [3/4] - in
/cayenne/main/trunk/framework/cayenne-modeler/src:
main/java/org/apache/cayenne/modeler/
main/java/org/apache/cayenne/modeler/action/
main/java/org/apache/cayenne/modeler/dialog/
main/java/org/apache/cayenne/modeler/dialo...
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/SelectQueryPrefetchTab.java Mon Oct 5 18:40:25 2009
@@ -19,27 +19,32 @@
package org.apache.cayenne.modeler.editor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JToolBar;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableModel;
+import javax.swing.tree.TreeModel;
+
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionException;
import org.apache.cayenne.map.Attribute;
import org.apache.cayenne.map.Entity;
import org.apache.cayenne.map.Relationship;
import org.apache.cayenne.map.event.QueryEvent;
+import org.apache.cayenne.modeler.Application;
import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.undo.AddPrefetchUndoableEdit;
import org.apache.cayenne.modeler.util.EntityTreeFilter;
import org.apache.cayenne.modeler.util.EntityTreeModel;
import org.apache.cayenne.modeler.util.ModelerUtil;
import org.apache.cayenne.query.PrefetchTreeNode;
-import javax.swing.*;
-import javax.swing.table.AbstractTableModel;
-import javax.swing.table.TableModel;
-import javax.swing.tree.TreeModel;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.Collection;
-import java.util.Iterator;
-
/**
* Subclass of the SelectQueryOrderingTab configured to work with prefetches.
*
@@ -54,20 +59,37 @@
JButton add = new JButton("Add Prefetch", ModelerUtil
.buildIcon("icon-move_up.gif"));
+
add.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
- addPrefetch();
+ String prefetch = getSelectedPath();
+
+ if (prefetch == null) {
+ return;
+ }
+
+ addPrefetch(prefetch);
+
+ Application.getInstance().getUndoManager().addEdit(new AddPrefetchUndoableEdit(prefetch, SelectQueryPrefetchTab.this));
}
});
JButton remove = new JButton("Remove Prefetch", ModelerUtil
.buildIcon("icon-move_down.gif"));
+
remove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- removePrefetch();
+ int selection = table.getSelectedRow();
+
+ if (selection < 0) {
+ return;
+ }
+
+ String prefetch = (String) table.getModel().getValueAt(selection, 0);
+
+ removePrefetch(prefetch);
}
});
@@ -97,12 +119,8 @@
return new PrefetchModel();
}
- void addPrefetch() {
- String prefetch = getSelectedPath();
- if (prefetch == null) {
- return;
- }
-
+ public void addPrefetch(String prefetch) {
+
// check if such prefetch already exists
if (selectQuery.getPrefetchTree() != null) {
@@ -113,24 +131,19 @@
}
selectQuery.addPrefetch(prefetch);
-
+
// reset the model, since it is immutable
table.setModel(createTableModel());
- mediator.fireQueryEvent(new QueryEvent(SelectQueryPrefetchTab.this, selectQuery));
+
+ mediator.fireQueryEvent(new QueryEvent(this, selectQuery));
}
- void removePrefetch() {
- int selection = table.getSelectedRow();
- if (selection < 0) {
- return;
- }
-
- String prefetch = (String) table.getModel().getValueAt(selection, 0);
+ public void removePrefetch(String prefetch) {
selectQuery.removePrefetch(prefetch);
// reset the model, since it is immutable
table.setModel(createTableModel());
- mediator.fireQueryEvent(new QueryEvent(SelectQueryPrefetchTab.this, selectQuery));
+ mediator.fireQueryEvent(new QueryEvent(this, selectQuery));
}
boolean isToMany(String prefetch) {
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/AdapterView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/AdapterView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/AdapterView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/AdapterView.java Mon Oct 5 18:40:25 2009
@@ -24,6 +24,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
@@ -32,7 +34,7 @@
protected JTextField customAdapter;
public AdapterView() {
- this.customAdapter = new JTextField();
+ this.customAdapter = CayenneWidgetFactory.createUndoableTextField();
// assemble
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java Mon Oct 5 18:40:25 2009
@@ -24,6 +24,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
@@ -35,7 +37,7 @@
public CustomDataSourceView() {
- locationHint = new JTextField();
+ locationHint = CayenneWidgetFactory.createUndoableTextField();
// assemble
FormLayout layout = new FormLayout("right:80dlu, 3dlu, fill:200dlu", "");
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DBCPDataSourceView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DBCPDataSourceView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DBCPDataSourceView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DBCPDataSourceView.java Mon Oct 5 18:40:25 2009
@@ -25,6 +25,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
@@ -36,7 +38,7 @@
public DBCPDataSourceView() {
- propertiesFile = new JTextField();
+ propertiesFile = CayenneWidgetFactory.createUndoableTextField();
// assemble
FormLayout layout = new FormLayout("right:80dlu, 3dlu, fill:200dlu", "");
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java Mon Oct 5 18:40:25 2009
@@ -26,6 +26,8 @@
import javax.swing.JPasswordField;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
@@ -49,12 +51,12 @@
public JDBCDataSourceView() {
- driver = new JTextField();
- url = new JTextField();
- userName = new JTextField();
+ driver = CayenneWidgetFactory.createUndoableTextField();
+ url = CayenneWidgetFactory.createUndoableTextField();
+ userName = CayenneWidgetFactory.createUndoableTextField();
password = new JPasswordField();
- minConnections = new JTextField(6);
- maxConnections = new JTextField(6);
+ minConnections = CayenneWidgetFactory.createUndoableTextField(6);
+ maxConnections = CayenneWidgetFactory.createUndoableTextField(6);
syncWithLocal = new JButton("Sync with Local");
syncWithLocal.setToolTipText("Update from local DataSource");
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JNDIDataSourceView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JNDIDataSourceView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JNDIDataSourceView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JNDIDataSourceView.java Mon Oct 5 18:40:25 2009
@@ -24,6 +24,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
@@ -35,7 +37,7 @@
public JNDIDataSourceView() {
- jndiPath = new JTextField();
+ jndiPath = CayenneWidgetFactory.createUndoableTextField();
// assemble
FormLayout layout = new FormLayout("right:80dlu, 3dlu, fill:200dlu", "");
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeView.java Mon Oct 5 18:40:25 2009
@@ -29,6 +29,8 @@
import javax.swing.JPanel;
import javax.swing.JTextField;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
@@ -49,11 +51,12 @@
public MainDataNodeView() {
// create widgets
- this.dataNodeName = new JTextField();
- this.factories = new JComboBox();
- this.localDataSources = new JComboBox();
+ this.dataNodeName = CayenneWidgetFactory.createUndoableTextField();
+ this.factories = CayenneWidgetFactory.createUndoableComboBox();
+
+ this.localDataSources = CayenneWidgetFactory.createUndoableComboBox();
- this.schemaUpdateStrategy = new JComboBox();
+ this.schemaUpdateStrategy = CayenneWidgetFactory.createUndoableComboBox();
this.dataSourceDetailLayout = new CardLayout();
this.dataSourceDetail = new JPanel(dataSourceDetailLayout);
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java?rev=821956&r1=821955&r2=821956&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java Mon Oct 5 18:40:25 2009
@@ -88,10 +88,10 @@
public PasswordEncoderView(){
- this.passwordEncoder = new JComboBox();
- this.passwordLocation = new JComboBox();
- this.passwordSource = new JTextField();
- this.passwordKey = new JTextField();
+ this.passwordEncoder = CayenneWidgetFactory.createUndoableComboBox();
+ this.passwordLocation = CayenneWidgetFactory.createUndoableComboBox();
+ this.passwordSource = CayenneWidgetFactory.createUndoableTextField();
+ this.passwordKey = CayenneWidgetFactory.createUndoableTextField();
@@ -99,7 +99,7 @@
passwordEncoder.setModel(new DefaultComboBoxModel(PasswordEncoding.standardEncoders));
passwordEncoder.setEditable(true);
- passwordLocation = CayenneWidgetFactory.createComboBox();
+ passwordLocation = CayenneWidgetFactory.createUndoableComboBox();
passwordLocation.setRenderer(new PasswordLocationRenderer());
DefaultComboBoxModel passwordLocationModel = new DefaultComboBoxModel(PASSWORD_LOCATIONS);
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/AddPrefetchUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/AddPrefetchUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/AddPrefetchUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/AddPrefetchUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,54 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.AbstractUndoableEdit;
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.modeler.editor.SelectQueryPrefetchTab;
+
+public class AddPrefetchUndoableEdit extends AbstractUndoableEdit {
+
+
+
+ private String prefetch;
+ private SelectQueryPrefetchTab tab;
+
+ public AddPrefetchUndoableEdit(String prefetch, SelectQueryPrefetchTab tab) {
+ super();
+ this.prefetch = prefetch;
+ this.tab = tab;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Add Prefetch";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ tab.addPrefetch(prefetch);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ tab.removePrefetch(prefetch);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneCompoundEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneCompoundEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneCompoundEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneCompoundEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,40 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CompoundEdit;
+
+public class CayenneCompoundEdit extends CompoundEdit {
+
+
+
+ public boolean hasEdits() {
+ return edits.size() > 0;
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public boolean isInProgress() {
+ return false;
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneTableModelUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneTableModelUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneTableModelUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneTableModelUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,69 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.AbstractUndoableEdit;
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.modeler.util.CayenneTableModel;
+
+public class CayenneTableModelUndoableEdit extends AbstractUndoableEdit {
+
+
+
+ private CayenneTableModel model;
+ private Object oldValue;
+ private Object newValue;
+ private int row;
+ private int col;
+
+ @Override
+ public String getPresentationName() {
+ return (newValue != null) ? newValue.toString() : "";
+ }
+
+ public CayenneTableModelUndoableEdit(CayenneTableModel model, Object oldValue, Object newValue,
+ int row, int col) {
+
+ this.model = model;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ this.row = row;
+ this.col = col;
+
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ model.setUpdatedValueAt(newValue, row, col);
+ model.fireTableCellUpdated(row, col);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ model.setUpdatedValueAt(oldValue, row, col);
+ model.fireTableCellUpdated(row, col);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,81 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+import javax.swing.undo.UndoableEdit;
+
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.action.RedoAction;
+import org.apache.cayenne.modeler.action.UndoAction;
+import org.apache.cayenne.modeler.util.CayenneAction;
+
+public class CayenneUndoManager extends javax.swing.undo.UndoManager {
+
+
+
+ private Application application;
+
+ public CayenneUndoManager(Application application) {
+ this.application = application;
+ setLimit(100);
+ }
+
+
+ @Override
+ public synchronized void discardAllEdits() {
+ super.discardAllEdits();
+ updateUI();
+ }
+
+ @Override
+ public synchronized boolean addEdit(UndoableEdit anEdit) {
+ boolean result = super.addEdit(anEdit);
+ updateUI();
+ return result;
+ }
+
+ @Override
+ public synchronized void redo() throws CannotRedoException {
+ super.redo();
+ updateUI();
+ }
+
+
+ @Override
+ public synchronized void undo() throws CannotUndoException {
+ super.undo();
+ updateUI();
+ }
+
+ private void updateUI() {
+ CayenneAction undoAction = application.getActionManager().getAction(
+ UndoAction.getActionName());
+
+ CayenneAction redoAction = application.getActionManager().getAction(
+ RedoAction.getActionName());
+
+ undoAction.setEnabled(canUndo());
+ redoAction.setEnabled(canRedo());
+
+ undoAction.setName(getUndoPresentationName());
+ redoAction.setName(getRedoPresentationName());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,56 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.tree.TreePath;
+import javax.swing.undo.AbstractUndoableEdit;
+
+import org.apache.cayenne.modeler.ActionManager;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.ProjectTreeView;
+
+public abstract class CayenneUndoableEdit extends AbstractUndoableEdit {
+
+
+ protected ProjectTreeView treeView;
+ protected ActionManager actionManager;
+ protected ProjectController controller;
+
+ private TreePath[] paths;
+
+
+ public CayenneUndoableEdit() {
+ this.treeView = ((CayenneModelerFrame) Application.getInstance()
+ .getFrameController().getView()).getView().getProjectTreeView();
+ this.actionManager = Application.getInstance().getActionManager();
+ this.paths = this.treeView.getSelectionPaths();
+ this.controller = Application.getInstance().getFrameController().getProjectController();
+ }
+
+ protected void restoreSelections() {
+ this.treeView.setSelectionPaths(paths);
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateAttributeUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateAttributeUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateAttributeUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateAttributeUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,119 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.action.CreateAttributeAction;
+import org.apache.cayenne.modeler.action.RemoveAttributeAction;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+
+public class CreateAttributeUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+
+
+ @Override
+ public String getPresentationName() {
+ return "Create Attribute";
+ }
+
+ private ObjEntity objEntity;
+ private ObjAttribute objAttr;
+
+ private DataDomain domain;
+ private DataMap dataMap;
+
+ private DbEntity dbEntity;
+ private DbAttribute dbAttr;
+
+ @Override
+ public void redo() throws CannotRedoException {
+ restoreSelections();
+
+ CreateAttributeAction action = (CreateAttributeAction) actionManager
+ .getAction(CreateAttributeAction.getActionName());
+
+ if (objEntity != null) {
+ action.createObjAttribute(domain, dataMap, objEntity, objAttr);
+ }
+
+ if (dbEntity != null) {
+ action.createDbAttribute(domain, dataMap, dbEntity, dbAttr);
+ }
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ restoreSelections();
+
+ RemoveAttributeAction action = (RemoveAttributeAction) actionManager
+ .getAction(RemoveAttributeAction.getActionName());
+
+ if (objEntity != null) {
+ action.removeObjAttributes(objEntity,
+ new ObjAttribute[] { objAttr });
+
+ controller.fireObjEntityDisplayEvent(new EntityDisplayEvent(
+ this,
+ objEntity,
+ dataMap,
+ domain));
+ }
+
+ if (dbEntity != null) {
+ action.removeDbAttributes(dataMap, dbEntity,
+ new DbAttribute[] { dbAttr });
+
+ controller.fireDbEntityDisplayEvent(new EntityDisplayEvent(
+ this,
+ dbEntity,
+ dataMap,
+ domain));
+ }
+ }
+
+ public CreateAttributeUndoableEdit(DataDomain domain, DataMap map,
+ ObjEntity objEntity, ObjAttribute attr) {
+ this.domain = domain;
+ this.dataMap = map;
+ this.objEntity = objEntity;
+ this.objAttr = attr;
+ }
+
+ public CreateAttributeUndoableEdit(DataDomain domain, DataMap map,
+ DbEntity dbEntity, DbAttribute attr) {
+ this.domain = domain;
+ this.dataMap = map;
+ this.dbEntity = dbEntity;
+ this.dbAttr = attr;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateCallbackMethodUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateCallbackMethodUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateCallbackMethodUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateCallbackMethodUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,63 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.CallbackMap;
+import org.apache.cayenne.modeler.action.CreateCallbackMethodAction;
+import org.apache.cayenne.modeler.action.RemoveCallbackMethodAction;
+import org.apache.cayenne.modeler.editor.CallbackType;
+
+public class CreateCallbackMethodUndoableEdit extends CayenneUndoableEdit {
+
+
+
+ private CallbackMap map;
+ private CallbackType callbackType;
+ private String methodName;
+
+ @Override
+ public String getPresentationName() {
+ return "Create Callback Method";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateCallbackMethodAction action = (CreateCallbackMethodAction) actionManager
+ .getAction(CreateCallbackMethodAction.getActionName());
+ action.createCallbackMethod(map, callbackType, methodName);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveCallbackMethodAction action = (RemoveCallbackMethodAction) actionManager
+ .getAction(RemoveCallbackMethodAction.getActionName());
+ action.removeCallbackMethod(map, callbackType, methodName);
+ }
+
+ public CreateCallbackMethodUndoableEdit(CallbackMap map,
+ CallbackType callbackType, String methodName) {
+ this.map = map;
+ this.callbackType = callbackType;
+ this.methodName = methodName;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,62 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.action.CreateDataMapAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+import org.apache.cayenne.modeler.event.DomainDisplayEvent;
+
+public class CreateDataMapUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public String getPresentationName() {
+ return "Create DataMap";
+ }
+
+
+
+ private DataDomain domain;
+ private DataMap map;
+
+ public CreateDataMapUndoableEdit(DataDomain domain, DataMap map) {
+ this.domain = domain;
+ this.map = map;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateDataMapAction action = (CreateDataMapAction) actionManager
+ .getAction(CreateDataMapAction.getActionName());
+ action.createDataMap(domain, map);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction.getActionName());
+
+ controller.fireDomainDisplayEvent(new DomainDisplayEvent(this, domain));
+
+ action.removeDataMap(domain, map);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDbEntityUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDbEntityUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDbEntityUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDbEntityUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,64 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.modeler.action.CreateDbEntityAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateDbEntityUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create DbEntity";
+ }
+
+
+
+ private DataMap map;
+ private DbEntity entity;
+
+ public CreateDbEntityUndoableEdit(DataMap map, DbEntity entity) {
+ this.map = map;
+ this.entity = entity;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateDbEntityAction action = (CreateDbEntityAction) actionManager
+ .getAction(CreateDbEntityAction.getActionName());
+ action.createEntity(map, entity);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+ action.removeDbEntity(map, entity);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDomainUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDomainUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDomainUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDomainUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,56 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.modeler.action.CreateDomainAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateDomainUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public String getPresentationName() {
+ return "Create DataDomain";
+ }
+
+
+
+ private DataDomain domain;
+
+ public CreateDomainUndoableEdit(DataDomain domain) {
+ this.domain = domain;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateDomainAction action = (CreateDomainAction) actionManager
+ .getAction(CreateDomainAction.getActionName());
+ action.createDomain(domain);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+ action.removeDomain(domain);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbAttributeUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbAttributeUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbAttributeUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbAttributeUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,61 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.EmbeddableAttribute;
+import org.apache.cayenne.modeler.action.CreateAttributeAction;
+import org.apache.cayenne.modeler.action.RemoveAttributeAction;
+
+public class CreateEmbAttributeUndoableEdit extends CayenneUndoableEdit {
+
+ private Embeddable embeddable;
+ private EmbeddableAttribute[] attrs;
+
+ public CreateEmbAttributeUndoableEdit(Embeddable embeddable,
+ EmbeddableAttribute[] attr) {
+ super();
+ this.embeddable = embeddable;
+ this.attrs = attr;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create Embeddable Attribute";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateAttributeAction action = (CreateAttributeAction) actionManager
+ .getAction(CreateAttributeAction.getActionName());
+ for (EmbeddableAttribute attr : attrs) {
+ action.createEmbAttribute(embeddable, attr);
+ }
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAttributeAction action = (RemoveAttributeAction) actionManager
+ .getAction(RemoveAttributeAction.getActionName());
+ action.removeEmbeddableAttributes(embeddable, attrs);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbeddableUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbeddableUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbeddableUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEmbeddableUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,59 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.modeler.action.CreateEmbeddableAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateEmbeddableUndoableEdit extends CayenneUndoableEdit {
+
+ private DataMap dataMap;
+ private Embeddable embeddable;
+
+ public CreateEmbeddableUndoableEdit(DataMap dataMap, Embeddable embeddable) {
+ this.dataMap = dataMap;
+ this.embeddable = embeddable;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create Embeddable";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateEmbeddableAction action = (CreateEmbeddableAction) actionManager
+ .getAction(CreateEmbeddableAction.getActionName());
+
+ action.createEmbeddable(dataMap, embeddable);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+ action.removeEmbeddable(dataMap, embeddable);
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEntityListenerUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEntityListenerUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEntityListenerUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateEntityListenerUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,59 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.EntityListener;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.action.CreateDataMapEntityListenerAction;
+import org.apache.cayenne.modeler.action.RemoveEntityListenerAction;
+
+public class CreateEntityListenerUndoableEdit extends CayenneUndoableEdit {
+
+
+ private ObjEntity objEntity;
+ private EntityListener listener;
+
+ public CreateEntityListenerUndoableEdit(ObjEntity objEntity, EntityListener listener) {
+ this.objEntity = objEntity;
+ this.listener = listener;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create Entity Listener";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateDataMapEntityListenerAction action = (CreateDataMapEntityListenerAction) actionManager
+ .getAction(CreateDataMapEntityListenerAction.getActionName());
+ action.createEntityListener(objEntity, listener);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveEntityListenerAction action = (RemoveEntityListenerAction) actionManager
+ .getAction(RemoveEntityListenerAction.getActionName());
+
+ action.removeEntityListener(objEntity, listener.getClassName());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateNodeUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateNodeUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateNodeUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateNodeUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,62 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.action.CreateNodeAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateNodeUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public String getPresentationName() {
+ return "Create DataNode";
+ }
+
+
+
+ private DataNode node;
+ private DataDomain domain;
+
+ public CreateNodeUndoableEdit(Application application, DataDomain domain,
+ DataNode node) {
+ this.domain = domain;
+ this.node = node;
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+ action.removeDataNode(domain, node);
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ domain.addNode(node);
+ CreateNodeAction action = (CreateNodeAction) actionManager
+ .getAction(CreateNodeAction.getActionName());
+ action.createDataNode(domain, node);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateObjEntityUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateObjEntityUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateObjEntityUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateObjEntityUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,67 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.action.CreateObjEntityAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateObjEntityUndoableEdit extends CayenneUndoableEdit {
+
+
+
+ private DataMap map;
+ private ObjEntity objEntity;
+
+ public CreateObjEntityUndoableEdit(DataMap map, ObjEntity objEntity) {
+ this.map = map;
+ this.objEntity = objEntity;
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create ObjEntity";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateObjEntityAction action = (CreateObjEntityAction) actionManager
+ .getAction(CreateObjEntityAction.getActionName());
+
+ action.createObjEntity(map, objEntity);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+
+ action.removeObjEntity(map, objEntity);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateProcedureUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateProcedureUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateProcedureUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateProcedureUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,59 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Procedure;
+import org.apache.cayenne.modeler.action.CreateProcedureAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+
+public class CreateProcedureUndoableEdit extends CayenneUndoableEdit {
+
+
+
+ private DataMap map;
+ private Procedure procedure;
+
+ public CreateProcedureUndoableEdit(DataMap map, Procedure procedure) {
+ this.map = map;
+ this.procedure = procedure;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create Stored Procedure";
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateProcedureAction action = (CreateProcedureAction) actionManager
+ .getAction(CreateProcedureAction.getActionName());
+ action.createProcedure(map, procedure);
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+ action.removeProcedure(map, procedure);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateQueryUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateQueryUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateQueryUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateQueryUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,65 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.modeler.action.CreateQueryAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+import org.apache.cayenne.query.Query;
+
+public class CreateQueryUndoableEdit extends CayenneUndoableEdit {
+
+
+
+ private DataDomain domain;
+ private DataMap map;
+ private Query query;
+
+ public CreateQueryUndoableEdit(DataDomain domain, DataMap map, Query query) {
+ this.domain = domain;
+ this.map = map;
+ this.query = query;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateQueryAction action = (CreateQueryAction) actionManager
+ .getAction(CreateQueryAction.getActionName());
+ action.createQuery(domain, map, query);
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Create Query";
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+
+ RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction
+ .getActionName());
+
+ action.removeQuery(map, query);
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateRelationshipUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateRelationshipUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateRelationshipUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateRelationshipUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,95 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.modeler.action.CreateRelationshipAction;
+import org.apache.cayenne.modeler.action.RemoveRelationshipAction;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+
+public class CreateRelationshipUndoableEdit extends CayenneUndoableEdit {
+
+ @Override
+ public String getPresentationName() {
+ return "Create Relationship";
+ }
+
+
+
+ private ObjEntity objEnt;
+ private ObjRelationship[] objectRel;
+
+ private DbEntity dbEnt;
+ private DbRelationship[] dbRel;
+
+ public CreateRelationshipUndoableEdit(ObjEntity objEnt, ObjRelationship[] objectRel) {
+ this.objEnt = objEnt;
+ this.objectRel = objectRel;
+ }
+
+ public CreateRelationshipUndoableEdit(DbEntity dbEnt, DbRelationship[] dbRel) {
+ this.dbEnt = dbEnt;
+ this.dbRel = dbRel;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ CreateRelationshipAction action = (CreateRelationshipAction) actionManager
+ .getAction(CreateRelationshipAction.getActionName());
+
+ if (objEnt != null) {
+ for (ObjRelationship rel : objectRel) {
+ action.createObjRelationship(objEnt, rel);
+ }
+ }
+
+ if (dbEnt != null) {
+ for (DbRelationship rel : dbRel) {
+ action.createDbRelationship(dbEnt, rel);
+ }
+ }
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ RemoveRelationshipAction action = (RemoveRelationshipAction) actionManager
+ .getAction(RemoveRelationshipAction.getActionName());
+
+ if (objEnt != null) {
+ action.removeObjRelationships(objEnt, objectRel);
+ controller.fireObjEntityDisplayEvent(new EntityDisplayEvent(
+ this,
+ objEnt,
+ objEnt.getDataMap(),
+ controller.getCurrentDataDomain()));
+ }
+
+ if (dbEnt != null) {
+ action.removeDbRelationships(dbEnt, dbRel);
+ controller.fireDbEntityDisplayEvent(new EntityDisplayEvent(this, dbEnt, dbEnt
+ .getDataMap(), controller.getCurrentDataDomain()));
+ }
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/InferRelationshipsUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/InferRelationshipsUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/InferRelationshipsUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/InferRelationshipsUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,39 @@
+/*****************************************************************
+ * 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.undo;
+
+
+public class InferRelationshipsUndoableEdit extends CayenneCompoundEdit {
+
+
+ @Override
+ public String getPresentationName() {
+ return "InferRelationships";
+ }
+
+ @Override
+ public String getRedoPresentationName() {
+ return "Redo InferRelationships";
+ }
+
+ @Override
+ public String getUndoPresentationName() {
+ return "Undo InferRelationships";
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java Mon Oct 5 18:40:25 2009
@@ -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
+ *
+ * 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.undo;
+
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.JComboBox;
+import javax.swing.undo.UndoManager;
+
+import org.apache.cayenne.modeler.Application;
+
+public class JComboBoxUndoListener implements ItemListener {
+
+ private Object deselectedItem;
+
+ public void itemStateChanged(ItemEvent e) {
+ int stateChange = e.getStateChange();
+
+ switch (stateChange) {
+ case ItemEvent.DESELECTED:
+ deselectedItem = e.getItem();
+ break;
+ case ItemEvent.SELECTED:
+
+ UndoManager undoManager = Application.getInstance().getUndoManager();
+ undoManager.addEdit(new JComboBoxUndoableEdit(
+ (JComboBox) e.getSource(),
+ deselectedItem,
+ e.getItem(),
+ this));
+
+ break;
+ }
+
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,78 @@
+/*****************************************************************
+ * 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.undo;
+
+import java.awt.event.ItemListener;
+
+import javax.swing.JComboBox;
+import javax.swing.undo.AbstractUndoableEdit;
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+public class JComboBoxUndoableEdit extends AbstractUndoableEdit {
+
+
+
+ private JComboBox comboBox;
+ private Object deselectedItem;
+ private Object selectedItem;
+ private ItemListener undoItemListener;
+
+ public JComboBoxUndoableEdit(JComboBox comboBox, Object deselectedItem,
+ Object selectedItem, ItemListener undoItemListener) {
+ super();
+ this.comboBox = comboBox;
+ this.deselectedItem = deselectedItem;
+ this.selectedItem = selectedItem;
+ this.undoItemListener = undoItemListener;
+ }
+
+ @Override
+ public String getPresentationName() {
+ return "Selection";
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public void redo() throws CannotRedoException {
+ comboBox.removeItemListener(undoItemListener);
+
+ try {
+ comboBox.setSelectedItem(selectedItem);
+ }
+ finally {
+ comboBox.addItemListener(undoItemListener);
+ }
+ }
+
+ @Override
+ public void undo() throws CannotUndoException {
+ comboBox.removeItemListener(undoItemListener);
+ try {
+ comboBox.setSelectedItem(deselectedItem);
+ }
+ finally {
+ comboBox.addItemListener(undoItemListener);
+ }
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JTextFieldUndoListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JTextFieldUndoListener.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JTextFieldUndoListener.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JTextFieldUndoListener.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,270 @@
+/*****************************************************************
+ * 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.undo;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.SwingUtilities;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.UndoableEditEvent;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.JTextComponent;
+import javax.swing.tree.TreePath;
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+import javax.swing.undo.CompoundEdit;
+import javax.swing.undo.UndoManager;
+import javax.swing.undo.UndoableEdit;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+
+public class JTextFieldUndoListener implements UndoableEditListener {
+
+ private UndoManager undoManager;
+ private CompoundEdit compoundEdit;
+ private JTextComponent textComponent;
+ private UndoDocumentListener undoDocumentListener;
+
+ private Object currentObj;
+ private TreePath[] paths;
+
+ private int lastOffset;
+ private int lastLength;
+
+ private JTextFieldUndoListener self = this;
+
+ private boolean inProgress = false;
+
+ private class UndoDocumentListener implements DocumentListener {
+
+ public void changedUpdate(DocumentEvent e) {
+ }
+
+ public void insertUpdate(final DocumentEvent e) {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ int offset = e.getOffset() + e.getLength();
+ offset = Math.min(offset, textComponent.getDocument()
+ .getLength());
+ textComponent.setCaretPosition(offset);
+ }
+ });
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ textComponent.setCaretPosition(e.getOffset());
+ }
+
+ }
+
+ public JTextFieldUndoListener(JTextComponent textComponent) {
+ this.textComponent = textComponent;
+ this.undoManager = Application.getInstance().getUndoManager();
+ this.undoDocumentListener = new UndoDocumentListener();
+
+ this.textComponent.addFocusListener(new FocusListener() {
+
+ public void focusGained(FocusEvent e) {
+ if (self.currentObj == null) {
+ self.currentObj = getProjectController().getCurrentObject();
+ self.paths = ((CayenneModelerFrame) Application
+ .getInstance().getFrameController().getView())
+ .getView().getProjectTreeView().getSelectionPaths();
+ }
+ }
+
+ public void focusLost(FocusEvent e) {
+ self.currentObj = null;
+
+ if (compoundEdit != null) {
+ compoundEdit.end();
+ compoundEdit = null;
+ }
+ }
+
+ });
+
+ this.textComponent.addKeyListener(new KeyListener() {
+
+ public void keyPressed(KeyEvent e) {
+ inProgress = true;
+ }
+
+ public void keyReleased(KeyEvent e) {
+ }
+
+ public void keyTyped(KeyEvent e) {
+ }
+
+ });
+
+ }
+
+ public void undoableEditHappened(UndoableEditEvent e) {
+ if (inProgress) {
+ if (compoundEdit == null) {
+ compoundEdit = startCompoundEdit(e.getEdit());
+ } else {
+ AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e
+ .getEdit();
+
+ if (event.getType().equals(DocumentEvent.EventType.CHANGE)) {
+ compoundEdit.addEdit(e.getEdit());
+ return;
+ }
+
+ int offsetChange = textComponent.getCaretPosition()
+ - lastOffset;
+ int lengthChange = textComponent.getDocument().getLength()
+ - lastLength;
+
+ if (offsetChange == lengthChange && Math.abs(offsetChange) == 1) {
+ compoundEdit.addEdit(e.getEdit());
+ lastOffset = textComponent.getCaretPosition();
+ lastLength = textComponent.getDocument().getLength();
+ return;
+ } else {
+ compoundEdit.end();
+ compoundEdit = startCompoundEdit(e.getEdit());
+ }
+ }
+
+ inProgress = !inProgress;
+ }
+ }
+
+ private CompoundEdit startCompoundEdit(UndoableEdit e) {
+ lastOffset = textComponent.getCaretPosition();
+ lastLength = textComponent.getDocument().getLength();
+
+ CompoundEdit compoundEdit = new TextCompoundEdit();
+ compoundEdit.addEdit(e);
+
+ undoManager.addEdit(compoundEdit);
+
+ return compoundEdit;
+ }
+
+ private class TextCompoundEdit extends CompoundEdit {
+
+
+ public boolean isInProgress() {
+ return false;
+ }
+
+ @Override
+ public String getRedoPresentationName() {
+ return "Redo Text Change";
+ }
+
+ @Override
+ public String getUndoPresentationName() {
+ return "Undo Text Change";
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ public void undo() throws CannotUndoException {
+ textComponent.getDocument().addDocumentListener(
+ undoDocumentListener);
+
+ if (compoundEdit != null) {
+ compoundEdit.end();
+ }
+
+ restoreSelections();
+
+ super.undo();
+
+ compoundEdit = null;
+
+ textComponent.getDocument().removeDocumentListener(
+ undoDocumentListener);
+
+ textComponent.requestFocusInWindow();
+ textComponent.selectAll();
+ }
+
+ public void redo() throws CannotRedoException {
+ textComponent.getDocument().addDocumentListener(
+ undoDocumentListener);
+
+ super.redo();
+
+ textComponent.getDocument().removeDocumentListener(
+ undoDocumentListener);
+ textComponent.requestFocusInWindow();
+ }
+
+ private void restoreSelections() {
+ ((CayenneModelerFrame) Application.getInstance()
+ .getFrameController().getView()).getView()
+ .getProjectTreeView().setSelectionPaths(self.paths);
+
+ if (self.currentObj instanceof DataMap) {
+
+ getProjectController().fireDataMapDisplayEvent(
+ new DataMapDisplayEvent(this,
+ (DataMap) self.currentObj,
+ getProjectController().getCurrentDataDomain(),
+ getProjectController().getCurrentDataNode()));
+
+ } else if (self.currentObj instanceof ObjEntity) {
+
+ getProjectController().fireObjEntityDisplayEvent(
+ new EntityDisplayEvent(this,
+ (ObjEntity) self.currentObj,
+ getProjectController().getCurrentDataMap(),
+ getProjectController().getCurrentDataNode(),
+ getProjectController().getCurrentDataDomain()));
+
+ } else if (self.currentObj instanceof DbEntity) {
+
+ getProjectController().fireDbEntityDisplayEvent(
+ new EntityDisplayEvent(this, (DbEntity) self.currentObj,
+ getProjectController().getCurrentDataMap(),
+ getProjectController().getCurrentDataNode(),
+ getProjectController().getCurrentDataDomain()));
+
+
+ }
+ }
+ }
+
+ private ProjectController getProjectController() {
+ return Application.getInstance().getFrameController()
+ .getProjectController();
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteCompoundUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteCompoundUndoableEdit.java?rev=821956&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteCompoundUndoableEdit.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteCompoundUndoableEdit.java Mon Oct 5 18:40:25 2009
@@ -0,0 +1,35 @@
+/*****************************************************************
+ * 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.undo;
+
+import javax.swing.undo.CompoundEdit;
+
+public class PasteCompoundUndoableEdit extends CompoundEdit {
+
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
+ @Override
+ public boolean isInProgress() {
+ return false;
+ }
+}