Ejemplo n.º 1
0
  private void startScolling() {

    mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity);
    int velocity = (int) mVelocityTracker.getYVelocity();

    if (!mScroller.isFinished()) {
      mScroller.forceFinished(true);
    }

    int progress = mProgressManager.getCurrentHeight();
    int end;
    if (Math.abs(velocity) > mMinFlingVelocity) {

      if (velocity > 0) {
        end = mProgressManager.getEndSize() - progress;
      } else {
        end = -progress;
      }

    } else {

      int endSize = mProgressManager.getEndSize();
      if (endSize / 2 <= progress) {
        end = endSize - progress;
      } else {
        end = -progress;
      }
    }

    mScroller.startScroll(0, progress, 0, end);
    mCalendarView.postInvalidate();

    mState = State.SETTLING;
  }
Ejemplo n.º 2
0
 public void onDraw() {
   if (!mScroller.isFinished()) {
     mScroller.computeScrollOffset();
     float position = mScroller.getCurrY() * 1f / mProgressManager.getEndSize();
     mProgressManager.apply(position);
     mCalendarView.postInvalidate();
   } else if (mState == State.SETTLING) {
     mState = State.IDLE;
     float position = mScroller.getCurrY() * 1f / mProgressManager.getEndSize();
     mProgressManager.finish(position > 0);
     mProgressManager = null;
   }
 }
Ejemplo n.º 3
0
  private FinishedJobs() {
    listener =
        new IJobProgressManagerListener() {
          public void addJob(JobInfo info) {
            checkForDuplicates(info);
          }

          public void addGroup(GroupInfo info) {
            checkForDuplicates(info);
          }

          public void refreshJobInfo(JobInfo info) {
            checkTasks(info);
          }

          public void refreshGroup(GroupInfo info) {}

          public void refreshAll() {}

          public void removeJob(JobInfo info) {
            if (keep(info)) {
              checkForDuplicates(info);
              add(info);
            }
          }

          public void removeGroup(GroupInfo group) {}

          public boolean showsDebug() {
            return false;
          }
        };
    ProgressManager.getInstance().addListener(listener);
  }
 /** Create a new instance of the receiver. */
 private ProgressViewUpdater() {
   createUpdateJob();
   collectors = new IProgressUpdateCollector[0];
   ProgressManager.getInstance().addListener(this);
   debug =
       PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS);
 }
Ejemplo n.º 5
0
  public boolean onTouchEvent(@NonNull MotionEvent event) {
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_MOVE) {
      mVelocityTracker.addMovement(event);
    }
    if (mState == State.DRAGGING) {
      switch (action) {
        case MotionEvent.ACTION_MOVE:
          int deltaY = calculateDistanceForDrag(event);
          mProgressManager.applyDelta(deltaY);
          break;
        case MotionEvent.ACTION_UP:
          finishMotionEvent();
          if (type == LEFT) {
            mCalendarView.prev();
          } else if (type == RIGHT) {
            mCalendarView.next();
          }
          break;
      }

    } else if (action == MotionEvent.ACTION_MOVE) {
      checkForResizing(event);
    } else if (action == MotionEvent.ACTION_UP) {
      if (type == LEFT) {
        mCalendarView.prev();
      } else if (type == RIGHT) {
        mCalendarView.next();
      }
    }

    return true;
  }
Ejemplo n.º 6
0
 private void finishMotionEvent() {
   if (mProgressManager != null) {
     if (mProgressManager.isInitialized()) {
       startScolling();
     }
   }
 }
Ejemplo n.º 7
0
  public void doRollback(
      final Collection<Change> changes,
      final boolean deleteLocallyAddedFiles,
      @Nullable final Runnable afterVcsRefreshInAwt,
      @Nullable final String localHistoryActionName) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    final Runnable notifier = changeListManager.prepareForChangeDeletion(changes);
    final Runnable afterRefresh =
        new Runnable() {
          public void run() {
            changeListManager.invokeAfterUpdate(
                new Runnable() {
                  public void run() {
                    notifier.run();
                    if (afterVcsRefreshInAwt != null) {
                      afterVcsRefreshInAwt.run();
                    }
                  }
                },
                InvokeAfterUpdateMode.SILENT,
                "Refresh change lists after update",
                ModalityState.current());
          }
        };

    final Runnable rollbackAction =
        new MyRollbackRunnable(
            changes, deleteLocallyAddedFiles, afterRefresh, localHistoryActionName);

    if (ApplicationManager.getApplication().isDispatchThread()) {
      ProgressManager.getInstance()
          .run(
              new Task.Backgroundable(
                  myProject,
                  VcsBundle.message("changes.action.rollback.text"),
                  true,
                  new PerformInBackgroundOption() {
                    public boolean shouldStartInBackground() {
                      return VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND;
                    }

                    public void processSentToBackground() {
                      VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND = true;
                    }
                  }) {
                public void run(@NotNull ProgressIndicator indicator) {
                  rollbackAction.run();
                }
              });
    } else {
      rollbackAction.run();
    }
    ((ChangeListManagerImpl) changeListManager).showLocalChangesInvalidated();
  }
 public void startSearch() {
   if (ApplicationManager.getApplication().isUnitTestMode()) {
     try {
       search();
       onFound();
     } catch (Throwable e) {
       LOG.error(e);
     }
   } else {
     myProcessIndicator = new BackgroundableProcessIndicator(this);
     ProgressManager.getInstance().runProcessWithProgressAsynchronously(this, myProcessIndicator);
   }
 }
