Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog.

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:com.mentor.nucleus.bp.ui.text.activity.ParseAllActivitiesAction.java

License:Open Source License

public void run(IAction action) {
    IRunnableWithProgress rwp = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            IStructuredSelection selection = Selection.getInstance().getStructuredSelection();
            for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
                Object context = iterator.next();
                if (context instanceof Domain_c) {
                    ModelRoot.disableChangeNotification();
                    try {
                        AllActivityModifier aam = new AllActivityModifier((Domain_c) context, monitor);
                        aam.processAllActivities(AllActivityModifier.PARSE);
                    } finally {
                        ModelRoot.enableChangeNotification();
                    }// www .j  a  v  a 2s .co  m
                } else if (context instanceof Component_c) {
                    ModelRoot.disableChangeNotification();
                    try {
                        AllActivityModifier aam = new AllActivityModifier((Component_c) context, monitor);
                        aam.processAllActivities(AllActivityModifier.PARSE);
                    } finally {
                        ModelRoot.enableChangeNotification();
                    }
                } else if (context instanceof Package_c) {
                    ModelRoot.disableChangeNotification();
                    try {
                        AllActivityModifier aam = new AllActivityModifier((Package_c) context, monitor);
                        aam.processAllActivities(AllActivityModifier.PARSE);
                    } finally {
                        ModelRoot.enableChangeNotification();
                    }
                }
            }
        }
    };
    try {
        // can't fork this as we need this to run in main thread when
        // a domain load is forced
        new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(false, true, rwp);
    } catch (InterruptedException ie) {
        TextPlugin.logError("ParseAllActivitiesAction", ie);
    } catch (InvocationTargetException ite) {
        TextPlugin.logError("ParseAllActivitiesAction", ite);
    }
}

From source file:com.mg.merp.wb.bai.ui.editor.BAiEditorPage.java

License:Open Source License

private String selectBAiImpl() {
    IJavaSearchScope scope = null;/* w ww . ja  v a 2 s  .  c o m*/
    IType type = BAiPlugin.getBusinessAddinType();
    try {
        if (type == null)
            scope = SearchEngine.createWorkspaceScope();
        else
            scope = SearchEngine.createHierarchyScope(type);

        Shell sh = CoreUtils.getMainShell();
        SelectionDialog dialog = JavaUI.createTypeDialog(sh, new ProgressMonitorDialog(sh), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false);

        dialog.setTitle(BAiPlugin.getDefault().getString(BROWSE_DIALOG_TITLE));
        if (dialog.open() == Window.OK)
            return ((IType) dialog.getResult()[0]).getFullyQualifiedName();
        else
            return "";
    } catch (JavaModelException e1) {
        return "";
    }
}

From source file:com.mg.merp.wb.entitymapper.ui.editor.EntityMapperEditorPage.java

License:Open Source License

private String selectAvailableClasses() {
    try {//  ww  w .j  a  v a2 s.  c om
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

        Shell sh = CoreUtils.getMainShell();
        SelectionDialog dialog = JavaUI.createTypeDialog(sh, new ProgressMonitorDialog(sh), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false);

        dialog.setTitle(Activator.getDefault().getString(BROWSE_DIALOG_TITLE));
        if (dialog.open() == Window.OK)
            return ((IType) dialog.getResult()[0]).getFullyQualifiedName();
        else
            return "";
    } catch (JavaModelException e1) {
        return "";
    }
}

From source file:com.microsoft.azuretools.core.ui.SignInDialog.java

License:Open Source License

private void signInAsync() throws InvocationTargetException, InterruptedException {
    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override/*  w  w  w .j av  a 2s  . co m*/
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask("Signing In...", IProgressMonitor.UNKNOWN);
            try {
                AdAuthManager.getInstance().signIn();
            } catch (AuthCanceledException ex) {
                System.out.println(ex.getMessage());
            } catch (IOException ex) {
                System.out.println("run@ProgressDialog@signInAsync@SingInDialog: " + ex.getMessage());
                //ex.printStackTrace();
                //LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@signInAsync@SingInDialog", e));
                Display.getDefault().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        ErrorWindow.go(getShell(), ex.getMessage(), "Sign In Error");
                        ;
                    }
                });
            }
        }
    };
    new ProgressMonitorDialog(this.getShell()).run(true, false, op);
}

From source file:com.microsoft.azuretools.core.ui.SignInDialog.java

License:Open Source License

