Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Feb 4, 2024
1 parent 01030ae commit d739b4c
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 214 deletions.
16 changes: 0 additions & 16 deletions src/main/java/viewtify/ui/dock/DockItem.java

This file was deleted.

23 changes: 16 additions & 7 deletions src/main/java/viewtify/ui/dock/DockModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,37 @@
import kiss.I;
import kiss.Variable;
import kiss.WiseConsumer;
import viewtify.ui.UITab;
import viewtify.ui.View;

@Icy
public abstract class DockModel {

@Property
public abstract String id();
public abstract Class<? extends View> view();

@Property
public abstract Variable<String> title();
public abstract WiseConsumer<Dock> registration();

@Property
public abstract WiseConsumer<UITab> content();
public String id() {
return I.make(view()).id();
}

public Variable<String> title() {
return I.make(view()).title();
}

@Property
public UnaryOperator<DockRecommendedLocation> location() {
return UnaryOperator.identity();
}

public void register() {
registration().accept((Dock) this);
}

public static Dock of(Class<? extends View> type) {
View view = I.make(type);
return Dock.with.id(view.id()).content(tab -> tab.contentsLazy(type)).title(view.title());
return Dock.with.view(type).registration(dock -> {
DockSystem.register(dock.id()).text(dock.title()).contentsLazy(tab -> I.make(dock.view()));
});
}
}
94 changes: 94 additions & 0 deletions src/main/java/viewtify/ui/dock/DockProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2023 Nameless Production Committee
*
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://opensource.org/licenses/mit-license.php
*/
package viewtify.ui.dock;

import java.lang.reflect.Modifier;
import java.util.Comparator;
import java.util.List;

import kiss.Extensible;
import kiss.I;
import kiss.Managed;
import kiss.Model;
import kiss.Singleton;
import kiss.;

@Managed(Singleton.class)
public abstract class DockProvider implements Extensible {

/** The managed independent dock items. */
private List<Dock> independents;

private List<<TypedDock, Class>> typed;

/**
* Initialize and analyze
*/
protected DockProvider() {
}

private List<Dock> docks() {
if (independents == null) {
independents = I.signal(getClass().getFields())
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == Dock.class)
.map(field -> (Dock) field.get(this))
.sort(Comparator.comparing(Dock::id))
.toList();
}
return independents;
}

private List<<TypedDock, Class>> typed() {
if (typed == null) {
typed = I.signal(getClass().getFields())
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == TypedDock.class)
.map(field -> I
.pair((TypedDock) field.get(this), (Class) Model.collectParameters(field.getGenericType(), TypedDock.class)[0]))
.toList();
}
return typed;
}

/**
* Query all independent views.
*/
public List<Dock> queryIndependentDocks() {
return docks();
}

/**
* Request registering dock by id.
*
* @param id
* @return
*/
protected boolean register(String id) {
for (Dock dock : docks()) {
if (dock.id().equals(id)) {
dock.registration.accept(dock);
return true;
}
}

int index = id.indexOf(' ');
if (index != -1) {
String prefix = id.substring(0, index);
String param = id.substring(index + 1);

for (<TypedDock, Class> dock : typed()) {
if (dock..id.equalsIgnoreCase(prefix)) {
dock..register(I.transform(param, dock.));
}
}
}

return false;
}
}
143 changes: 0 additions & 143 deletions src/main/java/viewtify/ui/dock/DockRegister.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/viewtify/ui/dock/DockSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ public static void initializeLayout(WiseRunnable defaultLayout) {
defaultLayout.run();
} else {
layout.find(TabArea.class).flatIterable(TabArea::getIds).to(id -> {
for (DockRegister register : I.find(DockRegister.class)) {
if (register.queryBy(id)) {
for (DockProvider register : I.find(DockProvider.class)) {
if (register.register(id)) {
break;
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/viewtify/ui/dock/DockType.java

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/java/viewtify/ui/dock/TypedDockModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 Nameless Production Committee
*
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://opensource.org/licenses/mit-license.php
*/
package viewtify.ui.dock;

import java.util.function.UnaryOperator;

import icy.manipulator.Icy;
import icy.manipulator.Icy.Property;
import kiss.I;
import kiss.WiseBiConsumer;
import viewtify.ui.UITab;

@Icy
public abstract class TypedDockModel<T> {

@Property
public abstract String id();

@Property
public abstract WiseBiConsumer<UITab, T> registration();

@Property
public UnaryOperator<DockRecommendedLocation> location() {
return UnaryOperator.identity();
}

public void register(T param) {
UITab tab = DockSystem.register(id() + " " + I.transform(param, String.class));
registration().accept(tab, param);
}
}
Loading

0 comments on commit d739b4c

Please sign in to comment.