use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class AddXSDAttributeDeclarationCommand method createGlobalXSDAttributeDeclaration.
protected XSDAttributeDeclaration createGlobalXSDAttributeDeclaration(XSDSchema xsdSchema) {
ensureSchemaElement(xsdSchema);
XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
// $NON-NLS-1$
attribute.setTypeDefinition(xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("string"));
// $NON-NLS-1$
attribute.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewAttribute" : nameToAdd, xsdSchema.getAttributeDeclarations()));
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
xsdSchema.getElement().appendChild(textNode);
xsdSchema.getContents().add(attribute);
return attribute;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class AddXSDSimpleTypeDefinitionCommand method execute.
public void execute() {
if (parent instanceof XSDSchema) {
ensureSchemaElement((XSDSchema) parent);
}
try {
beginRecording(parent.getElement());
XSDSimpleTypeDefinition typeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
// $NON-NLS-1$
typeDef.setBaseTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
if (parent instanceof XSDSchema) {
// $NON-NLS-1$
typeDef.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewSimpleType" : nameToAdd, ((XSDSchema) parent).getTypeDefinitions()));
createdSimpleType = typeDef;
try {
XSDSchema xsdSchema = (XSDSchema) parent;
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
xsdSchema.getElement().appendChild(textNode);
xsdSchema.getContents().add(typeDef);
} catch (Exception e) {
}
} else if (parent instanceof XSDElementDeclaration) {
((XSDElementDeclaration) parent).setAnonymousTypeDefinition(typeDef);
} else if (parent instanceof XSDAttributeDeclaration) {
((XSDAttributeDeclaration) parent).setAnonymousTypeDefinition(typeDef);
}
formatChild(createdSimpleType.getElement());
addedXSDConcreteComponent = createdSimpleType;
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDSectionLabelProvider method getText.
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object object) {
if (object == null || object.equals(StructuredSelection.EMPTY)) {
return org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NO_ITEMS_SELECTED;
}
String result = null;
boolean isReference = false;
Object selected = null;
if (object instanceof StructuredSelection) {
selected = ((StructuredSelection) object).getFirstElement();
if (selected instanceof XSDConcreteComponent) {
if (selected instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) selected;
if (xsdElementDeclaration.isElementDeclarationReference()) {
isReference = true;
}
} else if (selected instanceof XSDAttributeDeclaration) {
if (((XSDAttributeDeclaration) selected).isAttributeDeclarationReference()) {
isReference = true;
}
} else if (selected instanceof XSDModelGroupDefinition) {
if (((XSDModelGroupDefinition) selected).isModelGroupDefinitionReference()) {
isReference = true;
}
}
StringBuffer sb = new StringBuffer();
Element element = ((XSDConcreteComponent) selected).getElement();
if (element != null) {
sb.append(((XSDConcreteComponent) selected).getElement().getLocalName());
if (isReference) {
// $NON-NLS-1$
sb.append(" ref");
// This string is not easily translatable to other languages.
// For now, make it english-only since we use the element tag as the title anyway
// sb.append(Messages.UI_PAGE_HEADING_REFERENCE);
}
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow != null) {
IWorkbenchPage page = workbenchWindow.getActivePage();
if (page != null) {
IEditorPart editorPart = page.getActiveEditor();
XSDSchema xsdSchema = ((XSDConcreteComponent) selected).getSchema();
IEditorInput editorInput = editorPart.getEditorInput();
boolean isReadOnly = false;
if (!(editorInput instanceof IFileEditorInput || editorInput instanceof FileStoreEditorInput)) {
isReadOnly = true;
}
if (editorPart != null && xsdSchema != editorPart.getAdapter(XSDSchema.class) || isReadOnly) {
// $NON-NLS-1$ //$NON-NLS-2$
sb.append(" (" + Messages.UI_LABEL_READ_ONLY + ")");
}
}
}
return sb.toString();
} else {
// an appropriate name
if ((XSDConcreteComponent) selected instanceof XSDNamedComponent) {
return ((XSDNamedComponent) selected).getName();
} else if ((XSDConcreteComponent) selected instanceof XSDSchema) {
return XSDConstants.SCHEMA_ELEMENT_TAG;
}
// $NON-NLS-1$ //$NON-NLS-2$
return "(" + Messages.UI_LABEL_READ_ONLY + ")";
}
}
if (object instanceof Element) {
return ((Element) object).getLocalName();
}
}
return result;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class DeleteCommand method execute.
public void execute() {
XSDVisitor visitor = new XSDVisitor() {
public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
if (element.getTypeDefinition() == target) {
// $NON-NLS-1$
XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
element.setTypeDefinition(type);
}
super.visitElementDeclaration(element);
}
};
XSDConcreteComponent parent = target.getContainer();
XSDSchema schema = target.getSchema();
try {
beginRecording(parent.getElement());
boolean doCleanup = false;
if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
doCleanup = true;
if (parent instanceof XSDParticle) {
if (parent.getContainer() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
modelGroup.getContents().remove(parent);
} else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
complexType.setContent(null);
}
} else if (parent instanceof XSDSchema) {
visitor.visitSchema(target.getSchema());
((XSDSchema) parent).getContents().remove(target);
} else if (parent instanceof XSDRedefine) {
Object adapter = target.eAdapters().get(0);
if (adapter instanceof XSDModelGroupDefinitionAdapter) {
((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
}
((XSDRedefine) parent).getContents().remove(target);
}
} else if (target instanceof XSDAttributeDeclaration) {
doCleanup = true;
if (parent instanceof XSDAttributeUse) {
EObject obj = parent.eContainer();
XSDComplexTypeDefinition complexType = null;
while (obj != null) {
if (obj instanceof XSDComplexTypeDefinition) {
complexType = (XSDComplexTypeDefinition) obj;
break;
}
obj = obj.eContainer();
}
if (complexType != null) {
complexType.getAttributeContents().remove(parent);
}
if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
attrGroup.getContents().remove(parent);
}
} else if (parent instanceof XSDSchema) {
visitor.visitSchema(target.getSchema());
((XSDSchema) parent).getContents().remove(target);
}
} else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
doCleanup = true;
((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
} else if (target instanceof XSDEnumerationFacet) {
XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
} else if (target instanceof XSDWildcard) {
if (parent instanceof XSDParticle) {
if (parent.getContainer() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
modelGroup.getContents().remove(parent);
}
} else if (parent instanceof XSDComplexTypeDefinition) {
((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
} else if (parent instanceof XSDAttributeGroupDefinition) {
((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
}
} else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
doCleanup = true;
((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
} else {
if (parent instanceof XSDSchema) {
doCleanup = true;
visitor.visitSchema(target.getSchema());
((XSDSchema) parent).getContents().remove(target);
} else if (parent instanceof XSDRedefine) {
doCleanup = false;
EList contents = ((XSDRedefine) parent).getContents();
Object adapter = target.eAdapters().get(0);
if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
} else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
} else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
}
contents.remove(target);
}
}
if (doCleanup)
XSDDirectivesManager.removeUnusedXSDImports(schema);
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDComponentDescriptionProvider method getImage.
public Image getImage(Object component) {
Image result = null;
if (component instanceof SearchMatch) {
SearchMatch searchMatch = (SearchMatch) component;
QualifiedName qualifiedName = (QualifiedName) searchMatch.map.get("metaName");
if (qualifiedName != null) {
if (qualifiedName.equals(IXSDSearchConstants.SIMPLE_TYPE_META_NAME))
result = SIMPLE_TYPE_IMAGE;
else if (qualifiedName.equals(IXSDSearchConstants.COMPLEX_TYPE_META_NAME))
result = COMPLEX_TYPE_IMAGE;
else if (qualifiedName.equals(IXSDSearchConstants.ELEMENT_META_NAME))
result = ELEMENT_IMAGE;
else if (qualifiedName.equals(IXSDSearchConstants.ATTRIBUTE_META_NAME))
result = ATTRIBUTE_IMAGE;
}
} else if (component instanceof XSDComplexTypeDefinition)
result = COMPLEX_TYPE_IMAGE;
else if (component instanceof XSDSimpleTypeDefinition)
result = SIMPLE_TYPE_IMAGE;
else if (component instanceof XSDElementDeclaration)
result = ELEMENT_IMAGE;
else if (component instanceof XSDAttributeDeclaration)
result = ATTRIBUTE_IMAGE;
return result;
}
Aggregations