Skip to content

Commit

Permalink
Refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Aug 8, 2023
1 parent d14088d commit c84db86
Show file tree
Hide file tree
Showing 90 changed files with 119 additions and 265 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The feature set is the same for all supported connection types. It of course als

<br>
<p align="center">
<img src="https://github.com/xpipe-io/xpipe/assets/72509152/f3d29909-acd7-4568-a625-0667d936ef2b" />
<img src="https://github.com/xpipe-io/xpipe/assets/72509152/f3d29909-acd7-4568-a625-0667d936ef2b" alt="Terminal launcher"/>
</p>
<br>

Expand Down
6 changes: 2 additions & 4 deletions api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public static DataSource create(DataStoreId id, String type, DataStore store) {
.configureAll(false)
.build();
var startRes = XPipeApiConnection.execute(con -> {
ReadExchange.Response r = con.performSimpleExchange(startReq);
return r;
return con.<ReadExchange.Request, ReadExchange.Response>performSimpleExchange(startReq);
});

var configInstance = startRes.getConfig();
Expand Down Expand Up @@ -113,8 +112,7 @@ public static DataSource create(DataStoreId id, String type, InputStream in) {
.configureAll(false)
.build();
var startRes = XPipeApiConnection.execute(con -> {
ReadExchange.Response r = con.performSimpleExchange(startReq);
return r;
return con.<ReadExchange.Request, ReadExchange.Response>performSimpleExchange(startReq);
});

var configInstance = startRes.getConfig();
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/xpipe/api/impl/DataTableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ArrayNode read(int maxRows) {

@Override
public Iterator<TupleNode> iterator() {
return new Iterator<TupleNode>() {
return new Iterator<>() {
@Override
public boolean hasNext() {
return false;
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dependencies {
testImplementation project(':core')
}

project.allExtensions.forEach(p -> {
project.allExtensions.forEach((Project p) -> {
dependencies {
testCompileOnly p
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/io/xpipe/app/browser/BrowserClipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static void startCopy(FileSystem.FileEntry base, List<FileSystem.FileEntr
}

public static Instance retrieveCopy() {
var current = currentCopyClipboard;
return current.getValue();
return currentCopyClipboard.getValue();
}

public static Instance retrieveDrag(Dragboard dragboard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ private void createMenu() {
}

private static List<BrowserEntry> resolveIfNeeded(BrowserAction action, List<BrowserEntry> selected) {
var used = action.automaticallyResolveLinks()
return action.automaticallyResolveLinks()
? selected.stream()
.map(browserEntry -> new BrowserEntry(
browserEntry.getRawFileEntry().resolved(),
browserEntry.getModel(),
browserEntry.isSynthetic()))
.toList()
: selected;
return used;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public BrowserFileListComp(BrowserFileListModel fileList) {

@Override
protected Region createSimple() {
TableView<BrowserEntry> table = createTable();
return table;
return createTable();
}

@SuppressWarnings("unchecked")
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/io/xpipe/app/browser/BrowserNavBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ protected Region createSimple() {

var graphic = Bindings.createStringBinding(
() -> {
var icon = model.getCurrentDirectory() != null
return model.getCurrentDirectory() != null
? FileIconManager.getFileIcon(model.getCurrentDirectory(), false)
: "home_icon.svg";
return icon;
},
model.getCurrentPath());
var breadcrumbsGraphic = new PrettyImageComp(graphic, 22, 22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ protected Region createSimple() {
.map(s -> FileSystem.FileEntry.ofDirectory(model.getFileSystem(), s))
.filter(entry -> {
try {
var b = sc.getShellDialect()
return sc.getShellDialect()
.directoryExists(sc, entry.getPath())
.executeAndCheck();
return b;
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
public class BrowserSavedState {

static BrowserSavedState load() {
BrowserSavedState state = AppCache.get("browser-state", BrowserSavedState.class, () -> {
return AppCache.get("browser-state", BrowserSavedState.class, () -> {
return null;
});
return state;
}

@Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static Image snapshot(ObservableList<FileSystem.FileEntry> list) {
AppStyle.addStylesheets(scene);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
WritableImage image = r.snapshot(parameters, null);
return image;
return r.snapshot(parameters, null);
}

ObservableList<FileSystem.FileEntry> list;
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/io/xpipe/app/comp/DeveloperTabComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ protected Region createSimple() {

var button5 = new ButtonComp(AppI18n.observable("Operation mode null"), null, OperationMode::close);

var box = new HBox(
return new HBox(
button.createRegion(),
button2.createRegion(),
button3.createRegion(),
button4.createRegion(),
button5.createRegion());
return box;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/io/xpipe/app/comp/base/CountComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CompStructure<Label> createBase() {
if (sub.size() == all.size()) {
return all.size() + "";
} else {
return "" + sub.size() + "/" + all.size();
return sub.size() + "/" + all.size();
}
},
sub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected Region createSimple() {
}

private Region createOpenButton(Region container) {
var button = new IconButtonComp(
return new IconButtonComp(
"mdal-edit",
() -> FileOpener.openString(
identifier + (fileType.getValue() != null ? "." + fileType.getValue() : ""),
Expand All @@ -59,6 +59,5 @@ private Region createOpenButton(Region container) {
Platform.runLater(() -> value.setValue(s));
}))
.createRegion();
return button;
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/io/xpipe/app/comp/base/MarkdownComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -87,7 +87,7 @@ private void addLinkHandler(WebEngine engine) {
if (toBeopen.contains("http://") || toBeopen.contains("https://")) {
engine.getLoadWorker().cancel();
try {
Desktop.getDesktop().browse(new URL(toBeopen).toURI());
Desktop.getDesktop().browse(URI.create(toBeopen));
} catch (Exception e) {
ErrorEvent.fromThrowable(e).omit().handle();
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/io/xpipe/app/comp/base/OsLogoComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ private String getImage(String name) {
});
}

var found = ICONS.entrySet().stream().filter(e->name.toLowerCase().contains(e.getKey())).findAny().map(e->e.getValue()).orElse("os/" + LINUX_DEFAULT);
return found;
return ICONS.entrySet().stream().filter(e->name.toLowerCase().contains(e.getKey())).findAny().map(e->e.getValue()).orElse("os/" + LINUX_DEFAULT);
}
}
11 changes: 5 additions & 6 deletions app/src/main/java/io/xpipe/app/comp/base/SystemStateComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SystemStateComp(ObservableValue<State> state) {
this.state = state;
}

public static enum State {
public enum State {
FAILURE,
SUCCESS,
OTHER
Expand All @@ -29,16 +29,15 @@ public static enum State {
private final ObservableValue<State> state;

public SystemStateComp(StoreEntryWrapper w) {
var state = Bindings.createObjectBinding(
this.state = Bindings.createObjectBinding(
() -> {
return w.getState().getValue() == DataStoreEntry.State.COMPLETE_BUT_INVALID
? SystemStateComp.State.FAILURE
? State.FAILURE
: w.getState().getValue() == DataStoreEntry.State.COMPLETE_AND_VALID
? SystemStateComp.State.SUCCESS
: SystemStateComp.State.OTHER;
? State.SUCCESS
: State.OTHER;
},
w.getState());
this.state = state;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ protected Region createContent() {
var grid = new GridPane();
grid.setHgap(8);

int index = 0;
if (showIcon) {
var storeIcon = createIcon(26, 21);
grid.getColumnConstraints().add(new ColumnConstraints(26));
grid.add(storeIcon, 0, 0);
GridPane.setHalignment(storeIcon, HPos.CENTER);
index++;
}

var customSize = content != null ? 300 : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ protected final Region createSimple() {
new ContextMenuAugment<>(() -> this.createContextMenu()).augment(new SimpleCompStructure<>(button));

var loading = new LoadingOverlayComp(Comp.of(() -> button), wrapper.getValidating());
var region = loading.createRegion();
return region;
return loading.createRegion();
}

protected abstract Region createContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ protected Region createSimple() {
var label =
new Label(entry.getName(), new PrettyImageComp(new SimpleStringProperty(image), 20, 20).createRegion());
var spacer = new Spacer(depth * 10, Orientation.HORIZONTAL);
var box = new HBox(spacer, label);
return box;
return new HBox(spacer, label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class StoreNotFoundComp extends SimpleComp {

@Override
public Region createSimple() {
var sp = new StackPane();
return sp;
return new StackPane();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void detectOnPaste() {
}

private static boolean showAlert() {
var paste = AppWindowHelper.showBlockingAlert(alert -> {
return AppWindowHelper.showBlockingAlert(alert -> {
alert.setAlertType(Alert.AlertType.CONFIRMATION);
alert.setTitle(AppI18n.get("clipboardActionDetectedTitle"));
alert.setHeaderText(AppI18n.get("clipboardActionDetectedHeader"));
Expand All @@ -70,6 +70,5 @@ private static boolean showAlert() {
})
.map(buttonType -> buttonType.getButtonData().isDefaultButton())
.orElse(false);
return paste;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/io/xpipe/app/core/AppFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void loadFonts() {
"fonts",
path -> Files.walkFileTree(path, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try (var in = Files.newInputStream(file)) {
Font.loadFont(in, 12);
} catch (Throwable t) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/io/xpipe/app/core/AppGreetings.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private static TitledPane createEULA() {

public static void showIfNeeded() {
// TODO
//noinspection PointlessBooleanExpression
if (!AppProperties.get().isImage() || true) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public class MessageExchangeImpls {
public static void loadAll() {
ALL = ServiceLoader.load(MessageExchangeImpl.class).stream()
.map(s -> {
var ex = (MessageExchangeImpl<?, ?>) s.get();
// TrackEvent.trace("init", "Loaded exchange implementation " + ex.getId());
return ex;
return (MessageExchangeImpl<?, ?>) s.get();
})
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ReadDrainExchangeImpl extends ReadDrainExchange
implements MessageExchangeImpl<ReadDrainExchange.Request, ReadDrainExchange.Response> {

@Override
public Response handleRequest(BeaconHandler handler, Request msg) throws Exception {
public Response handleRequest(BeaconHandler handler, Request msg) {
return ReadDrainExchange.Response.builder().build();
}
}
8 changes: 3 additions & 5 deletions app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ default Comp<?> createInsightsComp(ObservableValue<DataStore> store) {
return createInsightsMarkdown(store.getValue());
},
store);
var markdown = new MarkdownComp(content, s -> s)
return new MarkdownComp(content, s -> s)
.apply(struc -> struc.get().setPrefWidth(450))
.apply(struc -> struc.get().setPrefHeight(200));
return markdown;
}

default String createInsightsMarkdown(DataStore store) {
Expand Down Expand Up @@ -124,7 +123,7 @@ default String queryInformationString(DataStore store, int length) throws Except
return null;
}

default String queryInvalidInformationString(DataStore store, int length) throws Exception {
default String queryInvalidInformationString(DataStore store, int length) {
return "Connection failed";
}

Expand Down Expand Up @@ -160,8 +159,7 @@ default String getDisplayIconFileName(DataStore store) {
return png;
}

var svg = getModuleName() + ":" + getId() + "_icon.svg";
return svg;
return getModuleName() + ":" + getId() + "_icon.svg";
}

default Dialog dialogForStore(DataStore store) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {

public static <T extends DataStore> DataStoreChoiceComp<T> other(Property<T> selected, Class<T> clazz, Predicate<T> filter) {
return new DataStoreChoiceComp<T>(Mode.OTHER, null, selected, clazz, filter);
return new DataStoreChoiceComp<>(Mode.OTHER, null, selected, clazz, filter);
}

public static DataStoreChoiceComp<ShellStore> proxy(Property<ShellStore> selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ public CompStructure<Pane> createBase() {
return Region.USE_COMPUTED_SIZE;
}

var m = compRegions.stream()
return compRegions.stream()
.map(Region::getWidth)
.max(Double::compareTo)
.orElse(0.0);
return m;
},
compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
compRegions.forEach(r -> r.prefWidthProperty().bind(compWidthBinding));
Expand All @@ -117,11 +116,10 @@ public CompStructure<Pane> createBase() {
return Region.USE_COMPUTED_SIZE;
}

var m = nameRegions.stream()
return nameRegions.stream()
.map(Region::getWidth)
.max(Double::compareTo)
.orElse(0.0);
return m;
},
nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
nameRegions.forEach(r -> r.prefWidthProperty().bind(nameWidthBinding));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public FileSystemStoreChoiceComp(Property<FileSystemStore> selected) {
}

private static String getName(FileSystemStore store) {
var name = DataStorage.get().getUsableStores().stream()
return DataStorage.get().getUsableStores().stream()
.filter(e -> e.equals(store))
.findAny()
.map(e -> DataStorage.get().getStoreDisplayName(e).orElse("?"))
.orElse("?");
return name;
}

private Region createGraphic(FileSystemStore s) {
Expand Down
Loading

0 comments on commit c84db86

Please sign in to comment.