@Override
 protected void addJUnitInterval(WatchDogEvent event) {
   JUnitInterval junitInterval = (JUnitInterval) event.getSource();
   intervalManager.addInterval(junitInterval);
 }
Beispiel #2
0
  /**
   * Introduces the supplied editorEvent, and sets the forcedDate to the interval that is being
   * created or closed.
   */
  public void update(WatchDogEvent event, Date forcedDate) {
    IntervalBase interval;
    switch (event.getType()) {
      case START_IDE:
        intervalManager.addInterval(new IDEOpenInterval(forcedDate));
        userInactivityNotifier.trigger(forcedDate);
        break;

      case END_IDE:
        userInactivityNotifier.cancelTimer(forcedDate);
        break;

      case ACTIVE_WINDOW:
        interval = intervalManager.getInterval(IDEActiveInterval.class);
        if (isClosed(interval)) {
          intervalManager.addInterval(new IDEActiveInterval(forcedDate));
        }
        userInactivityNotifier.trigger(forcedDate);
        break;

      case INACTIVE_WINDOW:
        interval = intervalManager.getInterval(IDEActiveInterval.class);
        intervalManager.closeInterval(interval, forcedDate);
        break;

      case START_PERSPECTIVE:
        Perspective perspecitve = (Perspective) event.getSource();
        createNewPerspectiveInterval(perspecitve, forcedDate);
        userInactivityNotifier.trigger(forcedDate);
        break;

      case JUNIT:
        JUnitInterval junitInterval = (JUnitInterval) event.getSource();
        intervalManager.addInterval(junitInterval);
        break;

      case USER_ACTIVITY:
        interval = intervalManager.getInterval(UserActiveInterval.class);
        if (isClosed(interval)) {
          intervalManager.addInterval(new UserActiveInterval(forcedDate));
        }
        userInactivityNotifier.trigger();
        break;

      case START_EDIT:
        EditorIntervalBase editorInterval = intervalManager.getEditorInterval();
        ITextEditor editor = (ITextEditor) event.getSource();

        readingInactivityNotifier.cancelTimer(forcedDate);
        if (intervalIsOfType(editorInterval, IntervalType.TYPING)
            && ((EditorWrapper) editorInterval.getEditorWrapper()).getEditor() == editor) {
          return;
        }

        intervalManager.closeInterval(editorInterval, forcedDate);

        TypingInterval typingInterval = new TypingInterval(new EditorWrapper(editor), forcedDate);
        Document document = null;
        if (editorInterval != null
            && ((EditorWrapper) editorInterval.getEditorWrapper()).getEditor() == editor) {
          document = editorInterval.getDocument();
        } else {
          document = DocumentCreator.createDocument(editor);
        }
        typingInterval.setDocument(document);
        intervalManager.addInterval(typingInterval);

        typingInactivityNotifier.trigger();
        userInactivityNotifier.trigger(forcedDate);
        break;

      case SUBSEQUENT_EDIT:
        editorInterval = intervalManager.getEditorInterval();
        editor = (ITextEditor) event.getSource();

        if (isClosed(editorInterval)
            || !intervalIsOfType(editorInterval, IntervalType.TYPING)
            || isDifferentEditor(editorInterval, editor)) {
          update(new WatchDogEvent(event.getSource(), EventType.START_EDIT));
          break;
        }

        typingInactivityNotifier.trigger();
        userInactivityNotifier.trigger(forcedDate);
        break;

      case PAINT:
      case CARET_MOVED:
      case ACTIVE_FOCUS:
        editorInterval = intervalManager.getEditorInterval();
        editor = (ITextEditor) event.getSource();
        if (needToCreateNewReadingInterval(editorInterval, editor)) {
          if (!isClosed(editorInterval)) {
            intervalManager.closeInterval(editorInterval, forcedDate);
          }

          ReadingInterval readingInterval =
              new ReadingInterval(new EditorWrapper(editor), forcedDate);
          readingInterval.setDocument(DocumentCreator.createDocument(editor));
          intervalManager.addInterval(readingInterval);
        }

        readingInactivityNotifier.trigger();
        userInactivityNotifier.trigger(forcedDate);
        break;

      case INACTIVE_FOCUS:
        editorInterval = intervalManager.getEditorInterval();
        intervalManager.closeInterval(editorInterval, forcedDate);
        readingInactivityNotifier.cancelTimer(forcedDate);
        typingInactivityNotifier.cancelTimer(forcedDate);
        break;

      case USER_INACTIVITY:
        interval = intervalManager.getInterval(UserActiveInterval.class);
        intervalManager.closeInterval(interval, forcedDate);
        typingInactivityNotifier.cancelTimer(forcedDate);
        readingInactivityNotifier.cancelTimer(forcedDate);
        break;

      case TYPING_INACTIVITY:
        editorInterval = intervalManager.getEditorInterval();
        if (intervalIsOfType(editorInterval, IntervalType.TYPING)) {
          intervalManager.closeInterval(editorInterval, forcedDate);
        }
        break;

      case READING_INACTIVITY:
        editorInterval = intervalManager.getEditorInterval();
        if (intervalIsOfType(editorInterval, IntervalType.READING)) {
          intervalManager.closeInterval(editorInterval, forcedDate);
        }
        break;

      case START_WATCHDOGVIEW:
        interval = intervalManager.getInterval(WatchDogViewInterval.class);
        if (!intervalIsOfType(interval, IntervalType.WATCHDOGVIEW)) {
          intervalManager.addInterval(new WatchDogViewInterval(forcedDate));
        }
        userInactivityNotifier.trigger(forcedDate);
        break;

      case END_WATCHDOGVIEW:
        interval = intervalManager.getInterval(WatchDogViewInterval.class);
        if (intervalIsOfType(interval, IntervalType.WATCHDOGVIEW)) {
          intervalManager.closeInterval(interval, forcedDate);
        }
        break;

      default:
        break;
    }
  }