commit | author | age
|
19c634
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
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
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
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.
|
|
15 |
*/
|
|
16 |
package com.gitblit.client;
|
|
17 |
|
|
18 |
import java.awt.BorderLayout;
|
|
19 |
import java.awt.Component;
|
841651
|
20 |
import java.awt.Insets;
|
19c634
|
21 |
import java.io.IOException;
|
841651
|
22 |
import java.util.List;
|
19c634
|
23 |
|
JM |
24 |
import javax.swing.JPanel;
|
|
25 |
import javax.swing.JTabbedPane;
|
38688b
|
26 |
import javax.swing.event.ChangeEvent;
|
JM |
27 |
import javax.swing.event.ChangeListener;
|
19c634
|
28 |
|
841651
|
29 |
import com.gitblit.client.ClosableTabComponent.CloseTabListener;
|
17820f
|
30 |
import com.gitblit.models.FeedModel;
|
19c634
|
31 |
|
841651
|
32 |
/**
|
c25a1d
|
33 |
* GitblitPanel is a container for the repository, users, settings, etc panels.
|
841651
|
34 |
*
|
JM |
35 |
* @author James Moger
|
|
36 |
*
|
|
37 |
*/
|
|
38 |
public class GitblitPanel extends JPanel implements CloseTabListener {
|
19c634
|
39 |
|
JM |
40 |
private static final long serialVersionUID = 1L;
|
|
41 |
|
4cac0d
|
42 |
private final RegistrationsDialog.RegistrationListener listener;
|
841651
|
43 |
|
84c1d5
|
44 |
private GitblitClient gitblit;
|
841651
|
45 |
|
JM |
46 |
private JTabbedPane tabs;
|
19c634
|
47 |
|
38688b
|
48 |
private RepositoriesPanel repositoriesPanel;
|
841651
|
49 |
|
38688b
|
50 |
private FeedsPanel feedsPanel;
|
841651
|
51 |
|
38688b
|
52 |
private UsersPanel usersPanel;
|
f08aab
|
53 |
|
JM |
54 |
private TeamsPanel teamsPanel;
|
4b430b
|
55 |
|
38688b
|
56 |
private SettingsPanel settingsPanel;
|
f306ef
|
57 |
|
486ee1
|
58 |
private StatusPanel statusPanel;
|
4cac0d
|
59 |
|
JM |
60 |
public GitblitPanel(GitblitRegistration reg, RegistrationsDialog.RegistrationListener listener) {
|
|
61 |
this.gitblit = new GitblitClient(reg);
|
|
62 |
this.listener = listener;
|
19c634
|
63 |
|
ee25c8
|
64 |
tabs = new JTabbedPane(JTabbedPane.BOTTOM);
|
JM |
65 |
tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel());
|
609a16
|
66 |
tabs.addTab(Translation.get("gb.activity"), createFeedsPanel());
|
f08aab
|
67 |
tabs.addTab(Translation.get("gb.teams"), createTeamsPanel());
|
ee25c8
|
68 |
tabs.addTab(Translation.get("gb.users"), createUsersPanel());
|
JM |
69 |
tabs.addTab(Translation.get("gb.settings"), createSettingsPanel());
|
486ee1
|
70 |
tabs.addTab(Translation.get("gb.status"), createStatusPanel());
|
38688b
|
71 |
tabs.addChangeListener(new ChangeListener() {
|
JM |
72 |
public void stateChanged(ChangeEvent e) {
|
c25a1d
|
73 |
tabs.getSelectedComponent().requestFocus();
|
38688b
|
74 |
}
|
c25a1d
|
75 |
});
|
ee25c8
|
76 |
|
JM |
77 |
setLayout(new BorderLayout());
|
|
78 |
add(tabs, BorderLayout.CENTER);
|
|
79 |
}
|
|
80 |
|
|
81 |
private JPanel createRepositoriesPanel() {
|
38688b
|
82 |
repositoriesPanel = new RepositoriesPanel(gitblit) {
|
44f2da
|
83 |
|
JM |
84 |
private static final long serialVersionUID = 1L;
|
|
85 |
|
38688b
|
86 |
@Override
|
JM |
87 |
protected void subscribeFeeds(List<FeedModel> feeds) {
|
|
88 |
GitblitPanel.this.subscribeFeeds(feeds);
|
44f2da
|
89 |
}
|
841651
|
90 |
|
38688b
|
91 |
@Override
|
JM |
92 |
protected void updateUsersTable() {
|
|
93 |
usersPanel.updateTable(false);
|
|
94 |
}
|
f08aab
|
95 |
|
JM |
96 |
@Override
|
|
97 |
protected void updateTeamsTable() {
|
|
98 |
teamsPanel.updateTable(false);
|
|
99 |
}
|
38688b
|
100 |
|
JM |
101 |
};
|
ee25c8
|
102 |
return repositoriesPanel;
|
JM |
103 |
}
|
|
104 |
|
4cac0d
|
105 |
private JPanel createFeedsPanel() {
|
38688b
|
106 |
feedsPanel = new FeedsPanel(gitblit) {
|
4cac0d
|
107 |
private static final long serialVersionUID = 1L;
|
JM |
108 |
|
|
109 |
@Override
|
38688b
|
110 |
protected void subscribeFeeds(List<FeedModel> feeds) {
|
JM |
111 |
GitblitPanel.this.subscribeFeeds(feeds);
|
4cac0d
|
112 |
}
|
JM |
113 |
};
|
38688b
|
114 |
return feedsPanel;
|
ee25c8
|
115 |
}
|
JM |
116 |
|
|
117 |
private JPanel createUsersPanel() {
|
f08aab
|
118 |
usersPanel = new UsersPanel(gitblit) {
|
JM |
119 |
|
|
120 |
private static final long serialVersionUID = 1L;
|
|
121 |
|
|
122 |
@Override
|
|
123 |
protected void updateTeamsTable() {
|
|
124 |
teamsPanel.updateTable(false);
|
|
125 |
}
|
|
126 |
};
|
ee25c8
|
127 |
return usersPanel;
|
841651
|
128 |
}
|
f08aab
|
129 |
|
JM |
130 |
private JPanel createTeamsPanel() {
|
|
131 |
teamsPanel = new TeamsPanel(gitblit) {
|
|
132 |
|
|
133 |
private static final long serialVersionUID = 1L;
|
|
134 |
|
|
135 |
@Override
|
|
136 |
protected void updateUsersTable() {
|
|
137 |
usersPanel.updateTable(false);
|
|
138 |
}
|
|
139 |
};
|
|
140 |
return teamsPanel;
|
|
141 |
}
|
841651
|
142 |
|
ee25c8
|
143 |
private JPanel createSettingsPanel() {
|
38688b
|
144 |
settingsPanel = new SettingsPanel(gitblit);
|
ee25c8
|
145 |
return settingsPanel;
|
15a51d
|
146 |
}
|
841651
|
147 |
|
486ee1
|
148 |
private JPanel createStatusPanel() {
|
38688b
|
149 |
statusPanel = new StatusPanel(gitblit);
|
JM |
150 |
return statusPanel;
|
486ee1
|
151 |
}
|
JM |
152 |
|
15a51d
|
153 |
public void login() throws IOException {
|
JM |
154 |
gitblit.login();
|
|
155 |
|
38688b
|
156 |
repositoriesPanel.updateTable(true);
|
JM |
157 |
feedsPanel.updateTable(true);
|
4cac0d
|
158 |
|
d03aff
|
159 |
if (gitblit.allowManagement()) {
|
f08aab
|
160 |
if (gitblit.getProtocolVersion() >= 2) {
|
JM |
161 |
// refresh teams panel
|
|
162 |
teamsPanel.updateTable(false);
|
|
163 |
} else {
|
|
164 |
// remove teams panel
|
|
165 |
String teams = Translation.get("gb.teams");
|
|
166 |
for (int i = 0; i < tabs.getTabCount(); i++) {
|
|
167 |
if (teams.equals(tabs.getTitleAt(i))) {
|
|
168 |
tabs.removeTabAt(i);
|
|
169 |
break;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|
38688b
|
173 |
usersPanel.updateTable(false);
|
15a51d
|
174 |
} else {
|
841651
|
175 |
// user does not have administrator privileges
|
JM |
176 |
// hide admin repository buttons
|
38688b
|
177 |
repositoriesPanel.disableManagement();
|
841651
|
178 |
|
ac7f17
|
179 |
while (tabs.getTabCount() > 2) {
|
d03aff
|
180 |
// remove all management/administration tabs
|
ac7f17
|
181 |
tabs.removeTabAt(2);
|
d03aff
|
182 |
}
|
JM |
183 |
}
|
|
184 |
|
|
185 |
if (gitblit.allowAdministration()) {
|
38688b
|
186 |
settingsPanel.updateTable(true);
|
JM |
187 |
statusPanel.updateTable(false);
|
d03aff
|
188 |
} else {
|
c25a1d
|
189 |
// remove the settings and status tab
|
8e40cd
|
190 |
String[] titles = { Translation.get("gb.settings"), Translation.get("gb.status") };
|
JM |
191 |
for (String title : titles) {
|
|
192 |
for (int i = 0; i < tabs.getTabCount(); i++) {
|
|
193 |
if (tabs.getTitleAt(i).equals(title)) {
|
|
194 |
tabs.removeTabAt(i);
|
|
195 |
break;
|
|
196 |
}
|
f306ef
|
197 |
}
|
4b430b
|
198 |
}
|
841651
|
199 |
}
|
19c634
|
200 |
}
|
JM |
201 |
|
841651
|
202 |
@Override
|
JM |
203 |
public Insets getInsets() {
|
38688b
|
204 |
return Utils.INSETS;
|
841651
|
205 |
}
|
JM |
206 |
|
|
207 |
@Override
|
|
208 |
public void closeTab(Component c) {
|
15a51d
|
209 |
gitblit = null;
|
JM |
210 |
}
|
|
211 |
|
17820f
|
212 |
protected void subscribeFeeds(final List<FeedModel> feeds) {
|
JM |
213 |
SubscriptionsDialog dialog = new SubscriptionsDialog(feeds) {
|
|
214 |
|
|
215 |
private static final long serialVersionUID = 1L;
|
|
216 |
|
|
217 |
@Override
|
|
218 |
public void save() {
|
|
219 |
gitblit.updateSubscribedFeeds(feeds);
|
|
220 |
listener.saveRegistration(gitblit.reg.name, gitblit.reg);
|
|
221 |
setVisible(false);
|
38688b
|
222 |
repositoriesPanel.updateTable(false);
|
4cac0d
|
223 |
}
|
17820f
|
224 |
};
|
JM |
225 |
dialog.setLocationRelativeTo(GitblitPanel.this);
|
|
226 |
dialog.setVisible(true);
|
2a99c3
|
227 |
}
|
15a51d
|
228 |
} |