KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > customizer > ComplexTypeCustomizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer;
21
22 import java.awt.CardLayout JavaDoc;
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collections JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33
34 import org.netbeans.modules.xml.schema.model.All;
35 import org.netbeans.modules.xml.schema.model.AnyAttribute;
36 import org.netbeans.modules.xml.schema.model.AttributeGroupReference;
37 import org.netbeans.modules.xml.schema.model.AttributeReference;
38 import org.netbeans.modules.xml.schema.model.Choice;
39 import org.netbeans.modules.xml.schema.model.ComplexContent;
40 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
41 import org.netbeans.modules.xml.schema.model.ComplexExtension;
42 import org.netbeans.modules.xml.schema.model.ComplexExtensionDefinition;
43 import org.netbeans.modules.xml.schema.model.ComplexType;
44 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
45 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
46 import org.netbeans.modules.xml.schema.model.GlobalGroup;
47 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
48 import org.netbeans.modules.xml.schema.model.GlobalType;
49 import org.netbeans.modules.xml.schema.model.GroupReference;
50 import org.netbeans.modules.xml.schema.model.LocalAttribute;
51 import org.netbeans.modules.xml.schema.model.LocalAttributeContainer;
52 import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent;
53 import org.netbeans.modules.xml.schema.model.SchemaComponent;
54 import org.netbeans.modules.xml.schema.model.SchemaComponentFactory;
55 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
56 import org.netbeans.modules.xml.schema.model.SchemaModel;
57 import org.netbeans.modules.xml.schema.model.Sequence;
58 import org.netbeans.modules.xml.schema.model.SimpleContent;
59 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
60 import org.netbeans.modules.xml.schema.model.SimpleExtension;
61 import org.netbeans.modules.xml.schema.ui.basic.editors.SchemaComponentSelectionPanel;
62 import org.netbeans.modules.xml.xam.ui.customizer.MessageDisplayer;
63 import org.openide.util.HelpCtx;
64 import org.openide.util.NbBundle;
65
66 /**
67  *
68  * @author Ajit Bhate
69  */

70 public class ComplexTypeCustomizer<T extends ComplexType>
71         extends AbstractSchemaComponentCustomizer<T>
72         implements PropertyChangeListener JavaDoc {
73     
74     static final long serialVersionUID = 1L;
75     /** Creates new form ComplexTypeCustomizer */
76     public ComplexTypeCustomizer(SchemaComponentReference<T> reference,
77             SchemaComponent parent) {
78         super(reference, parent);
79         initComponents();
80         reset();
81     }
82     
83     /** Creates new form ComplexTypeCustomizer */
84     public ComplexTypeCustomizer(SchemaComponentReference<T> reference) {
85         this(reference,null);
86     }
87     
88     /**
89      * non UI component (model) initialization and access methods
90      */

91     
92     /**
93      * Initializes non ui from model
94      */

95     private void initialize() {
96         ComplexType type = getSchemaComponent();
97         if(type==null) return;
98         ComplexTypeDefinition definition =type.getDefinition();
99         contentType = ContentType.NoType;
100         if(definition instanceof All) {
101             contentType = ContentType.All;
102         } else if(definition instanceof Choice) {
103             contentType = ContentType.Choice;
104         } else if(definition instanceof Sequence) {
105             contentType = ContentType.Sequence;
106         } else if(definition instanceof GroupReference) {
107             contentType = ContentType.Group;
108             gRef = ((GroupReference)definition).getRef().get();
109         } else if(definition instanceof ComplexContent) {
110             ComplexContent cc = (ComplexContent)definition;
111             if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
112                 contentType = ContentType.Restriction;
113                 ComplexContentRestriction ccr =
114                         (ComplexContentRestriction)cc.getLocalDefinition();
115                 gRef = ccr.getBase().get();
116                 ComplexTypeDefinition innerDefinition = ccr.getDefinition();
117                 if(innerDefinition instanceof All) {
118                     innerContentType = ContentType.All;
119                 } else if(innerDefinition instanceof Choice) {
120                     innerContentType = ContentType.Choice;
121                 } else if(innerDefinition instanceof Sequence) {
122                     innerContentType = ContentType.Sequence;
123                 } else if(innerDefinition instanceof GroupReference) {
124                     innerContentType = ContentType.Group;
125                 }
126             } else if(cc.getLocalDefinition() instanceof ComplexExtension) {
127                 contentType = ContentType.Extension;
128                 ComplexExtension ce =
129                         (ComplexExtension)cc.getLocalDefinition();
130                 gRef = ce.getBase().get();
131                 ComplexExtensionDefinition innerDefinition = ce.getLocalDefinition();
132                 if(innerDefinition instanceof All) {
133                     innerContentType = ContentType.All;
134                 } else if(innerDefinition instanceof Choice) {
135                     innerContentType = ContentType.Choice;
136                 } else if(innerDefinition instanceof Sequence) {
137                     innerContentType = ContentType.Sequence;
138                 } else if(innerDefinition instanceof GroupReference) {
139                     innerContentType = ContentType.Group;
140                 } else {
141                     innerContentType = ContentType.NoType;
142                 }
143             }
144         } else if(definition instanceof SimpleContent) {
145             SimpleContent sc = (SimpleContent)definition;
146             if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
147                 contentType = ContentType.Restriction;
148                 SimpleContentRestriction scr =
149                         (SimpleContentRestriction)sc.getLocalDefinition();
150                 if(scr.getBase()!=null)
151                     gRef = scr.getBase().get();
152             } else if(sc.getLocalDefinition() instanceof SimpleExtension) {
153                 contentType = ContentType.Extension;
154                 gRef = ((SimpleExtension)sc.getLocalDefinition()).getBase().get();
155             }
156         }
157     }
158     
159     private ContentType getModelContentType() {
160         return contentType;
161     }
162     
163     private ContentType getModelInnerContentType() {
164         return innerContentType;
165     }
166     
167     private ReferenceableSchemaComponent getModelReference() {
168         return gRef;
169     }
170     
171     /**
172      * UI component initialization and access methods
173      */

174     
175     /**
176      * Initializes ui elements
177      */

