use of org.eclipse.xsd.XSDConcreteComponent 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();
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGlobalAction method canEnable.
private boolean canEnable(XSDConcreteComponent xsdComponent) {
if (xsdComponent instanceof XSDComplexTypeDefinition) {
fSelectedComponent = (XSDComplexTypeDefinition) xsdComponent;
isComplexType = true;
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
fParentName = ((XSDElementDeclaration) parent).getName();
return true;
}
} else if (xsdComponent instanceof XSDSimpleTypeDefinition) {
fSelectedComponent = (XSDSimpleTypeDefinition) xsdComponent;
isComplexType = false;
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
fParentName = ((XSDElementDeclaration) parent).getName();
return true;
} else if (parent instanceof XSDAttributeDeclaration) {
fParentName = ((XSDAttributeDeclaration) parent).getName();
return true;
}
}
return false;
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDAttributeDragAndDropCommand method doDrop.
protected void doDrop(List siblings, GraphicalEditPart movingEditPart) {
commonSetup(siblings, movingEditPart);
if ((previousRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDWildcard) && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
if (closerSibling == BELOW_IS_CLOSER) {
parent = nextRefComponent.getContainer().getContainer();
}
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
} else if (previousRefComponent == null && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
XSDConcreteComponent parent = nextRefComponent.getContainer().getContainer();
if (closerSibling == ABOVE_IS_CLOSER) {
if (leftSiblingEditPart == null) {
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
} else if (parentEditPart != null) {
action = new MoveXSDAttributeAction(parentEditPart.getXSDConcreteComponent(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
}
} else {
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
}
} else if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent == null) {
XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
if (closerSibling == ABOVE_IS_CLOSER) {
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
} else {
if (rightSiblingEditPart == null) {
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
} else {
action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
}
}
}
if (action != null)
canExecute = action.canMove();
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDBaseFieldEditPart method refreshIcon.
protected void refreshIcon() {
IFieldFigure figure = getFieldFigure();
// our model implements ITreeElement
if (getModel() instanceof XSDBaseAdapter) {
Image image = ((XSDBaseAdapter) getModel()).getImage();
boolean isReadOnly = ((XSDBaseAdapter) getModel()).isReadOnly();
figure.getNameLabel().setIcon(image);
if (image != null) {
XSDConcreteComponent comp = (XSDConcreteComponent) ((XSDBaseAdapter) getModel()).getTarget();
figure.getNameLabel().setIcon(XSDCommonUIUtils.getUpdatedImage(comp, image, isReadOnly));
}
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class OpenOnSelectionHelper method openOnSelection.
public boolean openOnSelection() {
List selectedNodes = null;
ISelection selection = textEditor.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
selectedNodes = ((IStructuredSelection) selection).toList();
}
if (selectedNodes != null && !selectedNodes.isEmpty()) {
for (Iterator i = selectedNodes.iterator(); i.hasNext(); ) {
Object obj = i.next();
if (xsdSchema != null) {
XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) obj);
XSDConcreteComponent objectToReveal = null;
if (xsdComp instanceof XSDElementDeclaration) {
XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
if (elementDecl.isElementDeclarationReference()) {
objectToReveal = elementDecl.getResolvedElementDeclaration();
} else {
XSDConcreteComponent typeDef = null;
if (elementDecl.getAnonymousTypeDefinition() == null) {
typeDef = elementDecl.getTypeDefinition();
}
XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
if (typeDef != null && subGroupAffiliation != null) {
// then jump to that, otherwise just go to the typeDef.
if (obj instanceof Attr && ((Attr) obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
objectToReveal = subGroupAffiliation;
} else {
// if we fail, set the substitution group as the object to reveal as a backup plan.
if (revealObject(typeDef)) {
return true;
} else {
objectToReveal = subGroupAffiliation;
}
}
} else {
// one or more of these is null. If the typeDef is non-null, use it. Otherwise
// try and use the substitution group
objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
}
}
} else if (xsdComp instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
if (elementDecl.isModelGroupDefinitionReference()) {
objectToReveal = elementDecl.getResolvedModelGroupDefinition();
}
} else if (xsdComp instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
if (attrDecl.isAttributeDeclarationReference()) {
objectToReveal = attrDecl.getResolvedAttributeDeclaration();
} else if (attrDecl.getAnonymousTypeDefinition() == null) {
objectToReveal = attrDecl.getTypeDefinition();
}
} else if (xsdComp instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
if (attrGroupDef.isAttributeGroupDefinitionReference()) {
objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
}
} else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
if (idConstraintDef.getReferencedKey() != null) {
objectToReveal = idConstraintDef.getReferencedKey();
}
} else if (xsdComp instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
objectToReveal = typeDef.getItemTypeDefinition();
if (objectToReveal == null) {
// if itemType attribute is not set, then check for memberType
List memberTypes = typeDef.getMemberTypeDefinitions();
if (memberTypes != null && memberTypes.size() > 0) {
objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
}
}
} else if (xsdComp instanceof XSDTypeDefinition) {
XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
objectToReveal = typeDef.getBaseType();
} else if (xsdComp instanceof XSDSchemaDirective) {
XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
// String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
// openXSDEditor(schemaLocation);
// return false;
objectToReveal = directive.getResolvedSchema();
}
// now reveal the object if this isn't null
if (objectToReveal != null) {
return revealObject(objectToReveal);
}
}
}
}
return false;
}
Aggregations