use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method execute.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.commands.Command#execute()
*/
public void execute() {
try {
if (xsdSchema != null) {
beginRecording(xsdSchema.getElement());
XSDElementDeclaration element = createGlobalXSDElementDeclaration();
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
xsdSchema.getElement().appendChild(textNode);
xsdSchema.getContents().add(element);
addedXSDConcreteComponent = element;
} else if (xsdModelGroupDefinition != null) {
beginRecording(xsdModelGroupDefinition.getElement());
if (xsdModelGroup == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDParticle particle = factory.createXSDParticle();
xsdModelGroup = factory.createXSDModelGroup();
xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
particle.setContent(xsdModelGroup);
xsdModelGroupDefinition.setModelGroup(xsdModelGroup);
}
xsdSchema = xsdModelGroupDefinition.getSchema();
if (!isReference) {
xsdModelGroup.getContents().add(createXSDElementDeclarationForModelGroupDefinitions());
} else {
xsdModelGroup.getContents().add(createXSDElementReference());
}
formatChild(xsdModelGroupDefinition.getElement());
} else if (xsdModelGroup != null && (xsdComplexTypeDefinition == null || xsdModelGroupDefinition == null)) {
xsdSchema = xsdModelGroup.getSchema();
beginRecording(xsdSchema.getElement());
if (!isReference) {
index = getInsertionIndex();
if (index >= 0 && index < xsdModelGroup.getContents().size()) {
xsdModelGroup.getContents().add(index, createXSDElementDeclaration());
} else {
xsdModelGroup.getContents().add(createXSDElementDeclaration());
}
} else {
xsdModelGroup.getContents().add(createXSDElementReference());
}
formatChild(xsdModelGroup.getElement());
} else {
xsdSchema = xsdComplexTypeDefinition.getSchema();
beginRecording(xsdSchema.getElement());
if (xsdModelGroup == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDParticle particle = factory.createXSDParticle();
xsdModelGroup = factory.createXSDModelGroup();
xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
particle.setContent(xsdModelGroup);
xsdComplexTypeDefinition.setContent(particle);
}
if (!isReference) {
xsdModelGroup.getContents().add(createXSDElementDeclarationForComplexType());
} else {
xsdModelGroup.getContents().add(createXSDElementReference());
}
formatChild(xsdComplexTypeDefinition.getElement());
}
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationSection method fillTypesCombo.
private void fillTypesCombo() {
IEditorPart editor = getActiveEditor();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
if (manager != null) {
ComponentSpecification[] items = manager.getQuickPicks();
typeCombo.removeAll();
typeCombo.add(Messages._UI_COMBO_BROWSE);
typeCombo.add(Messages._UI_COMBO_NEW);
for (int i = 0; i < items.length; i++) {
typeCombo.add(items[i].getName());
}
// Add the current Type of this element if needed
XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
XSDTypeDefinition td = namedComponent.getType();
if (td != null) {
String currentTypeName = td.getQName(xsdSchema);
if (// anonymous type
currentTypeName == null)
currentTypeName = "**Anonymous**";
ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
if (// not in quickPick
ret == null && currentTypeName != null) {
typeCombo.add(currentTypeName);
}
}
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationSection method doHandleEvent.
public 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) {
String newValue = nameText.getText().trim();
if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
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);
}
// doReferentialIntegrityCheck(namedComponent, newValue);
}
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationSection method init.
protected void init() {
if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) input;
isElementReference = xsdElementDeclaration.isElementDeclarationReference();
hideHyperLink = !xsdElementDeclaration.isGlobal() || isElementReference;
typeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition();
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project webtools.sourceediting by eclipse.
the class XSDFacetSection method updateInput.
private void updateInput() {
previousPrimitiveType = currentPrimitiveType;
if (input instanceof XSDFeature) {
xsdFeature = (XSDFeature) input;
typeDefinition = xsdFeature.getResolvedFeature().getType();
XSDTypeDefinition anonymousTypeDefinition = null;
if (xsdFeature instanceof XSDElementDeclaration) {
xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
} else if (xsdFeature instanceof XSDAttributeDeclaration) {
xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
}
if (typeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
}
if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
}
if (xsdSimpleTypeDefinition != null) {
if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
currentPrimitiveType = basePrimitiveType;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
} else {
currentPrimitiveType = xsdSimpleTypeDefinition;
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
}
}
} else if (input instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
currentPrimitiveType = xsdSimpleTypeDefinition;
// $NON-NLS-1$ //$NON-NLS-2$
titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
}
}
Aggregations