Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 166054 Details for
Bug 272803
Display#findDisplay() is missing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed implementation
Bug-272803.patch (text/plain), 5.40 KB, created by
Ivan Furnadjiev
on 2010-04-26 05:03:27 EDT
(
hide
)
Description:
Proposed implementation
Filename:
MIME Type:
Creator:
Ivan Furnadjiev
Created:
2010-04-26 05:03:27 EDT
Size:
5.40 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.rwt >Index: src/org/eclipse/swt/widgets/Display.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Display.java,v >retrieving revision 1.95 >diff -u -r1.95 Display.java >--- src/org/eclipse/swt/widgets/Display.java 23 Mar 2010 10:13:35 -0000 1.95 >+++ src/org/eclipse/swt/widgets/Display.java 26 Apr 2010 09:01:03 -0000 >@@ -13,6 +13,7 @@ > > import java.io.IOException; > import java.io.InputStream; >+import java.lang.ref.WeakReference; > import java.text.MessageFormat; > import java.util.*; > import java.util.List; >@@ -128,6 +129,8 @@ > = Display.class.getName() + "#appName"; > private static final String APP_VERSION > = Display.class.getName() + "#appVersion"; >+ private static final String DISPLAYS >+ = Display.class.getName() + "#displays"; > > > /* Package Name */ >@@ -233,6 +236,7 @@ > SWT.error( SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]" ); > } > RWTLifeCycle.setSessionDisplay( this ); >+ register( this); > shells = new ArrayList(); > readInitialBounds(); > readScrollBarSize(); >@@ -690,6 +694,10 @@ > // TODO [rh] zero fields > } > >+ protected void destroy () { >+ deregister( this ); >+ } >+ > private void sendDisposeEvent() { > Event event = new Event(); > event.display = this; >@@ -1880,6 +1888,93 @@ > session.setAttribute( APP_VERSION, version ); > } > >+ /** >+ * Returns the display which the given thread is the >+ * user-interface thread for, or null if the given thread >+ * is not a user-interface thread for any display. Specifying >+ * <code>null</code> as the thread will return <code>null</code> >+ * for the display. >+ * >+ * @param thread the user-interface thread >+ * @return the display for the given thread >+ * >+ * @since 1.3 >+ */ >+ public static Display findDisplay( final Thread thread ) { >+ synchronized( Device.class ) { >+ Display result = null; >+ ISessionStore session = ContextProvider.getSession(); >+ WeakReference[] displaysRef >+ = ( WeakReference[] )session.getAttribute( DISPLAYS ); >+ if( displaysRef != null ) { >+ for( int i = 0; i < displaysRef.length && result == null; i++ ) { >+ WeakReference currentRef = displaysRef[ i ]; >+ if( currentRef != null ) { >+ Display display = ( Display )currentRef.get(); >+ if( display != null && display.thread == thread ) { >+ result = display; >+ } >+ } >+ } >+ } >+ return result; >+ } >+ } >+ >+ private static void register( final Display display ) { >+ synchronized( Device.class ) { >+ ISessionStore session = ContextProvider.getSession(); >+ WeakReference[] displaysRef >+ = ( WeakReference[] )session.getAttribute( DISPLAYS ); >+ if( displaysRef == null ) { >+ displaysRef = new WeakReference[ 4 ]; >+ } >+ boolean registered = false; >+ for( int i = 0; i < displaysRef.length && !registered; i++ ) { >+ if( displaysRef[ i ] == null ) { >+ displaysRef[ i ] = new WeakReference( display ); >+ registered = true; >+ } >+ } >+ if( !registered ) { >+ WeakReference[] newDisplaysRef >+ = new WeakReference[ displaysRef.length + 4 ]; >+ System.arraycopy( displaysRef, >+ 0, >+ newDisplaysRef, >+ 0, >+ displaysRef.length ); >+ newDisplaysRef[ displaysRef.length ] = new WeakReference( display ); >+ displaysRef = newDisplaysRef; >+ } >+ session.setAttribute( DISPLAYS, displaysRef ); >+ } >+ } >+ >+ private static void deregister( final Display display ) { >+ synchronized( Device.class ) { >+ ISessionStore session = ContextProvider.getSession(); >+ WeakReference[] displaysRef >+ = ( WeakReference[] )session.getAttribute( DISPLAYS ); >+ if( displaysRef != null ) { >+ boolean empty = true; >+ for( int i = 0; i < displaysRef.length; i++ ) { >+ WeakReference currentRef = displaysRef[ i ]; >+ if( currentRef != null && display == currentRef.get() ) { >+ displaysRef[ i ] = null; >+ } >+ if( displaysRef[ i ] != null ) { >+ empty = false; >+ } >+ } >+ if( empty ) { >+ displaysRef = null; >+ } >+ } >+ session.setAttribute( DISPLAYS, displaysRef ); >+ } >+ } >+ > ///////////////////// > // Consistency checks > >#P org.eclipse.rap.rwt.test >Index: src/org/eclipse/swt/widgets/Display_Test.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt.test/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Display_Test.java,v >retrieving revision 1.43 >diff -u -r1.43 Display_Test.java >--- src/org/eclipse/swt/widgets/Display_Test.java 23 Mar 2010 10:07:28 -0000 1.43 >+++ src/org/eclipse/swt/widgets/Display_Test.java 26 Apr 2010 09:01:05 -0000 >@@ -1122,6 +1122,14 @@ > assertNull( Display.getAppVersion() ); > } > >+ public void testFindDisplay() { >+ Display display = new Display(); >+ assertSame( display, Display.findDisplay( display.getThread() ) ); >+ assertNull( Display.findDisplay( null ) ); >+ display.dispose(); >+ assertNull( Display.findDisplay( display.getThread() ) ); >+ } >+ > protected void setUp() throws Exception { > Fixture.setUp(); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 272803
:
166054
|
166069