Search in sources :

Example 31 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class AbstractOutlineButton method execInitField.

/**
 * Initializes this outline button.
 * <p>
 * This implementation does the following:
 * <ul>
 * <li>find an instance of {@code IOutline} on the desktop consistent with the configured outline of this button, this
 * becomes the associated outline instance for this button
 * <li>the label for this button is taken from the outline
 * <li>a property change listener is registered with the outline such that this button can react on dynamic changes of
 * its associated outline (label, icon, visible, enabled etc.)
 * </ul>
 *
 * @throws ProcessingException
 *           if initialization fails
 */
@Override
protected void execInitField() {
    final IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
    for (IOutline o : desktop.getAvailableOutlines()) {
        if (o.getClass() == getConfiguredOutline()) {
            m_outline = o;
            break;
        }
    }
    if (m_outline != null) {
        setVisible(m_outline.isVisible());
        setEnabled(m_outline.isEnabled(), true, false);
        setLabel(m_outline.getTitle());
        setTooltipText(m_outline.getTitle());
        setSelected(desktop.getOutline() == m_outline);
        // add selection listener
        desktop.addDesktopListener(new DesktopListener() {

            @Override
            public void desktopChanged(DesktopEvent e) {
                switch(e.getType()) {
                    case DesktopEvent.TYPE_OUTLINE_CHANGED:
                        {
                            setSelected(e.getOutline() == m_outline);
                            break;
                        }
                }
            }
        });
        // add change listener
        m_outline.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                String n = e.getPropertyName();
                Object v = e.getNewValue();
                if (n.equals(IOutline.PROP_VISIBLE)) {
                    setVisible((Boolean) v);
                } else if (n.equals(IOutline.PROP_ENABLED)) {
                    setEnabled((Boolean) v, true, false);
                } else if (n.equals(IOutline.PROP_TITLE)) {
                    setLabel((String) v);
                } else if (n.equals(IOutline.PROP_DEFAULT_ICON_ID)) {
                    setIconId((String) v);
                }
            }
        });
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DesktopListener(org.eclipse.scout.rt.client.ui.desktop.DesktopListener) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) DesktopEvent(org.eclipse.scout.rt.client.ui.desktop.DesktopEvent)

Example 32 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class AbstractOutlineTreeField method execInitField.

@Override
protected void execInitField() {
    m_desktopListener = new DesktopListener() {

        @Override
        public void desktopChanged(DesktopEvent e) {
            switch(e.getType()) {
                case DesktopEvent.TYPE_OUTLINE_CHANGED:
                    {
                        installOutline(e.getOutline());
                        break;
                    }
            }
        }
    };
    m_treePropertyListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals(ITree.PROP_TITLE)) {
                setLabel((String) e.getNewValue());
            }
        }
    };
    // 
    IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
    desktop.addDesktopListener(m_desktopListener);
    installOutline(desktop.getOutline());
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DesktopListener(org.eclipse.scout.rt.client.ui.desktop.DesktopListener) DesktopEvent(org.eclipse.scout.rt.client.ui.desktop.DesktopEvent) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 33 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class ClientSessionProviderWithCache method afterStartSession.

@Override
protected void afterStartSession(IClientSession clientSession) {
    final IDesktop desktop = clientSession.getDesktop();
    if (desktop != null) {
        desktop.getUIFacade().openFromUI();
        desktop.getUIFacade().fireGuiAttached();
    }
}
Also used : IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 34 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class ClientRunContextTest method testRunContextsCopyCurrent.

@Test
public void testRunContextsCopyCurrent() {
    final IClientSession session = mock(IClientSession.class);
    final UserAgent sessionUserAgent = UserAgents.create().build();
    final Locale sessionLocale = Locale.CANADA_FRENCH;
    final Subject sessionSubject = new Subject();
    final IDesktop sessionDesktop = mock(IDesktop.class);
    when(session.getUserAgent()).thenReturn(sessionUserAgent);
    when(session.getLocale()).thenReturn(sessionLocale);
    when(session.getSubject()).thenReturn(sessionSubject);
    when(session.getDesktopElseVirtualDesktop()).thenReturn(sessionDesktop);
    ClientRunContexts.empty().withSession(session, true).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            RunContext runContext = RunContexts.copyCurrent();
            assertThat(runContext, CoreMatchers.instanceOf(ClientRunContext.class));
            ClientRunContext clientCtx = (ClientRunContext) runContext;
            assertSame(session, clientCtx.getSession());
            assertSame(sessionLocale, clientCtx.getLocale());
            assertSame(sessionUserAgent, clientCtx.getUserAgent());
            assertSame(sessionDesktop, clientCtx.getDesktop());
        }
    });
}
Also used : NlsLocale(org.eclipse.scout.rt.platform.nls.NlsLocale) Locale(java.util.Locale) UserAgent(org.eclipse.scout.rt.shared.ui.UserAgent) IClientSession(org.eclipse.scout.rt.client.IClientSession) RunContext(org.eclipse.scout.rt.platform.context.RunContext) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Subject(javax.security.auth.Subject) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 35 with IDesktop

