use of org.eclipse.wst.xsd.ui.internal.util.TypesHelper in project webtools.sourceediting by eclipse.
the class TypeSection method getPrefix.
public String getPrefix(String ns, XSDSchema xsdSchema) {
TypesHelper helper = new TypesHelper(xsdSchema);
String key = helper.getPrefix(ns, true);
return key;
}
use of org.eclipse.wst.xsd.ui.internal.util.TypesHelper 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.xsd.ui.internal.util.TypesHelper in project webtools.sourceediting by eclipse.
the class XSDModelGroupDefinitionSection method setInput.
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
init();
relayout();
if (isReference) {
TypesHelper helper = new TypesHelper(xsdSchema);
List items = new ArrayList();
items = helper.getModelGroups();
if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition group = (XSDModelGroupDefinition) input;
XSDConcreteComponent parent = group.getContainer();
while (parent != null) {
if (parent instanceof XSDModelGroupDefinition) {
items.remove(((XSDModelGroupDefinition) parent).getQName());
break;
}
parent = parent.getContainer();
}
}
// $NON-NLS-1$
items.add(0, "");
componentNameCombo.setItems((String[]) items.toArray(new String[0]));
}
}
Aggregations