@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); }
void onSaveInProgress(@Observes SaveInProgressEvent evt) { if (lockTarget != null && evt.getPath().equals(lockTarget.getPath())) { releaseLock(); } }
void onResourceAdded(@Observes ResourceAddedEvent res) { if (lockTarget != null && res.getPath().equals(lockTarget.getPath())) { releaseLock(); } }
void onRenameInProgress(@Observes RenameInProgressEvent event) { if (getLockTarget() != null && event.getPath().equals(lockTarget.getPath())) { releaseLock(); } }
void onResourceUpdated(@Observes ResourceUpdatedEvent res) { if (lockTarget != null && res.getPath().equals(lockTarget.getPath())) { if (!res.getSessionInfo().getIdentity().equals(user)) { reload(); } releaseLock(); } }
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); } }
void updateLockInfo(final @Observes LockInfo lockInfo) { /* Comparing URIs since lockInfo.getFile() can be an ObservablePath or a PathImpl. */ if (getLockTarget() != null && lockInfo.getFile().toURI().equals(lockTarget.getPath().toURI())) { this.lockInfo = lockInfo; this.lockSyncComplete = true; fireChangeTitleEvent(); fireUpdatedLockStatusEvent(); for (Runnable runnable : getSyncCompleteRunnables()) { runnable.run(); } getSyncCompleteRunnables().clear(); } }
@Override public void acquireLock() { if (lockTarget == null) { return; } if (isLockedByCurrentUser()) { fireChangeTitleEvent(); return; } 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); } }
assertNotNull(lockTarget); assertEquals(dtGraphPath, lockTarget.getPath()); assertEquals(dtGraphPlaceRequest, lockTarget.getPlace());