use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog 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;
}
Aggregations