/* * Copyright 2000-2014 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. */ /* * Created by IntelliJ IDEA. * User: Anna.Kozlova * Date: 19-Aug-2006 * Time: 14:54:29 */ package com.intellij.ide.plugins; import com.intellij.util.ui.ColumnInfo; import javax.swing.*; import java.util.ArrayList; import java.util.List; import java.util.TreeSet; /** * @author stathik */ public class AvailablePluginsTableModel extends PluginTableModel { public static final String ALL = "All"; private String myCategory = ALL; private TreeSet<String> myAvailableCategories = new TreeSet<String>(); protected static final String STATUS = "Status"; public AvailablePluginsTableModel() { super.columns = new ColumnInfo[] { new AvailablePluginColumnInfo(this), //new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DOWNLOADS, this), //new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_RATE, this), //new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_DATE, this) /*, new PluginManagerColumnInfo(PluginManagerColumnInfo.COLUMN_CATEGORY, this)*/}; setSortKey(new RowSorter.SortKey(getNameColumn(), SortOrder.ASCENDING)); view = new ArrayList<IdeaPluginDescriptor>(); } public String getCategory() { return myCategory; } public void setCategory(String category, String filter) { myCategory = category; filter(filter); } @Override public boolean isPluginDescriptorAccepted(IdeaPluginDescriptor descriptor) { final String category = descriptor.getCategory(); if (category != null){ if (!ALL.equals(myCategory) && !category.equals(myCategory)) return false; } return true; } public TreeSet<String> getAvailableCategories() { return myAvailableCategories; } private static void updateStatus(final IdeaPluginDescriptor descr) { if (descr instanceof PluginNode) { final PluginNode node = (PluginNode)descr; IdeaPluginDescriptor existing = PluginManager.getPlugin(descr.getPluginId()); if (existing != null) { node.setStatus(PluginNode.STATUS_INSTALLED); node.setInstalledVersion(existing.getVersion()); } } } @Override public void updatePluginsList(List<IdeaPluginDescriptor> list) { view.clear(); myAvailableCategories.clear(); filtered.clear(); // For each downloadable plugin we need to know whether its counterpart // is already installed, and if yes compare the difference in versions: // availability of newer versions will be indicated separately. for (IdeaPluginDescriptor descr : list) { updateStatus(descr); view.add(descr); final String category = descr.getCategory(); if (category != null) { myAvailableCategories.add(category); } else { myAvailableCategories.add(AvailablePluginsManagerMain.N_A); } } fireTableDataChanged(); } @Override public void filter(final List<IdeaPluginDescriptor> filtered) { view.clear(); for (IdeaPluginDescriptor descriptor : filtered) { view.add(descriptor); } super.filter(filtered); } @Override public int getNameColumn() { return 0; } }