use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand in project webtools.sourceediting by eclipse.
the class XSDAttributeReferenceEditManager method modifyComponentReference.
public void modifyComponentReference(Object referencingObject, ComponentSpecification referencedComponent) {
XSDAttributeDeclaration concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adapter = (Adapter) referencingObject;
if (adapter.getTarget() instanceof XSDAttributeDeclaration) {
concreteComponent = (XSDAttributeDeclaration) adapter.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDAttributeDeclaration) referencingObject;
}
if (concreteComponent != null) {
if (referencedComponent.isNew()) {
XSDAttributeDeclaration attributeDec = null;
if (referencedComponent.getMetaName() == IXSDSearchConstants.ATTRIBUTE_META_NAME) {
AddXSDAttributeDeclarationCommand command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, concreteComponent.getSchema());
command.setNameToAdd(referencedComponent.getName());
command.execute();
attributeDec = (XSDAttributeDeclaration) command.getAddedComponent();
}
if (attributeDec != null) {
Command command = new UpdateAttributeReferenceCommand(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, concreteComponent, attributeDec);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
} else {
Command command = new UpdateAttributeReferenceAndManagerDirectivesCommand(concreteComponent, referencedComponent.getName(), referencedComponent.getQualifier(), referencedComponent.getFile());
command.setLabel(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE);
command.execute();
}
}
}
use of org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand in project webtools.sourceediting by eclipse.
the class AddXSDAttributeDeclarationAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
if (selection instanceof XSDAttributeDeclaration) {
selection = ((XSDAttributeDeclaration) selection).getContainer();
}
}
AddXSDAttributeDeclarationCommand command = null;
if (selection instanceof XSDComplexTypeDefinition) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDAttributeUse) {
XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
XSDConcreteComponent parent = null;
XSDComplexTypeDefinition ct = null;
XSDAttributeGroupDefinition group = null;
for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
if (parent instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) parent;
break;
} else if (parent instanceof XSDAttributeGroupDefinition) {
group = (XSDAttributeGroupDefinition) parent;
break;
}
parent = parent.getContainer();
}
if (ct != null) {
XSDAttributeUse sel = (XSDAttributeUse) selection;
int index = ct.getAttributeContents().indexOf(sel);
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (group != null) {
XSDAttributeUse sel = (XSDAttributeUse) selection;
int index = group.eContents().indexOf(sel);
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
}
} else if (selection instanceof XSDAttributeGroupDefinition) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDSchema) {
command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
getCommandStack().execute(command);
}
if (command != null) {
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
Aggregations