use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.
the class ActionTest method testOutlineButton.
@Test
public void testOutlineButton() {
IDesktop desktopMock = Mockito.mock(IDesktop.class);
IOutline outlineMock = Mockito.mock(IOutline.class);
Mockito.when(desktopMock.getAvailableOutlines()).thenReturn(CollectionUtility.arrayList(outlineMock));
final IntegerHolder execActionHolder = new IntegerHolder(0);
final IntegerHolder execToggleHolder = new IntegerHolder(0);
AbstractOutlineViewButton b = new AbstractOutlineViewButton(desktopMock, outlineMock.getClass()) {
@Override
protected void execAction() {
execActionHolder.setValue(execActionHolder.getValue() + 1);
}
@Override
protected void execSelectionChanged(boolean selection) {
execToggleHolder.setValue(execToggleHolder.getValue() + 1);
}
};
b.getUIFacade().setSelectedFromUI(true);
b.getUIFacade().fireActionFromUI();
assertEquals(1, execActionHolder.getValue().intValue());
assertEquals(1, execToggleHolder.getValue().intValue());
assertTrue(b.isSelected());
b.getUIFacade().fireActionFromUI();
assertEquals(2, execActionHolder.getValue().intValue());
assertEquals(1, execToggleHolder.getValue().intValue());
assertTrue(b.isSelected());
b.getUIFacade().setSelectedFromUI(false);
b.getUIFacade().fireActionFromUI();
assertEquals(3, execActionHolder.getValue().intValue());
assertEquals(2, execToggleHolder.getValue().intValue());
assertFalse(b.isSelected());
}
use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.
the class AbstractContentAssistField method prepareTextLookup.
@Override
public void prepareTextLookup(ILookupCall<LOOKUP_KEY> call, String text) {
String textPattern = text;
if (textPattern == null) {
textPattern = "";
}
textPattern = textPattern.toLowerCase();
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
if (desktop != null && desktop.isAutoPrefixWildcardForTextSearch()) {
textPattern = getWildcard() + textPattern;
}
if (!textPattern.endsWith(getWildcard())) {
textPattern = textPattern + getWildcard();
}
// localLookupCalls should return hierarchical matches as well (children of exact matches), if field is configured accordingly
if (call instanceof LocalLookupCall) {
((LocalLookupCall) call).setHierarchicalLookup(isBrowseHierarchy());
}
call.setKey(null);
call.setText(textPattern);
call.setAll(null);
call.setRec(null);
call.setActive(isActiveFilterEnabled() ? getActiveFilter() : TriState.TRUE);
// when there is a master value defined in the original call, don't set it to null when no master value is available
if (getMasterValue() != null || getLookupCall() == null || getLookupCall().getMaster() == null) {
call.setMaster(getMasterValue());
}
interceptPrepareLookup(call);
interceptPrepareTextLookup(call, text);
}
use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.
the class UiSession method startDesktop.
protected void startDesktop(Map<String, String> sessionStartupParams) {
final IFuture<Void> future = ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
IDesktop desktop = m_clientSession.getDesktop();
IDesktopUIFacade uiFacade = desktop.getUIFacade();
boolean desktopOpen = desktop.isOpened();
if (!desktopOpen) {
uiFacade.openFromUI();
}
// Don't handle deep links for persistent sessions,
// in that case the client state shall be recovered rather than following the deep link
PropertyMap.CURRENT.get().put(DeepLinkUrlParameter.HANDLE_DEEP_LINK, !isPersistent() || !desktopOpen);
uiFacade.fireGuiAttached();
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent().withSession(m_clientSession, true).withProperties(// Make startup parameters available at {@link PropertyMap#CURRENT} during desktop attaching
sessionStartupParams)).withName("Starting Desktop").withExceptionHandling(null, false));
BEANS.get(UiJobs.class).awaitAndGet(future);
}
use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.
the class PasswordPolicyVerifier method verify.
/**
* Calls {@link IPasswordManagementService#getPasswordExpirationDate(String)} to check whether the password has
* expired. When desired, warns the user in advance about the expiration. If expired, calls the
* {@link DefaultPasswordForm#startChange()} and - when closed - re-checks the expiry date. When still expired, exits
* the application (scout session).
*
* @param warnInAdvanceDays
* number of days before the expiry when a warning shall occur, -1 to omit this feature
* @return true if the password is not expired, false if - after all - the password has expired. Normally when
* returned false, the application quits.
*/
public boolean verify(String userId, int warnInAdvanceDays) {
IPasswordManagementService service = BEANS.get(IPasswordManagementService.class);
if (service == null) {
LOG.error("missing client service proxy for {}. Check registered beans.", IPasswordManagementService.class.getName());
return false;
}
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
if (desktop == null) {
LOG.error("desktop is null");
return false;
}
if (!desktop.isOpened()) {
LOG.error("desktop is available, but there is not yet a GUI attached. Make sure to calll this verifier at earliest in the Desktop.execGuiAvailable callback");
return false;
}
try {
boolean changeNow = false;
Date now = new Date();
Date expiryDate = service.getPasswordExpirationDate(userId);
if (expiryDate.after(now)) {
// not expired
long remainDays = (expiryDate.getTime() - now.getTime()) / 3600000L / 24L;
if (remainDays < warnInAdvanceDays) {
String header;
if (remainDays == 0) {
header = TEXTS.get("PasswordWillExpireHeaderX", TEXTS.get("Today"));
} else if (remainDays == 1) {
header = TEXTS.get("PasswordWillExpireHeaderX", TEXTS.get("Tomorrow"));
} else {
header = TEXTS.get("PasswordWillExpireHeaderX", TEXTS.get("InDaysX", "" + remainDays));
}
int answer = MessageBoxes.createYesNoCancel().withHeader(header).withBody(TEXTS.get("PasswordWillExpireInfo")).show();
if (answer == MessageBox.YES_OPTION) {
changeNow = true;
}
}
} else {
// has expired
MessageBoxes.createOk().withHeader(TEXTS.get("PasswordHasExpiredTitle")).withBody(TEXTS.get("PasswordHasExpiredHeader")).show();
changeNow = true;
}
//
if (changeNow) {
callPasswordForm(userId);
// re-check
expiryDate = service.getPasswordExpirationDate(userId);
}
return expiryDate.after(now);
} catch (Exception t) {
BEANS.get(ExceptionHandler.class).handle(t);
return false;
}
}
use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.
the class SmallMemoryPolicy method beforeTablePageLoadData.
/**
* clear table before loading new data, thus disabling "replaceRow" mechanism but saving memory
*/
@Override
public void beforeTablePageLoadData(IPageWithTable<?> page) {
// make sure inactive outlines have no selection that "keeps" the pages
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
for (IOutline o : desktop.getAvailableOutlines()) {
if (o != desktop.getOutline()) {
o.selectNode(null);
}
}
desktop.releaseUnusedPages();
if (page.getTable() != null) {
page.getTable().discardAllRows();
}
}
Aggregations