use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.
the class AbstractSection method beginRecording.
public void beginRecording(String description, Element element) {
DocumentImpl doc = getDocument(element);
doc.getModel().beginRecording(this, description);
}
use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.
the class AbstractSection method endRecording.
public void endRecording(Element element) {
DocumentImpl doc = getDocument(element);
doc.getModel().endRecording(this);
}
use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.
the class XSDSchemaSection method doHandleEvent.
public void doHandleEvent(Event event) {
// $NON-NLS-1$
errorText.setText("");
String prefixValue = prefixText.getText();
String tnsValue = targetNamespaceText.getText();
Element element = xsdSchema.getElement();
TypesHelper helper = new TypesHelper(xsdSchema);
String currentPrefix = helper.getPrefix(element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE), false);
String currentNamespace = xsdSchema.getTargetNamespace();
if (tnsValue.trim().length() == 0) {
if (prefixValue.trim().length() > 0) {
// $NON-NLS-1$
errorText.setText(XSDEditorPlugin.getXSDString("_ERROR_TARGET_NAMESPACE_AND_PREFIX"));
int length = errorText.getText().length();
red = new Color(null, 255, 0, 0);
StyleRange style = new StyleRange(0, length, red, targetNamespaceText.getBackground());
errorText.setStyleRange(style);
return;
}
}
if (event.widget == prefixText) {
// widget loses focus.
if (prefixValue.equals(currentPrefix))
return;
updateNamespaceInfo(prefixValue, tnsValue);
} else if (event.widget == targetNamespaceText) {
// widget loses focus.
if (tnsValue.equals(currentNamespace))
return;
DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager();
List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(xsdSchema.getElement());
Element xsdSchemaElement = xsdSchema.getElement();
DocumentImpl doc = (DocumentImpl) xsdSchemaElement.getOwnerDocument();
try {
doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE"));
if (// remove the targetNamespace attribute
tnsValue.trim().length() == 0) {
xsdSchemaElement.removeAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE);
return;
}
// Now replace the namespace for the xmlns entry
for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) {
NamespaceInfo info = (NamespaceInfo) i.next();
if (info.uri.equals(currentNamespace)) {
info.uri = tnsValue;
}
}
xsdSchema.setIncrementalUpdate(false);
// set the new xmlns entries
namespaceInfoManager.removeNamespaceInfo(element);
namespaceInfoManager.addNamespaceInfo(element, namespaceInfoList, false);
xsdSchema.setIncrementalUpdate(true);
// set the targetNamespace attribute
xsdSchema.setTargetNamespace(tnsValue);
TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, currentNamespace, tnsValue);
targetNamespaceChangeHandler.resolve();
} catch (Exception e) {
} finally {
try {
xsdSchema.update();
} finally {
doc.getModel().endRecording(this);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.
the class TestRangeCompare method testRangeCompare.
public void testRangeCompare() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
model.getStructuredDocument().set(decl);
Document document = model.getDocument();
// $NON-NLS-1$
Element root = document.createElement("parent");
document.appendChild(root);
// $NON-NLS-1$
Element child = document.createElement("child");
root.appendChild(child);
// $NON-NLS-1$
child.appendChild(document.createElement("child1-1"));
// $NON-NLS-1$
Text textnode = document.createTextNode("Text Node");
root.appendChild(textnode);
// $NON-NLS-1$
NodeList children = root.getElementsByTagName("child");
Range range = ((DocumentImpl) document).createRange();
range.setEnd(children.item(0), 1);
Range sourceRange = ((DocumentImpl) document).createRange();
sourceRange.setEnd(textnode, 0);
int result = range.compareBoundaryPoints(Range.END_TO_END, sourceRange);
assertEquals(-1, result);
}
use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.
the class MakeLocalElementGlobalHandler method run.
public void run(ISelection selection, XSDElementDeclaration selectedComponent) {
DocumentImpl doc = (DocumentImpl) selectedComponent.getElement().getOwnerDocument();
doc.getModel().beginRecording(this, "MakeLocalElementGlobalHandler.text");
MakeLocalElementGlobalCommand command = new MakeLocalElementGlobalCommand(selectedComponent);
command.run();
doc.getModel().endRecording(this);
}
Aggregations