use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class UpdateMinOccursCommand method execute.
public void execute() {
Element element = component.getElement();
try {
beginRecording(element);
removeMinOccursAttribute = (!(element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE))) ? true : false;
if (component instanceof XSDParticle) {
oldMinOccurs = ((XSDParticle) component).getMinOccurs();
((XSDParticle) component).setMinOccurs(newMinOccurs);
} else if (component instanceof XSDAttributeUse) {
oldMinOccurs = (((XSDAttributeUse) component).getUse() == XSDAttributeUseCategory.REQUIRED_LITERAL ? 1 : 0);
if (newMinOccurs == 1)
((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.REQUIRED_LITERAL);
else
((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.OPTIONAL_LITERAL);
}
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDAttributeUse 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.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class XSDTabbedPropertySheetPage method selectionChanged.
/* (non-Javadoc)
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof XSDBaseAdapter) {
XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
if (oldSelection != null) {
oldSelection.unregisterListener(this);
if (oldSelection instanceof XSDElementDeclarationAdapter) {
XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
if (elem.getContainer() != null) {
Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
if (adap instanceof XSDParticleAdapter) {
XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
particleAdapter.unregisterListener(this);
}
}
if (elem.isElementDeclarationReference()) {
XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
resolvedElementAdapter.unregisterListener(this);
}
}
}
if (adapter instanceof XSDElementDeclarationAdapter) {
XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
if (adap instanceof XSDParticleAdapter) {
XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
particleAdapter.registerListener(this);
}
if (elem.isElementDeclarationReference()) {
XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
resolvedElementAdapter.registerListener(this);
}
} else if (adapter instanceof XSDAttributeUseAdapter) {
XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
}
adapter.registerListener(this);
oldSelection = adapter;
Object model = adapter.getTarget();
if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
}
Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
if (element != null) {
xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
}
if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
}
if (model instanceof XSDConcreteComponent) {
selection = new StructuredSelection(model);
}
super.selectionChanged(part, selection);
return;
}
super.selectionChanged(part, selection);
}
use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class MoveXSDAttributeAction method moveUnderXSDComplexTypeDefinition.
protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType) {
int originalIndex = 0;
for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (attribute == selected) {
complexType.getAttributeContents().remove(attribute.getContainer());
break;
}
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
List attributeGroupContents = complexType.getAttributeContents();
for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (insertType == INSERT_AFTER) {
if (attribute == previousRefComponent) {
complexType.getAttributeContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_BEFORE) {
if (attribute == nextRefComponent) {
complexType.getAttributeContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
}
index++;
}
if (attributeGroupContents.size() == 0) {
complexType.getAttributeContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
complexType.getAttributeContents().add(originalIndex, selected.getContainer());
}
}
use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class MoveXSDAttributeAction method moveUnderXSDAttributeGroupDefinition.
protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup) {
int originalIndex = 0;
for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (attribute == selected) {
parentGroup.getContents().remove(attribute.getContainer());
break;
}
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
if (insertAtEnd)
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
else
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
addedBack = true;
}
return;
}
List attributeGroupContents = parentGroup.getContents();
for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (insertType == INSERT_BEFORE) {
if (attribute == nextRefComponent) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (attribute == previousRefComponent) {
parentGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
}
index++;
}
if (attributeGroupContents.size() == 0) {
parentGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentGroup.getContents().add(originalIndex, selected.getContainer());
}
}
Aggregations