Esempio n. 1
0
  private void handleLockFailure(final LockInfo lockInfo) {

    if (lockInfo != null) {
      updateLockInfo(lockInfo);
      lockNotification.fire(
          new NotificationEvent(
              WorkbenchConstants.INSTANCE.lockedMessage(lockInfo.lockedBy()),
              NotificationEvent.NotificationType.INFO,
              true,
              lockTarget.getPlace(),
              20));
    } else {
      lockNotification.fire(
          new NotificationEvent(
              WorkbenchConstants.INSTANCE.lockError(),
              NotificationEvent.NotificationType.ERROR,
              true,
              lockTarget.getPlace(),
              20));
    }
    // Delay reloading slightly in case we're dealing with a flood of events
    if (reloadTimer == null) {
      reloadTimer =
          new Timer() {

            public void run() {
              reload();
            }
          };
    }

    if (!reloadTimer.isRunning()) {
      reloadTimer.schedule(250);
    }
  }
Esempio n. 2
0
 void onResourceUpdated(@Observes ResourceUpdatedEvent res) {
   if (lockTarget != null && res.getPath().equals(lockTarget.getPath())) {
     if (!res.getSessionInfo().getIdentity().equals(user)) {
       reload();
     }
     releaseLock();
   }
 }
Esempio n. 3
0
  private boolean isVisible() {
    Element element = lockTarget.getWidget().getElement();
    boolean visible =
        UIObject.isVisible(element)
            && (element.getAbsoluteLeft() != 0)
            && (element.getAbsoluteTop() != 0);

    return visible;
  }
Esempio n. 4
0
  @Override
  public void acquireLockOnDemand() {
    if (lockTarget == null) return;

    final Element element = lockTarget.getWidget().getElement();
    acquireLockOnDemand(element);

    lockTarget
        .getWidget()
        .addAttachHandler(
            new AttachEvent.Handler() {

              @Override
              public void onAttachOrDetach(AttachEvent event) {
                // Handle widget reattachment/reparenting
                if (event.isAttached()) {
                  acquireLockOnDemand(element);
                }
              }
            });
  }
Esempio n. 5
0
  private void updateLockInfo(@Observes LockInfo lockInfo) {
    if (lockTarget != null && lockInfo.getFile().equals(lockTarget.getPath())) {
      this.lockInfo = lockInfo;
      this.lockSyncComplete = true;

      fireChangeTitleEvent();
      fireUpdatedLockStatusEvent();

      for (Runnable runnable : syncCompleteRunnables) {
        runnable.run();
      }
      syncCompleteRunnables.clear();
    }
  }
Esempio n. 6
0
  @Override
  public void init(final LockTarget lockTarget) {
    this.lockTarget = lockTarget;

    final ParameterizedCommand<LockInfo> command =
        new ParameterizedCommand<LockInfo>() {

          @Override
          public void execute(final LockInfo lockInfo) {
            if (!lockRequestPending && !unlockRequestPending) {
              updateLockInfo(lockInfo);
            }
          }
        };
    lockService.retrieveLockInfo(lockTarget.getPath(), command);
  }
Esempio n. 7
0
  private void acquireLock() {
    if (lockInfo.isLocked()) {
      handleLockFailure(lockInfo);
    } else if (!lockRequestPending) {
      lockRequestPending = true;
      final ParameterizedCommand<LockResult> command =
          new ParameterizedCommand<LockResult>() {

            @Override
            public void execute(final LockResult result) {
              if (result.isSuccess()) {
                updateLockInfo(result.getLockInfo());
                releaseLockOnClose();
              } else {
                handleLockFailure(result.getLockInfo());
              }
              lockRequestPending = false;
            }
          };
      lockService.acquireLock(lockTarget.getPath(), command);
    }
  }
Esempio n. 8
0
  private void releaseLockInternal() {
    if (isLockedByCurrentUser() && !unlockRequestPending) {
      unlockRequestPending = true;

      ParameterizedCommand<LockResult> command =
          new ParameterizedCommand<LockResult>() {

            @Override
            public void execute(final LockResult result) {
              updateLockInfo(result.getLockInfo());

              if (result.isSuccess()) {
                if (closeHandler != null) {
                  closeHandler.removeHandler();
                }
              }

              unlockRequestPending = false;
            }
          };
      lockService.releaseLock(lockTarget.getPath(), command);
    }
  }
Esempio n. 9
0
 void onSaveInProgress(@Observes SaveInProgressEvent evt) {
   if (lockTarget != null && evt.getPath().equals(lockTarget.getPath())) {
     releaseLock();
   }
 }
Esempio n. 10
0
 void onResourceAdded(@Observes ResourceAddedEvent res) {
   if (lockTarget != null && res.getPath().equals(lockTarget.getPath())) {
     releaseLock();
   }
 }
Esempio n. 11
0
 private void reload() {
   lockTarget.getReloadRunnable().run();
 }