use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDModelGroupDefinitionSection method setInput.
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
init();
relayout();
if (isReference) {
TypesHelper helper = new TypesHelper(xsdSchema);
List items = new ArrayList();
items = helper.getModelGroups();
if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition group = (XSDModelGroupDefinition) input;
XSDConcreteComponent parent = group.getContainer();
while (parent != null) {
if (parent instanceof XSDModelGroupDefinition) {
items.remove(((XSDModelGroupDefinition) parent).getQName());
break;
}
parent = parent.getContainer();
}
}
// $NON-NLS-1$
items.add(0, "");
componentNameCombo.setItems((String[]) items.toArray(new String[0]));
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class XSDExtensionTreeContentProvider method getElements.
public Object[] getElements(Object inputElement) {
if (inputElement instanceof XSDConcreteComponent) {
XSDConcreteComponent component = (XSDConcreteComponent) inputElement;
List elementsAndAttributes = new ArrayList();
XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
if (xsdAnnotation != null) {
// Added this if statement
if (xsdAnnotation.getSchema() == component.getSchema()) {
List appInfoList = xsdAnnotation.getApplicationInformation();
Element appInfoElement = null;
if (appInfoList.size() > 0) {
appInfoElement = (Element) appInfoList.get(0);
}
if (appInfoElement != null) {
for (Iterator it = appInfoList.iterator(); it.hasNext(); ) {
Object obj = it.next();
if (obj instanceof Element) {
Element appInfo = (Element) obj;
NodeList nodeList = appInfo.getChildNodes();
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
elementsAndAttributes.add(node);
}
}
}
}
/**
* Construct attributes list
*/
NamedNodeMap attributes = appInfoElement.getAttributes();
if (attributes != null) {
// String defaultNamespace =
// (String)component.getSchema().getQNamePrefixToNamespaceMap().get("");
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
Node oneAttribute = attributes.item(i);
if (!isXmlnsAttribute(oneAttribute)) {
String namespace = oneAttribute.getNamespaceURI();
boolean isExtension = true;
if (namespace == null && oneAttribute.getPrefix() == null) {
isExtension = false;
} else if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace)) {
isExtension = true;
}
if (isExtension) {
elementsAndAttributes.add(oneAttribute);
}
}
}
}
}
}
}
return elementsAndAttributes.toArray();
}
return Collections.EMPTY_LIST.toArray();
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MakeLocalElementGlobalCommand method run.
public void run() {
if (getModelObject() instanceof XSDElementDeclaration) {
XSDElementDeclaration localElementDeclaration = (XSDElementDeclaration) getModelObject();
XSDConcreteComponent parent = getParent();
XSDConcreteComponent container = parent.getContainer();
// Clone the local element with its content and set it global
XSDElementDeclaration globalElementDeclaration = (XSDElementDeclaration) localElementDeclaration.cloneConcreteComponent(true, false);
// The schema may already have a global element declaration with this name. In that case, ensure the name of the newly created
// element does not collide with an existing one.
XSDSchema schema = container.getSchema();
String localElementName = localElementDeclaration.getName();
XSDElementDeclaration existingGlobalElement = schema.resolveElementDeclaration(localElementName);
boolean elementExists = existingGlobalElement != null && existingGlobalElement.getSchema() != null;
if (elementExists) {
String newElementName = XSDCommonUIUtils.createUniqueElementName(localElementName, schema.getElementDeclarations());
globalElementDeclaration.setName(newElementName);
}
EList schemaContents = schema.getContents();
schemaContents.add(globalElementDeclaration);
// Modify the local element to become a reference to the global element.
localElementDeclaration.setName(null);
localElementDeclaration.setTypeDefinition(null);
localElementDeclaration.setAnonymousTypeDefinition(null);
localElementDeclaration.setResolvedElementDeclaration(globalElementDeclaration);
XSDModelGroup modelGroup = (XSDModelGroup) container;
// Format the markup.
formatChild(modelGroup.getElement());
formatChild(globalElementDeclaration.getElement());
}
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class RenameComponentAction method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject) {
selectedComponent = null;
if (selectedObject instanceof XSDNamedComponent) {
selectedComponent = (XSDNamedComponent) selectedObject;
// if it's element reference, then this action is not appropriate
if (selectedComponent instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
if (element.isElementDeclarationReference()) {
selectedComponent = null;
}
}
if (selectedComponent instanceof XSDTypeDefinition) {
XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
XSDConcreteComponent parent = type.getContainer();
if (parent instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) parent;
if (element.getAnonymousTypeDefinition().equals(type)) {
selectedComponent = null;
}
} else if (parent instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
if (element.getAnonymousTypeDefinition().equals(type)) {
selectedComponent = null;
}
}
}
}
return canRun();
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class RefactorEnablementTester method test.
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
IWorkbenchPage activePage = window.getActivePage();
if (activePage == null) {
return false;
}
IEditorPart editor = activePage.getActiveEditor();
if (editor == null) {
return false;
}
XSDSchema schema = (XSDSchema) editor.getAdapter(XSDSchema.class);
if (receiver instanceof IStructuredSelection) {
IStructuredSelection fStructuredSelection = (IStructuredSelection) receiver;
receiver = fStructuredSelection.getFirstElement();
if (receiver instanceof XSDBaseAdapter) {
receiver = ((XSDBaseAdapter) receiver).getTarget();
}
if (receiver instanceof XSDConcreteComponent) {
return canEnable((XSDConcreteComponent) receiver, schema);
} else if (receiver instanceof Node) {
Node node = (Node) receiver;
if (schema != null) {
XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
return canEnable(concreteComponent, schema);
}
}
return true;
}
return false;
}
Aggregations