Git Product home page Git Product logo

Comments (1)

me-nkr avatar me-nkr commented on September 3, 2024

I found out why it's not working and why it worked when there was a file in file history.

It has to do with the order of executions and the following lines of code

if (builder.fileToOpen != null) {
LOGGER.debug("create with given file " + builder.fileToOpen);
SwingUtilities.invokeLater(() -> loadFile(builder.fileToOpen, builder.library == null, builder.library == null));
} else {
File name = fileHistory.getMostRecent();
LOGGER.debug("create with history file " + name);
if (name != null) {
SwingUtilities.invokeLater(() -> loadFile(name, true, false));
}

Here is a detailed explanation

The order of executions is as follows when debugging

  1. create a new element library
    a. calls the LibraryNode.traverse() method from populateNodeMap()
    b. calls the LibraryNode.traverse() method directly
    populateNodeMap();
    isProgrammable.clear();
    root.traverse(libraryNode -> {
    ElementTypeDescription d = libraryNode.getDescriptionOrNull();
    if (d != null && d.hasAttribute(Keys.BLOWN))
    isProgrammable.add(d.getName());
    });
  2. register components from custom Java components to the above-created library using the ElementLibrary.registerComponentSource() method
  3. set the above created and modified library as the library of MainBuilder using the MainBuilder.setLibrary() method
  4. then the MainBuilder.openLater() method calls the MainBuilder.build() method which in turn instantiates the Main class
  5. while instantiating the Main class, as per the first block of code linked, the LibraryNode.traverse() method is called once more as a result of calling the Main.loadFile() method which only happens if there is a file in File History

The gotcha

First two calls to the LibraryNode.traverse() method happens before the ElementLibrary.registerComponentSource() and the MainBuilder.setLibrary() method calls. Because of this, the custom Java components are not in the element library when the LibraryNode.traverse() method is called which is responsible for marking library nodes as unique. Since the custom Java components are not marked as unique, they become unusable. And since the LibraryNode.traverse() method is called once more after all this when there is a file in File History, the custom Java components become usable.

Originally posted by @me-nkr in #1312 (comment)

from digital.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.