Ejemplo n.º 9
0
    private void doRun() {
      myIndicator = ProgressManager.getInstance().getProgressIndicator();

      final List<Change> changesToRefresh = new ArrayList<Change>();
      try {
        ChangesUtil.processChangesByVcs(
            myProject,
            myChanges,
            new ChangesUtil.PerVcsProcessor<Change>() {
              public void process(AbstractVcs vcs, List<Change> changes) {
                final RollbackEnvironment environment = vcs.getRollbackEnvironment();
                if (environment != null) {
                  changesToRefresh.addAll(changes);

                  if (myIndicator != null) {
                    myIndicator.setText(vcs.getDisplayName() + ": performing rollback...");
                    myIndicator.setIndeterminate(false);
                    myIndicator.checkCanceled();
                  }
                  environment.rollbackChanges(
                      changes,
                      myExceptions,
                      new RollbackProgressModifier(changes.size(), myIndicator));
                  if (myIndicator != null) {
                    myIndicator.setText2("");
                    myIndicator.checkCanceled();
                  }

                  if (myExceptions.isEmpty() && myDeleteLocallyAddedFiles) {
                    deleteAddedFilesLocally(changes);
                  }
                }
              }
            });
      } catch (ProcessCanceledException e) {
        // still do refresh
      }

      if (myIndicator != null) {
        myIndicator.startNonCancelableSection();
        myIndicator.setIndeterminate(true);
        myIndicator.setText2("");
        myIndicator.setText(VcsBundle.message("progress.text.synchronizing.files"));
      }

      doRefresh(myProject, changesToRefresh);

      AbstractVcsHelper.getInstance(myProject)
          .showErrors(myExceptions, VcsBundle.message("changes.action.rollback.text"));
    }
  private void startBackgroundProcess(
      @NotNull final DumbModeTask task, @NotNull final ProgressIndicatorEx indicator) {
    ProgressManager.getInstance()
        .run(
            new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) {

              @Override
              public void run(@NotNull final ProgressIndicator visibleIndicator) {
                if (ApplicationManager.getApplication().isInternal())
                  LOG.info("Running dumb mode task: " + task);

                final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
                final Thread self = Thread.currentThread();
                try {
                  HeavyProcessLatch.INSTANCE.processStarted();
                  shutdownTracker.registerStopperThread(self);

                  indicator.checkCanceled();

                  if (visibleIndicator instanceof ProgressIndicatorEx) {
                    indicator.addStateDelegate((ProgressIndicatorEx) visibleIndicator);
                    ((ProgressIndicatorEx) visibleIndicator)
                        .addStateDelegate(new AppIconProgress());
                  }

                  indicator.setIndeterminate(true);
                  indicator.setText(IdeBundle.message("progress.indexing.scanning"));

                  task.performInDumbMode(indicator);
                } catch (ProcessCanceledException ignored) {
                } catch (Throwable unexpected) {
                  LOG.error(unexpected);
                } finally {
                  shutdownTracker.unregisterStopperThread(self);
                  HeavyProcessLatch.INSTANCE.processFinished();
                  taskFinished(task);
                }
              }
            });
  }
  private void scheduleCacheUpdate(@NotNull final DumbModeTask task, boolean forceDumbMode) {
    if (ApplicationManager.getApplication().isInternal()) LOG.info("schedule " + task);
    final Application application = ApplicationManager.getApplication();

    if (application.isUnitTestMode()
        || application.isHeadlessEnvironment()
        || !forceDumbMode && !myDumb && application.isReadAccessAllowed()) {
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      if (indicator != null) {
        indicator.pushState();
      }
      try {
        HeavyProcessLatch.INSTANCE.processStarted();
        task.performInDumbMode(indicator != null ? indicator : new EmptyProgressIndicator());
      } finally {
        HeavyProcessLatch.INSTANCE.processFinished();
        if (indicator != null) {
          indicator.popState();
        }
        Disposer.dispose(task);
      }
      return;
    }

    UIUtil.invokeLaterIfNeeded(
        new DumbAwareRunnable() {
          @Override
          public void run() {
            if (myProject.isDisposed()) {
              return;
            }
            final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
            myProgresses.put(task, indicator);
            Disposer.register(
                task,
                new Disposable() {
                  @Override
                  public void dispose() {
                    application.assertIsDispatchThread();
                    myProgresses.remove(task);
                  }
                });
            // ok to test and set the flag like this, because the change is always done from
            // dispatch thread
            if (!myDumb) {
              // always change dumb status inside write action.
              // This will ensure all active read actions are completed before the app goes dumb
              boolean startSuccess =
                  application.runWriteAction(
                      new Computable<Boolean>() {
                        @Override
                        public Boolean compute() {
                          myDumb = true;
                          try {
                            myPublisher.enteredDumbMode();
                          } catch (Throwable e) {
                            LOG.error(e);
                          }

                          try {
                            startBackgroundProcess(task, indicator);
                          } catch (Throwable e) {
                            LOG.error("Failed to start background index update task", e);
                            return false;
                          }
                          return true;
                        }
                      });
              if (!startSuccess) {
                updateFinished();
              }
            } else {
              myUpdatesQueue.addLast(task);
            }
          }
        });
  }
 @Override
 public final void cancel() {
   myIsCanceled = true;
   ProgressManager.canceled(this);
 }
 static void clearSingleton() {
   if (singleton != null) {
     ProgressManager.getInstance().removeListener(singleton);
   }
   singleton = null;
 }
  public void performActionSync(
      final CvsHandler handler, final CvsOperationExecutorCallback callback) {
    final CvsTabbedWindow tabbedWindow = myIsQuietOperation ? null : openTabbedWindow(handler);

    final Runnable finish =
        new Runnable() {
          @Override
          public void run() {
            try {
              myResult.addAllErrors(handler.getErrorsExceptAborted());
              handler.finish();
              if (myProject == null || myProject != null && !myProject.isDisposed()) {
                showErrors(handler, tabbedWindow);
              }
            } finally {
              try {
                if (myResult.finishedUnsuccessfully(handler)) {
                  callback.executionFinished(false);
                } else {
                  if (handler.getErrors().isEmpty()) callback.executionFinishedSuccessfully();
                  callback.executionFinished(true);
                }
              } finally {
                if (myProject != null && handler != CvsHandler.NULL) {
                  StatusBar.Info.set(getStatusMessage(handler), myProject);
                }
              }
            }
          }
        };

    final Runnable cvsAction =
        new Runnable() {
          @Override
          public void run() {
            try {
              if (handler == CvsHandler.NULL) return;
              setText(CvsBundle.message("progress.text.preparing.for.login"));

              handler.beforeLogin();

              if (myResult.finishedUnsuccessfully(handler)) return;

              setText(CvsBundle.message("progress.text.preparing.for.action", handler.getTitle()));

              handler.run(myProject, myExecutor);
              if (myResult.finishedUnsuccessfully(handler)) return;

            } catch (ProcessCanceledException ex) {
              myResult.setIsCanceled();
            } finally {
              callback.executeInProgressAfterAction(myExecutor);
            }
          }
        };

    if (doNotShowProgress()) {
      cvsAction.run();
      if (myIsQuietOperation) {
        finish.run();
      } else {
        myExecutor.runInDispatchThread(finish, myProject);
      }
    } else {
      final PerformInBackgroundOption backgroundOption = handler.getBackgroundOption(myProject);
      if (backgroundOption != null) {
        final Task.Backgroundable task =
            new Task.Backgroundable(
                myProject, handler.getTitle(), handler.canBeCanceled(), backgroundOption) {
              @Override
              public void run(@NotNull final ProgressIndicator indicator) {
                cvsAction.run();
              }

              @Override
              public void onSuccess() {
                finish.run();
              }
            };
        ProgressManager.getInstance().run(task);
      } else {
        if (ProgressManager.getInstance()
            .runProcessWithProgressSynchronously(
                cvsAction, handler.getTitle(), handler.canBeCanceled(), myProject)) {
          finish.run();
        }
      }
    }
  }
 private static boolean isInProgress() {
   return ProgressManager.getInstance().getProgressIndicator() != null;
 }
 private static void setText(String text) {
   ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
   if (progressIndicator != null) {
     progressIndicator.setText(text);
   }
 }