Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.dialog.objentity;
 
 
 import  org.scopemvc.controller.basic.BasicController;
 import  org.scopemvc.core.Control;
 import  org.scopemvc.core.ControlException;

Author(s):
Andrei Adamchik
Since:
1.1
 
 public class ObjRelationshipInfoController extends BasicController {
 
     static final Logger logObj = Logger.getLogger(ObjRelationshipInfoController.class);
 
     public static final String SAVE_CONTROL = "cayenne.modeler.mapObjRelationship.save.button";
     public static final String CANCEL_CONTROL = "cayenne.modeler.mapObjRelationship.cancel.button";
     public static final String NEW_TOONE_CONTROL = "cayenne.modeler.mapObjRelationship.newtoone.button";
     public static final String NEW_TOMANY_CONTROL = "cayenne.modeler.mapObjRelationship.newtomany.button";
 
     protected ProjectController mediator;
 
             ObjRelationship relationship) {
 
         this. = mediator;
         Collection objEntities = mediator.getCurrentDataMap().getNamespace().getObjEntities();
         ObjRelationshipInfoModel model = new ObjRelationshipInfoModel(
                 relationship,
                 objEntities);
         setModel(model);
     }

    
Creates and runs the classpath dialog.
 
     public void startup() {
         setView(new ObjRelationshipInfoDialog());
         super.startup();
     }
 
     protected void doHandleControl(Control controlthrows ControlException {
         if (control.matchesID()) {
             shutdown();
         }
         else if (control.matchesID()) {
             saveMapping();
         }
         else if (control.matchesID()) {
             createRelationship(false);
         }
         else if (control.matchesID()) {
             createRelationship(true);
         }
     }
 
     protected void saveMapping() {
 
         if (model.savePath()) {
             .fireObjRelationshipEvent(new RelationshipEvent(Application
                     .getFrame(), model.getRelationship(), model
                     .getRelationship()
                     .getSourceEntity()));
         }
         shutdown();
     }

    
Creates a new relationship connecting currently selected source entity with ObjRelationship target entity. User is allowed to edit the relationship, change its name, and create joins.
    protected void createRelationship(boolean toMany) {
        cancelEditing();
        DbEntity source = model.getStartEntity();
        DbEntity target = model.getEndEntity();
        EntityRelationshipsModel selectedPathComponent = model.getSelectedPathComponent();
        if (selectedPathComponent != null) {
            source = (DbEntityselectedPathComponent.getSourceEntity();
        }
        DbRelationship dbRelationship = (DbRelationship) NamedObjectFactory
                .createRelationship(sourcetargettoMany);
        // note: NamedObjectFactory doesn't set source or target, just the name
        dbRelationship.setSourceEntity(source);
        dbRelationship.setTargetEntity(target);
        dbRelationship.setToMany(toMany);
        source.addRelationship(dbRelationship);
        // TODO: creating relationship outside of ResolveDbRelationshipDialog confuses it
        // to send incorrect event - CHANGE instead of ADD
                dbRelationship);
        dialog.setVisible(true);
        if (dialog.isCancelPressed()) {
            source.removeRelationship(dbRelationship.getName());
        }
        else {
            if (selectedPathComponent == null) {
                selectedPathComponent = (EntityRelationshipsModelmodel
                        .getDbRelationshipPath()
                        .get(0);
                model.setSelectedPathComponent(selectedPathComponent);
            }
            selectedPathComponent.setRelationshipName(dbRelationship.getName());
        }
        dialog.dispose();
    }
    protected void cancelEditing() {
    }
New to GrepCode? Check out our FAQ X