Search in sources :

Example 6 with IDesktop

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());
}
Also used : IntegerHolder(org.eclipse.scout.rt.platform.holders.IntegerHolder) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) AbstractOutlineViewButton(org.eclipse.scout.rt.client.ui.desktop.outline.AbstractOutlineViewButton) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 7 with IDesktop

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);
}
Also used : IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) LocalLookupCall(org.eclipse.scout.rt.shared.services.lookup.LocalLookupCall)

Example 8 with IDesktop

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);
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IDesktopUIFacade(org.eclipse.scout.rt.client.ui.desktop.IDesktopUIFacade) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 9 with IDesktop

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;
    }
}
Also used : IPasswordManagementService(org.eclipse.scout.rt.shared.services.common.pwd.IPasswordManagementService) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Date(java.util.Date)

Example 10 with IDesktop

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();
    }
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Aggregations

IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)61 Test (org.junit.Test)36 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)18 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)7 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)7 IOutlineViewButton (org.eclipse.scout.rt.client.ui.desktop.outline.IOutlineViewButton)5 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)5 JsonForm (org.eclipse.scout.rt.ui.html.json.form.JsonForm)5 JSONObject (org.json.JSONObject)5 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)4 IClientSession (org.eclipse.scout.rt.client.IClientSession)3 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)3 IForm (org.eclipse.scout.rt.client.ui.form.IForm)3 DesktopWithOneOutline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline)3 OutlineViewButton (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineViewButton)3 OutlineWithOneNode (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.OutlineWithOneNode)3 FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Locale (java.util.Locale)2