use of org.eclipse.scout.rt.client.ui.desktop.IDesktop in project scout.rt by eclipse.

the class ClientRunContextTest method testCurrentSessionAndDerivedValues.

@Test
public void testCurrentSessionAndDerivedValues() {
    final IClientSession session = mock(IClientSession.class);
    final UserAgent sessionUserAgent = UserAgents.create().build();
    final Locale sessionLocale = Locale.CANADA_FRENCH;
    final Subject sessionSubject = new Subject();
    final IDesktop sessionDesktop = mock(IDesktop.class);
    when(session.getUserAgent()).thenReturn(sessionUserAgent);
    when(session.getLocale()).thenReturn(sessionLocale);
    when(session.getSubject()).thenReturn(sessionSubject);
    when(session.getDesktopElseVirtualDesktop()).thenReturn(sessionDesktop);
    ClientRunContexts.empty().withSession(null, false).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertNull(ISession.CURRENT.get());
            assertNull(NlsLocale.CURRENT.get());
            assertNull(UserAgent.CURRENT.get());
            assertNull(IDesktop.CURRENT.get());
            assertNull(ClientRunContexts.copyCurrent().getSession());
            assertNull(ClientRunContexts.copyCurrent().getLocale());
            assertNull(ClientRunContexts.copyCurrent().getUserAgent());
            assertNull(ClientRunContexts.copyCurrent().getDesktop());
        }
    });
    ClientRunContexts.empty().withSession(session, false).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertSame(session, ISession.CURRENT.get());
            assertNull(NlsLocale.CURRENT.get());
            assertNull(UserAgent.CURRENT.get());
            assertNull(IDesktop.CURRENT.get());
            assertSame(session, ClientRunContexts.copyCurrent().getSession());
            assertNull(ClientRunContexts.copyCurrent().getLocale());
            assertNull(ClientRunContexts.copyCurrent().getUserAgent());
            assertNull(ClientRunContexts.copyCurrent().getDesktop());
            final UserAgent customUserAgent = UserAgents.create().build();
            assertSame(customUserAgent, ClientRunContexts.copyCurrent().withUserAgent(customUserAgent).getUserAgent());
            final Locale customLocale = Locale.ITALIAN;
            assertSame(customLocale, ClientRunContexts.copyCurrent().withLocale(customLocale).getLocale());
        }
    });
    ClientRunContexts.empty().withSession(session, true).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertSame(session, ISession.CURRENT.get());
            assertSame(sessionLocale, NlsLocale.CURRENT.get());
            assertSame(sessionUserAgent, UserAgent.CURRENT.get());
            assertSame(sessionDesktop, IDesktop.CURRENT.get());
            assertSame(session, ClientRunContexts.copyCurrent().getSession());
            assertSame(sessionLocale, ClientRunContexts.copyCurrent().getLocale());
            assertSame(sessionUserAgent, ClientRunContexts.copyCurrent().getUserAgent());
            assertSame(sessionDesktop, ClientRunContexts.copyCurrent().getDesktop());
            final UserAgent customUserAgent = UserAgents.create().build();
            assertSame(customUserAgent, ClientRunContexts.copyCurrent().withUserAgent(customUserAgent).getUserAgent());
            final Locale customLocale = Locale.ITALIAN;
            assertSame(customLocale, ClientRunContexts.copyCurrent().withLocale(customLocale).getLocale());
            final IDesktop customDesktop = mock(IDesktop.class);
            assertSame(customDesktop, ClientRunContexts.copyCurrent().withDesktop(customDesktop).getDesktop());
        }
    });
}
Also used : NlsLocale(org.eclipse.scout.rt.platform.nls.NlsLocale) Locale(java.util.Locale) UserAgent(org.eclipse.scout.rt.shared.ui.UserAgent) IClientSession(org.eclipse.scout.rt.client.IClientSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Subject(javax.security.auth.Subject) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

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