1 56 package org.objectstyle.cayenne.modeler.action; 57 58 import java.awt.event.ActionEvent ; 59 import java.util.Collection ; 60 61 import org.objectstyle.cayenne.map.DataMap; 62 import org.objectstyle.cayenne.map.DbEntity; 63 import org.objectstyle.cayenne.map.event.EntityEvent; 64 import org.objectstyle.cayenne.modeler.Application; 65 import org.objectstyle.cayenne.modeler.ProjectController; 66 import org.objectstyle.cayenne.modeler.util.CayenneAction; 67 import org.objectstyle.cayenne.project.ProjectPath; 68 import org.objectstyle.cayenne.util.EntityMergeSupport; 69 70 76 public class DbEntitySyncAction extends CayenneAction { 77 78 public static String getActionName() { 79 return "Sync Dependent ObjEntities with DbEntity"; 80 } 81 82 public DbEntitySyncAction(Application application) { 83 super(getActionName(), application); 84 } 85 86 public String getIconName() { 87 return "icon-sync.gif"; 88 } 89 90 93 public void performAction(ActionEvent e) { 94 synchDbEntity(); 95 } 96 97 protected void synchDbEntity() { 98 ProjectController mediator = getProjectController(); 99 DataMap map = mediator.getCurrentDataMap(); 100 DbEntity ent = mediator.getCurrentDbEntity(); 101 102 if (map != null && ent != null) { 103 EntityMergeSupport merger = new EntityMergeSupport(map); 104 Collection objEntities = map.getMappedEntities(ent); 105 merger.synchronizeWithDbEntities(objEntities); 106 107 mediator.fireObjEntityEvent( 110 new EntityEvent(this, ent, EntityEvent.REMOVE)); 111 112 mediator.fireObjEntityEvent( 113 new EntityEvent(this, ent, EntityEvent.ADD)); 114 } 115 } 116 117 120 public boolean enableForPath(ProjectPath path) { 121 if (path == null) { 122 return false; 123 } 124 125 return path.firstInstanceOf(DbEntity.class) != null; 126 } 127 } 128 | Popular Tags |