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.serverconfig;
18  
19  import com.atlassian.theplugin.commons.ServerType;
20  import com.atlassian.theplugin.commons.configuration.*;
21  import com.atlassian.theplugin.idea.config.ContentPanel;
22  import com.intellij.uiDesigner.core.GridConstraints;
23  import com.intellij.uiDesigner.core.GridLayoutManager;
24  import com.intellij.uiDesigner.core.Spacer;
25  
26  import javax.swing.*;
27  import java.awt.*;
28  
29  /**
30   * Created by IntelliJ IDEA.
31   * User: Jacek
32   * Date: 2008-03-07
33   * Time: 11:30:05
34   * To change this template use File | Settings | File Templates.
35   */
36  public class CrucibleGeneralForm extends JComponent implements ContentPanel {
37  	private JPanel rootComponent;
38  	private JSpinner pollTimeSpinner;
39  	private JRadioButton unreadCrucibleReviews;
40  	private JRadioButton never;
41  	private SpinnerModel model;
42  
43  	private transient PluginConfigurationBean globalPluginConfiguration;
44  
45  	private transient CrucibleConfigurationBean crucibleConfiguration;
46  
47  	private transient PluginConfiguration localPluginConfigurationCopy;
48  	private static CrucibleGeneralForm instance;
49  
50  	private CrucibleGeneralForm(PluginConfigurationBean globalPluginConfiguration) {
51  
52  		this.globalPluginConfiguration = globalPluginConfiguration;
53  
54  		$$$setupUI$$$();
55  
56  		model = new SpinnerNumberModel(1, 1, 1000, 1);
57  		pollTimeSpinner.setModel(model);
58  
59  		this.setLayout(new BorderLayout());
60  		add(rootComponent, BorderLayout.WEST);
61  	}
62  
63  	public static CrucibleGeneralForm getInstance(PluginConfigurationBean globalPluginConfiguration) {
64  		if (instance == null) {
65  			instance = new CrucibleGeneralForm(globalPluginConfiguration);
66  		}
67  		return instance;
68  	}
69  
70  
71  	public boolean isEnabled() {
72  		return true;  //To change body of implemented methods use File | Settings | File Templates.
73  	}
74  
75  	public boolean isModified() {
76  		if (crucibleConfiguration.getCrucibleTooltipOption() != null) {
77  			if (crucibleConfiguration.getCrucibleTooltipOption() != getCrucibleTooltipOption()) {
78  				return true;
79  			}
80  		} else if (getCrucibleTooltipOption() != CrucibleTooltipOption.UNREAD_REVIEWS) {
81  			return true;
82  		}
83  		return (Integer) model.getValue() != crucibleConfiguration.getPollTime();
84  	}
85  
86  	public String getTitle() {
87  		return "Crucible";
88  	}
89  
90  	private CrucibleTooltipOption getCrucibleTooltipOption() {
91  		if (unreadCrucibleReviews.isSelected()) {
92  			return CrucibleTooltipOption.UNREAD_REVIEWS;
93  		} else if (never.isSelected()) {
94  			return CrucibleTooltipOption.NEVER;
95  		} else {
96  			return getDefaultTooltipOption();
97  		}
98  	}
99  
100 	public void getData() {
101 		((CrucibleConfigurationBean) getLocalPluginConfigurationCopy()
102 				.getProductServers(ServerType.CRUCIBLE_SERVER))
103 				.setCrucibleTooltipOption(getCrucibleTooltipOption());
104 
105 		((CrucibleConfigurationBean) globalPluginConfiguration
106 				.getProductServers(ServerType.CRUCIBLE_SERVER))
107 				.setCrucibleTooltipOption(getCrucibleTooltipOption());
108 
109 		((CrucibleConfigurationBean) getLocalPluginConfigurationCopy()
110 				.getProductServers(ServerType.CRUCIBLE_SERVER))
111 				.setPollTime((Integer) model.getValue());
112 
113 		((CrucibleConfigurationBean) globalPluginConfiguration
114 				.getProductServers(ServerType.CRUCIBLE_SERVER))
115 				.setPollTime((Integer) model.getValue());
116 	}
117 
118 	public void setData(PluginConfiguration config) {
119 
120 		localPluginConfigurationCopy = config;
121 
122 		crucibleConfiguration =
123 				(CrucibleConfigurationBean) localPluginConfigurationCopy.getProductServers(ServerType.CRUCIBLE_SERVER);
124 		CrucibleTooltipOption configOption = this.crucibleConfiguration.getCrucibleTooltipOption();
125 
126 		if (configOption != null) {
127 			switch (configOption) {
128 				case UNREAD_REVIEWS:
129 					unreadCrucibleReviews.setSelected(true);
130 					break;
131 				case NEVER:
132 					never.setSelected(true);
133 					break;
134 				default:
135 					never.setSelected(true);
136 					break;
137 			}
138 		} else {
139 			setDefaultTooltipOption();
140 		}
141 
142 		model.setValue(crucibleConfiguration.getPollTime());
143 	}
144 
145 	private void setDefaultTooltipOption() {
146 		unreadCrucibleReviews.setSelected(true);
147 	}
148 
149 	private CrucibleTooltipOption getDefaultTooltipOption() {
150 		return CrucibleTooltipOption.UNREAD_REVIEWS;
151 	}
152 
153 	public PluginConfiguration getLocalPluginConfigurationCopy() {
154 		return localPluginConfigurationCopy;
155 	}
156 
157 	private void createUIComponents() {
158 		// TODO: place custom component creation code here
159 	}
160 
161 	/**
162 	 * Method generated by IntelliJ IDEA GUI Designer
163 	 * >>> IMPORTANT!! <<<
164 	 * DO NOT edit this method OR call it in your code!
165 	 *
166 	 * @noinspection ALL
167 	 */
168 	private void $$$setupUI$$$() {
169 		rootComponent = new JPanel();
170 		rootComponent.setLayout(new GridLayoutManager(4, 3, new Insets(0, 0, 0, 0), -1, -1));
171 		rootComponent.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12), null));
172 		final JLabel label1 = new JLabel();
173 		label1.setText("Polling Time [minutes]:");
174 		rootComponent.add(label1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
175 		final JPanel panel1 = new JPanel();
176 		panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
177 		rootComponent.add(panel1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
178 		pollTimeSpinner = new JSpinner();
179 		panel1.add(pollTimeSpinner, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(50, -1), null, 0, false));
180 		final Spacer spacer1 = new Spacer();
181 		rootComponent.add(spacer1, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
182 		final Spacer spacer2 = new Spacer();
183 		rootComponent.add(spacer2, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(70, 14), null, 0, false));
184 		final JLabel label2 = new JLabel();
185 		label2.setText("Show Popup:");
186 		rootComponent.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
187 		unreadCrucibleReviews = new JRadioButton();
188 		unreadCrucibleReviews.setText("Unread crucible reviews exist");
189 		rootComponent.add(unreadCrucibleReviews, new GridConstraints(0, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
190 		never = new JRadioButton();
191 		never.setText("Never");
192 		rootComponent.add(never, new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
193 		ButtonGroup buttonGroup;
194 		buttonGroup = new ButtonGroup();
195 		buttonGroup.add(unreadCrucibleReviews);
196 		buttonGroup.add(never);
197 	}
198 
199 	/**
200 	 * @noinspection ALL
201 	 */
202 	public JComponent $$$getRootComponent$$$() {
203 		return rootComponent;
204 	}
205 }