Search in sources :

Example 21 with ComponentSpecification

use of org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification in project webtools.sourceediting by eclipse.

the class XSDElementDeclarationSection 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(true);
        } else if (selection.equals(Messages._UI_COMBO_NEW)) {
            dialog = manager.getNewDialog();
            ((NewTypeDialog) dialog).allowComplexType(true);
        }
        if (dialog != null) {
            if (dialog.createAndOpen() == Window.OK) {
                newValue = dialog.getSelectedComponent();
                XSDElementDeclaration elementDeclaration = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
                manager.modifyComponentReference(elementDeclaration, 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(XSDElementReferenceEditManager.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("");
            }
        } else // use the value from selected quickPick item
        {
            newValue = getComponentSpecFromQuickPickForValue(selection, manager);
            if (newValue != null)
                manager.modifyComponentReference(input, newValue);
        }
    } else if (e.widget == maxCombo) {
        updateMaxAttribute();
    } else if (e.widget == minCombo) {
        updateMinAttribute();
    }
}
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) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 22 with ComponentSpecification

use of org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeSection method fillTypesCombo.

private void fillTypesCombo() {
    typesCombo.removeAll();
    IEditorPart editor = getActiveEditor();
    ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
    if (manager != null) {
        ComponentSpecification[] items = manager.getQuickPicks();
        typesCombo.add(Messages._UI_COMBO_BROWSE);
        typesCombo.add(Messages._UI_COMBO_NEW);
        for (int i = 0; i < items.length; i++) {
            typesCombo.add(items[i].getName());
        }
        // Add the current Type of this attribute if needed
        XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input;
        XSDTypeDefinition baseType = simpleType.getBaseType();
        if (baseType != null && baseType.getQName() != null) {
            // no prefix
            String currentTypeName = baseType.getQName(xsdSchema);
            ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
            if (// not in quickPick
            ret == null && currentTypeName != null) {
                typesCombo.add(currentTypeName);
            }
        }
    }
}
Also used : XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 23 with ComponentSpecification

use of org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification in project webtools.sourceediting by eclipse.

the class SetTypeCommand method execute.

public void execute() {
    try {
        beginRecording(parent.getElement());
        ComponentReferenceEditManager componentReferenceEditManager = getComponentReferenceEditManager();
        continueApply = true;
        if (parent instanceof XSDElementDeclaration) {
            if (action.equals(SetTypeAction.SET_NEW_TYPE_ID)) {
                ComponentSpecification newValue = (ComponentSpecification) invokeDialog(componentReferenceEditManager.getNewDialog());
                if (continueApply)
                    componentReferenceEditManager.modifyComponentReference(adapter, newValue);
            } else {
                ComponentSpecification newValue = (ComponentSpecification) invokeDialog(componentReferenceEditManager.getBrowseDialog());
                if (continueApply)
                    componentReferenceEditManager.modifyComponentReference(adapter, newValue);
            }
            formatChild(parent.getElement());
        }
    } finally {
        endRecording();
    }
}
Also used : ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager)

Example 24 with ComponentSpecification

use of org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification in project webtools.sourceediting by eclipse.

the class XSDComponentDescriptionProvider method getFile.

public IFile getFile(Object component) {
    IFile result = null;
    if (component instanceof ComponentSpecification) {
        result = ((ComponentSpecification) component).getFile();
    } else if (component instanceof SearchMatch) {
        result = ((SearchMatch) component).getFile();
    } else if (component instanceof XSDConcreteComponent) {
        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) component;
        XSDSchema schema = concreteComponent.getSchema();
        if (schema != null) {
            // TODO (cs) revisit and test more
            // 
            String location = schema.getSchemaLocation();
            String platformResource = "platform:/resource";
            if (location != null && location.startsWith(platformResource)) {
                Path path = new Path(location.substring(platformResource.length()));
                result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) IFile(org.eclipse.core.resources.IFile) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 25 with ComponentSpecification

use of org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification 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)

Aggregations

ComponentSpecification (org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification)28 ComponentReferenceEditManager (org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager)15 IEditorPart (org.eclipse.ui.IEditorPart)12 ArrayList (java.util.ArrayList)7 List (java.util.List)7 IComponentDialog (org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog)6 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)6 XSDTypeReferenceEditManager (org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager)5 XSDSearchListDialogDelegate (org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)4 Element (org.w3c.dom.Element)4 XSDComplexTypeBaseTypeEditManager (org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager)3 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 Iterator (java.util.Iterator)1 IFile (org.eclipse.core.resources.IFile)1 Path (org.eclipse.core.runtime.Path)1