mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-02 00:57:59 +07:00
refactor to support multiple sorters
This commit is contained in:
+1
-1
@@ -179,7 +179,7 @@ public class AvailablePluginsManagerMain extends PluginManagerMain {
|
||||
actionGroup.add(new MyFilterCategoryAction());
|
||||
}
|
||||
else {
|
||||
actionGroup.add(new SortByStatusAction("Sort Installed First"));
|
||||
actionGroup.add(createSortersGroup());
|
||||
actionGroup.add(Separator.getInstance());
|
||||
actionGroup.add(new ActionInstallPlugin(getAvailable(), getInstalled()));
|
||||
}
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ public class InstalledPluginsManagerMain extends PluginManagerMain {
|
||||
//actionGroup.add(new MyFilterBundleAction());
|
||||
} else {
|
||||
actionGroup.add(new RefreshAction());
|
||||
actionGroup.addAction(new SortByStatusAction("Sort by Status"));
|
||||
actionGroup.addAction(createSortersGroup());
|
||||
actionGroup.add(Separator.getInstance());
|
||||
actionGroup.add(new ActionInstallPlugin(getAvailable(), getInstalled()));
|
||||
actionGroup.add(new UninstallPluginAction(this, pluginTable));
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.CommonBundle;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.plugins.sorters.SortByStatusAction;
|
||||
import com.intellij.ide.ui.search.SearchUtil;
|
||||
import com.intellij.ide.ui.search.SearchableOptionsRegistrar;
|
||||
import com.intellij.notification.*;
|
||||
@@ -73,7 +74,7 @@ import static com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces;
|
||||
|
||||
/**
|
||||
* @author stathik
|
||||
* @since Dec 25, 2003
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public abstract class PluginManagerMain implements Disposable {
|
||||
public static Logger LOG = Logger.getInstance("#com.intellij.ide.plugins.PluginManagerMain");
|
||||
@@ -584,28 +585,6 @@ public abstract class PluginManagerMain implements Disposable {
|
||||
}).notify(project);
|
||||
}
|
||||
|
||||
protected class SortByStatusAction extends ToggleAction {
|
||||
|
||||
protected SortByStatusAction(final String title) {
|
||||
super(title, title, AllIcons.ObjectBrowser.SortByType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return pluginsModel.isSortByStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
IdeaPluginDescriptor[] selected = pluginTable.getSelectedObjects();
|
||||
pluginsModel.setSortByStatus(state);
|
||||
pluginsModel.sort();
|
||||
if (selected != null) {
|
||||
select(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MyPluginsFilter extends FilterComponent {
|
||||
|
||||
public MyPluginsFilter() {
|
||||
@@ -634,4 +613,10 @@ public abstract class PluginManagerMain implements Disposable {
|
||||
e.getPresentation().setEnabled(!myBusy);
|
||||
}
|
||||
}
|
||||
|
||||
protected DefaultActionGroup createSortersGroup() {
|
||||
final DefaultActionGroup group = new DefaultActionGroup("Sort by", true);
|
||||
group.addAction(new SortByStatusAction(pluginTable, pluginsModel));
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -22,14 +22,14 @@ import com.intellij.util.ui.SortableColumnModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: stathik
|
||||
* Date: Dec 26, 2003
|
||||
* Time: 4:16:50 PM
|
||||
* To change this template use Options | File Templates.
|
||||
* @author stathik
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
abstract public class PluginTableModel extends AbstractTableModel implements SortableColumnModel {
|
||||
protected static final String NAME = "Name";
|
||||
@@ -38,6 +38,9 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
private RowSorter.SortKey myDefaultSortKey;
|
||||
protected final List<IdeaPluginDescriptor> filtered = new ArrayList<IdeaPluginDescriptor>();
|
||||
private boolean mySortByStatus;
|
||||
private boolean mySortByRating;
|
||||
private boolean mySortByDownloads;
|
||||
private boolean mySortByUpdated;
|
||||
|
||||
protected PluginTableModel() {
|
||||
}
|
||||
@@ -156,7 +159,7 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
|
||||
public abstract boolean isPluginDescriptorAccepted(IdeaPluginDescriptor descriptor);
|
||||
|
||||
protected void sort() {
|
||||
public void sort() {
|
||||
Collections.sort(view, columns[getNameColumn()].getComparator());
|
||||
fireTableDataChanged();
|
||||
}
|
||||
@@ -168,7 +171,31 @@ abstract public class PluginTableModel extends AbstractTableModel implements Sor
|
||||
public void setSortByStatus(boolean sortByStatus) {
|
||||
mySortByStatus = sortByStatus;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSortByRating() {
|
||||
return mySortByRating;
|
||||
}
|
||||
|
||||
public void setSortByRating(boolean sortByRating) {
|
||||
mySortByRating = sortByRating;
|
||||
}
|
||||
|
||||
public boolean isSortByDownloads() {
|
||||
return mySortByDownloads;
|
||||
}
|
||||
|
||||
public void setSortByDownloads(boolean sortByDownloads) {
|
||||
mySortByDownloads = sortByDownloads;
|
||||
}
|
||||
|
||||
public boolean isSortByUpdated() {
|
||||
return mySortByUpdated;
|
||||
}
|
||||
|
||||
public void setSortByUpdated(boolean sortByUpdated) {
|
||||
mySortByUpdated = sortByUpdated;
|
||||
}
|
||||
|
||||
public List<IdeaPluginDescriptor> getAllPlugins() {
|
||||
final ArrayList<IdeaPluginDescriptor> list = new ArrayList<IdeaPluginDescriptor>();
|
||||
list.addAll(view);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.ide.plugins.sorters;
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.ide.plugins.PluginTable;
|
||||
import com.intellij.ide.plugins.PluginTableModel;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class SortByStatusAction extends ToggleAction {
|
||||
private final PluginTable myTable;
|
||||
private final PluginTableModel myModel;
|
||||
|
||||
public SortByStatusAction(PluginTable pluginTable, PluginTableModel pluginsModel) {
|
||||
super("Status", "Status", null);
|
||||
myTable = pluginTable;
|
||||
myModel = pluginsModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return myModel.isSortByStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
IdeaPluginDescriptor[] selected = myTable.getSelectedObjects();
|
||||
myModel.setSortByStatus(state);
|
||||
myModel.sort();
|
||||
if (selected != null) {
|
||||
myTable.select(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user