Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stasgora/observetree
Observetree is a library extending the Observable pattern by integrating it in a tree structure with propagating events
https://github.com/stasgora/observetree
events java library listener maven observable pattern tree
Last synced: about 1 month ago
JSON representation
Observetree is a library extending the Observable pattern by integrating it in a tree structure with propagating events
- Host: GitHub
- URL: https://github.com/stasgora/observetree
- Owner: stasgora
- License: mit
- Created: 2019-04-13T20:10:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T16:49:16.000Z (about 4 years ago)
- Last Synced: 2024-10-15T21:48:08.513Z (3 months ago)
- Topics: events, java, library, listener, maven, observable, pattern, tree
- Language: Java
- Homepage: https://stasgora.github.io/observetree/
- Size: 835 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Maven Central](https://img.shields.io/maven-central/v/dev.sgora/observetree.svg)](https://search.maven.org/search?q=g:%22dev.sgora%22%20AND%20a:%22observetree%22)
[![Build Status](https://travis-ci.org/stasgora/observetree.svg?branch=master)](https://travis-ci.org/stasgora/observetree)
[![Last Release Date](https://img.shields.io/github/release-date/stasgora/observetree?color=orange)](https://github.com/stasgora/observetree/releases)
[![Sonar Tests](https://img.shields.io/sonar/tests/dev.sgora:observetree?compact_message&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=dev.sgora%3Aobservetree)
[![Code Coverage](https://img.shields.io/coveralls/github/stasgora/observetree)](https://coveralls.io/github/stasgora/observetree?branch=master)
[![License](https://img.shields.io/github/license/stasgora/observetree?color=blueviolet)](https://github.com/stasgora/observetree/blob/master/LICENSE)
[![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/dev.sgora:observetree?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=dev.sgora%3Aobservetree)# Observetree library
Observetree is a library that extends the classic _Observable pattern_ by integrating it in a tree structure. _Change events_ are propagated through the Observable tree. _Listeners_ can be assigned a priority to control the order at which they are called.## Getting started
### Documentation [![Javadocs](https://javadoc.io/badge/dev.sgora/observetree.svg)](https://javadoc.io/doc/dev.sgora/observetree)
Javadoc also available at [sgora.dev/observetree/](https://sgora.dev/observetree/)For detailed technical description see [Observable class](https://javadoc.io/doc/dev.sgora/observetree/latest/stasgora.observetree/dev/sgora/observetree/Observable.html)
### Installation
#### Maven [![Maven Central](https://img.shields.io/maven-central/v/dev.sgora/observetree.svg)](https://search.maven.org/search?q=g:%22dev.sgora%22%20AND%20a:%22observetree%22)
```xmldev.sgora
observetree
${observetree-version}```
(Earlier versions released under ```io.github.stasgora``` groupId)
SNAPSHOT versions are **not** synchronized to Central. If you want to use a snapshot version you need to add the https://oss.sonatype.org/content/repositories/snapshots/ repository to your pom.xml.
#### Manual
See the [release page](https://github.com/stasgora/observetree/releases) for _jar_ downloads. Follow your IDE instructions for detailed steps on adding external library dependencies to your project.### Basic usage
- Create model class extending ```Observable```:
```java
class Point extends Observable {
public int x, y;
}
```
- Internally call ```onValueChanged()```:
```java
private void set(int x, int y) {
this.x = x;
this.y = y;
onValueChanged();
}
```
- Create instance and register a listener:
```java
Point p = new Point();
p.addListener(() -> {...});
```
- Change model object and allow it to call it's listeners:
```java
p.set(1, 1);
p.notifyListeners();
```### Advanced functions
#### Using _Observable_ trees
- Build model structure:
```java
class Model extends Observable {
public Point point;
...
public Model() {
addSubObservable(point);
...
}
}
```
- You can subscribe to changes of objects on different levels:
```java
model.addListener(...); // Changes to model and all it's sub-observables
model.point.addListener(...);
```
- After changes to potentially many objects notify listeners of all changed objects in tree:
```java
model.notifyListeners();
```
(For detailed behaviour description see the [documentation](https://javadoc.io/doc/dev.sgora/observetree/latest/stasgora.observetree/dev/sgora/observetree/Observable.html))
#### Specifying listener priority
```java
p.addListener(() -> {...}, ListenerPriority.HIGH);
```
#### Creating _Settables_ out of external objects
- Declare:
```java
SettableProperty size = new SettableProperty<>(1);
```
- Get notified when the value is set:
```java
size.set(2);
```
#### Using _Settable Observables_ with persistent listeners
- Declare:
```java
SettableObservable point = new SettableObservable<>(new Point());
```
- Register static listener:
```java
point.addStaticListener(() -> {...});
```
- After replacing the object the listeners will remain attached:
```java
point.set(new Point());
```### Author
Stanisław Góra### License
[MIT License](http://www.opensource.org/licenses/mit-license.php)