Search in sources :

Example 1 with IListener

use of com.microsoft.azuretools.authmanage.srvpri.report.IListener in project azure-tools-for-java by Microsoft.

the class SrvPriCreationStatusDialog method createServicePrincipalAsync.

private void createServicePrincipalAsync() {
    try {
        class StatusTask implements IRunnableWithProgress, IListener<Status> {

            IProgressMonitor progressIndicator = null;

            @Override
            public void listen(Status status) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (progressIndicator != null) {
                            progressIndicator.setTaskName(status.getAction());
                        }
                        // if only action was set in the status - the info for progress indicator only - igonre for table
                        if (status.getResult() != null) {
                            TableItem item = new TableItem(table, SWT.NULL);
                            item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
                        }
                    }
                });
            }

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                progressIndicator = monitor;
                monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
                for (String tid : tidSidsMap.keySet()) {
                    if (monitor.isCanceled()) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                TableItem item = new TableItem(table, SWT.NULL);
                                item.setText(new String[] { "!!! Canceled by user" });
                            }
                        });
                        return;
                    }
                    List<String> sidList = tidSidsMap.get(tid);
                    if (!sidList.isEmpty()) {
                        try {
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    TableItem item = new TableItem(table, SWT.NULL);
                                    item.setText(new String[] { "tenant ID: " + tid + " ===" });
                                }
                            });
                            Date now = new Date();
                            String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
                            ;
                            String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
                            if (authFilepath != null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        listCreatedFiles.add(authFilepath);
                                        listCreatedFiles.setSelection(0);
                                    }
                                });
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
                        }
                    }
                }
            }
        }
        new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) TableItem(org.eclipse.swt.widgets.TableItem) IListener(com.microsoft.azuretools.authmanage.srvpri.report.IListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

IListener (com.microsoft.azuretools.authmanage.srvpri.report.IListener)1 Status (com.microsoft.azuretools.authmanage.srvpri.step.Status)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TableItem (org.eclipse.swt.widgets.TableItem)1