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.connector.cfg.ProjectCfgManager;
19  import com.atlassian.theplugin.commons.ServerType;
20  import com.atlassian.theplugin.commons.cfg.*;
21  import com.atlassian.theplugin.commons.remoteapi.ServerData;
22  import com.atlassian.theplugin.commons.util.MiscUtil;
23  import org.jetbrains.annotations.NotNull;
24  
25  import javax.swing.*;
26  import java.awt.*;
27  import java.awt.event.ActionEvent;
28  import java.awt.event.ActionListener;
29  import java.awt.event.WindowAdapter;
30  import java.awt.event.WindowEvent;
31  import java.util.Collection;
32  
33  public final class ServerConfigPanelTestUi {
34  	private ServerConfigPanelTestUi() {
35  	}
36  
37  	public static void main(String[] args) {
38  		JFrame frame = new JFrame("ServerConfigPanel test");
39  		final BambooServerCfg bambooServerCfg = new BambooServerCfg(false, "mybamboo2", new ServerId());
40  		final Collection<ServerCfg> serverCfgs = MiscUtil.buildArrayList(
41  				new BambooServerCfg(true, "mybamboo", new ServerId()),
42  				bambooServerCfg,
43  				new CrucibleServerCfg("Crucible EAC", new ServerId()),
44  				new JiraServerCfg("My Jira Server", new ServerId()),
45  				new JiraServerCfg("Second Jira", new ServerId()),
46  				new FishEyeServerCfg("FishEye1 Server", new ServerId())
47  		);
48  
49  		final Collection<ServerCfg> serverCfgs2 = MiscUtil.buildArrayList(
50  				new BambooServerCfg(true, "2-mybamboo", new ServerId()),
51  				bambooServerCfg,
52  				new CrucibleServerCfg("2-Crucible EAC Very Very long name", new ServerId()),
53  				new JiraServerCfg("2-My Jira Server", new ServerId()),
54  				new JiraServerCfg("2-Second Jira", new ServerId())
55  		);
56  
57  		ServerConfigPanel configPanel = new ServerConfigPanel(
58  				null, null, new ProjectConfiguration(serverCfgs), null, false) {
59  
60  			@Override
61  			protected JComponent createToolbar() {
62  				JToolBar toolbar = new JToolBar("My Fake Toolbar", JToolBar.HORIZONTAL);
63  				final JButton button = new JButton("Test Only");
64  				button.addActionListener(new ActionListener() {
65  
66  					public void actionPerformed(final ActionEvent e) {
67  						setData(serverCfgs2);
68  					}
69  				});
70  				toolbar.add(button);
71  				final JButton addButton = new JButton("Add");
72  				addButton.addActionListener(new ActionListener() {
73  
74  					public void actionPerformed(final ActionEvent e) {
75  						addServer(ServerType.CRUCIBLE_SERVER);
76  					}
77  				});
78  				toolbar.add(addButton);
79  				return toolbar;
80  			}
81  		};
82  
83  		frame.getContentPane().add(configPanel, BorderLayout.CENTER);
84  
85  		//Finish setting up the frame, and show it.
86  		frame.addWindowListener(new WindowAdapter() {
87  			@Override
88  			public void windowClosing(WindowEvent e) {
89  				System.exit(0);
90  			}
91  		});
92  		frame.pack();
93  		frame.setVisible(true);
94  
95  	}
96  
97  
98  }
99  
100 class LocalProjectCfgManager implements ProjectCfgManager {
101 
102 	@NotNull
103 	public ServerData getServerData(@NotNull final Server serverCfg) {
104 		return new ServerData(serverCfg.getName(), serverCfg.getServerId().toString(), serverCfg.getUserName(),
105 				serverCfg.getPassword(), serverCfg.getUrl());
106 	}
107 
108 	public Collection<BambooServerCfg> getAllEnabledBambooServers() {
109 		throw new UnsupportedOperationException("not yet implemented");
110 	}
111 
112 }