Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/PasteUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,156 @@ +/***************************************************************** + * 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.map.DataMap; +import org.apache.cayenne.map.DbAttribute; +import org.apache.cayenne.map.DbEntity; +import org.apache.cayenne.map.DbRelationship; +import org.apache.cayenne.map.ObjAttribute; +import org.apache.cayenne.map.ObjEntity; +import org.apache.cayenne.map.ObjRelationship; +import org.apache.cayenne.map.Procedure; +import org.apache.cayenne.map.ProcedureParameter; +import org.apache.cayenne.modeler.action.PasteAction; +import org.apache.cayenne.modeler.action.RemoveAction; +import org.apache.cayenne.modeler.action.RemoveAttributeAction; +import org.apache.cayenne.modeler.action.RemoveProcedureParameterAction; +import org.apache.cayenne.modeler.action.RemoveRelationshipAction; +import org.apache.cayenne.query.Query; + +public class PasteUndoableEdit extends CayenneUndoableEdit { + + + + private DataDomain domain; + private DataMap map; + private Object where; + private Object content; + + public PasteUndoableEdit(DataDomain domain, DataMap map, Object where, Object content) { + this.domain = domain; + this.map = map; + this.where = where; + this.content = content; + } + + @Override + public String getPresentationName() { + + String className = this.content.getClass().getName(); + int pos = className.lastIndexOf("."); + String contentName = className.substring(pos + 1); + + return "Paste " + contentName; + } + + @Override + public void redo() throws CannotRedoException { + PasteAction action = (PasteAction) actionManager.getAction(PasteAction + .getActionName()); + + action.paste(where, content, domain, map); + } + + @Override + public void undo() throws CannotUndoException { + RemoveAttributeAction rAttributeAction = (RemoveAttributeAction) actionManager + .getAction(RemoveAttributeAction.getActionName()); + + RemoveAction rAction = (RemoveAction) actionManager.getAction(RemoveAction + .getActionName()); + + RemoveRelationshipAction rRelationShipAction = (RemoveRelationshipAction) actionManager + .getAction(RemoveRelationshipAction.getActionName()); + + RemoveProcedureParameterAction rProcedureParamAction = (RemoveProcedureParameterAction) actionManager + .getAction(RemoveProcedureParameterAction.getActionName()); + + if (content instanceof DataMap) { + if (where instanceof DataDomain) { + rAction.removeDataMap((DataDomain) where, (DataMap) content); + } + else if (where instanceof DataNode) { + rAction.removeDataMapFromDataNode((DataNode) where, (DataMap) content); + } + } + else if (where instanceof DataMap) { + if (content instanceof DbEntity) { + rAction.removeDbEntity(map, (DbEntity) content); + } + else if (content instanceof ObjEntity) { + rAction.removeObjEntity(map, (ObjEntity) content); + } + else if (content instanceof Query) { + rAction.removeQuery(map, (Query) content); + } + else if (content instanceof Procedure) { + rAction.removeProcedure(map, (Procedure) content); + } + } + else if (where instanceof DbEntity) { + if (content instanceof DbAttribute) { + rAttributeAction.removeDbAttributes( + map, + (DbEntity) where, + new DbAttribute[] { + (DbAttribute) content + }); + } + else if (content instanceof DbRelationship) { + rRelationShipAction.removeDbRelationships( + (DbEntity) where, + new DbRelationship[] { + (DbRelationship) content + }); + } + } + else if (where instanceof ObjEntity) { + if (content instanceof ObjAttribute) { + rAttributeAction.removeObjAttributes( + (ObjEntity) where, + new ObjAttribute[] { + (ObjAttribute) content + }); + } + else if (content instanceof ObjRelationship) { + rRelationShipAction.removeObjRelationships( + (ObjEntity) where, + new ObjRelationship[] { + (ObjRelationship) content + }); + } + } + else if (where instanceof Procedure) { + final Procedure procedure = (Procedure) where; + if (content instanceof ProcedureParameter) { + rProcedureParamAction.removeProcedureParameters( + procedure, + new ProcedureParameter[] { + (ProcedureParameter) content + }); + } + } + } +}
Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RelationshipUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RelationshipUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RelationshipUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RelationshipUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,129 @@ +/***************************************************************** + * 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.map.DbJoin; +import org.apache.cayenne.map.DbRelationship; +import org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog; +import org.apache.cayenne.modeler.util.ProjectUtil; + +public class RelationshipUndoableEdit extends CayenneCompoundEdit { + + @Override + public void redo() throws CannotRedoException { + super.redo(); + + ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog( + relationship, false); + + dialog.setVisible(true); + } + + @Override + public void undo() throws CannotUndoException { + super.undo(); + + ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog( + relationship, false); + + dialog.setVisible(true); + } + + @Override + public String getRedoPresentationName() { + return "Redo Edit relationship"; + } + + @Override + public String getUndoPresentationName() { + return "Undo Edit relationship"; + } + + + + private DbRelationship relationship; + + @Override + public boolean canUndo() { + return hasEdits(); + } + + public RelationshipUndoableEdit(DbRelationship relationship) { + this.relationship = relationship; + } + + public void addDbJoinAddUndo(final DbJoin join) { + this.addEdit(new AbstractUndoableEdit() { + + + @Override + public void redo() throws CannotRedoException { + relationship.addJoin(join); + } + + @Override + public void undo() throws CannotUndoException { + relationship.removeJoin(join); + } + }); + } + + public void addDbJoinRemoveUndo(final DbJoin join) { + this.addEdit(new AbstractUndoableEdit() { + + + + @Override + public void redo() throws CannotRedoException { + relationship.removeJoin(join); + } + + @Override + public void undo() throws CannotUndoException { + relationship.addJoin(join); + } + + }); + } + + public void addNameUndo(final DbRelationship relationship, + final String oldName, final String newName) { + this.addEdit(new AbstractUndoableEdit() { + + + + @Override + public void redo() throws CannotRedoException { + ProjectUtil.setRelationshipName(relationship.getSourceEntity(), + relationship, newName); + } + + @Override + public void undo() throws CannotUndoException { + ProjectUtil.setRelationshipName(relationship.getSourceEntity(), + relationship, oldName); + } + + }); + } +} Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,160 @@ +/***************************************************************** + * 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.Embeddable; +import org.apache.cayenne.map.EmbeddableAttribute; +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.EmbeddableDisplayEvent; +import org.apache.cayenne.modeler.event.EntityDisplayEvent; + +public class RemoveAttributeUndoableEdit extends CayenneUndoableEdit { + + + + private DataDomain domain; + private DataMap dataMap; + + private DbAttribute[] dbAttributes; + private ObjAttribute[] objAttributes; + + private ObjEntity objEntity; + private DbEntity dbEntity; + + private Embeddable embeddable; + private EmbeddableAttribute[] embeddableAttrs; + + public RemoveAttributeUndoableEdit(Embeddable embeddable, + EmbeddableAttribute[] embeddableAttrs) { + super(); + this.embeddable = embeddable; + this.embeddableAttrs = embeddableAttrs; + } + + public RemoveAttributeUndoableEdit(DataDomain domain, DataMap dataMap, + ObjEntity entity, ObjAttribute[] attribs) { + this.objEntity = entity; + this.objAttributes = attribs; + this.domain = domain; + this.dataMap = dataMap; + } + + public RemoveAttributeUndoableEdit(DataDomain domain, DataMap dataMap, + DbEntity entity, DbAttribute[] attribs) { + this.dbEntity = entity; + this.dbAttributes = attribs; + this.domain = domain; + this.dataMap = dataMap; + } + + @Override + public void redo() throws CannotRedoException { + restoreSelections(); + + RemoveAttributeAction action = (RemoveAttributeAction) actionManager + .getAction(RemoveAttributeAction.getActionName()); + + if (objEntity != null) { + action.removeObjAttributes(objEntity, objAttributes); + controller.fireObjEntityDisplayEvent(new EntityDisplayEvent( + this, + objEntity, + dataMap, + domain)); + } + + if (dbEntity != null) { + action.removeDbAttributes(dbEntity.getDataMap(), dbEntity, dbAttributes); + controller.fireDbEntityDisplayEvent(new EntityDisplayEvent( + this, + dbEntity, + dataMap, + domain)); + } + + if (embeddable != null) { + action.removeEmbeddableAttributes(embeddable, embeddableAttrs); + controller.fireEmbeddableDisplayEvent(new EmbeddableDisplayEvent( + this, + embeddable, + dataMap, + domain)); + } + } + + @Override + public void undo() throws CannotUndoException { + restoreSelections(); + + CreateAttributeAction action = (CreateAttributeAction) actionManager + .getAction(CreateAttributeAction.getActionName()); + + if (objEntity != null) { + for (ObjAttribute attr : objAttributes) { + action.createObjAttribute(domain, dataMap, objEntity, attr); + } + } + + if (dbEntity != null) { + for (DbAttribute attr : dbAttributes) { + action.createDbAttribute(domain, dataMap, dbEntity, attr); + } + } + + if (embeddable != null) { + for (EmbeddableAttribute attr : embeddableAttrs) { + action.createEmbAttribute(embeddable, attr); + } + } + + } + + @Override + public String getPresentationName() { + if (objEntity != null) { + return (objAttributes.length > 1) + ? "Remove ObjAttributes" + : "Remove ObjAttribute"; + } + + if (dbEntity != null) { + return (dbAttributes.length > 1) + ? "Remove DbAttributes" + : "Remove DbAttribute"; + } + + if (embeddableAttrs != null) { + return (embeddableAttrs.length > 1) + ? "Remove Embeddable Attributes" + : "Remove Embeddable Attribute"; + } + + return super.getPresentationName(); + } +} Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveCompoundUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveCompoundUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveCompoundUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveCompoundUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,30 @@ +/***************************************************************** + * 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 RemoveCompoundUndoableEdit extends CayenneCompoundEdit { + + + + @Override + public String getPresentationName() { + return "Remove Objects"; + } +} Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,93 @@ +/***************************************************************** + * 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; + +public class RemoveRelationshipUndoableEdit extends CayenneUndoableEdit { + + + + private ObjEntity objEntity; + private ObjRelationship[] rels; + + private DbEntity dbEntity; + private DbRelationship[] dbRels; + + public RemoveRelationshipUndoableEdit(ObjEntity objEntity, + ObjRelationship[] rels) { + super(); + this.objEntity = objEntity; + this.rels = rels; + } + + public RemoveRelationshipUndoableEdit(DbEntity dbEntity, + DbRelationship[] dbRels) { + super(); + this.dbEntity = dbEntity; + this.dbRels = dbRels; + } + + @Override + public String getPresentationName() { + if (objEntity != null) { + return "Remove Obj Relationship"; + } else { + return "Remove Db Relationship"; + } + } + + @Override + public void redo() throws CannotRedoException { + restoreSelections(); + + RemoveRelationshipAction action = (RemoveRelationshipAction) actionManager + .getAction(RemoveRelationshipAction.getActionName()); + if (objEntity != null) { + action.removeObjRelationships(objEntity, rels); + } else { + action.removeDbRelationships(dbEntity, dbRels); + } + } + + @Override + public void undo() throws CannotUndoException { + restoreSelections(); + + CreateRelationshipAction action = (CreateRelationshipAction) actionManager + .getAction(CreateRelationshipAction.getActionName()); + if (objEntity != null) { + for (ObjRelationship r : rels) { + action.createObjRelationship(objEntity, r); + } + } else { + for (DbRelationship dr : dbRels) { + action.createDbRelationship(dbEntity, dr); + } + } + } +} Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveUndoableEdit.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveUndoableEdit.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveUndoableEdit.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveUndoableEdit.java Mon Oct 5 18:40:25 2009 @@ -0,0 +1,340 @@ +/***************************************************************** + * 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.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +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.map.DataMap; +import org.apache.cayenne.map.DbEntity; +import org.apache.cayenne.map.DbRelationship; +import org.apache.cayenne.map.Embeddable; +import org.apache.cayenne.map.ObjEntity; +import org.apache.cayenne.map.ObjRelationship; +import org.apache.cayenne.map.Procedure; +import org.apache.cayenne.map.Relationship; +import org.apache.cayenne.map.event.DataNodeEvent; +import org.apache.cayenne.modeler.Application; +import org.apache.cayenne.modeler.ProjectController; +import org.apache.cayenne.modeler.action.CreateDataMapAction; +import org.apache.cayenne.modeler.action.CreateDbEntityAction; +import org.apache.cayenne.modeler.action.CreateDomainAction; +import org.apache.cayenne.modeler.action.CreateEmbeddableAction; +import org.apache.cayenne.modeler.action.CreateNodeAction; +import org.apache.cayenne.modeler.action.CreateObjEntityAction; +import org.apache.cayenne.modeler.action.CreateProcedureAction; +import org.apache.cayenne.modeler.action.CreateQueryAction; +import org.apache.cayenne.modeler.action.CreateRelationshipAction; +import org.apache.cayenne.modeler.action.RemoveAction; +import org.apache.cayenne.query.Query; + +public class RemoveUndoableEdit extends CayenneUndoableEdit { + + + + private DataMap map; + private DbEntity dbEntity; + private ObjEntity objEntity; + private Query query; + private Procedure procedure; + + private DataNode dataNode; + private DataDomain domain; + + private Embeddable embeddable; + + private Map<DbEntity, List<DbRelationship>> dbRelationshipMap = new HashMap<DbEntity, List<DbRelationship>>(); + private Map<ObjEntity, List<ObjRelationship>> objRelationshipMap = new HashMap<ObjEntity, List<ObjRelationship>>(); + + private static enum REMOVE_MODE { + OBJECT_ENTITY, DB_ENTITY, QUERY, PROCEDURE, MAP_FROM_NODE, MAP_FROM_DOMAIN, NODE, DOMAIN, EMBEDDABLE + }; + + private REMOVE_MODE mode; + + public RemoveUndoableEdit(Application application, DataDomain domain) { + this.domain = domain; + this.mode = REMOVE_MODE.DOMAIN; + } + + public RemoveUndoableEdit(Application application, DataNode node, DataMap map) { + this.map = map; + this.dataNode = node; + this.mode = REMOVE_MODE.MAP_FROM_NODE; + } + + public RemoveUndoableEdit(Application application, DataDomain domain, DataMap map) { + this.domain = domain; + this.map = map; + this.mode = REMOVE_MODE.MAP_FROM_DOMAIN; + } + + public RemoveUndoableEdit(Application application, DataDomain domain, DataNode node) { + this.domain = domain; + this.dataNode = node; + this.mode = REMOVE_MODE.NODE; + } + + public RemoveUndoableEdit(DataMap map, ObjEntity objEntity) { + this.map = map; + this.objEntity = objEntity; + this.mode = REMOVE_MODE.OBJECT_ENTITY; + + for (ObjEntity ent : map.getObjEntities()) { + // take a copy since we're going to modify the entity + for (Relationship relationship : new ArrayList<Relationship>(ent + .getRelationships())) { + + if (this.objEntity.getName().equals(relationship.getTargetEntityName())) { + + ObjRelationship rel = (ObjRelationship) relationship; + + if (objRelationshipMap.get(rel.getSourceEntity()) == null) { + objRelationshipMap.put( + (ObjEntity) rel.getSourceEntity(), + new LinkedList<ObjRelationship>()); + } + + objRelationshipMap.get(rel.getSourceEntity()).add(rel); + } + } + } + } + + public RemoveUndoableEdit(DataMap map, DbEntity dbEntity) { + this.map = map; + this.dbEntity = dbEntity; + this.mode = REMOVE_MODE.DB_ENTITY; + + for (ObjEntity objEnt : map.getObjEntities()) { + for (Relationship rel : objEnt.getRelationships()) { + for (DbRelationship dbRel : ((ObjRelationship) rel).getDbRelationships()) { + if (dbRel.getTargetEntity() == dbEntity) { + + if (dbRelationshipMap.get(dbRel.getSourceEntity()) == null) { + dbRelationshipMap.put( + (DbEntity) dbRel.getSourceEntity(), + new LinkedList<DbRelationship>()); + } + dbRelationshipMap.get(dbRel.getSourceEntity()).add(dbRel); + + break; + } + } + } + } + } + + public RemoveUndoableEdit(DataMap map, Query query) { + this.map = map; + this.query = query; + this.mode = REMOVE_MODE.QUERY; + } + + public RemoveUndoableEdit(DataMap map, Procedure procedure) { + this.map = map; + this.procedure = procedure; + this.mode = REMOVE_MODE.PROCEDURE; + } + + public RemoveUndoableEdit(DataMap map, Embeddable embeddable) { + this.map = map; + this.embeddable = embeddable; + this.mode = REMOVE_MODE.EMBEDDABLE; + } + + @Override + public String getPresentationName() { + switch (this.mode) { + case OBJECT_ENTITY: + return "Remove Object Entity"; + case DB_ENTITY: + return "Remove Db Entity"; + case QUERY: + return "Remove Query"; + case PROCEDURE: + return "Remove Procedure"; + case MAP_FROM_NODE: + return "Remove DataMap"; + case MAP_FROM_DOMAIN: + return "Remove DataMap"; + case NODE: + return "Remove DataNode"; + case DOMAIN: + return "Remove DataDomain"; + case EMBEDDABLE: + return "Remove Embeddable"; + default: + return "Remove"; + + } + } + + @Override + public void redo() throws CannotRedoException { + RemoveAction action = (RemoveAction) actionManager.getAction(RemoveAction + .getActionName()); + + switch (this.mode) { + case OBJECT_ENTITY: + action.removeObjEntity(map, objEntity); + break; + case DB_ENTITY: + action.removeDbEntity(map, dbEntity); + break; + case QUERY: + action.removeQuery(map, query); + break; + case PROCEDURE: + action.removeProcedure(map, procedure); + case MAP_FROM_NODE: + action.removeDataMapFromDataNode(dataNode, map); + break; + case MAP_FROM_DOMAIN: + action.removeDataMap(domain, map); + break; + case NODE: + action.removeDataNode(domain, dataNode); + break; + case DOMAIN: + action.removeDomain(domain); + break; + case EMBEDDABLE: + action.removeEmbeddable(map, embeddable); + } + } + + @Override + public void undo() throws CannotUndoException { + + CreateRelationshipAction relationshipAction = (CreateRelationshipAction) actionManager + .getAction(CreateRelationshipAction.getActionName()); + + switch (this.mode) { + case OBJECT_ENTITY: { + for (Entry<ObjEntity, List<ObjRelationship>> entry : objRelationshipMap + .entrySet()) { + + ObjEntity objEntity = entry.getKey(); + for (ObjRelationship rel : entry.getValue()) { + relationshipAction.createObjRelationship(objEntity, rel); + } + } + + CreateObjEntityAction action = (CreateObjEntityAction) actionManager + .getAction(CreateObjEntityAction.getActionName()); + action.createObjEntity(map, objEntity); + + break; + } + case DB_ENTITY: { + + for (Entry<DbEntity, List<DbRelationship>> entry : dbRelationshipMap + .entrySet()) { + DbEntity dbEntity = entry.getKey(); + for (DbRelationship rel : entry.getValue()) { + relationshipAction.createDbRelationship(dbEntity, rel); + } + } + + CreateDbEntityAction action = (CreateDbEntityAction) actionManager + .getAction(CreateDbEntityAction.getActionName()); + + action.createEntity(map, dbEntity); + + break; + } + case QUERY: { + this.domain = Application + .getInstance() + .getFrameController() + .getProjectController() + .findDomain(map); + + CreateQueryAction action = (CreateQueryAction) actionManager + .getAction(CreateQueryAction.getActionName()); + + action.createQuery(domain, map, query); + + break; + } + case PROCEDURE: { + CreateProcedureAction action = (CreateProcedureAction) actionManager + .getAction(CreateProcedureAction.getActionName()); + action.createProcedure(map, procedure); + break; + } + case MAP_FROM_NODE: { + this.dataNode.addDataMap(map); + + DataNodeEvent e = new DataNodeEvent(Application.getFrame(), this.dataNode); + + ProjectController controller = Application + .getInstance() + .getFrameController() + .getProjectController(); + + e.setDomain(controller.findDomain(this.dataNode)); + + controller.fireDataNodeEvent(e); + + break; + } + case MAP_FROM_DOMAIN: { + CreateDataMapAction action = (CreateDataMapAction) actionManager + .getAction(CreateDataMapAction.getActionName()); + action.createDataMap(domain, map); + + break; + } + case NODE: { + CreateNodeAction action = (CreateNodeAction) actionManager + .getAction(CreateNodeAction.getActionName()); + action.createDataNode(domain, dataNode); + + break; + } + + case DOMAIN: { + CreateDomainAction action = (CreateDomainAction) actionManager + .getAction(CreateDomainAction.getActionName()); + action.createDomain(domain); + + break; + } + + case EMBEDDABLE: { + CreateEmbeddableAction action = (CreateEmbeddableAction) actionManager + .getAction(CreateEmbeddableAction.getActionName()); + action.createEmbeddable(map, embeddable); + + break; + } + } + } +} Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneTableModel.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneTableModel.java?rev=821956&r1=821955&r2=821956&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneTableModel.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneTableModel.java Mon Oct 5 18:40:25 2009 @@ -34,6 +34,7 @@ import org.apache.cayenne.CayenneRuntimeException; import org.apache.cayenne.modeler.Application; import org.apache.cayenne.modeler.ProjectController; +import org.apache.cayenne.modeler.undo.CayenneTableModelUndoableEdit; import org.apache.cayenne.util.Util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,7 +48,7 @@ protected ProjectController mediator; protected Object eventSource; protected List objectList; - + private static Log logObj = LogFactory.getLog(CayenneTableModel.class); /** @@ -55,6 +56,7 @@ */ public CayenneTableModel(ProjectController mediator, Object eventSource, java.util.List objectList) { + super(); this.eventSource = eventSource; this.mediator = mediator; @@ -65,8 +67,14 @@ public void setValueAt(Object newVal, int row, int col) { try { - if (!Util.nullSafeEquals(newVal, getValueAt(row, col))) { + + Object oldValue = getValueAt(row, col); + if (!Util.nullSafeEquals(newVal, oldValue)) { + setUpdatedValueAt(newVal, row, col); + + this.mediator.getApplication().getUndoManager().addEdit( + new CayenneTableModelUndoableEdit(this, oldValue, newVal, row, col)); } } catch (IllegalArgumentException e) { Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java?rev=821956&r1=821955&r2=821956&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneWidgetFactory.java Mon Oct 5 18:40:25 2009 @@ -17,7 +17,6 @@ * under the License. ****************************************************************/ - package org.apache.cayenne.modeler.util; import java.awt.Color; @@ -38,6 +37,7 @@ import javax.swing.table.TableCellEditor; import org.apache.cayenne.modeler.ModelerPreferences; +import org.apache.cayenne.modeler.undo.JComboBoxUndoListener; import org.apache.cayenne.modeler.util.combo.AutoCompletion; import org.apache.cayenne.modeler.util.combo.ComboBoxCellEditor; import org.apache.cayenne.swing.components.textpane.JCayenneTextPane; @@ -68,7 +68,7 @@ public static JComboBox createComboBox(Collection<String> model, boolean sort) { return createComboBox(model.toArray(), sort); } - + /** * Creates a new JComboBox with an array of model objects. */ @@ -82,7 +82,7 @@ comboBox.setModel(new DefaultComboBoxModel(model)); return comboBox; } - + /** * Creates a new JComboBox. */ @@ -91,17 +91,45 @@ initFormWidget(comboBox); comboBox.setBackground(Color.WHITE); comboBox.setMaximumRowCount(ModelerPreferences.COMBOBOX_MAX_VISIBLE_SIZE); - return comboBox; } + + /** + * Creates undoable JComboBox. + * + */ + public static JComboBox createUndoableComboBox() { + JComboBox comboBox = new JComboBox(); + initFormWidget(comboBox); + comboBox.addItemListener(new JComboBoxUndoListener()); + comboBox.setBackground(Color.WHITE); + comboBox.setMaximumRowCount(ModelerPreferences.COMBOBOX_MAX_VISIBLE_SIZE); + return comboBox; + } + + /** + * Creates undoable JTextField. + * + */ + public static JTextField createUndoableTextField() { + return new JTextFieldUndoable(); + } /** + * Creates undoable JTextField. + * + */ + public static JTextField createUndoableTextField(int size) { + return new JTextFieldUndoable(size); + } + + /** * Creates cell editor for text field */ public static DefaultCellEditor createCellEditor(JTextField textField) { return new CayenneCellEditor(textField); } - + /** * Creates cell editor for a table with combo as editor component. Type of this editor * depends on auto-completion behavior of JComboBox @@ -109,12 +137,13 @@ * @param combo JComboBox to be used as editor component */ public static TableCellEditor createCellEditor(JComboBox combo) { - if (Boolean.TRUE.equals(combo.getClientProperty(AutoCompletion.AUTOCOMPLETION_PROPERTY))) { + if (Boolean.TRUE.equals(combo + .getClientProperty(AutoCompletion.AUTOCOMPLETION_PROPERTY))) { return new ComboBoxCellEditor(combo); } - + DefaultCellEditor editor = new DefaultCellEditor(combo); - editor.setClickCountToStart(1); + editor.setClickCountToStart(1); return editor; } @@ -179,7 +208,7 @@ public static JButton createButton(String text) { return new JButton(text); } - + /** * Creates and returns a JEdit text component with syntax highlighing */ @@ -188,29 +217,29 @@ if (OperatingSystem.getOS() == OperatingSystem.MAC_OS_X) { area.setInputHandler(new MacInputHandler()); } - + return area; } - -// public static JSQLTextPane createJSQLTextPane() { -// JSQLTextPane area = new JSQLTextPane(); -// return area; -// } - + + // public static JSQLTextPane createJSQLTextPane() { + // JSQLTextPane area = new JSQLTextPane(); + // return area; + // } + public static JCayenneTextPane createJEJBQLTextPane() { JCayenneTextPane area = new JCayenneTextPane(new EJBQLSyntaxConstant()); return area; } - - + /** * Class for enabling Mac OS X keys */ private static class MacInputHandler extends DefaultInputHandler { + MacInputHandler() { addDefaultKeyBindings(); } - + /** * Sets up the default key bindings. */ @@ -243,23 +272,23 @@ addKeyBinding("LEFT", PREV_CHAR); addKeyBinding("S+LEFT", SELECT_PREV_CHAR); - addKeyBinding("A+LEFT", PREV_WORD); //option + left - addKeyBinding("AS+LEFT", SELECT_PREV_WORD); //option + shift + left + addKeyBinding("A+LEFT", PREV_WORD); // option + left + addKeyBinding("AS+LEFT", SELECT_PREV_WORD); // option + shift + left addKeyBinding("RIGHT", NEXT_CHAR); addKeyBinding("S+RIGHT", SELECT_NEXT_CHAR); - addKeyBinding("A+RIGHT", NEXT_WORD); //option + right - addKeyBinding("AS+RIGHT", SELECT_NEXT_WORD); //option + shift + right + addKeyBinding("A+RIGHT", NEXT_WORD); // option + right + addKeyBinding("AS+RIGHT", SELECT_NEXT_WORD); // option + shift + right addKeyBinding("UP", PREV_LINE); addKeyBinding("S+UP", SELECT_PREV_LINE); addKeyBinding("DOWN", NEXT_LINE); addKeyBinding("S+DOWN", SELECT_NEXT_LINE); addKeyBinding("M+ENTER", REPEAT); - + // Clipboard - addKeyBinding("M+C", CLIP_COPY); //command + c - addKeyBinding("M+V", CLIP_PASTE); //command + v - addKeyBinding("M+X", CLIP_CUT); //command + x + addKeyBinding("M+C", CLIP_COPY); // command + c + addKeyBinding("M+V", CLIP_PASTE); // command + v + addKeyBinding("M+X", CLIP_CUT); // command + x } } } Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldUndoable.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldUndoable.java?rev=821956&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldUndoable.java (added) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JTextFieldUndoable.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.util; + +import javax.swing.JTextField; +import javax.swing.event.UndoableEditListener; + +import org.apache.cayenne.modeler.undo.JTextFieldUndoListener; + +class JTextFieldUndoable extends JTextField { + + + + private UndoableEditListener undoListener; + + JTextFieldUndoable() { + super(); + this.undoListener = new JTextFieldUndoListener(this); + this.getDocument().addUndoableEditListener(this.undoListener); + } + + JTextFieldUndoable(int size) { + super(size); + this.undoListener = new JTextFieldUndoListener(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); + } + } +} Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java?rev=821956&r1=821955&r2=821956&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/TextAdapter.java Mon Oct 5 18:40:25 2009 @@ -29,9 +29,11 @@ import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.event.UndoableEditListener; import javax.swing.text.JTextComponent; import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog; +import org.apache.cayenne.modeler.undo.JTextFieldUndoListener; import org.apache.cayenne.validation.ValidationException; /** @@ -46,6 +48,7 @@ protected JTextComponent textComponent; protected String defaultToolTip; protected boolean modelUpdateDisabled; + protected UndoableEditListener undoableListener; public TextAdapter(JTextField textField) { this(textField, true, false, true); @@ -53,6 +56,7 @@ public TextAdapter(JTextField textField, boolean checkOnFocusLost, boolean checkOnTyping, boolean checkOnEnter) { + this(textField, true, false); if (checkOnEnter) { @@ -72,10 +76,14 @@ public TextAdapter(JTextComponent textComponent, boolean checkOnFocusLost, boolean checkOnTyping) { + this.errorColor = ValidatorDialog.WARNING_COLOR; this.defaultBGColor = textComponent.getBackground(); this.defaultToolTip = textComponent.getToolTipText(); this.textComponent = textComponent; + + this.undoableListener = new JTextFieldUndoListener(this.textComponent); + this.textComponent.getDocument().addUndoableEditListener(this.undoableListener); if (checkOnFocusLost) { textComponent.setInputVerifier(new InputVerifier() { @@ -129,13 +137,21 @@ */ public void setText(String text) { modelUpdateDisabled = true; + + this.textComponent + .getDocument() + .removeUndoableEditListener(this.undoableListener); + try { clear(); textComponent.setText(text); } finally { modelUpdateDisabled = false; + this.textComponent.getDocument().addUndoableEditListener( + this.undoableListener); } + } protected void updateModel() { Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java?rev=821956&r1=821955&r2=821956&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java Mon Oct 5 18:40:25 2009 @@ -345,7 +345,7 @@ class JTextPaneScrollable extends JTextPane { - private static final long serialVersionUID = 1L; + public JTextPaneScrollable(EditorKit editorKit) { // Set editor kit Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-redo.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-redo.gif?rev=821956&view=auto ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-redo.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-undo.gif URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-undo.gif?rev=821956&view=auto ============================================================================== Binary file - no diff available. Propchange: cayenne/main/trunk/framework/cayenne-modeler/src/main/resources/org/apache/cayenne/modeler/images/icon-undo.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/CreateNodeActionTest.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/CreateNodeActionTest.java?rev=821956&r1=821955&r2=821956&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/CreateNodeActionTest.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/CreateNodeActionTest.java Mon Oct 5 18:40:25 2009 @@ -42,7 +42,7 @@ return; } - DataNode node = action.createDataNode(new DataDomain("DD")); + DataNode node = action.buildDataNode(new DataDomain("DD")); assertNotNull(node); assertNotNull(node.getName());
