Search in sources :

Example 21 with BindingBuilder

use of org.apache.cayenne.swing.BindingBuilder in project cayenne by apache.

the class LockingUpdateController method initBindings.

protected void initBindings() {
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.bindToAction(view.getCancelButton(), "cancelAction()");
    builder.bindToAction(view.getUpdateButton(), "updateAction()");
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder)

Example 22 with BindingBuilder

use of org.apache.cayenne.swing.BindingBuilder in project cayenne by apache.

the class DBGeneratorOptions method initController.

protected void initController() {
    DefaultComboBoxModel<String> adapterModel = new DefaultComboBoxModel<>(DbAdapterInfo.getStandardAdapters());
    view.getAdapters().setModel(adapterModel);
    view.getAdapters().setSelectedIndex(0);
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    sqlBinding = builder.bindToTextArea(view.getSql(), "textForSQL");
    adapterBinding = builder.bindToComboSelection(view.getAdapters(), "connectionInfo.dbAdapter", "refreshSQLAction()", "org.apache.cayenne.dba.JdbcAdapter");
    optionBindings = new ObjectBinding[5];
    optionBindings[0] = builder.bindToStateChangeAndAction(view.getCreateFK(), "generatorDefaults.createFK", "refreshSQLAction()");
    optionBindings[1] = builder.bindToStateChangeAndAction(view.getCreatePK(), "generatorDefaults.createPK", "refreshSQLAction()");
    optionBindings[2] = builder.bindToStateChangeAndAction(view.getCreateTables(), "generatorDefaults.createTables", "refreshSQLAction()");
    optionBindings[3] = builder.bindToStateChangeAndAction(view.getDropPK(), "generatorDefaults.dropPK", "refreshSQLAction()");
    optionBindings[4] = builder.bindToStateChangeAndAction(view.getDropTables(), "generatorDefaults.dropTables", "refreshSQLAction()");
    builder.bindToAction(view.getGenerateButton(), "generateSchemaAction()");
    builder.bindToAction(view.getSaveSqlButton(), "storeSQLAction()");
    builder.bindToAction(view.getCancelButton(), "closeAction()");
    // refresh SQL if different tables were selected
    view.getTabs().addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            if (view.getTabs().getSelectedIndex() == 0) {
                // this assumes that some tables where checked/unchecked... not very
                // efficient
                refreshGeneratorAction();
            }
        }
    });
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) BindingBuilder(org.apache.cayenne.swing.BindingBuilder) ChangeListener(javax.swing.event.ChangeListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 23 with BindingBuilder

use of org.apache.cayenne.swing.BindingBuilder in project cayenne by apache.

the class TableSelectorController method initController.

// ------ other stuff ------
protected void initController() {
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.bindToAction(view.getCheckAll(), "checkAllAction()");
    TableBindingBuilder tableBuilder = new TableBindingBuilder(builder);
    tableBuilder.addColumn("", "setTable(#item), included", Boolean.class, true, Boolean.TRUE);
    tableBuilder.addColumn("Table", "#item.name", String.class, false, "XXXXXXXXXXXXXXXX");
    tableBuilder.addColumn("Problems", "setTable(#item), problem", String.class, false, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    this.tableBinding = tableBuilder.bindToTable(view.getTables(), "tables");
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder) TableBindingBuilder(org.apache.cayenne.swing.TableBindingBuilder) TableBindingBuilder(org.apache.cayenne.swing.TableBindingBuilder)

Example 24 with BindingBuilder

use of org.apache.cayenne.swing.BindingBuilder in project cayenne by apache.

the class MergerTokenSelectorController method initController.

// ------ other stuff ------
protected void initController() {
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.bindToAction(view.getCheckAll(), "checkAllAction()");
    builder.bindToAction(view.getReverseAll(), "reverseAllAction()");
    TableModel model = new MergerTokenTableModel(this);
    MergeDirection[] dirs = new MergeDirection[] { MergeDirection.TO_DB, MergeDirection.TO_MODEL };
    view.getTokens().setModel(model);
    TableColumnModel columnModel = view.getTokens().getColumnModel();
    // dropdown for direction column
    JComboBox directionCombo = Application.getWidgetFactory().createComboBox(dirs, false);
    directionCombo.setEditable(false);
    TableColumn directionColumn = columnModel.getColumn(MergerTokenTableModel.COL_DIRECTION);
    directionColumn.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);
            setHorizontalTextPosition(SwingConstants.LEFT);
            setIcon(ModelerUtil.buildIcon("icon-arrow-open.png"));
            return this;
        }
    });
    directionColumn.setCellEditor(new DefaultCellEditor(directionCombo));
    columnModel.getColumn(MergerTokenTableModel.COL_SELECT).setPreferredWidth(50);
    columnModel.getColumn(MergerTokenTableModel.COL_DIRECTION).setPreferredWidth(100);
    columnModel.getColumn(MergerTokenTableModel.COL_SELECT).setMaxWidth(50);
    columnModel.getColumn(MergerTokenTableModel.COL_DIRECTION).setMaxWidth(100);
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) MergeDirection(org.apache.cayenne.dbsync.merge.context.MergeDirection) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 25 with BindingBuilder

