<commit_before>
/*
 * Copyright (C) 2012 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.stuff.pobj.vaadin;

import org.dellroad.stuff.pobj.PersistentObject;
import org.dellroad.stuff.pobj.PersistentObjectEvent;
import org.dellroad.stuff.pobj.PersistentObjectListener;
import org.dellroad.stuff.vaadin7.VaadinExternalListener;

/**
 * Specialization of {@link VaadinExternalListener} customized for listening to {@link PersistentObject}s.
 *
 * @param <T> type of the root persistent object
 */
public abstract class VaadinPersistentObjectListener<T> extends VaadinExternalListener<PersistentObject<T>>
  implements PersistentObjectListener<T> {

    public VaadinPersistentObjectListener(PersistentObject<T> pobj) {
        super(pobj);
    }

    @Override
    public final void handleEvent(final PersistentObjectEvent<T> event) {
        this.handleEvent(new Runnable() {
            @Override
            public void run() {
                VaadinPersistentObjectListener.this.handlePersistentObjectChange(
                  event.getOldRoot(), event.getNewRoot(), event.getVersion());
            }
        });
    }

    /**
     * Handle an update of the {@link PersistentObject} root object.
     * The current thread will already have the Vaadin session locked.
     *
     * <p>
     * The caller should not modify {@code oldRoot} or {@code newRoot}.
     * </p>
     *
     * @param oldRoot previous root object; may be null if empty starts or stops are supported
     * @param newRoot new root object; may be null if empty starts or stops are supported
     * @param version version corresponding to {@code newRoot}
     */
    protected abstract void handlePersistentObjectChange(T oldRoot, T newRoot, long version);

    @Override
    protected final void register(PersistentObject<T> pobj) {
        pobj.addListener(this);
    }

    @Override
    protected final void unregister(PersistentObject<T> pobj) {
        pobj.removeListener(this);
    }
}
<commit_msg>Javadoc tweak.<commit_after>
/*
 * Copyright (C) 2012 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.stuff.pobj.vaadin;

import org.dellroad.stuff.pobj.PersistentObject;
import org.dellroad.stuff.pobj.PersistentObjectEvent;
import org.dellroad.stuff.pobj.PersistentObjectListener;
import org.dellroad.stuff.vaadin7.VaadinExternalListener;

/**
 * Specialization of {@link VaadinExternalListener} customized for listening to {@link PersistentObject}s.
 *
 * @param <T> type of the root persistent object
 */
public abstract class VaadinPersistentObjectListener<T> extends VaadinExternalListener<PersistentObject<T>>
  implements PersistentObjectListener<T> {

    public VaadinPersistentObjectListener(PersistentObject<T> pobj) {
        super(pobj);
    }

    @Override
    public final void handleEvent(final PersistentObjectEvent<T> event) {
        this.handleEvent(new Runnable() {
            @Override
            public void run() {
                VaadinPersistentObjectListener.this.handlePersistentObjectChange(
                  event.getOldRoot(), event.getNewRoot(), event.getVersion());
            }
        });
    }

    /**
     * Handle an update of the {@link PersistentObject} root object.
     * The current thread will already have the Vaadin session locked, so it
     * <i>should not invoke {@link #handleEvent handleEvent()}</i> to handle the event.
     *
     * <p>
     * The caller should not modify {@code oldRoot} or {@code newRoot}.
     * </p>
     *
     * @param oldRoot previous root object; may be null if empty starts or stops are supported
     * @param newRoot new root object; may be null if empty starts or stops are supported
     * @param version version corresponding to {@code newRoot}
     */
    protected abstract void handlePersistentObjectChange(T oldRoot, T newRoot, long version);

    @Override
    protected final void register(PersistentObject<T> pobj) {
        pobj.addListener(this);
    }

    @Override
    protected final void unregister(PersistentObject<T> pobj) {
        pobj.removeListener(this);
    }
}

{'fraction_non_alphanumeric': 0.0929322572756175, 'fraction_numerical': 0.002445585717779408, 'mean_word_length': 3.2604166666666665, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118512', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1130, 'n_words': 327}