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
|
// Copyright (C) 2012 The Android Open Source Project
//
// 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.google.gerrit.client.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.api.ExtensionScreen;
import com.google.gerrit.client.plugins.PluginInfo;
import com.google.gerrit.client.plugins.PluginMap;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.FancyFlexTable;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.ImageResourceRenderer;
import com.google.gwt.user.client.ui.Panel;
public class PluginListScreen extends PluginScreen {
private Panel pluginPanel;
private PluginTable pluginTable;
@Override
protected void onInitUI() {
super.onInitUI();
initPluginList();
}
@Override
protected void onLoad() {
super.onLoad();
PluginMap.all(
new ScreenLoadCallback<PluginMap>(this) {
@Override
protected void preDisplay(final PluginMap result) {
pluginTable.display(result);
}
});
}
private void initPluginList() {
pluginTable = new PluginTable();
pluginTable.addStyleName(Gerrit.RESOURCES.css().pluginsTable());
pluginPanel = new FlowPanel();
pluginPanel.setWidth("500px");
pluginPanel.add(pluginTable);
add(pluginPanel);
}
private static class PluginTable extends FancyFlexTable<PluginInfo> {
PluginTable() {
table.setText(0, 1, AdminConstants.I.columnPluginName());
table.setText(0, 2, AdminConstants.I.columnPluginSettings());
table.setText(0, 3, AdminConstants.I.columnPluginVersion());
table.setText(0, 4, AdminConstants.I.columnPluginStatus());
final FlexCellFormatter fmt = table.getFlexCellFormatter();
fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().dataHeader());
fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader());
fmt.addStyleName(0, 3, Gerrit.RESOURCES.css().dataHeader());
fmt.addStyleName(0, 4, Gerrit.RESOURCES.css().dataHeader());
}
void display(final PluginMap plugins) {
while (1 < table.getRowCount()) {
table.removeRow(table.getRowCount() - 1);
}
for (final PluginInfo p : Natives.asList(plugins.values())) {
final int row = table.getRowCount();
table.insertRow(row);
applyDataRowStyle(row);
populate(row, p);
}
}
void populate(final int row, final PluginInfo plugin) {
if (plugin.disabled() || plugin.indexUrl() == null) {
table.setText(row, 1, plugin.name());
} else {
table.setWidget(
row, 1, new Anchor(plugin.name(), Gerrit.selfRedirect(plugin.indexUrl()), "_blank"));
if (new ExtensionScreen(plugin.name() + "/settings").isFound()) {
InlineHyperlink adminScreenLink = new InlineHyperlink();
adminScreenLink.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.gear()));
adminScreenLink.setTargetHistoryToken("/x/" + plugin.name() + "/settings");
adminScreenLink.setTitle(AdminConstants.I.pluginSettingsToolTip());
table.setWidget(row, 2, adminScreenLink);
}
}
table.setText(row, 3, plugin.version());
table.setText(
row,
4,
plugin.disabled() ? AdminConstants.I.pluginDisabled() : AdminConstants.I.pluginEnabled());
final FlexCellFormatter fmt = table.getFlexCellFormatter();
fmt.addStyleName(row, 1, Gerrit.RESOURCES.css().dataCell());
fmt.addStyleName(row, 2, Gerrit.RESOURCES.css().dataCell());
fmt.addStyleName(row, 3, Gerrit.RESOURCES.css().dataCell());
fmt.addStyleName(row, 4, Gerrit.RESOURCES.css().dataCell());
setRowItem(row, plugin);
}
}
}
|