/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * 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 com.intellij.uiDesigner.palette;

import com.intellij.refactoring.listeners.RefactoringElementAdapter;
import com.intellij.refactoring.listeners.RefactoringElementListenerProvider;
import com.intellij.refactoring.listeners.RefactoringElementListener;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.ClassUtil;
import javax.annotation.Nonnull;

/**
 * @author yole
*/
public class PaletteRefactoringListenerProvider implements RefactoringElementListenerProvider {
  private final UIDesignerPaletteProvider myUiDesignerPaletteProvider;
  private final Palette myPalette;

  public PaletteRefactoringListenerProvider(UIDesignerPaletteProvider uiDesignerPaletteProvider, Palette palette) {
    myUiDesignerPaletteProvider = uiDesignerPaletteProvider;
    myPalette = palette;
  }

  public RefactoringElementListener getListener(PsiElement element) {
    if (element instanceof PsiClass) {
      PsiClass psiClass = (PsiClass) element;
      final String oldName = ClassUtil.getJVMClassName(psiClass);
      if (oldName != null) {
        final ComponentItem item = myPalette.getItem(oldName);
        if (item != null) {
          return new MyRefactoringElementListener(item);
        }
      }
    }
    return null;
  }

  private class MyRefactoringElementListener extends RefactoringElementAdapter{
    private final ComponentItem myItem;

    public MyRefactoringElementListener(final ComponentItem item) {
      myItem = item;
    }

    public void elementRenamedOrMoved(@Nonnull PsiElement newElement) {
      PsiClass psiClass = (PsiClass) newElement;
      final String qName = ClassUtil.getJVMClassName(psiClass);
      if (qName != null) {
        myItem.setClassName(qName);
        myUiDesignerPaletteProvider.fireGroupsChanged();
      }
    }

    @Override
    public void undoElementMovedOrRenamed(@Nonnull PsiElement newElement, @Nonnull String oldQualifiedName) {
      myItem.setClassName(oldQualifiedName);
      myUiDesignerPaletteProvider.fireGroupsChanged();
    }
  }
}

@@ -647,68 +647,196 @@
 ort 
-com.intellij.refactoring.listeners.RefactoringElementAdapter
+javax.annotation.Nonnull;%0A%0Aimport com.intellij.ide.palette.PaletteItemProvider;%0Aimport com.intellij.psi.PsiClass;%0Aimport com.intellij.psi.PsiElement;%0Aimport com.intellij.psi.util.ClassUtil
 ;%0Aim
@@ -893,30 +893,21 @@
 gElement
-ListenerProvid
+Adapt
 er;%0Aimpo
@@ -996,129 +996,64 @@
 lij.
-psi.PsiElement;%0Aimport com.intellij.psi.PsiClass;%0Aimport com.intellij.psi.util.ClassUtil;%0Aimport javax.annotation.Nonnull
+refactoring.listeners.RefactoringElementListenerProvider
 ;%0A%0A/
@@ -1325,61 +1325,8 @@
 der(
-UIDesignerPaletteProvider uiDesignerPaletteProvider, 
 Pale
@@ -1374,18 +1374,60 @@
 vider = 
-ui
+PaletteItemProvider.EP_NAME.findExtension(UI
 Designer
@@ -1437,24 +1437,31 @@
 etteProvider
+.class)
 ;%0A    myPale

fix dep - now extensions is not resolved from injecting container