Search in sources :

Example 1 with AnnotationLanguageLabelsDialog

use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog in project tmdm-studio-se by Talend.

the class DescAnnotationComposite method widgetSelected.

public void widgetSelected(SelectionEvent e) {
    AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(dataStore, new DescAnnotationListener(), descriptionText.getShell(), dlgTitle);
    dlg.setBlockOnOpen(true);
    dlg.open();
    if (dlg.getReturnCode() == Window.OK) {
        dlg.close();
    }
}
Also used : AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)

Example 2 with AnnotationLanguageLabelsDialog

use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog in project tmdm-studio-se by Talend.

the class XSDSetAnnotaionDisplayFormatAction 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.XSDSetAnnoXX_ExceptionInfo + selection.getFirstElement().getClass().getName());
        }
        dlg = new AnnotationLanguageLabelsDialog(struc.getDisplayFormat(), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle2);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        LinkedHashMap<String, String> fomats = dlg.getDescriptionsMap();
        struc.setDisplayFormat(fomats);
        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.XSDSetAnnoXX_ErrorMsg2, 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 3 with AnnotationLanguageLabelsDialog

use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog 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 4 with AnnotationLanguageLabelsDialog

use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog 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 5 with AnnotationLanguageLabelsDialog

use of com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog in project tmdm-studio-se by Talend.

the class ConfigReturnMessagePage method createControl.

/**
 * Create contents of the wizard.
 *
 * @param parent
 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(3, false));
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel.setText(Messages.ConfigReturnMessagePage_type);
    typeCombo = new Combo(container, SWT.READ_ONLY);
    // $NON-NLS-1$ //$NON-NLS-2$
    typeCombo.setItems(new String[] { "error", "info" });
    typeCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    typeCombo.select(0);
    typeCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            getWizard().getContainer().updateButtons();
        }
    });
    Label lblMessage = new Label(container, SWT.NONE);
    lblMessage.setText(Messages.ConfigReturnMessagePage_message);
    Button btnNewButton = new Button(container, SWT.NONE);
    btnNewButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AnnotationLanguageLabelsDialog dialog = new AnnotationLanguageLabelsDialog(null, null, getShell(), Messages.ConfigReturnMessagePage_setMessage);
            if (dialog.open() == IDialogConstants.OK_ID) {
                StringBuffer output = new StringBuffer();
                for (Map.Entry<String, String> m : dialog.getDescriptionsMap().entrySet()) {
                    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    output.append("[").append(m.getKey().toUpperCase()).append(":").append(m.getValue()).append("]");
                }
                messageText.setText(output.toString());
            }
        }
    });
    btnNewButton.setText(Messages.ConfigReturnMessagePage_selectMessage);
    messageText = new Text(container, SWT.BORDER);
    messageText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            getWizard().getContainer().updateButtons();
        }
    });
    messageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    setPageComplete(false);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)

Aggregations

AnnotationLanguageLabelsDialog (com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)6 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 TreePath (org.eclipse.jface.viewers.TreePath)4 TreeSelection (org.eclipse.jface.viewers.TreeSelection)4 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)4 XSDComponent (org.eclipse.xsd.XSDComponent)4 Element (org.w3c.dom.Element)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Iterator (java.util.Iterator)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1