private void doCreateServicePrincipal() {
    setErrorMessage(null);/*w  ww.j  a  v  a  2 s . c  o m*/
    AdAuthManager adAuthManager = null;
    try {
        adAuthManager = AdAuthManager.getInstance();
        if (adAuthManager.isSignedIn()) {
            adAuthManager.signOut();
        }

        signInAsync();

        if (!adAuthManager.isSignedIn()) {
            // canceled by the user
            System.out.println(">> Canceled by the user");
            return;
        }

        AccessTokenAzureManager accessTokenAzureManager = new AccessTokenAzureManager();
        SubscriptionManager subscriptionManager = accessTokenAzureManager.getSubscriptionManager();

        IRunnableWithProgress op = new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Getting Subscription List...", IProgressMonitor.UNKNOWN);
                try {
                    subscriptionManager.getSubscriptionDetails();
                } catch (Exception ex) {
                    System.out.println(
                            "run@ProgressDialog@doCreateServicePrincipal@SignInDialog: " + ex.getMessage());
                    LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                            "run@ProgressDialog@doCreateServicePrincipal@SignInDialogg", ex));
                }
            }
        };
        new ProgressMonitorDialog(this.getShell()).run(true, false, op);

        SrvPriSettingsDialog d = SrvPriSettingsDialog.go(this.getShell(),
                subscriptionManager.getSubscriptionDetails());
        List<SubscriptionDetail> subscriptionDetailsUpdated;
        String destinationFolder;
        if (d != null) {
            subscriptionDetailsUpdated = d.getSubscriptionDetails();
            destinationFolder = d.getDestinationFolder();
        } else {
            System.out.println(">> Canceled by the user");
            return;
        }

        Map<String, List<String>> tidSidsMap = new HashMap<>();
        for (SubscriptionDetail sd : subscriptionDetailsUpdated) {
            if (sd.isSelected()) {
                System.out.format(">> %s\n", sd.getSubscriptionName());
                String tid = sd.getTenantId();
                List<String> sidList;
                if (!tidSidsMap.containsKey(tid)) {
                    sidList = new LinkedList<>();
                } else {
                    sidList = tidSidsMap.get(tid);
                }
                sidList.add(sd.getSubscriptionId());
                tidSidsMap.put(tid, sidList);
            }
        }

        SrvPriCreationStatusDialog d1 = SrvPriCreationStatusDialog.go(this.getShell(), tidSidsMap,
                destinationFolder);
        if (d1 == null) {
            System.out.println(">> Canceled by the user");
            return;
        }

        String path = d1.getSelectedAuthFilePath();
        if (path == null) {
            System.out.println(">> No file was created");
            return;
        }

        textAuthenticationFilePath.setText(path);
        fileDialog.setFilterPath(destinationFolder);

    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "doCreateServicePrincipal@SignInDialog", ex));
    } finally {
        if (adAuthManager != null) {
            adAuthManager.signOut();
        }
    }
}

From source file:com.microsoft.azuretools.core.ui.SrvPriCreationStatusDialog.java

License:Open Source License

private void createServicePrincipalAsync() {
    try {/*  w w w  .j av  a 2 s .  co m*/
        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();
    }
}

From source file:com.microsoft.azuretools.docker.utils.AzureDockerUIResources.java

License:Open Source License

public static void updateAzureResourcesWithProgressDialog(Shell shell, IProject project) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {//from  w  w w.j a v  a2s .c  o  m
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Loading Azure Resources", 100);
                try {
                    monitor.subTask("Creating an Azure instance...");
                    AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
                    if (monitor.isCanceled()) {
                        monitor.done();
                        return;
                    }
                    // not signed in
                    if (azureAuthManager == null) {
                        monitor.done();
                        return;
                    }
                    AzureDockerHostsManager dockerManager = AzureDockerHostsManager
                            .getAzureDockerHostsManagerEmpty(azureAuthManager);
                    monitor.worked(10);

                    monitor.subTask("Retrieving the subscription details...");
                    dockerManager.refreshDockerSubscriptions();
                    if (monitor.isCanceled()) {
                        monitor.done();
                        return;
                    }

                    monitor.worked(10);
                    monitor.subTask("Retrieving the key vault...");
                    dockerManager.refreshDockerVaults();
                    monitor.worked(10);
                    if (monitor.isCanceled()) {
                        monitor.done();
                        return;
                    }

                    monitor.worked(10);
                    monitor.subTask("Retrieving the key vault details...");
                    dockerManager.refreshDockerVaultDetails();
                    if (monitor.isCanceled()) {
                        CANCELED = true;
                        monitor.done();
                        return;
                    }

                    monitor.worked(10);
                    monitor.subTask("Retrieving the network details...");
                    dockerManager.refreshDockerVnetDetails();
                    if (monitor.isCanceled()) {
                        monitor.done();
                        return;
                    }

                    monitor.worked(10);
                    monitor.subTask("Retrieving the storage account details...");
                    dockerManager.refreshDockerStorageAccountDetails();
                    if (monitor.isCanceled()) {
                        monitor.done();
                        return;
                    }

                    monitor.subTask("Retrieving the Docker virtual machines details...");
                    dockerManager.refreshDockerHostDetails();
                    CANCELED = false;
                } catch (Exception e) {
                    CANCELED = true;
                    log.log(Level.SEVERE, "updateAzureResourcesWithProgressDialog: " + e.getMessage(), e);
                    e.printStackTrace();
                }

                monitor.done();
            }
        });
    } catch (Exception e) {
        CANCELED = true;
        log.log(Level.SEVERE, "updateAzureResourcesWithProgressDialog: " + e.getMessage(), e);
        e.printStackTrace();
    }
}

