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):
  *
  * Portions Copyrighted 2007 Sun Microsystems, Inc.
  */
 package org.netbeans.modules.xml.jaxb.model;
 
 import java.util.List;

Author(s):
gpatil
 
 @ProjectServiceProvider(service=JAXBWizModel.class, projectType={
     "org-netbeans-modules-java-j2seproject",
     "org-netbeans-modules-web-project",
     "org-netbeans-modules-j2ee-ejbjarproject"
 })
 public class JAXBWizModelImpl implements JAXBWizModel {
     private List<JAXBWizEventListenerlisteners = null;
     private Project project;
     // Do not need to listen to Dir see #110406
     //private JaxbCfgChangeListener jaxbListener = new JaxbCfgChangeListener();
     private boolean swallowCfgFileEditEvent = false;
         
     public JAXBWizModelImpl(Project prj){
         this. = prj;
          // Do not need to listen to Dir see #110406
         //ProjectHelper.addCfgFileChangeListener(project, jaxbListener);
     }
     
     public synchronized void addJAXBWizEventListener(JAXBWizEventListener listener) {
         if (this. == null){
             this. = new ArrayList<JAXBWizEventListener>();
         }
         this..add(listener);
     }
 
     public synchronized void removeJAXBWizEventListener(JAXBWizEventListener listener) {
         if (this. != null){
             this..remove(listener);
         }
     }
     
     public void fireSchemaAddedEvent(Schemas ssSchema schema){
         JAXBWizEvent event = new JAXBWizEventImpl(ssnullschema
                 ..);
         dispatchEvent(event);
     }
     
     public void fireSchemaChangedEvent(Schemas ssSchema oSSchema nS){
         JAXBWizEvent event = new JAXBWizEventImpl(ssoSnS,
                 ..);
         dispatchEvent(event);
     }
 
     public void fireSchemaDeletedEvent(Schemas ssSchema oS){
         JAXBWizEvent event = new JAXBWizEventImpl(ssoSnull,
                 ..);
         dispatchEvent(event);
    }
    public void fireCfgFileEditedEvent(Schemas ss){
        JAXBWizEvent event = new JAXBWizEventImpl(ssnullnull,
                ..);
        dispatchEvent(event);
    }
    
    private void dispatchEvent(JAXBWizEvent event){
        List<JAXBWizEventListenerlss = new ArrayList<JAXBWizEventListener>();
        synchronized (this){
            if (this. != null){
                lss.addAll(this.);
            }
        }
        JAXBWizEvent.JAXBWizEventType  eventType = event.getEventType();
        
        for (JAXBWizEventListener lslss){
            try {                
                switch (eventType){
                    case 
                        ls.bindingAdded(event);
                        break;
                    case 
                        ls.bindingChanged(event);
                        break;
                    case 
                        ls.bindingDeleted(event);
                        break;
                    case :
                        ls.configFileEdited(event);
                        break;                        
                }
            } catch (Exception ex){
                Exceptions.printStackTrace(ex);
            }
        }
    }
    
    public void addSchema(Schema schema){
        Schemas scs = ProjectHelper.getXMLBindingSchemas();
        try {
            synchronized(this){
                this. = true;
            }
            ProjectHelper.addSchema(scsschema);                    
            this.fireSchemaAddedEvent(scsschema);
        } finally {
            synchronized(this){
                this. = false;
            }            
        }
    }
    
    public void changeSchema(Schema osSchema ns){        
        Schemas scs = ProjectHelper.getXMLBindingSchemas();        
        try {
            synchronized(this){
                this. = true;
            }
            ProjectHelper.removeSchema(scsos);
            ProjectHelper.addSchema(scsns);
            this.fireSchemaChangedEvent(scsosns);        
        } finally {
            synchronized(this){
                this. = false;
            }            
        }        
    }    
    
    public void deleteSchema(Schema schema){
        Schemas scs = ProjectHelper.getXMLBindingSchemas();
        try {
            synchronized(this){
                this. = true;
            }
        
            ProjectHelper.removeSchema(scsschema);
            this.fireSchemaDeletedEvent(scsschema);
        } finally {
            synchronized(this){
                this. = false;
            }            
        }        
    }    
    
    private final class JaxbCfgChangeListener extends FileChangeAdapter {
        private void refreshNodes() {
            boolean skipEvent = false;
            synchronized (JAXBWizModelImpl.this){
                skipEvent = JAXBWizModelImpl.this.;
            }
            if (!skipEvent){
                Schemas scs = ProjectHelper.getXMLBindingSchemas();
                JAXBWizModelImpl.this.fireCfgFileEditedEvent(scs);
            }
            
//            SwingUtilities.invokeLater(new Runnable() {
//
//                public void run() {
//                    try {
//                        JAXBRootNodeList.this.rootKeys.clear();
//                        fireChange();
//                    } catch (Exception ex) {
//                        logger.log(Level.WARNING, "refreshing root nodes.", ex);
//                    }
//
//                    try {
//                        updateKeys();
//                    } catch (Exception ex) {
//                        logger.log(Level.WARNING, "refreshing root nodes.", ex);
//                    }
//                    fireChange();
//                }
//            });
        }
        public void fileChanged(FileEvent fe) {
            refreshNodes();
        }
        public void fileRenamed(FileEvent fe) {
            refreshNodes();
        }
        public void fileDataCreated(FileEvent fe) {
            // New file is created, check if config file is created.
            FileObject fo = ProjectHelper.getFOForBindingConfigFile();
            if ((fo != null) && (fo.isValid())) {
                // Remove listening on folder, add for the file
                
                // Do not need to listen to Dir see #110406
                //ProjectHelper.removeModelListner(project, jaxbListener);
                //ProjectHelper.addCfgFileChangeListener(project, jaxbListener);
                refreshNodes();
            } 
        }
        public void fileDeleted(FileEvent fe) {
            refreshNodes();
        }
    }
New to GrepCode? Check out our FAQ X