Search in sources :

Example 1 with LogicalNodeController

use of com.faforever.client.query.LogicalNodeController in project downlords-faf-client by FAForever.

the class SearchControllerTest method setUp.

@Before
public void setUp() throws Exception {
    when(uiService.loadFxml("theme/vault/search/logical_node.fxml")).thenAnswer(invocation -> {
        LogicalNodeController controller = mock(LogicalNodeController.class);
        controller.logicalOperatorField = new ChoiceBox<>();
        controller.specificationController = mock(SpecificationController.class);
        controller.specificationController.propertyField = new ComboBox<>();
        controller.specificationController.operationField = new ChoiceBox<>();
        controller.specificationController.valueField = new ComboBox<>();
        when(controller.getRoot()).thenReturn(new Pane());
        return controller;
    });
    when(preferencesService.getPreferences()).thenReturn(new Preferences());
    instance = new SearchController(uiService, i18n, preferencesService);
    loadFxml("theme/vault/search/search.fxml", clazz -> {
        if (SpecificationController.class.isAssignableFrom(clazz)) {
            return specificationController;
        }
        if (LogicalNodeController.class.isAssignableFrom(clazz)) {
            return logicalNodeController;
        }
        return instance;
    });
    instance.setSearchableProperties(SearchableProperties.GAME_PROPERTIES);
    instance.setSortConfig(preferencesService.getPreferences().getVaultPrefs().onlineReplaySortConfigProperty());
}
Also used : LogicalNodeController(com.faforever.client.query.LogicalNodeController) SpecificationController(com.faforever.client.query.SpecificationController) Preferences(com.faforever.client.preferences.Preferences) Pane(javafx.scene.layout.Pane) Before(org.junit.Before)

Example 2 with LogicalNodeController

use of com.faforever.client.query.LogicalNodeController in project downlords-faf-client by FAForever.

the class SearchController method onAddCriteriaButtonClicked.

public void onAddCriteriaButtonClicked() {
    LogicalNodeController controller = uiService.loadFxml("theme/vault/search/logical_node.fxml");
    controller.logicalOperatorField.valueProperty().addListener(queryInvalidationListener);
    controller.specificationController.setRootType(rootType);
    controller.specificationController.setProperties(searchableProperties);
    controller.setRemoveCriteriaButtonListener(() -> {
        criteriaPane.getChildren().remove(controller.getRoot());
        queryNodes.remove(controller);
        if (queryNodes.isEmpty()) {
            initialLogicalNodeController.logicalOperatorField.setVisible(false);
        }
    });
    addInvalidationListener(controller);
    criteriaPane.getChildren().add(controller.getRoot());
    queryNodes.add(controller);
    initialLogicalNodeController.logicalOperatorField.setVisible(true);
}
Also used : LogicalNodeController(com.faforever.client.query.LogicalNodeController)

Example 3 with LogicalNodeController

use of com.faforever.client.query.LogicalNodeController in project downlords-faf-client by FAForever.

the class SearchController method buildQuery.

/**
 * Builds the query string if possible, returns empty string if not. A query string can not be built if the user
 * selected no or invalid values.
 */
private String buildQuery(SpecificationController initialSpecification, List<LogicalNodeController> queryNodes) {
    QBuilder qBuilder = new QBuilder();
    Optional<Condition> condition = initialSpecification.appendTo(qBuilder);
    if (!condition.isPresent()) {
        return "";
    }
    for (LogicalNodeController queryNode : queryNodes) {
        Optional<Condition> currentCondition = queryNode.appendTo(condition.get());
        if (!currentCondition.isPresent()) {
            break;
        }
        condition = currentCondition;
    }
    return (String) condition.get().query(new RSQLVisitor());
}
Also used : Condition(com.github.rutledgepaulv.qbuilders.conditions.Condition) QBuilder(com.github.rutledgepaulv.qbuilders.builders.QBuilder) LogicalNodeController(com.faforever.client.query.LogicalNodeController) RSQLVisitor(com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor)

Aggregations

LogicalNodeController (com.faforever.client.query.LogicalNodeController)3 Preferences (com.faforever.client.preferences.Preferences)1 SpecificationController (com.faforever.client.query.SpecificationController)1 QBuilder (com.github.rutledgepaulv.qbuilders.builders.QBuilder)1 Condition (com.github.rutledgepaulv.qbuilders.conditions.Condition)1 RSQLVisitor (com.github.rutledgepaulv.qbuilders.visitors.RSQLVisitor)1 Pane (javafx.scene.layout.Pane)1 Before (org.junit.Before)1