/*
 * Copyright 2000-2015 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.openapi.wm.impl.welcomeScreen;

import com.intellij.ide.ProjectGroupActionGroup;
import com.intellij.ide.RecentProjectsManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.ui.speedSearch.NameFilteringListModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Konstantin Bulenkov
 */
public abstract class RecentProjectsWelcomeScreenActionBase extends DumbAwareAction {
  @Nullable
  public DefaultListModel getDataModel(AnActionEvent e) {
    final JList list = getList(e);
    if (list != null) {
      ListModel model = list.getModel();
      if (model instanceof NameFilteringListModel) {
        model = ((NameFilteringListModel)model).getOriginalModel();
        if (model instanceof DefaultListModel) {
          return (DefaultListModel)model;
        }
      }
    }
    return null;
  }

  @NotNull
  public List<AnAction> getSelectedElements(AnActionEvent e) {
    final JList list = getList(e);
    final List<AnAction> actions = new ArrayList<AnAction>();
    if (list != null) {
      for (Object value : list.getSelectedValues()) {
        if (value instanceof AnAction) {
          actions.add((AnAction)value);
        }
      }
    }
    return actions;
  }

  @Nullable
  public JList getList(AnActionEvent e) {
    final Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    if (component instanceof JList) {
      return (JList)component;
    }
    return null;
  }

  public boolean hasGroupSelected(AnActionEvent e) {
    for (AnAction action : getSelectedElements(e)) {
      if (action instanceof ProjectGroupActionGroup) {
        return true;
      }
    }
    return false;
  }

  public void rebuildRecentProjectsList(AnActionEvent e) {
    final DefaultListModel model = getDataModel(e);
    if (model != null) {
      model.clear();
      for (AnAction action : RecentProjectsManager.getInstance().getRecentProjectsActions(false, FlatWelcomeFrame.isUseProjectGroups())) {
        //noinspection unchecked
        model.addElement(action);
      }
    }
  }
}

@@ -1346,16 +1346,23 @@
  public 
+static 
 DefaultL
@@ -1394,32 +1394,32 @@
 ctionEvent e) %7B%0A
-
     final JList 
@@ -1780,16 +1780,23 @@
  public 
+static 
 List%3CAnA
@@ -2167,16 +2167,23 @@
  public 
+static 
 JList ge
@@ -2392,16 +2392,23 @@
  public 
+static 
 boolean 
@@ -2618,16 +2618,23 @@
  public 
+static 
 void reb
@@ -2750,24 +2750,163 @@
 = null) %7B%0A  
+    rebuildRecentProjectDataModel(model);%0A    %7D%0A  %7D%0A%0A  public static void rebuildRecentProjectDataModel(@NotNull DefaultListModel model) %7B%0A
     model.cl
@@ -2908,26 +2908,24 @@
 el.clear();%0A
-  
     for (AnA
@@ -3055,18 +3055,16 @@
 %7B%0A      
-  
 //noinsp
@@ -3080,18 +3080,16 @@
 checked%0A
-  
       mo
@@ -3112,24 +3112,16 @@
 ction);%0A
-      %7D%0A
     %7D%0A  

make methods public static, add rebuildModel method