xml.schema.ui.basic/src/org/netbeans/modules/xml/schema/ui/nodes/categorized/customizer/ComplexTypeCustomizer.java
author Svata Dedic <sdedic@netbeans.org>
Tue, 30 Oct 2012 16:47:50 +0100
changeset 1578 f93ef9fcf584
parent 1328 c1e336e0199e
child 1579 e5512c829073
permissions -rw-r--r--
Bugfix #215583: avoiding NPE
abadea@61
     1
/*
sonali@553
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
sonali@553
     3
 *
jglick@1328
     4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
jglick@1328
     5
 *
jglick@1328
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
jglick@1328
     7
 * Other names may be trademarks of their respective owners.
sonali@553
     8
 *
sonali@553
     9
 * The contents of this file are subject to the terms of either the GNU
sonali@553
    10
 * General Public License Version 2 only ("GPL") or the Common
sonali@553
    11
 * Development and Distribution License("CDDL") (collectively, the
sonali@553
    12
 * "License"). You may not use this file except in compliance with the
sonali@553
    13
 * License. You can obtain a copy of the License at
sonali@553
    14
 * http://www.netbeans.org/cddl-gplv2.html
sonali@553
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
sonali@553
    16
 * specific language governing permissions and limitations under the
sonali@553
    17
 * License.  When distributing the software, include this License Header
sonali@553
    18
 * Notice in each file and include the License file at
jglick@1328
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
sonali@553
    20
 * particular file as subject to the "Classpath" exception as provided
jglick@1328
    21
 * by Oracle in the GPL Version 2 section of the License file that
sonali@553
    22
 * accompanied this code. If applicable, add the following below the
sonali@553
    23
 * License Header, with the fields enclosed by brackets [] replaced by
sonali@553
    24
 * your own identifying information:
abadea@61
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
sonali@553
    26
 *
sonali@553
    27
 * Contributor(s):
sonali@553
    28
 *
abadea@61
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
samaresh@116
    30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
abadea@61
    31
 * Microsystems, Inc. All Rights Reserved.
sonali@553
    32
 *
sonali@553
    33
 * If you wish your version of this file to be governed by only the CDDL
sonali@553
    34
 * or only the GPL Version 2, indicate your decision by adding
sonali@553
    35
 * "[Contributor] elects to include this software in this distribution
sonali@553
    36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
sonali@553
    37
 * single choice of license, a recipient has the option to distribute
sonali@553
    38
 * your version of this file under either the CDDL, the GPL Version 2 or
sonali@553
    39
 * to extend the choice of license to its licensees as provided above.
sonali@553
    40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
sonali@553
    41
 * Version 2 license, then the option applies only if the new code is
sonali@553
    42
 * made subject to such option by the copyright holder.
abadea@61
    43
 */
abadea@61
    44
abadea@61
    45
package org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer;
abadea@61
    46
abadea@61
    47
import java.awt.CardLayout;
abadea@61
    48
import java.awt.event.ItemEvent;
abadea@61
    49
import java.awt.event.ItemListener;
abadea@61
    50
import java.beans.PropertyChangeEvent;
abadea@61
    51
import java.beans.PropertyChangeListener;
abadea@61
    52
import java.io.IOException;
abadea@61
    53
import java.util.ArrayList;
abadea@61
    54
import java.util.Collections;
abadea@61
    55
import javax.swing.DefaultComboBoxModel;
abadea@61
    56
import javax.swing.event.DocumentEvent;
abadea@61
    57
import javax.swing.event.DocumentListener;
abadea@61
    58
abadea@61
    59
import org.netbeans.modules.xml.schema.model.All;
abadea@61
    60
import org.netbeans.modules.xml.schema.model.AnyAttribute;
abadea@61
    61
import org.netbeans.modules.xml.schema.model.AttributeGroupReference;
abadea@61
    62
import org.netbeans.modules.xml.schema.model.AttributeReference;
abadea@61
    63
import org.netbeans.modules.xml.schema.model.Choice;
abadea@61
    64
import org.netbeans.modules.xml.schema.model.ComplexContent;
abadea@61
    65
import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
abadea@61
    66
import org.netbeans.modules.xml.schema.model.ComplexExtension;
abadea@61
    67
import org.netbeans.modules.xml.schema.model.ComplexExtensionDefinition;
abadea@61
    68
import org.netbeans.modules.xml.schema.model.ComplexType;
abadea@61
    69
import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
sdedic@1578
    70
import org.netbeans.modules.xml.schema.model.Extension;
abadea@61
    71
import org.netbeans.modules.xml.schema.model.GlobalComplexType;
abadea@61
    72
import org.netbeans.modules.xml.schema.model.GlobalGroup;
abadea@61
    73
import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
abadea@61
    74
import org.netbeans.modules.xml.schema.model.GlobalType;
abadea@61
    75
import org.netbeans.modules.xml.schema.model.GroupReference;
abadea@61
    76
import org.netbeans.modules.xml.schema.model.LocalAttribute;
abadea@61
    77
import org.netbeans.modules.xml.schema.model.LocalAttributeContainer;
abadea@61
    78
import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
abadea@61
    79
import org.netbeans.modules.xml.schema.model.SchemaComponent;
abadea@61
    80
import org.netbeans.modules.xml.schema.model.SchemaComponentFactory;
abadea@61
    81
import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
abadea@61
    82
import org.netbeans.modules.xml.schema.model.SchemaModel;
abadea@61
    83
import org.netbeans.modules.xml.schema.model.Sequence;
abadea@61
    84
import org.netbeans.modules.xml.schema.model.SimpleContent;
abadea@61
    85
import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
abadea@61
    86
import org.netbeans.modules.xml.schema.model.SimpleExtension;
abadea@61
    87
import org.netbeans.modules.xml.schema.ui.basic.editors.SchemaComponentSelectionPanel;
sdedic@1578
    88
import org.netbeans.modules.xml.xam.Reference;
abadea@61
    89
import org.netbeans.modules.xml.xam.ui.customizer.MessageDisplayer;
abadea@61
    90
import org.openide.util.HelpCtx;
abadea@61
    91
import org.openide.util.NbBundle;
abadea@61
    92
abadea@61
    93
/**
abadea@61
    94
 *
abadea@61
    95
 * @author  Ajit Bhate
abadea@61
    96
 */
abadea@61
    97
public class ComplexTypeCustomizer<T extends ComplexType>
abadea@61
    98
        extends AbstractSchemaComponentCustomizer<T>
abadea@61
    99
        implements PropertyChangeListener {
abadea@61
   100
    
abadea@61
   101
    static final long serialVersionUID = 1L;
abadea@61
   102
    /** Creates new form ComplexTypeCustomizer */
abadea@61
   103
    public ComplexTypeCustomizer(SchemaComponentReference<T> reference,
abadea@61
   104
            SchemaComponent parent) {
abadea@61
   105
        super(reference, parent);
abadea@61
   106
        initComponents();
abadea@61
   107
        reset();
abadea@61
   108
    }
abadea@61
   109
    
abadea@61
   110
    /** Creates new form ComplexTypeCustomizer */
abadea@61
   111
    public ComplexTypeCustomizer(SchemaComponentReference<T> reference) {
abadea@61
   112
        this(reference,null);
abadea@61
   113
    }
abadea@61
   114
    
sdedic@1578
   115
    static GlobalType getBase(Extension ext) {
sdedic@1578
   116
        Reference<GlobalType> ref = ext.getBase();
sdedic@1578
   117
        return ref == null ? null : ref.get();
sdedic@1578
   118
    }
sdedic@1578
   119
    
abadea@61
   120
    /**
abadea@61
   121
     * non UI component (model) initialization and access methods
abadea@61
   122
     */
abadea@61
   123
    
abadea@61
   124
    /**
abadea@61
   125
     * Initializes non ui from model
abadea@61
   126
     */
abadea@61
   127
    private void initialize() {
abadea@61
   128
        ComplexType type = getSchemaComponent();
abadea@61
   129
        if(type==null) return;
abadea@61
   130
        ComplexTypeDefinition definition =type.getDefinition();
abadea@61
   131
        contentType = ContentType.NoType;
abadea@61
   132
        if(definition instanceof All) {
abadea@61
   133
            contentType = ContentType.All;
abadea@61
   134
        } else if(definition instanceof Choice) {
abadea@61
   135
            contentType = ContentType.Choice;
abadea@61
   136
        } else if(definition instanceof Sequence) {
abadea@61
   137
            contentType = ContentType.Sequence;
abadea@61
   138
        } else if(definition instanceof GroupReference) {
abadea@61
   139
            contentType = ContentType.Group;
abadea@61
   140
            gRef = ((GroupReference)definition).getRef().get();
abadea@61
   141
        } else if(definition instanceof ComplexContent) {
abadea@61
   142
            ComplexContent cc = (ComplexContent)definition;
abadea@61
   143
            if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
abadea@61
   144
                contentType = ContentType.Restriction;
abadea@61
   145
                ComplexContentRestriction ccr =
abadea@61
   146
                        (ComplexContentRestriction)cc.getLocalDefinition();
sdedic@1578
   147
                gRef = getBase(ccr);
abadea@61
   148
                ComplexTypeDefinition innerDefinition = ccr.getDefinition();
abadea@61
   149
                if(innerDefinition instanceof All) {
abadea@61
   150
                    innerContentType = ContentType.All;
abadea@61
   151
                } else if(innerDefinition instanceof Choice) {
abadea@61
   152
                    innerContentType = ContentType.Choice;
abadea@61
   153
                } else if(innerDefinition instanceof Sequence) {
abadea@61
   154
                    innerContentType = ContentType.Sequence;
abadea@61
   155
                } else if(innerDefinition instanceof GroupReference) {
abadea@61
   156
                    innerContentType = ContentType.Group;
abadea@61
   157
                }
abadea@61
   158
            } else if(cc.getLocalDefinition() instanceof ComplexExtension) {
abadea@61
   159
                contentType = ContentType.Extension;
abadea@61
   160
                ComplexExtension ce =
abadea@61
   161
                        (ComplexExtension)cc.getLocalDefinition();
sdedic@1578
   162
                gRef = getBase(ce);
abadea@61
   163
                ComplexExtensionDefinition innerDefinition = ce.getLocalDefinition();
abadea@61
   164
                if(innerDefinition instanceof All) {
abadea@61
   165
                    innerContentType = ContentType.All;
abadea@61
   166
                } else if(innerDefinition instanceof Choice) {
abadea@61
   167
                    innerContentType = ContentType.Choice;
abadea@61
   168
                } else if(innerDefinition instanceof Sequence) {
abadea@61
   169
                    innerContentType = ContentType.Sequence;
abadea@61
   170
                } else if(innerDefinition instanceof GroupReference) {
abadea@61
   171
                    innerContentType = ContentType.Group;
abadea@61
   172
                } else {
abadea@61
   173
                    innerContentType = ContentType.NoType;
abadea@61
   174
                }
abadea@61
   175
            }
abadea@61
   176
        } else if(definition instanceof SimpleContent) {
abadea@61
   177
            SimpleContent sc = (SimpleContent)definition;
abadea@61
   178
            if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
abadea@61
   179
                contentType = ContentType.Restriction;
abadea@61
   180
                SimpleContentRestriction scr =
abadea@61
   181
                        (SimpleContentRestriction)sc.getLocalDefinition();
sdedic@1578
   182
                Reference<GlobalType> ref = scr.getBase();
sdedic@1578
   183
                gRef = ref == null ? null : ref.get();
abadea@61
   184
            } else if(sc.getLocalDefinition() instanceof SimpleExtension) {
abadea@61
   185
                contentType = ContentType.Extension;
sdedic@1578
   186
                gRef = getBase(((SimpleExtension)sc.getLocalDefinition()));
abadea@61
   187
            }
abadea@61
   188
        }
