use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class SetBaseTypeAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
boolean complexType = selection instanceof XSDComplexTypeDefinition;
boolean simpleType = selection instanceof XSDSimpleTypeDefinition;
if (complexType || simpleType) {
if (getWorkbenchPart() instanceof IEditorPart) {
IEditorPart editor = (IEditorPart) getWorkbenchPart();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
ComponentSpecification newValue;
IComponentDialog dialog = null;
dialog = manager.getBrowseDialog();
if (dialog != null) {
if (simpleType) {
((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
}
if (dialog.createAndOpen() == Window.OK) {
newValue = dialog.getSelectedComponent();
manager.modifyComponentReference(selection, newValue);
}
}
}
}
}
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDImpl method findTypesDerivedFrom.
/**
* Adapted from public static List findTypesDerivedFrom(XSDSchema schema,
* String namespace, String localName) in class XSDSchemaQueryTools found in
* org.eclipse.xsd plugin.
*
* Find typeDefinitions that derive from a given type.
*
* @param type
* the type derived from
* @return List of any XSDTypeDefinitions found
*/
public static List findTypesDerivedFrom(XSDTypeDefinition type) {
ArrayList typesDerivedFrom = new ArrayList();
if (type != null) {
XSDSchema schema = type.getSchema();
String localName = type.getName();
if ((null != schema) && (null != localName)) {
String namespace = schema.getTargetNamespace();
// A handy convenience method quickly gets all
// typeDefinitions within our schema; note that
// whether or not this returns types in included,
// imported, or redefined schemas is subject to change
List typedefs = schema.getTypeDefinitions();
for (Iterator iter = typedefs.iterator(); iter.hasNext(); ) {
XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
if (typedef instanceof XSDComplexTypeDefinition) {
// of them match the requested one
if (isTypeDerivedFrom(typedef, namespace, localName)) {
// We found it, return the original one and continue
typesDerivedFrom.add(typedef);
continue;
}
}
}
}
}
return typesDerivedFrom;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDComplexTypeAdvancedSection method refresh.
public void refresh() {
super.refresh();
setListenerEnabled(false);
try {
if (input instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input;
boolean enabled = true;
if (complexType.getContainer() instanceof XSDSchema) {
enabled = !isReadOnly;
} else {
enabled = false;
}
if (complexType.getElement().hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) {
String blockAttValue = complexType.getElement().getAttribute(XSDConstants.BLOCK_ATTRIBUTE);
blockCombo.setText(blockAttValue);
} else {
blockCombo.setText(EMPTY);
}
blockCombo.setEnabled(enabled);
if (complexType.getElement().hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) {
String finalAttValue = complexType.getElement().getAttribute(XSDConstants.FINAL_ATTRIBUTE);
finalCombo.setText(finalAttValue);
} else {
finalCombo.setText(EMPTY);
}
finalCombo.setEnabled(enabled);
if (complexType.getElement().hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) {
boolean absAttValue = complexType.isAbstract();
if (absAttValue)
abstractCombo.setText(TRUE);
else
abstractCombo.setText(FALSE);
} else {
abstractCombo.setText(EMPTY);
}
abstractCombo.setEnabled(enabled);
if (complexType.getElement().hasAttribute(XSDConstants.MIXED_ATTRIBUTE)) {
boolean mixedValue = complexType.isMixed();
if (mixedValue)
mixedCombo.setText(TRUE);
else
mixedCombo.setText(FALSE);
} else {
mixedCombo.setText(EMPTY);
}
}
} catch (Exception e) {
}
setListenerEnabled(true);
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method getOwner.
private XSDConcreteComponent getOwner() {
XSDConcreteComponent owner = null;
if (parent instanceof XSDElementDeclaration) {
XSDElementDeclaration ed = (XSDElementDeclaration) parent;
if (ed.getTypeDefinition() != null) {
if (ed.getAnonymousTypeDefinition() == null) {
ed.setTypeDefinition(null);
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = ed.getTypeDefinition();
} else {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
}
} else if (ed.getAnonymousTypeDefinition() == null) {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
} else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) {
owner = ed.getAnonymousTypeDefinition();
} else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) {
XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ed.setAnonymousTypeDefinition(td);
owner = td;
}
} else if (parent instanceof XSDModelGroup) {
newModelGroup = createModelGroup();
((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer());
} else if (parent instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
owner = parent;
if (ct.getContent() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) ct.getContent();
if (particle.getContent() instanceof XSDModelGroup) {
owner = null;
newModelGroup = createModelGroup();
XSDModelGroup newParent = (XSDModelGroup) particle.getContent();
newParent.getContents().add(newModelGroup.getContainer());
}
}
} else if (parent instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition) parent;
owner = null;
newModelGroup = createModelGroup();
if (modelGroupDefinition.getModelGroup() != null) {
XSDModelGroup newParent = modelGroupDefinition.getModelGroup();
newParent.getContents().add(newModelGroup.getContainer());
} else {
modelGroupDefinition.setModelGroup(newModelGroup);
}
}
return owner;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method execute.
public void execute() {
try {
beginRecording(parent.getElement());
XSDConcreteComponent owner = getOwner();
if (owner != null) {
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
newModelGroup = createModelGroup();
particle.setContent(newModelGroup);
XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) owner;
ctd.setContent(particle);
}
formatChild(parent.getElement());
} finally {
endRecording();
}
}
Aggregations