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();
}
}
Aggregations