abadea@61
   189
    }
abadea@61
   190
    
abadea@61
   191
    private ContentType getModelContentType() {
abadea@61
   192
        return contentType;
abadea@61
   193
    }
abadea@61
   194
    
abadea@61
   195
    private ContentType getModelInnerContentType() {
abadea@61
   196
        return innerContentType;
abadea@61
   197
    }
abadea@61
   198
    
abadea@61
   199
    private ReferenceableSchemaComponent getModelReference() {
abadea@61
   200
        return gRef;
abadea@61
   201
    }
abadea@61
   202
    
abadea@61
   203
    /**
abadea@61
   204
     * UI component initialization and access methods
abadea@61
   205
     */
abadea@61
   206
    
abadea@61
   207
    /**
abadea@61
   208
     * Initializes ui elements
abadea@61
   209
     */
abadea@61
   210
    private void initializeUI() {
abadea@61
   211
        getMessageDisplayer().clear();
abadea@61
   212
        if(isNameable()) {
abadea@61
   213
            nameTextField.setText(_getName());
abadea@61
   214
            if(!hasParent()) nameTextField.setSelectionStart(0);
abadea@61
   215
        } else {
abadea@61
   216
            namePanel.setVisible(false);
abadea@61
   217
        }
abadea@61
   218
        
abadea@61
   219
        if(getModelContentType()==null) {
abadea@61
   220
            inlineDefinitionButton.setSelected(true);
abadea@61
   221
        } else {
abadea@61
   222
            switch(getModelContentType()) {
abadea@61
   223
                case NoType:
abadea@61
   224
                    inlineDefinitionButton.setSelected(true);
abadea@61
   225
                    noTypeButton.setSelected(true);
abadea@61
   226
                    break;
abadea@61
   227
                case Sequence:
abadea@61
   228
                    inlineDefinitionButton.setSelected(true);
abadea@61
   229
                    sequenceButton.setSelected(true);
abadea@61
   230
                    break;
abadea@61
   231
                case Choice:
abadea@61
   232
                    inlineDefinitionButton.setSelected(true);
abadea@61
   233
                    choiceButton.setSelected(true);
abadea@61
   234
                    break;
abadea@61
   235
                case All:
abadea@61
   236
                    inlineDefinitionButton.setSelected(true);
abadea@61
   237
                    allButton.setSelected(true);
abadea@61
   238
                    break;
abadea@61
   239
                case Group:
abadea@61
   240
                    existingDefinitionButton.setSelected(true);
abadea@61
   241
                    groupButton.setSelected(true);
abadea@61
   242
                    break;
abadea@61
   243
                case Extension:
abadea@61
   244
                    existingDefinitionButton.setSelected(true);
abadea@61
   245
                    extensionButton.setSelected(true);
abadea@61
   246
                    innerContentComboBox.setSelectedItem(getModelInnerContentType());
abadea@61
   247
                    break;
abadea@61
   248
                case Restriction:
abadea@61
   249
                    existingDefinitionButton.setSelected(true);
abadea@61
   250
                    restrictionButton.setSelected(true);
abadea@61
   251
                    break;
abadea@61
   252
            }
abadea@61
   253
        }
abadea@61
   254
        switchDefinitionPanels();
abadea@61
   255
        selectModelNode();
abadea@61
   256
        enableDisableComboBox();
abadea@61
   257
        setPreviewText();
abadea@61
   258
    }
abadea@61
   259
    
abadea@61
   260
    private void enableDisableComboBox() {
abadea@61
   261
        if(getUIContentType()==ContentType.Extension &&
abadea@61
   262
                getUIReference() instanceof GlobalComplexType &&
abadea@61
   263
                !(((GlobalComplexType)getUIReference()).getDefinition()
abadea@61
   264
                instanceof SimpleContent)) {
abadea@61
   265
            innerContentLabel.setEnabled(true);
abadea@61
   266
            innerContentComboBox.setEnabled(true);
abadea@61
   267
            if(innerContentComboBox.getSelectedItem()==null)
abadea@61
   268
                innerContentComboBox.setSelectedIndex(0);
abadea@61
   269
        } else {
abadea@61
   270
            innerContentLabel.setEnabled(false);
abadea@61
   271
            innerContentComboBox.setEnabled(false);
abadea@61
   272
        }
abadea@61
   273
    }
abadea@61
   274
    
abadea@61
   275
    /**
abadea@61
   276
     * enables disables the inner base type panel and inner content combo box.
abadea@61
   277
     */
abadea@61
   278
    private void switchDefinitionPanels() {
abadea@61
   279
        if(existingDefinitionButton.isSelected()) {
abadea@61
   280
            ((CardLayout)definitionPanel.getLayout()).show(definitionPanel,"reference"); //NO I18N
abadea@61
   281
            if(referenceButtonGroup.getSelection()==null)
abadea@61
   282
                referenceButtonGroup.getElements().nextElement().setSelected(true);
abadea@61
   283
            //groupButton.setSelected(true);
abadea@61
   284
            switchInnerContentPanels();
abadea@61
   285
        } else {
abadea@61
   286
            ((CardLayout)definitionPanel.getLayout()).show(definitionPanel,"compositor"); //NO I18N
abadea@61
   287
            if(compositorButtonGroup.getSelection()==null)
abadea@61
   288
                compositorButtonGroup.getElements().nextElement().setSelected(true);
abadea@61
   289
//				sequenceButton.setSelected(true);
abadea@61
   290
        }
abadea@61
   291
        enableDisableComboBox();
abadea@61
   292
    }
abadea@61
   293
    
abadea@61
   294
    private void switchInnerContentPanels() {
abadea@61
   295
        if(groupButton.isSelected())
abadea@61
   296
            ((CardLayout)innerContentPanel.getLayout()).show(innerContentPanel,"group");
abadea@61
   297
        else
abadea@61
   298
            ((CardLayout)innerContentPanel.getLayout()).show(innerContentPanel,"type");
abadea@61
   299
    }
abadea@61
   300
    
abadea@61
   301
    /**
abadea@61
   302
     * selects model node on ui
abadea@61
   303
     */
abadea@61
   304
    private void selectModelNode() {
abadea@61
   305
        switch(getUIContentType()) {
abadea@61
   306
            case Group:
abadea@61
   307
                groupSelectionPanel.setInitialSelection((GlobalGroup)getModelReference());
abadea@61
   308
                break;
abadea@61
   309
            case Extension:
abadea@61
   310
            case Restriction:
abadea@61
   311
                typeSelectionPanel.setInitialSelection((GlobalType)getModelReference());
abadea@61
   312
                break;
abadea@61
   313
            default:
abadea@61
   314
        }
abadea@61
   315
    }
abadea@61
   316
    
abadea@61
   317
    /**
abadea@61
   318
     * adds listeners
abadea@61
   319
     */
abadea@61
   320
    private void addListeners() {
abadea@61
   321
        if(isNameable()) {
abadea@61
   322
            if (nameListener == null) {
abadea@61
   323
                nameListener = new DocumentListener() {
abadea@61
   324
                    public void changedUpdate(DocumentEvent e) {
abadea@61
   325
                        setPreviewText();
abadea@61
   326
                        determineValidity();
abadea@61
   327
                    }
abadea@61
   328
                    public void insertUpdate(DocumentEvent e) {
abadea@61
   329
                        setPreviewText();
abadea@61
   330
                        determineValidity();
abadea@61
   331
                    }
abadea@61
   332
                    public void removeUpdate(DocumentEvent e) {
abadea@61
   333
                        setPreviewText();
abadea@61
   334
                        determineValidity();
abadea@61
   335
                    }
abadea@61
   336
                };
abadea@61
   337
            }
abadea@61
   338
            nameTextField.getDocument().addDocumentListener(nameListener);
abadea@61
   339
        }
abadea@61
   340
        if (buttonListener ==null) {
abadea@61
   341
            buttonListener = new ItemListener() {
abadea@61
   342
                public void itemStateChanged(ItemEvent evt) {
abadea@61
   343
                    Object source = evt.getSource();
abadea@61
   344
                    if(source==extensionButton) {
abadea@61
   345
                        enableDisableComboBox();
abadea@61
   346
                    }
abadea@61
   347
                    if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
abadea@61
   348
                        if(source==inlineDefinitionButton ||
abadea@61
   349
                                source==existingDefinitionButton) {
abadea@61
   350
                            switchDefinitionPanels();
abadea@61
   351
                        }
abadea@61
   352
                        if(source==groupButton ||
abadea@61
   353
                                source==extensionButton ||
abadea@61
   354
                                source==restrictionButton) {
abadea@61
   355
                            switchInnerContentPanels();
abadea@61
   356
                        }
abadea@61
   357
                        setPreviewText();
abadea@61
   358
                        determineValidity();
abadea@61
   359
                    }
abadea@61
   360
                }
abadea@61
   361
            };
abadea@61
   362
        }
