Search in sources :

Example 6 with SWTRunnable

use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.

the class TabbedEntry method widgetDisposed.

@Override
public void widgetDisposed(DisposeEvent e) {
    setSwtItem(null);
    SWTThread instance = SWTThread.getInstance();
    triggerCloseListeners(instance != null && !instance.isTerminated());
    try {
        setEventListener(null, false);
    } catch (UISWTViewEventCancelledException e1) {
    }
    SWTSkinObject so = getSkinObject();
    if (so != null) {
        setSkinObjectMaster(null);
        so.getSkin().removeSkinObject(so);
    }
    // delay saving of removing of auto-open flag.  If after the delay, we are
    // still alive, it's assumed the user invoked the close, and we should
    // remove the auto-open flag
    Utils.execSWTThreadLater(0, new SWTRunnable() {

        @Override
        public void runWithDisplay(Display display) {
            // even though execThreadLater will not run on close of app because
            // the display is disposed, do a double check of tree disposal just
            // in case.  We don't want to trigger close listeners or
            // remove autoopen parameters if the user is closing the app (as
            // opposed to closing  the sidebar)
            mdi.removeItem(TabbedEntry.this);
            mdi.removeEntryAutoOpen(id);
        }
    });
}
Also used : UISWTViewEventCancelledException(com.biglybt.ui.swt.pifimpl.UISWTViewEventCancelledException) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread)

Example 7 with SWTRunnable

use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.

the class PrivacyView method dataSourceChanged.

private void dataSourceChanged(Object newDataSource) {
    synchronized (this) {
        DownloadManager new_dm = ViewUtils.getDownloadManagerFromDataSource(newDataSource);
        if (new_dm == current_dm) {
            return;
        }
        final DownloadManager f_old_dm = current_dm;
        current_dm = new_dm;
        final DownloadManager f_new_dm = current_dm;
        Utils.execSWTThread(new SWTRunnable() {

            @Override
            public void runWithDisplay(Display display) {
                swt_updateFields(f_old_dm, f_new_dm);
            }
        });
    }
}
Also used : SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 8 with SWTRunnable

use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.

the class UIUpdaterSWT method run.

// @see com.biglybt.core.util.AEThread2#run()
@Override
public void run() {
    final AESemaphore sem = new AESemaphore("UI Updater");
    while (!finished) {
        Utils.execSWTThread(new SWTRunnable() {

            @Override
            public void runWithDisplay(Display display) {
                try {
                    if (finished) {
                        return;
                    }
                    if (display.getActiveShell() == null) {
                        Shell[] shells = display.getShells();
                        boolean noneVisible = true;
                        for (int i = 0; i < shells.length; i++) {
                            if (shells[i].isVisible() && !shells[i].getMinimized()) {
                                noneVisible = false;
                                break;
                            }
                        }
                        if (noneVisible) {
                            // System.out.println("nothing visible!");
                            if (alwaysUpdateables.size() > 0) {
                                update(alwaysUpdateables, false);
                            }
                            return;
                        }
                        // inactive means "active shell is not one of our app's"
                        if (inactiveTicks++ % inactiveFactor != 0) {
                            return;
                        }
                    }
                    update(updateables, true);
                } catch (Exception e) {
                    Logger.log(new LogEvent(LOGID, "Error while trying to update GUI", e));
                } finally {
                    try {
                        for (UIUpdaterListener l : listeners) {
                            try {
                                l.updateComplete(++update_count);
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    } finally {
                        sem.release();
                    }
                }
            }

            @Override
            public void runNoDisplay() {
                sem.release();
            }
        });
        long start = SystemTime.getHighPrecisionCounter();
        sem.reserve();
        long elapsed = SystemTime.getHighPrecisionCounter() - start;
        long to_sleep = waitTimeMS - (elapsed / 1000000);
        if (to_sleep < 10) {
            to_sleep = 10;
        } else if (to_sleep > 25000) {
            to_sleep = 25000;
        }
        try {
            // System.out.println( "sleep=" + to_sleep );
            Thread.sleep(to_sleep);
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) Display(org.eclipse.swt.widgets.Display)

Example 9 with SWTRunnable

use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.

the class TabbedEntry method setCloseable.

/* (non-Javadoc)
	 * @see BaseMdiEntry#setCloseable(boolean)
	 */
@Override
public void setCloseable(boolean closeable) {
    // override.. we don't support non-closeable for main
    if (((TabbedMDI) getMDI()).isMainMDI) {
        closeable = true;
    }
    super.setCloseable(closeable);
    Utils.execSWTThread(new SWTRunnable() {

        @Override
        public void runWithDisplay(Display display) {
            if (swtItem == null || swtItem.isDisposed()) {
                return;
            }
            swtItem.setShowClose(isCloseable());
        }
    });
}
Also used : SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable)

Example 10 with SWTRunnable

use of com.biglybt.ui.swt.utils.SWTRunnable in project BiglyBT by BiglySoftware.

the class MyTorrentsView method tableViewDestroyed.

protected void tableViewDestroyed() {
    tv.removeKeyListener(this);
    Utils.execSWTThread(new SWTRunnable() {

        @Override
        public void runWithDisplay(Display display) {
            try {
                Utils.disposeSWTObjects(new Object[] { dragSource, dropTarget, fontButton, tableHeaderMenu });
                dragSource = null;
                dropTarget = null;
                fontButton = null;
                tableHeaderMenu = null;
            } catch (Exception e) {
                Debug.out(e);
            }
        }
    });
    Object[] dms = globalManager.getDownloadManagers().toArray();
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = (DownloadManager) dms[i];
        dm.removeListener(this);
    }
    if (currentTags != null) {
        for (Tag tag : currentTags) {
            tag.removeTagListener(this);
        }
    }
    TagManager tagManager = TagManagerFactory.getTagManager();
    TagType ttManual = tagManager.getTagType(TagType.TT_DOWNLOAD_MANUAL);
    TagType ttCat = tagManager.getTagType(TagType.TT_DOWNLOAD_CATEGORY);
    ttManual.removeTagTypeListener(MyTorrentsView.this);
    ttCat.removeTagTypeListener(MyTorrentsView.this);
    globalManager.removeListener(this);
    globalManager.removeEventListener(gm_event_listener);
    COConfigurationManager.removeParameterListener("DND Always In Incomplete", this);
    COConfigurationManager.removeParameterListener("User Mode", this);
    COConfigurationManager.removeParameterListener("Library.ShowCatButtons", this);
    COConfigurationManager.removeParameterListener("Library.ShowTagButtons", this);
    COConfigurationManager.removeParameterListener("Library.ShowTagButtons.CompOnly", this);
}
Also used : SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException)

Aggregations

SWTRunnable (com.biglybt.ui.swt.utils.SWTRunnable)13 DownloadManager (com.biglybt.core.download.DownloadManager)2 SWTThread (com.biglybt.ui.swt.mainwindow.SWTThread)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 Display (org.eclipse.swt.widgets.Display)2 LogEvent (com.biglybt.core.logging.LogEvent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 MdiEntry (com.biglybt.ui.mdi.MdiEntry)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)1 UISWTViewEventCancelledException (com.biglybt.ui.swt.pifimpl.UISWTViewEventCancelledException)1