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.conn.DataSourceInfo;
 import  org.apache.cayenne.map.event.DataNodeEvent;
 import  org.apache.cayenne.project.ProjectDataSource;
 
 
 public class PasswordEncoderEditor extends CayenneController  {
     
     protected DataNode node;
     protected ObjectBinding[] bindings;
     protected PasswordEncoderView view;
     protected BindingDelegate nodeChangeProcessor;
     
     public PasswordEncoderEditor(CayenneController parent){
 
         super(parent);
         
         this. = new PasswordEncoderView();
         
         this. = new BindingDelegate() {
 
             public void modelUpdated(
                     ObjectBinding binding,
                     Object oldValue,
                     Object newValue) {
 
                 DataNodeEvent e = new DataNodeEvent(PasswordEncoderEditor.this);
                 ((ProjectControllergetParent()).fireDataNodeEvent(e);
             }
         };
                 
         initController();
     }
     
     protected void initController() {
         BindingBuilder builder = new BindingBuilder(
                 getApplication().getBindingFactory(),
                 this);
         
         builder.setDelegate();
         
          = new ObjectBinding[4];
         
         [0] =
               builder.bindToComboSelection(.getPasswordEncoder(), "node.dataSource.dataSourceInfo.passwordEncoderClass");
         [1] =
               builder.bindToTextField(.getPasswordKey(), "node.dataSource.dataSourceInfo.passwordEncoderKey");
         [2] =
               builder.bindToComboSelection(.getPasswordLocation(), "node.dataSource.dataSourceInfo.passwordLocation");
         [3] =
               builder.bindToTextField(.getPasswordSource(), "node.dataSource.dataSourceInfo.passwordSource");
 
           ((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());
               }
          });
          
          
      
        builder.bindToAction(.getPasswordEncoder(),  "validatePasswordEncoderAction()");
        builder.bindToAction(.getPasswordLocation(), "passwordLocationChangedAction()");
      
    }
    
    protected void refreshView(DataNode node) {
        this. = node;
        if (node == null) {
            getView().setVisible(false);
            return;
        }
        for (ObjectBinding binding : ) {
            binding.updateView();
        }
    }
    
    public void validatePasswordEncoderAction()
    {
      if ( == null || .getDataSource() == null)
        return;
      DataSourceInfo dsi = ((ProjectDataSource) .getDataSource()).getDataSourceInfo();
      if (.getPasswordEncoder().getSelectedItem().equals(dsi.getPasswordEncoderClass()) == false)
        return;
      if (dsi.getPasswordEncoder() == null)
      {
        JOptionPane.showMessageDialog(getView(),
                                      "A valid Password Encoder should be specified (check your CLASSPATH).",
                                      "Invalid Password Encoder",
                                      .);
      }
    }
    
    private void updatePasswordElements(boolean isPasswordFieldEnabled,
            boolean isPasswordLocationEnabled,
            String  passwordText,
            String  passwordLocationLabel,
            String  passwordLocationText)
    {
        .getPasswordSource().setEnabled(isPasswordLocationEnabled);
        .getPasswordSourceLabel().setText(passwordLocationLabel);
        .getPasswordSource().setText(passwordLocationText);
        
    }
    
    public void passwordLocationChangedAction()
    {
      if ( == null || .getDataSource() == null)
        return;
      DataSourceInfo dsi = ((ProjectDataSource) .getDataSource()).getDataSourceInfo();
      String selectedItem = (String.getPasswordLocation().getSelectedItem();
      if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH))
        updatePasswordElements(truetruedsi.getPassword(), "Password Filename:"dsi.getPasswordSourceFilename());
      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE))
        updatePasswordElements(falsetruenull"Password Executable:"dsi.getPasswordSourceExecutable());
      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_MODEL))
        updatePasswordElements(truefalsedsi.getPassword(), "Password Source:"dsi.getPasswordSourceModel());
      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_URL))
        updatePasswordElements(falsetruenull"Password URL:"dsi.getPasswordSourceUrl());
    }
    public Component getView() {
        return ;
    }
    
    public DataNode getNode() {
        return ;
    }
    
    public void setNode(DataNode node) {
        this. = node;
    }
New to GrepCode? Check out our FAQ X