mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-18 10:13:38 +00:00
Rework [stage]
This commit is contained in:
parent
43a7978f5d
commit
0d3c04b822
6 changed files with 81 additions and 26 deletions
|
@ -2,7 +2,9 @@ package io.xpipe.app.comp.store;
|
|||
|
||||
import io.xpipe.app.comp.SimpleComp;
|
||||
|
||||
import io.xpipe.app.util.BooleanScope;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.input.MouseButton;
|
||||
|
@ -19,27 +21,36 @@ public class StoreEntryBatchSelectComp extends SimpleComp {
|
|||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var selfUpdate = new SimpleBooleanProperty(false);
|
||||
var cb = new CheckBox();
|
||||
cb.setAllowIndeterminate(true);
|
||||
cb.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
StoreViewState.get().selectBatchMode(section);
|
||||
} else {
|
||||
StoreViewState.get().unselectBatchMode(section);
|
||||
}
|
||||
BooleanScope.executeExclusive(selfUpdate, () -> {
|
||||
if (newValue) {
|
||||
StoreViewState.get().selectBatchMode(section);
|
||||
} else {
|
||||
StoreViewState.get().unselectBatchMode(section);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
StoreViewState.get().getBatchModeSelection().getList().addListener((ListChangeListener<
|
||||
? super StoreEntryWrapper>)
|
||||
c -> {
|
||||
if (selfUpdate.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
update(cb);
|
||||
externalUpdate(cb);
|
||||
});
|
||||
});
|
||||
section.getShownChildren().getList().addListener((ListChangeListener<? super StoreSection>) c -> {
|
||||
if (cb.isSelected()) {
|
||||
StoreViewState.get().selectBatchMode(section);
|
||||
}
|
||||
BooleanScope.executeExclusive(selfUpdate, () -> {
|
||||
if (cb.isSelected()) {
|
||||
StoreViewState.get().selectBatchMode(section);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cb.getStyleClass().add("batch-mode-selector");
|
||||
|
@ -52,7 +63,7 @@ public class StoreEntryBatchSelectComp extends SimpleComp {
|
|||
return cb;
|
||||
}
|
||||
|
||||
private void update(CheckBox checkBox) {
|
||||
private void externalUpdate(CheckBox checkBox) {
|
||||
var isSelected = StoreViewState.get().isSectionSelected(section);
|
||||
checkBox.setSelected(isSelected);
|
||||
if (section.getShownChildren().getList().size() == 0) {
|
||||
|
@ -62,7 +73,7 @@ public class StoreEntryBatchSelectComp extends SimpleComp {
|
|||
|
||||
var count = section.getShownChildren().getList().stream()
|
||||
.filter(c ->
|
||||
StoreViewState.get().getBatchModeSelection().getList().contains(c.getWrapper()))
|
||||
StoreViewState.get().isBatchModeSelected(c.getWrapper()))
|
||||
.count();
|
||||
checkBox.setIndeterminate(
|
||||
count > 0 && count != section.getShownChildren().getList().size());
|
||||
|
|
|
@ -50,6 +50,8 @@ public class StoreViewState {
|
|||
@Getter
|
||||
private final DerivedObservableList<StoreEntryWrapper> batchModeSelection = DerivedObservableList.synchronizedArrayList(true);
|
||||
|
||||
private final Set<StoreEntryWrapper> batchModeSelectionSet = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
private boolean initialized = false;
|
||||
|
||||
|
@ -107,10 +109,13 @@ public class StoreViewState {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public boolean isBatchModeSelected(StoreEntryWrapper entry) {
|
||||
return batchModeSelectionSet.contains(entry);
|
||||
}
|
||||
|
||||
public void selectBatchMode(StoreSection section) {
|
||||
System.out.println("Select " + section.getWrapper());
|
||||
var wrapper = section.getWrapper();
|
||||
if (wrapper != null && !batchModeSelection.getList().contains(wrapper)) {
|
||||
if (wrapper != null && !batchModeSelectionSet.contains(wrapper)) {
|
||||
batchModeSelection.getList().add(wrapper);
|
||||
}
|
||||
if (wrapper == null
|
||||
|
@ -134,11 +139,10 @@ public class StoreViewState {
|
|||
|
||||
public boolean isSectionSelected(StoreSection section) {
|
||||
if (section.getWrapper() == null) {
|
||||
var batchSet = new HashSet<>(batchModeSelection.getList());
|
||||
var childSet = section.getShownChildren().getList().stream()
|
||||
.map(s -> s.getWrapper())
|
||||
.toList();
|
||||
return batchSet.containsAll(childSet);
|
||||
return batchModeSelectionSet.containsAll(childSet);
|
||||
}
|
||||
|
||||
return getBatchModeSelection().getList().contains(section.getWrapper());
|
||||
|
@ -150,17 +154,10 @@ public class StoreViewState {
|
|||
}
|
||||
|
||||
private void initSections() {
|
||||
// Faster selection check with a hash set
|
||||
var set = new HashSet<>(batchModeSelection.getList());
|
||||
batchModeSelection.getList().addListener((ListChangeListener<? super StoreEntryWrapper>) c -> {
|
||||
set.clear();
|
||||
set.addAll(c.getList());
|
||||
});
|
||||
|
||||
try {
|
||||
currentTopLevelSection = StoreSection.createTopLevel(
|
||||
allEntries,
|
||||
set,
|
||||
batchModeSelectionSet,
|
||||
storeEntryWrapper -> true,
|
||||
filter,
|
||||
activeCategory,
|
||||
|
@ -193,6 +190,21 @@ public class StoreViewState {
|
|||
}
|
||||
|
||||
private void initBatchListeners() {
|
||||
batchModeSelection.getList().addListener((ListChangeListener<? super StoreEntryWrapper>) c -> {
|
||||
if (c.getList().isEmpty()) {
|
||||
batchModeSelectionSet.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
while (c.next()) {
|
||||
if (c.wasAdded()) {
|
||||
batchModeSelectionSet.addAll(c.getAddedSubList());
|
||||
} else if (c.wasRemoved()) {
|
||||
c.getRemoved().forEach(batchModeSelectionSet::remove);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
allEntries.getList().addListener((ListChangeListener<? super StoreEntryWrapper>) c -> {
|
||||
batchModeSelection.getList().retainAll(c.getList());
|
||||
});
|
||||
|
|
|
@ -7,8 +7,8 @@ import lombok.Setter;
|
|||
|
||||
@Getter
|
||||
public enum PredefinedScriptGroup {
|
||||
MANAGEMENT("Management", "Some commonly used management scripts", true),
|
||||
FILES("Files", "Scripts for files", true);
|
||||
MANAGEMENT("Management", "Sample management scripts", true),
|
||||
FILES("Files", "Sample scripts for files", true);
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
|
|
@ -40,6 +40,12 @@ public enum PredefinedScriptStore {
|
|||
.minimumDialect(null)
|
||||
.commands(file(("git_config.sh")))
|
||||
.runnableScript(true)
|
||||
.build()),
|
||||
SYSTEM_HEALTH_STATUS("System health status", () -> SimpleScriptStore.builder()
|
||||
.group(PredefinedScriptGroup.MANAGEMENT.getEntry())
|
||||
.minimumDialect(ShellDialects.SH)
|
||||
.commands(file(("system_health.sh")))
|
||||
.initScript(true)
|
||||
.build());
|
||||
|
||||
private final String name;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
DELIMITER="-------------------------------------"
|
||||
|
||||
hostname -f &> /dev/null && printf "Hostname : $(hostname -f)" || printf "Hostname : $(hostname -s)"
|
||||
|
||||
[ -f /etc/os-release ] && echo $(egrep -w "NAME|VERSION" /etc/os-release|awk -F= '{ print $2 }'|sed 's/"//g') || cat /etc/system-release
|
||||
|
||||
echo -e "Kernel Version :" $(uname -r)
|
||||
printf "OS Architecture :"$(arch | grep x86_64 &> /dev/null) && printf " 64 Bit OS\n" || printf " 32 Bit OS\n"
|
||||
|
||||
echo -en "System Uptime : " $(uptime -p)
|
||||
echo -e "\nCurrent System Date & Time : "$(date +%c)
|
||||
|
||||
echo -e "Total Swap Memory in MiB : "$(grep -w SwapTotal /proc/meminfo|awk '{print $2/1024}')", in GiB : "\
|
||||
$(grep -w SwapTotal /proc/meminfo|awk '{print $2/1024/1024}')
|
||||
echo -e "Swap Free Memory in MiB : "$(grep -w SwapFree /proc/meminfo|awk '{print $2/1024}')", in GiB : "\
|
||||
$(grep -w SwapFree /proc/meminfo|awk '{print $2/1024/1024}')
|
||||
|
||||
echo -e "\n\nMost Recent 3 Reboots"
|
||||
echo -e "$DELIMITER$DELIMITER"
|
||||
last -x 2> /dev/null|grep reboot 1> /dev/null && /usr/bin/last -x 2> /dev/null|grep reboot|head -3 || \
|
||||
echo -e "No reboot events are recorded."
|
||||
|
||||
echo -e "\n\nMost Recent 3 Shutdowns"
|
||||
echo -e "$DELIMITER$DELIMITER"
|
||||
last -x 2> /dev/null|grep shutdown 1> /dev/null && /usr/bin/last -x 2> /dev/null|grep shutdown|head -3 || \
|
||||
echo -e "No shutdown events are recorded."
|
2
version
2
version
|
@ -1 +1 @@
|
|||
16.0-24
|
||||
16.0-25
|
||||
|
|
Loading…
Add table
Reference in a new issue