use of org.eclipse.xsd.XSDConcreteComponent 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();
}
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDTabbedPropertySheetPage method selectionChanged.
/* (non-Javadoc)
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
if (selected instanceof XSDBaseAdapter) {
XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
if (oldSelection != null) {
oldSelection.unregisterListener(this);
if (oldSelection instanceof XSDElementDeclarationAdapter) {
XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
if (elem.getContainer() != null) {
Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
if (adap instanceof XSDParticleAdapter) {
XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
particleAdapter.unregisterListener(this);
}
}
if (elem.isElementDeclarationReference()) {
XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
resolvedElementAdapter.unregisterListener(this);
}
}
}
if (adapter instanceof XSDElementDeclarationAdapter) {
XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
if (adap instanceof XSDParticleAdapter) {
XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
particleAdapter.registerListener(this);
}
if (elem.isElementDeclarationReference()) {
XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
resolvedElementAdapter.registerListener(this);
}
} else if (adapter instanceof XSDAttributeUseAdapter) {
XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
}
adapter.registerListener(this);
oldSelection = adapter;
Object model = adapter.getTarget();
if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
}
Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
if (element != null) {
xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
}
if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
}
if (model instanceof XSDConcreteComponent) {
selection = new StructuredSelection(model);
}
super.selectionChanged(part, selection);
return;
}
super.selectionChanged(part, selection);
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDComponentDescriptionProvider method getFile.
public IFile getFile(Object component) {
IFile result = null;
if (component instanceof ComponentSpecification) {
result = ((ComponentSpecification) component).getFile();
} else if (component instanceof SearchMatch) {
result = ((SearchMatch) component).getFile();
} else if (component instanceof XSDConcreteComponent) {
XSDConcreteComponent concreteComponent = (XSDConcreteComponent) component;
XSDSchema schema = concreteComponent.getSchema();
if (schema != null) {
// TODO (cs) revisit and test more
//
String location = schema.getSchemaLocation();
String platformResource = "platform:/resource";
if (location != null && location.startsWith(platformResource)) {
Path path = new Path(location.substring(platformResource.length()));
result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
}
}
return result;
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MoveXSDAttributeAction method moveUnderXSDAttributeGroupDefinition.
protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup) {
int originalIndex = 0;
for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (attribute == selected) {
parentGroup.getContents().remove(attribute.getContainer());
break;
}
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
if (insertAtEnd)
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
else
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
addedBack = true;
}
return;
}
List attributeGroupContents = parentGroup.getContents();
for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (insertType == INSERT_BEFORE) {
if (attribute == nextRefComponent) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (attribute == previousRefComponent) {
parentGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
}
index++;
}
if (attributeGroupContents.size() == 0) {
parentGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentGroup.getContents().add(originalIndex, selected.getContainer());
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class ExtensionsSection method getAddExtensionCommand.
protected AddExtensionCommand getAddExtensionCommand(Object o) {
AddExtensionCommand addExtensionCommand = null;
if (o instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) o;
ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace());
if (extensibleAddExtensionCommand != null) {
extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element);
addExtensionCommand = extensibleAddExtensionCommand;
} else {
addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element);
}
} else if (o instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute);
}
return addExtensionCommand;
}
Aggregations