use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class RenameEnablementTester method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
if (selectedObject == null) {
return false;
}
XSDNamedComponent selectedComponent = null;
boolean enable = false;
XSDSchema selectedComponentSchema = null;
selectedComponentSchema = selectedObject.getSchema();
if (selectedComponentSchema != null && selectedComponentSchema == schema) {
enable = true;
}
if (enable && selectedObject instanceof XSDNamedComponent) {
selectedComponent = (XSDNamedComponent) selectedObject;
if (selectedComponent instanceof XSDElementDeclaration) {
XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
if (element.isElementDeclarationReference()) {
return false;
}
if (!element.isGlobal()) {
return false;
}
}
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)) {
return false;
}
} else if (parent instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
if (element.getAnonymousTypeDefinition().equals(type)) {
return false;
}
}
}
return true;
}
return false;
}
use of org.eclipse.xsd.XSDConcreteComponent in project tmdm-studio-se by Talend.
the class XSDGetXPathAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDParticle particle = (XSDParticle) selection.getFirstElement();
XSDTerm term = particle.getTerm();
if (!(term instanceof XSDElementDeclaration))
return Status.CANCEL_STATUS;
Clipboard clipboard = Util.getClipboard();
// $NON-NLS-1$
String path = "";
TreeItem item = page.getTreeViewer().getTree().getSelection()[0];
do {
XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
if (component instanceof XSDParticle) {
if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration)
// $NON-NLS-1$
path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
} else if (component instanceof XSDElementDeclaration) {
path = ((XSDElementDeclaration) component).getName() + path;
}
// System.out.println(" "+path+ " $$"+component.toString()+"$$");
item = item.getParentItem();
} while (item != null);
xpath = path;
clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() });
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDGetXPathAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDConcreteComponent in project tmdm-studio-se by Talend.
the class XSDDeleteAttributeAction method doAction.
@Override
protected IStatus doAction() {
try {
XSDAttributeUse attriUse = attributeUse;
XSDAttributeDeclaration attriDec = attributeDeclaration;
if (attriUse == null || attriDec == null) {
ISelection selection = page.getTreeViewer().getSelection();
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
if (firstElement instanceof XSDAttributeUse) {
attriUse = (XSDAttributeUse) firstElement;
} else if (firstElement instanceof XSDAttributeDeclaration) {
attriDec = (XSDAttributeDeclaration) firstElement;
}
}
if (attriUse != null) {
if (attriUse.getContainer() == null) {
return Status.CANCEL_STATUS;
}
XSDConcreteComponent container = attriUse.getContainer();
if (container instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition cType = (XSDComplexTypeDefinition) container;
cType.getAttributeUses().remove(attriUse);
cType.getAttributeContents().remove(attriUse);
cType.updateElement();
}
} else if (attriDec != null) {
if (attriDec.getContainer() == null) {
return Status.CANCEL_STATUS;
}
XSDConcreteComponent container = attriDec.getContainer();
if (container instanceof XSDSchema) {
XSDSchema xsdschema = (XSDSchema) container;
xsdschema.getContents().remove(attriDec);
}
}
schema.update();
attributeUse = null;
attributeDeclaration = null;
page.refresh();
page.markDirtyWithoutCommit();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations