Search in sources :

Example 6 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.

the class XSDSetAnnotationSourceSystemAction 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.ExceptionInfo, xSDCom.getClass().getName()));
        }
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle1, Messages.XSDSetAnnoXX_DialogTip, struc.getSourceSystem(), 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.setSourceSystem("".equals(id.getValue()) ? null : id.getValue());
        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.XSDSetAnnoXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) 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) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 7 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.

the class UpdateTypeReferenceAndManageDirectivesCommand method execute.

public void execute() {
    try {
        beginRecording(concreteComponent.getElement());
        XSDComponent td = computeComponent();
        if (td != null && td instanceof XSDTypeDefinition) {
            UpdateTypeReferenceCommand command = new UpdateTypeReferenceCommand(concreteComponent, (XSDTypeDefinition) td);
            command.execute();
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        }
    } catch (Exception e) {
    } finally {
        endRecording();
    }
}
Also used : XSDComponent(org.eclipse.xsd.XSDComponent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 8 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.

the class SetBaseTypeAndManagerDirectivesCommand method execute.

public void execute() {
    try {
        beginRecording(concreteComponent.getElement());
        XSDComponent td = computeComponent();
        if (td != null && td instanceof XSDTypeDefinition) {
            SetBaseTypeCommand command = new SetBaseTypeCommand(concreteComponent, (XSDTypeDefinition) td);
            command.execute();
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        }
    } catch (Exception e) {
    } finally {
        endRecording();
    }
}
Also used : XSDComponent(org.eclipse.xsd.XSDComponent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 9 with XSDComponent

use of org.eclipse.xsd.XSDComponent 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 10 with XSDComponent

use of org.eclipse.xsd.XSDComponent 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)

Aggregations

XSDComponent (org.eclipse.xsd.XSDComponent)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 TreePath (org.eclipse.jface.viewers.TreePath)14 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 ArrayList (java.util.ArrayList)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 AnnotationLanguageLabelsDialog (com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)4 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)4 AnnotationOrderedListsDialog (com.amalto.workbench.dialogs.AnnotationOrderedListsDialog)3 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)3 Iterator (java.util.Iterator)2 XSDParticle (org.eclipse.xsd.XSDParticle)2 XSDSchema (org.eclipse.xsd.XSDSchema)2 DataModelMainPage (com.amalto.workbench.editors.DataModelMainPage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1