use of org.apache.cayenne.swing.BindingBuilder in project cayenne by apache.

the class ObjAttributeInfoDialog method initController.

private void initController(ObjAttribute attr) {
    for (String embeddableName : embeddableNames) {
        ((DefaultComboBoxModel) view.getTypeComboBox().getModel()).addElement(embeddableName);
    }
    this.attribute = attr;
    if (attribute instanceof EmbeddedAttribute || embeddableNames.contains(attribute.getType())) {
        this.attributeSaved = new EmbeddedAttribute();
    } else {
        this.attributeSaved = new ObjAttribute();
    }
    copyObjAttribute(attributeSaved, attribute);
    relTargets = new ArrayList<DbEntity>(attribute.getEntity().getDataMap().getDbEntities());
    /*
		 * Register auto-selection of the target
		 */
    view.getPathBrowser().addTreeSelectionListener(this);
    view.getAttributeName().setText(attribute.getName());
    if (attribute.getDbAttributePath() != null) {
        if (attribute.getDbAttributePath().contains(".")) {
            String path = attribute.getDbAttributePath();
            view.getCurrentPathLabel().setText(path.replace(".", " -> "));
        } else {
            view.getCurrentPathLabel().setText(attribute.getDbAttributePath());
        }
    } else {
        view.getCurrentPathLabel().setText("");
    }
    view.getSourceEntityLabel().setText(attribute.getEntity().getName());
    view.getTypeComboBox().setSelectedItem(attribute.getType());
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.bindToAction(view.getCancelButton(), "closeAction()");
    builder.bindToAction(view.getSelectPathButton(), "setPath(true)");
    builder.bindToAction(view.getSaveButton(), "saveMapping()");
    /*
		 * set filter for ObjAttributePathBrowser
		 */
    if (view.getPathBrowser().getModel() == null) {
        Entity firstEntity = null;
        if (attribute.getDbAttribute() == null) {
            if (attribute.getParent() instanceof ObjEntity) {
                DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
                if (dbEnt != null) {
                    Collection<DbAttribute> attrib = dbEnt.getAttributes();
                    Collection<DbRelationship> rel = dbEnt.getRelationships();
                    if (attrib.size() > 0) {
                        Iterator<DbAttribute> iter = attrib.iterator();
                        firstEntity = iter.next().getEntity();
                    } else if (rel.size() > 0) {
                        Iterator<DbRelationship> iter = rel.iterator();
                        firstEntity = iter.next().getSourceEntity();
                    }
                }
            }
        } else {
            firstEntity = getFirstEntity();
        }
        if (firstEntity != null) {
            EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
            treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
            view.getPathBrowser().setModel(treeModel);
        }
    }
    if (attribute.getDbAttribute() != null) {
        setSelectionPath();
    }
    view.getTypeComboBox().addItemListener(e -> {
        if (lastObjectType != null) {
            if (!lastObjectType.equals(e.getItemSelectable())) {
                if (embeddableNames.contains(e.getItemSelectable().getSelectedObjects()[0].toString())) {
                    if (attributeSaved instanceof ObjAttribute) {
                        EmbeddedAttribute copyAttrSaved = new EmbeddedAttribute();
                        copyObjAttribute(copyAttrSaved, attributeSaved);
                        attributeSaved = copyAttrSaved;
                    }
                } else {
                    if (attributeSaved instanceof EmbeddedAttribute) {
                        ObjAttribute copyAttrSaved = new ObjAttribute();
                        copyObjAttribute(copyAttrSaved, attributeSaved);
                        attributeSaved = copyAttrSaved;
                    }
                }
                attributeSaved.setType(e.getItemSelectable().getSelectedObjects()[0].toString());
                rebuildTable();
                setEnabledSaveButton();
            }
        }
    });
    view.getAttributeName().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (!view.getAttributeName().getText().equals(attribute.getName())) {
                setEnabledSaveButton();
            }
        }

        public void keyReleased(KeyEvent e) {
            if (!view.getAttributeName().getText().equals(attribute.getName())) {
                setEnabledSaveButton();
            }
        }

        public void keyTyped(KeyEvent e) {
        }
    });
    rebuildTable();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) KeyEvent(java.awt.event.KeyEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) DbRelationship(org.apache.cayenne.map.DbRelationship) EntityTreeAttributeRelationshipFilter(org.apache.cayenne.modeler.util.EntityTreeAttributeRelationshipFilter) Iterator(java.util.Iterator) KeyListener(java.awt.event.KeyListener)

Aggregations

BindingBuilder (org.apache.cayenne.swing.BindingBuilder)29 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)5 TableBindingBuilder (org.apache.cayenne.swing.TableBindingBuilder)4 ComponentAdapter (java.awt.event.ComponentAdapter)3 ComponentEvent (java.awt.event.ComponentEvent)3 Entry (java.util.Map.Entry)3 DataMap (org.apache.cayenne.map.DataMap)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)3 DataNodeDisplayListener (org.apache.cayenne.modeler.event.DataNodeDisplayListener)3 DataMapDefaults (org.apache.cayenne.modeler.pref.DataMapDefaults)3 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 File (java.io.File)1