2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.javadoc
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.openapi
.ui
.DialogWrapper
;
20 import com
.intellij
.openapi
.ui
.Messages
;
21 import com
.intellij
.openapi
.help
.HelpManager
;
22 import com
.intellij
.ui
.IdeBorderFactory
;
23 import com
.intellij
.CommonBundle
;
27 import java
.awt
.event
.ActionEvent
;
28 import java
.awt
.event
.ActionListener
;
31 final class GenerateJavadocDialog
extends DialogWrapper
{
32 private JRadioButton myForProjectRadio
;
33 private JRadioButton myForPackageRadio
;
34 private JCheckBox myIncludeSubpackagesCheckBox
;
35 private final String myPackageName
;
36 private final JavadocConfigurable myConfigurable
;
37 private final Project myProject
;
39 GenerateJavadocDialog(String packageName
, Project project
, JavadocConfiguration configuration
) {
43 myConfigurable
= configuration
.createConfigurable();
45 setOKButtonText(JavadocBundle
.message("javadoc.generate.start.button"));
46 myPackageName
= "".equals(packageName
) ? JavadocBundle
.message("javadoc.generate.package.default") : packageName
;
47 setTitle(JavadocBundle
.message("javadoc.generate.title"));
49 myConfigurable
.reset();
52 protected JComponent
createNorthPanel() {
53 JPanel panel
= new JPanel(new GridBagLayout());
54 panel
.setBorder(BorderFactory
.createEmptyBorder(4,8,8,0));
55 GridBagConstraints gbConstraints
= new GridBagConstraints();
56 gbConstraints
.gridy
= 0;
57 gbConstraints
.gridx
= 0;
58 gbConstraints
.gridwidth
= 3;
59 gbConstraints
.gridheight
= 1;
60 gbConstraints
.weightx
= 1;
62 gbConstraints
.fill
= GridBagConstraints
.BOTH
;
63 gbConstraints
.insets
= new Insets(0,0,0,0);
65 myForProjectRadio
= new JRadioButton(JavadocBundle
.message("javadoc.generate.scope.whole.project"));
66 panel
.add(myForProjectRadio
, gbConstraints
);
68 myForPackageRadio
= new JRadioButton(
69 JavadocBundle
.message("javadoc.generate.scope.package", (myPackageName
!= null ?
" \"" + myPackageName
+ "\"" : "")));
70 gbConstraints
.gridy
++;
71 gbConstraints
.insets
= new Insets(0,0,0,0);
72 panel
.add(myForPackageRadio
, gbConstraints
);
74 myIncludeSubpackagesCheckBox
= new JCheckBox(JavadocBundle
.message("javadoc.generate.scope.include.subpackages.checkbox"));
75 gbConstraints
.gridy
++;
76 gbConstraints
.insets
= new Insets(0,20,0,0);
77 panel
.add(myIncludeSubpackagesCheckBox
, gbConstraints
);
80 ButtonGroup buttonGroup
= new ButtonGroup();
81 buttonGroup
.add(myForProjectRadio
);
82 buttonGroup
.add(myForPackageRadio
);
84 ActionListener actionListener
= new ActionListener() {
85 public void actionPerformed(ActionEvent e
) {
86 myIncludeSubpackagesCheckBox
.setEnabled(myForPackageRadio
.isSelected());
90 myForProjectRadio
.addActionListener(actionListener
);
91 myForPackageRadio
.addActionListener(actionListener
);
96 protected JComponent
createCenterPanel() {
97 JPanel pane
= new JPanel(new BorderLayout());
98 pane
.setBorder(IdeBorderFactory
.createTitledBorder(JavadocBundle
.message("javadoc.generate.settings.group")));
99 pane
.add(myConfigurable
.createComponent(), BorderLayout
.CENTER
);
104 myForPackageRadio
.setEnabled(myPackageName
!= null);
105 myForPackageRadio
.setSelected(myPackageName
!= null);
106 myForProjectRadio
.setEnabled(true);
107 myForProjectRadio
.setSelected(myPackageName
== null);
108 myIncludeSubpackagesCheckBox
.setSelected(myPackageName
!= null);
109 myIncludeSubpackagesCheckBox
.setEnabled(myPackageName
!= null && myForPackageRadio
.isSelected());
112 boolean isGenerationForProject() {
113 return myForProjectRadio
.isSelected();
116 boolean isGenerationForPackage() {
117 return myForPackageRadio
.isSelected();
120 boolean isGenerationWithSubpackages() {
121 return isGenerationForPackage() && myIncludeSubpackagesCheckBox
.isSelected();
124 protected Action
[] createActions(){
125 return new Action
[]{getOKAction(), getCancelAction(), getHelpAction() };
128 protected void doOKAction() {
129 if (checkOutputDirectory(myConfigurable
.getOutputDir())) {
130 myConfigurable
.apply();
135 protected void doHelpAction() {
136 HelpManager
.getInstance().invokeHelp("editing.javadocGeneration");
139 private boolean checkOutputDirectory(String outputDirectory
) {
140 if (outputDirectory
== null || outputDirectory
.trim().length() == 0) {
141 Messages
.showMessageDialog(myProject
, JavadocBundle
.message("javadoc.generate.output.directory.not.specified"),
142 CommonBundle
.getErrorTitle(), Messages
.getErrorIcon());
146 File outputDir
= new File(outputDirectory
);
147 if (!outputDir
.exists()){
148 int choice
= Messages
.showOkCancelDialog(
150 JavadocBundle
.message("javadoc.generate.output.directory.not.exists", outputDirectory
),
151 JavadocBundle
.message("javadoc.generate.message.title"),
152 Messages
.getWarningIcon()
154 if (choice
!= 0) return false;
155 if (!outputDir
.mkdirs()){
156 Messages
.showMessageDialog(
158 JavadocBundle
.message("javadoc.generate.output.directory.creation.failed", outputDirectory
),
159 CommonBundle
.getErrorTitle(),
160 Messages
.getErrorIcon()
165 else if (!outputDir
.isDirectory()){
166 Messages
.showMessageDialog(
168 JavadocBundle
.message("javadoc.generate.output.not.a.directory", outputDirectory
),
169 CommonBundle
.getErrorTitle(),
170 Messages
.getErrorIcon()