2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ide
.plugins
;
18 import com
.intellij
.openapi
.extensions
.PluginId
;
19 import com
.intellij
.util
.ui
.ColumnInfo
;
20 import com
.intellij
.util
.ui
.SortableColumnModel
;
22 import javax
.swing
.table
.AbstractTableModel
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Collections
;
25 import java
.util
.List
;
28 * Created by IntelliJ IDEA.
32 * To change this template use Options | File Templates.
34 abstract public class PluginTableModel
extends AbstractTableModel
implements SortableColumnModel
{
35 protected ColumnInfo
[] columns
;
36 protected SortableProvider sortableProvider
;
37 protected List
<IdeaPluginDescriptor
> view
;
39 protected PluginTableModel() {
42 public PluginTableModel(SortableProvider sortableProvider
, ColumnInfo
... columns
) {
43 this.columns
= columns
;
44 this.sortableProvider
= sortableProvider
;
47 public int getColumnCount() {
48 return columns
.length
;
51 public ColumnInfo
[] getColumnInfos() {
55 public boolean isSortable() {
59 public void setSortable(boolean aBoolean
) {
60 // do nothing cause it's always sortable
63 public String
getColumnName(int column
) {
64 return columns
[column
].getName();
67 public int getSortedColumnIndex() {
68 return sortableProvider
.getSortColumn();
71 public int getSortingType() {
72 return sortableProvider
.getSortOrder();
75 public IdeaPluginDescriptor
getObjectAt (int row
) {
79 public int getRowCount() {
83 public Object
getValueAt(int rowIndex
, int columnIndex
) {
84 return columns
[columnIndex
].valueOf(getObjectAt(rowIndex
));
87 public boolean isCellEditable(final int rowIndex
, final int columnIndex
) {
88 return columns
[columnIndex
].isCellEditable(getObjectAt(rowIndex
));
91 public void setValueAt(final Object aValue
, final int rowIndex
, final int columnIndex
) {
92 columns
[columnIndex
].setValue(getObjectAt(rowIndex
), aValue
);
95 public void sortByColumn(int columnIndex
) {
96 Collections
.sort(view
, columns
[columnIndex
].getComparator());
97 fireTableDataChanged();
100 public void sortByColumn(int columnIndex
, int sortingType
) {
101 sortByColumn(columnIndex
);
105 public ArrayList
<IdeaPluginDescriptorImpl
> dependent(IdeaPluginDescriptorImpl plugin
) {
106 ArrayList
<IdeaPluginDescriptorImpl
> list
= new ArrayList
<IdeaPluginDescriptorImpl
>();
107 for (IdeaPluginDescriptor any
: view
) {
108 if (any
instanceof IdeaPluginDescriptorImpl
) {
109 PluginId
[] dep
= any
.getDependentPluginIds();
110 for (PluginId id
: dep
) {
111 if (id
== plugin
.getPluginId()) {
112 list
.add((IdeaPluginDescriptorImpl
)any
);
121 public abstract void addData(List
<IdeaPluginDescriptor
> list
);
123 public abstract void modifyData(List
<IdeaPluginDescriptor
> list
);
125 public void filter(ArrayList
<IdeaPluginDescriptor
> filtered
){
129 protected void safeSort() {
130 final int sortColumn
= sortableProvider
.getSortColumn();
131 sortByColumn(-1 < sortColumn
&& sortColumn
< getColumnCount() ? sortColumn
: 0);
134 public abstract int getNameColumn();