Search in sources :

Example 1 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method openFiles.

private void openFiles() {
    Analytics.sendEvent("search", "openfolder");
    SearchResultItem selectedItem = table.getSelectionModel().getSelectedItem();
    ContentEntryInfo searchItems = searchService.getSearchItems(selectedItem.getId(), selectedItem.getCategory());
    GuiUtils.showDialogBare("searchViewFiles.fxml", "Files and info for '" + selectedItem.getName() + "'", selectedItem, searchItems, true);
}
Also used : SearchResultItem(se.light.assembly64.model.SearchResultItem) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo)

Example 2 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method handleMouseClicked.

// first stage
private void handleMouseClicked(MouseEvent event) {
    // user either rightclicks
    if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
        final ContextMenu contextMenu = new ContextMenu();
        List<SearchResultItem> selectedItems = table.getSelectionModel().getSelectedItems();
        MenuItem view = new MenuItem("Download to installbase");
        view.setOnAction((ActionEvent event2) -> {
            Analytics.sendEvent("search", "installfiles");
            if (userService.getPrimaryInstallation().exists()) {
                downloadFiles(selectedItems, userService.resolveDownloadFolderAsString());
            } else {
                GenericMessageDialogController.withErrorProps("Ooops..", "No valid downloadlocation is present").showAndWait();
            }
        });
        MenuItem downloadTo = new MenuItem("Download to...");
        downloadTo.setOnAction((ActionEvent event2) -> {
            File tmp = new DirectoryChooser().showDialog(getStage());
            Analytics.sendEvent("search", "installfilecustompath");
            if (tmp != null) {
                downloadFiles(selectedItems, Support.getAndfixPathAsString(tmp));
            }
        });
        if (userService.isLocationSelectedAndExisting()) {
            contextMenu.getItems().add(view);
        }
        contextMenu.getItems().add(downloadTo);
        table.setContextMenu(contextMenu);
        Analytics.sendEvent("search", "installfolder");
    // or jumps straight to the files
    } else if (event.getClickCount() == 2) {
        openFiles();
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) SearchResultItem(se.light.assembly64.model.SearchResultItem) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 3 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method init.

