Skip to content

Commit

Permalink
Improve datasource configuration in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Sep 23, 2024
1 parent 75a2b90 commit 9ec3bb4
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 65 deletions.
6 changes: 5 additions & 1 deletion sdmx-dl-desktop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<groupId>com.github.nbbrd.java-desktop-util</groupId>
<artifactId>java-desktop-util-chart</artifactId>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-desktop-util</groupId>
<artifactId>java-desktop-util-os</artifactId>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
Expand Down Expand Up @@ -116,7 +120,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>sdmx-dl-provider-ri</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<!-- <scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ private ImageIcon loadImage() {
return new FlatSVGIcon("sdmxdl/desktop/SDMX_logo.svg", 16, 16);
}

public Icon getIcon(String source, int size, Runnable onUpdate) {
return getIcon(properties.getSdmxManager().getSources().get(source), size, onUpdate);
}

public Icon getIcon(DataSourceRef dataSourceRef, int size, Runnable onUpdate) {
return getIcon(dataSourceRef.getSource(), size, onUpdate);
return getIcon(dataSourceRef.toWebSource(properties.getSdmxManager()), size, onUpdate);
}

public Icon getIcon(WebSource source, int size, Runnable onUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class DataSourceBean {
String flow;
List<String> dimensions;
String languages;
boolean debug;

static DataSourceBean from(DataSourceRef ref) {
DataSourceBean result = new DataSourceBean();
Expand All @@ -56,6 +57,7 @@ static DataSourceBean from(DataSourceRef ref) {
result.flow = ref.getFlow();
result.dimensions = ref.getDimensions();
result.languages = ref.getLanguages().toString();
result.debug = ref.isDebug();
return result;
}

Expand All @@ -67,6 +69,7 @@ DataSourceRef to() {
.flow(flow)
.dimensions(dimensions != null ? dimensions : emptyList())
.languages(Languages.parse(languages))
.debug(debug)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.function.Consumer;

public final class Actions {
Expand All @@ -16,6 +17,7 @@ private Actions() {
return onActionPerformed(ignore -> action.run());
}


public static @NonNull Action onActionPerformed(@NonNull Consumer<? super ActionEvent> action) {
return new AbstractAction() {
@Override
Expand All @@ -24,4 +26,16 @@ public void actionPerformed(ActionEvent e) {
}
};
}

public static <C extends AbstractButton> @NonNull C hideWhenDisabled(@NonNull C c) {
c.setVisible(c.isEnabled());
c.addPropertyChangeListener(HIDE);
return c;
}

private static final PropertyChangeListener HIDE = evt -> {
if ("enabled".equals(evt.getPropertyName()) && evt.getSource() instanceof JComponent) {
((JComponent) evt.getSource()).setVisible((Boolean) evt.getNewValue());
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<? extends Object> getChildren(Object userObject) throws Exception {
}

private static List<DataSetRef> getChildren(SdmxWebManager manager, DataSourceRef dataSourceRef, Key key) throws IOException {
try (Connection conn = manager.getConnection(dataSourceRef.getSource(), dataSourceRef.getLanguages())) {
try (Connection conn = dataSourceRef.getConnection(manager)) {
Structure dsd = conn.getStructure(dataSourceRef.getCatalog(), dataSourceRef.toFlowRef());
List<sdmxdl.Dimension> dimensionList = dsd.getDimensionList();
Key.Builder builder = Key.builder(dsd);
Expand Down
38 changes: 35 additions & 3 deletions sdmx-dl-desktop/src/main/java/sdmxdl/desktop/DataSourceRef.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package sdmxdl.desktop;

import lombok.NonNull;
import sdmxdl.CatalogRef;
import sdmxdl.FlowRef;
import sdmxdl.Languages;
import nbbrd.io.sys.SystemProperties;
import sdmxdl.*;
import sdmxdl.provider.ri.caching.RiCaching;
import sdmxdl.provider.ri.drivers.RiHttpUtils;
import sdmxdl.web.SdmxWebManager;
import sdmxdl.web.WebSource;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import static java.util.Objects.requireNonNull;

@lombok.Value
@lombok.Builder(toBuilder = true)
Expand All @@ -30,7 +38,31 @@ public class DataSourceRef {
@NonNull
Languages languages = Sdmxdl.INSTANCE.getLanguages();

@lombok.Singular
Map<String, String> properties;

@lombok.Builder.Default
boolean debug = false;

public FlowRef toFlowRef() {
return FlowRef.parse(flow);
}

public WebSource toWebSource(SdmxWebManager manager) {
WebSource result = manager.getSources().get(source);
if (result == null) return null;
WebSource.Builder builder = result.toBuilder().properties(properties);
if (debug) {
Path tmp = requireNonNull(SystemProperties.DEFAULT.getJavaIoTmpdir()).resolve(About.NAME).resolve("debug_" + source);
builder.property(RiHttpUtils.DUMP_FOLDER_PROPERTY.getKey(), tmp.resolve("dump").toString());
builder.property(RiCaching.CACHE_FOLDER_PROPERTY.getKey(), tmp.resolve("cache").toString());
builder.property(RiCaching.NO_COMPRESSION_PROPERTY.getKey(), "true");
builder.property(RiCaching.PERSISTENCE_ID_PROPERTY.getKey(), "JSON");
}
return builder.build();
}

public Connection getConnection(SdmxWebManager manager) throws IOException {
return manager.getConnection(toWebSource(manager), languages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FlowStruct {
Structure structure;

public static FlowStruct load(SdmxWebManager manager, DataSourceRef ref) throws IOException {
try (Connection conn = manager.getConnection(ref.getSource(), ref.getLanguages())) {
try (Connection conn = ref.getConnection(manager)) {
return new FlowStruct(conn.getFlow(ref.getCatalog(), ref.toFlowRef()), conn.getStructure(ref.getCatalog(), ref.toFlowRef()));
}
}
Expand Down
1 change: 1 addition & 0 deletions sdmx-dl-desktop/src/main/java/sdmxdl/desktop/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static void printEvent(WebSource source, String marker, CharSequence mes

private static void printError(WebSource source, String marker, CharSequence message, IOException error) {
System.err.println("[" + source.getId() + "] (" + marker + ") " + message + ": " + error.getMessage());
error.printStackTrace(System.err);
}

private static void printRegistryEvent(CharSequence message) {
Expand Down
Loading

0 comments on commit 9ec3bb4

Please sign in to comment.