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);
}
}
}
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();
}
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;
}
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;
}
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();
}
}
}
Aggregations