public void init(Artifact searchEntry) throws Exception {
    localDb = LocalDBService.getInstance();
    userService = UserService.getInstance();
    searchService = SearchService.getInstance();
    mappingService = CategoryMappingService.getInstance();
    // populate years
    table.setPlaceholder(new Label(""));
    yearInput.getItems().add(ALL);
    IntStream.range(1980, Calendar.getInstance().get(Calendar.YEAR) + 1).forEach(item -> yearInput.getItems().add(String.valueOf(item)));
    yearInput.getSelectionModel().selectFirst();
    // populate ratings
    ratingInput.getItems().add(ALL);
    IntStream.range(1, 10).forEach(item -> ratingInput.getItems().add(String.valueOf(item)));
    ratingInput.getSelectionModel().selectFirst();
    categoryInput.getItems().add(ALL);
    List<CategoryMapping> l = new ArrayList<CategoryMapping>(mappingService.values());
    Collections.sort(l, (i1, i2) -> i1.getDescription().toLowerCase().compareTo(i2.getDescription().toLowerCase()));
    l.stream().forEach(item -> categoryInput.getItems().add(item.getDescription()));
    if (searchEntry != null) {
        try {
            CategoryMapping categoryMappingByName = mappingService.getCategoryMappingByName(searchEntry.getDatabaseId());
            categoryInput.getSelectionModel().select(categoryMappingByName.getDescription());
        } catch (Exception e) {
            categoryInput.getSelectionModel().selectFirst();
        }
    } else {
        categoryInput.getSelectionModel().selectFirst();
    }
    name.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("name"));
    group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
    year.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("year"));
    handle.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("handle"));
    event.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("event"));
    group.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("group"));
    rating.setCellValueFactory(new PropertyValueFactory<SearchResultItem, Integer>("rating"));
    category.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("categoryName"));
    updated.setCellValueFactory(new PropertyValueFactory<SearchResultItem, String>("updated"));
    EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
        handleMouseClicked(event);
    };
    table.setOnKeyTyped(event -> {
        if (event.getCharacter().length() > 0 && event.getCharacter().charAt(0) == ENTER_KEY) {
            openFiles();
        }
    });
    table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    registerSearchOnEnter(nameInput);
    registerSearchOnEnter(groupInput);
    registerSearchOnEnter(handleInput);
    registerSearchOnEnter(eventInput);
    registerChoice(yearInput);
    registerChoice(categoryInput);
    registerChoice(ratingInput);
    checkCheckbox(t64, T64SEARCH);
    checkCheckbox(d64, D64SEARCH);
    checkCheckbox(d71, T71SEARCH);
    checkCheckbox(d81, T81SEARCH);
    checkCheckbox(prg, PRGSEARCH);
    checkCheckbox(tap, TAPSEARCH);
    checkCheckbox(crt, CRTSEARCH);
    checkCheckbox(bin, BINSEARCH);
    checkCheckbox(sid, SIDSEARCH);
    checkCheckbox(g64, G64SEARCH);
    searchPeriod.setItems(FXCollections.observableArrayList(SEARCH_PERIOD.ALL, SEARCH_PERIOD.ONE_DAY, SEARCH_PERIOD.TWO_DAYS, SEARCH_PERIOD.FOUR_DAYS, SEARCH_PERIOD.ONE_WEEK, SEARCH_PERIOD.TWO_WEEKS, SEARCH_PERIOD.THREE_WEEKS, SEARCH_PERIOD.ONE_MONTH, SEARCH_PERIOD.TWO_MONTHS));
    searchPeriod.getSelectionModel().select(0);
    try {
        searchPeriod.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends SEARCH_PERIOD> observable, SEARCH_PERIOD oldValue, SEARCH_PERIOD newValue) -> performSearch());
    } catch (Exception e) {
        logger.error("Unable to install listener", e);
    }
    registerCheckboxChangeForSearch(t64, T64SEARCH);
    registerCheckboxChangeForSearch(d64, D64SEARCH);
    registerCheckboxChangeForSearch(d71, T71SEARCH);
    registerCheckboxChangeForSearch(d81, T81SEARCH);
    registerCheckboxChangeForSearch(prg, PRGSEARCH);
    registerCheckboxChangeForSearch(tap, TAPSEARCH);
    registerCheckboxChangeForSearch(crt, CRTSEARCH);
    registerCheckboxChangeForSearch(bin, BINSEARCH);
    registerCheckboxChangeForSearch(sid, SIDSEARCH);
    registerCheckboxChangeForSearch(g64, G64SEARCH);
    searchFromStartOfString.selectedProperty().addListener(new ChangeListener<Boolean>() {

        public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
            ExecutorUtil.executeAsyncWithRetry(() -> {
                localDb.addLocalDBSetting("search_from_start", String.valueOf(newVal));
                return null;
            });
        }
    });
    String val = localDb.getLocalDBSetting("search_from_start");
    if (val != null) {
        searchFromStartOfString.setSelected(Boolean.valueOf(val));
    } else {
        searchFromStartOfString.setSelected(true);
    }
    if (!userService.isLocationSelectedAndExisting()) {
        downloadFolderImage.setVisible(false);
    }
}
Also used : SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) CategoryMapping(se.light.assembly64.model.CategoryMapping) MouseEvent(javafx.scene.input.MouseEvent) Label(javafx.scene.control.Label) ArrayList(java.util.ArrayList) SearchResultItem(se.light.assembly64.model.SearchResultItem) ObservableValue(javafx.beans.value.ObservableValue) SearchException(se.light.assembly64.model.SearchException)

Example 4 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method downloadEntryAndSubItems.

private boolean downloadEntryAndSubItems(SearchResultItem selectedItem, String downloadPath) {
    List<ContentEntry> searchItems = searchService.getSearchItems(selectedItem.getId(), selectedItem.getCategory()).getContentEntry();
    boolean success = true;
    for (ContentEntry entry : searchItems) {
        try {
            DownloadArtifactsService.getInstance().downloadItem(selectedItem.getId(), selectedItem.getCategory(), entry.getId(), selectedItem.getName(), entry.getName(), selectedItem.getCategoryShortName(), FILE_ACTION.DOWNLOAD, downloadPath);
        } catch (Exception e) {
            success = false;
        }
    }
    return success;
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) SearchException(se.light.assembly64.model.SearchException)

Example 5 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchViewFilesController method init.

