Search in sources :

Example 16 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class ElementInfoConfigComposite method initUIContents.

private void initUIContents() {
    String name = Util.getParticleName(curXSDParticle);
    removeTextListener();
    txtName.setText(name);
    if (name != null) {
        int length = name.length();
        if (length >= caretOffset) {
            txtName.setSelection(caretOffset, caretOffset);
        } else {
            txtName.setSelection(length, length);
        }
    }
    addTextListener();
    comboReference.setItems(getAllReferences());
    comboReference.setText(Util.getParticleReferenceName(curXSDParticle));
    if (curXSDParticle != null) {
        spinMin.setSelection(curXSDParticle.getMinOccurs());
        spinMax.setSelection(curXSDParticle.getMaxOccurs());
        if (autoExpandBtn != null) {
            XSDAnnotationsStructure struct = new XSDAnnotationsStructure(curXSDParticle);
            String auto = struct.getAutoExpand();
            if (auto != null) {
                autoExpandBtn.setSelection(Boolean.valueOf(auto));
            } else {
                autoExpandBtn.setSelection(false);
            }
        }
    }
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure)

Example 17 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class XSDSetAnnotationLabelAction method doAction.

@Override
public IStatus doAction() {
    try {
        // IStructuredSelection selection = (IStructuredSelection)page.getTreeViewer().getSelection();
        // 
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        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.XSDSetAnnotationLabelAction_ExceptioInfo, xSDCom.getClass().getName()));
        }
        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getLabels(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationLabelAction_DialogTitle);
        dlg.setBlockOnOpen(true);
        dlg.open();
        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllLabels();
            // 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.setLabel(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.XSDSetAnnotationLabelAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 18 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class XSDSetAnnotationTargetSystemsAction 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.XSDSetAnnotationTargetSystemsAction_ExceptionInfo, xSDCom.getClass().getName()));
        }
        dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getTargetSystems().values()), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetAnnotationTargetSystemsAction_DialogTitle, Messages.XSDSetAnnotationTargetSystemsAction_DialogTip, page, AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType, dataModelName);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        struc.setTargetSystems(dlg.getXPaths());
        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.XSDSetAnnotationTargetSystemsAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) AnnotationOrderedListsDialog(com.amalto.workbench.dialogs.AnnotationOrderedListsDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 19 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure 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;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 20 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class FacetMsgCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    LinkedHashMap<String, String> langCode2Value = new LinkedHashMap<String, String>();
    for (Entry<String, LanguageInfo> eachLangCode2LangInfo : getCommitedObj().getLangCode2LangInfo().entrySet()) langCode2Value.put(eachLangCode2LangInfo.getKey(), eachLangCode2LangInfo.getValue().getLabel());
    return xsdAnnoStruct.setFactMessage(langCode2Value);
}
Also used : LanguageInfo(com.amalto.workbench.detailtabs.sections.model.annotationinfo.langinfo.LanguageInfo) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)33 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDComponent (org.eclipse.xsd.XSDComponent)13 Element (org.w3c.dom.Element)13 TreePath (org.eclipse.jface.viewers.TreePath)12 TreeSelection (org.eclipse.jface.viewers.TreeSelection)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)10 XSDParticle (org.eclipse.xsd.XSDParticle)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 ArrayList (java.util.ArrayList)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)5 XSDTerm (org.eclipse.xsd.XSDTerm)5 AnnotationLanguageLabelsDialog (com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)4 XSDFactory (org.eclipse.xsd.XSDFactory)4 CommitException (com.amalto.workbench.detailtabs.exception.CommitException)3 CommitValidationException (com.amalto.workbench.detailtabs.exception.CommitValidationException)3 LanguageInfo (com.amalto.workbench.detailtabs.sections.model.annotationinfo.langinfo.LanguageInfo)3