178     private void initializeUI() {
179         getMessageDisplayer().clear();
180         if(isNameable()) {
181             nameTextField.setText(_getName());
182             if(!hasParent()) nameTextField.setSelectionStart(0);
183         } else {
184             namePanel.setVisible(false);
185         }
186         
187         if(getModelContentType()==null) {
188             inlineDefinitionButton.setSelected(true);
189         } else {
190             switch(getModelContentType()) {
191                 case NoType:
192                     inlineDefinitionButton.setSelected(true);
193                     noTypeButton.setSelected(true);
194                     break;
195                 case Sequence:
196                     inlineDefinitionButton.setSelected(true);
197                     sequenceButton.setSelected(true);
198                     break;
199                 case Choice:
200                     inlineDefinitionButton.setSelected(true);
201                     choiceButton.setSelected(true);
202                     break;
203                 case All:
204                     inlineDefinitionButton.setSelected(true);
205                     allButton.setSelected(true);
206                     break;
207                 case Group:
208                     existingDefinitionButton.setSelected(true);
209                     groupButton.setSelected(true);
210                     break;
211                 case Extension:
212                     existingDefinitionButton.setSelected(true);
213                     extensionButton.setSelected(true);
214                     innerContentComboBox.setSelectedItem(getModelInnerContentType());
215                     break;
216                 case Restriction:
217                     existingDefinitionButton.setSelected(true);
218                     restrictionButton.setSelected(true);
219                     break;
220             }
221         }
222         switchDefinitionPanels();
223         selectModelNode();
224         enableDisableComboBox();
225         setPreviewText();
226     }
227     
228     private void enableDisableComboBox() {
229         if(getUIContentType()==ContentType.Extension &&
230                 getUIReference() instanceof GlobalComplexType &&
231                 !(((GlobalComplexType)getUIReference()).getDefinition()
232                 instanceof SimpleContent)) {
233             innerContentLabel.setEnabled(true);
234             innerContentComboBox.setEnabled(true);
235             if(innerContentComboBox.getSelectedItem()==null)
236                 innerContentComboBox.setSelectedIndex(0);
237         } else {
238             innerContentLabel.setEnabled(false);
239             innerContentComboBox.setEnabled(false);
240         }
241     }
242     
243     /**
244      * enables disables the inner base type panel and inner content combo box.
245      */

246     private void switchDefinitionPanels() {
247         if(existingDefinitionButton.isSelected()) {
248             ((CardLayout JavaDoc)definitionPanel.getLayout()).show(definitionPanel,"reference"); //NO I18N
249
if(referenceButtonGroup.getSelection()==null)
250                 referenceButtonGroup.getElements().nextElement().setSelected(true);
251             //groupButton.setSelected(true);
252
switchInnerContentPanels();
253         } else {
254             ((CardLayout JavaDoc)definitionPanel.getLayout()).show(definitionPanel,"compositor"); //NO I18N
255
if(compositorButtonGroup.getSelection()==null)
256                 compositorButtonGroup.getElements().nextElement().setSelected(true);
257 // sequenceButton.setSelected(true);
258
}
259         enableDisableComboBox();
260     }
261     
262     private void switchInnerContentPanels() {
263         if(groupButton.isSelected())
264             ((CardLayout JavaDoc)innerContentPanel.getLayout()).show(innerContentPanel,"group");
265         else
266             ((CardLayout JavaDoc)innerContentPanel.getLayout()).show(innerContentPanel,"type");
267     }
268     
269     /**
270      * selects model node on ui
271      */

272     private void selectModelNode() {
273         switch(getUIContentType()) {
274             case Group:
275                 groupSelectionPanel.setInitialSelection((GlobalGroup)getModelReference());
276                 break;
277             case Extension:
278             case Restriction:
279                 typeSelectionPanel.setInitialSelection((GlobalType)getModelReference());
280                 break;
281             default:
282         }
283     }
284     
285     /**
286      * adds listeners
287      */

288     private void addListeners() {
289         if(isNameable()) {
290             if (nameListener == null) {
291                 nameListener = new DocumentListener JavaDoc() {
292                     public void changedUpdate(DocumentEvent JavaDoc e) {
293                         setPreviewText();
294                         determineValidity();
295                     }
296                     public void insertUpdate(DocumentEvent JavaDoc e) {
297                         setPreviewText();
298                         determineValidity();
299                     }
300                     public void removeUpdate(DocumentEvent JavaDoc e) {
301                         setPreviewText();
302                         determineValidity();
303                     }
304                 };
305             }
306             nameTextField.getDocument().addDocumentListener(nameListener);
307         }
308         if (buttonListener ==null) {
309             buttonListener = new ItemListener JavaDoc() {
310                 public void itemStateChanged(ItemEvent JavaDoc evt) {
311                     Object JavaDoc source = evt.getSource();
312                     if(source==extensionButton) {
313                         enableDisableComboBox();
314                     }
315                     if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
316                         if(source==inlineDefinitionButton ||
317                                 source==existingDefinitionButton) {
318                             switchDefinitionPanels();
319                         }
320                         if(source==groupButton ||
321                                 source==extensionButton ||
322                                 source==restrictionButton) {
323                             switchInnerContentPanels();
324                         }
325                         setPreviewText();
326                         determineValidity();
327                     }
328                 }
329             };
330         }
331         inlineDefinitionButton.addItemListener(buttonListener);
332         existingDefinitionButton.addItemListener(buttonListener);
333         noTypeButton.addItemListener(buttonListener);
334         sequenceButton.addItemListener(buttonListener);
335         allButton.addItemListener(buttonListener);
336         choiceButton.addItemListener(buttonListener);
337         groupButton.addItemListener(buttonListener);
338         extensionButton.addItemListener(buttonListener);
339         restrictionButton.addItemListener(buttonListener);
340         innerContentComboBox.addItemListener(buttonListener);
341     }
342     
343     /**
344      * removes listeners
345      */

346     private void removeListeners() {
347         if(isNameable()) nameTextField.getDocument().removeDocumentListener(nameListener);
348         inlineDefinitionButton.removeItemListener(buttonListener);
349         existingDefinitionButton.removeItemListener(buttonListener);
350         noTypeButton.removeItemListener(buttonListener);
351         sequenceButton.removeItemListener(buttonListener);
352         allButton.removeItemListener(buttonListener);
353         choiceButton.removeItemListener(buttonListener);
354         groupButton.removeItemListener(buttonListener);
355         extensionButton.removeItemListener(buttonListener);
356         restrictionButton.removeItemListener(buttonListener);
357         innerContentComboBox.removeItemListener(buttonListener);
358     }
359     
360     /**
361      * returns name from ui name text field
362      */

363     protected String JavaDoc getUIName() {
364         return nameTextField.getText();
365     }
366     
367     /**
368      * returns ui content type selection from content list
369      */

370     private ContentType getUIContentType() {
371         if(inlineDefinitionButton.isSelected()) {
372             if(noTypeButton.isSelected())
373                 return ContentType.NoType;
374             if(sequenceButton.isSelected())
375                 return ContentType.Sequence;
376             if(choiceButton.isSelected())
377                 return ContentType.Choice;
378             if(allButton.isSelected())
379                 return ContentType.All;
380         }
381         if(existingDefinitionButton.isSelected()) {
382             if(groupButton.isSelected())
383                 return ContentType.Group;
384             if(extensionButton.isSelected())
385                 return ContentType.Extension;
386             if(restrictionButton.isSelected())
387                 return ContentType.Restriction;
388         }
389         return null;
390     }
391     
392     /**
393      * returns ui inner content type selection from inner content combo box
394      */

