Search in sources :

Example 1 with DataNodeDisplayEvent

use of org.apache.cayenne.modeler.event.DataNodeDisplayEvent in project cayenne by apache.

the class ImportEOModelAction method loadDataNode.

protected void loadDataNode(Map eomodelIndex) {
    // if this is JDBC or JNDI node and connection dictionary is specified, load a
    // DataNode, otherwise ignore it (meaning that pre 5.* EOModels will not have a
    // node).
    String adapter = (String) eomodelIndex.get("adaptorName");
    Map connection = (Map) eomodelIndex.get("connectionDictionary");
    if (adapter != null && connection != null) {
        CreateNodeAction nodeBuilder = (CreateNodeAction) getApplication().getActionManager().getAction(CreateNodeAction.class);
        // this should make created node current, resulting in the new map being added
        // to the node automatically once it is loaded
        DataNodeDescriptor node = nodeBuilder.buildDataNode();
        // configure node...
        if ("JNDI".equalsIgnoreCase(adapter)) {
            node.setDataSourceFactoryType(JNDIDataSourceFactory.class.getName());
            node.setParameters((String) connection.get("serverUrl"));
        } else {
            // guess adapter from plugin or driver
            AdapterMapping adapterDefaults = getApplication().getAdapterMapping();
            String cayenneAdapter = adapterDefaults.adapterForEOFPluginOrDriver((String) connection.get("plugin"), (String) connection.get("driver"));
            if (cayenneAdapter != null) {
                try {
                    Class<DbAdapter> adapterClass = getApplication().getClassLoadingService().loadClass(DbAdapter.class, cayenneAdapter);
                    node.setAdapterType(adapterClass.toString());
                } catch (Throwable ex) {
                // ignore...
                }
            }
            node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
            DataSourceInfo dsi = node.getDataSourceDescriptor();
            dsi.setDataSourceUrl(keyAsString(connection, "URL"));
            dsi.setJdbcDriver(keyAsString(connection, "driver"));
            dsi.setPassword(keyAsString(connection, "password"));
            dsi.setUserName(keyAsString(connection, "username"));
        }
        DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
        domain.getNodeDescriptors().add(node);
        // send events after the node creation is complete
        getProjectController().fireDataNodeEvent(new DataNodeEvent(this, node, MapEvent.ADD));
        getProjectController().fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, (DataChannelDescriptor) getProjectController().getProject().getRootNode(), node));
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) AdapterMapping(org.apache.cayenne.modeler.util.AdapterMapping) JNDIDataSourceFactory(org.apache.cayenne.configuration.server.JNDIDataSourceFactory) DbAdapter(org.apache.cayenne.dba.DbAdapter) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) XMLPoolingDataSourceFactory(org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) Map(java.util.Map) DataMap(org.apache.cayenne.map.DataMap)

Example 2 with DataNodeDisplayEvent

use of org.apache.cayenne.modeler.event.DataNodeDisplayEvent in project cayenne by apache.

the class DataNodeDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    if (!dataChannel.getName().equals(preferences.getDomain())) {
        return;
    }
    DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
    if (dataNode == null) {
        return;
    }
    DataNodeDisplayEvent dataNodeDisplayEvent = new DataNodeDisplayEvent(this, dataChannel, dataNode);
    controller.fireDataNodeDisplayEvent(dataNodeDisplayEvent);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 3 with DataNodeDisplayEvent

use of org.apache.cayenne.modeler.event.DataNodeDisplayEvent in project cayenne by apache.

the class ProjectController method removeFromHistory.

