Search in sources :

Example 21 with XSDNamedComponent

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

the class FindReferencesInWorkingSetAction method run.

public void run() {
    IWorkingSet[] workingSets = queryWorkingSets();
    if (workingSets == null || workingSets.length == 0)
        // The user chooses nothing, no point to continue.
        return;
    String pattern = "";
    XSDNamedComponent component = getXSDNamedComponent();
    IFile file = getCurrentFile();
    if (file != null && component != null) {
        QualifiedName metaName = determineMetaName(component);
        QualifiedName elementQName = new QualifiedName(component.getTargetNamespace(), component.getName());
        // Create a scope from the selected working sets
        WorkingSetSearchScope scope = new WorkingSetSearchScope();
        for (int i = 0; i < workingSets.length; i++) {
            IAdaptable[] elements = workingSets[i].getElements();
            scope.addAWorkingSetToScope(elements);
        }
        String scopeDescription = "Working Set";
        XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
        NewSearchUI.activateSearchResultView();
        NewSearchUI.runQueryInBackground(searchQuery);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFile(org.eclipse.core.resources.IFile) WorkingSetSearchScope(org.eclipse.wst.common.core.search.scope.WorkingSetSearchScope) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) IWorkingSet(org.eclipse.ui.IWorkingSet) XSDSearchQuery(org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)

Example 22 with XSDNamedComponent

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

the class XSDModelGroupDefinitionSection method doWidgetSelected.

public void doWidgetSelected(SelectionEvent e) {
    if (e.widget == componentNameCombo) {
        String newValue = componentNameCombo.getText();
        if (input instanceof XSDNamedComponent) {
            XSDNamedComponent namedComponent = (XSDNamedComponent) input;
            Element element = namedComponent.getElement();
            if (namedComponent instanceof XSDModelGroupDefinition) {
                element.setAttribute(XSDConstants.REF_ATTRIBUTE, newValue);
                XSDDirectivesManager.removeUnusedXSDImports(namedComponent.getSchema());
            }
        }
    }
    super.doWidgetSelected(e);
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) Element(org.w3c.dom.Element) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition)

Example 23 with XSDNamedComponent

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

the class XSDModelGroupDefinitionSection method refresh.

public void refresh() {
    super.refresh();
    if (isReadOnly) {
        composite.setEnabled(false);
    } else {
        composite.setEnabled(true);
    }
    setListenerEnabled(false);
    XSDNamedComponent namedComponent = (XSDNamedComponent) input;
    if (isReference) {
        Element element = namedComponent.getElement();
        if (element != null) {
            String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE);
            if (attrValue == null) {
                // $NON-NLS-1$
                attrValue = "";
            }
            componentNameCombo.setText(attrValue);
            // refresh min max
            if (minCombo != null && maxCombo != null) {
                refreshMinMax();
            }
        }
    } else {
        // refresh name
        // $NON-NLS-1$
        nameText.setText("");
        String name = namedComponent.getName();
        if (name != null) {
            nameText.setText(name);
        }
    }
    setListenerEnabled(true);
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) Element(org.w3c.dom.Element)

Example 24 with XSDNamedComponent

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

the class RenameComponentAction method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject) {
    selectedComponent = null;
    if (selectedObject instanceof XSDNamedComponent) {
        selectedComponent = (XSDNamedComponent) selectedObject;
        // if it's element reference, then this action is not appropriate
        if (selectedComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
            if (element.isElementDeclarationReference()) {
                selectedComponent = null;
            }
        }
        if (selectedComponent instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
            XSDConcreteComponent parent = type.getContainer();
            if (parent instanceof XSDElementDeclaration) {
                XSDElementDeclaration element = (XSDElementDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            } else if (parent instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            }
        }
    }
    return canRun();
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 25 with XSDNamedComponent

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

the class XSDDirectivesManager method doCrossReferencer.

/**
 * This determines the list of referenced components and hence the used schemas from which
 * we can determine what are the unused directives
 *
 * @param schema
 * @param unusedImportList
 * @param usedSchemas
 */
protected void doCrossReferencer(XSDSchema schema, List usedSchemas, Map xsdNamedComponentUsage) {
    // Calculate additional unused imports that may have the same
    // namespace that did not get added in the initial pass
    Iterator iterator = xsdNamedComponentUsage.keySet().iterator();
    // First determine the used schemas from the cross referencer
    while (iterator.hasNext()) {
        XSDNamedComponent namedComponent = (XSDNamedComponent) iterator.next();
        XSDSchema namedComponentSchema = namedComponent.getSchema();
        // want to check the external references
        if (namedComponentSchema == schema) {
            continue;
        }
        Collection collection = (Collection) xsdNamedComponentUsage.get(namedComponent);
        Iterator iterator2 = collection.iterator();
        while (iterator2.hasNext()) {
            Setting setting = (Setting) iterator2.next();
            Object obj = setting.getEObject();
            if (isComponentUsed(obj, schema, namedComponentSchema)) {
                if (!usedSchemas.contains(namedComponentSchema))
                    usedSchemas.add(namedComponentSchema);
            }
        }
    }
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Iterator(java.util.Iterator) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)26 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)8 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)6 XSDSchema (org.eclipse.xsd.XSDSchema)6 Element (org.w3c.dom.Element)6 ArrayList (java.util.ArrayList)4 Command (org.eclipse.gef.commands.Command)4 UpdateNameCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand)4 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)4 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)4 Iterator (java.util.Iterator)3 IFile (org.eclipse.core.resources.IFile)3 QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)3 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)3 Point (org.eclipse.draw2d.geometry.Point)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)2 XSDSearchQuery (org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)2 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)2 TreeObject (com.amalto.workbench.models.TreeObject)1