395     private ContentType getUIInnerContentType() {
396         if (!innerContentComboBox.isEnabled())
397             return null;
398         return (ContentType) innerContentComboBox.getSelectedItem();
399     }
400     
401     /**
402      * returns ui reference selection from inner type/ref panel
403      */

404     private ReferenceableSchemaComponent getUIReference() {
405         switch(getUIContentType()) {
406             case Group:
407                 return groupSelectionPanel.getCurrentSelection();
408             case Extension:
409             case Restriction:
410                 return typeSelectionPanel.getCurrentSelection();
411             default:
412         }
413         return null;
414     }
415     
416     /**
417      * initializes the base type (group ref) panel, with view and explorer
418      *
419      */

420     private void initializeTypePanel() {
421         typeSelectionPanel = new SchemaComponentSelectionPanel<GlobalType>(
422                 getReference().get().getModel(),GlobalType.class, null,
423                 Collections.singleton(getReference().get()), true);
424         typeSelectionPanel.addPropertyChangeListener(this);
425         groupSelectionPanel = new SchemaComponentSelectionPanel<GlobalGroup>(
426                 getReference().get().getModel(),GlobalGroup.class, null, null, false);
427         groupSelectionPanel.addPropertyChangeListener(this);
428         innerContentPanel.add(groupSelectionPanel.getTypeSelectionPanel(),"group");
429         innerContentPanel.add(typeSelectionPanel.getTypeSelectionPanel(),"type");
430         typeSelectionPanel.getTypeSelectionPanel().getAccessibleContext().
431                 setAccessibleParent(innerContentPanel);
432         groupSelectionPanel.getTypeSelectionPanel().getAccessibleContext().
433                 setAccessibleParent(innerContentPanel);
434     }
435     
436     private Class JavaDoc<? extends ReferenceableSchemaComponent> getReferenceType() {
437         ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>> childTypes =
438                 new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
439         switch(getUIContentType()) {
440             case Group:
441                 return GlobalGroup.class;
442             case Extension:
443             case Restriction:
444                 return GlobalType.class;
445             default:
446         }
447         return null;
448     }
449     /** This method is called from within the constructor to
450      * initialize the form.
451      * WARNING: Do NOT modify this code. The content of this method is
452      * always regenerated by the Form Editor.
453      */