abadea@61
   363
        inlineDefinitionButton.addItemListener(buttonListener);
abadea@61
   364
        existingDefinitionButton.addItemListener(buttonListener);
abadea@61
   365
        noTypeButton.addItemListener(buttonListener);
abadea@61
   366
        sequenceButton.addItemListener(buttonListener);
abadea@61
   367
        allButton.addItemListener(buttonListener);
abadea@61
   368
        choiceButton.addItemListener(buttonListener);
abadea@61
   369
        groupButton.addItemListener(buttonListener);
abadea@61
   370
        extensionButton.addItemListener(buttonListener);
abadea@61
   371
        restrictionButton.addItemListener(buttonListener);
abadea@61
   372
        innerContentComboBox.addItemListener(buttonListener);
abadea@61
   373
    }
abadea@61
   374
    
abadea@61
   375
    /**
abadea@61
   376
     * removes listeners
abadea@61
   377
     */
abadea@61
   378
    private void removeListeners() {
abadea@61
   379
        if(isNameable()) nameTextField.getDocument().removeDocumentListener(nameListener);
abadea@61
   380
        inlineDefinitionButton.removeItemListener(buttonListener);
abadea@61
   381
        existingDefinitionButton.removeItemListener(buttonListener);
abadea@61
   382
        noTypeButton.removeItemListener(buttonListener);
abadea@61
   383
        sequenceButton.removeItemListener(buttonListener);
abadea@61
   384
        allButton.removeItemListener(buttonListener);
abadea@61
   385
        choiceButton.removeItemListener(buttonListener);
abadea@61
   386
        groupButton.removeItemListener(buttonListener);
abadea@61
   387
        extensionButton.removeItemListener(buttonListener);
abadea@61
   388
        restrictionButton.removeItemListener(buttonListener);
abadea@61
   389
        innerContentComboBox.removeItemListener(buttonListener);
abadea@61
   390
    }
abadea@61
   391
    
abadea@61
   392
    /**
abadea@61
   393
     * returns name from ui name text field
abadea@61
   394
     */
abadea@61
   395
    protected String getUIName() {
abadea@61
   396
        return nameTextField.getText();
abadea@61
   397
    }
abadea@61
   398
    
abadea@61
   399
    /**
abadea@61
   400
     * returns ui content type selection from content list
abadea@61
   401
     */
abadea@61
   402
    private ContentType getUIContentType() {
abadea@61
   403
        if(inlineDefinitionButton.isSelected()) {
abadea@61
   404
            if(noTypeButton.isSelected())
abadea@61
   405
                return ContentType.NoType;
abadea@61
   406
            if(sequenceButton.isSelected())
abadea@61
   407
                return ContentType.Sequence;
abadea@61
   408
            if(choiceButton.isSelected())
abadea@61
   409
                return ContentType.Choice;
abadea@61
   410
            if(allButton.isSelected())
abadea@61
   411
                return ContentType.All;
abadea@61
   412
        }
abadea@61
   413
        if(existingDefinitionButton.isSelected()) {
abadea@61
   414
            if(groupButton.isSelected())
abadea@61
   415
                return ContentType.Group;
abadea@61
   416
            if(extensionButton.isSelected())
abadea@61
   417
                return ContentType.Extension;
abadea@61
   418
            if(restrictionButton.isSelected())
abadea@61
   419
                return ContentType.Restriction;
abadea@61
   420
        }
abadea@61
   421
        return null;
abadea@61
   422
    }
abadea@61
   423
    
abadea@61
   424
    /**
abadea@61
   425
     * returns ui inner content type selection from inner content combo box
abadea@61
   426
     */
abadea@61
   427
    private ContentType getUIInnerContentType() {
abadea@61
   428
        if (!innerContentComboBox.isEnabled())
abadea@61
   429
            return null;
abadea@61
   430
        return (ContentType) innerContentComboBox.getSelectedItem();
abadea@61
   431
    }
abadea@61
   432
    
abadea@61
   433
    /**
abadea@61
   434
     * returns ui reference selection from inner type/ref panel
abadea@61
   435
     */
abadea@61
   436
    private ReferenceableSchemaComponent getUIReference() {
abadea@61
   437
        switch(getUIContentType()) {
abadea@61
   438
            case Group:
abadea@61
   439
                return groupSelectionPanel.getCurrentSelection();
abadea@61
   440
            case Extension:
abadea@61
   441
            case Restriction:
abadea@61
   442
                return typeSelectionPanel.getCurrentSelection();
abadea@61
   443
            default:
abadea@61
   444
        }
abadea@61
   445
        return null;
abadea@61
   446
    }
abadea@61
   447
    
abadea@61
   448
    /**
abadea@61
   449
     * initializes the base type (group ref) panel, with view and explorer
abadea@61
   450
     *
abadea@61
   451
     */
abadea@61
   452
    private void initializeTypePanel() {
abadea@61
   453
        typeSelectionPanel = new SchemaComponentSelectionPanel<GlobalType>(
abadea@61
   454
                getReference().get().getModel(),GlobalType.class, null,
abadea@61
   455
                Collections.singleton(getReference().get()), true);
abadea@61
   456
        typeSelectionPanel.addPropertyChangeListener(this);
abadea@61
   457
        groupSelectionPanel = new SchemaComponentSelectionPanel<GlobalGroup>(
abadea@61
   458
                getReference().get().getModel(),GlobalGroup.class, null, null, false);
abadea@61
   459
        groupSelectionPanel.addPropertyChangeListener(this);
abadea@61
   460
        innerContentPanel.add(groupSelectionPanel.getTypeSelectionPanel(),"group");
abadea@61
   461
        innerContentPanel.add(typeSelectionPanel.getTypeSelectionPanel(),"type");
abadea@61
   462
        typeSelectionPanel.getTypeSelectionPanel().getAccessibleContext().
abadea@61
   463
                setAccessibleParent(innerContentPanel);
abadea@61
   464
        groupSelectionPanel.getTypeSelectionPanel().getAccessibleContext().
abadea@61
   465
                setAccessibleParent(innerContentPanel);
abadea@61
   466
    }
abadea@61
   467
    
abadea@61
   468
    private Class<? extends ReferenceableSchemaComponent> getReferenceType() {
abadea@61
   469
        ArrayList<Class<? extends SchemaComponent>> childTypes =
abadea@61
   470
                new ArrayList<Class<? extends SchemaComponent>>();
abadea@61
   471
        switch(getUIContentType()) {
abadea@61
   472
            case Group:
abadea@61
   473
                return GlobalGroup.class;
abadea@61
   474
            case Extension:
abadea@61
   475
            case Restriction:
abadea@61
   476
                return GlobalType.class;
abadea@61
   477
            default:
abadea@61
   478
        }
abadea@61
   479
        return null;
abadea@61
   480
    }
abadea@61
   481
    /** This method is called from within the constructor to
abadea@61
   482
     * initialize the form.
abadea@61
   483
     * WARNING: Do NOT modify this code. The content of this method is
abadea@61
   484
     * always regenerated by the Form Editor.
abadea@61
   485
     */
abadea@61
   486
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
abadea@61
   487
    private void initComponents() {
abadea@61
   488
        compositorButtonGroup = new javax.swing.ButtonGroup();
abadea@61
   489
        definitionButtonGroup = new javax.swing.ButtonGroup();
abadea@61
   490
        referenceButtonGroup = new javax.swing.ButtonGroup();
abadea@61
   491
        previewLabel = new javax.swing.JLabel();
abadea@61
   492
        jScrollPane1 = new javax.swing.JScrollPane();
abadea@61
   493
        previewPane = new javax.swing.JEditorPane() {
abadea@61
   494
            static final long serialVersionUID = 1L;
abadea@61
   495
            // disable mouse and mouse motion events
abadea@61
   496
            protected void processMouseEvent(java.awt.event.MouseEvent e) {
abadea@61
   497
                e.consume();
abadea@61
   498
            }
abadea@61
   499
            protected void processMouseMotionEvent(java.awt.event.MouseEvent e) {
abadea@61
   500
                e.consume();
abadea@61
   501
            }
abadea@61
   502
        };
abadea@61
   503
        definitionPanel = new javax.swing.JPanel();
abadea@61
   504
        compositorPanel = new javax.swing.JPanel();
abadea@61
   505
        sequenceButton = new javax.swing.JRadioButton();
abadea@61
   506
        choiceButton = new javax.swing.JRadioButton();
abadea@61
   507
        allButton = new javax.swing.JRadioButton();
abadea@61
   508
        noTypeButton = new javax.swing.JRadioButton();
abadea@61
   509
        compositorLabel = new javax.swing.JLabel();
abadea@61
   510
        referencePanel = new javax.swing.JPanel();
abadea@61
   511
        extensionButton = new javax.swing.JRadioButton();
abadea@61
   512
        restrictionButton = new javax.swing.JRadioButton();
abadea@61
   513
        groupButton = new javax.swing.JRadioButton();
abadea@61
   514
        innerContentLabel = new javax.swing.JLabel();
abadea@61
   515
        innerContentComboBox = new javax.swing.JComboBox();
abadea@61
   516
        innerContentPanel = new javax.swing.JPanel();
abadea@61
   517
        referenceLabel = new javax.swing.JLabel();
abadea@61
   518
        typeLabel = new javax.swing.JLabel();
abadea@61
   519
        inlineDefinitionButton = new javax.swing.JRadioButton();
abadea@61
   520
        existingDefinitionButton = new javax.swing.JRadioButton();
abadea@61
   521
        mPanel = new javax.swing.JPanel();
abadea@61
   522
        namePanel = new javax.swing.JPanel();
abadea@61
   523
        nameLabel = new javax.swing.JLabel();
abadea@61
   524
        nameTextField = new javax.swing.JTextField();
abadea@61
   525
abadea@61
   526
        previewLabel.setLabelFor(previewPane);
abadea@61
   527
        org.openide.awt.Mnemonics.setLocalizedText(previewLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "TITLE_CustomizerForm_Preview"));
