Search in sources :

Example 16 with XSDNamedComponent

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

the class XSDAttributeGroupDefinitionSection method doWidgetSelected.

public void doWidgetSelected(SelectionEvent e) {
    if (e.widget == refCombo) {
        String newValue = refCombo.getText();
        if (input instanceof XSDNamedComponent) {
            XSDNamedComponent namedComponent = (XSDNamedComponent) input;
            Element element = namedComponent.getElement();
            if (namedComponent instanceof XSDAttributeGroupDefinition) {
                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) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 17 with XSDNamedComponent

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

the class XSDAttributeGroupDefinitionSection 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 = "";
            }
            refCombo.setText(attrValue);
        }
    } 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 18 with XSDNamedComponent

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

the class XSDComplexTypeSection method doHandleEvent.

public void doHandleEvent(Event event) {
    if (event.type == SWT.Traverse) {
        if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
            isTraversing = true;
            return;
        }
    }
    super.doHandleEvent(event);
    if (event.widget == nameText) {
        if (!nameText.getEditable())
            return;
        String newValue = nameText.getText().trim();
        if (input instanceof XSDNamedComponent) {
            XSDNamedComponent namedComponent = (XSDNamedComponent) input;
            if (!validateSection())
                return;
            Command command = null;
            // Make sure an actual name change has taken place
            String oldName = namedComponent.getName();
            if (!newValue.equals(oldName)) {
                command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue);
            }
            if (command != null && getCommandStack() != null) {
                getCommandStack().execute(command);
            }
        // doReferentialIntegrityCheck(namedComponent, newValue);
        }
    }
}
Also used : UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) Command(org.eclipse.gef.commands.Command)

Example 19 with XSDNamedComponent

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

the class XSDSectionLabelProvider method getText.

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 */
public String getText(Object object) {
    if (object == null || object.equals(StructuredSelection.EMPTY)) {
        return org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NO_ITEMS_SELECTED;
    }
    String result = null;
    boolean isReference = false;
    Object selected = null;
    if (object instanceof StructuredSelection) {
        selected = ((StructuredSelection) object).getFirstElement();
        if (selected instanceof XSDConcreteComponent) {
            if (selected instanceof XSDElementDeclaration) {
                XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) selected;
                if (xsdElementDeclaration.isElementDeclarationReference()) {
                    isReference = true;
                }
            } else if (selected instanceof XSDAttributeDeclaration) {
                if (((XSDAttributeDeclaration) selected).isAttributeDeclarationReference()) {
                    isReference = true;
                }
            } else if (selected instanceof XSDModelGroupDefinition) {
                if (((XSDModelGroupDefinition) selected).isModelGroupDefinitionReference()) {
                    isReference = true;
                }
            }
            StringBuffer sb = new StringBuffer();
            Element element = ((XSDConcreteComponent) selected).getElement();
            if (element != null) {
                sb.append(((XSDConcreteComponent) selected).getElement().getLocalName());
                if (isReference) {
                    // $NON-NLS-1$
                    sb.append(" ref");
                // This string is not easily translatable to other languages.
                // For now, make it english-only since we use the element tag as the title anyway
                // sb.append(Messages.UI_PAGE_HEADING_REFERENCE);
                }
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                if (workbenchWindow != null) {
                    IWorkbenchPage page = workbenchWindow.getActivePage();
                    if (page != null) {
                        IEditorPart editorPart = page.getActiveEditor();
                        XSDSchema xsdSchema = ((XSDConcreteComponent) selected).getSchema();
                        IEditorInput editorInput = editorPart.getEditorInput();
                        boolean isReadOnly = false;
                        if (!(editorInput instanceof IFileEditorInput || editorInput instanceof FileStoreEditorInput)) {
                            isReadOnly = true;
                        }
                        if (editorPart != null && xsdSchema != editorPart.getAdapter(XSDSchema.class) || isReadOnly) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            sb.append(" (" + Messages.UI_LABEL_READ_ONLY + ")");
                        }
                    }
                }
                return sb.toString();
            } else {
                // an appropriate name
                if ((XSDConcreteComponent) selected instanceof XSDNamedComponent) {
                    return ((XSDNamedComponent) selected).getName();
                } else if ((XSDConcreteComponent) selected instanceof XSDSchema) {
                    return XSDConstants.SCHEMA_ELEMENT_TAG;
                }
                // $NON-NLS-1$ //$NON-NLS-2$
                return "(" + Messages.UI_LABEL_READ_ONLY + ")";
            }
        }
        if (object instanceof Element) {
            return ((Element) object).getLocalName();
        }
    }
    return result;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) Element(org.w3c.dom.Element) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFileEditorInput(org.eclipse.ui.IFileEditorInput) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 20 with XSDNamedComponent

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

the class FindReferencesAction method getXSDNamedComponent.

protected XSDNamedComponent getXSDNamedComponent() {
    if (editor != null) {
        ISelectionProvider provider = (ISelectionProvider) editor.getAdapter(ISelectionProvider.class);
        ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class);
        if (provider != null) {
            ISelection selection = provider.getSelection();
            if (mapper != null) {
                selection = mapper.mapSelection(selection);
            }
            if (selection != null && selection instanceof IStructuredSelection) {
                IStructuredSelection s = (IStructuredSelection) selection;
                Object o = s.getFirstElement();
                if (o != null && o instanceof XSDNamedComponent) {
                    return (XSDNamedComponent) o;
                }
            }
        }
    }
    // our expectation
    return null;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionMapper(org.eclipse.wst.xsd.ui.internal.editor.ISelectionMapper) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

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