private void removeFromHistory(EventObject e) {
    int count = controllerStateHistory.size();
    List<ControllerState> removeList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ControllerState cs = controllerStateHistory.get(i);
        if (cs == null || cs.event == null) {
            continue;
        }
        EventObject csEvent = cs.event;
        if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
            if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent).getEntity()) {
                removeList.add(cs);
            }
        } else if (e instanceof EmbeddableEvent && csEvent instanceof EmbeddableDisplayEvent) {
            if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEvent) csEvent).getEmbeddable()) {
                removeList.add(cs);
            }
        } else if (e instanceof ProcedureEvent && csEvent instanceof ProcedureDisplayEvent) {
            if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent).getProcedure()) {
                removeList.add(cs);
            }
        } else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
            if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent).getQuery()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
            if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent).getDataMap()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataNodeEvent && csEvent instanceof DataNodeDisplayEvent) {
            if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent).getDataNode()) {
                removeList.add(cs);
            }
        } else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
            if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent).getDomain()) {
                removeList.add(cs);
            }
        }
    }
    for (ControllerState o : removeList) {
        controllerStateHistory.remove(o);
    }
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) ArrayList(java.util.ArrayList) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) EventObject(java.util.EventObject) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 4 with DataNodeDisplayEvent

use of org.apache.cayenne.modeler.event.DataNodeDisplayEvent in project cayenne by apache.

the class AdapterEditor method initController.

protected void initController() {
    // init bindings
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    adapterNameBinding = builder.bindToTextField(view.getCustomAdapter(), "adapterName");
    ((ProjectController) getParent()).addDataNodeDisplayListener(new DataNodeDisplayListener() {

        public void currentDataNodeChanged(DataNodeDisplayEvent e) {
            refreshView(e.getDataNode());
        }
    });
    getView().addComponentListener(new ComponentAdapter() {

        public void componentShown(ComponentEvent e) {
            refreshView(node != null ? node : ((ProjectController) getParent()).getCurrentDataNode());
        }
    });
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DataNodeDisplayListener(org.apache.cayenne.modeler.event.DataNodeDisplayListener) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) ComponentEvent(java.awt.event.ComponentEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 5 with DataNodeDisplayEvent

use of org.apache.cayenne.modeler.event.DataNodeDisplayEvent in project cayenne by apache.

the class PasswordEncoderEditor method initController.

protected void initController() {
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.setDelegate(nodeChangeProcessor);
    bindings = new ObjectBinding[4];
    bindings[0] = builder.bindToComboSelection(view.getPasswordEncoder(), "node.dataSourceDescriptor.passwordEncoderClass");
    bindings[1] = builder.bindToTextField(view.getPasswordKey(), "node.dataSourceDescriptor.passwordEncoderKey");
    bindings[2] = builder.bindToComboSelection(view.getPasswordLocation(), "node.dataSourceDescriptor.passwordLocation");
    bindings[3] = builder.bindToTextField(view.getPasswordSource(), "node.dataSourceDescriptor.passwordSource");
    ((ProjectController) getParent()).addDataNodeDisplayListener(new DataNodeDisplayListener() {

        public void currentDataNodeChanged(DataNodeDisplayEvent e) {
            refreshView(e.getDataNode());
        }
    });
    getView().addComponentListener(new ComponentAdapter() {

        public void componentShown(ComponentEvent e) {
            refreshView(node != null ? node : ((ProjectController) getParent()).getCurrentDataNode());
        }
    });
    builder.bindToAction(view.getPasswordEncoder(), "validatePasswordEncoderAction()");
    builder.bindToAction(view.getPasswordLocation(), "passwordLocationChangedAction()");
}
Also used : BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DataNodeDisplayListener(org.apache.cayenne.modeler.event.DataNodeDisplayListener) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) ComponentEvent(java.awt.event.ComponentEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)3 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)3 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)3 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)3 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)3 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)3 ComponentAdapter (java.awt.event.ComponentAdapter)2 ComponentEvent (java.awt.event.ComponentEvent)2 EventObject (java.util.EventObject)2 DataMap (org.apache.cayenne.map.DataMap)2 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 DataNodeDisplayListener (org.apache.cayenne.modeler.event.DataNodeDisplayListener)2 BindingBuilder (org.apache.cayenne.swing.BindingBuilder)2 ArrayList (java.util.ArrayList)1