use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.
the class XSDSetFacetMessageAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetFacetMessageAction_ExceptionInfo, selection.getFirstElement().getClass().getName()));
}
dlg = new AnnotationLanguageLabelsDialog(struc.getFactMessage(), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDSetFacetMessageAction_DialogTip);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
LinkedHashMap<String, String> facets = dlg.getDescriptionsMap();
struc.setFactMessage(facets);
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetFacetMessageAction_ErrorMsg + e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.
the class DataModelMainPage method getStructureByActiveItem.
public XSDAnnotationsStructure getStructureByActiveItem() {
XSDComponent xSDCom = null;
XSDAnnotationsStructure struc = null;
IStructuredSelection selection = (TreeSelection) getTreeViewer().getSelection();
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
}
} else {
xSDCom = (XSDComponent) selection.getFirstElement();
}
if (xSDCom != null) {
struc = new XSDAnnotationsStructure(xSDCom);
}
return struc;
}
use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.
the class DataModelMainPage method addLabelForTheItem.
private void addLabelForTheItem(TreeItem[] items, boolean isAdd) {
XSDComponent xSDCom = null;
for (TreeItem item : items) {
XSDAnnotationsStructure struc = null;
String labelValue = null;
if (item.getData() instanceof XSDElementDeclaration) {
xSDCom = (XSDElementDeclaration) item.getData();
struc = new XSDAnnotationsStructure(xSDCom);
labelValue = ((XSDElementDeclaration) xSDCom).getName();
setLabel(struc, labelValue, isAdd);
setLabelForElement((XSDElementDeclaration) xSDCom, isAdd);
}
}
}
use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.
the class XSDAnnotationsStructure method setAccessRole.
/**
**************************************************************************
* WRITE ACCESS
*
* @throws XtentisException
***************************************************************************
*/
public boolean setAccessRole(Collection<String> roles, boolean recursive, IStructuredContentProvider provider, String access) throws Exception {
XSDSchema xsd = schema != null ? schema : declaration.getSchema();
String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
if (recursive) {
ArrayList<Object> objList = new ArrayList<Object>();
XSDComponent component = declaration;
if (declaration == null) {
component = this.componet;
}
Object[] objs = Util.getAllObject(component, objList, provider);
while (objs.length > 0) {
Object[] objCpys = objs;
for (Object obj : objCpys) {
if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
boolean isImported = false;
if (obj instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) obj;
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
if (Util.IsAImporedElement(decl, xsdString)) {
XSDTypeDefinition typeDef = decl.getTypeDefinition();
if (Util.IsAImporedElement(typeDef, xsdString)) {
isImported = true;
}
}
}
} else if (obj instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
if (Util.IsAImporedElement(decl, xsdString)) {
isImported = true;
}
}
if (!isImported) {
XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
// see 7993, if UUID/AUTO_INCREMENT ,should not add write access
if (obj instanceof XSDParticle) {
XSDParticle o = (XSDParticle) obj;
// String name=Util.getFirstTextNode(o.getElement(), "@name");
// $NON-NLS-1$
String type = Util.getFirstTextNode(o.getElement(), "@type");
if (EUUIDCustomType.AUTO_INCREMENT.equals(type) || EUUIDCustomType.UUID.equals(type)) {
objList.remove(obj);
objs = objList.toArray();
continue;
}
}
// X_Write
annotion.removeAppInfos(access);
for (Iterator<String> iter = roles.iterator(); iter.hasNext(); ) {
String role = iter.next();
annotion.addAppInfo(access, role);
}
}
}
objList.remove(obj);
objs = objList.toArray();
}
}
return setAccessRole(roles, access);
} else {
if (Util.IsAImporedElement(declaration, xsdString)) {
return false;
}
return setAccessRole(roles, access);
}
}
use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.
the class UpdateAttributeReferenceAndManagerDirectivesCommand method execute.
public void execute() {
try {
beginRecording(concreteComponent.getElement());
XSDComponent componentDef = computeComponent();
if (componentDef != null) {
UpdateAttributeReferenceCommand command = new UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, (XSDAttributeDeclaration) concreteComponent, (XSDAttributeDeclaration) componentDef);
command.execute();
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
}
} catch (Exception e) {
} finally {
endRecording();
}
}
Aggregations