Search in sources :

Example 6 with UISWTViewEventListener

use of com.biglybt.ui.swt.pif.UISWTViewEventListener in project BiglyBT by BiglySoftware.

the class UISWTViewImpl method triggerBooleanEvent.

private boolean triggerBooleanEvent(int eventType, Object data) {
    if (DEBUG_TRIGGERS) {
        if (eventListener == null || eventType != UISWTViewEvent.TYPE_REFRESH) {
            System.out.println(System.currentTimeMillis() + "." + padRight(id, 20) + "] " + "trigger " + padRight((eventType < UISWTViewEvent.DEBUG_TYPES.length ? UISWTViewEvent.DEBUG_TYPES[eventType] : "" + eventType), 6) + ", " + (eventListener == null ? "null" : "nonn") + ";data=" + (data instanceof Object[] ? Arrays.toString((Object[]) data) : data) + "/ds=" + (datasource instanceof Object[] ? Arrays.toString((Object[]) datasource) : datasource) + ";" + title + ";" + Debug.getCompressedStackTrace());
        }
    }
    if (eventType == UISWTViewEvent.TYPE_LANGUAGEUPDATE) {
        // put it back to how it was constructed
        this.titleID = CFG_PREFIX + this.id + ".title";
        if (!MessageText.keyExists(titleID) && MessageText.keyExists(this.id)) {
            this.titleID = id;
        } else if (id.contains(" ")) {
            // hack to fix HD Video Player which is using the expanded name as the id at the moment :(
            this.titleID = "!" + id + "!";
        }
        title = null;
        if (setTitleID != null) {
            setTitleID(setTitleID);
        }
        if (setTitle != null) {
            setTitle(setTitle);
        }
        refreshTitle();
        Messages.updateLanguageForControl(getComposite());
    }
    if (eventListener == null && eventType != UISWTViewEvent.TYPE_DATASOURCE_CHANGED) {
        return false;
    }
    if (eventType == UISWTViewEvent.TYPE_INITIALIZE) {
        if (haveSentInitialize) {
            if (DEBUG_TRIGGERS) {
                System.out.println("  -> already haveSentInitialize");
            }
            return false;
        }
        if (!created) {
            // create will set DS changed
            triggerBooleanEvent(UISWTViewEvent.TYPE_CREATE, this);
        } else if (datasource != null) {
            triggerBooleanEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, datasource);
        }
        haveSentInitialize = true;
    }
    if (eventType == UISWTViewEvent.TYPE_CREATE) {
        created = true;
    }
    if (delayInitializeToFirstActivate && eventType == UISWTViewEvent.TYPE_FOCUSGAINED && !haveSentInitialize) {
        swt_triggerInitialize();
    }
    // prevent double fire of focus gained/lost
    if (eventType == UISWTViewEvent.TYPE_FOCUSGAINED && hasFocus != null && hasFocus) {
        if (DEBUG_TRIGGERS) {
            System.out.println("  -> already hasFocus");
        }
        return true;
    }
    if (eventType == UISWTViewEvent.TYPE_FOCUSLOST && hasFocus != null && !hasFocus) {
        if (DEBUG_TRIGGERS) {
            System.out.println("  -> already !hasFocus");
        }
        return true;
    }
    if (eventType == UISWTViewEvent.TYPE_DATASOURCE_CHANGED) {
        Object newDataSource = PluginCoreUtils.convert(data, true);
        if (datasource == newDataSource) {
            if (DEBUG_TRIGGERS) {
                System.out.println("  -> same DS, skip");
            }
            return true;
        }
        if (newDataSource instanceof Object[] && datasource instanceof Object[]) {
            if (Arrays.equals((Object[]) newDataSource, (Object[]) datasource)) {
                if (DEBUG_TRIGGERS) {
                    System.out.println("  -> same DS[], skip");
                }
                return true;
            }
        }
        datasource = newDataSource;
        data = PluginCoreUtils.convert(datasource, useCoreDataSource);
        if (initialDatasource == null) {
            initialDatasource = datasource;
        } else if (datasource == null) {
            // explicit clearing of datasource - we need to forget the initial one as it will be
            // re-instated incorrectly if the view is subsequently switched to. This was happening in sub-tabs
            // when a download was selected, then deselected (ctrl+click) - the active sub-tab view was cleared
            // but the other ones still remembered the selection when switched to
            initialDatasource = null;
        }
        if (eventListener == null) {
            return true;
        }
    // TODO: What about triggering skinObject's EVENT_DATASOURCE_CHANGED?
    } else if (eventType == UISWTViewEvent.TYPE_OBFUSCATE && (eventListener instanceof ObfuscateImage)) {
        if (data instanceof Map) {
            ((ObfuscateImage) eventListener).obfuscatedImage((Image) MapUtils.getMapObject((Map<?, ?>) data, "image", null, Image.class));
        }
    } else if (eventType == UISWTViewEvent.TYPE_FOCUSGAINED) {
        hasFocus = true;
        if (!haveSentInitialize) {
            swt_triggerInitialize();
        }
    } else if (eventType == UISWTViewEvent.TYPE_FOCUSLOST) {
        hasFocus = false;
        if (isDestroyOnDeactivate()) {
            triggerEvent(UISWTViewEvent.TYPE_DESTROY, null);
        }
    } else if (eventType == UISWTViewEvent.TYPE_DESTROY) {
        if (hasFocus != null && hasFocus) {
            triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null);
        }
        // focus lost may have destroyed us already
        if (!created && !haveSentInitialize && getComposite() == null) {
            return true;
        }
    }
    boolean result = false;
    try {
        result = eventListener.eventOccurred(new UISWTViewEventImpl(parentViewID, this, eventType, data));
    } catch (Throwable t) {
        Debug.out("ViewID=" + id + "; EventID=" + UISWTViewEvent.DEBUG_TYPES[eventType] + "; data=" + data, t);
    // throw (new UIRuntimeException("UISWTView.triggerEvent:: ViewID="
    // + sViewID + "; EventID=" + eventType + "; data=" + data, t));
    }
    if (eventType == UISWTViewEvent.TYPE_DESTROY) {
        if (masterComposite != null && !masterComposite.isDisposed()) {
            Composite parent = masterComposite.getParent();
            Utils.disposeComposite(masterComposite);
            Utils.relayoutUp(parent);
        }
        masterComposite = null;
        composite = null;
        haveSentInitialize = false;
        hasFocus = false;
        created = false;
        initialDatasource = datasource;
        datasource = null;
    } else if (eventType == UISWTViewEvent.TYPE_CREATE) {
        if (eventListener instanceof UISWTViewEventListenerHolder) {
            UISWTViewEventListenerHolder h = (UISWTViewEventListenerHolder) eventListener;
            UISWTViewEventListener delegatedEventListener = h.getDelegatedEventListener(this);
            if (delegatedEventListener != null) {
                try {
                    setEventListener(delegatedEventListener, false);
                } catch (UISWTViewEventCancelledException e) {
                }
            }
        }
        if (DEBUG_TRIGGERS) {
            System.out.println(" -> raw DS Change");
        }
        triggerEventRaw(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, PluginCoreUtils.convert(datasource, useCoreDataSource));
    }
    return result;
}
Also used : ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) Image(org.eclipse.swt.graphics.Image) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) Map(java.util.Map) LightHashMap(com.biglybt.core.util.LightHashMap)

