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  
17  package com.atlassian.theplugin.idea.config;
18  
19  import com.atlassian.theplugin.commons.cfg.CfgManager;
20  import com.atlassian.theplugin.commons.configuration.PluginConfiguration;
21  import com.atlassian.theplugin.commons.configuration.PluginConfigurationBean;
22  import com.atlassian.theplugin.idea.Constants;
23  import com.atlassian.theplugin.idea.config.serverconfig.BambooGeneralForm;
24  import com.atlassian.theplugin.idea.config.serverconfig.CrucibleGeneralForm;
25  import com.atlassian.theplugin.idea.config.serverconfig.JiraGeneralForm;
26  
27  import javax.swing.*;
28  import java.awt.*;
29  
30  public final class ConfigPanel extends JPanel {
31  
32  	private transient PluginConfigurationBean localPluginConfigurationCopy = null;
33  
34  	private final FooterPanel footerPanel = new FooterPanel();
35  	private final JTabbedPane contentPanel = new JTabbedPane();
36  	//private final ServerConfigPanel serverConfigPanel;
37  	private final BambooGeneralForm bambooConfigPanel;
38  	private final CrucibleGeneralForm crucibleConfigPanel;
39  	private final JiraGeneralForm jiraConfigPanel;
40  	private final GeneralConfigPanel generalConfigPanel;
41  
42  	private final transient PluginConfiguration globalConfigurationBean;
43  //    private final ProjectId projectId;
44      private final CfgManager cfgManager;
45  
46  //	private ProjectConfiguration projectConfiguration;
47  
48  //	public ProjectConfiguration getProjectConfiguration() {
49  //		return projectConfiguration;
50  //	}
51  
52  	public ConfigPanel(PluginConfiguration globalConfigurationBean, /*ProjectId projectId, */CfgManager cfgManager) {
53  //        this.projectId = projectId;
54          this.cfgManager = cfgManager;
55  //		projectConfiguration = cfgManager.getProjectConfiguration(projectId).getClone();
56  //		final Collection<ServerCfg> allServers = projectConfiguration.getServers();
57  		//this.serverConfigPanel = new ServerConfigPanel(null, allServers);
58  		//this.bambooConfigPanel = new BambooGeneralForm(cfgManager.getGlobalBambooCfg());
59  		this.bambooConfigPanel = BambooGeneralForm.getInstance(globalConfigurationBean);
60  		this.crucibleConfigPanel = CrucibleGeneralForm.getInstance(globalConfigurationBean);
61  		this.jiraConfigPanel = JiraGeneralForm.getInstance(globalConfigurationBean);
62  		this.generalConfigPanel = GeneralConfigPanel.getInstance(globalConfigurationBean);
63  		this.globalConfigurationBean = globalConfigurationBean;
64  		initLayout();
65  	}
66  
67  
68  	private void initLayout() {
69  		setLayout(new BorderLayout());
70  
71  		contentPanel.setOpaque(true);
72  		contentPanel.setBackground(new Color(Constants.BG_COLOR_R, Constants.BG_COLOR_G, Constants.BG_COLOR_B));
73  
74  		// add servers tab
75  		//contentPanel.add(serverConfigPanel.getTitle(), serverConfigPanel);
76  
77  		// add Bamboo option tab
78  		contentPanel.add(bambooConfigPanel.getTitle(), bambooConfigPanel);
79  
80  		// add Crucible option tab
81  		contentPanel.add(crucibleConfigPanel.getTitle(), crucibleConfigPanel);
82  
83  		// add Jira option tab
84  		contentPanel.add(jiraConfigPanel.getTitle(), jiraConfigPanel);
85  
86  		// add general tab
87  		contentPanel.add(generalConfigPanel.getTitle(), generalConfigPanel);
88  
89  		add(contentPanel, BorderLayout.CENTER);
90  		add(footerPanel, BorderLayout.SOUTH);
91  	}
92  
93  
94  
95  	public boolean isModified() {
96  		return !this.localPluginConfigurationCopy.equals(globalConfigurationBean)
97  				/*|| projectConfiguration.equals(cfgManager.getProjectConfiguration(projectId)) == false*/
98  				/*|| serverConfigPanel.isModified()*/
99  				|| bambooConfigPanel.isModified()
100 				|| crucibleConfigPanel.isModified()
101 				|| jiraConfigPanel.isModified()
102 				|| generalConfigPanel.isModified();
103 	}
104 
105 	public void saveData() {
106 		/*serverConfigPanel.saveData();*/
107 		if (isModified()) {
108 			/*cfgManager.updateProjectConfiguration(projectId, projectConfiguration);*/
109 			generalConfigPanel.saveData();
110 			bambooConfigPanel.saveData();
111 			jiraConfigPanel.saveData();
112 			crucibleConfigPanel.saveData();
113 		}
114 	}
115 
116 	public void setData() {
117 		this.localPluginConfigurationCopy = new PluginConfigurationBean(globalConfigurationBean);
118 		/*projectConfiguration = cfgManager.getProjectConfiguration(projectId).getClone();*/
119 		/*serverConfigPanel.setData(projectConfiguration.getServers());*/
120 		generalConfigPanel.setData(localPluginConfigurationCopy);
121 		//bambooConfigPanel.setData(cfgManager.getGlobalBambooCfg());
122 		bambooConfigPanel.setData(localPluginConfigurationCopy);
123 		jiraConfigPanel.setData(localPluginConfigurationCopy);
124 		crucibleConfigPanel.setData(localPluginConfigurationCopy);
125 	}
126 }