Skip to content

Commit

Permalink
feat(#237): add vst type filter button in explore view
Browse files Browse the repository at this point in the history
  • Loading branch information
DropSnorz committed Aug 11, 2024
1 parent 684419e commit d2a14e7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.owlplug.core.components.LazyViewRegistry;
import com.owlplug.core.controllers.BaseController;
import com.owlplug.core.controllers.MainController;
import com.owlplug.core.model.PluginFormat;
import com.owlplug.core.utils.FileUtils;
import com.owlplug.explore.components.ExploreTaskFactory;
import com.owlplug.explore.model.PackageBundle;
Expand Down Expand Up @@ -90,14 +91,14 @@ public class ExploreController extends BaseController {
@FXML
private Button sourcesButton;
@FXML
private Button formatFilterButton;
@FXML
private Button platformFilterButton;
@FXML
private Button syncSourcesButton;
@FXML
private Label resultCounter;
@FXML
private VBox masonryWrapper;
@FXML
private MasonryPane masonryPane;
@FXML
private ScrollPane scrollPane;
Expand All @@ -108,7 +109,9 @@ public class ExploreController extends BaseController {
@FXML
private Pane exploreChipViewContainer;

private HashMap<String, CheckBox> targetFilterCheckBoxes = new HashMap<>();
private final HashMap<String, CheckBox> targetFilterCheckBoxes = new HashMap<>();

private final HashMap<String, CheckBox> formatsFilterCheckBoxes = new HashMap<>();


private ExploreChipView exploreChipView;
Expand Down Expand Up @@ -139,6 +142,31 @@ public void initialize() {
mainController.getLeftDrawer().open();

});

for (PluginFormat format : PluginFormat.values()) {
CheckBox checkbox = new CheckBox(format.getText());
formatsFilterCheckBoxes.put(format.getText().toLowerCase(), checkbox);
checkbox.setSelected(false);
checkbox.setOnAction(e -> {
performPackageSearch();
});
}

VBox formatFilterVbox = new VBox();
formatFilterVbox.setSpacing(5);
formatFilterVbox.setPadding(new Insets(5,10,5,10));
Label formatLabel = new Label("Plugin format");
formatLabel.getStyleClass().add("label-disabled");
formatFilterVbox.getChildren().add(formatLabel);
for (Entry<String, CheckBox> entry : formatsFilterCheckBoxes.entrySet()) {
formatFilterVbox.getChildren().add(entry.getValue());
}

formatFilterButton.setOnAction(e -> {
Popup popup = new Popup(formatFilterVbox);
popup.show(formatFilterButton, Popup.PopupVPosition.TOP, Popup.PopupHPosition.RIGHT);
});


targetFilterCheckBoxes.put("win32", new CheckBox("Windows 32 bits"));
targetFilterCheckBoxes.put("win64", new CheckBox("Windows 64 bits"));
Expand All @@ -152,18 +180,18 @@ public void initialize() {
});
}

VBox vbx = new VBox();
vbx.setSpacing(5);
vbx.setPadding(new Insets(5,10,5,10));
VBox platformFilterVbox = new VBox();
platformFilterVbox.setSpacing(5);
platformFilterVbox.setPadding(new Insets(5,10,5,10));
Label popupLabel = new Label("Target environment contains");
popupLabel.getStyleClass().add("label-disabled");
vbx.getChildren().add(popupLabel);
platformFilterVbox.getChildren().add(popupLabel);
for (Entry<String, CheckBox> entry : targetFilterCheckBoxes.entrySet()) {
vbx.getChildren().add(entry.getValue());
platformFilterVbox.getChildren().add(entry.getValue());
}

platformFilterButton.setOnAction(e -> {
Popup popup = new Popup(vbx);
Popup popup = new Popup(platformFilterVbox);
popup.show(platformFilterButton, Popup.PopupVPosition.TOP, Popup.PopupHPosition.RIGHT);
});

Expand Down Expand Up @@ -215,6 +243,12 @@ private void performPackageSearch() {
}
}

