diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/AbstractSortByAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/AbstractSortByAction.java new file mode 100644 index 000000000000..b858a3025e1f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/AbstractSortByAction.java @@ -0,0 +1,55 @@ +/* + * 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 abstract class AbstractSortByAction extends ToggleAction { + protected final PluginTable myTable; + protected final PluginTableModel myModel; + + public AbstractSortByAction(String name, PluginTable table, PluginTableModel model) { + super(name, name, null); + myTable = table; + myModel = model; + } + + public abstract boolean isSelected(); + + protected abstract void setSelected(boolean state); + + @Override + public final boolean isSelected(AnActionEvent e) { + return isSelected(); + } + + @Override + public final void setSelected(AnActionEvent e, boolean state) { + IdeaPluginDescriptor[] selected = myTable.getSelectedObjects(); + setSelected(state); + myModel.sort(); + if (selected != null) { + myTable.select(selected); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByDownloadsAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByDownloadsAction.java new file mode 100644 index 000000000000..34066c3ddc61 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByDownloadsAction.java @@ -0,0 +1,38 @@ +/* + * 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.PluginTable; +import com.intellij.ide.plugins.PluginTableModel; + +/** + * @author Konstantin Bulenkov + */ +public class SortByDownloadsAction extends AbstractSortByAction { + public SortByDownloadsAction(PluginTable table, PluginTableModel model) { + super("Downloads", table, model); + } + + @Override + public boolean isSelected() { + return myModel.isSortByDownloads(); + } + + @Override + protected void setSelected(boolean state) { + myModel.setSortByDownloads(state); + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByRatingAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByRatingAction.java new file mode 100644 index 000000000000..3d63b09f379a --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByRatingAction.java @@ -0,0 +1,38 @@ +/* + * 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.PluginTable; +import com.intellij.ide.plugins.PluginTableModel; + +/** + * @author Konstantin Bulenkov + */ +public class SortByRatingAction extends AbstractSortByAction { + public SortByRatingAction(PluginTable table, PluginTableModel model) { + super("Rating", table, model); + } + + @Override + public boolean isSelected() { + return myModel.isSortByRating(); + } + + @Override + protected void setSelected(boolean state) { + myModel.setSortByRating(state); + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByStatusAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByStatusAction.java index 44deaa56c058..8092f63468de 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByStatusAction.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByStatusAction.java @@ -15,37 +15,24 @@ */ 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 class SortByStatusAction extends AbstractSortByAction { public SortByStatusAction(PluginTable pluginTable, PluginTableModel pluginsModel) { - super("Status", "Status", null); - myTable = pluginTable; - myModel = pluginsModel; + super("Status", pluginTable, pluginsModel); } @Override - public boolean isSelected(AnActionEvent e) { + public boolean isSelected() { return myModel.isSortByStatus(); } @Override - public void setSelected(AnActionEvent e, boolean state) { - IdeaPluginDescriptor[] selected = myTable.getSelectedObjects(); + public void setSelected(boolean state) { myModel.setSortByStatus(state); - myModel.sort(); - if (selected != null) { - myTable.select(selected); - } } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByUpdatedAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByUpdatedAction.java new file mode 100644 index 000000000000..c4e3a9dfeaee --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/plugins/sorters/SortByUpdatedAction.java @@ -0,0 +1,38 @@ +/* + * 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.PluginTable; +import com.intellij.ide.plugins.PluginTableModel; + +/** + * @author Konstantin Bulenkov + */ +public class SortByUpdatedAction extends AbstractSortByAction { + public SortByUpdatedAction(PluginTable table, PluginTableModel model) { + super("Last Updated", table, model); + } + + @Override + public boolean isSelected() { + return myModel.isSortByUpdated(); + } + + @Override + protected void setSelected(boolean state) { + myModel.setSortByUpdated(state); + } +}