use of org.eclipse.xsd.XSDAttributeDeclaration 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.XSDAttributeDeclaration 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());
}
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDAdapterFactory method createAdapter.
public Adapter createAdapter(Notifier target) {
XSDSwitch xsdSwitch = new XSDSwitch() {
public Object caseXSDSchemaDirective(XSDSchemaDirective object) {
return new XSDSchemaDirectiveAdapter();
}
public Object caseXSDWildcard(XSDWildcard object) {
return new XSDWildcardAdapter();
}
public Object caseXSDAttributeGroupDefinition(XSDAttributeGroupDefinition object) {
return new XSDAttributeGroupDefinitionAdapter();
}
public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object) {
return new XSDModelGroupDefinitionAdapter();
}
public Object caseXSDAttributeDeclaration(XSDAttributeDeclaration object) {
return new XSDAttributeDeclarationAdapter();
}
public Object caseXSDAttributeUse(XSDAttributeUse object) {
return new XSDAttributeUseAdapter();
}
public Object caseXSDParticle(XSDParticle object) {
return new XSDParticleAdapter();
}
public Object caseXSDElementDeclaration(XSDElementDeclaration object) {
return new XSDElementDeclarationAdapter();
}
public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition object) {
return new XSDSimpleTypeDefinitionAdapter();
}
public Object caseXSDComplexTypeDefinition(XSDComplexTypeDefinition object) {
//
if (// $NON-NLS-1$
"anyType".equals(object.getName())) {
return new XSDAnyTypeDefinitionAdapter();
} else {
return new XSDComplexTypeDefinitionAdapter();
}
}
public Object caseXSDModelGroup(XSDModelGroup object) {
return new XSDModelGroupAdapter();
}
public Object caseXSDSchema(XSDSchema object) {
return new XSDSchemaAdapter();
}
public Object caseXSDEnumerationFacet(XSDEnumerationFacet object) {
return new XSDEnumerationFacetAdapter();
}
public Object caseXSDRedefine(XSDRedefine object) {
return new XSDRedefineAdapter();
}
};
Object o = xsdSwitch.doSwitch((EObject) target);
Adapter result = null;
if (o instanceof Adapter) {
result = (Adapter) o;
} else {
// Thread.dumpStack();
}
return result;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class ExtensionsSection method getAddExtensionCommand.
protected AddExtensionCommand getAddExtensionCommand(Object o) {
AddExtensionCommand addExtensionCommand = null;
if (o instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) o;
ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace());
if (extensibleAddExtensionCommand != null) {
extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element);
addExtensionCommand = extensibleAddExtensionCommand;
} else {
addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element);
}
} else if (o instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute);
}
return addExtensionCommand;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDAttributeDeclarationSection method doHandleEvent.
protected void doHandleEvent(Event event) {
if (event.type == SWT.Traverse) {
if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
isTraversing = true;
return;
}
}
super.doHandleEvent(event);
if (event.widget == nameText) {
if (!nameText.getEditable())
return;
String newValue = nameText.getText().trim();
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
if (!validateSection())
return;
Command command = null;
// Make sure an actual name change has taken place
String oldName = namedComponent.getName();
if (!newValue.equals(oldName)) {
command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue);
}
if (command != null && getCommandStack() != null) {
getCommandStack().execute(command);
}
if (isAttributeReference) {
XSDAttributeDeclaration attrRef = (XSDAttributeDeclaration) input;
String qname = attrRef.getResolvedAttributeDeclaration().getQName();
attrRef.getElement().setAttribute(XSDConstants.REF_ATTRIBUTE, qname);
// TypesHelper helper = new TypesHelper(xsdSchema);
// List items = new ArrayList();
// items = helper.getGlobalElements();
// items.add(0, "");
// componentNameCombo.setItems((String [])items.toArray(new String[0]));
//
// refreshRefCombo();
}
}
} else if (event.widget == defaultOrFixedText) {
XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
String newValue = defaultOrFixedText.getText();
Element element = xsdAttribute.getElement();
if (element != null) {
if (newValue.length() == 0) {
PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_VALUE) {
protected void doExecuteSteps() {
element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
}
};
getCommandStack().execute(command);
} else {
UpdateAttributeValueCommand command = null;
if (fixedButton.getSelection()) {
command = new UpdateAttributeValueCommand(element, XSDConstants.FIXED_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) {
protected void doPostProcessing() {
element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
}
};
} else {
command = new UpdateAttributeValueCommand(element, XSDConstants.DEFAULT_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) {
protected void doPostProcessing() {
element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
}
};
}
command.setDeleteIfEmpty(true);
getCommandStack().execute(command);
}
}
}
}
Aggregations