Rework connection sharing

This commit is contained in:
crschnick 2023-12-11 17:52:45 +00:00
parent 42f83e331a
commit 6df9169e38
5 changed files with 35 additions and 12 deletions

View file

@ -122,8 +122,8 @@ public interface DataStoreProvider {
default void storageInit() throws Exception {}
default boolean isShareable() {
return false;
default boolean isShareable(DataStoreEntry entry) {
return true;
}
default String summaryString(StoreEntryWrapper wrapper) {

View file

@ -161,6 +161,38 @@ public abstract class DataStorage {
public abstract void save();
public abstract boolean supportsSharing();
public boolean shouldShare(DataStoreCategory entry) {
if (!entry.canShare()) {
return false;
}
DataStoreCategory c = entry;
do {
if (!c.shouldShareChildren()) {
return false;
}
} while ((c = DataStorage.get()
.getStoreCategoryIfPresent(c.getParentCategory())
.orElse(null))
!= null);
return true;
}
public boolean shouldShare(DataStoreEntry entry) {
if (!shouldShare(DataStorage.get()
.getStoreCategoryIfPresent(entry.getCategoryUuid())
.orElseThrow())) {
return false;
}
DataStoreEntry c = entry;
do {
if (!c.getProvider().isShareable(c)) {
return false;
}
} while ((c = DataStorage.get().getDisplayParent(c).orElse(null)) != null);
return true;
}
protected void refreshValidities(boolean makeValid) {
var changed = new AtomicBoolean(false);

View file

@ -57,7 +57,7 @@ public class ShareStoreAction implements ActionProvider {
@Override
public boolean isApplicable(DataStoreEntryRef<DataStore> o) {
return o.get().getProvider().isShareable();
return o.get().getProvider().isShareable(o.get());
}
@Override

View file

@ -24,10 +24,6 @@ import java.util.List;
public class ScriptGroupStoreProvider implements DataStoreProvider {
public boolean isShareable() {
return true;
}
@Override
public Comp<?> customEntryComp(StoreSection sec, boolean preferLarge) {
ScriptGroupStore s = sec.getWrapper().getEntry().getStore().asNeeded();

View file

@ -89,11 +89,6 @@ public class SimpleScriptStoreProvider implements DataStoreProvider {
return true;
}
@Override
public boolean isShareable() {
return true;
}
@Override
public DataStoreEntry getDisplayParent(DataStoreEntry store) {
SimpleScriptStore st = store.getStore().asNeeded();