Search in sources :

Example 41 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method init.

protected void init() {
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
        isAttributeReference = xsdAttribute.isAttributeDeclarationReference();
        hideHyperLink = !xsdAttribute.isGlobal() || isAttributeReference;
    }
}
Also used : XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 42 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method refresh.

/*
   * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
   */
public void refresh() {
    super.refresh();
    setListenerEnabled(false);
    // refresh name
    // $NON-NLS-1$
    nameText.setText("");
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
        String name = namedComponent.getName();
        if (name != null) {
            nameText.setText(name);
        }
    }
    if (isAttributeReference) {
        refreshRefCombo();
    }
    // refresh type
    // $NON-NLS-1$
    typeCombo.setText("");
    if (input != null) {
        if (input instanceof XSDAttributeDeclaration) {
            XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
            isAttributeReference = ((XSDAttributeDeclaration) input).isAttributeDeclarationReference();
            XSDTypeDefinition typeDef = xsdAttribute.getResolvedAttributeDeclaration().getTypeDefinition();
            boolean isAnonymous = xsdAttribute.getAnonymousTypeDefinition() != null;
            if (isAnonymous) {
                // $NON-NLS-1$
                typeCombo.setText("**anonymous**");
            } else {
                fillTypesCombo();
                if (typeDef != null) {
                    typeName = typeDef.getQName(xsdSchema);
                    if (typeName == null) {
                        // $NON-NLS-1$
                        typeName = "";
                    }
                    typeCombo.setText(typeName);
                } else {
                    // $NON-NLS-1$
                    typeCombo.setText(Messages.UI_NO_TYPE);
                }
            }
            usageCombo.setText("");
            usageCombo.setEnabled(!xsdAttribute.isGlobal());
            Element element = xsdAttribute.getElement();
            boolean hasUseAttribute = false;
            if (element != null) {
                hasUseAttribute = element.hasAttribute(XSDConstants.USE_ATTRIBUTE);
                if (hasUseAttribute) {
                    String usage = element.getAttribute(XSDConstants.USE_ATTRIBUTE);
                    usageCombo.setText(usage);
                }
            }
            // $NON-NLS-1$
            defaultOrFixedText.setText("");
            boolean hasDefaultAttribute = false, hasFixedAttribute = false;
            if (element != null) {
                hasDefaultAttribute = element.hasAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                hasFixedAttribute = element.hasAttribute(XSDConstants.FIXED_ATTRIBUTE);
                // Case where no fixed or default attributes exist, so ensure one of the radio buttons is selected
                if (!hasDefaultAttribute && !hasFixedAttribute) {
                    if (// if none are selected then pick fixed
                    !defaultButton.getSelection() && !fixedButton.getSelection())
                        fixedButton.setSelection(true);
                } else {
                    // if both are present in source (an error!), assume that *fixed* takes "precedence"
                    defaultButton.setSelection(!hasFixedAttribute && hasDefaultAttribute);
                    fixedButton.setSelection(hasFixedAttribute);
                    if (hasDefaultAttribute) {
                        String theDefault = element.getAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                        defaultOrFixedText.setText(theDefault);
                    }
                    if (// will overwrite default if both present
                    hasFixedAttribute) {
                        String fixed = element.getAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        defaultOrFixedText.setText(fixed);
                    }
                }
            }
            formCombo.setText("");
            formCombo.setEnabled(!xsdAttribute.isGlobal() && !isAttributeReference);
            boolean hasFormAttribute = false;
            if (element != null) {
                hasFormAttribute = element.hasAttribute(XSDConstants.FORM_ATTRIBUTE);
                if (hasFormAttribute) {
                    String form = element.getAttribute(XSDConstants.FORM_ATTRIBUTE);
                    formCombo.setText(form);
                }
            }
        }
    }
    setListenerEnabled(true);
}
Also used : Element(org.w3c.dom.Element) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 43 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method handleWidgetSelection.

