Search in sources :

Example 1 with AddTemplateDialog

use of org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog in project syncope by apache.

the class SyncopeView method makeActions.

private void makeActions() {
    loginAction = new Action() {

        public void run() {
            Shell shell = viewer.getControl().getShell();
            LoginDialog dialog = new LoginDialog(shell);
            dialog.create();
            if (dialog.open() == Window.OK) {
                String deploymentUrl = dialog.getDeploymentUrl();
                String username = dialog.getUsername();
                String password = dialog.getPassword();
                vcp.deploymentUrl = deploymentUrl;
                vcp.username = username;
                vcp.password = password;
                updateTreeViewer();
            }
        }
    };
    loginAction.setText(LOGIN_ACTION_TEXT);
    loginAction.setToolTipText(LOGIN_ACTION_TOOLTIP_TEXT);
    refreshAction = new Action() {

        public void run() {
            updateTreeViewer();
        }
    };
    refreshAction.setText(REFRESH_ACTION_TEXT);
    refreshAction.setToolTipText(REFRESH_ACTION_TOOLTIP_TEXT);
    doubleClickAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            Object obj = ((IStructuredSelection) selection).getFirstElement();
            if (!(obj instanceof TreeParent)) {
                openTemplateInEditor((TreeObject) obj);
            } else {
                viewer.expandToLevel(obj, 1);
            }
        }
    };
    readAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement();
            openTemplateInEditor(obj);
        }
    };
    readAction.setText(READ_ACTION_TEXT);
    addAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeParent tp = (TreeParent) ((IStructuredSelection) selection).getFirstElement();
            Shell shell = viewer.getControl().getShell();
            AddTemplateDialog addTemplateDialog = new AddTemplateDialog(shell);
            addTemplateDialog.create();
            if (addTemplateDialog.open() == Window.OK) {
                String key = addTemplateDialog.getKey();
                try {
                    if (tp.getName().equals(MAIL_TEMPLATE_LABEL)) {
                        MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class);
                        MailTemplateTO mtto = new MailTemplateTO();
                        mtto.setKey(key);
                        mailTemplateService.create(mtto);
                    } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) {
                        ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
                        ReportTemplateTO rtto = new ReportTemplateTO();
                        rtto.setKey(key);
                        reportTemplateService.create(rtto);
                    }
                    updateTreeViewer();
                } catch (final SyncopeClientException e) {
                    if (e.toString().contains("EntityExists")) {
                        MessageDialog.openError(shell, "Template already exists", "A template named " + key + " already exists.");
                    }
                }
            }
        }
    };
    addAction.setText(ADD_ACTION_TEXT);
    removeAction = new Action() {

        public void run() {
            ISelection selection = viewer.getSelection();
            TreeObject obj = (TreeObject) ((IStructuredSelection) selection).getFirstElement();
            TreeParent tp = (TreeParent) vcp.getParent(obj);
            if (MAIL_TEMPLATE_LABEL.equals(tp.getName())) {
                MailTemplateService mailTemplateService = SYNCOPE_CLIENT.getService(MailTemplateService.class);
                mailTemplateService.delete(obj.getName());
            } else if (tp.getName().equals(REPORT_TEMPLATE_LABEL)) {
                ReportTemplateService reportTemplateService = SYNCOPE_CLIENT.getService(ReportTemplateService.class);
                reportTemplateService.delete(obj.getName());
            }
            updateTreeViewer();
        }
    };
    removeAction.setText(REMOVE_ACTION_TEXT);
}
Also used : ReportTemplateService(org.apache.syncope.common.rest.api.service.ReportTemplateService) Action(org.eclipse.jface.action.Action) AddTemplateDialog(org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) MailTemplateService(org.apache.syncope.common.rest.api.service.MailTemplateService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Shell(org.eclipse.swt.widgets.Shell) MailTemplateTO(org.apache.syncope.common.lib.to.MailTemplateTO) ISelection(org.eclipse.jface.viewers.ISelection) LoginDialog(org.apache.syncope.ide.eclipse.plugin.dialogs.LoginDialog)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 MailTemplateTO (org.apache.syncope.common.lib.to.MailTemplateTO)1 ReportTemplateTO (org.apache.syncope.common.lib.to.ReportTemplateTO)1 MailTemplateService (org.apache.syncope.common.rest.api.service.MailTemplateService)1 ReportTemplateService (org.apache.syncope.common.rest.api.service.ReportTemplateService)1 AddTemplateDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.AddTemplateDialog)1 LoginDialog (org.apache.syncope.ide.eclipse.plugin.dialogs.LoginDialog)1 Action (org.eclipse.jface.action.Action)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1