abadea@61
   528
        previewLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Preview"));
abadea@61
   529
abadea@61
   530
        previewPane.setEditable(false);
abadea@61
   531
        previewPane.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Preview"));
abadea@61
   532
        previewPane.setContentType("text/xml");
abadea@61
   533
        previewPane.setEnabled(false);
abadea@61
   534
        jScrollPane1.setViewportView(previewPane);
abadea@61
   535
abadea@61
   536
        definitionPanel.setLayout(new java.awt.CardLayout());
abadea@61
   537
abadea@61
   538
        definitionPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
abadea@61
   539
        compositorButtonGroup.add(sequenceButton);
abadea@61
   540
        org.openide.awt.Mnemonics.setLocalizedText(sequenceButton, ContentType.Sequence.getLabel());
abadea@61
   541
        sequenceButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Sequence"));
abadea@61
   542
        sequenceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   543
        sequenceButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   544
abadea@61
   545
        compositorButtonGroup.add(choiceButton);
abadea@61
   546
        org.openide.awt.Mnemonics.setLocalizedText(choiceButton, ContentType.Choice.getLabel());
abadea@61
   547
        choiceButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Choice"));
abadea@61
   548
        choiceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   549
        choiceButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   550
abadea@61
   551
        compositorButtonGroup.add(allButton);
abadea@61
   552
        org.openide.awt.Mnemonics.setLocalizedText(allButton, ContentType.All.getLabel());
abadea@61
   553
        allButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_All"));
abadea@61
   554
        allButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   555
        allButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   556
abadea@61
   557
        compositorButtonGroup.add(noTypeButton);
abadea@61
   558
        org.openide.awt.Mnemonics.setLocalizedText(noTypeButton, ContentType.NoType.getLabel());
abadea@61
   559
        noTypeButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_NoType"));
abadea@61
   560
        noTypeButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   561
        noTypeButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   562
