Search in sources :

Example 1 with SWTThread

use of com.biglybt.ui.swt.mainwindow.SWTThread in project BiglyBT by BiglySoftware.

the class SideBarEntrySWT method widgetDisposed.

@Override
public void widgetDisposed(DisposeEvent e) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    if (imageLoader != null) {
        imageLoader.releaseImage("image.sidebar.closeitem");
        imageLoader.releaseImage("image.sidebar.closeitem-selected");
    }
    setDisposed(true);
    final TreeItem treeItem = (TreeItem) e.widget;
    if (treeItem != swtItem) {
        Debug.out("Warning: TreeItem changed for sidebar " + id);
        return;
    }
    if (swtItem == null) {
        return;
    }
    if (swtItem != null && !Constants.isOSX) {
        // In theory, the disposal of swtItem will trigger the disposal of the
        // children.  Let's force it just in case
        // On OSX this will cause disposal confusion in SWT, and possibly result
        // in a SIGSEGV crash.
        TreeItem[] children = swtItem.getItems();
        for (TreeItem child : children) {
            if (child.isDisposed()) {
                continue;
            }
            MdiEntry entry = (MdiEntry) child.getData("MdiEntry");
            if (entry != null) {
                entry.close(true);
            }
        }
    }
    final Tree tree = sidebar.getTree();
    if (tree.isDisposed() || (swtItem != null && swtItem.isDisposed()) || tree.getShell().isDisposed()) {
        return;
    }
    setTreeItem(null);
    mdi.removeItem(SideBarEntrySWT.this);
    SWTThread instance = SWTThread.getInstance();
    boolean user = instance != null && !instance.isTerminated();
    if (user) {
        // It's not a user close if the parent is making the children (this entry)
        // close.  parent will be marked disposed, so use that as a check.
        String parentID = getParentID();
        if (parentID != null) {
            MdiEntry entry = mdi.getEntry(parentID);
            if (entry != null && entry.isDisposed()) {
                user = false;
            }
        }
    }
    triggerCloseListeners(user);
    SWTSkinObject so = getSkinObject();
    if (so != null) {
        setSkinObjectMaster(null);
        so.getSkin().removeSkinObject(so);
    }
    for (SideBarVitalityImageSWT vitalityImage : listVitalityImages) {
        vitalityImage.dispose();
    }
    listVitalityImages.clear();
    // 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) {
            // opposed to closing  the sidebar)
            if (tree.isDisposed()) {
                return;
            }
            try {
                COConfigurationManager.removeParameter("SideBar.AutoOpen." + id);
                // Force selection
                if (Constants.isOSX && !tree.isDisposed() && tree.getSelectionCount() == 0) {
                    String parentid = getParentID();
                    if (parentid != null && mdi.getEntry(parentid) != null) {
                        mdi.showEntryByID(parentid);
                    } else {
                        mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
                    }
                }
            } catch (Exception e2) {
                Debug.out(e2);
            }
            // See if this entry has been replaced by another in the meantime. This happens when we are
            // moving an entry in the sidebar by removing it and then re-adding it. We assume that the
            // auto-open properties of the replacement are the same as those of the initial entry
            boolean replaced = false;
            String my_id = SideBarEntrySWT.this.getId();
            if (my_id != null) {
                MdiEntry entry = mdi.getEntry(my_id);
                if (entry != null && entry != SideBarEntrySWT.this) {
                    replaced = true;
                }
            }
            if (!replaced) {
                mdi.removeEntryAutoOpen(id);
            }
        }
    });
}
Also used : SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread)

Example 2 with SWTThread

use of com.biglybt.ui.swt.mainwindow.SWTThread in project BiglyBT by BiglySoftware.

the class Alerts method showAlert.

/**
 * @param alert
 *
 * @since 3.0.0.9
 */
