@Override public void onFocus() { publishJsApi(); fireChangeTitleEvent(); fireUpdatedLockStatusEvent(); }
@Override public void fireChangeTitleEvent() { final Path path = getLockInfo().getFile(); if (path == null) { return; } presenter.getActiveDecisionTable().ifPresent(dtPresenter -> { final ObservablePath dtPath = dtPresenter.getCurrentPath(); if (dtPath == null) { return; } if (path.equals(dtPath)) { super.fireChangeTitleEvent(); } }); } }
@Override public void fireChangeTitleEvent() { final Path path = getLockInfo().getFile(); if (path == null) { return; } presenter.getActiveDecisionTable().ifPresent(dtPresenter -> { final ObservablePath dtPath = dtPresenter.getCurrentPath(); if (dtPath == null) { return; } if (path.equals(dtPath)) { super.fireChangeTitleEvent(); } }); } }
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(); } }
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).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); } }