for (Entry<String, CheckBox> entry : formatsFilterCheckBoxes.entrySet()) {
if (entry.getValue().isSelected()) {
criteriaList.add(new StoreFilterCriteria(entry.getKey(), ExploreFilterCriteriaType.FORMAT));
}
}

Task<Iterable<RemotePackage>> task = new Task<Iterable<RemotePackage>>() {
@Override
protected Iterable<RemotePackage> call() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ static Specification<RemotePackage> hasCreator(String creator) {


/**
* Platform filtering JPA Specification Filter products matching the given
* platformTag or products without platform assignment.
* Bundle format filtering JPA Specification to filter packages matching the given format.
*
* @param format - The platformTag to find
* @return The JPA Specification
*/
@SuppressWarnings("unchecked")
static Specification<RemotePackage> hasFormat(String format) {
return (remotePackage, cq, cb) -> {
Join<Object, Object> bundles = (Join<Object, Object>) remotePackage.fetch("bundles");
return cb.isMember(format, bundles.get("formats"));
};
}

/**
* Platform filtering JPA Specification Filter packages matching the given platformTag.
*
* @param platformTag - The platformTag to find
* @return The JPA Specification
Expand All @@ -77,8 +90,8 @@ static Specification<RemotePackage> hasPlatformTag(String platformTag) {
}

/**
* Platform filtering JPA Specification Filter products matching the given
* platformTag or products without platform assignment.
* Platform filtering JPA Specification Filter packages matching the given
* platformTag or packages without platform assignment.
*
* @param platformTagList - The compatible platformTagList to find
* @return The JPA Specification
Expand All @@ -97,7 +110,7 @@ static Specification<RemotePackage> hasPlatformTag(List<String> platformTagList)
}

/**
* Product tag filtering specification. Filter products matching the given tags
* Product tag filtering specification. Filter packages matching the given tags
*
* @param tag - The tag to find
* @return The JPA Specification
Expand All @@ -112,7 +125,7 @@ static Specification<RemotePackage> hasTag(String tag) {
}

/**
* Product tag filtering specification. Filter products matching the given tags
* Product tag filtering specification. Filter packages matching the given tags
*
* @param type - The type to find
* @return The JPA Specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ public static PackageBundle jsonMapperToEntity(BundleJsonMapper bundleMapper) {
} else if (bundleMapper.getFormat() != null) {
List<String> formats = new ArrayList<>();
formats.add(bundleMapper.getFormat());
formats.replaceAll(e -> e.equals("vst") ? "vst2" : e.toLowerCase());
packageBundle.setFormats(formats);
} else {
packageBundle.setFormats(new ArrayList<>(List.of("vst")));
packageBundle.setFormats(new ArrayList<>(List.of("vst2")));
}

return packageBundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
package com.owlplug.explore.model.search;

public enum ExploreFilterCriteriaType {
NAME, TAG, TYPE, PLATFORM, CREATOR
NAME, TAG, TYPE, PLATFORM, CREATOR, FORMAT
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static Specification<RemotePackage> toSpecification(StoreFilterCriteria c
if (criteria.getFilterType().equals(ExploreFilterCriteriaType.PLATFORM)) {
return RemotePackageDAO.hasPlatformTag(String.valueOf(criteria.getValue()));
}
if (criteria.getFilterType().equals(ExploreFilterCriteriaType.FORMAT)) {
return RemotePackageDAO.hasFormat(String.valueOf(criteria.getValue()));
}
return Specification.where(null);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public RemoteSource getRemoteSourceByUrl(String url) {
}

/**
* Retrieves products from store with name matching the given criteria and
* Retrieves packages from store with name matching the given criteria and
* compatible with the current platform.
*
* @param criteriaList criteria list
Expand Down
12 changes: 12 additions & 0 deletions owlplug-client/src/main/resources/fxml/ExploreView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
<Insets top="10.0" />
</padding>
</HBox>
<Button fx:id="formatFilterButton" contentDisplay="GRAPHIC_ONLY">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/format-white-16.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="platformFilterButton" contentDisplay="GRAPHIC_ONLY">
<HBox.margin>
<Insets top="5.0" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d2a14e7

Please sign in to comment.