<commit_before>/*
 * Copyright 2012 Canoo Engineering AG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.canoo.dolphin.demo

import com.canoo.dolphin.core.client.ClientPresentationModel
import com.canoo.dolphin.core.client.ClientDolphin
import groovyx.javafx.SceneGraphBuilder

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.util.Callback

import static com.canoo.dolphin.demo.DemoStyle.blueStyle
import static com.canoo.dolphin.demo.VehicleProperties.*

import static groovyx.javafx.GroovyFX.start
import javafx.event.EventHandler

import com.canoo.dolphin.core.client.ClientAttributeWrapper
import com.canoo.dolphin.core.ModelStoreEvent

/**
 * This demos shows two list views on the same list of PresentationModels where one list view shows
 * all models of a given type and the second view shows only a subset (the "magenta" ones).
 * It also shows how to bind against a (changing) list of PresentationModels of a certain type and how
 * to use an additional custom filter.
 * How to use: initially, the right view should be empty (no magenta ones).
 * Clicking the button adds magenta objects to the store and they should appear in both list views.
 */

class BindListView {

    static show(ClientDolphin dolphin) {

        ObservableList<ClientPresentationModel> observableListOfPms = FXCollections.observableArrayList()
        ObservableList<ClientPresentationModel> observableListOfMagentaPms = FXCollections.observableArrayList()

        dolphin.addModelStoreListener PM_TYPE_VEHICLE, { evt ->
            switch(evt.type) {
                case ModelStoreEvent.Type.ADDED:
                    observableListOfPms << evt.presentationModel
                    break
                case ModelStoreEvent.Type.REMOVED:
                    observableListOfPms.remove(evt.presentationModel)
            }
        }

        dolphin.addModelStoreListener PM_TYPE_VEHICLE, { evt ->
            switch(evt.type) {
                case ModelStoreEvent.Type.ADDED:
                    observableListOfPms << evt.presentationModel
                    break
                case ModelStoreEvent.Type.REMOVED:
                    observableListOfPms.remove(evt.presentationModel)
            }
            if(evt.type == ModelStoreEvent.Type.ADDED &&
               evt.presentationModel.id.startsWith('magenta')) {
                observableListOfMagentaPms << evt.presentationModel
            }
        }

        start { app ->
            SceneGraphBuilder sgb = delegate
            stage {
                scene width: 700, height: 500, {
                    borderPane {
                        left margin: 10, {
                            tableView(id: 'table', opacity: 0.2d) {
                                tableColumn(property: 'id', text: "Color", prefWidth: 50)
                                x1Col = tableColumn(text: 'X', prefWidth: 40)
                            }
                        }
                        center margin: 10, {
                            tableView(id: 'smallTable', opacity: 0.2d) {
                                tableColumn(property: 'id', text: "Color", prefWidth: 50)
                                x2Col = tableColumn(text: 'X', prefWidth: 40)
                            }
                        }<commit_msg>DOL-3 closed: "doubled entries in list views". Reason for the bug was an unsolicited merge.<commit_after>/*
 * Copyright 2012 Canoo Engineering AG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.canoo.dolphin.demo

import com.canoo.dolphin.core.client.ClientPresentationModel
import com.canoo.dolphin.core.client.ClientDolphin
import groovyx.javafx.SceneGraphBuilder

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.util.Callback

import static com.canoo.dolphin.demo.DemoStyle.blueStyle
import static com.canoo.dolphin.demo.VehicleProperties.*

import static groovyx.javafx.GroovyFX.start
import javafx.event.EventHandler

import com.canoo.dolphin.core.client.ClientAttributeWrapper
import com.canoo.dolphin.core.ModelStoreEvent

/**
 * This demos shows two list views on the same list of PresentationModels where one list view shows
 * all models of a given type and the second view shows only a subset (the "magenta" ones).
 * It also shows how to bind against a (changing) list of PresentationModels of a certain type and how
 * to use an additional custom filter.
 * How to use: initially, the right view should be empty (no magenta ones).
 * Clicking the button adds magenta objects to the store and they should appear in both list views.
 */

class BindListView {

    static show(ClientDolphin dolphin) {

        ObservableList<ClientPresentationModel> observableListOfPms = FXCollections.observableArrayList()
        ObservableList<ClientPresentationModel> observableListOfMagentaPms = FXCollections.observableArrayList()

        dolphin.addModelStoreListener PM_TYPE_VEHICLE, { evt ->
            switch(evt.type) {
                case ModelStoreEvent.Type.ADDED:
                    observableListOfPms << evt.presentationModel
                    break
                case ModelStoreEvent.Type.REMOVED:
                    observableListOfPms.remove(evt.presentationModel)
            }
        }

        dolphin.addModelStoreListener PM_TYPE_VEHICLE, { evt ->
            if(evt.type == ModelStoreEvent.Type.ADDED &&
               evt.presentationModel.id.startsWith('magenta')) {
                observableListOfMagentaPms << evt.presentationModel
            }
        }

        start { app ->
            SceneGraphBuilder sgb = delegate
            stage {
                scene width: 700, height: 500, {
                    borderPane {
                        left margin: 10, {
                            tableView(id: 'table', opacity: 0.2d) {
                                tableColumn(property: 'id', text: "Color", prefWidth: 50)
                                x1Col = tableColumn(text: 'X', prefWidth: 40)
                            }
                        }
                        center margin: 10, {
                            tableView(id: 'smallTable', opacity: 0.2d) {
                                tableColumn(property: 'id', text: "Color", prefWidth: 50)
                                x2Col = tableColumn(text: 'X', prefWidth: 40)
                            }
                        }
{'fraction_non_alphanumeric': 0.07294180745508179, 'fraction_numerical': 0.00871547331724323, 'mean_word_length': 2.195801199657241, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '423928', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1902, 'n_words': 583}