Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common
   * Development and Distribution License("CDDL") (collectively, the
   * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  *
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 /*
  * DataSourceWizard.java
  *
  * Created on September 30, 2003, 10:05 AM
  */
 
 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;

Author(s):
nityad
 
 
 import java.util.Set;
 
 
 
 public final class DataSourceWizard implements WizardDescriptor.InstantiatingIteratorChangeListenerWizardConstants{
    
    
An array of all wizard panels
 
        
     private static final String DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/DSWizard.xml";  //NOI18N
     private static final String CP_DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/CPWizard.xml";  //NOI18N
     
     private transient int index;
     private transient WizardDescriptor.Panel[] panels;
 //    private transient WizardDescriptor wiz;
     private transient String[] steps;
     
     private ResourceConfigHelper helper;
     private Wizard wizardInfo;
         
     private boolean addSteps = false;
 //    private boolean firstTime = true;
     
     private ResourceConfigHelper cphelper;
     private Wizard cpWizardInfo;
      
     private transient WizardDescriptor.Panel[] morePanels = null;
     private transient WizardDescriptor.Panel[] dsPanels = null;
     
     private transient String[] dsSteps = null;
     private transient String[] moreSteps = null;
    
    
Creates a new instance of DataSourceWizard
 
    public static DataSourceWizard create () {
        return new DataSourceWizard ();
    }
    
    private WizardDescriptor.Panel[] createPanels() {
         = null;
        WizardDescriptor.Panel panel = new CommonAttributePanel(new String[] {"general"});   //NOI18N
        panel.addChangeListener(this);
        return new WizardDescriptor.Panel[] {
            panel,
            new CommonPropertyPanel(this.this.)
        };
    }
    
    private String[] createSteps() {
        return new String[] {
            NbBundle.getMessage(DataSourceWizard.class,),
            NbBundle.getMessage(DataSourceWizard.class"LBL_GeneralAttributes_DS"), // NOI18N
            NbBundle.getMessage(DataSourceWizard.class"LBL_AddProperty"// NOI18N
        };
    }
    
    public Set instantiate(){
        try{
            if(this..hasCPHelper()){
                String poolName = this..getData().getString();
                this..getData().setString(poolName);
                this..getData().setTargetFile(poolName);
                this..getData().setTargetFileObject(this..getData().getTargetFileObject());
                ResourceUtils.saveJDBCResourceDatatoXml(this..getData(), this..getData());
            }else{
                ResourceUtils.saveJDBCResourceDatatoXml(this..getData(), null);
            }    
        }catch (Exception ex){
                                ErrorManager.getDefault().notify(.,
                                        ex);
        }
        return ...;
    }
    
    public void initialize(WizardDescriptor wiz){
        this. = getWizardInfo();
        this. = new ResourceConfigHelperHolder();
        this. = .getDataSourceHelper();
        
        //this.wiz = wiz;
        wiz.putProperty("NewFileWizard_Title", NbBundle.getMessage(ConnPoolWizard.class"Templates/SunResources/JDBC_Resource")); //NOI18N
         = 0;
                
        Project project = Templates.getProject(wiz);
        
         = createPanels();
        // Make sure list of steps is accurate.
         = createSteps();
        
        try{
            FileObject pkgLocation = project.getProjectDirectory();
            if (pkgLocation != null) {
                this..getData().setTargetFileObject(pkgLocation);
            }
        }catch (Exception ex){
                                ErrorManager.getDefault().notify(.,
                                        ex);
        }
        
        for (int i = 0; i < .i++) {
            Component c = [i].getComponent();
            if (c instanceof JComponent) { // assume Swing components
                JComponent jc = (JComponent)c;
                // Step #.
                jc.putClientProperty(.new Integer(i)); // NOI18N
                // Step name (actually the whole list for reference).
                jc.putClientProperty(.); // NOI18N
            }
        }
        
    }
    
    public void uninitialize(WizardDescriptor wiz){
        //this.wiz = null;
         = null;
    }
    
    public Wizard getWizardInfo(String filePath){
        try{
            InputStream in = Wizard.class.getClassLoader().getResourceAsStream(filePath);
            this. = Wizard.createGraph(in);
        }catch(Exception ex){
                                ErrorManager.getDefault().notify(.,
                                        ex);
        }
        return this.;
    }
    
    public String name(){
        return NbBundle.getMessage(DataSourceWizard.class"Templates/SunResources/JDBC_Resource"); //NOI18N
    }
    
    public boolean hasNext(){
        return  < . - 1;
    }
    
    public boolean hasPrevious(){
        return  > 0;
    }
    
    public synchronized void nextPanel(){
        if ( + 1 == .) {
            throw new java.util.NoSuchElementException();
        }
        
        if ( == 0) {
            ((CommonPropertyPanel[1]).setInitialFocus();
        }else if ( == 1) {
            ((CPVendor[2]).setInitialFocus();
        }else if ( == 2){
            ((CPPropertiesPanelPanel[3]).refreshFields();
        }else if ( == 3){
            ((CommonAttributePanel[4]).setPropInitialFocus();
        }
        
         ++;
    }
    
    public synchronized void previousPanel(){
        if ( == 0) {
            throw new java.util.NoSuchElementException();
        }
        
        --;
    }
    
    public WizardDescriptor.Panel current(){
        return (WizardDescriptor.Panel)[];
    }
    
    public final void addChangeListener(ChangeListener l) {
    }
    public final void removeChangeListener(ChangeListener l) {
    }
    public void setResourceConfigHelper(ResourceConfigHelper helper){
        this. = helper;
    }
    
        return this.;
    }
    
    public void stateChanged(javax.swing.event.ChangeEvent e) {
        if( (e.getSource().getClass() == CommonAttributePanel.class) || (e.getSource().getClass() == CommonAttributeVisualPanel.class) ) {
            CommonAttributePanel commonPane = (CommonAttributePanel)this.current();
            CommonAttributeVisualPanel visPane = (CommonAttributeVisualPanel)commonPane.getComponent();
            boolean oldVal = ;
            this. = visPane.isNewResourceSelected();
            
            if((!oldVal && ) || (oldVal && !)){
                this..setHasCPHelper(this.);
                if ( &&  == null) {
                    addPanels();
                    addSteps();
                    for (int i = 0; i < .i++) {
                        Component c = [i].getComponent();
                        if ([i] == null) {
                            [i] = c.getName();
                        }
                        if (c instanceof JComponent) {
                            JComponent jc = (JComponent)c;
                            jc.putClientProperty(.new Integer(i)); // NOI18N
                            jc.putClientProperty(.); // NOI18N
                        }
                    }
                }else if((!) && ( != null)){
                    if( != null){
                         = ;
                         = null;
                    }else
                         = createPanels();
                    if( != null)
                         = ;
                    else
                         = createSteps();
                    
                    for (int i = 0; i < .i++) {
                        Component c = [i].getComponent();
                        if ([i] == null) {
                            [i] = c.getName();
                        }
                        if (c instanceof JComponent) {
                            JComponent jc = (JComponent)c;
                            jc.putClientProperty(.new Integer(i)); // NOI18N
                            jc.putClientProperty(.); // NOI18N
                        }
                    }
                    ((CommonAttributePanel)[0]).setInitialFocus();
                }
            }
        }
    }
    
    protected void addPanels() {
        if ( != null &&  == null) {
            this. = this..addAssociatedHelper();
            this..getData().setResourceName();
            this..setHasCPHelper(true);
            this. = getWizardInfo();
            this..getData().setTargetFileObject(this..getData().getTargetFileObject());
            this..getData().setString("true"); //NOI18N
            
             = new WizardDescriptor.Panel[] {
                [0],
                [1],
                new CPVendor(this.this.),
                new CPPropertiesPanelPanel(this.this.),
                new CommonAttributePanel(this.this.,  new String[] {"pool-setting""pool-setting-2""pool-setting-3"}), //NOI18N
            };
        }
         = ;
         = ;
    }
        
    protected void addSteps() {
        if ( != null &&  == null) {
             = new String[] {
                [0],
                [1],
                [2],
                NbBundle.getMessage(DataSourceWizard.class"TITLE_ConnPoolWizardPanel_dbConn"), // NOI18N
                NbBundle.getMessage(DataSourceWizard.class"TITLE_ConnPoolWizardPanel_properties"), // NOI18N
                NbBundle.getMessage(DataSourceWizard.class"TITLE_ConnPoolWizardPanel_optionalProps"// NOI18N
            };
        }
         = ;
         = ;
    }     

New to GrepCode? Check out our FAQ X