Example 7 with UISWTViewEventListener

use of com.biglybt.ui.swt.pif.UISWTViewEventListener in project BiglyBT by BiglySoftware.

the class SubscriptionMDIEntry method refreshView.

protected void refreshView() {
    if (!(mdiEntry instanceof BaseMdiEntry)) {
        return;
    }
    UISWTViewEventListener eventListener = ((BaseMdiEntry) mdiEntry).getEventListener();
    if (eventListener instanceof SubscriptionView) {
        SubscriptionView subsView = (SubscriptionView) eventListener;
        subsView.refreshView();
    }
}
Also used : BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener)

Example 8 with UISWTViewEventListener

use of com.biglybt.ui.swt.pif.UISWTViewEventListener in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method exportStandAlone.

public Map<String, Object> exportStandAlone() {
    Map<String, Object> result = new HashMap<>();
    result.put("mdi", (this instanceof SideBarEntrySWT) ? "sidebar" : "tabbed");
    String title = null;
    ViewTitleInfo vti = getViewTitleInfo();
    if (vti != null) {
        title = (String) vti.getTitleInfoProperty(ViewTitleInfo.TITLE_TEXT);
    }
    if (title == null || title.length() == 0) {
        title = getFullTitle();
    }
    result.put("title", title);
    result.put("skin_ref", getSkinRef());
    result.put("skin_id", skin.getSkinID());
    result.put("parent_id", getParentID());
    result.put("id", id);
    Object data_source = getDatasourceCore();
    if (data_source == null) {
        data_source = getInitialDataSource();
    }
    if (data_source != null) {
        if (data_source instanceof String) {
            result.put("data_source", data_source);
        } else if (data_source instanceof Integer) {
            List l = new ArrayList();
            l.add("i");
            l.add(((Integer) data_source).longValue());
            result.put("data_source", l);
        } else {
            result.put("data_source", DataSourceResolver.exportDataSource(data_source));
        }
    }
    result.put("control_type", getControlType());
    UISWTViewEventListener listener = getEventListener();
    if (listener instanceof UISWTViewCoreEventListenerEx) {
        CloneConstructor cc = ((UISWTViewCoreEventListenerEx) listener).getCloneConstructor();
        String name = cc.getCloneClass().getName();
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        List<Object> params = cc.getParameters();
        if (params != null) {
            List p_types = new ArrayList<>();
            List p_vals = new ArrayList<>();
            map.put("p_types", p_types);
            map.put("p_vals", p_vals);
            for (Object p : params) {
                if (p instanceof Boolean) {
                    p_types.add("bool");
                    p_vals.add(new Long(((Boolean) p) ? 1 : 0));
                } else if (p instanceof Long) {
                    p_types.add("long");
                    p_vals.add(p);
                } else if (p instanceof String) {
                    p_types.add("string");
                    p_vals.add(p);
                } else {
                    Debug.out("Unsupported param type: " + p);
                }
            }
        }
        result.put("event_listener", map);
    } else if (listener instanceof UISWTViewEventListenerEx) {
        com.biglybt.ui.swt.pif.UISWTViewEventListenerEx.CloneConstructor cc = ((UISWTViewEventListenerEx) listener).getCloneConstructor();
        PluginInterface pi = cc.getPluginInterface();
        Map<String, Object> map = new HashMap<>();
        map.put("plugin_id", pi.getPluginID());
        map.put("plugin_name", pi.getPluginName());
        map.put("ipc_method", cc.getIPCMethod());
        List<Object> params = cc.getIPCParameters();
        if (params != null) {
            List p_types = new ArrayList<>();
            List p_vals = new ArrayList<>();
            map.put("p_types", p_types);
            map.put("p_vals", p_vals);
            for (Object p : params) {
                if (p instanceof Boolean) {
                    p_types.add("bool");
                    p_vals.add(new Long(((Boolean) p) ? 1 : 0));
                } else if (p instanceof Long) {
                    p_types.add("long");
                    p_vals.add(p);
                } else if (p instanceof String) {
                    p_types.add("string");
                    p_vals.add(p);
                } else {
                    Debug.out("Unsupported param type: " + p);
                }
            }
        }
        result.put("event_listener", map);
    }
    return (result);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEventListenerEx(com.biglybt.ui.swt.pif.UISWTViewEventListenerEx) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) List(java.util.List) CloneConstructor(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListenerEx.CloneConstructor) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 9 with UISWTViewEventListener

