17 November 2016

Java dynamic proxy adding interface implementation (introducing an interface) to an object with Spring

I'm not an AOP expert and not knowing the terminology took me a while before I find the solution to the topic. The keyword appeared to be the introduction.
While knowing the keyword makes task way easier I will still share the recipe.

What we need to do

To wrap an object instance with a AOP proxy adding an interface implementation to it.

Code example is available here http://www.java2s.com/Code/Java/Spring/SpringAspectIntroductionExample.htm

03 May 2016

Make 'Open class' dialogue of IntelliJ IDEA behave under Awesome WM

There is a quite well known [in narrow circles]  problem in IntelliJ IDEA (as well as other Jetbrains products) with 'Open class'\'Open file' dialogues (AKA Ctrl+N\Ctrl+Shift+N): in some environments the dialogue tend to often disappear\close as you type. For other environments this problem just never happens.

Recently it was demystified for me with the help of Jetbrains developers and support and the community. There appeared to be a long-hanging issue regarding this weird behaviour IDEA-65043. And once it gained some more attention at least exact conditions triggering the issue were discovered.

The problem was caused by sloppy focus (AKA focus-follows-mouse) which is the default in some environments among which Awesome WM is. Now it can easily be solved!

I'm using default configuration of Awesome WM 3.5.9 as a base (which can be found in /etc/xdg/awesome/rc.lua).

Somewhere in the bottom there is a snippet we're looking for

-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c) then
            client.focus = c
        end
    end)
This is the sloppy focus implementation. Need to introduce a flag to switch it on\off. Change it to:
-- {{{ Signals
-- Signal function to execute when a new client appears.
sloppyFocus = true
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c)
            and sloppyFocus then
            client.focus = c 
        end 
    end)

Now we have a switch, and we need to turn it off while we're working with IDEA (or WebStorm, etc) and the turn back on when we're off it. Find awfule.rules section in your config (for me it's right above the sloppy focus implementation snippet) and add a new rule:

{ rule = { class = "jetbrains-%w+" },
      callback = function(c)
          c:connect_signal("focus", function (client)
              sloppyFocus = false
          end)
          c:connect_signal("unfocus", function (client)
              sloppyFocus = true
          end)
      end
    },
This matches any window of virtually any Jetbrains' product and switches sloppy focus off while it's focused, then switches sloppy back on when focus leaves IDE.

Thanks awesome Awesome developers for allowing patterns in rule preconditions! :-)