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

Swing and Spring Integration #372

Open
bosbeles opened this issue Sep 24, 2020 · 0 comments
Open

Swing and Spring Integration #372

bosbeles opened this issue Sep 24, 2020 · 0 comments
Labels

Comments

@bosbeles
Copy link

bosbeles commented Sep 24, 2020

Hello.
This is a question rather than an issue. (I apologize for this.)

I have a spring boot desktop application (Swing).
I want to change a bean which is an instance of JPanel, and reload the class.
(see for full code: https://github.com/bosbeles/spring-swing-deneme)

I am using Intellij. Java 8.
Problem 1:
When I change constructor, and add/modify a method name, then Ctrl+Shift+F9, it is working.
But when I change only the constructor, and then Ctrl+Shift+F9; intellij shows a popup for hot code replace. But bean definition is not refreshed.
How can I force to refresh bean definition when I change only the constructor (or probably a method body).

Problem 2
As I said before, if I change method name, it works. But this is a hack.

I have modified your example plugin, and scheduled a timer with 2 seconds delay.
I am holding panel instance in a map. When I change the class, I am fetching the panel bean from the application context (which is statically gotten [a bad design]).
Then an action get panel from the map, and uses it.
It works because of the delay. Normally Spring plugin works after my example plugin. When I put 2 seconds delay, my example plugin works after the spring plugin. Then I can get the new, modified, refreshed bean.
As you see, there are some hacks. Is there a more appropriate way to do this?

`

    @OnClassFileEvent(classNameRegexp = MAIN_PANEL, events = {CREATE, MODIFY})
   public void changeClassFile(String className) {
    scheduler.scheduleCommand(new ReloadClassCommand(appClassLoader, className, mainPanel), 2000);
   }

    public static void classReloaded(String className, Object mainPanel) {

    // this is the main purpose of this class. Finally, we can use typed variables and
    // use normal code instead of reflection. Imagine more complex code to reload part of your
    // framework - it would be inconvenient to use reflection for each invocation.
    EventQueue.invokeLater(() -> {
        MainFrame mainFrame = Application.context.getBean(MainFrame.class);
        mainFrame.getFactory().put("Window 2", Application.context.getBean(MainPanel.class));

    });


}

`

@skybber skybber added the bug label Feb 14, 2021
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