Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * 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.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle 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-2007 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.
  */
 
 package org.netbeans.modules.xml.jaxb.ui;
 
 import java.awt.Image;
 import java.io.File;
 import java.util.List;

Author(s):
gmpatil
lgao
 
 public class JAXBWizardSchemaNode extends AbstractNode {
     private String schemaName;
     private Project project;
     private Schema schema;
     private static Action[] actions = null;
     
     public JAXBWizardSchemaNode(Project projectSchema schema) {
         this(projectschemanew InstanceContent());
         this. = schema.getName();
         this. = project;
         this. = schema;
         this.initActions();                    
     }
 
     private JAXBWizardSchemaNode(Project projectSchema schemaInstanceContent content) {
         super(new JAXBWizardSchemaNodeChildrenprojectschema ), 
                new AbstractLookup(content));
        // adds the node to our own lookup
        content.add (this);
        // adds additional items to the lookup
        //content.add (...);
    }
    
    @Override
    public Action[] getActions(boolean b) {
        return ;
    }
    
    public Schema getSchema(){
        return this.;
    }
    public void setSchema(Schema schm){
        this. = schm;
        Children c = this.getChildren();
        if (c instanceof JAXBWizardSchemaNodeChildren){
                    c;
            jaxbC.setSchema(this.);
        }
    }
    
    public Project getProject(){
        return this.;
    }    
    private void initActions() {
        if (  == null ) {
             = new Action[] {
                SystemAction.get(OpenJAXBCustomizerAction.class),
                null,
                SystemAction.get(DeleteAction.class)
            };
        }
    }
    
    @Override
    public String getDisplayName() {
        return ;
    }
    
    @Override
    public boolean canDestroy(){
        return true;
    }
    
    @Override
    public void destroy() throws IOException {
        super.destroy();
        // Delete schema
        JAXBDeleteSchemaAction delAction = SystemAction.get(
                                                JAXBDeleteSchemaAction.class);
        delAction.performAction(new Node[] {this});
    }
    
    @Override
    public Image getIcon(int type) {
        return ImageUtilities.loadImage"org/netbeans/modules/xml/jaxb/resources/package.gif" ); // No I18N
    }
    
    @Override
    public Image getOpenedIcon(int type) {
        return ImageUtilities.loadImage"org/netbeans/modules/xml/jaxb/resources/packageOpen.gif" ); // No I18N
    }
    
    public static class JAXBWizardSchemaNodeChildren extends Children.Keys{
        private Project project;
        private Schema schema;
        
        public JAXBWizardSchemaNodeChildren(Project prjSchema schema) {
            super();
            this. = schema;
            this. = prj;
            this.addNodify();
        }
        public void addNodify() {
            updateKeys();
            super.addNotify();
        }        
        @Override
        public void removeNotify() {
        }
                
        private void updateKeys(){
            List childrenNodes = new ArrayList();
            SchemaSources sss = this..getSchemaSources();
            SchemaSource[] ss = sss.getSchemaSource();
            Bindings bs  = this..getBindings();
            Catalog cat = this..getCatalog();
            
            if (ss != null){
                for (int i = 0; i < ss.lengthi++){
                     childrenNodes.add(ss[i]);
                }
            }
            
            if ((bs != null) && (bs.sizeBinding() > 0)){
                Binding[] binding = bs.getBinding();
                for (int i = 0; i < binding.lengthi++){
                     childrenNodes.add(binding[i]);
                }
            }
            
            if ((cat != null) && (cat.getLocation() != null)){
                   childrenNodes.add(cat);
            }
            
            super.setKeys(childrenNodes );
        }
        
        public void setSchema(Schema schm){
            this. = schm;
            updateKeys();
        }
       
        public void refreshChildren(){
            updateKeys();
        }
        
        protected Node[] createNodes(Object key) {
            Node[] xsdNodes = null;
            try {
                FileObject prjRoot = .getProjectDirectory();                    
                FileObject xsdFolder = 
                        ProjectHelper.getFOProjectSchemaDir();
                File projDir = FileUtil.toFile(prjRoot);
                FileObject locSchemaRoot = 
                        xsdFolder.getFileObject(.getName());
                
                Node xsdNode = null;
                FileObject fo = null;
                if ( key instanceof SchemaSource ) {
                    SchemaSource ss = (SchemaSourcekey;
                    File tmpFile = null;
                    String originLocType = null;
                    Boolean isURL = .;
                    
                    originLocType = ss.getOrigLocationType();
                    if ((originLocType != null) && 
                            ("url".equals(originLocType))){ //NOI18N
                        isURL = .;
                    }
                    fo = FileUtil.toFileObject(new File(projDir
                            ss.getLocation()));
                    if (fo != null){
                        xsdNode = new JAXBBindingSupportFileNode(fo
                                locSchemaRootisURLss.getOrigLocation());
                        try {
                            DataObject dataObj = DataObject.find(fo);
                            Node delegate = dataObj.getNodeDelegate();
                            ((JAXBBindingSupportFileNode)xsdNode).
                                    setNodeDelegate(delegate);
                        } catch (DataObjectNotFoundException ex){
                            // Use JAXBBindingSupportFileNode
                        }
                        
                    } else {
                        // Log
                        tmpFile = new File(ss.getLocation());
                        fo = xsdFolder.getFileObject(tmpFile.getName());
                        if (fo != null){
                            xsdNode = new JAXBBindingSupportFileNode(
                                    folocSchemaRootisURL
                                    ss.getOrigLocation());
                        }
                    }    
                }
                
                if (key instanceof Binding ) {
                    Binding bndg = (Binding)key;
                    fo = FileUtil.toFileObject(new File(projDir
                            bndg.getLocation()));
                    if (fo != null){
                        xsdNode = new JAXBBindingSupportFileNode(
                                folocSchemaRootfalse
                                bndg.getOrigLocation());                        
                        try {
                            DataObject dataObj = DataObject.find(fo);
                            Node delegate = dataObj.getNodeDelegate();
                            ((JAXBBindingSupportFileNode)xsdNode).
                                    setNodeDelegate(delegate);
                        } catch (DataObjectNotFoundException ex){
                            // Use JAXBBindingSupportFileNode
                        }
                    }                    
                }
                
                if (key instanceof Catalog ) {
                    Catalog cat = (Catalogkey;
                    fo = FileUtil.toFileObject(new File(projDir
                            cat.getLocation()));
                    if (fo != null){
                        xsdNode = new JAXBBindingSupportFileNode(
                                folocSchemaRootfalse
                                cat.getOrigLocation());
                        try {
                            DataObject dataObj = DataObject.find(fo);
                            Node delegate  = dataObj.getNodeDelegate();
                            ((JAXBBindingSupportFileNode)xsdNode).
                                    setNodeDelegate(delegate);                            
                        } catch (DataObjectNotFoundException ex){
                            // Use JAXBBindingSupportFileNode
                        }
                    }
                }
                
                if (xsdNode != null){
                    xsdNodes = new Node[]{xsdNode};
                }                
            } catch ( IntrospectionException inse ) {
                Exceptions.printStackTrace(inse);
            }
            
            return xsdNodes;
        }
    }    
New to GrepCode? Check out our FAQ X