/*
 * Copyright 2013-2017 consulo.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package consulo.ui.desktop.internal;

import consulo.awt.impl.FromSwingComponentWrapper;
import consulo.disposer.Disposable;
import consulo.ui.Button;
import consulo.ui.Component;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.desktop.internal.base.SwingComponentDelegate;
import consulo.ui.event.ClickListener;

import javax.annotation.Nonnull;
import javax.swing.*;
import java.awt.event.ActionListener;

/**
 * @author VISTALL
 * @since 13-Sep-17
 */
class DesktopButtonImpl extends SwingComponentDelegate<JButton> implements Button {
  class MyButton extends JButton implements FromSwingComponentWrapper {
    MyButton(String text) {
      super(text);
    }

    @Nonnull
    @Override
    public Component toUIComponent() {
      return DesktopButtonImpl.this;
    }
  }

  public DesktopButtonImpl(String text) {
    initialize(new MyButton(text));
  }

  @Override
  public Disposable addClickListener(@Nonnull ClickListener clickListener) {
    ActionListener actionListener = e -> getListenerDispatcher(ClickListener.class);
    toAWTComponent().addActionListener(actionListener);
    return () -> toAWTComponent().removeActionListener(actionListener);
  }

  @Nonnull
  @Override
  public String getText() {
    return toAWTComponent().getText();
  }

  @RequiredUIAccess
  @Override
  public void setText(@Nonnull String text) {
    toAWTComponent().setText(text);
  }
}

@@ -879,16 +879,52 @@
 legate;%0A
+import consulo.ui.event.ClickEvent;%0A
 import c
@@ -1013,46 +1013,8 @@
 g.*;
-%0Aimport java.awt.event.ActionListener;
 %0A%0A/*
@@ -1464,225 +1464,204 @@
 ));%0A
-  %7D%0A%0A  @Override%0A  public Disposable addClickListener(@Nonnull ClickListener clickListener) %7B%0A    ActionListener actionListener = e -%3E getListenerDispatcher(ClickListener.class);%0A    toAWTComponent().addAction
+%0A    toAWTComponent().addActionListener(e -%3E getListenerDispatcher(ClickListener.class).clicked(new ClickEvent(this)));%0A  %7D%0A%0A  @Override%0A  public Disposable addClickListener(@Nonnull Click
 Listener
 (act
@@ -1648,39 +1648,38 @@
 ll ClickListener
-(action
+ click
 Listener);%0A    r
@@ -1671,17 +1671,18 @@
 istener)
-;
+ %7B
 %0A    ret
@@ -1689,58 +1689,46 @@
 urn 
-() -%3E toAWTComponent().removeActionListener(action
+addListener(ClickListener.class, click
 List

fix new ui button clickable after rework