Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing scalafx.Includes._ breaks cellFactory creation #236

Closed
OndrejSpanel opened this issue Mar 31, 2016 · 3 comments
Closed

Importing scalafx.Includes._ breaks cellFactory creation #236

OndrejSpanel opened this issue Mar 31, 2016 · 3 comments
Milestone

Comments

@OndrejSpanel
Copy link

@OndrejSpanel OndrejSpanel commented Mar 31, 2016

Following code does not compile:

import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.TableColumn._
import scalafx.scene.control.{TableColumn, TableView}
import scalafx.beans.property.StringProperty
import scalafx.scene.control.cell.TextFieldTableCell
import scalafx.Includes._ // does not compile
//import scalafx.util.UtilIncludes.function12jfxCallback // does not compile
//import scalafx.Includes.{function12jfxCallback => _, _} // compiles OK


class Person(name_ : String) {

  val name = new StringProperty(this, "firstName", name_)
}
object SimpleTableView extends JFXApp {

  val characters = ObservableBuffer[Person](
    new Person("Peggy"),
    new Person("Rocky")
  )

  stage = new PrimaryStage {
    title = "Simple Table View"
    scene = new Scene {
      content = new TableView[Person](characters) {
        columns ++= List(
          new TableColumn[Person, String] {
            text = "First Name"
            cellValueFactory = {_.value.name}
            cellFactory = _ => new TextFieldTableCell[Person, String]()
            prefWidth = 180
          }
        )
      }
    }
  }
}

The error is

Error:(34, 27) missing parameter type
cellFactory = _ => new TextFieldTableCell[Person, String]()

As a workaround one can disable import of function12jfxCallback, as indicated in the source comments.

I am not sure what can be done to fix this, but the error was confusing and it was quite hard to identify the exact cause.

@jpsacha
Copy link
Member

@jpsacha jpsacha commented Mar 31, 2016

Looks that function12jfxCallback is too eager to convert lambdas with anonymous parameter to Callbacks. I think function12jfxCallback should be removed as too generic. Question is how many things (outside ScalaFX source code) depend on it.

@jpsacha
Copy link
Member

@jpsacha jpsacha commented Apr 1, 2016

To make it clear, it is possible to make the code in the initial post compile correctly be specifying lambdas argument type explicitly:

cell factory = _: TableColumn[Person, String]=> new TextFieldTableCell[Person, String]()

even when import scalafx.Includes._ is used.

@jpsacha jpsacha added this to the 8.0.*-R10 milestone Apr 10, 2016
@jpsacha
Copy link
Member

@jpsacha jpsacha commented Apr 11, 2016

Removal of function12jfxCallback fixes the issue in Scala 2.10 and 2.11, but in 2.12.0-M4 type parameter has to be specified:

cellFactory = (_: TableColumn[Person, String]) => new TextFieldTableCell[Person, String]()
@jpsacha jpsacha closed this Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants