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);
}
}
});
}
}
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());
}
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();
}
}
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());
}
});
}
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());
}
});
}
Aggregations