Search in sources :

Example 11 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class CommonEditNamespacesTargetFieldDialog method performEdit.

public void performEdit() {
    Object selection = getSelection(tableViewer.getSelection());
    if (selection != null) {
        boolean editTargetNamespace = false;
        NamespaceInfo nsInfo = (NamespaceInfo) selection;
        if (getTargetNamespace().equals(nsInfo.uri)) {
            editTargetNamespace = true;
        }
        invokeDialog(XMLUIMessages._UI_LABEL_NEW_NAMESPACE_INFORMATION, nsInfo);
        updateErrorMessage(namespaceInfoList);
        performDelayedUpdate();
        if (editTargetNamespace) {
            targetNamespaceField.setText(nsInfo.uri);
        }
    }
}
Also used : NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 12 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class CommonEditNamespacesTargetFieldDialog method updateTargetNamespaceAndNamespaceInfo.

void updateTargetNamespaceAndNamespaceInfo(String oldTargetNamespace, String newTargetNamespace) {
    NamespaceInfo info = getNamespaceInfo(newTargetNamespace);
    if (info == null) {
        info = getNamespaceInfo(oldTargetNamespace);
        if (info == null) {
            // $NON-NLS-1$
            info = new NamespaceInfo(newTargetNamespace, "tns", null);
            namespaceInfoList.add(info);
        } else {
            info.uri = targetNamespace;
        }
    }
    tableViewer.refresh();
}
Also used : NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 13 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class XSDEditNamespacesAction method createPrefixMapping.

protected Map createPrefixMapping(List oldList, List newList) {
    Map map = new Hashtable();
    Hashtable oldURIToPrefixTable = new Hashtable();
    for (Iterator i = oldList.iterator(); i.hasNext(); ) {
        NamespaceInfo oldInfo = (NamespaceInfo) i.next();
        oldURIToPrefixTable.put(oldInfo.uri, oldInfo);
    }
    for (Iterator i = newList.iterator(); i.hasNext(); ) {
        NamespaceInfo newInfo = (NamespaceInfo) i.next();
        // $NON-NLS-1$
        NamespaceInfo oldInfo = (NamespaceInfo) oldURIToPrefixTable.get(newInfo.uri != null ? newInfo.uri : "");
        // assuming that the user changed the URI and the prefix
        if (oldInfo == null) {
            // $NON-NLS-1$
            oldInfo = (NamespaceInfo) newInfo.getProperty("oldCopy");
        }
        if (oldInfo != null) {
            // $NON-NLS-1$
            String newPrefix = newInfo.prefix != null ? newInfo.prefix : "";
            // $NON-NLS-1$
            String oldPrefix = oldInfo.prefix != null ? oldInfo.prefix : "";
            if (!oldPrefix.equals(newPrefix)) {
                map.put(oldPrefix, newPrefix);
            }
        }
    }
    return map;
}
Also used : Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) Map(java.util.Map)

Example 14 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class NamespaceSelectionAdapter method createNamespaceInfo.

private List<NamespaceInfo> createNamespaceInfo(Document document) {
    List<NamespaceInfo> info = namespaceInfo.get(document);
    if (info == null) {
        info = new ArrayList<NamespaceInfo>();
        NamespaceTable namespaceTable = new NamespaceTable(document);
        namespaceTable.visitElement(document.getDocumentElement());
        Collection<?> namespaces = namespaceTable.getNamespaceInfoCollection();
        info.addAll((Collection<NamespaceInfo>) namespaces);
        namespaceInfo.put(document, info);
    }
    return info;
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 15 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class NamespaceSelectionAdapter method widgetSelected.

@Override
public void widgetSelected(SelectionEvent e) {
    IEditorPart activeEditor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = createNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Aggregations

NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)30 List (java.util.List)9 Iterator (java.util.Iterator)8 Element (org.w3c.dom.Element)6 NamespaceTable (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)5 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)4 IFile (org.eclipse.core.resources.IFile)3 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)3 NodeList (org.w3c.dom.NodeList)3 Path (org.eclipse.core.runtime.Path)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IPathEditorInput (org.eclipse.ui.IPathEditorInput)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2