abadea@61
   563
        org.openide.awt.Mnemonics.setLocalizedText(compositorLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Inline_Definition_Panel", new Object[] {}));
abadea@61
   564
        compositorLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Inline_Definition_Panel"));
abadea@61
   565
abadea@61
   566
        org.jdesktop.layout.GroupLayout compositorPanelLayout = new org.jdesktop.layout.GroupLayout(compositorPanel);
abadea@61
   567
        compositorPanel.setLayout(compositorPanelLayout);
abadea@61
   568
        compositorPanelLayout.setHorizontalGroup(
abadea@61
   569
            compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   570
            .add(compositorPanelLayout.createSequentialGroup()
abadea@61
   571
                .add(compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   572
                    .add(compositorLabel)
abadea@61
   573
                    .add(compositorPanelLayout.createSequentialGroup()
abadea@61
   574
                        .add(11, 11, 11)
abadea@61
   575
                        .add(compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   576
                            .add(sequenceButton)
abadea@61
   577
                            .add(choiceButton)
abadea@61
   578
                            .add(allButton)
abadea@61
   579
                            .add(noTypeButton))))
abadea@61
   580
                .addContainerGap(384, Short.MAX_VALUE))
abadea@61
   581
        );
abadea@61
   582
        compositorPanelLayout.setVerticalGroup(
abadea@61
   583
            compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   584
            .add(compositorPanelLayout.createSequentialGroup()
abadea@61
   585
                .add(compositorLabel)
abadea@61
   586
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   587
                .add(sequenceButton)
abadea@61
   588
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   589
                .add(choiceButton)
abadea@61
   590
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   591
                .add(allButton)
abadea@61
   592
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   593
                .add(noTypeButton)
abadea@61
   594
                .addContainerGap(187, Short.MAX_VALUE))
abadea@61
   595
        );
abadea@61
   596
        definitionPanel.add(compositorPanel, "compositor");
abadea@61
   597
abadea@61
   598
        referenceButtonGroup.add(extensionButton);
abadea@61
   599
        org.openide.awt.Mnemonics.setLocalizedText(extensionButton, ContentType.Extension.getLabel());
abadea@61
   600
        extensionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Extension"));
abadea@61
   601
        extensionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   602
        extensionButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   603
abadea@61
   604
        referenceButtonGroup.add(restrictionButton);
abadea@61
   605
        org.openide.awt.Mnemonics.setLocalizedText(restrictionButton, ContentType.Restriction.getLabel());
abadea@61
   606
        restrictionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Restriction"));
abadea@61
   607
        restrictionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   608
        restrictionButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   609
abadea@61
   610
        referenceButtonGroup.add(groupButton);
abadea@61
   611
        org.openide.awt.Mnemonics.setLocalizedText(groupButton, ContentType.Group.getLabel());
abadea@61
   612
        groupButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Group"));
abadea@61
   613
        groupButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   614
        groupButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   615
abadea@61
   616
        innerContentLabel.setLabelFor(innerContentComboBox);
abadea@61
   617
        org.openide.awt.Mnemonics.setLocalizedText(innerContentLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_InnerContent"));
abadea@61
   618
        innerContentLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_InnerContent"));
abadea@61
   619
        innerContentLabel.setEnabled(false);
abadea@61
   620
abadea@61
   621
        innerContentComboBox.setModel(new DefaultComboBoxModel(
abadea@61
   622
            new Object[]
abadea@61
   623
            {
abadea@61
   624
                ContentType.Sequence,
abadea@61
   625
                ContentType.Choice,
abadea@61
   626
                ContentType.All,
abadea@61
   627
                ContentType.NoType,
abadea@61
   628
                ContentType.Group,
abadea@61
   629
            }
abadea@61
   630
        ));
abadea@61
   631
        innerContentComboBox.setEnabled(false);
abadea@61
   632
abadea@61
   633
        innerContentPanel.setLayout(new java.awt.CardLayout());
abadea@61
   634
abadea@61
   635
        initializeTypePanel();
abadea@61
   636
abadea@61
   637
        org.openide.awt.Mnemonics.setLocalizedText(referenceLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Existing_Definition_Panel", new Object[] {}));
abadea@61
   638
        referenceLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Existing_Definition_Panel"));
abadea@61
   639
abadea@61
   640
        org.jdesktop.layout.GroupLayout referencePanelLayout = new org.jdesktop.layout.GroupLayout(referencePanel);
abadea@61
   641
        referencePanel.setLayout(referencePanelLayout);
abadea@61
   642
        referencePanelLayout.setHorizontalGroup(
abadea@61
   643
            referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   644
            .add(referenceLabel)
abadea@61
   645
            .add(referencePanelLayout.createSequentialGroup()
abadea@61
   646
                .addContainerGap()
abadea@61
   647
                .add(extensionButton)
abadea@61
   648
                .add(5, 5, 5)
abadea@61
   649
                .add(innerContentLabel)
abadea@61
   650
                .add(5, 5, 5)
abadea@61
   651
                .add(innerContentComboBox, 0, 278, Short.MAX_VALUE)
abadea@61
   652
                .addContainerGap())
abadea@61
   653
            .add(referencePanelLayout.createSequentialGroup()
abadea@61
   654
                .addContainerGap()
abadea@61
   655
                .add(restrictionButton)
abadea@61
   656
                .addContainerGap(385, Short.MAX_VALUE))
abadea@61
   657
            .add(referencePanelLayout.createSequentialGroup()
abadea@61
   658
                .addContainerGap()
abadea@61
   659
                .add(referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   660
                    .add(referencePanelLayout.createSequentialGroup()
abadea@61
   661
                        .add(17, 17, 17)
abadea@61
   662
                        .add(innerContentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE))
abadea@61
   663
                    .add(referencePanelLayout.createSequentialGroup()
abadea@61
   664
                        .add(groupButton)
abadea@61
   665
                        .addContainerGap(385, Short.MAX_VALUE))))
abadea@61
   666
        );
abadea@61
   667
abadea@61
   668
        referencePanelLayout.linkSize(new java.awt.Component[] {extensionButton, groupButton, restrictionButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
abadea@61
   669
abadea@61
   670
        referencePanelLayout.setVerticalGroup(
abadea@61
   671
            referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   672
            .add(referencePanelLayout.createSequentialGroup()
abadea@61
   673
                .add(referenceLabel)
abadea@61
   674
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   675
                .add(referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
abadea@61
   676
                    .add(extensionButton)
abadea@61
   677
                    .add(innerContentLabel)
abadea@61
   678
                    .add(innerContentComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
abadea@61
   679
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   680
                .add(restrictionButton)
abadea@61
   681
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   682
                .add(groupButton)
abadea@61
   683
                .add(0, 0, 0)
abadea@61
   684
                .add(innerContentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
abadea@61
   685
        );
abadea@61
   686
        definitionPanel.add(referencePanel, "reference");
abadea@61
   687
abadea@61
   688
        org.openide.awt.Mnemonics.setLocalizedText(typeLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Content", new Object[] {}));
abadea@61
   689
        typeLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content"));
abadea@61
   690
abadea@61
   691
        definitionButtonGroup.add(inlineDefinitionButton);
abadea@61
   692
        org.openide.awt.Mnemonics.setLocalizedText(inlineDefinitionButton, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Inline_Definition_Button"));
abadea@61
   693
        inlineDefinitionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Inline_Definition_Button"));
abadea@61
   694
        inlineDefinitionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   695
        inlineDefinitionButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   696
abadea@61
   697
        definitionButtonGroup.add(existingDefinitionButton);
abadea@61
   698
        org.openide.awt.Mnemonics.setLocalizedText(existingDefinitionButton, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Existing_Definition_Button"));
abadea@61
   699
        existingDefinitionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Existing_Definition_Button"));
abadea@61
   700
        existingDefinitionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
abadea@61
   701
        existingDefinitionButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
abadea@61
   702
abadea@61
   703
        mPanel.setLayout(new java.awt.BorderLayout());
abadea@61
   704
abadea@61
   705
        mPanel.add(getMessageDisplayer().getComponent(),java.awt.BorderLayout.CENTER);
abadea@61
   706
abadea@61
   707
        nameLabel.setLabelFor(nameTextField);
abadea@61
   708
        org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_CustomizerForm_Name"));
abadea@61
   709
        nameLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Name"));
abadea@61
   710
abadea@61
   711
        nameTextField.setEditable(!hasParent());
abadea@61
   712
abadea@61
   713
        org.jdesktop.layout.GroupLayout namePanelLayout = new org.jdesktop.layout.GroupLayout(namePanel);
abadea@61
   714
        namePanel.setLayout(namePanelLayout);
abadea@61
   715
        namePanelLayout.setHorizontalGroup(
abadea@61
   716
            namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   717
            .add(namePanelLayout.createSequentialGroup()
abadea@61
   718
                .addContainerGap()
abadea@61
   719
                .add(nameLabel)
abadea@61
   720
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   721
                .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)
abadea@61
   722
                .addContainerGap())
abadea@61
   723
        );
abadea@61
   724
        namePanelLayout.setVerticalGroup(
abadea@61
   725
            namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   726
            .add(namePanelLayout.createSequentialGroup()
abadea@61
   727
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
abadea@61
   728
                .add(namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
abadea@61
   729
                    .add(nameLabel)
abadea@61
   730
                    .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
abadea@61
   731
        );
abadea@61
   732
abadea@61
   733
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
abadea@61
   734
        this.setLayout(layout);
abadea@61
   735
        layout.setHorizontalGroup(
abadea@61
   736
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   737
            .add(layout.createSequentialGroup()
abadea@61
   738
                .addContainerGap()
abadea@61
   739
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   740
                    .add(typeLabel)
abadea@61
   741
                    .add(layout.createSequentialGroup()
abadea@61
   742
                        .add(10, 10, 10)
abadea@61
   743
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   744
                            .add(existingDefinitionButton)
abadea@61
   745
                            .add(inlineDefinitionButton))))
abadea@61
   746
                .addContainerGap(357, Short.MAX_VALUE))
abadea@61
   747
            .add(layout.createSequentialGroup()
abadea@61
   748
                .addContainerGap()
abadea@61
   749
                .add(previewLabel)
abadea@61
   750
                .addContainerGap(448, Short.MAX_VALUE))
abadea@61
   751
            .add(namePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
abadea@61
   752
            .add(layout.createSequentialGroup()
abadea@61
   753
                .addContainerGap()
abadea@61
   754
                .add(definitionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
abadea@61
   755
                .addContainerGap())
abadea@61
   756
            .add(layout.createSequentialGroup()
abadea@61
   757
                .addContainerGap()
abadea@61
   758
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
abadea@61
   759
                .addContainerGap())
abadea@61
   760
            .add(org.jdesktop.layout.GroupLayout.TRAILING, mPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
abadea@61
   761
        );
abadea@61
   762
        layout.setVerticalGroup(
abadea@61
   763
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
abadea@61
   764
            .add(layout.createSequentialGroup()
abadea@61
   765
                .add(namePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
abadea@61
   766
                .add(11, 11, 11)
abadea@61
   767
                .add(typeLabel)
abadea@61
   768
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   769
                .add(inlineDefinitionButton)
abadea@61
   770
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
abadea@61
   771
                .add(existingDefinitionButton)
abadea@61
   772
                .add(11, 11, 11)
abadea@61
   773
                .add(definitionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
abadea@61
   774
                .add(11, 11, 11)
abadea@61
   775
                .add(previewLabel)
abadea@61
   776
                .add(5, 5, 5)
abadea@61
   777
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
abadea@61
   778
                .add(0, 0, 0)
abadea@61
   779
                .add(mPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
abadea@61
   780
        );
abadea@61
   781
    }// </editor-fold>//GEN-END:initComponents
abadea@61
   782
    
abadea@61
   783
    
abadea@61
   784
    // Variables declaration - do not modify//GEN-BEGIN:variables
abadea@61
   785
    private javax.swing.JRadioButton allButton;
abadea@61
   786
    private javax.swing.JRadioButton choiceButton;
abadea@61
   787
    private javax.swing.ButtonGroup compositorButtonGroup;
abadea@61
   788
    private javax.swing.JLabel compositorLabel;
abadea@61
   789
    private javax.swing.JPanel compositorPanel;
abadea@61
   790
    private javax.swing.ButtonGroup definitionButtonGroup;
abadea@61
   791
    private javax.swing.JPanel definitionPanel;
abadea@61
   792
    private javax.swing.JRadioButton existingDefinitionButton;
abadea@61
   793
    private javax.swing.JRadioButton extensionButton;
abadea@61
   794
    private javax.swing.JRadioButton groupButton;
abadea@61
   795
    private javax.swing.JRadioButton inlineDefinitionButton;
abadea@61
   796
    private javax.swing.JComboBox innerContentComboBox;
abadea@61
   797
    private javax.swing.JLabel innerContentLabel;
abadea@61
   798
    private javax.swing.JPanel innerContentPanel;
abadea@61
   799
    private javax.swing.JScrollPane jScrollPane1;
abadea@61
   800
    private javax.swing.JPanel mPanel;
abadea@61
   801
    private javax.swing.JLabel nameLabel;
abadea@61
   802
    private javax.swing.JPanel namePanel;
abadea@61
   803
    private javax.swing.JTextField nameTextField;
abadea@61
   804
    private javax.swing.JRadioButton noTypeButton;
abadea@61
   805
    private javax.swing.JLabel previewLabel;
abadea@61
   806
    private javax.swing.JEditorPane previewPane;
abadea@61
   807
    private javax.swing.ButtonGroup referenceButtonGroup;
abadea@61
   808
    private javax.swing.JLabel referenceLabel;
abadea@61
   809
    private javax.swing.JPanel referencePanel;
abadea@61
   810
    private javax.swing.JRadioButton restrictionButton;
abadea@61
   811
    private javax.swing.JRadioButton sequenceButton;
abadea@61
   812
    private javax.swing.JLabel typeLabel;
abadea@61
   813
    // End of variables declaration//GEN-END:variables
abadea@61
   814
    
abadea@61
   815
    /**
abadea@61
   816
     * content type from model
abadea@61
   817
     */
abadea@61
   818
    private transient ContentType contentType;
abadea@61
   819
    /**
abadea@61
   820
     * inner content type from model
abadea@61
   821
     */
abadea@61
   822
    private transient ContentType innerContentType;
abadea@61
   823
    /**
abadea@61
   824
     * reference to group or base type from model
abadea@61
   825
     */
abadea@61
   826
    private transient ReferenceableSchemaComponent gRef;
abadea@61
   827
    /**
abadea@61
   828
     * name document listener
abadea@61
   829
     */
abadea@61
   830
    private transient DocumentListener nameListener;
abadea@61
   831
    /**
abadea@61
   832
     * content radio buttons listener
abadea@61
   833
     */
abadea@61
   834
    private transient ItemListener buttonListener;
abadea@61
   835
    /**
abadea@61
   836
     * parent component for new type
abadea@61
   837
     */
abadea@61
   838
    private transient SchemaComponent parent;
abadea@61
   839
    
abadea@61
   840
    /**
abadea@61
   841
     * group selection panel
abadea@61
   842
     */
abadea@61
   843
    private transient SchemaComponentSelectionPanel<GlobalGroup>
abadea@61
   844
            groupSelectionPanel;
abadea@61
   845
    /**
abadea@61
   846
     * type selection panel
abadea@61
   847
     */
abadea@61
   848
    private transient SchemaComponentSelectionPanel<GlobalType>
abadea@61
   849
            typeSelectionPanel;
abadea@61
   850
    
abadea@61
   851
    
abadea@61
   852
    
abadea@61
   853
    private enum ContentType {
abadea@61
   854
        NoType(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   855
        "LBL_ComplexType_Content_NoType")),
abadea@61
   856
        Sequence(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   857
        "LBL_ComplexType_Content_Sequence")),
abadea@61
   858
        Choice(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   859
        "LBL_ComplexType_Content_Choice")),
abadea@61
   860
        All(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   861
        "LBL_ComplexType_Content_All")),
abadea@61
   862
        Group(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   863
        "LBL_ComplexType_Content_Group")),
abadea@61
   864
        Extension(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   865
        "LBL_ComplexType_Content_Extension")),
abadea@61
   866
        Restriction(NbBundle.getMessage(ComplexTypeCustomizer.class,
abadea@61
   867
        "LBL_ComplexType_Content_Restriction"));
abadea@61
   868
        ContentType(String label) {
abadea@61
   869
            this.label = label;
abadea@61
   870
        }
abadea@61
   871
        
abadea@61
   872
        public String toString() {
abadea@61
   873
            int idx = org.openide.awt.Mnemonics.findMnemonicAmpersand(label);
abadea@61
   874
            if(idx>-1&&idx<label.length()) {
abadea@61
   875
                String toStr = label.substring(0,idx);
abadea@61
   876
                if(idx+1<label.length()) {
abadea@61
   877
                    toStr = toStr.concat(label.substring(idx+1,label.length()));
abadea@61
   878
                }
abadea@61
   879
                return toStr;
abadea@61
   880
            }
abadea@61
   881
            return label;
abadea@61
   882
        }
abadea@61
   883
        
abadea@61
   884
        public String getLabel() {
abadea@61
   885
            return label;
abadea@61
   886
        }
abadea@61
   887
        
abadea@61
   888
        private String label;
abadea@61
   889
    }
abadea@61
   890
    
abadea@61
   891
    protected void applyChanges() throws IOException {
abadea@61
   892
        saveName();
abadea@61
   893
        ContentType uiContentType = getUIContentType();
abadea@61
   894
        ReferenceableSchemaComponent uiRef = getUIReference();
abadea@61
   895
        switch(uiContentType) {
abadea@61
   896
            case NoType:
abadea@61
   897
            case All:
abadea@61
   898
            case Sequence:
abadea@61
   899
            case Choice:
abadea@61
   900
                if(uiContentType!=getModelContentType()) saveContentType();
abadea@61
   901
                break;
abadea@61
   902
            case Group:
abadea@61
   903
                if(uiRef instanceof GlobalGroup && (uiContentType!=
abadea@61
   904
                        getModelContentType() || uiRef!=getModelReference()))
abadea@61
   905
                    saveContentType();
abadea@61
   906
                break;
abadea@61
   907
            case Restriction:
abadea@61
   908
                if(uiRef instanceof GlobalType && (uiContentType!=
abadea@61
   909
                        getModelContentType() || uiRef!=getModelReference()))
abadea@61
   910
                    saveContentType();
abadea@61
   911
                break;
abadea@61
   912
            case Extension:
abadea@61
   913
                if(uiRef instanceof GlobalSimpleType ||
abadea@61
   914
                        uiRef instanceof GlobalComplexType &&
abadea@61
   915
                        ((GlobalComplexType)uiRef).getDefinition() instanceof
abadea@61
   916
                        SimpleContent) {
abadea@61
   917
                    if(uiContentType!=getModelContentType() ||
abadea@61
   918
                            uiRef!=getModelReference()) {
abadea@61
   919
                        saveContentType();
abadea@61
   920
                    }
abadea@61
   921
                } else if(uiRef instanceof GlobalComplexType) {
abadea@61
   922
                    ContentType uiInnerContentType = getUIInnerContentType();
abadea@61
   923
                    if(uiInnerContentType!=null) {
abadea@61
   924
                        if(uiContentType!=getModelContentType() ||
abadea@61
   925
                                uiRef!=getModelReference() ||
abadea@61
   926
                                uiInnerContentType!= getModelInnerContentType()) {
abadea@61
   927
                            saveContentType();
abadea@61
   928
                        }
abadea@61
   929
                    }
abadea@61
   930
                }
abadea@61
   931
        }
abadea@61
   932
    }
abadea@61
   933
    
abadea@61
   934
    ComplexType saveContentType() {
abadea@61
   935
        ComplexType type = getSchemaComponent();
abadea@61
   936
        SchemaComponentFactory factory = getSchemaModel().getFactory();
abadea@61
   937
        ComplexTypeDefinition currentDef = type.getDefinition();
abadea@61
   938
        ReferenceableSchemaComponent ref = getUIReference();
abadea@61
   939
        LocalAttributeContainer lac = type;
abadea@61
   940
        if(currentDef instanceof ComplexContent) {
abadea@61
   941
            ComplexContent cc = (ComplexContent)currentDef;
abadea@61
   942
            if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
abadea@61
   943
                lac = (ComplexContentRestriction)cc.getLocalDefinition();
abadea@61
   944
            } else if(cc.getLocalDefinition() instanceof ComplexExtension) {
abadea@61
   945
                lac = (ComplexExtension)cc.getLocalDefinition();
abadea@61
   946
            }
abadea@61
   947
        } else if(currentDef instanceof SimpleContent) {
abadea@61
   948
            SimpleContent sc = (SimpleContent)currentDef;
abadea@61
   949
            if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
abadea@61
   950
                lac = (SimpleContentRestriction)sc.getLocalDefinition();
abadea@61
   951
            } else if(sc.getLocalDefinition() instanceof SimpleExtension) {
abadea@61
   952
                lac = (SimpleExtension)sc.getLocalDefinition();
abadea@61
   953
            }
abadea@61
   954
        }
abadea@61
   955
        switch (getUIContentType()) {
abadea@61
   956
            case NoType:
abadea@61
   957
                assert currentDef != null;
abadea@61
   958
                type.setDefinition(null);
abadea@61
   959
                break;
abadea@61
   960
            case All:
abadea@61
   961
                assert !(currentDef instanceof All);
abadea@61
   962
                All all = factory.createAll();
abadea@61
   963
                // try to preserve old contents
abadea@61
   964
                if(currentDef instanceof Choice || currentDef instanceof Sequence) {
abadea@61
   965
                    copyContent(currentDef, all);
abadea@61
   966
                }
abadea@61
   967
                type.setDefinition(all);
abadea@61
   968
                break;
abadea@61
   969
            case Choice:
abadea@61
   970
                assert !(currentDef instanceof Choice);
abadea@61
   971
                Choice choice = factory.createChoice();
abadea@61
   972
                // try to preserve old contents
abadea@61
   973
                if(currentDef instanceof All || currentDef instanceof Sequence) {
abadea@61
   974
                    copyContent(currentDef, choice);
abadea@61
   975
                }
abadea@61
   976
                type.setDefinition(choice);
abadea@61
   977
                break;
abadea@61
   978
            case Sequence:
abadea@61
   979
                Sequence sequence = factory.createSequence();
abadea@61
   980
                // try to preserve old contents
abadea@61
   981
                if(currentDef instanceof All || currentDef instanceof Choice) {
abadea@61
   982
                    copyContent(currentDef, sequence);
abadea@61
   983
                }
abadea@61
   984
                type.setDefinition(sequence);
abadea@61
   985
                break;
abadea@61
   986
            case Group:
abadea@61
   987
                assert ref instanceof GlobalGroup;
abadea@61
   988
                GroupReference group;
abadea@61
   989
                if(currentDef instanceof GroupReference)
abadea@61
   990
                    group = (GroupReference) currentDef;
abadea@61
   991
                else
abadea@61
   992
                    group = factory.createGroupReference();
abadea@61
   993
                group.setRef(group.createReferenceTo((GlobalGroup)ref, GlobalGroup.class));
abadea@61
   994
                type.setDefinition(group);
abadea@61
   995
                break;
abadea@61
   996
            case Extension:
abadea@61
   997
                assert ref instanceof GlobalType;
abadea@61
   998
                if(ref instanceof GlobalSimpleType ||
abadea@61
   999
                        ref instanceof GlobalComplexType &&
abadea@61
  1000
                        ((GlobalComplexType)ref).getDefinition() instanceof SimpleContent) {
abadea@61
  1001
                    SimpleExtension se = null;
abadea@61
  1002
                    if(currentDef instanceof SimpleContent) {
abadea@61
  1003
                        SimpleContent sc = (SimpleContent)currentDef;
abadea@61
  1004
                        if(sc.getLocalDefinition() instanceof SimpleExtension) {
abadea@61
  1005
                            se = (SimpleExtension)sc.getLocalDefinition();
abadea@61
  1006
                        } else {
abadea@61
  1007
                            se = factory.createSimpleExtension();
abadea@61
  1008
                            moveAttributeContents(lac,se);
abadea@61
  1009
                            sc.setLocalDefinition(se);
abadea@61
  1010
                        }
abadea@61
  1011
                    } else {
abadea@61
  1012
                        SimpleContent sc = factory.createSimpleContent();
abadea@61
  1013
                        se = factory.createSimpleExtension();
abadea@61
  1014
                        moveAttributeContents(lac,se);
abadea@61
  1015
                        sc.setLocalDefinition(se);
abadea@61
  1016
                        type.setDefinition(sc);
abadea@61
  1017
                    }
abadea@61
  1018
                    se.setBase(se.createReferenceTo(
abadea@61
  1019
                            (GlobalType)ref, GlobalType.class));
abadea@61
  1020
                } else if(ref instanceof GlobalComplexType) {
abadea@61
  1021
                    assert getUIInnerContentType()!=null;
abadea@61
  1022
                    ComplexExtension ce = null;
abadea@61
  1023
                    if(currentDef instanceof ComplexContent) {
abadea@61
  1024
                        ComplexContent cc = (ComplexContent)currentDef;
abadea@61
  1025
                        if(cc.getLocalDefinition() instanceof ComplexExtension) {
abadea@61
  1026
                            ce = (ComplexExtension)cc.getLocalDefinition();
abadea@61
  1027
                        } else {
abadea@61
  1028
                            ce = factory.createComplexExtension();
abadea@61
  1029
                            copyContent(cc.getLocalDefinition(),ce);
abadea@61
  1030
                            //moveAttributeContents(lac,ce);
abadea@61
  1031
                            cc.setLocalDefinition(ce);
abadea@61
  1032
                        }
abadea@61
  1033
                    } else {
abadea@61
  1034
                        ComplexContent cc = factory.createComplexContent();
abadea@61
  1035
                        ce = factory.createComplexExtension();
samaresh@151
  1036
                        moveComplexContents(lac,ce);
abadea@61
  1037
                        cc.setLocalDefinition(ce);
abadea@61
  1038
                        type.setDefinition(cc);
abadea@61
  1039
                    }
abadea@61
  1040
                    GlobalComplexType gct = (GlobalComplexType)ref;
abadea@61
  1041
                    ce.setBase(ce.createReferenceTo(gct, GlobalType.class));
abadea@61
  1042
                    if(getUIInnerContentType()!=getModelInnerContentType()) {
abadea@61
  1043
                        ComplexExtensionDefinition ced = null;
abadea@61
  1044
                        switch(getUIInnerContentType()) {
abadea@61
  1045
                            case Group:
abadea@61
  1046
                                ced = factory.createGroupReference();
abadea@61
  1047
                                break;
abadea@61
  1048
                            case All:
abadea@61
  1049
                                ced = factory.createAll();
abadea@61
  1050
                                break;
abadea@61
  1051
                            case Sequence:
abadea@61
  1052
                                ced = factory.createSequence();
abadea@61
  1053
                                break;
abadea@61
  1054
                            case Choice:
abadea@61
  1055
                                ced = factory.createChoice();
abadea@61
  1056
                                break;
abadea@61
  1057
                            default:
abadea@61
  1058
                        }
abadea@61
  1059
                        if(ced!=null && ce.getLocalDefinition()!=null) {
abadea@61
  1060
                            copyContent(ce.getLocalDefinition(),ced);
abadea@61
  1061
                        }
abadea@61
  1062
                        ce.setLocalDefinition(ced);
abadea@61
  1063
                    }
abadea@61
  1064
                }
abadea@61
  1065
                break;
abadea@61
  1066
            case Restriction:
abadea@61
  1067
                assert ref instanceof GlobalType;
abadea@61
  1068
                if(ref instanceof GlobalSimpleType ||
abadea@61
  1069
                        ref instanceof GlobalComplexType &&
abadea@61
  1070
                        ((GlobalComplexType)ref).getDefinition() instanceof SimpleContent) {
abadea@61
  1071
                    SimpleContentRestriction scr = null;
abadea@61
  1072
                    if(currentDef instanceof SimpleContent) {
abadea@61
  1073
                        SimpleContent sc = (SimpleContent)currentDef;
abadea@61
  1074
                        if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
abadea@61
  1075
                            scr = (SimpleContentRestriction)sc.getLocalDefinition();
abadea@61
  1076
                            if(scr.getInlineType()!=null) scr.setInlineType(null);
abadea@61
  1077
                        } else {
abadea@61
  1078
                            scr = factory.createSimpleContentRestriction();
abadea@61
  1079
                            moveAttributeContents(lac,scr);
abadea@61
  1080
                            sc.setLocalDefinition(scr);
abadea@61
  1081
                        }
abadea@61
  1082
                    } else {
abadea@61
  1083
                        SimpleContent sc = factory.createSimpleContent();
abadea@61
  1084
                        scr = factory.createSimpleContentRestriction();
abadea@61
  1085
                        moveAttributeContents(lac,scr);
abadea@61
  1086
                        sc.setLocalDefinition(scr);
abadea@61
  1087
                        type.setDefinition(sc);
abadea@61
  1088
                    }
abadea@61
  1089
                    scr.setBase(scr.createReferenceTo(
abadea@61
  1090
                            (GlobalType)ref, GlobalType.class));
abadea@61
  1091
                } else if(ref instanceof GlobalComplexType) {
abadea@61
  1092
                    ComplexContentRestriction ccr = null;
abadea@61
  1093
                    if(currentDef instanceof ComplexContent) {
abadea@61
  1094
                        ComplexContent cc = (ComplexContent)currentDef;
abadea@61
  1095
                        if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
abadea@61
  1096
                            ccr = (ComplexContentRestriction)cc.getLocalDefinition();
abadea@61
  1097
                        } else {
abadea@61
  1098
                            ccr = factory.createComplexContentRestriction();
abadea@61
  1099
                            moveAttributeContents(lac,ccr);
abadea@61
  1100
                            cc.setLocalDefinition(ccr);
abadea@61
  1101
                        }
abadea@61
  1102
                    } else {
abadea@61
  1103
                        ComplexContent cc = factory.createComplexContent();
abadea@61
  1104
                        ccr = factory.createComplexContentRestriction();
abadea@61
  1105
                        moveAttributeContents(lac,ccr);
abadea@61
  1106
                        cc.setLocalDefinition(ccr);
abadea@61
  1107
                        type.setDefinition(cc);
abadea@61
  1108
                    }
abadea@61
  1109
                    GlobalComplexType gct = (GlobalComplexType)ref;
abadea@61
  1110
                    ccr.setBase(ccr.createReferenceTo(
abadea@61
  1111
                            gct, GlobalComplexType.class));
abadea@61
  1112
                    ComplexTypeDefinition newInnerDef = null;
abadea@61
  1113
                    
abadea@61
  1114
                    if(gct.getDefinition() instanceof All ||
abadea@61
  1115
                            gct.getDefinition() instanceof Choice ||
abadea@61
  1116
                            gct.getDefinition() instanceof Sequence ||
abadea@61
  1117
                            gct.getDefinition() instanceof GroupReference) {
abadea@61
  1118
                        newInnerDef = gct.getDefinition();
abadea@61
  1119
                    } else if(gct.getDefinition() instanceof ComplexContent) {
abadea@61
  1120
                        ComplexContent cc = (ComplexContent)gct.getDefinition();
abadea@61
  1121
                        if (cc.getLocalDefinition() instanceof ComplexContentRestriction) {
abadea@61
  1122
                            newInnerDef = ((ComplexContentRestriction)cc.
abadea@61
  1123
                                    getLocalDefinition()).getDefinition();
abadea@61
  1124
                        } else if (cc.getLocalDefinition() instanceof ComplexExtension) {
abadea@61
  1125
                            newInnerDef = (ComplexTypeDefinition)((ComplexExtension)cc.
abadea@61
  1126
                                    getLocalDefinition()).getLocalDefinition();
abadea@61
  1127
                        }
abadea@61
  1128
                    }
samaresh@664
  1129
                    if(ccr != null)
samaresh@664
  1130
                        ccr.setDefinition((ComplexTypeDefinition) newInnerDef.copy(ccr));
abadea@61
  1131
                }
abadea@61
  1132
                break;
abadea@61
  1133
        }
abadea@61
  1134
        this.contentType = contentType;
abadea@61
  1135
        return type;
abadea@61
  1136
    }
abadea@61
  1137
    
abadea@61
  1138
    private void copyContent(final SchemaComponent oldParent,
abadea@61
  1139
            final SchemaComponent newParent) {
abadea@61
  1140
        if(oldParent==null || newParent==null) return;
abadea@61
  1141
        SchemaModel model = getSchemaModel();
abadea@61
  1142
        for(SchemaComponent child :oldParent.getChildren()) {
abadea@61
  1143
            if(newParent.canPaste(child))
abadea@61
  1144
                model.addChildComponent(newParent,child.copy(newParent),-1);
abadea@61
  1145
        }
abadea@61
  1146
    }
abadea@61
  1147
    
abadea@61
  1148
    private void moveAttributeContents(final LocalAttributeContainer oldParent,
abadea@61
  1149
            final LocalAttributeContainer newParent) {
abadea@61
  1150
        if(oldParent==null || newParent==null) return;
abadea@61
  1151
        SchemaModel model = getSchemaModel();
abadea@61
  1152
        ArrayList<Class<? extends SchemaComponent>> attrChildTypes =
abadea@61
  1153
                new ArrayList<Class<? extends SchemaComponent>>(4);
abadea@61
  1154
        attrChildTypes.add(LocalAttribute.class);
abadea@61
  1155
        attrChildTypes.add(AttributeReference.class);
abadea@61
  1156
        attrChildTypes.add(AttributeGroupReference.class);
abadea@61
  1157
        attrChildTypes.add(AnyAttribute.class);
abadea@61
  1158
        for(SchemaComponent child :oldParent.getChildren(attrChildTypes)) {
abadea@61
  1159
            if(newParent.canPaste(child))
abadea@61
  1160
                model.addChildComponent(newParent,child.copy(newParent),-1);
abadea@61
  1161
            model.removeChildComponent(child);
abadea@61
  1162
        }
abadea@61
  1163
    }
samaresh@151
  1164
        
samaresh@151
  1165
    private void moveComplexContents(final LocalAttributeContainer oldParent,
samaresh@151
  1166
            final LocalAttributeContainer newParent) {
samaresh@151
  1167
        if(oldParent==null || newParent==null) return;
samaresh@151
  1168
        SchemaModel model = getSchemaModel();
samaresh@151
  1169
        ArrayList<Class<? extends SchemaComponent>> childTypes =
samaresh@151
  1170
                new ArrayList<Class<? extends SchemaComponent>>(4);
samaresh@151
  1171
        childTypes.add(LocalAttribute.class);
samaresh@151
  1172
        childTypes.add(AttributeReference.class);
samaresh@151
  1173
        childTypes.add(AttributeGroupReference.class);
samaresh@151
  1174
        childTypes.add(AnyAttribute.class);
samaresh@151
  1175
        childTypes.add(ComplexTypeDefinition.class);
samaresh@151
  1176
        for(SchemaComponent child :oldParent.getChildren(childTypes)) {
samaresh@151
  1177
            if(newParent.canPaste(child))
samaresh@151
  1178
                model.addChildComponent(newParent,child.copy(newParent),-1);
samaresh@151
  1179
            model.removeChildComponent(child);
samaresh@151
  1180
        }
samaresh@151
  1181
    }
abadea@61
  1182
    
abadea@61
  1183
    public void reset() {
abadea@61
  1184
        removeListeners();
abadea@61
  1185
        initialize();
abadea@61
  1186
        initializeUI();
abadea@61
  1187
        addListeners();
abadea@61
  1188
        if(hasParent()) {
abadea@61
  1189
            setSaveEnabled(false);
abadea@61
  1190
        } else {
abadea@61
  1191
            setSaveEnabled(true);
abadea@61
  1192
        }
abadea@61
  1193
        setResetEnabled(false);
abadea@61
  1194
    }
abadea@61
  1195
    
abadea@61
  1196
    public HelpCtx getHelpCtx() {
abadea@61
  1197
        return new HelpCtx(ComplexTypeCustomizer.class);
abadea@61
  1198
    }
abadea@61
  1199
    
abadea@61
  1200
    /**
abadea@61
  1201
     * listens to property change events from explorer manager node selections
abadea@61
  1202
     */
abadea@61
  1203
    public void propertyChange(PropertyChangeEvent evt) {
abadea@61
  1204
        if (evt.getPropertyName().equals(SchemaComponentSelectionPanel.PROPERTY_SELECTION)) {
abadea@61
  1205
            enableDisableComboBox();
abadea@61
  1206
            setPreviewText();
abadea@61
  1207
            determineValidity();
abadea@61
  1208
        }
abadea@61
  1209
    }
abadea@61
  1210
    
abadea@61
  1211
    /**
abadea@61
  1212
     * determines validity of customizer.
abadea@61
  1213
     */
abadea@61
  1214
    private void determineValidity() {
abadea@61
  1215
        getMessageDisplayer().clear();
abadea@61
  1216
        boolean nameChanged = isNameable()&&isNameChanged();
abadea@61
  1217
        if(!nameChanged && getUIContentType() == getModelContentType() &&
abadea@61
  1218
                getUIInnerContentType()==getModelInnerContentType() &&
abadea@61
  1219
                getUIReference()==getModelReference()) {
abadea@61
  1220
            if(hasParent()) {
abadea@61
  1221
                setSaveEnabled(false);
abadea@61
  1222
            } else {
abadea@61
  1223
                setSaveEnabled(true);
abadea@61
  1224
            }
abadea@61
  1225
            setResetEnabled(false);
abadea@61
  1226
        } else {
abadea@61
  1227
            setResetEnabled(true);
abadea@61
  1228
            boolean valid = false;
abadea@61
  1229
            switch(getUIContentType()) {
abadea@61
  1230
                case Extension:
abadea@61
  1231
                    if(getUIReference() instanceof GlobalSimpleType ||
abadea@61
  1232
                            getUIReference() instanceof GlobalComplexType &&
abadea@61
  1233
                            (((GlobalComplexType)getUIReference()).getDefinition()
abadea@61
  1234
                            instanceof SimpleContent || getUIInnerContentType()!=null)) {
abadea@61
  1235
                        valid = true;
abadea@61
  1236
                    }
abadea@61
  1237
                    break;
abadea@61
  1238
                case Restriction:
abadea@61
  1239
                    if(getUIReference() instanceof GlobalType) {
abadea@61
  1240
                        valid = true;
abadea@61
  1241
                    }
abadea@61
  1242
                    break;
abadea@61
  1243
                case Group:
abadea@61
  1244
                    if(getUIReference() instanceof GlobalGroup) {
abadea@61
  1245
                        valid = true;
abadea@61
  1246
                    }
abadea@61
  1247
                    break;
abadea@61
  1248
                case NoType:
abadea@61
  1249
                case All:
abadea@61
  1250
                case Sequence:
abadea@61
  1251
                case Choice:
abadea@61
  1252
                    valid = true;
abadea@61
  1253
                    break;
abadea@61
  1254
                default:
abadea@61
  1255
            }
abadea@61
  1256
            setSaveEnabled(valid && (!isNameChanged() || isNameValid()));
abadea@61
  1257
            if(!valid) {
abadea@61
  1258
                if(getUIContentType()==ContentType.Group) {
abadea@61
  1259
                    getMessageDisplayer().annotate(org.openide.util.NbBundle.
abadea@61
  1260
                            getMessage(ComplexTypeCustomizer.class,
abadea@61
  1261
                            "MSG_Group_Error"),
abadea@61
  1262
                            MessageDisplayer.Type.ERROR);
abadea@61
  1263
                } else {
abadea@61
  1264
                    getMessageDisplayer().annotate(org.openide.util.NbBundle.
abadea@61
  1265
                            getMessage(ComplexTypeCustomizer.class,
abadea@61
  1266
                            "MSG_Type_Error"),
abadea@61
  1267
                            MessageDisplayer.Type.ERROR);
abadea@61
  1268
                }
abadea@61
  1269
            }
abadea@61
  1270
        }
abadea@61
  1271
    }
abadea@61
  1272
    
abadea@61
  1273
    private void setPreviewText() {
abadea@61
  1274
        StringBuffer retValue = new StringBuffer("<");
abadea@61
  1275
        String prefix = getReference().get().getPeer().getPrefix();
abadea@61
  1276
        if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1277
        retValue.append("complexType");
abadea@61
  1278
        if(isNameable()) {
abadea@61
  1279
            retValue.append(" name=\"");
abadea@61
  1280
            retValue.append(getUIName());
abadea@61
  1281
            retValue.append("\"");
abadea@61
  1282
        }
abadea@61
  1283
        retValue.append(">");
abadea@61
  1284
        ReferenceableSchemaComponent ref = getUIReference();
abadea@61
  1285
        boolean complexContent = true;
abadea@61
  1286
        if(ref instanceof GlobalSimpleType ||
abadea@61
  1287
                ref instanceof GlobalComplexType &&
abadea@61
  1288
                ((GlobalComplexType)ref).getDefinition()
abadea@61
  1289
                instanceof SimpleContent)
abadea@61
  1290
            complexContent = false;
abadea@61
  1291
        switch(getUIContentType()) {
abadea@61
  1292
            case NoType:
abadea@61
  1293
                break;
abadea@61
  1294
            case Sequence:
abadea@61
  1295
                retValue.append("\n    <");
abadea@61
  1296
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1297
                retValue.append("sequence/>");
abadea@61
  1298
                break;
abadea@61
  1299
            case Choice:
abadea@61
  1300
                retValue.append("\n    <");
abadea@61
  1301
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1302
                retValue.append("choice/>");
abadea@61
  1303
                break;
abadea@61
  1304
            case All:
abadea@61
  1305
                retValue.append("\n    <");
abadea@61
  1306
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1307
                retValue.append("all/>");
abadea@61
  1308
                break;
abadea@61
  1309
            case Group:
abadea@61
  1310
                retValue.append("\n    <");
abadea@61
  1311
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1312
                retValue.append("group ref=\"");
abadea@61
  1313
                if(ref!=null) {
abadea@61
  1314
                    retValue.append(ref.getName());
abadea@61
  1315
                }
abadea@61
  1316
                retValue.append("\"/>");
abadea@61
  1317
                break;
abadea@61
  1318
            case Extension:
abadea@61
  1319
                if(complexContent) {
abadea@61
  1320
                    retValue.append("\n    <");
abadea@61
  1321
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1322
                    retValue.append("complexContent>");
abadea@61
  1323
                } else {
abadea@61
  1324
                    retValue.append("\n    <");
abadea@61
  1325
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1326
                    retValue.append("simpleContent>");
abadea@61
  1327
                }
abadea@61
  1328
                retValue.append("\n        <");
abadea@61
  1329
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1330
                retValue.append("extension base=\"");
abadea@61
  1331
                if(ref!=null) {
abadea@61
  1332
                    retValue.append(ref.getName());
abadea@61
  1333
                }
abadea@61
  1334
                retValue.append("\">");
abadea@61
  1335
                if(complexContent && ref!=null) {
abadea@61
  1336
                    switch(getUIInnerContentType()) {
abadea@61
  1337
                        case NoType:
abadea@61
  1338
                            break;
abadea@61
  1339
                        case Sequence:
abadea@61
  1340
                            retValue.append("\n            <");
abadea@61
  1341
                            if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1342
                            retValue.append("sequence/>");
abadea@61
  1343
                            break;
abadea@61
  1344
                        case Choice:
abadea@61
  1345
                            retValue.append("\n            <");
abadea@61
  1346
                            if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1347
                            retValue.append("choice/>");
abadea@61
  1348
                            break;
abadea@61
  1349
                        case All:
abadea@61
  1350
                            retValue.append("\n            <");
abadea@61
  1351
                            if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1352
                            retValue.append("all/>");
abadea@61
  1353
                            break;
abadea@61
  1354
                        case Group:
abadea@61
  1355
                            retValue.append("\n            <");
abadea@61
  1356
                            if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1357
                            retValue.append("group ref=\"\"/>");
abadea@61
  1358
                            break;
abadea@61
  1359
                    }
abadea@61
  1360
                }
abadea@61
  1361
                retValue.append("\n        </");
abadea@61
  1362
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1363
                retValue.append("extension>");
abadea@61
  1364
                if(complexContent) {
abadea@61
  1365
                    retValue.append("\n    </");
abadea@61
  1366
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1367
                    retValue.append("complexContent>");
abadea@61
  1368
                } else {
abadea@61
  1369
                    retValue.append("\n    </");
abadea@61
  1370
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1371
                    retValue.append("simpleContent>");
abadea@61
  1372
                }
abadea@61
  1373
                break;
abadea@61
  1374
            case Restriction:
abadea@61
  1375
                if(complexContent) {
abadea@61
  1376
                    retValue.append("\n    <");
abadea@61
  1377
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1378
                    retValue.append("complexContent>");
abadea@61
  1379
                } else {
abadea@61
  1380
                    retValue.append("\n    <");
abadea@61
  1381
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1382
                    retValue.append("simpleContent>");
abadea@61
  1383
                }
abadea@61
  1384
                retValue.append("\n        <");
abadea@61
  1385
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1386
                retValue.append("restriction base=\"");
abadea@61
  1387
                if(ref!=null) {
abadea@61
  1388
                    retValue.append(ref.getName());
abadea@61
  1389
                }
abadea@61
  1390
                retValue.append("\">");
abadea@61
  1391
                retValue.append("\n        </");
abadea@61
  1392
                if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1393
                retValue.append("restriction>");
abadea@61
  1394
                if(complexContent) {
abadea@61
  1395
                    retValue.append("\n    </");
abadea@61
  1396
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1397
                    retValue.append("complexContent>");
abadea@61
  1398
                } else {
abadea@61
  1399
                    retValue.append("\n    </");
abadea@61
  1400
                    if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1401
                    retValue.append("simpleContent>");
abadea@61
  1402
                }
abadea@61
  1403
                break;
abadea@61
  1404
        }
abadea@61
  1405
        retValue.append("\n</");
abadea@61
  1406
        if(prefix!=null) retValue.append(prefix+":");
abadea@61
  1407
        retValue.append("complexType>\n");
abadea@61
  1408
        previewPane.setText(retValue.toString());
abadea@61
  1409
    }
abadea@61
  1410
    
abadea@61
  1411
    private SchemaModel getSchemaModel() {
abadea@61
  1412
        return getSchemaComponent().getModel();
abadea@61
  1413
    }
abadea@61
  1414
    
abadea@61
  1415
    private ComplexType getSchemaComponent() {
abadea@61
  1416
        if(getReference()==null || getReference().get()==null) return null;
abadea@61
  1417
        return getReference().get();
abadea@61
  1418
    }
abadea@61
  1419
}