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); } }
void onResourceUpdated(@Observes ResourceUpdatedEvent res) { if (lockTarget != null && res.getPath().equals(lockTarget.getPath())) { if (!res.getSessionInfo().getIdentity().equals(user)) { reload(); } releaseLock(); } }
private boolean isVisible() { Element element = lockTarget.getWidget().getElement(); boolean visible = UIObject.isVisible(element) && (element.getAbsoluteLeft() != 0) && (element.getAbsoluteTop() != 0); return visible; }
@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); } } }); }
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(); } }
@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); }
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); } }
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 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(); } }
private void reload() { lockTarget.getReloadRunnable().run(); }