use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand in project webtools.sourceediting by eclipse.
the class XSDSubstitutionGroupEditManager method modifyComponentReference.
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
XSDElementDeclaration concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adapter = (Adapter) referencingObject;
if (adapter.getTarget() instanceof XSDElementDeclaration) {
concreteComponent = (XSDElementDeclaration) adapter.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDElementDeclaration) referencingObject;
}
if (concreteComponent != null) {
if (component.isNew()) {
XSDElementDeclaration elementDec = null;
if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
elementDec = (XSDElementDeclaration) command.getAddedComponent();
}
if (elementDec != null) {
Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, elementDec.getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
command.execute();
}
} else {
Command command = new UpdateAttributeValueCommand(concreteComponent.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, ((XSDElementDeclaration) component.getObject()).getQName(concreteComponent.getSchema()), org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
}
}
use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand in project webtools.sourceediting by eclipse.
the class AddXSDElementAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
AddXSDElementCommand command = null;
if (selection instanceof XSDComplexTypeDefinition) {
command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroupDefinition) {
command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDSchema) {
command = new AddXSDElementCommand(getText(), (XSDSchema) selection);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) selection;
XSDConcreteComponent component = modelGroup.getContainer();
XSDComplexTypeDefinition ct = null;
while (component != null) {
if (component instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) component;
break;
}
component = component.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct);
} else {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection);
}
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) {
XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection;
XSDConcreteComponent parent = null;
XSDComplexTypeDefinition ct = null;
XSDModelGroupDefinition group = null;
XSDModelGroupImpl ctGroup = null;
for (parent = xsdConcreteComponent.getContainer(); parent != null; ) {
if (parent instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupDefinition) {
group = (XSDModelGroupDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupImpl) {
ctGroup = (XSDModelGroupImpl) parent;
break;
}
parent = parent.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), ct);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (ctGroup != null) {
XSDElementDeclaration sel = (XSDElementDeclaration) selection;
int index = ctGroup.getContents().indexOf(sel.eContainer());
command = new AddXSDElementCommand(getText(), ctGroup, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (group != null) {
command = new AddXSDElementCommand(getText(), group);
command.setReference(isReference);
getCommandStack().execute(command);
}
}
if (command != null) {
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand in project webtools.sourceediting by eclipse.
the class XSDElementReferenceEditManager method modifyComponentReference.
// TODO not changed yet
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
XSDElementDeclaration concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adapter = (Adapter) referencingObject;
if (adapter.getTarget() instanceof XSDElementDeclaration) {
concreteComponent = (XSDElementDeclaration) adapter.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDElementDeclaration) referencingObject;
}
if (concreteComponent != null) {
if (component.isNew()) {
XSDElementDeclaration elementDec = null;
if (component.getMetaName() == IXSDSearchConstants.ELEMENT_META_NAME) {
AddXSDElementCommand command = new AddXSDElementCommand(Messages._UI_ACTION_ADD_ELEMENT, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
elementDec = (XSDElementDeclaration) command.getAddedComponent();
}
if (elementDec != null) {
Command command = new UpdateElementReferenceCommand(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE, concreteComponent, elementDec);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
} else {
Command command = new UpdateElementReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
command.setLabel(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE);
command.execute();
}
}
}
Aggregations