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  org.apache.log4j.Logger;
 import  org.scopemvc.core.Selector;
 import  org.scopemvc.view.swing.SAction;
 import  org.scopemvc.view.swing.SButton;
 import  org.scopemvc.view.swing.SComboBox;
 import  org.scopemvc.view.swing.SLabel;
 import  org.scopemvc.view.swing.SListCellRenderer;
 import  org.scopemvc.view.swing.SPanel;
 import  org.scopemvc.view.swing.STable;
 import  org.scopemvc.view.swing.STableModel;
 import  org.scopemvc.view.swing.STextField;
 import  org.scopemvc.view.swing.SwingView;
 import  com.jgoodies.forms.builder.PanelBuilder;
 import  com.jgoodies.forms.layout.CellConstraints;
 import  com.jgoodies.forms.layout.FormLayout;

A view of the dialog for mapping an ObjRelationship to one or more DbRelationships.

Andrei Adamchik
 public class ObjRelationshipInfoDialog extends SPanel {
     static final Logger logObj = Logger.getLogger(ObjRelationshipInfoDialog.class);
     protected STable pathTable;
     public ObjRelationshipInfoDialog() {
     protected void init() {
         // create widgets 
         SButton saveButton =
             new SButton(new SAction(.));
         SButton cancelButton =
             new SButton(new SAction(.));
         SButton newToOneButton =
             new SButton(new SAction(.));
         SButton newToManyButton =
             new SButton(new SAction(.));
         STextField relationshipName = new STextField(25);
         SLabel sourceEntityLabel = new SLabel();
         SComboBox targetCombo = new SComboBox();
         SListCellRenderer renderer = (SListCellRenderer) targetCombo.getRenderer();
          = new ObjRelationshipPathTable();
         STableModel pathTableModel = new STableModel();
        pathTableModel.setColumnNames(new String[] { "DbRelationships" });
            new Selector[] {
        // assemble
        setTitle("ObjRelationship Inspector");
        setLayout(new BorderLayout());
        CellConstraints cc = new CellConstraints();
        PanelBuilder builder =
            new PanelBuilder(
                new FormLayout(
                    "right:max(50dlu;pref), 3dlu, fill:min(150dlu;pref), 3dlu, fill:min(150dlu;pref)",
                    "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, top:14dlu, 3dlu, top:p:grow"));
        builder.addSeparator("ObjRelationship Information"cc.xywh(1, 1, 5, 1));
        builder.addLabel("Relationship:"cc.xy(1, 3));
        builder.add(relationshipNamecc.xywh(3, 3, 1, 1));
        builder.addLabel("Source:"cc.xy(1, 5));
        builder.add(sourceEntityLabelcc.xywh(3, 5, 1, 1));
        builder.addLabel("Target:"cc.xy(1, 7));
        builder.add(targetCombocc.xywh(3, 7, 1, 1));
        builder.addSeparator("Mapping to DbRelationships"cc.xywh(1, 9, 5, 1));
        builder.add(new JScrollPane(), cc.xywh(1, 11, 3, 3));
        builder.add(newToOneButtoncc.xywh(5, 11, 1, 1));
        builder.add(newToManyButtoncc.xywh(5, 13, 1, 1));
        add(builder.getPanel(), .);
            PanelFactory.createButtonPanel(new JButton[] { saveButtoncancelButton }),

Cancels any editing that might be going on in the path table.
    public void cancelTableEditing() {
        int row = .getEditingRow();
        if (row < 0) {
        int column = .getEditingColumn();
        if (column < 0) {
        TableCellEditor editor = .getCellEditor(rowcolumn);
        if (editor != null) {
    class ObjRelationshipPathTable extends STable {
        final Dimension preferredSize = new Dimension(203, 100);
        ObjRelationshipPathTable() {
        public Dimension getPreferredScrollableViewportSize() {
            return ;
    static final class RelationshipPicker extends DefaultCellEditor {
        JComboBox comboBox;
        SwingView view;
        static TableCellEditor createEditor(SwingView view) {
            JComboBox relationshipCombo = new JComboBox();
            return new RelationshipPicker(viewrelationshipCombo);
        RelationshipPicker(SwingView viewJComboBox comboBox) {
            this. = comboBox;
            this. = view;
        public Component getTableCellEditorComponent(
            JTable table,
            Object value,
            boolean isSelected,
            int row,
            int column) {
            // initialize combo box
            ObjRelationshipInfoModel model =
            EntityRelationshipsModel relationshipWrapper =
            DefaultComboBoxModel comboModel =
                new DefaultComboBoxModel(relationshipWrapper.getRelationshipNames());
            // call super
            return super.getTableCellEditorComponent(
New to GrepCode? Check out our FAQ X