use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.
the class UpdateComponentReferenceAndManageDirectivesCommand method computeComponent.
protected XSDComponent computeComponent() {
XSDComponent result = null;
XSDSchema schema = concreteComponent.getSchema();
XSDSchemaDirective directive = null;
// lets see if the element is already visible to our schema
result = getDefinedComponent(schema, componentName, componentNamespace);
if (result == null) {
// includes/imports to get to it
if (componentNamespace != null && componentNamespace.equals(schema.getTargetNamespace())) {
// we need to add an include
// if the component's namespace is not null and matches the schema's
// target namespace
directive = XSDFactory.eINSTANCE.createXSDInclude();
} else if (componentNamespace == null) {
// we need to add an include
// if the component's namespace is null, then we can just add it
// only if the current namespace is not null
directive = XSDFactory.eINSTANCE.createXSDInclude();
// we have to ensure the schema for schema prefix is NOT null
if (schema.getSchemaForSchemaQNamePrefix() == null) {
String targetNS = schema.getTargetNamespace();
if (targetNS == null)
targetNS = "";
// this will just update the schema for schema prefix to be, say, xsd
UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand("", schema, "", targetNS);
command.execute();
}
} else {
// we need to add an import
XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
xsdImport.setNamespace(componentNamespace);
directive = xsdImport;
}
String location = computeNiceLocation(schema.getSchemaLocation(), file);
directive.setSchemaLocation(location);
// TODO (cs) we should at the directive 'next' in the list of directives
// for now I'm just adding as the first thing in the schema :-(
//
schema.getContents().add(0, directive);
XSDSchema resolvedSchema = directive.getResolvedSchema();
if (resolvedSchema == null) {
String platformLocation = "platform:/resource" + file.getFullPath();
Resource resource = concreteComponent.eResource().getResourceSet().createResource(URI.createURI(platformLocation));
if (resource instanceof XSDResourceImpl) {
try {
resource.load(null);
XSDResourceImpl resourceImpl = (XSDResourceImpl) resource;
resolvedSchema = resourceImpl.getSchema();
if (resolvedSchema != null) {
directive.setResolvedSchema(resolvedSchema);
}
} catch (Exception e) {
}
}
}
if (resolvedSchema != null) {
result = getDefinedComponent(resolvedSchema, componentName, componentNamespace);
} else {
// TODO (cs) consider setting some error state so that the client can
// provide a pop-dialog error
// we should also remove the import/include so save from cluttering
// the file with bogus directives
}
}
return result;
}
use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.
the class UpdateElementReferenceAndManageDirectivesCommand method execute.
public void execute() {
try {
beginRecording(concreteComponent.getElement());
XSDComponent elementDef = computeComponent();
if (elementDef != null) {
UpdateElementReferenceCommand command = new UpdateElementReferenceCommand(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE, (XSDElementDeclaration) concreteComponent, (XSDElementDeclaration) elementDef);
command.execute();
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
}
} catch (Exception e) {
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.
the class XSDSetAnnotationDescriptionsAction 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);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
}
AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem);
dlg.setBlockOnOpen(true);
dlg.open();
if (dlg.getReturnCode() == Window.OK) {
// remove existing annotations with labels
struc.removeAllDescriptions();
// add the new ones
LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
Set<String> isoCodes = descriptions.keySet();
for (Iterator iter = isoCodes.iterator(); iter.hasNext(); ) {
String isoCode = (String) iter.next();
struc.setDescription(isoCode, descriptions.get(isoCode));
}
} else {
return Status.CANCEL_STATUS;
}
if (struc.hasChanged()) {
page.markDirty();
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_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 XSDSetAnnotationFKFilterAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
String conceptName = 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();
}
if (xSDCom instanceof XSDElementDeclaration) {
// $NON-NLS-1$
conceptName = xSDCom.getElement().getAttributes().getNamedItem("name").getNodeValue();
}
if (xSDCom instanceof XSDParticle) {
}
XSDAnnotationsStructure struc = null;
if (xSDCom != null) {
struc = new XSDAnnotationsStructure(xSDCom);
}
if (struc == null || struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
}
fkd = getNewFKFilterDialog(page.getSite().getShell(), struc.getFKFilter(), page, conceptName);
fkd.setDataModel(dataModelName);
fkd.setLock(true);
fkd.setBlockOnOpen(true);
int ret = fkd.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
String fkfilter = fkd.getFilter();
struc.setFKFilter(fkfilter);
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorFKFilter, 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 XSDSetAnnotationForeignKeyInfoAction method doAction.
@Override
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);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
}
dlg = getNewAnnotaionOrderedListsDialog(struc.getForeignKeyInfos().values());
dlg.setLock(true);
dlg.setRetrieveFKinfos(struc.getRetrieveFKinfos());
dlg.setFormatFKInfo(struc.getFormatForeignKeyInfo());
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
struc.setForeignKeyInfos(dlg.getXPaths());
struc.setRetrieveFKinfos(dlg.isRetrieveFKinfos());
struc.setFormatForeignKeyInfo(dlg.getFormatFKInfo());
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations