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

Displaying multiple FXML models (with same classField) #159

Closed
Rizen59 opened this issue Jul 29, 2015 · 1 comment
Closed

Displaying multiple FXML models (with same classField) #159

Rizen59 opened this issue Jul 29, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@Rizen59
Copy link
Contributor

Rizen59 commented Jul 29, 2015

This issue follow the issue #126 and the following lines in AbstractFXMLObjectModel:

if (getFXMLItem() != null) {
     this.fxmlComponent = getFXMLItem().get();
} else if (getFXMLPath() != null) {
     this.fxmlComponent = FXMLUtils.loadFXML(this, getFXMLPath(), getFXMLBundlePath());
}

When a FXMLItem is defined we get the same instance of FXMLComponent (so the same node).
If multiple instances of a model are defined then the same instance node will be retrieve. In this case we must use getFXMLItem().getNew().

Here is the temporary code I did to fix this issue. But I would like to have your opinion first.
If it's ok for you can include it as a next commit.

/**
 * Inform if the model will be displayed multiple times on screen
 * As consequence the FXMLItem will provide a new FXMLComponent instance to avoid
 * duplicate children on the scene graph
 *
 * @return true is the node mus
 */
 protected boolean duplicateOnScreen() {
    return false;
 }

 /**
  * {@inheritDoc}
  */
  @Override
  protected final void initInternalModel() throws CoreException {
     [... DO THINGS ...]

     if (getFXMLItem() != null) {
         if (!duplicateOnScreen()) {
             this.fxmlComponent = getFXMLItem().get();
         } else {
             this.fxmlComponent = getFXMLItem().getNew();
         }
         // Don't forget to set the model to the controller here cause of FXMLBuilder#buildComponent
         this.fxmlComponent.getController().setModel(this);
     } else if (getFXMLPath() != null) {
         this.fxmlComponent = FXMLUtils.loadFXML(this, getFXMLPath(), getFXMLBundlePath());
     }

      [... DO OTHERS THINGS ...]
  }
@sbordes sbordes added this to the 8.0.3 milestone Jul 29, 2015
@sbordes sbordes added the bug label Jul 29, 2015
@sbordes sbordes self-assigned this Jul 29, 2015
sbordes added a commit that referenced this issue Jul 30, 2015
@sbordes sbordes closed this as completed Jul 30, 2015
@sbordes
Copy link
Member

sbordes commented Jul 30, 2015

Set the isSingleton flag to false to indicates if you need fresh instance for FXMLComponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants