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