| | |
| | | import java.awt.Font;
|
| | | import java.awt.GridLayout;
|
| | | import java.awt.Insets;
|
| | | import java.awt.event.ActionEvent;
|
| | | import java.awt.event.ActionListener;
|
| | | import java.io.IOException;
|
| | |
|
| | | import javax.swing.JButton;
|
| | | import javax.swing.JLabel;
|
| | | import javax.swing.JPanel;
|
| | | import javax.swing.JScrollPane;
|
| | | import javax.swing.JTable;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.models.ServerStatus;
|
| | | import com.gitblit.utils.ByteFormat;
|
| | | import com.gitblit.utils.TimeUtils;
|
| | |
| | | public class StatusPanel extends JPanel {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | private final Insets insets = new Insets(5, 5, 5, 5);
|
| | | private final GitblitClient gitblit;
|
| | | private JLabel bootDate;
|
| | | private JLabel url;
|
| | | private JLabel servletContainer;
|
| | | private JLabel heapMaximum;
|
| | | private JLabel heapAllocated;
|
| | | private JLabel heapUsed;
|
| | | private PropertiesTableModel model;
|
| | | private HeaderPanel headerPanel;
|
| | | private PropertiesTableModel tableModel;
|
| | | private HeaderPanel header;
|
| | | private JLabel version;
|
| | | private JLabel releaseDate;
|
| | |
|
| | | public StatusPanel() {
|
| | | public StatusPanel(GitblitClient gitblit) {
|
| | | super();
|
| | | this.gitblit = gitblit;
|
| | | initialize();
|
| | | }
|
| | |
|
| | | public StatusPanel(String url, ServerStatus status) {
|
| | | this();
|
| | | setStatus(url, status);
|
| | | }
|
| | |
|
| | | private void initialize() {
|
| | | JButton refreshStatus = new JButton(Translation.get("gb.refresh"));
|
| | | refreshStatus.addActionListener(new ActionListener() {
|
| | | public void actionPerformed(ActionEvent e) {
|
| | | refreshStatus();
|
| | | }
|
| | | });
|
| | |
|
| | | version = new JLabel();
|
| | | releaseDate = new JLabel();
|
| | | bootDate = new JLabel();
|
| | |
| | | heapAllocated = new JLabel();
|
| | | heapUsed = new JLabel();
|
| | |
|
| | | JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 0, 5)) {
|
| | | JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 0, Utils.MARGIN)) {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | public Insets getInsets() {
|
| | | return insets;
|
| | | return Utils.INSETS;
|
| | | }
|
| | | };
|
| | | fieldsPanel.add(createFieldPanel("gb.version", version));
|
| | |
| | | fieldsPanel.add(createFieldPanel("gb.heapAllocated", heapAllocated));
|
| | | fieldsPanel.add(createFieldPanel("gb.heapMaximum", heapMaximum));
|
| | |
|
| | | model = new PropertiesTableModel();
|
| | | JTable propertiesTable = Utils.newTable(model, Utils.DATE_FORMAT);
|
| | | tableModel = new PropertiesTableModel();
|
| | | JTable propertiesTable = Utils.newTable(tableModel, Utils.DATE_FORMAT);
|
| | | String name = propertiesTable.getColumnName(PropertiesTableModel.Columns.Name.ordinal());
|
| | | NameRenderer nameRenderer = new NameRenderer();
|
| | | propertiesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
|
| | |
| | | centerPanel.add(fieldsPanel, BorderLayout.NORTH);
|
| | | centerPanel.add(new JScrollPane(propertiesTable), BorderLayout.CENTER);
|
| | |
|
| | | headerPanel = new HeaderPanel(Translation.get("gb.status"), "health_16x16.png");
|
| | | JPanel controls = new JPanel();
|
| | | controls.add(refreshStatus);
|
| | |
|
| | | header = new HeaderPanel(Translation.get("gb.status"), "health_16x16.png");
|
| | | setLayout(new BorderLayout());
|
| | | add(headerPanel, BorderLayout.NORTH);
|
| | | add(header, BorderLayout.NORTH);
|
| | | add(centerPanel, BorderLayout.CENTER);
|
| | | add(controls, BorderLayout.SOUTH);
|
| | | }
|
| | |
|
| | | private JPanel createFieldPanel(String key, JLabel valueLabel) {
|
| | | JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
|
| | | JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
|
| | | JLabel textLabel = new JLabel(Translation.get(key));
|
| | | textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD));
|
| | | textLabel.setPreferredSize(new Dimension(120, 10));
|
| | |
| | |
|
| | | @Override
|
| | | public Insets getInsets() {
|
| | | return insets;
|
| | | return Utils.INSETS;
|
| | | }
|
| | |
|
| | | public void setStatus(String url, ServerStatus status) {
|
| | | headerPanel.setText(Translation.get("gb.status"));
|
| | | protected void refreshStatus() {
|
| | | GitblitWorker worker = new GitblitWorker(StatusPanel.this, RpcRequest.LIST_STATUS) {
|
| | | @Override
|
| | | protected Boolean doRequest() throws IOException {
|
| | | gitblit.refreshStatus();
|
| | | return true;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void onSuccess() {
|
| | | updateTable(false);
|
| | | }
|
| | | };
|
| | | worker.execute();
|
| | | }
|
| | |
|
| | | protected void updateTable(boolean pack) {
|
| | | ServerStatus status = gitblit.getStatus();
|
| | | header.setText(Translation.get("gb.status"));
|
| | | version.setText(Constants.NAME + (status.isGO ? " GO v" : " WAR v") + status.version);
|
| | | releaseDate.setText(status.releaseDate);
|
| | | bootDate.setText(status.bootDate.toString() + " (" + TimeUtils.timeAgo(status.bootDate)
|
| | | + ")");
|
| | | this.url.setText(url);
|
| | | url.setText(gitblit.url);
|
| | | servletContainer.setText(status.servletContainer);
|
| | | ByteFormat byteFormat = new ByteFormat();
|
| | | heapMaximum.setText(byteFormat.format(status.heapMaximum));
|
| | | heapAllocated.setText(byteFormat.format(status.heapAllocated));
|
| | | heapUsed.setText(byteFormat.format(status.heapAllocated - status.heapFree) + " ("
|
| | | + byteFormat.format(status.heapFree) + " " + Translation.get("gb.free") + ")");
|
| | | model.setProperties(status.systemProperties);
|
| | | model.fireTableDataChanged();
|
| | | tableModel.setProperties(status.systemProperties);
|
| | | tableModel.fireTableDataChanged();
|
| | | }
|
| | | }
|