private void handleWidgetSelection(SelectionEvent e) {
    if (e.widget == typeCombo) {
        IEditorPart editor = getActiveEditor();
        if (editor == null)
            return;
        ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
        String selection = typeCombo.getText();
        ComponentSpecification newValue;
        IComponentDialog dialog = null;
        if (selection.equals(Messages._UI_COMBO_BROWSE)) {
            dialog = manager.getBrowseDialog();
            ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
        } else if (selection.equals(Messages._UI_COMBO_NEW)) {
            dialog = manager.getNewDialog();
            ((NewTypeDialog) dialog).allowComplexType(false);
        }
        if (dialog != null) {
            if (dialog.createAndOpen() == Window.OK) {
                newValue = dialog.getSelectedComponent();
                XSDAttributeDeclaration xsdAttribute = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
                manager.modifyComponentReference(xsdAttribute, newValue);
            } else {
                typeCombo.setText(typeName);
            }
        } else // use the value from selected quickPick item
        {
            newValue = getComponentSpecFromQuickPickForValue(selection, manager);
            if (newValue != null)
                manager.modifyComponentReference(input, newValue);
        }
    } else if (e.widget == componentNameCombo) {
        IEditorPart editor = getActiveEditor();
        if (editor == null)
            return;
        ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDAttributeReferenceEditManager.class);
        String selection = componentNameCombo.getText();
        ComponentSpecification newValue;
        IComponentDialog dialog = null;
        if (selection.equals(Messages._UI_COMBO_BROWSE)) {
            dialog = manager.getBrowseDialog();
        } else if (selection.equals(Messages._UI_COMBO_NEW)) {
            dialog = manager.getNewDialog();
        }
        if (dialog != null) {
            if (dialog.createAndOpen() == Window.OK) {
                newValue = dialog.getSelectedComponent();
                manager.modifyComponentReference(input, newValue);
            } else {
                componentNameCombo.setText(refName);
            }
        } else // use the value from selected quickPick item
        {
            newValue = getComponentSpecFromQuickPickForValue(selection, manager);
            if (newValue != null)
                manager.modifyComponentReference(input, newValue);
        }
    } else {
        XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
        Element element = xsdAttribute.getElement();
        if (e.widget == usageCombo) {
            final String newValue = usageCombo.getText();
            if (element != null) {
                PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_USAGE) {

                    protected void doExecuteSteps() {
                        if (newValue.length() == 0)
                            element.removeAttribute(XSDConstants.USE_ATTRIBUTE);
                        else
                            element.setAttribute(XSDConstants.USE_ATTRIBUTE, newValue);
                    }
                };
                getCommandStack().execute(command);
            }
        } else if (e.widget == formCombo) {
            final String newValue = formCombo.getText();
            if (element != null) {
                PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FORM) {

                    protected void doExecuteSteps() {
                        if (newValue.length() == 0)
                            element.removeAttribute(XSDConstants.FORM_ATTRIBUTE);
                        else
                            element.setAttribute(XSDConstants.FORM_ATTRIBUTE, newValue);
                    }
                };
                getCommandStack().execute(command);
            }
        } else if (e.widget == defaultButton) {
            boolean newValue = defaultButton.getSelection();
            if (element != null) {
                if (newValue) {
                    if (element.hasAttribute(XSDConstants.FIXED_ATTRIBUTE)) {
                        final String value = element.getAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) {

                            protected void doExecuteSteps() {
                                element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
                                element.setAttribute(XSDConstants.DEFAULT_ATTRIBUTE, value);
                            }
                        };
                        getCommandStack().execute(command);
                    }
                }
            }
        } else if (e.widget == fixedButton) {
            boolean newValue = fixedButton.getSelection();
            if (element != null) {
                if (newValue) {
                    if (element.hasAttribute(XSDConstants.DEFAULT_ATTRIBUTE)) {
                        final String value = element.getAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                        PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) {

                            protected void doExecuteSteps() {
                                element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                                element.setAttribute(XSDConstants.FIXED_ATTRIBUTE, value);
                            }
                        };
                        getCommandStack().execute(command);
                    }
                }
            }
        }
    }
    super.doWidgetSelected(e);
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) Element(org.w3c.dom.Element) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 44 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method fillComponentNameCombo.

private void fillComponentNameCombo() {
    IEditorPart editor = getActiveEditor();
    ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDAttributeReferenceEditManager.class);
    componentNameCombo.removeAll();
    componentNameCombo.add(Messages._UI_ACTION_BROWSE);
    componentNameCombo.add(Messages._UI_ACTION_NEW);
    ComponentSpecification[] quickPicks = manager.getQuickPicks();
    if (quickPicks != null) {
        for (int i = 0; i < quickPicks.length; i++) {
            ComponentSpecification componentSpecification = quickPicks[i];
            componentNameCombo.add(componentSpecification.getName());
        }
    }
    ComponentSpecification[] history = manager.getHistory();
    if (history != null) {
        for (int i = 0; i < history.length; i++) {
            ComponentSpecification componentSpecification = history[i];
            componentNameCombo.add(componentSpecification.getName());
        }
    }
    XSDAttributeDeclaration namedComponent = (XSDAttributeDeclaration) input;
    Element element = namedComponent.getElement();
    if (element != null) {
        String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE);
        if (attrValue == null) {
            // $NON-NLS-1$
            attrValue = "";
        }
        ComponentSpecification ret = getComponentSpecFromQuickPickForValue(attrValue, manager);
        if (ret == null) {
            componentNameCombo.add(attrValue);
        }
        componentNameCombo.setText(attrValue);
        refName = attrValue;
    }
}
Also used : ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDAttributeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDAttributeReferenceEditManager) Element(org.w3c.dom.Element) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 45 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class XSDAttributeDeclarationSection method fillTypesCombo.

private void fillTypesCombo() {
    IEditorPart editor = getActiveEditor();
    XSDTypeReferenceEditManager manager = (XSDTypeReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
    if (manager != null) {
        ComponentSpecification[] items = manager.getQuickPicks();
        typeCombo.removeAll();
        typeCombo.add(Messages._UI_COMBO_BROWSE);
        typeCombo.add(Messages._UI_COMBO_NEW);
        for (int i = 0; i < items.length; i++) {
            typeCombo.add(items[i].getName());
        }
        XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
        XSDTypeDefinition namedComponentType = namedComponent.getType();
        if (namedComponentType != null) {
            // no
            String currentTypeName = namedComponentType.getQName(xsdSchema);
            // prefix
            ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
            if (// not in quickPick
            ret == null)
                typeCombo.add(currentTypeName);
        }
    }
}
Also used : XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) IEditorPart(org.eclipse.ui.IEditorPart) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)49 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)27 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)18 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)17 Iterator (java.util.Iterator)16 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)16 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)15 XSDSchema (org.eclipse.xsd.XSDSchema)15 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 List (java.util.List)10 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)9 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 XSDParticle (org.eclipse.xsd.XSDParticle)7 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)6 XSDWildcard (org.eclipse.xsd.XSDWildcard)6 EList (org.eclipse.emf.common.util.EList)5