1 56 package org.objectstyle.cayenne.modeler.dialog.datamap; 57 58 import java.util.Iterator ; 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.ProjectController; 64 import org.objectstyle.cayenne.util.Util; 65 import org.scopemvc.core.Control; 66 import org.scopemvc.core.ControlException; 67 import org.scopemvc.view.swing.SPanel; 68 69 72 public class SuperclassUpdateController extends DefaultsPreferencesController { 73 74 public static final String ALL_CONTROL = "cayenne.modeler.datamap.defaultprefs.superclass.radio"; 75 public static final String UNINIT_CONTROL = "cayenne.modeler.datamap.defaultprefs.superclassnull.radio"; 76 77 public SuperclassUpdateController(ProjectController mediator, DataMap dataMap) { 78 super(mediator, dataMap); 79 } 80 81 84 public void startup() { 85 SPanel view = new DefaultsPreferencesDialog(ALL_CONTROL, UNINIT_CONTROL); 86 view.setTitle("Update DataObjects Superclass"); 87 setView(view); 88 super.startup(); 89 } 90 91 protected void doHandleControl(Control control) throws ControlException { 92 if (control.matchesID(UPDATE_CONTROL)) { 93 updateSuperclass(); 94 } 95 else { 96 super.doHandleControl(control); 97 } 98 } 99 100 protected void updateSuperclass() { 101 boolean doAll = ((DefaultsPreferencesModel) getModel()).isAllEntities(); 102 String defaultSuperclass = dataMap.getDefaultSuperclass(); 103 104 Iterator it = dataMap.getObjEntities().iterator(); 105 while (it.hasNext()) { 106 ObjEntity entity = (ObjEntity) it.next(); 107 if (doAll || Util.isEmptyString(entity.getSuperClassName())) { 108 if (!Util.nullSafeEquals(defaultSuperclass, entity.getSuperClassName())) { 109 entity.setSuperClassName(defaultSuperclass); 110 111 mediator.fireDbEntityEvent(new EntityEvent(this, entity)); 114 } 115 } 116 } 117 118 shutdown(); 119 } 120 121 } | Popular Tags |