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.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.

Author(s):
Andrei Adamchik
Since:
1.1
 
 public class ObjRelationshipInfoDialog extends SPanel {
     static final Logger logObj = Logger.getLogger(ObjRelationshipInfoDialog.class);
 
     protected STable pathTable;
 
     public ObjRelationshipInfoDialog() {
         init();
     }
 
     protected void init() {
         // create widgets 
         SButton saveButton =
             new SButton(new SAction(.));
         saveButton.setEnabled(true);
 
         SButton cancelButton =
             new SButton(new SAction(.));
         cancelButton.setEnabled(true);
 
         SButton newToOneButton =
             new SButton(new SAction(.));
         newToOneButton.setEnabled(true);
         SButton newToManyButton =
             new SButton(new SAction(.));
         newToManyButton.setEnabled(true);
 
         STextField relationshipName = new STextField(25);
         relationshipName.setSelector(.);
 
         SLabel sourceEntityLabel = new SLabel();
         sourceEntityLabel.setSelector(
 
         SComboBox targetCombo = new SComboBox();
         targetCombo.setSelector(.);
         targetCombo.setSelectionSelector(.);
         SListCellRenderer renderer = (SListCellRenderer) targetCombo.getRenderer();
         renderer.setTextSelector("name");
 
          = new ObjRelationshipPathTable();
         STableModel pathTableModel = new STableModel();
        pathTableModel.setSelector(
        pathTableModel.setColumnNames(new String[] { "DbRelationships" });
        pathTableModel.setColumnSelectors(
            new Selector[] {
        .setModel(pathTableModel);
        .setSelectionSelector(
        .getColumn("DbRelationships").setCellEditor(
            RelationshipPicker.createEditor(this));
        // assemble
        setDisplayMode(SwingView.MODAL_DIALOG);
        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.setDefaultDialogBorder();
        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(), .);
        add(
            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) {
            return;
        }
        int column = .getEditingColumn();
        if (column < 0) {
            return;
        }
        TableCellEditor editor = .getCellEditor(rowcolumn);
        if (editor != null) {
            editor.cancelCellEditing();
        }
    }
    class ObjRelationshipPathTable extends STable {
        final Dimension preferredSize = new Dimension(203, 100);
        ObjRelationshipPathTable() {
            setRowHeight(25);
            setRowMargin(3);
        }
        public Dimension getPreferredScrollableViewportSize() {
            return ;
        }
    }
    static final class RelationshipPicker extends DefaultCellEditor {
        JComboBox comboBox;
        SwingView view;
        static TableCellEditor createEditor(SwingView view) {
            JComboBox relationshipCombo = new JComboBox();
            relationshipCombo.setEditable(false);
            return new RelationshipPicker(viewrelationshipCombo);
        }
        RelationshipPicker(SwingView viewJComboBox comboBox) {
            super(comboBox);
            this. = comboBox;
            this. = view;
        }
        public Component getTableCellEditorComponent(
            JTable table,
            Object value,
            boolean isSelected,
            int row,
            int column) {
            // initialize combo box
            ObjRelationshipInfoModel model =
                (ObjRelationshipInfoModel.getBoundModel();
            EntityRelationshipsModel relationshipWrapper =
                (EntityRelationshipsModelmodel.getDbRelationshipPath().get(row);
            DefaultComboBoxModel comboModel =
                new DefaultComboBoxModel(relationshipWrapper.getRelationshipNames());
            comboModel.setSelectedItem(value);
            .setModel(comboModel);
            // call super
            return super.getTableCellEditorComponent(
                table,
                value,
                isSelected,
                row,
                column);
        }
    }
New to GrepCode? Check out our FAQ X