Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 89029253ab6123dbef61af1502bd49007bb7a508 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.properties.sections;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand;
import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils;
import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds;
import org.eclipse.xsd.XSDForm;
import org.eclipse.xsd.util.XSDConstants;

public class XSDSchemaAdvancedSection extends AbstractSection
{
  IWorkbenchPart part;
  protected CLabel elementFormLabel, attributeFormLabel, blockDefaultLabel, finalDefaultLabel;
  protected CCombo elementFormCombo, attributeFormCombo, blockDefaultCombo, finalDefaultCombo;  
  
  protected static final String emptyOption = ""; //$NON-NLS-1$
  
  protected static final String [] formQualification = { emptyOption, XSDForm.QUALIFIED_LITERAL.getLiteral(), 
      XSDForm.UNQUALIFIED_LITERAL.getLiteral() };  //$NON-NLS-1$

    
  protected static final String derivedByChoicesComboValues[] = { "", XSDConstants.RESTRICTION_ELEMENT_TAG, //$NON-NLS-1$ 
      XSDConstants.EXTENSION_ELEMENT_TAG }; 
  
  protected static final String blockDefaultValues[] = { emptyOption, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$
      XSDConstants.EXTENSION_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG,
      "substitution"};
  
  protected static final String finalDefaultValues[] = { emptyOption, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$
      XSDConstants.EXTENSION_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG, 
      XSDConstants.LIST_ELEMENT_TAG, XSDConstants.UNION_ELEMENT_TAG};      

  public XSDSchemaAdvancedSection()
  {
    super();
  }

  /**
   * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite,
   *      org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory)
   */
  public void createContents(Composite parent)
  {
    composite = getWidgetFactory().createFlatFormComposite(parent);

    GridLayout gridLayout = new GridLayout();
    gridLayout.marginTop = 0;
    gridLayout.marginBottom = 0;
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);

    // Create elementFormDefault label and combo       
    elementFormLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(),
        Messages._UI_LABEL_ELEMENTFORMDEFAULT);
    elementFormCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this,
        formQualification,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_ELEMENT_FORM_DEFAULT);

    // Create attributeFormDefault label and combo
    attributeFormLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(),
        Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT);
    attributeFormCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this,
        formQualification,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_ATTRIBUTE_FORM_DEFAULT);    
    
    // Create blockDefault label and combo
    blockDefaultLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(),
        Messages._UI_LABEL_BLOCKDEFAULT);
    blockDefaultCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this,
        blockDefaultValues,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_BLOCK_DEFAULT);
    
    // Create finalDefault label and combo
    finalDefaultLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(),
        Messages._UI_LABEL_FINALDEFAULT);
    finalDefaultCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this,
        finalDefaultValues,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_FINAL_DEFAULT);    
    
    Dialog.applyDialogFont(parent);
  }

  /*
   * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
   */
  public void refresh()
  {
    super.refresh();
    setListenerEnabled(false);
    
    if (xsdSchema != null)
    {
      if (elementFormCombo != null)
      {
        String text;
        if (xsdSchema.getElement().hasAttribute(XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE))
        {
          text = xsdSchema.getElementFormDefault().getName();  
        }
        else 
        {
          text = emptyOption;  
        } 
        elementFormCombo.setText(text);
      }
      
      if (attributeFormCombo != null)
      {
        String text;
        if (xsdSchema.getElement().hasAttribute(XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE))
        {
          text = xsdSchema.getAttributeFormDefault().getName();
        }
        else 
        {
          text = emptyOption;
        }
        attributeFormCombo.setText(text);
      }
      
      if (blockDefaultCombo != null)
      {
        String text;
        if (xsdSchema.getElement().hasAttribute(XSDConstants.BLOCKDEFAULT_ATTRIBUTE))
        {
          text = xsdSchema.getElement().getAttribute(XSDConstants.BLOCKDEFAULT_ATTRIBUTE);
        }
        else 
        {
          text = emptyOption;
        }
        blockDefaultCombo.setText(text);
      }
      
      if (finalDefaultCombo != null)
      {
        String text;
        if (xsdSchema.getElement().hasAttribute(XSDConstants.FINALDEFAULT_ATTRIBUTE))
        {
          text = xsdSchema.getElement().getAttribute(XSDConstants.FINALDEFAULT_ATTRIBUTE);
        }
        else 
        {
          text = emptyOption;
        }
        finalDefaultCombo.setText(text);
      }      
    }    
    setListenerEnabled(true);
  }
  
  public void doWidgetSelected(SelectionEvent e)
  {
    if (xsdSchema != null)
    {          
      if (e.widget == elementFormCombo && elementFormCombo != null)
      {
        String valueElementForm = elementFormCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), 
            XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE, valueElementForm, 
            Messages._UI_LABEL_ELEMENTFORMDEFAULT);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
      }
            
      if (e.widget == attributeFormCombo && attributeFormCombo != null)
      {     
        String valueAttributeForm = attributeFormCombo.getText();
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), 
            XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE, valueAttributeForm, 
            Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);        
      }
      
      if (e.widget == blockDefaultCombo && blockDefaultCombo != null)
      {
        String valueBlockDefault = blockDefaultCombo.getText();        
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), 
            XSDConstants.BLOCKDEFAULT_ATTRIBUTE, valueBlockDefault, Messages._UI_LABEL_BLOCKDEFAULT);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
      }
      
      if(e.widget == finalDefaultCombo && finalDefaultCombo != null)
      {
        String finalBlockDefault = finalDefaultCombo.getText();        
        UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), 
            XSDConstants.FINALDEFAULT_ATTRIBUTE, finalBlockDefault, Messages._UI_LABEL_FINALDEFAULT);
        command.setDeleteIfEmpty(true);
        getCommandStack().execute(command);
      }
    }
  }
}

Back to the top