use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class PrefixHandler method execute.
/**
* This will use the active editor, and try and retrieve a structured
* model from it. If successful, it setups the namespace edit dialog
* to capture the namespace information.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
XPathUIPlugin plugin = XPathUIPlugin.getDefault();
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
// suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
if (activeEditor == null)
return null;
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 = plugin.getNamespaceInfo(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();
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class NamespaceInfoContentBuilder method createAnyElementNode.
protected void createAnyElementNode(CMAnyElement anyElement) {
String uri = anyElement.getNamespaceURI();
if (// $NON-NLS-1$
(uri != null) && !uri.startsWith("##")) {
if (table.get(uri) == null) {
NamespaceInfo info = new NamespaceInfo();
info.uri = uri;
// $NON-NLS-1$
info.prefix = "p" + count++;
table.put(uri, info);
list.add(info);
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class NewXMLGenerator method createNamespaceInfoList.
public void createNamespaceInfoList() {
List result = new Vector();
if (cmDocument != null) {
// $NON-NLS-1$
List result2 = (List) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/completeNamespaceInfo");
if (result2 != null) {
result = result2;
int size = result.size();
for (int i = 0; i < size; i++) {
NamespaceInfo info = (NamespaceInfo) result.get(i);
if (i == 0) {
String locationInfo = null;
if (xmlCatalogEntry != null) {
if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) {
locationInfo = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL);
} else {
locationInfo = xmlCatalogEntry.getKey();
}
}
if (locationInfo == null) {
locationInfo = defaultSystemId;
}
info.locationHint = locationInfo;
// $NON-NLS-1$ //$NON-NLS-2$
info.setProperty("locationHint-readOnly", "true");
// $NON-NLS-1$ //$NON-NLS-2$
info.setProperty("uri-readOnly", "true");
// $NON-NLS-1$ //$NON-NLS-2$
info.setProperty("unremovable", "true");
} else {
info.locationHint = null;
}
}
}
NamespaceInfoContentBuilder builder = new NamespaceInfoContentBuilder();
builder.setBuildPolicy(ContentBuilder.BUILD_ONLY_REQUIRED_CONTENT);
builder.visitCMNode(cmDocument);
result.addAll(builder.list);
}
namespaceInfoList = result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class EditSchemaInfoAction 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 EditSchemaInfoAction method run.
public void run() {
Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
if (validateEdit(manager.getModel(), shell)) {
manager.beginNodeAction(this);
// todo... change constructor to take an element
Element element = getElement(node);
if (element != null) {
EditSchemaInfoDialog dialog = new EditSchemaInfoDialog(shell, new Path(resourceLocation));
List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element);
List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList);
// in response to these changes
for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) {
NamespaceInfo info = (NamespaceInfo) i.next();
NamespaceInfo oldCopy = new NamespaceInfo(info);
// $NON-NLS-1$
info.setProperty("oldCopy", oldCopy);
}
dialog.setNamespaceInfoList(namespaceInfoList);
dialog.create();
// dialog.getShell().setSize(500, 300);
dialog.getShell().setText(XMLUIMessages._UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE);
dialog.setBlockOnOpen(true);
dialog.open();
if (dialog.getReturnCode() == Window.OK) {
List newInfoList = dialog.getNamespaceInfoList();
namespaceInfoManager.removeNamespaceInfo(element);
namespaceInfoManager.addNamespaceInfo(element, newInfoList, false);
// see if we need to rename any prefixes
Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList);
if (prefixMapping.size() > 0) {
try {
manager.getModel().aboutToChangeModel();
ReplacePrefixAction replacePrefixAction = new ReplacePrefixAction(manager, element, prefixMapping);
replacePrefixAction.run();
} finally {
manager.getModel().changedModel();
}
}
}
}
manager.endNodeAction(this);
}
}
Aggregations