From source file:com.microsoft.azuretools.docker.utils.AzureDockerUIResources.java

License:Open Source License

public static void createArtifact(Shell shell, IProject project) {
    if (project == null) {
        return;//from   w  w  w. j a v a2 s  .  c om
    }

    String projectName = project.getName();
    String destinationPath = project.getLocation() + "/" + projectName + ".war";
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask("Creating WAR artifact", 100);
                try {
                    progressMonitor
                            .subTask(String.format("Building selected project: %s ...", project.getName()));
                    progressMonitor.worked(35);
                    project.build(IncrementalProjectBuilder.FULL_BUILD, null);

                    progressMonitor.subTask("Exporting to WAR ...");
                    progressMonitor.worked(75);
                    IDataModel dataModel = DataModelFactory
                            .createDataModel(new WebComponentExportDataModelProvider());
                    dataModel.setProperty(IJ2EEComponentExportDataModelProperties.PROJECT_NAME, projectName);
                    dataModel.setProperty(IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION,
                            destinationPath);

                    if (dataModel.getDefaultOperation() != null)
                        try {
                            dataModel.getDefaultOperation().execute(null, null);
                        } catch (Exception ignored) {
                        }

                    //                  progressMonitor.subTask("");
                    //                  progressMonitor.worked(1);
                    //                  if (progressMonitor.isCanceled()) {
                    //                     if (displayWarningOnCreateKeyVaultCancelAction() == 0) {
                    //                        progressMonitor.done();
                    //                        return Status.CANCEL_STATUS;
                    //                     }
                    //                  }
                    progressMonitor.done();
                } catch (Exception e) {
                    String msg = "An error occurred while attempting to create WAR artifact" + "\n"
                            + e.getMessage();
                    log.log(Level.SEVERE, "createArtifact: " + msg, e);
                    e.printStackTrace();
                }

                progressMonitor.done();
            }
        });
    } catch (Exception e) {
        CANCELED = true;
        log.log(Level.SEVERE, "updateAzureResourcesWithProgressDialog: " + e.getMessage(), e);
        e.printStackTrace();
    }
}

From source file:com.microsoft.tfs.client.common.ui.framework.command.ProgressMonitorDialogCommandExecutor.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww w  . j  a va  2 s.  c om
 */
@Override
protected IRunnableContext getRunnableContext(final ICommand command) {
    final IRunnableContext runnableContext;

    if (progressUIDeferTime <= 0) {
        runnableContext = new ProgressMonitorDialog(shell);
    } else {
        runnableContext = new DeferredProgressMonitorDialogContext(shell, progressUIDeferTime);
    }

    /*
     * Set up a state change listener if the command changes is
     * cancellability.
     */
    if (command instanceof CancellableCommand) {
        ((CancellableCommand) command)
                .addCancellableChangedListener(new CommandCancellableChangedListener(runnableContext));
    }

    return runnableContext;
}

From source file:com.microsoft.tfs.client.common.ui.framework.runnable.DeferredProgressMonitorDialogContext.java

License:Open Source License

@Override
public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress inputRunnable)
        throws InvocationTargetException, InterruptedException {
    final RunnableWithProgressWrapper wrappedRunnable = new RunnableWithProgressWrapper(inputRunnable);

    final InvocationTargetException[] invocationTargetExceptionHolder = new InvocationTargetException[1];
    final InterruptedException[] interruptedExceptionHolder = new InterruptedException[1];

    /*/*from  w w  w . j a  va  2  s.  c o m*/
     * Start executing the command in the context of a
     * ProgressMonitorDialog, however do not actually open the progress
     * monitor dialog. The command will execute properly, and we can open
     * the progress monitor dialog after our defer time.
     */
    UIHelpers.runOnUIThread(shell, false, new Runnable() {
        @Override
        public void run() {
            dialog = new ProgressMonitorDialog(shell);
            dialog.setOpenOnRun(false);

            /*
             * Create a job that will open the progress monitor dialog after
             * our defer time has elapsed.
             */
            final Job showProgressUIJob = createProgressUIJob(inputRunnable, wrappedRunnable, dialog);

            showProgressUIJob.setSystem(true);
            showProgressUIJob.schedule(deferTimeMillis);

            BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
                @Override
                public void run() {
                    setUserInterfaceActive(false);
                    try {
                        /* Run the command. */
                        dialog.run(fork, cancelable, wrappedRunnable);
                    } catch (final InvocationTargetException e) {
                        invocationTargetExceptionHolder[0] = e;
                    } catch (final InterruptedException e) {
                        interruptedExceptionHolder[0] = e;
                    } finally {
                        setUserInterfaceActive(true);
                    }
                }
            });
        }
    });

    if (invocationTargetExceptionHolder[0] != null) {
        throw invocationTargetExceptionHolder[0];
    }

    if (interruptedExceptionHolder[0] != null) {
        throw interruptedExceptionHolder[0];
    }
}