protected static void showAlert(final LogAlert alert) {
    final SWTThread instance = SWTThread.getInstance();
    final Display display = instance == null ? null : instance.getDisplay();
    if (alert.err != null) {
        alert.details = Debug.getStackTrace(alert.err);
    }
    for (Iterator<AlertListener> iter = listeners.iterator(); iter.hasNext(); ) {
        AlertListener l = (AlertListener) iter.next();
        if (!l.allowPopup(alert.relatedTo, alert.entryType)) {
            return;
        }
    }
    if (stopping || display == null || display.isDisposed()) {
        try {
            alert_queue_mon.enter();
            List close_alerts = COConfigurationManager.getListParameter("Alerts.raised.at.close", new ArrayList());
            Map alert_map = new HashMap();
            alert_map.put("type", new Long(alert.entryType));
            alert_map.put("message", alert.text);
            alert_map.put("timeout", new Long(alert.getGivenTimeoutSecs()));
            if (alert.details != null) {
                alert_map.put("details", alert.details);
            }
            close_alerts.add(alert_map);
            COConfigurationManager.setParameter("Alerts.raised.at.close", close_alerts);
            return;
        } finally {
            alert_queue_mon.exit();
        }
    }
    if (display == null || display.isDisposed()) {
        return;
    }
    String key = (alert.err == null) ? alert.text : alert.text + ":" + alert.err.toString();
    try {
        alert_history_mon.enter();
        if (!alert.repeatable) {
            if (alert_history.contains(key)) {
                return;
            }
            alert_history.add(key);
            if (alert_history.size() > 512) {
                alert_history.remove(0);
            }
        }
        listUnviewedLogAlerts.add(alert);
    } finally {
        alert_history_mon.exit();
    }
    AlertHistoryListener[] array = listMessageHistoryListeners.toArray(new AlertHistoryListener[0]);
    for (AlertHistoryListener l : array) {
        l.alertHistoryAdded(alert);
    }
    if (alert.forceNotify) {
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                int swtIconID = SWT.ICON_INFORMATION;
                switch(alert.getType()) {
                    case LogAlert.LT_WARNING:
                        swtIconID = SWT.ICON_WARNING;
                        break;
                    case LogAlert.LT_ERROR:
                        swtIconID = SWT.ICON_ERROR;
                        break;
                }
                String text = alert.getText();
                int pos = text.indexOf(":");
                String title;
                if (pos == -1) {
                    title = "";
                } else {
                    title = text.substring(0, pos).trim();
                    text = text.substring(pos + 1).trim();
                }
                new MessageSlideShell(display, swtIconID, title, text, alert.details, alert.getContext(), alert.getTimeoutSecs());
            }
        });
    }
}
Also used : MessageSlideShell(com.biglybt.ui.swt.shells.MessageSlideShell) ILogAlertListener(com.biglybt.core.logging.ILogAlertListener) SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread) Display(org.eclipse.swt.widgets.Display)

Example 3 with SWTThread

use of com.biglybt.ui.swt.mainwindow.SWTThread in project BiglyBT by BiglySoftware.

the class Utils method getDisplay.

private static Display getDisplay(boolean warn) {
    SWTThread swt = SWTThread.getInstance();
    Display display;
    if (swt == null) {
        try {
            display = Display.getCurrent();
            if (display == null && warn) {
                System.err.println("SWT null " + Debug.getCompressedStackTrace());
                return null;
            }
        } catch (Throwable t) {
            // ignore
            return null;
        }
    } else {
        if (swt.isTerminated()) {
            return null;
        }
        display = swt.getDisplay();
    }
    if (display == null || display.isDisposed()) {
        if (warn) {
            System.err.println("SWT disposed " + Debug.getCompressedStackTrace());
        }
        return null;
    }
    return display;
}
Also used : SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread)

Example 4 with SWTThread

use of com.biglybt.ui.swt.mainwindow.SWTThread in project BiglyBT by BiglySoftware.

the class Utils method isThisThreadSWT.

public static boolean isThisThreadSWT() {
    SWTThread swt = SWTThread.getInstance();
    if (swt == null) {
    // System.err.println("WARNING: SWT Thread not started yet");
    }
    Display display = (swt == null) ? Display.getCurrent() : swt.getDisplay();
    if (display == null) {
        return false;
    }
    // and may end up causing sync lock when disposing
    try {
        display.getWarnings();
    } catch (SWTException e) {
        return false;
    }
    return (display.getThread() == Thread.currentThread());
}
Also used : SWTException(org.eclipse.swt.SWTException) SWTThread(com.biglybt.ui.swt.mainwindow.SWTThread)

Example 5 with SWTThread

use of com.biglybt.ui.swt.mainwindow.SWTThread 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)

Aggregations

SWTThread (com.biglybt.ui.swt.mainwindow.SWTThread)6 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 SWTRunnable (com.biglybt.ui.swt.utils.SWTRunnable)2 ILogAlertListener (com.biglybt.core.logging.ILogAlertListener)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 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 MessageSlideShell (com.biglybt.ui.swt.shells.MessageSlideShell)1 SWTException (org.eclipse.swt.SWTException)1 Display (org.eclipse.swt.widgets.Display)1