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;
18  
19  import com.intellij.ide.DataManager;
20  import com.intellij.openapi.options.Configurable;
21  import com.intellij.openapi.options.ShowSettingsUtil;
22  import com.intellij.openapi.project.Project;
23  import com.intellij.openapi.util.IconLoader;
24  import com.intellij.ui.HyperlinkLabel;
25  
26  import javax.swing.*;
27  import javax.swing.event.HyperlinkEvent;
28  import javax.swing.event.HyperlinkListener;
29  import java.awt.*;
30  
31  public class ToolWindowConfigPanel extends JPanel {
32  	private static final int ROW_COUNT = 3;
33  
34  	public ToolWindowConfigPanel(final Project project) {
35  		super(new GridBagLayout());
36  
37  		JPanel panel = new JPanel(new GridLayout(ROW_COUNT, 1));
38  		GridBagConstraints c = new GridBagConstraints();
39  		c.anchor = GridBagConstraints.CENTER;
40  		this.add(panel, c);
41  
42  		HyperlinkLabel projectSettingsLink = new HyperlinkLabel("Configure Plugin Project Settings");
43  		projectSettingsLink.addHyperlinkListener(new HyperlinkListener() {
44  			public void hyperlinkUpdate(HyperlinkEvent e) {
45  
46  				Configurable component = project.getComponent(ProjectConfigurationComponent.class);
47  				ShowSettingsUtil.getInstance().editConfigurable(
48                          IdeaHelper.getCurrentProject(DataManager.getInstance().getDataContext(ToolWindowConfigPanel.this)),
49  						component
50  						);
51  			}
52  		});
53  
54  		projectSettingsLink.setIcon(IconLoader.getIcon("/general/ideOptions.png"));
55  
56  		panel.add(projectSettingsLink);
57  
58  		HyperlinkLabel globalSettingsLink = new HyperlinkLabel("Configure Plugin Global Settings");
59  		globalSettingsLink.addHyperlinkListener(new HyperlinkListener() {
60  			public void hyperlinkUpdate(final HyperlinkEvent e) {
61  
62  				Configurable component = project.getComponent(ThePluginApplicationComponent.class);
63  				ShowSettingsUtil.getInstance().editConfigurable(
64  						IdeaHelper.getCurrentProject(DataManager.getInstance().getDataContext(ToolWindowConfigPanel.this)),
65  						IdeaHelper.getAppComponent());
66  			}
67  		});
68  
69  		globalSettingsLink.setIcon(IconLoader.getIcon("/general/ideOptions.png"));
70  
71  		panel.add(new JLabel(" "));
72  		panel.add(globalSettingsLink);
73  
74  
75  	}
76  }