View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
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.atlassian.theplugin.idea.config.serverconfig;
17  
18  import com.atlassian.theplugin.commons.ServerType;
19  import com.atlassian.theplugin.commons.cfg.BambooServerCfg;
20  import com.atlassian.theplugin.commons.cfg.CrucibleServerCfg;
21  import com.atlassian.theplugin.commons.cfg.JiraServerCfg;
22  import com.atlassian.theplugin.commons.cfg.ServerCfg;
23  import com.atlassian.theplugin.commons.cfg.ServerId;
24  import com.atlassian.theplugin.commons.util.MiscUtil;
25  
26  import javax.swing.*;
27  import java.awt.*;
28  import java.awt.event.ActionEvent;
29  import java.awt.event.ActionListener;
30  import java.awt.event.WindowAdapter;
31  import java.awt.event.WindowEvent;
32  import java.util.Collection;
33  
34  public final class ServerConfigPanelTestUi {
35  
36  	private ServerConfigPanelTestUi() {
37  	}
38  
39  	public static void main(String[] args) {
40          JFrame frame = new JFrame("ServerConfigPanel test");
41          final BambooServerCfg bambooServerCfg = new BambooServerCfg(false, "mybamboo2", new ServerId());
42          final Collection<ServerCfg> serverCfgs = MiscUtil.buildArrayList(
43                  new BambooServerCfg(true, "mybamboo", new ServerId()),
44                  bambooServerCfg,
45                  new CrucibleServerCfg("Crucible EAC", new ServerId()),
46                  new JiraServerCfg("My Jira Server", new ServerId()),
47                  new JiraServerCfg("Second Jira", new ServerId())
48          );
49  
50          final Collection<ServerCfg> serverCfgs2 = MiscUtil.buildArrayList(
51                  new BambooServerCfg(true, "2-mybamboo", new ServerId()),
52                  bambooServerCfg,
53                  new CrucibleServerCfg("2-Crucible EAC Very Very long name", new ServerId()),
54                  new JiraServerCfg("2-My Jira Server", new ServerId()),
55                  new JiraServerCfg("2-Second Jira", new ServerId())
56          );
57  
58          ServerConfigPanel configPanel = new ServerConfigPanel(null, serverCfgs) {
59              @Override
60              protected JComponent createToolbar() {
61                  JToolBar toolbar = new JToolBar("My Fake Toolbar", JToolBar.HORIZONTAL);
62                  final JButton button = new JButton("Test Only");
63                  button.addActionListener(new ActionListener() {
64  
65                      public void actionPerformed(final ActionEvent e) {
66                          setData(serverCfgs2);
67                      }
68                  });
69                  toolbar.add(button);
70                  final JButton addButton = new JButton("Add");
71                  addButton.addActionListener(new ActionListener() {
72  
73                      public void actionPerformed(final ActionEvent e) {
74                          addServer(ServerType.CRUCIBLE_SERVER);
75                      }
76                  });
77                  toolbar.add(addButton);
78                  return toolbar;
79              }
80          };
81  
82          frame.getContentPane().add(configPanel, BorderLayout.CENTER);
83  
84          //Finish setting up the frame, and show it.
85          frame.addWindowListener(new WindowAdapter() {
86              @Override
87              public void windowClosing(WindowEvent e) {
88                  System.exit(0);
89              }
90          });
91          frame.pack();
92          frame.setVisible(true);
93  
94      }
95  }