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.editor.datanode;
 
 
 import  org.apache.cayenne.access.DataNode;
 import  org.apache.cayenne.dba.AutoAdapter;
 import  org.apache.cayenne.dba.DbAdapter;
 import  org.apache.cayenne.map.event.DataNodeEvent;
 
 public class AdapterEditor extends CayenneController {
 
     protected AdapterView view;
     protected DataNode node;
     protected ObjectBinding adapterNameBinding;
 
     public AdapterEditor(CayenneController parent) {
         super(parent);
 
         this. = new AdapterView();
         initController();
     }
 
     protected void initController() {
         // init bindings
         BindingBuilder builder = new BindingBuilder(
                 getApplication().getBindingFactory(),
                 this);
 
          = builder.bindToTextField(
                 .getCustomAdapter(),
                 "adapterName");
 
         // init listeners–ö
         ((ProjectControllergetParent())
                 .addDataNodeDisplayListener(new DataNodeDisplayListener() {
 
                     public void currentDataNodeChanged(DataNodeDisplayEvent e) {
                         refreshView(e.getDataNode());
                     }
                 });
 
         getView().addComponentListener(new ComponentAdapter() {
 
             public void componentShown(ComponentEvent e) {
                 refreshView( != null ?  : ((ProjectControllergetParent())
                         .getCurrentDataNode());
             }
         });
     }
 
     protected void refreshView(DataNode node) {
         this. = node;
 
         if (node == null) {
             getView().setVisible(false);
             return;
         }
 
         .updateView();
     }
 
     public Component getView() {
         return ;
     }
 
     public String getAdapterName() {
         if ( == null) {
             return null;
         }
        DbAdapter adapter = .getAdapter();
        // TODO, Andrus, 11/3/2005 - to simplify this logic, it would be nice to
        // consistently load CustomDbAdapter... this would require an ability to set a
        // load delegate in OpenProjectAction
        if (adapter == null) {
            return null;
        }
        else if (adapter instanceof ModelerDbAdapter) {
            return ((ModelerDbAdapteradapter).getAdapterClassName();
        }
        // don't do "instanceof" here, as we maybe dealing with a custom subclass...
        else if (adapter.getClass() == AutoAdapter.class) {
            return null;
        }
        else {
            return adapter.getClass().getName();
        }
    }
    public void setAdapterName(String name) {
        if ( == null) {
            return;
        }
        ModelerDbAdapter adapter = new ModelerDbAdapter(name.getDataSource());
        adapter.validate();
        .setAdapter(adapter);
        
        DataNodeEvent e = new DataNodeEvent(AdapterEditor.this);
    }
New to GrepCode? Check out our FAQ X