Search in sources :

Example 31 with XSDAnnotationsStructure

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

the class XSDSetAnnotationDocumentationAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetXX_ExceptionInfo, selection.getFirstElement().getClass().getName()));
        }
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetXX_DialogTitle, Messages.XSDSetXX_DialogTip, struc.getDocumentation(), new IInputValidator() {

            public String isValid(String newText) {
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // $NON-NLS-1$
        struc.setDocumentation("".equals(id.getValue()) ? null : id.getValue());
        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.XSDSetXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 32 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure 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;
}
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) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 33 with XSDAnnotationsStructure

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

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