blob: a3e989ef5d9157e05371725df80d58cb81435686 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.pluginmanager;
import java.util.*;
import javax.swing.table.*;
import org.osgi.framework.*;
/**
* The <tt>TableModel</tt> of the table containing all plug-ins.
*
* @author Yana Stamcheva
*/
public class PluginTableModel extends AbstractTableModel
{
private BundleContext bundleContext = PluginManagerActivator.bundleContext;
private boolean showSystemBundles;
private Object showSystemBundlesSync = new Object();
private Bundle[] bundles = null;
private BundleComparator bundleComparator = new BundleComparator();
/**
* Create an instance of <tt>PluginTableModel</tt>
*/
public PluginTableModel()
{
refreshSortedBundlesList();
}
/**
* Returns the count of table rows.
* @return int the count of table rows
*/
public int getRowCount()
{
boolean showSystem;
synchronized (showSystemBundlesSync)
{
showSystem = showSystemBundles;
}
if(bundles == null)
return 0;
else
{
if(showSystem)
return bundles.length;
else
{
int bundlesSize = 0;
for (int i = 0; i < bundles.length; i ++)
{
Bundle bundle = bundles[i];
Object sysBundleProp
= bundle.getHeaders().get("System-Bundle");
if(sysBundleProp == null || !sysBundleProp.equals("yes"))
bundlesSize++;
}
return bundlesSize;
}
}
}
/**
* Returns TRUE if the given <tt>Bundle</tt> is contained in this table,
* FALSE - otherwise.
* @param bundle the <tt>Bundle</tt> to search for
* @return TRUE if the given <tt>Bundle</tt> is contained in this table,
* FALSE - otherwise.
*/
public boolean contains(Bundle bundle)
{
boolean showSystem;
synchronized (showSystemBundlesSync)
{
showSystem = showSystemBundles;
}
for (int i = 0; i < bundles.length; i ++)
{
Bundle b = bundles[i];
if(b.equals(bundle))
{
if(showSystem)
return true;
else
{
Object sysBundleProp
= bundle.getHeaders().get("System-Bundle");
if(sysBundleProp == null || !sysBundleProp.equals("yes"))
return true;
else
return false;
}
}
}
return false;
}
/**
* Returns the count of table columns.
* @return int the count of table columns
*/
public int getColumnCount()
{
return 1;
}
/**
* Returns FALSE for all cells in this table.
*/
public boolean isCellEditable(int row, int column)
{
return false;
}
/**
* Returns the value in the cell given by row and column.
*/
public Object getValueAt(int row, int column)
{
boolean showSystem;
synchronized (showSystemBundlesSync)
{
showSystem = showSystemBundles;
}
if(showSystem)
return bundles[row];
else
{
int bundleCounter = 0;
for(int i = 0; i < bundles.length; i++)
{
Object sysBundleProp
= bundles[i].getHeaders().get("System-Bundle");
//ignore if this is a system bundle
if(sysBundleProp != null && sysBundleProp.equals("yes"))
continue;
if(bundleCounter == row)
return bundles[i];
bundleCounter++;
}
}
return null;
}
/**
* Updates the table content.
*/
public void update()
{
refreshSortedBundlesList();
fireTableDataChanged();
}
/**
* Returns TRUE if system bundles are show, FALSE - otherwise.
* @return TRUE if system bundles are show, FALSE - otherwise
*/
public boolean isShowSystemBundles()
{
boolean showSystem;
synchronized (showSystemBundlesSync)
{
showSystem = showSystemBundles;
}
return showSystem;
}
/**
* Sets the <tt>showSystemBundles</tt> property.
* @param showSystemBundles indicates if system bundles will be shown or not
*/
public void setShowSystemBundles(boolean showSystemBundles)
{
synchronized (showSystemBundlesSync)
{
this.showSystemBundles = showSystemBundles;
}
}
/**
* Syncs the content of the bundle list with the bundles currently
* available in the bundle context and sorts it again.
*/
private void refreshSortedBundlesList()
{
this.bundles = this.bundleContext.getBundles();
Arrays.sort(this.bundles, bundleComparator);
}
}
|