public void init(SearchResultItem searchedItem, ContentEntryInfo contentEntry, boolean fromSearch) {
    localDb = LocalDBService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    playlistService = PlaylistService.getInstance();
    viceService = ViceService.getInstance();
    userService = UserService.getInstance();
    this.fromSearch = fromSearch;
    ReturningTask<Void> task = () -> {
        MetadataService metaDataSercice = MetadataService.getInstance();
        metadata = metaDataSercice.resolve(searchedItem);
        if (metadata.getUrl() == null) {
            toSourceButton.setVisible(false);
        }
        Platform.runLater(() -> {
            if (isNotEmpty(metadata.getEvent()) && isNotEmpty(metadata.getEventType())) {
                eventName.setText(capitalize(metadata.getEvent()));
                eventType.setText(capitalize(metadata.getEventType()));
                showEventName();
            }
            if (isNotEmpty(metadata.getReleaseDate())) {
                date.setText(metadata.getReleaseDate());
                showDate();
            }
            if (isNotEmpty(metadata.getName())) {
                releaseName.setText(capitalize(metadata.getName()));
                showReleaseName();
            }
            if (isNotEmpty(metadata.getGroup())) {
                group.setText(capitalize(metadata.getGroup()));
                showGroup();
            }
            if (isNotEmpty(metadata.getRating())) {
                rating.setText(metadata.getRating());
                showRating();
            }
            if (isNotEmpty(metadata.getPlace())) {
                place.setText("#" + metadata.getPlace());
                showPlace();
            }
            if (metadata.getImages().size() == 1) {
                try {
                    ReturningTask<Void> task2 = () -> {
                        TargetAndPath name = metadata.getImages().iterator().next();
                        fadeUpImage(new Image(CachedImageService.getInstance().getImage(name)));
                        return null;
                    };
                    ExecutorUtil.executeAsyncWithRetry(task2);
                } catch (Exception e) {
                    imageView.setImage(metaDataSercice.getNoPreview());
                }
            } else if (metadata.getImages().size() > 1) {
                loopImages(metadata.getImages());
            } else {
                fadeUpImage(metaDataSercice.getNoPreview());
            }
        });
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task);
    this.searchedItem = searchedItem;
    name.setCellValueFactory(new PropertyValueFactory<ContentEntry, String>("name"));
    EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
        handleMouseClicked(event);
    };
    table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    contentEntry.getContentEntry().sort((i1, i2) -> i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase()));
    data.addAll(contentEntry.getContentEntry());
    table.setItems(data);
    getStage().setOnCloseRequest(event -> {
        closeImageLoop();
    });
    table.setOnKeyTyped(event -> {
        if (event.getCharacter().charAt(0) == Support.ENTER_KEY) {
            openFile(false);
        }
    });
    Executors.newSingleThreadExecutor().execute(() -> {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
        Platform.runLater(() -> {
            GuiUtils.selectFirstInList(table);
        });
    });
}
Also used : TargetAndPath(se.light.assembly64.model.TargetAndPath) MouseEvent(javafx.scene.input.MouseEvent) ReturningTask(se.light.assembly64.model.ReturningTask) Image(javafx.scene.image.Image) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) ContentEntry(se.light.assembly64.model.ContentEntry)

Aggregations

SearchResultItem (se.light.assembly64.model.SearchResultItem)8 ContentEntry (se.light.assembly64.model.ContentEntry)4 File (java.io.File)3 List (java.util.List)3 Label (javafx.scene.control.Label)3 SearchException (se.light.assembly64.model.SearchException)3 ArrayList (java.util.ArrayList)2 ActionEvent (javafx.event.ActionEvent)2 ContextMenu (javafx.scene.control.ContextMenu)2 MenuItem (javafx.scene.control.MenuItem)2 MouseEvent (javafx.scene.input.MouseEvent)2 CancelableTask (se.light.assembly64.model.CancelableTask)2 ContentEntryInfo (se.light.assembly64.model.ContentEntryInfo)2 IOException (java.io.IOException)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ObservableValue (javafx.beans.value.ObservableValue)1 ObservableList (javafx.collections.ObservableList)1 Image (javafx.scene.image.Image)1 DirectoryChooser (javafx.stage.DirectoryChooser)1 Response (javax.ws.rs.core.Response)1