use of com.biglybt.ui.swt.pif.UISWTViewEventListener in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method setViewTitleInfo.

/* (non-Javadoc)
	 * @see MdiEntry#setViewTitleInfo(ViewTitleInfo)
	 */
@Override
public void setViewTitleInfo(ViewTitleInfo viewTitleInfo) {
    if (this.viewTitleInfo == viewTitleInfo) {
        return;
    }
    this.viewTitleInfo = viewTitleInfo;
    // TODO: Need to listen for viewTitleInfo triggers so we can refresh items below
    if (viewTitleInfo != null) {
        if (viewTitleInfo instanceof ViewTitleInfo2) {
            ViewTitleInfo2 vti2 = (ViewTitleInfo2) viewTitleInfo;
            try {
                vti2.titleInfoLinked(mdi, this);
            } catch (Exception e) {
                Debug.out(e);
            }
        }
        String imageID = (String) viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_IMAGEID);
        if (imageID != null) {
            setImageLeftID(imageID.length() == 0 ? null : imageID);
        }
        ViewTitleInfoManager.addListener(this);
        if (getEventListener() == null && (viewTitleInfo instanceof UISWTViewEventListener)) {
            try {
                setEventListener((UISWTViewEventListener) viewTitleInfo, true);
            } catch (UISWTViewEventCancelledException e) {
            }
        }
    }
    redraw();
}
Also used : ViewTitleInfo2(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo2) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) ConfigurationParameterNotFoundException(com.biglybt.core.config.impl.ConfigurationParameterNotFoundException)

