xml.schema/src/org/netbeans/modules/xml/schema/actions/GenerateXMLAction.java
author Milutin Kristofic <mkristofic@netbeans.org>
Mon, 30 Jan 2017 14:30:54 +0100
changeset 1583 fe20f672a61a
parent 1138 0b115953d06c
permissions -rw-r--r--
Added Missing copyright information in source files
mkristofic@1583
     1
/*
mkristofic@1583
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
mkristofic@1583
     3
 *
mkristofic@1583
     4
 * Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved.
mkristofic@1583
     5
 *
mkristofic@1583
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
mkristofic@1583
     7
 * Other names may be trademarks of their respective owners.
mkristofic@1583
     8
 *
mkristofic@1583
     9
 * The contents of this file are subject to the terms of either the GNU
mkristofic@1583
    10
 * General Public License Version 2 only ("GPL") or the Common
mkristofic@1583
    11
 * Development and Distribution License("CDDL") (collectively, the
mkristofic@1583
    12
 * "License"). You may not use this file except in compliance with the
mkristofic@1583
    13
 * License. You can obtain a copy of the License at
mkristofic@1583
    14
 * http://www.netbeans.org/cddl-gplv2.html
mkristofic@1583
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
mkristofic@1583
    16
 * specific language governing permissions and limitations under the
mkristofic@1583
    17
 * License.  When distributing the software, include this License Header
mkristofic@1583
    18
 * Notice in each file and include the License file at
mkristofic@1583
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
mkristofic@1583
    20
 * particular file as subject to the "Classpath" exception as provided
mkristofic@1583
    21
 * by Oracle in the GPL Version 2 section of the License file that
mkristofic@1583
    22
 * accompanied this code. If applicable, add the following below the
mkristofic@1583
    23
 * License Header, with the fields enclosed by brackets [] replaced by
mkristofic@1583
    24
 * your own identifying information:
mkristofic@1583
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
mkristofic@1583
    26
 *
mkristofic@1583
    27
 * Contributor(s):
mkristofic@1583
    28
 *
mkristofic@1583
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
mkristofic@1583
    30
 * Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun
mkristofic@1583
    31
 * Microsystems, Inc. All Rights Reserved.
mkristofic@1583
    32
 *
mkristofic@1583
    33
 * If you wish your version of this file to be governed by only the CDDL
mkristofic@1583
    34
 * or only the GPL Version 2, indicate your decision by adding
mkristofic@1583
    35
 * "[Contributor] elects to include this software in this distribution
mkristofic@1583
    36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
mkristofic@1583
    37
 * single choice of license, a recipient has the option to distribute
mkristofic@1583
    38
 * your version of this file under either the CDDL, the GPL Version 2 or
mkristofic@1583
    39
 * to extend the choice of license to its licensees as provided above.
mkristofic@1583
    40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
mkristofic@1583
    41
 * Version 2 license, then the option applies only if the new code is
mkristofic@1583
    42
 * made subject to such option by the copyright holder.
mkristofic@1583
    43
 */
sonali@667
    44
/*
sonali@667
    45
 * To change this template, choose Tools | Templates
sonali@667
    46
 * and open the template in the editor.
sonali@667
    47
 */
sonali@667
    48
package org.netbeans.modules.xml.schema.actions;
sonali@667
    49
sonali@667
    50
import org.netbeans.modules.xml.schema.SchemaDataObject;
sonali@667
    51
import org.netbeans.modules.xml.schema.ui.basic.SchemaModelCookie;
sonali@667
    52
import org.netbeans.modules.xml.schema.wizard.SampleXMLGeneratorWizardIterator;
samaresh@1138
    53
import org.netbeans.modules.xml.wizard.SchemaParser;
sonali@667
    54
import org.openide.DialogDisplayer;
sonali@667
    55
import org.openide.nodes.Node;
sonali@667
    56
import org.openide.util.HelpCtx;
sonali@667
    57
import org.openide.util.NbBundle;
sonali@667
    58
import org.openide.util.actions.CookieAction;
sonali@983
    59
import org.openide.NotifyDescriptor;
sonali@667
    60
sonali@667
    61
public final class GenerateXMLAction extends CookieAction {
sonali@667
    62
    
sonali@667
    63
    private static final Class[] COOKIE_ARRAY =
sonali@667
    64
            new Class[] {SchemaModelCookie.class};
sonali@667
    65
sonali@667
    66
    protected void performAction(Node[] activatedNodes) {
sonali@667
    67
         assert activatedNodes.length==1:
sonali@667
    68
            "Length of nodes array should be 1";
sonali@667
    69
        
sonali@667
    70
         if(activatedNodes[0] == null)
sonali@667
    71
             return;
sonali@667
    72
         
sonali@667
    73
         SchemaDataObject sdo = activatedNodes[0].getCookie(SchemaDataObject.class);
sonali@667
    74
         if(sdo == null)
sonali@667
    75
             return;
sonali@983
    76
         
samaresh@1138
    77
         if(SchemaParser.getRootElements(sdo.getPrimaryFile()).roots.size() == 0) {
sonali@983
    78
             //no root elements; cannot generate XML
sonali@983
    79
            NotifyDescriptor desc = new NotifyDescriptor.Message
sonali@983
    80
                                    (NbBundle.getMessage(GenerateXMLAction.class, "MSG_cannot_generate_XML_file"), NotifyDescriptor.ERROR_MESSAGE);
sonali@983
    81
            DialogDisplayer.getDefault().notify (desc);
sonali@983
    82
            return;
sonali@983
    83
         }
sonali@983
    84
        
sonali@667
    85
         SampleXMLGeneratorWizardIterator wizard = new SampleXMLGeneratorWizardIterator(sdo);
sonali@667
    86
         wizard.show();
sonali@667
    87
               
sonali@667
    88
    }
sonali@667
    89
sonali@667
    90
    protected int mode() {
sonali@667
    91
        return CookieAction.MODE_EXACTLY_ONE;
sonali@667
    92
    }
sonali@667
    93
sonali@667
    94
    public String getName() {
sonali@667
    95
        return NbBundle.getMessage(GenerateXMLAction.class, "CTL_GenerateXMLAction");
sonali@667
    96
    }
sonali@667
    97
sonali@667
    98
    protected Class[] cookieClasses() {
sonali@667
    99
        return COOKIE_ARRAY;
sonali@667
   100
    }
sonali@667
   101
sonali@667
   102
    @Override
sonali@667
   103
    protected void initialize() {
sonali@667
   104
        super.initialize();
sonali@667
   105
        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
sonali@667
   106
        putValue("noIconInMenu", Boolean.TRUE);
sonali@667
   107
    }
sonali@667
   108
sonali@667
   109
    public HelpCtx getHelpCtx() {
sonali@667
   110
        return HelpCtx.DEFAULT_HELP;
sonali@667
   111
    }
sonali@667
   112
sonali@667
   113
    @Override
sonali@667
   114
    protected boolean asynchronous() {
sonali@667
   115
        return false;
sonali@667
   116
    }
sonali@667
   117
}
sonali@667
   118