Search in sources :

Example 1 with DbRelationshipPathComboBoxEditor

use of org.apache.cayenne.modeler.util.DbRelationshipPathComboBoxEditor in project cayenne by apache.

the class ObjEntityRelationshipPanel method rebuildTable.

protected void rebuildTable(ObjEntity entity) {
    final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this);
    model.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (table.getSelectedRow() >= 0) {
                ObjRelationship rel = model.getRelationship(table.getSelectedRow());
                enabledResolve = rel.getSourceEntity().getDbEntity() != null;
                resolveMenu.setEnabled(enabledResolve);
            }
        }
    });
    table.setModel(model);
    table.setRowHeight(25);
    table.setRowMargin(3);
    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET_PATH);
    col.setCellEditor(new DbRelationshipPathComboBoxEditor());
    col.setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
            setToolTipText("To choose relationship press enter two times.To choose next relationship press dot.");
            return this;
        }
    });
    col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETE_RULE);
    JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(DELETE_RULES, false);
    deleteRulesCombo.setFocusable(false);
    deleteRulesCombo.setEditable(true);
    ((JComponent) deleteRulesCombo.getEditor().getEditorComponent()).setBorder(null);
    deleteRulesCombo.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    // Default to the first value
    deleteRulesCombo.setSelectedIndex(0);
    col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo));
    tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true);
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationshipPathComboBoxEditor(org.apache.cayenne.modeler.util.DbRelationshipPathComboBoxEditor) JComboBox(javax.swing.JComboBox) TableModelEvent(javax.swing.event.TableModelEvent) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableModelListener(javax.swing.event.TableModelListener) JTable(javax.swing.JTable) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

Component (java.awt.Component)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JTable (javax.swing.JTable)1 TableModelEvent (javax.swing.event.TableModelEvent)1 TableModelListener (javax.swing.event.TableModelListener)1 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)1 TableColumn (javax.swing.table.TableColumn)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 DbRelationshipPathComboBoxEditor (org.apache.cayenne.modeler.util.DbRelationshipPathComboBoxEditor)1