Example 10 with UISWTViewEventListener

use of com.biglybt.ui.swt.pif.UISWTViewEventListener in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method setEventListener.

/* (non-Javadoc)
	 * @see com.biglybt.ui.swt.pifimpl.UISWTViewImpl2#setEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener, boolean)
	 */
@Override
public void setEventListener(UISWTViewEventListener _eventListener, boolean doCreate) throws UISWTViewEventCancelledException {
    UISWTViewEventListener eventListener = getEventListener();
    if (eventListener instanceof UIToolBarEnablerBase) {
        removeToolbarEnabler((UIToolBarEnablerBase) eventListener);
    }
    if ((eventListener instanceof ViewTitleInfo) && viewTitleInfo == eventListener) {
        setViewTitleInfo(null);
    }
    if (_eventListener instanceof UISWTViewEventListenerHolder) {
        UISWTViewEventListenerHolder h = (UISWTViewEventListenerHolder) _eventListener;
        UISWTViewEventListener delegatedEventListener = h.getDelegatedEventListener(this);
        if (delegatedEventListener != null) {
            _eventListener = delegatedEventListener;
        }
    }
    if (_eventListener instanceof UIToolBarEnablerBase) {
        addToolbarEnabler((UIToolBarEnablerBase) _eventListener);
    }
    if ((_eventListener instanceof ViewTitleInfo) && viewTitleInfo == null) {
        setViewTitleInfo((ViewTitleInfo) _eventListener);
    }
    if (_eventListener instanceof BasicPluginViewImpl) {
        String existing_id = getImageLeftID();
        if (existing_id == null || "image.sidebar.plugin".equals(existing_id)) {
            setImageLeftID("image.sidebar.logview");
        }
    }
    super.setEventListener(_eventListener, doCreate);
}
Also used : UIToolBarEnablerBase(com.biglybt.pif.ui.toolbar.UIToolBarEnablerBase) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Aggregations

UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)14 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)4 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)3 PluginUISWTSkinObject (com.biglybt.ui.swt.pif.PluginUISWTSkinObject)3 UISWTViewEventListenerEx (com.biglybt.ui.swt.pif.UISWTViewEventListenerEx)3 UISWTViewImpl (com.biglybt.ui.swt.pifimpl.UISWTViewImpl)3 Map (java.util.Map)3 Point (org.eclipse.swt.graphics.Point)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 PluginInterface (com.biglybt.pif.PluginInterface)2 UIFunctions (com.biglybt.ui.UIFunctions)2 UIUpdatable (com.biglybt.ui.common.updater.UIUpdatable)2 UIUpdater (com.biglybt.ui.common.updater.UIUpdater)2 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)2 MdiEntryVitalityImage (com.biglybt.ui.mdi.MdiEntryVitalityImage)2 UISWTView (com.biglybt.ui.swt.pif.UISWTView)2 UISWTViewCore (com.biglybt.ui.swt.pifimpl.UISWTViewCore)2 UISWTViewEventListenerHolder (com.biglybt.ui.swt.pifimpl.UISWTViewEventListenerHolder)2 HashMap (java.util.HashMap)2