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 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 java.util.List;
 import  org.apache.cayenne.project.NamedObjectFactory;
 import  org.scopemvc.controller.basic.BasicController;
 import  org.scopemvc.core.Control;
 import  org.scopemvc.core.ControlException;

 public class ObjRelationshipInfoController extends BasicController implements
         TreeSelectionListener {
     public static final String SAVE_CONTROL = "";
     public static final String CANCEL_CONTROL = "cayenne.modeler.mapObjRelationship.cancel.button";
     public static final String NEW_REL_CONTROL = "cayenne.modeler.mapObjRelationship.newrel.button";
     public static final String SELECT_PATH_CONTROL = "";
     public static final String REVERT_PATH_CONTROL = "cayenne.modeler.mapObjRelationship.revert.path.button";
     public static final String CLEAR_PATH_CONTROL = "cayenne.modeler.mapObjRelationship.clear.path.button";
     protected ProjectController mediator;
             ObjRelationship relationship) {
         this. = mediator;
         ObjRelationshipInfoModel model = new ObjRelationshipInfoModel(relationship);

Creates and runs the classpath dialog.
     public void startup() {
Some workaround: need to save target first, because even if it is null, first item will be displayed in combobox. Also we do not want to have empty item in the combobox.
         ObjEntity target = model.getObjectTarget();
         ObjRelationshipInfoDialog view = new ObjRelationshipInfoDialog();

Register auto-selection of the target
    protected void doHandleControl(Control controlthrows ControlException {
        if (control.matchesID()) {
        else if (control.matchesID()) {
        else if (control.matchesID()) {
        else if (control.matchesID()) {
        else if (control.matchesID()) {
        else if (control.matchesID()) {

Saves selected path
    protected void selectPath() {

Reverts current path to saved path
    protected void revertPath() {

Clears paths and selections in browser
    protected void clearPath() {
        model.setDbRelationships(new ArrayList<DbRelationship>());
    protected void saveMapping() {
        if (!model.getDbRelationships().equals(model.getSavedDbRelationships())) {
            if (JOptionPane.showConfirmDialog(
                    "You have changed Db Relationship path. Do you want it to be saved?",
                    "Save ObjRelationship",
                    .) == .) {
        if (model.savePath()) {
            .fireObjRelationshipEvent(new RelationshipEvent(Application
                    .getFrame(), model.getRelationship(), model

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() {
        DbRelationship dbRel = model.getLastRelationship();
        DbEntity source = dbRel != null ? (DbEntity) dbRel.getTargetEntity() : null;
        DbRelationshipTargetController targetController = new DbRelationshipTargetController(
        if (!targetController.isSavePressed()) {
        DbRelationshipTargetModel targetModel = (DbRelationshipTargetModeltargetController
        DbRelationship dbRelationship = (DbRelationship) NamedObjectFactory
        // note: NamedObjectFactory doesn't set source or target, just the name
        // TODO: creating relationship outside of ResolveDbRelationshipDialog confuses it
        // to send incorrect event - CHANGE instead of ADD
        if (dialog.isCancelPressed()) {
        else {
            MultiColumnBrowser pathBrowser = ((ObjRelationshipInfoDialoggetView())
            Object[] oldPath = targetModel.isSource1Selected() ? new Object[] {
            } : pathBrowser.getSelectionPath().getPath();

Update the view
            EntityTreeModel treeModel = (EntityTreeModelpathBrowser.getModel();
            pathBrowser.setSelectionPath(new TreePath(new Object[] {
            Object[] path = new Object[oldPath.length + 1];
            System.arraycopy(oldPath, 0, path, 0, path.length - 1);
            path[path.length - 1] = dbRelationship;
            pathBrowser.setSelectionPath(new TreePath(path));
    public void valueChanged(TreeSelectionEvent e) {
        TreePath selectedPath = e.getPath();
        // first item in the path is Entity, so we must have
        // at least two elements to constitute a valid ordering path
        if (selectedPath == null || selectedPath.getPathCount() < 2) {
        Relationship rel = (Relationship) selectedPath.getLastPathComponent();
        DbEntity target = (DbEntity) rel.getTargetEntity();
        ObjRelationshipInfoModel model = (ObjRelationshipInfoModelgetModel();

Initialize root with one of mapped ObjEntities.
        Collection<ObjEntity> objEntities = target.getDataMap().getMappedEntities(target);
        List<DbRelationship> relPath = new Vector<DbRelationship>(selectedPath
                .getPathCount() - 1);
        for (int i = 1; i < selectedPath.getPathCount(); i++) {
            relPath.add((DbRelationship) selectedPath.getPathComponent(i));
        model.setObjectTarget(objEntities.size() == 0 ? null : objEntities
New to GrepCode? Check out our FAQ X