Search in sources :

Example 6 with XSDNamedComponent

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

the class XSDCommonUIUtils method createUniqueElementName.

public static String createUniqueElementName(String prefix, List elements) {
    ArrayList usedNames = new ArrayList();
    for (Iterator i = elements.iterator(); i.hasNext(); ) {
        usedNames.add(getDisplayName((XSDNamedComponent) i.next()));
    }
    int i = 1;
    String testName = prefix;
    while (usedNames.contains(testName)) {
        testName = prefix + i++;
    }
    return testName;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 7 with XSDNamedComponent

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

the class TopLevelComponentEditPart method doEditName.

public void doEditName(boolean addFromDesign) {
    if (!addFromDesign)
        return;
    // removeFeedback();
    Object object = ((XSDBaseAdapter) getModel()).getTarget();
    if (object instanceof XSDNamedComponent) {
        Point p = label.getLocation();
        TopLevelNameDirectEditManager manager = new TopLevelNameDirectEditManager(TopLevelComponentEditPart.this, new TopLevelComponentLabelCellEditorLocator(TopLevelComponentEditPart.this, p), (XSDNamedComponent) object);
        NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
        adtDirectEditPolicy.setUpdateCommand(wrapper);
        manager.show();
    }
}
Also used : TopLevelNameDirectEditManager(org.eclipse.wst.xsd.ui.internal.design.editpolicies.TopLevelNameDirectEditManager) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) TopLevelComponentLabelCellEditorLocator(org.eclipse.wst.xsd.ui.internal.design.editpolicies.TopLevelComponentLabelCellEditorLocator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Point(org.eclipse.draw2d.geometry.Point)

Example 8 with XSDNamedComponent

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

the class OpenOnSelectionHelper method openOnGlobalReference.

public XSDNamedComponent openOnGlobalReference(XSDConcreteComponent comp) {
    XSDSchema schema = xsdSchema;
    String name = null;
    String namespace = null;
    if (comp instanceof XSDNamedComponent) {
        name = ((XSDNamedComponent) comp).getName();
        namespace = ((XSDNamedComponent) comp).getTargetNamespace();
    }
    if (name == null) {
        // For Anonymous types, just show the element
        if (comp instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) comp;
            comp = type.getContainer();
            if (comp instanceof XSDNamedComponent) {
                name = ((XSDNamedComponent) comp).getName();
                namespace = ((XSDNamedComponent) comp).getTargetNamespace();
            }
        }
    }
    if (schema == null || name == null) {
        return null;
    }
    List objects = null;
    if (comp instanceof XSDElementDeclaration) {
        objects = schema.getElementDeclarations();
    } else if (comp instanceof XSDTypeDefinition) {
        objects = schema.getTypeDefinitions();
    } else if (comp instanceof XSDAttributeGroupDefinition) {
        objects = schema.getAttributeGroupDefinitions();
    } else if (comp instanceof XSDIdentityConstraintDefinition) {
        objects = schema.getIdentityConstraintDefinitions();
    } else if (comp instanceof XSDModelGroupDefinition) {
        objects = schema.getModelGroupDefinitions();
    } else if (comp instanceof XSDAttributeDeclaration) {
        objects = schema.getAttributeDeclarations();
    }
    if (objects != null) {
        if (namespace != null) {
            // First, look for a namespace and name match
            for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
                XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
                String targetNamespace = namedComp.getTargetNamespace();
                if (namedComp.getName().equals(name) && targetNamespace != null && targetNamespace.equals(namespace)) {
                    revealObject(namedComp);
                    return namedComp;
                }
            }
        }
        // Next, look for just a name match
        for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
            XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
            if (namedComp.getName().equals(name)) {
                revealObject(namedComp);
                return namedComp;
            }
        }
    }
    return null;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 9 with XSDNamedComponent

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

the class CreateElementAction method run.

/*
   * @see IAction#run()
   */
public void run() {
    beginRecording(getDescription());
    final Element child = createAndAddNewChildElement();
    endRecording();
    if (selectionProvider != null) {
        final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
        // selectionProvider.setSelection(new StructuredSelection(comp));
        Runnable runnable = new Runnable() {

            public void run() {
                if (comp instanceof XSDAttributeDeclaration) {
                    if (((XSDAttributeDeclaration) comp).getContainer() instanceof XSDAttributeUse) {
                        if (comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition) {
                            selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                        } else if (comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
                            if (XSDDOMHelper.inputEquals(child, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true)) {
                                selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                            } else {
                                selectionProvider.setSelection(new StructuredSelection(comp));
                            }
                        } else {
                            selectionProvider.setSelection(new StructuredSelection(comp));
                        }
                    } else {
                        selectionProvider.setSelection(new StructuredSelection(comp));
                    }
                } else {
                    selectionProvider.setSelection(new StructuredSelection(comp));
                }
                if (comp instanceof XSDNamedComponent) {
                    if (sourceContext instanceof AbstractEditPartViewer) {
                    // AbstractEditPartViewer viewer = (AbstractEditPartViewer)sourceContext;
                    // Object obj = viewer.getSelectedEditParts().get(0);
                    // if (obj instanceof GraphicalEditPart)
                    // {
                    // if (obj instanceof ElementDeclarationEditPart)
                    // {
                    // XSDElementDeclaration elem = ((ElementDeclarationEditPart)obj).getXSDElementDeclaration();
                    // if (!elem.isElementDeclarationReference())
                    // {
                    // ((ElementDeclarationEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ModelGroupDefinitionEditPart)
                    // {
                    // XSDModelGroupDefinition group = ((ModelGroupDefinitionEditPart)obj).getXSDModelGroupDefinition();
                    // if (!group.isModelGroupDefinitionReference())
                    // {
                    // ((ModelGroupDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ComplexTypeDefinitionEditPart)
                    // {
                    // XSDComplexTypeDefinition ct = ((ComplexTypeDefinitionEditPart)obj).getXSDComplexTypeDefinition();
                    // if (ct.getName() != null)
                    // {
                    // ((ComplexTypeDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof TopLevelComponentEditPart)
                    // {
                    // ((TopLevelComponentEditPart)obj).doEditName();
                    // }
                    // }
                    }
                }
            }
        };
        Display.getDefault().timerExec(50, runnable);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AbstractEditPartViewer(org.eclipse.gef.ui.parts.AbstractEditPartViewer) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 10 with XSDNamedComponent

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

the class FindReferencesAction method run.

public void run() {
    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());
        SearchScope scope = new WorkspaceSearchScope();
        String scopeDescription = "Workspace";
        XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
        NewSearchUI.activateSearchResultView();
        NewSearchUI.runQueryInBackground(searchQuery);
    }
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFile(org.eclipse.core.resources.IFile) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) SearchScope(org.eclipse.wst.common.core.search.scope.SearchScope) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) XSDSearchQuery(org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)

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