Skip to content

Commit e9260ce

Browse files
committed
Add EventService and default component names
1 parent 5c6c875 commit e9260ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+677
-216
lines changed

src/main/java/com/kodedu/controller/ApplicationController.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import org.springframework.web.socket.handler.TextWebSocketHandler;
8585
import org.springframework.web.util.UriComponentsBuilder;
8686

87+
import javax.annotation.PostConstruct;
8788
import javax.imageio.ImageIO;
8889
import javax.imageio.ImageReader;
8990
import javax.imageio.stream.ImageInputStream;
@@ -303,6 +304,9 @@ public class ApplicationController extends TextWebSocketHandler implements Initi
303304
@Autowired
304305
private SpellcheckConfigBean spellcheckConfigBean;
305306

307+
@Autowired
308+
private EventService eventService;
309+
306310
private Stage stage;
307311
private List<WebSocketSession> sessionList = new ArrayList<>();
308312
private Scene scene;
@@ -373,6 +377,15 @@ public class ApplicationController extends TextWebSocketHandler implements Initi
373377
private Scene markdownTableScene;
374378
private String VERSION_PATTERN = "\\.AsciidocFX-\\d+\\.\\d+\\.\\d+";
375379

380+
@PostConstruct
381+
public void install_listeners() {
382+
// Listen to working directory update events
383+
eventService.subscribe(DirectoryService.WORKING_DIRECTORY_UPDATE_EVENT, event -> {
384+
Path path = (Path) event.getData();
385+
getStage().setTitle(String.format("AsciidocFX - %s", path));
386+
});
387+
}
388+
376389
public void createAsciidocTable() {
377390
asciidocTableStage.showAndWait();
378391
}
@@ -2548,7 +2561,7 @@ public String readAsciidoctorResource(String uri, Integer parent) {
25482561
return String.format("link:%s[]", uri);
25492562
}
25502563

2551-
PathFinderService fileReader = applicationContext.getBean("pathFinder", PathFinderService.class);
2564+
PathFinderService fileReader = applicationContext.getBean(PathFinderService.label, PathFinderService.class);
25522565
Path path = fileReader.findPath(uri, parent);
25532566

25542567
if (!Files.exists(path)) {

src/main/java/com/kodedu/service/DirectoryService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
* Created by usta on 25.12.2014.
1313
*/
1414
public interface DirectoryService {
15+
public final static String label = "core::service::DirectoryService";
16+
17+
/**
18+
* Notify a working directory update. Sends a nullable {@link java.nio.file.Path}.
19+
*/
20+
public final static String WORKING_DIRECTORY_UPDATE_EVENT = "event::directory::workingdirectory::update";
1521

1622
public DirectoryChooser newDirectoryChooser(String title);
1723

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.kodedu.service;
2+
3+
import java.util.Date;
4+
import java.util.function.Consumer;
5+
6+
/**
7+
* Used to share state changes accross the application
8+
* @author Ayowel
9+
* @since RC-SNAPSHOT
10+
*/
11+
public interface EventService {
12+
/**
13+
* The default service label to use
14+
*/
15+
public final static String label = "core::service::EventService";
16+
17+
/**
18+
* Propagate an event to all subscribed listeners
19+
* @param label
20+
* The label of the event to subscribe to.
21+
* Label have scopes separated with :: scopes must be alpha-numerical
22+
* @param data The dataset associated to the dispatched event
23+
*/
24+
public void sendEvent(String label, Object data);
25+
26+
/**
27+
* Subscribe to receive event notifications
28+
* @param eventLabel The name of the event to listen for. May use a whole-scope wildcard with * instead of a scope's name
29+
* @param callback A consumer to call when the event is triggered
30+
* @return An event subscription object used to unsubscribe if needs be
31+
* @see #sendEvent(String, Object)
32+
*/
33+
public Subscription subscribe(String eventLabel, Consumer<Event> callback);
34+
35+
/**
36+
* Stop receiving event notifications for a subscription
37+
* @param subscription The event subscription to cancel
38+
*/
39+
public void unsubscribe(Subscription subscription);
40+
41+
/**
42+
* Represents a subscription to an event
43+
* @author Ayowel
44+
* @since RC-SNAPSHOT
45+
*/
46+
public interface Subscription { }
47+
48+
/**
49+
* Event object
50+
* @author Ayowel
51+
* @since RC-SNAPSHOT
52+
* @param <T> The data type propagated by the event
53+
*/
54+
public interface Event {
55+
/**
56+
* The label of the event
57+
* @return
58+
*/
59+
public String getLabel();
60+
/**
61+
* The event's payload
62+
* @return
63+
*/
64+
public Object getData();
65+
66+
/**
67+
* The event's creation timestamp
68+
* @return
69+
*/
70+
public Date getTimestamp();
71+
}
72+
}

src/main/java/com/kodedu/service/FileWatchService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Created by usta on 31.12.2014.
99
*/
1010
public interface FileWatchService {
11+
public final static String label = "core::service::FileWatch";
1112

1213
public void reCreateWatchService();
1314

src/main/java/com/kodedu/service/ParserService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Created by usta on 16.12.2014.
1010
*/
1111
public interface ParserService {
12+
public final static String label = "core::service::Parser";
1213

1314
public Optional<String> toIncludeBlock(List<File> dropFiles);
1415

src/main/java/com/kodedu/service/PathFinderService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Created by usta on 20.05.2015.
77
*/
88
public interface PathFinderService {
9+
public final static String label = "core::service::PathFinder";
910

1011
public Path findPath(String uri, Integer parent);
1112
}

src/main/java/com/kodedu/service/PathOrderService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Created by usta on 01.01.2015.
77
*/
88
public interface PathOrderService {
9+
public final static String label = "core::service::PathOrder";
910

1011
public int comparePaths(Path first, Path second);
1112

src/main/java/com/kodedu/service/PathResolverService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Created by usta on 07.09.2014.
77
*/
88
public interface PathResolverService {
9+
public final static String label = "core::service::PathResolver";
910

1011
public boolean isPDF(Path path);
1112

@@ -25,7 +26,6 @@ public interface PathResolverService {
2526

2627
public boolean isOffice(Path path);
2728

28-
2929
public boolean isBook(Path path);
3030

3131
public boolean isMobi(Path path);

src/main/java/com/kodedu/service/SampleBookService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Created by usta on 02.09.2014.
77
*/
88
public interface SampleBookService {
9+
public final static String label = "core::service::SampleBook";
910

1011
public void produceSampleBook(Path configPath, Path outputPath);
1112
}

src/main/java/com/kodedu/service/ThreadService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Created by usta on 25.12.2014.
1414
*/
1515
public interface ThreadService {
16+
public final static String label = "core::service::ThreadService";
1617

1718
public ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit timeUnit);
1819

0 commit comments

Comments
 (0)