@Override
  public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog =
        new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500);
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
      dialog.run(
          true,
          true,
          new IRunnableWithProgress() {
            @Override
            public void run(final IProgressMonitor m)
                throws InvocationTargetException, InterruptedException {
              synchronized (listener) {
                listener.fProgressMonitor = m;
                listener.fProgressMonitor.beginTask(
                    DebugUIPlugin.removeAccelerators(getText()), listener.fRemainingUpdatesCount);
              }

              while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                  && !listener.fProgressMonitor.isCanceled()) {
                Thread.sleep(1);
              }
              synchronized (listener) {
                listener.fProgressMonitor = null;
              }
            }
          });
    } catch (InvocationTargetException e) {
      DebugUIPlugin.log(e);
      return;
    } catch (InterruptedException e) {
      return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
      List<VirtualItem> list = new ArrayList<VirtualItem>();
      collectAllChildren(root, list);
      FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
      VirtualItem result = performFind(list, labelProvider);
      if (result != null) {
        setSelectionToClient(virtualViewer, labelProvider, result);
      }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
  }
  /** Executes the Action */
  public void run() {
    try {
      final ProgressMonitorDialog dialog =
          new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
      dialog.setCancelable(true);

      dialog.run(
          false,
          false,
          new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              final TreeItem[] items = getViewer().getTree().getItems();
              final int unitCount = calculateWorkUnits(items);
              monitor.beginTask(getString(StringKeys.MONITOR_CALC_STATS_TASK), unitCount);
              for (TreeItem item : items) {
                if (monitor.isCanceled()) {
                  break;
                }
                if (item.getData() instanceof PackageRecord) {
                  final PackageRecord record = (PackageRecord) item.getData();
                  final AbstractPMDRecord[] children = record.getChildren();
                  monitor.subTask(
                      getString(StringKeys.MONITOR_CALC_STATS_OF_PACKAGE)
                          + ": "
                          + record.getName());
                  for (AbstractPMDRecord kid : children) {
                    if (kid instanceof FileRecord) {
                      calculateFileRecord((FileRecord) kid);
                      monitor.worked(1);
                    }
                  }
                } else if (item.getData() instanceof FileRecord) {
                  calculateFileRecord((FileRecord) item.getData());
                  monitor.worked(1);
                }
              }

              getViewer().refresh(true);
            }
          });
    } catch (InvocationTargetException e) {
      logErrorByKey(StringKeys.ERROR_INVOCATIONTARGET_EXCEPTION, e);
    } catch (InterruptedException e) {
      logErrorByKey(StringKeys.ERROR_INTERRUPTED_EXCEPTION, e);
    }
  }
示例#3
0
 private void connectWithProgress(final MonitorServer server) {
   ProgressMonitorDialog progress = new ProgressMonitorDialog(null);
   progress.setCancelable(true);
   try {
     progress.run(
         true,
         true,
         new IRunnableWithProgress() {
           public void run(IProgressMonitor monitor) throws InvocationTargetException {
             try {
               server.connectAndLogin(monitor);
             } catch (Exception e) {
               e.printStackTrace();
             }
           }
         });
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
  public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
      String name = event.getCommand().getName();
      Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

      if (!MessageDialog.openConfirm(
          shell,
          Messages.JavaBeansGeneratorAction_MSG_DIALOG_MESSAGE,
          name + Messages.JavaBeansGeneratorAction_MSG_DIALOG_DESC)) {
        return null;
      }

      /* 実行中のダイアログ表示 */
      ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
      dialog.setCancelable(true);

      IWorkbenchPartSite site = HandlerUtil.getActivePartChecked(event).getSite();
      ISelection selection = HandlerUtil.getCurrentSelection(event);
      IStructuredSelection ss = null;
      if (selection instanceof IStructuredSelection) {
        ss = (IStructuredSelection) selection;
      }

      try {
        logger.debug("execute"); // $NON-NLS-1$
        String id = event.getCommand().getId();
        JavaBeansCreatorWithProgress progress = new JavaBeansCreatorWithProgress(ss, site, id);
        dialog.run(true, true, progress);
      } catch (InvocationTargetException e) {
        Activator.logException(e);
      } catch (InterruptedException e) {
        Activator.logException(e, false);
      }
    } catch (NotDefinedException e) {
      Activator.logException(e);
    }
    return null;
  }