/**
   * Restores the modules. Is called when the user changed something in the editor and applies the
   * change.
   *
   * <p>Gathers all the info and calls the hook that really restores things within a thread, so that
   * the user can get information on the progress.
   *
   * <p>Only the information on the default interpreter is stored.
   *
   * @param editorChanged whether the editor was changed (if it wasn't, we'll ask the user what to
   *     restore).
   * @return true if the info was restored and false otherwise.
   */
  protected void restoreInterpreterInfos(boolean editorChanged) {
    final Set<String> interpreterNamesToRestore =
        pathEditor.getInterpreterExeOrJarToRestoreAndClear();
    final IInterpreterInfo[] exesList = pathEditor.getExesList();

    if (!editorChanged && interpreterNamesToRestore.size() == 0) {
      IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      SelectionDialog listDialog =
          createChooseIntepreterInfoDialog(
              workbenchWindow, exesList, "Select interpreters to be restored", true);

      int open = listDialog.open();
      if (open != ListDialog.OK) {
        return;
      }
      Object[] result = (Object[]) listDialog.getResult();
      if (result == null || result.length == 0) {
        return;
      }
      for (Object o : result) {
        interpreterNamesToRestore.add(((IInterpreterInfo) o).getExecutableOrJar());
      }
    }

    // this is the default interpreter
    ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(this.getShell());
    monitorDialog.setBlockOnOpen(false);

    try {
      IRunnableWithProgress operation =
          new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN);
              try {
                // clear all but the ones that appear
                getInterpreterManager().setInfos(exesList, interpreterNamesToRestore, monitor);
              } finally {
                monitor.done();
              }
            }
          };

      monitorDialog.run(true, true, operation);

    } catch (Exception e) {
      Log.log(e);
    }
  }
 public static boolean waitForServerToChangeState(
     IServer server, Shell shell, int changeStateFrom, int changeStateTo, String msg) {
   ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
   CarbonServerStateChange serverStateChange =
       new CarbonServerStateChange(server, changeStateFrom, changeStateTo, 180000, msg);
   progressMonitorDialog.setBlockOnOpen(false);
   try {
     progressMonitorDialog.run(true, true, serverStateChange);
     return progressMonitorDialog.getReturnCode() != ProgressMonitorDialog.CANCEL;
   } catch (InvocationTargetException e) {
     log.error(e);
   } catch (InterruptedException e) {
     log.error(e);
   }
   return false;
 }
Esempio n. 3
0
  @Override
  public void run(IAction action) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

    dialog.setText("Select text file...");
    String sourceFile = dialog.open();
    if (sourceFile == null) return;
    ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
    try {
      List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
      pd.setBlockOnOpen(false);
      pd.open();
      pd.getProgressMonitor().beginTask("Generating cloud...", 200);
      TagCloudViewer viewer = getViewer();
      viewer.setInput(types, pd.getProgressMonitor());
      long start = System.currentTimeMillis();
      viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
      long end = System.currentTimeMillis();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      pd.close();
    }
  }
Esempio n. 4
0
  public synchronized void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
      final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
      if (!selection.isEmpty()) {
        if (selection.getFirstElement() instanceof ICaller) {

          ProgressMonitorDialog pmd =
              new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
          try {
            IRunnableWithProgress r =
                new IRunnableWithProgress() {
                  public void run(IProgressMonitor progressMonitor) {
                    progressMonitor.beginTask(
                        getI18nManager()
                            .getString(getNamespace(), "identifyprogress", "label", getLanguage()),
                        IProgressMonitor.UNKNOWN);

                    progressMonitor.worked(1);

                    final ICaller caller = (ICaller) selection.getFirstElement();

                    List phones = new ArrayList();
                    if (caller instanceof IMultiPhoneCaller) {
                      phones.addAll(((IMultiPhoneCaller) caller).getPhonenumbers());
                    } else {
                      phones.add(caller.getPhoneNumber());
                    }

                    String ignoreCM = "";
                    IAttribute att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                    if (att != null) {
                      ignoreCM = att.getValue();
                    }

                    List activeCMs = getAllActiveCallerManagers(getRuntime(), ignoreCM);

                    ICaller identifiedCaller = null;
                    // identification only makes sence if there are active CMs or if there are
                    // numbers
                    if (activeCMs.size() > 0 && phones.size() > 0) {
                      IPhonenumber pn = null;
                      for (int i = 0; i < phones.size(); i++) {
                        pn = (IPhonenumber) phones.get(i);
                        identifiedCaller = Identifier.identify(getRuntime(), pn, activeCMs);
                        if (identifiedCaller != null) break;
                      }
                    }
                    progressMonitor.done();

                    if (identifiedCaller == null) {
                      progressMonitor.beginTask(
                          getI18nManager()
                              .getString(getNamespace(), "failedidentify", "label", getLanguage()),
                          IProgressMonitor.UNKNOWN);

                      PropagationFactory.getInstance()
                          .fire(
                              new Message(
                                  Message.INFO,
                                  getNamespace(),
                                  "failedidentify",
                                  new Exception(
                                      "Caller with number "
                                          + caller.getPhoneNumber()
                                          + " not identified...")));
                      return;
                    }

                    // remove repository flag and set all numbers
                    if (!(identifiedCaller instanceof IMultiPhoneCaller)) {
                      identifiedCaller =
                          getRuntime().getCallerFactory().toMultiPhoneCaller(identifiedCaller);
                    }
                    ((IMultiPhoneCaller) identifiedCaller).setPhonenumbers(phones);
                    ((IMultiPhoneCaller) identifiedCaller)
                        .setPhoneNumber((IPhonenumber) phones.get(0));

                    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                    m.addAll(caller.getAttributes());
                    m.addAll(identifiedCaller.getAttributes());
                    m.remove(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                    identifiedCaller.setAttributes(m);

                    final ICaller theIdentifiedCaller = identifiedCaller;
                    new SWTExecuter() {

                      protected void execute() {
                        if (MessageDialog.openConfirm(
                            new Shell(DisplayManager.getDefaultDisplay()),
                            getI18nManager()
                                .getString(getNamespace(), "identify", "label", getLanguage()),
                            getI18nManager()
                                .getString(
                                    getNamespace(), "identify", "description", getLanguage()))) {

                          ICaller newCaller = openCallerWizard(theIdentifiedCaller);
                          if (newCaller != null) {
                            ICallerList list = getRuntime().getCallerFactory().createCallerList(1);
                            list.add(caller);
                            m_app.getController().deleteElements(list);

                            list.clear();
                            list.add(newCaller);

                            m_app.getController().addElements(list);
                            m_app.updateViews(true);
                          }
                        }
                      }
                    }.start();
                  }
                };
            pmd.setBlockOnOpen(false);
            pmd.run(true, false, r);

            // ModalContext.run(r, true, pmd.getProgressMonitor(),
            // DisplayManager.getDefaultDisplay());
          } catch (InterruptedException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
          } catch (InvocationTargetException e) {
            m_logger.log(Level.SEVERE, e.getMessage(), e);
          }
        }
      }
    }
  }