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.actions;
 
 import java.util.List;
 import java.util.Map;

Author(s):
lgao
gmpatil
 
 
 public class OpenJAXBCustomizerAction extends NodeAction  {
     
     private void populateSchemaBindingValues(WizardDescriptor wiz,
                                              Project prj,
                                              Schema schema){
         String name = ProjectUtils.getInformation(prj).getName();
         wiz.putProperty(.schema.getName());
         wiz.putProperty(.name);
                 FileUtil.toFile(prj.getProjectDirectory()));
         wiz.putProperty(.schema.getPackage());
         wiz.putProperty(.schema.getType());
         
         XjcOptions opts = schema.getXjcOptions();
         if (opts != null){
             int i = opts.sizeXjcOption();
             if (i > 0){
                Map<StringBooleanoptions = new HashMap<StringBoolean>();                
                String key = null;
                String value = null;
                Boolean boolVal = null;
                for (int j =0; j < ij++){
                    XjcOption xo = opts.getXjcOption(j);
                    key = xo.getName();
                    value = xo.getValue();
                    boolVal = .;
                    if ((value != null
                            && ("true".equals(value.toLowerCase()))){ //NOI18N
                        boolVal = .;
                    }
                    options.put(keyboolVal);
                }                
                wiz.putProperty(.options);                
            }
        }
        
        SchemaSources sss = schema.getSchemaSources();
        SchemaSource ss = null;
        if (sss != null){
            int sssSize = sss.sizeSchemaSource();
            String origSrcLocType = null;
            if (sssSize > 0){
                List<StringxsdFileList = new ArrayList<String>();                            
                for (int i=0; i < sssSizei++){
                    ss = sss.getSchemaSource(i);
                    xsdFileList.add(ss.getOrigLocation());
                    origSrcLocType = ss.getOrigLocationType();
                }
                
                wiz.putProperty(.,
                        xsdFileList);                
                wiz.putProperty(.
                        origSrcLocType); 
            }
        }
        
        Bindings bindings = schema.getBindings();
        if (bindings != null){
            int numBindings = bindings.sizeBinding();
            if (numBindings > 0){
                List<Stringbs = new ArrayList<String>();
                Binding binding = null;
                for (int i=0; i < numBindings;i++){
                    binding = bindings.getBinding(i);
                    bs.add(binding.getOrigLocation());
                }
                wiz.putProperty(.bs);
            }
        }
        
        Catalog cat = schema.getCatalog();
        if (cat != null){
            if (cat.getOrigLocation() != null){
                wiz.putProperty(.
                        cat.getOrigLocation());
            }
        }
    }
    
    protected void performAction(Node[] activatedNodes) {
        JAXBWizardSchemaNode schemaNode = null;
        Project project = null;
        Schema schema = null;
        
        if (activatedNodes.length == 1){
            final Node theNode = activatedNodes[0];            
            schemaNode = theNode.getLookup().lookup(
                    JAXBWizardSchemaNode.class );
            project = schemaNode.getProject();
            schema = schemaNode.getSchema();
            if ( project != null ) {
                JAXBWizardIterator wizardIter = new JAXBWizardIterator(project);
                WizardDescriptor wd = new WizardDescriptor(
                        wizardIter );
                wd.putProperty(.
                        .);                
                wd.putProperty(
                        .,
                        .);
                wd.putProperty(
                        .
                        .);  
                
                List<StringschemaNames = ProjectHelper.getSchemaNames(project);                
                if (schemaNames != null){
                    schemaNames.remove(schema.getName());
                }
                wd.putProperty(
                        .,
                        schemaNames);
                boolean displayDlg = true;
                wizardIter.initialize(wd);
                populateSchemaBindingValues(wdprojectschema);
                wd.setTitleFormat(new MessageFormat("{0}"));
                
                DialogDisplayer dd = DialogDisplayer.getDefault();
                Dialog dlg = dd.createDialog(wd);
                dlg.setTitle(getDialogTitle()); 
                dlg.getAccessibleContext().setAccessibleDescription(
                        getDialogTitle());
                
                while (displayDlg) {
                    dlg.setVisible(true);                    
                    // Redisplay only if errors
                    displayDlg = false;
                    if ( wd.getValue() == . ) {
                        try {
                            Schema nSchema = ProjectHelper.importResources(project
                                    wdschema);
                            schemaNode.setSchema(nSchema);                        
                            ProjectHelper.changeSchemaInModel(projectschema
                                    nSchema);                        
                            ProjectHelper.cleanCompileXSDs(projecttrue);
                        } catch (Throwable ex) {
                            displayDlg = true;
                            //Exceptions.printStackTrace(ioe);
                            wd = new WizardDescriptor(wizardIter);
                            String msg = NbBundle.getMessage(JAXBWizardIterator.class
                                    "MSG_ErrorReadingSchema");//NOI18N
                            wd.putProperty(.msg); 
                            
                            wd.putProperty(.
                                    .);                
                            wd.putProperty(
                                    .,
                                    .);
                            wd.putProperty(
                                    .
                                    .);  
                            wd.putProperty(.
                                    schemaNames);
                            populateSchemaBindingValues(wdprojectschema);
                            wd.setTitleFormat(new MessageFormat("{0}"));                            
                            wizardIter.initialize(wd);  
                            
                            wd.setValid(false);
                            wd.setMessage(msg);
                            
                            dlg = dd.createDialog(wd);
                            dlg.setTitle(getDialogTitle()); 
                            dlg.getAccessibleContext().setAccessibleDescription(
                                    getDialogTitle());                            
                        }                        
                    }
                }
            }
        }
    }
    
    
    public String getName() {
        return NbBundle.getMessage(
                this.getClass(), "LBL_CustomizeJAXBOptions");//NOI18N
    }
    protected String getDialogTitle(){
        return NbBundle.getMessage(
                this.getClass(), "LBL_DialogTitleChangeBindingOptions");//NOI18N  
    }   
            
    @Override
    protected void initialize() {
        super.initialize();
        // see org.openide.util.actions.SystemAction.iconResource()
        // javadoc for more details
        putValue("noIconInMenu".);
    }
    
    public HelpCtx getHelpCtx() {
        return .;
    }
    
    @Override
    protected boolean asynchronous() {
        return false;
    }
    
    protected boolean enable(Node[] activatedNodes) {
        if ( activatedNodes.length != 1 )
            return false;
        
        DataObject dataobj = activatedNodes[0].getCookie(DataObject.class);
        if ( dataobj != null ) {
            FileObject fo = dataobj.getPrimaryFile();
        }
        
        return true;
    }    
New to GrepCode? Check out our FAQ X