454     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
455
private void initComponents() {
456         compositorButtonGroup = new javax.swing.ButtonGroup JavaDoc();
457         definitionButtonGroup = new javax.swing.ButtonGroup JavaDoc();
458         referenceButtonGroup = new javax.swing.ButtonGroup JavaDoc();
459         previewLabel = new javax.swing.JLabel JavaDoc();
460         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
461         previewPane = new javax.swing.JEditorPane JavaDoc() {
462             static final long serialVersionUID = 1L;
463             // disable mouse and mouse motion events
464
protected void processMouseEvent(java.awt.event.MouseEvent JavaDoc e) {
465                 e.consume();
466             }
467             protected void processMouseMotionEvent(java.awt.event.MouseEvent JavaDoc e) {
468                 e.consume();
469             }
470         };
471         definitionPanel = new javax.swing.JPanel JavaDoc();
472         compositorPanel = new javax.swing.JPanel JavaDoc();
473         sequenceButton = new javax.swing.JRadioButton JavaDoc();
474         choiceButton = new javax.swing.JRadioButton JavaDoc();
475         allButton = new javax.swing.JRadioButton JavaDoc();
476         noTypeButton = new javax.swing.JRadioButton JavaDoc();
477         compositorLabel = new javax.swing.JLabel JavaDoc();
478         referencePanel = new javax.swing.JPanel JavaDoc();
479         extensionButton = new javax.swing.JRadioButton JavaDoc();
480         restrictionButton = new javax.swing.JRadioButton JavaDoc();
481         groupButton = new javax.swing.JRadioButton JavaDoc();
482         innerContentLabel = new javax.swing.JLabel JavaDoc();
483         innerContentComboBox = new javax.swing.JComboBox JavaDoc();
484         innerContentPanel = new javax.swing.JPanel JavaDoc();
485         referenceLabel = new javax.swing.JLabel JavaDoc();
486         typeLabel = new javax.swing.JLabel JavaDoc();
487         inlineDefinitionButton = new javax.swing.JRadioButton JavaDoc();
488         existingDefinitionButton = new javax.swing.JRadioButton JavaDoc();
489         mPanel = new javax.swing.JPanel JavaDoc();
490         namePanel = new javax.swing.JPanel JavaDoc();
491         nameLabel = new javax.swing.JLabel JavaDoc();
492         nameTextField = new javax.swing.JTextField JavaDoc();
493
494         previewLabel.setLabelFor(previewPane);
495         org.openide.awt.Mnemonics.setLocalizedText(previewLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "TITLE_CustomizerForm_Preview"));
496         previewLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Preview"));
497
498         previewPane.setEditable(false);
499         previewPane.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Preview"));
500         previewPane.setContentType("text/xml");
501         previewPane.setEnabled(false);
502         jScrollPane1.setViewportView(previewPane);
503
504         definitionPanel.setLayout(new java.awt.CardLayout JavaDoc());
505
506         definitionPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
507         compositorButtonGroup.add(sequenceButton);
508         org.openide.awt.Mnemonics.setLocalizedText(sequenceButton, ContentType.Sequence.getLabel());
509         sequenceButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Sequence"));
510         sequenceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
511         sequenceButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
512
513         compositorButtonGroup.add(choiceButton);
514         org.openide.awt.Mnemonics.setLocalizedText(choiceButton, ContentType.Choice.getLabel());
515         choiceButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Choice"));
516         choiceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
517         choiceButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
518
519         compositorButtonGroup.add(allButton);
520         org.openide.awt.Mnemonics.setLocalizedText(allButton, ContentType.All.getLabel());
521         allButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_All"));
522         allButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
523         allButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
524
525         compositorButtonGroup.add(noTypeButton);
526         org.openide.awt.Mnemonics.setLocalizedText(noTypeButton, ContentType.NoType.getLabel());
527         noTypeButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_NoType"));
528         noTypeButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
529         noTypeButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
530
531         org.openide.awt.Mnemonics.setLocalizedText(compositorLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Inline_Definition_Panel", new Object JavaDoc[] {}));
532         compositorLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Inline_Definition_Panel"));
533
534         org.jdesktop.layout.GroupLayout compositorPanelLayout = new org.jdesktop.layout.GroupLayout(compositorPanel);
535         compositorPanel.setLayout(compositorPanelLayout);
536         compositorPanelLayout.setHorizontalGroup(
537             compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
538             .add(compositorPanelLayout.createSequentialGroup()
539                 .add(compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
540                     .add(compositorLabel)
541                     .add(compositorPanelLayout.createSequentialGroup()
542                         .add(11, 11, 11)
543                         .add(compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
544                             .add(sequenceButton)
545                             .add(choiceButton)
546                             .add(allButton)
547                             .add(noTypeButton))))
548                 .addContainerGap(384, Short.MAX_VALUE))
549         );
550         compositorPanelLayout.setVerticalGroup(
551             compositorPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
552             .add(compositorPanelLayout.createSequentialGroup()
553                 .add(compositorLabel)
554                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
555                 .add(sequenceButton)
556                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
557                 .add(choiceButton)
558                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
559                 .add(allButton)
560                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
561                 .add(noTypeButton)
562                 .addContainerGap(187, Short.MAX_VALUE))
563         );
564         definitionPanel.add(compositorPanel, "compositor");
565
566         referenceButtonGroup.add(extensionButton);
567         org.openide.awt.Mnemonics.setLocalizedText(extensionButton, ContentType.Extension.getLabel());
568         extensionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Extension"));
569         extensionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
570         extensionButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
571
572         referenceButtonGroup.add(restrictionButton);
573         org.openide.awt.Mnemonics.setLocalizedText(restrictionButton, ContentType.Restriction.getLabel());
574         restrictionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Restriction"));
575         restrictionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
576         restrictionButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
577
578         referenceButtonGroup.add(groupButton);
579         org.openide.awt.Mnemonics.setLocalizedText(groupButton, ContentType.Group.getLabel());
580         groupButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content_Group"));
581         groupButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
582         groupButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
583
584         innerContentLabel.setLabelFor(innerContentComboBox);
585         org.openide.awt.Mnemonics.setLocalizedText(innerContentLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_InnerContent"));
586         innerContentLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_InnerContent"));
587         innerContentLabel.setEnabled(false);
588
589         innerContentComboBox.setModel(new DefaultComboBoxModel JavaDoc(
590             new Object JavaDoc[]
591             {
592                 ContentType.Sequence,
593                 ContentType.Choice,
594                 ContentType.All,
595                 ContentType.NoType,
596                 ContentType.Group,
597             }
598         ));
599         innerContentComboBox.setEnabled(false);
600
601         innerContentPanel.setLayout(new java.awt.CardLayout JavaDoc());
602
603         initializeTypePanel();
604
605         org.openide.awt.Mnemonics.setLocalizedText(referenceLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Existing_Definition_Panel", new Object JavaDoc[] {}));
606         referenceLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Existing_Definition_Panel"));
607
608         org.jdesktop.layout.GroupLayout referencePanelLayout = new org.jdesktop.layout.GroupLayout(referencePanel);
609         referencePanel.setLayout(referencePanelLayout);
610         referencePanelLayout.setHorizontalGroup(
611             referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
612             .add(referenceLabel)
613             .add(referencePanelLayout.createSequentialGroup()
614                 .addContainerGap()
615                 .add(extensionButton)
616                 .add(5, 5, 5)
617                 .add(innerContentLabel)
618                 .add(5, 5, 5)
619                 .add(innerContentComboBox, 0, 278, Short.MAX_VALUE)
620                 .addContainerGap())
621             .add(referencePanelLayout.createSequentialGroup()
622                 .addContainerGap()
623                 .add(restrictionButton)
624                 .addContainerGap(385, Short.MAX_VALUE))
625             .add(referencePanelLayout.createSequentialGroup()
626                 .addContainerGap()
627                 .add(referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
628                     .add(referencePanelLayout.createSequentialGroup()
629                         .add(17, 17, 17)
630                         .add(innerContentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE))
631                     .add(referencePanelLayout.createSequentialGroup()
632                         .add(groupButton)
633                         .addContainerGap(385, Short.MAX_VALUE))))
634         );
635
636         referencePanelLayout.linkSize(new java.awt.Component JavaDoc[] {extensionButton, groupButton, restrictionButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
637
638         referencePanelLayout.setVerticalGroup(
639             referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
640             .add(referencePanelLayout.createSequentialGroup()
641                 .add(referenceLabel)
642                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
643                 .add(referencePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
644                     .add(extensionButton)
645                     .add(innerContentLabel)
646                     .add(innerContentComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
647                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
648                 .add(restrictionButton)
649                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
650                 .add(groupButton)
651                 .add(0, 0, 0)
652                 .add(innerContentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
653         );
654         definitionPanel.add(referencePanel, "reference");
655
656         org.openide.awt.Mnemonics.setLocalizedText(typeLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Content", new Object JavaDoc[] {}));
657         typeLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Content"));
658
659         definitionButtonGroup.add(inlineDefinitionButton);
660         org.openide.awt.Mnemonics.setLocalizedText(inlineDefinitionButton, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Inline_Definition_Button"));
661         inlineDefinitionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Inline_Definition_Button"));
662         inlineDefinitionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
663         inlineDefinitionButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
664
665         definitionButtonGroup.add(existingDefinitionButton);
666         org.openide.awt.Mnemonics.setLocalizedText(existingDefinitionButton, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_ComplexType_Existing_Definition_Button"));
667         existingDefinitionButton.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Existing_Definition_Button"));
668         existingDefinitionButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
669         existingDefinitionButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
670
671         mPanel.setLayout(new java.awt.BorderLayout JavaDoc());
672
673         mPanel.add(getMessageDisplayer().getComponent(),java.awt.BorderLayout.CENTER);
674
675         nameLabel.setLabelFor(nameTextField);
676         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "LBL_CustomizerForm_Name"));
677         nameLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ComplexTypeCustomizer.class, "HINT_ComplexType_Name"));
678
679         nameTextField.setEditable(!hasParent());
680
681         org.jdesktop.layout.GroupLayout namePanelLayout = new org.jdesktop.layout.GroupLayout(namePanel);
682         namePanel.setLayout(namePanelLayout);
683         namePanelLayout.setHorizontalGroup(
684             namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
685             .add(namePanelLayout.createSequentialGroup()
686                 .addContainerGap()
687                 .add(nameLabel)
688                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
689                 .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)
690                 .addContainerGap())
691         );
692         namePanelLayout.setVerticalGroup(
693             namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
694             .add(namePanelLayout.createSequentialGroup()
695                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
696                 .add(namePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
697                     .add(nameLabel)
698                     .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
699         );
700
701         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
702         this.setLayout(layout);
703         layout.setHorizontalGroup(
704             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
705             .add(layout.createSequentialGroup()
706                 .addContainerGap()
707                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
708                     .add(typeLabel)
709                     .add(layout.createSequentialGroup()
710                         .add(10, 10, 10)
711                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
712                             .add(existingDefinitionButton)
713                             .add(inlineDefinitionButton))))
714                 .addContainerGap(357, Short.MAX_VALUE))
715             .add(layout.createSequentialGroup()
716                 .addContainerGap()
717                 .add(previewLabel)
718                 .addContainerGap(448, Short.MAX_VALUE))
719             .add(namePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
720             .add(layout.createSequentialGroup()
721                 .addContainerGap()
722                 .add(definitionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
723                 .addContainerGap())
724             .add(layout.createSequentialGroup()
725                 .addContainerGap()
726                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
727                 .addContainerGap())
728             .add(org.jdesktop.layout.GroupLayout.TRAILING, mPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
729         );
730         layout.setVerticalGroup(
731             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
732             .add(layout.createSequentialGroup()
733                 .add(namePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
734                 .add(11, 11, 11)
735                 .add(typeLabel)
736                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
737                 .add(inlineDefinitionButton)
738                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
739                 .add(existingDefinitionButton)
740                 .add(11, 11, 11)
741                 .add(definitionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
742                 .add(11, 11, 11)
743                 .add(previewLabel)
744                 .add(5, 5, 5)
745                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
746                 .add(0, 0, 0)
747                 .add(mPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
748         );
749     }// </editor-fold>//GEN-END:initComponents
750

751     
752     // Variables declaration - do not modify//GEN-BEGIN:variables
753
private javax.swing.JRadioButton JavaDoc allButton;
754     private javax.swing.JRadioButton JavaDoc choiceButton;
755     private javax.swing.ButtonGroup JavaDoc compositorButtonGroup;
756     private javax.swing.JLabel JavaDoc compositorLabel;
757     private javax.swing.JPanel JavaDoc compositorPanel;
758     private javax.swing.ButtonGroup JavaDoc definitionButtonGroup;
759     private javax.swing.JPanel JavaDoc definitionPanel;
760     private javax.swing.JRadioButton JavaDoc existingDefinitionButton;
761     private javax.swing.JRadioButton JavaDoc extensionButton;
762     private javax.swing.JRadioButton JavaDoc groupButton;
763     private javax.swing.JRadioButton JavaDoc inlineDefinitionButton;
764     private javax.swing.JComboBox JavaDoc innerContentComboBox;
765     private javax.swing.JLabel JavaDoc innerContentLabel;
766     private javax.swing.JPanel JavaDoc innerContentPanel;
767     private javax.swing.JScrollPane JavaDoc jScrollPane1;
768     private javax.swing.JPanel JavaDoc mPanel;
769     private javax.swing.JLabel JavaDoc nameLabel;
770     private javax.swing.JPanel JavaDoc namePanel;
771     private javax.swing.JTextField JavaDoc nameTextField;
772     private javax.swing.JRadioButton JavaDoc noTypeButton;
773     private javax.swing.JLabel JavaDoc previewLabel;
774     private javax.swing.JEditorPane JavaDoc previewPane;
775     private javax.swing.ButtonGroup JavaDoc referenceButtonGroup;
776     private javax.swing.JLabel JavaDoc referenceLabel;
777     private javax.swing.JPanel JavaDoc referencePanel;
778     private javax.swing.JRadioButton JavaDoc restrictionButton;
779     private javax.swing.JRadioButton JavaDoc sequenceButton;
780     private javax.swing.JLabel JavaDoc typeLabel;
781     // End of variables declaration//GEN-END:variables
782

783     /**
784      * content type from model
785      */

786     private transient ContentType contentType;
787     /**
788      * inner content type from model
789      */

790     private transient ContentType innerContentType;
791     /**
792      * reference to group or base type from model
793      */

794     private transient ReferenceableSchemaComponent gRef;
795     /**
796      * name document listener
797      */

798     private transient DocumentListener JavaDoc nameListener;
799     /**
800      * content radio buttons listener
801      */

802     private transient ItemListener JavaDoc buttonListener;
803     /**
804      * parent component for new type
805      */

806     private transient SchemaComponent parent;
807     
808     /**
809      * group selection panel
810      */

811     private transient SchemaComponentSelectionPanel<GlobalGroup>
812             groupSelectionPanel;
813     /**
814      * type selection panel
815      */

816     private transient SchemaComponentSelectionPanel<GlobalType>
817             typeSelectionPanel;
818     
819     
820     
821     private enum ContentType {
822         NoType(NbBundle.getMessage(ComplexTypeCustomizer.class,
823         "LBL_ComplexType_Content_NoType")),
824         Sequence(NbBundle.getMessage(ComplexTypeCustomizer.class,
825         "LBL_ComplexType_Content_Sequence")),
826         Choice(NbBundle.getMessage(ComplexTypeCustomizer.class,
827         "LBL_ComplexType_Content_Choice")),
828         All(NbBundle.getMessage(ComplexTypeCustomizer.class,
829         "LBL_ComplexType_Content_All")),
830         Group(NbBundle.getMessage(ComplexTypeCustomizer.class,
831         "LBL_ComplexType_Content_Group")),
832         Extension(NbBundle.getMessage(ComplexTypeCustomizer.class,
833         "LBL_ComplexType_Content_Extension")),
834         Restriction(NbBundle.getMessage(ComplexTypeCustomizer.class,
835         "LBL_ComplexType_Content_Restriction"));
836         ContentType(String JavaDoc label) {
837             this.label = label;
838         }
839         
840         public String JavaDoc toString() {
841             int idx = org.openide.awt.Mnemonics.findMnemonicAmpersand(label);
842             if(idx>-1&&idx<label.length()) {
843                 String JavaDoc toStr = label.substring(0,idx);
844                 if(idx+1<label.length()) {
845                     toStr = toStr.concat(label.substring(idx+1,label.length()));
846                 }
847                 return toStr;
848             }
849             return label;
850         }
851         
852         public String JavaDoc getLabel() {
853             return label;
854         }
855         
856         private String JavaDoc label;
857     }
858     
859     protected void applyChanges() throws IOException JavaDoc {
860         saveName();
861         ContentType uiContentType = getUIContentType();
862         ReferenceableSchemaComponent uiRef = getUIReference();
863         switch(uiContentType) {
864             case NoType:
865             case All:
866             case Sequence:
867             case Choice:
868                 if(uiContentType!=getModelContentType()) saveContentType();
869                 break;
870             case Group:
871                 if(uiRef instanceof GlobalGroup && (uiContentType!=
872                         getModelContentType() || uiRef!=getModelReference()))
873                     saveContentType();
874                 break;
875             case Restriction:
876                 if(uiRef instanceof GlobalType && (uiContentType!=
877                         getModelContentType() || uiRef!=getModelReference()))
878                     saveContentType();
879                 break;
880             case Extension:
881                 if(uiRef instanceof GlobalSimpleType ||
882                         uiRef instanceof GlobalComplexType &&
883                         ((GlobalComplexType)uiRef).getDefinition() instanceof
884                         SimpleContent) {
885                     if(uiContentType!=getModelContentType() ||
886                             uiRef!=getModelReference()) {
887                         saveContentType();
888                     }
889                 } else if(uiRef instanceof GlobalComplexType) {
890                     ContentType uiInnerContentType = getUIInnerContentType();
891                     if(uiInnerContentType!=null) {
892                         if(uiContentType!=getModelContentType() ||
893                                 uiRef!=getModelReference() ||
894                                 uiInnerContentType!= getModelInnerContentType()) {
895                             saveContentType();
896                         }
897                     }
898                 }
899         }
900     }
901     
902     ComplexType saveContentType() {
903         ComplexType type = getSchemaComponent();
904         SchemaComponentFactory factory = getSchemaModel().getFactory();
905         ComplexTypeDefinition currentDef = type.getDefinition();
906         ReferenceableSchemaComponent ref = getUIReference();
907         LocalAttributeContainer lac = type;
908         if(currentDef instanceof ComplexContent) {
909             ComplexContent cc = (ComplexContent)currentDef;
910             if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
911                 lac = (ComplexContentRestriction)cc.getLocalDefinition();
912             } else if(cc.getLocalDefinition() instanceof ComplexExtension) {
913                 lac = (ComplexExtension)cc.getLocalDefinition();
914             }
915         } else if(currentDef instanceof SimpleContent) {
916             SimpleContent sc = (SimpleContent)currentDef;
917             if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
918                 lac = (SimpleContentRestriction)sc.getLocalDefinition();
919             } else if(sc.getLocalDefinition() instanceof SimpleExtension) {
920                 lac = (SimpleExtension)sc.getLocalDefinition();
921             }
922         }
923         switch (getUIContentType()) {
924             case NoType:
925                 assert currentDef != null;
926                 type.setDefinition(null);
927                 break;
928             case All:
929                 assert !(currentDef instanceof All);
930                 All all = factory.createAll();
931                 // try to preserve old contents
932
if(currentDef instanceof Choice || currentDef instanceof Sequence) {
933                     copyContent(currentDef, all);
934                 }
935                 type.setDefinition(all);
936                 break;
937             case Choice:
938                 assert !(currentDef instanceof Choice);
939                 Choice choice = factory.createChoice();
940                 // try to preserve old contents
941
if(currentDef instanceof All || currentDef instanceof Sequence) {
942                     copyContent(currentDef, choice);
943                 }
944                 type.setDefinition(choice);
945                 break;
946             case Sequence:
947                 Sequence sequence = factory.createSequence();
948                 // try to preserve old contents
949
if(currentDef instanceof All || currentDef instanceof Choice) {
950                     copyContent(currentDef, sequence);
951                 }
952                 type.setDefinition(sequence);
953                 break;
954             case Group:
955                 assert ref instanceof GlobalGroup;
956                 GroupReference group;
957                 if(currentDef instanceof GroupReference)
958                     group = (GroupReference) currentDef;
959                 else
960                     group = factory.createGroupReference();
961                 group.setRef(group.createReferenceTo((GlobalGroup)ref, GlobalGroup.class));
962                 type.setDefinition(group);
963                 break;
964             case Extension:
965                 assert ref instanceof GlobalType;
966                 if(ref instanceof GlobalSimpleType ||
967                         ref instanceof GlobalComplexType &&
968                         ((GlobalComplexType)ref).getDefinition() instanceof SimpleContent) {
969                     SimpleExtension se = null;
970                     if(currentDef instanceof SimpleContent) {
971                         SimpleContent sc = (SimpleContent)currentDef;
972                         if(sc.getLocalDefinition() instanceof SimpleExtension) {
973                             se = (SimpleExtension)sc.getLocalDefinition();
974                         } else {
975                             se = factory.createSimpleExtension();
976                             moveAttributeContents(lac,se);
977                             sc.setLocalDefinition(se);
978                         }
979                     } else {
980                         SimpleContent sc = factory.createSimpleContent();
981                         se = factory.createSimpleExtension();
982                         moveAttributeContents(lac,se);
983                         sc.setLocalDefinition(se);
984                         type.setDefinition(sc);
985                     }
986                     se.setBase(se.createReferenceTo(
987                             (GlobalType)ref, GlobalType.class));
988                 } else if(ref instanceof GlobalComplexType) {
989                     assert getUIInnerContentType()!=null;
990                     ComplexExtension ce = null;
991                     if(currentDef instanceof ComplexContent) {
992                         ComplexContent cc = (ComplexContent)currentDef;
993                         if(cc.getLocalDefinition() instanceof ComplexExtension) {
994                             ce = (ComplexExtension)cc.getLocalDefinition();
995                         } else {
996                             ce = factory.createComplexExtension();
997                             copyContent(cc.getLocalDefinition(),ce);
998                             //moveAttributeContents(lac,ce);
999
cc.setLocalDefinition(ce);
1000                        }
1001                    } else {
1002                        ComplexContent cc = factory.createComplexContent();
1003                        ce = factory.createComplexExtension();
1004                        moveComplexContents(lac,ce);
1005                        cc.setLocalDefinition(ce);
1006                        type.setDefinition(cc);
1007                    }
1008                    GlobalComplexType gct = (GlobalComplexType)ref;
1009                    ce.setBase(ce.createReferenceTo(gct, GlobalType.class));
1010                    if(getUIInnerContentType()!=getModelInnerContentType()) {
1011                        ComplexExtensionDefinition ced = null;
1012                        switch(getUIInnerContentType()) {
1013                            case Group:
1014                                ced = factory.createGroupReference();
1015                                break;
1016                            case All:
1017                                ced = factory.createAll();
1018                                break;
1019                            case Sequence:
1020                                ced = factory.createSequence();
1021                                break;
1022                            case Choice:
1023                                ced = factory.createChoice();
1024                                break;
1025                            default:
1026                        }
1027                        if(ced!=null && ce.getLocalDefinition()!=null) {
1028                            copyContent(ce.getLocalDefinition(),ced);
1029                        }
1030                        ce.setLocalDefinition(ced);
1031                    }
1032                }
1033                break;
1034            case Restriction:
1035                assert ref instanceof GlobalType;
1036                if(ref instanceof GlobalSimpleType ||
1037                        ref instanceof GlobalComplexType &&
1038                        ((GlobalComplexType)ref).getDefinition() instanceof SimpleContent) {
1039                    SimpleContentRestriction scr = null;
1040                    if(currentDef instanceof SimpleContent) {
1041                        SimpleContent sc = (SimpleContent)currentDef;
1042                        if(sc.getLocalDefinition() instanceof SimpleContentRestriction) {
1043                            scr = (SimpleContentRestriction)sc.getLocalDefinition();
1044                            if(scr.getInlineType()!=null) scr.setInlineType(null);
1045                        } else {
1046                            scr = factory.createSimpleContentRestriction();
1047                            moveAttributeContents(lac,scr);
1048                            sc.setLocalDefinition(scr);
1049                        }
1050                    } else {
1051                        SimpleContent sc = factory.createSimpleContent();
1052                        scr = factory.createSimpleContentRestriction();
1053                        moveAttributeContents(lac,scr);
1054                        sc.setLocalDefinition(scr);
1055                        type.setDefinition(sc);
1056                    }
1057                    scr.setBase(scr.createReferenceTo(
1058                            (GlobalType)ref, GlobalType.class));
1059                } else if(ref instanceof GlobalComplexType) {
1060                    ComplexContentRestriction ccr = null;
1061                    if(currentDef instanceof ComplexContent) {
1062                        ComplexContent cc = (ComplexContent)currentDef;
1063                        if(cc.getLocalDefinition() instanceof ComplexContentRestriction) {
1064                            ccr = (ComplexContentRestriction)cc.getLocalDefinition();
1065                        } else {
1066                            ccr = factory.createComplexContentRestriction();
1067                            moveAttributeContents(lac,ccr);
1068                            cc.setLocalDefinition(ccr);
1069                        }
1070                    } else {
1071                        ComplexContent cc = factory.createComplexContent();
1072                        ccr = factory.createComplexContentRestriction();
1073                        moveAttributeContents(lac,ccr);
1074                        cc.setLocalDefinition(ccr);
1075                        type.setDefinition(cc);
1076                    }
1077                    GlobalComplexType gct = (GlobalComplexType)ref;
1078                    ccr.setBase(ccr.createReferenceTo(
1079                            gct, GlobalComplexType.class));
1080                    ComplexTypeDefinition newInnerDef = null;
1081                    
1082                    if(gct.getDefinition() instanceof All ||
1083                            gct.getDefinition() instanceof Choice ||
1084                            gct.getDefinition() instanceof Sequence ||
1085                            gct.getDefinition() instanceof GroupReference) {
1086                        newInnerDef = gct.getDefinition();
1087                    } else if(gct.getDefinition() instanceof ComplexContent) {
1088                        ComplexContent cc = (ComplexContent)gct.getDefinition();
1089                        if (cc.getLocalDefinition() instanceof ComplexContentRestriction) {
1090                            newInnerDef = ((ComplexContentRestriction)cc.
1091                                    getLocalDefinition()).getDefinition();
1092                        } else if (cc.getLocalDefinition() instanceof ComplexExtension) {
1093                            newInnerDef = (ComplexTypeDefinition)((ComplexExtension)cc.
1094                                    getLocalDefinition()).getLocalDefinition();
1095                        }
1096                    }
1097                    ccr.setDefinition((ComplexTypeDefinition) newInnerDef.copy(ccr));
1098                }
1099                break;
1100        }
1101        this.contentType = contentType;
1102        return type;
1103    }
1104    
1105    private void copyContent(final SchemaComponent oldParent,
1106            final SchemaComponent newParent) {
1107        if(oldParent==null || newParent==null) return;
1108        SchemaModel model = getSchemaModel();
1109        for(SchemaComponent child :oldParent.getChildren()) {
1110            if(newParent.canPaste(child))
1111                model.addChildComponent(newParent,child.copy(newParent),-1);
1112        }
1113    }
1114    
1115    private void moveAttributeContents(final LocalAttributeContainer oldParent,
1116            final LocalAttributeContainer newParent) {
1117        if(oldParent==null || newParent==null) return;
1118        SchemaModel model = getSchemaModel();
1119        ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>> attrChildTypes =
1120                new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>(4);
1121        attrChildTypes.add(LocalAttribute.class);
1122        attrChildTypes.add(AttributeReference.class);
1123        attrChildTypes.add(AttributeGroupReference.class);
1124        attrChildTypes.add(AnyAttribute.class);
1125        for(SchemaComponent child :oldParent.getChildren(attrChildTypes)) {
1126            if(newParent.canPaste(child))
1127                model.addChildComponent(newParent,child.copy(newParent),-1);
1128            model.removeChildComponent(child);
1129        }
1130    }
1131        
1132    private void moveComplexContents(final LocalAttributeContainer oldParent,
1133            final LocalAttributeContainer newParent) {
1134        if(oldParent==null || newParent==null) return;
1135        SchemaModel model = getSchemaModel();
1136        ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>> childTypes =
1137                new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>(4);
1138        childTypes.add(LocalAttribute.class);
1139        childTypes.add(AttributeReference.class);
1140        childTypes.add(AttributeGroupReference.class);
1141        childTypes.add(AnyAttribute.class);
1142        childTypes.add(ComplexTypeDefinition.class);
1143        for(SchemaComponent child :oldParent.getChildren(childTypes)) {
1144            if(newParent.canPaste(child))
1145                model.addChildComponent(newParent,child.copy(newParent),-1);
1146            model.removeChildComponent(child);
1147        }
1148    }
1149    
1150    public void reset() {
1151        removeListeners();
1152        initialize();
1153        initializeUI();
1154        addListeners();
1155        if(hasParent()) {
1156            setSaveEnabled(false);
1157        } else {
1158            setSaveEnabled(true);
1159        }
1160        setResetEnabled(false);
1161    }
1162    
1163    public HelpCtx getHelpCtx() {
1164        return new HelpCtx(ComplexTypeCustomizer.class);
1165    }
1166    
1167    /**
1168     * listens to property change events from explorer manager node selections
1169     */

1170    public void propertyChange(PropertyChangeEvent JavaDoc evt) {
1171        if (evt.getPropertyName().equals(SchemaComponentSelectionPanel.PROPERTY_SELECTION)) {
1172            enableDisableComboBox();
1173            setPreviewText();
1174            determineValidity();
1175        }
1176    }
1177    
1178    /**
1179     * determines validity of customizer.
1180     */

1181    private void determineValidity() {
1182        getMessageDisplayer().clear();
1183        boolean nameChanged = isNameable()&&isNameChanged();
1184        if(!nameChanged && getUIContentType() == getModelContentType() &&
1185                getUIInnerContentType()==getModelInnerContentType() &&
1186                getUIReference()==getModelReference()) {
1187            if(hasParent()) {
1188                setSaveEnabled(false);
1189            } else {
1190                setSaveEnabled(true);
1191            }
1192            setResetEnabled(false);
1193        } else {
1194            setResetEnabled(true);
1195            boolean valid = false;
1196            switch(getUIContentType()) {
1197                case Extension:
1198                    if(getUIReference() instanceof GlobalSimpleType ||
1199                            getUIReference() instanceof GlobalComplexType &&
1200                            (((GlobalComplexType)getUIReference()).getDefinition()
1201                            instanceof SimpleContent || getUIInnerContentType()!=null)) {
1202                        valid = true;
1203                    }
1204                    break;
1205                case Restriction:
1206                    if(getUIReference() instanceof GlobalType) {
1207                        valid = true;
1208                    }
1209                    break;
1210                case Group:
1211                    if(getUIReference() instanceof GlobalGroup) {
1212                        valid = true;
1213                    }
1214                    break;
1215                case NoType:
1216                case All:
1217                case Sequence:
1218                case Choice:
1219                    valid = true;
1220                    break;
1221                default:
1222            }
1223            setSaveEnabled(valid && (!isNameChanged() || isNameValid()));
1224            if(!valid) {
1225                if(getUIContentType()==ContentType.Group) {
1226                    getMessageDisplayer().annotate(org.openide.util.NbBundle.
1227                            getMessage(ComplexTypeCustomizer.class,
1228                            "MSG_Group_Error"),
1229                            MessageDisplayer.Type.ERROR);
1230                } else {
1231                    getMessageDisplayer().annotate(org.openide.util.NbBundle.
1232                            getMessage(ComplexTypeCustomizer.class,
1233                            "MSG_Type_Error"),
1234                            MessageDisplayer.Type.ERROR);
1235                }
1236            }
1237        }
1238    }
1239    
1240    private void setPreviewText() {
1241        StringBuffer JavaDoc retValue = new StringBuffer JavaDoc("<");
1242        String JavaDoc prefix = getReference().get().getPeer().getPrefix();
1243        if(prefix!=null) retValue.append(prefix+":");
1244        retValue.append("complexType");
1245        if(isNameable()) {
1246            retValue.append(" name=\"");
1247            retValue.append(getUIName());
1248            retValue.append("\"");
1249        }
1250        retValue.append(">");
1251        ReferenceableSchemaComponent ref = getUIReference();
1252        boolean complexContent = true;
1253        if(ref instanceof GlobalSimpleType ||
1254                ref instanceof GlobalComplexType &&
1255                ((GlobalComplexType)ref).getDefinition()
1256                instanceof SimpleContent)
1257            complexContent = false;
1258        switch(getUIContentType()) {
1259            case NoType:
1260                break;
1261            case Sequence:
1262                retValue.append("\n <");
1263                if(prefix!=null) retValue.append(prefix+":");
1264                retValue.append("sequence/>");
1265                break;
1266            case Choice:
1267                retValue.append("\n <");
1268                if(prefix!=null) retValue.append(prefix+":");
1269                retValue.append("choice/>");
1270                break;
1271            case All:
1272                retValue.append("\n <");
1273                if(prefix!=null) retValue.append(prefix+":");
1274                retValue.append("all/>");
1275                break;
1276            case Group:
1277                retValue.append("\n <");
1278                if(prefix!=null) retValue.append(prefix+":");
1279                retValue.append("group ref=\"");
1280                if(ref!=null) {
1281                    retValue.append(ref.getName());
1282                }
1283                retValue.append("\"/>");
1284                break;
1285            case Extension:
1286                if(complexContent) {
1287                    retValue.append("\n <");
1288                    if(prefix!=null) retValue.append(prefix+":");
1289                    retValue.append("complexContent>");
1290                } else {
1291                    retValue.append("\n <");
1292                    if(prefix!=null) retValue.append(prefix+":");
1293                    retValue.append("simpleContent>");
1294                }
1295                retValue.append("\n <");
1296                if(prefix!=null) retValue.append(prefix+":");
1297                retValue.append("extension base=\"");
1298                if(ref!=null) {
1299                    retValue.append(ref.getName());
1300                }
1301                retValue.append("\">");
1302                if(complexContent && ref!=null) {
1303                    switch(getUIInnerContentType()) {
1304                        case NoType:
1305                            break;
1306                        case Sequence:
1307                            retValue.append("\n <");
1308                            if(prefix!=null) retValue.append(prefix+":");
1309                            retValue.append("sequence/>");
1310                            break;
1311                        case Choice:
1312                            retValue.append("\n <");
1313                            if(prefix!=null) retValue.append(prefix+":");
1314                            retValue.append("choice/>");
1315                            break;
1316                        case All:
1317                            retValue.append("\n <");
1318                            if(prefix!=null) retValue.append(prefix+":");
1319                            retValue.append("all/>");
1320                            break;
1321                        case Group:
1322                            retValue.append("\n <");
1323                            if(prefix!=null) retValue.append(prefix+":");
1324                            retValue.append("group ref=\"\"/>");
1325                            break;
1326                    }
1327                }
1328                retValue.append("\n </");
1329                if(prefix!=null) retValue.append(prefix+":");
1330                retValue.append("extension>");
1331                if(complexContent) {
1332                    retValue.append("\n </");
1333                    if(prefix!=null) retValue.append(prefix+":");
1334                    retValue.append("complexContent>");
1335                } else {
1336                    retValue.append("\n </");
1337                    if(prefix!=null) retValue.append(prefix+":");
1338                    retValue.append("simpleContent>");
1339                }
1340                break;
1341            case Restriction:
1342                if(complexContent) {
1343                    retValue.append("\n <");
1344                    if(prefix!=null) retValue.append(prefix+":");
1345                    retValue.append("complexContent>");
1346                } else {
1347                    retValue.append("\n <");
1348                    if(prefix!=null) retValue.append(prefix+":");
1349                    retValue.append("simpleContent>");
1350                }
1351                retValue.append("\n <");
1352                if(prefix!=null) retValue.append(prefix+":");
1353                retValue.append("restriction base=\"");
1354                if(ref!=null) {
1355                    retValue.append(ref.getName());
1356                }
1357                retValue.append("\">");
1358                retValue.append("\n </");
1359                if(prefix!=null) retValue.append(prefix+":");
1360                retValue.append("restriction>");
1361                if(complexContent) {
1362                    retValue.append("\n </");
1363                    if(prefix!=null) retValue.append(prefix+":");
1364                    retValue.append("complexContent>");
1365                } else {
1366                    retValue.append("\n </");
1367                    if(prefix!=null) retValue.append(prefix+":");
1368                    retValue.append("simpleContent>");
1369                }
1370                break;
1371        }
1372        retValue.append("\n</");
1373        if(prefix!=null) retValue.append(prefix+":");
1374        retValue.append("complexType>\n");
1375        previewPane.setText(retValue.toString());
1376    }
1377    
1378    private SchemaModel getSchemaModel() {
1379        return getSchemaComponent().getModel();
1380    }
1381    
1382    private ComplexType getSchemaComponent() {
1383        if(getReference()==null || getReference().get()==null) return null;
1384        return getReference().get();
1385    }
1386}
1387
Popular Tags