This is an automated email from the ASF dual-hosted git repository.

junichi11 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b58c7b  [NETBEANS-5244] Add the project settings for XML 
configuration of phpDocumentor
     new fabd5e4  Merge pull request #2678 from 
junichi11/netbeans-5244-phpdocumentor-config
4b58c7b is described below

commit 4b58c7bd0b2da2e0317c3a49913c7a2c9538b4de
Author: Junichi Yamamoto <junich...@apache.org>
AuthorDate: Fri Jan 15 14:59:58 2021 +0900

    [NETBEANS-5244] Add the project settings for XML configuration of 
phpDocumentor
    
    https://issues.apache.org/jira/browse/NETBEANS-5244
    
    - Add settings for an XML configuration file
    - Add parameters (`--config /path/to/configuration/file.xml`)
---
 php/php.phpdoc/manifest.mf                         |   2 +-
 php/php.phpdoc/nbproject/project.xml               |  28 ++++-
 .../netbeans/modules/php/phpdoc/PhpDocScript.java  |  78 +++++++++++-
 .../modules/php/phpdoc/PhpDocumentorProvider.java  |   5 +-
 .../modules/php/phpdoc/ui/PhpDocPreferences.java   |  31 +++++
 .../php/phpdoc/ui/PhpDocPreferencesValidator.java  |  90 +++++++++++++
 .../php/phpdoc/ui/customizer/Bundle.properties     |   6 +-
 .../php/phpdoc/ui/customizer/PhpDocPanel.form      |  58 ++++++++-
 .../php/phpdoc/ui/customizer/PhpDocPanel.java      | 139 +++++++++++++++++----
 9 files changed, 398 insertions(+), 39 deletions(-)

diff --git a/php/php.phpdoc/manifest.mf b/php/php.phpdoc/manifest.mf
index 35e96c4..9c9b181 100644
--- a/php/php.phpdoc/manifest.mf
+++ b/php/php.phpdoc/manifest.mf
@@ -3,5 +3,5 @@ AutoUpdate-Show-In-Client: true
 OpenIDE-Module: org.netbeans.modules.php.phpdoc
 OpenIDE-Module-Layer: org/netbeans/modules/php/phpdoc/resources/layer.xml
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/php/phpdoc/resources/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.32
+OpenIDE-Module-Specification-Version: 1.33
 
diff --git a/php/php.phpdoc/nbproject/project.xml 
b/php/php.phpdoc/nbproject/project.xml
index 2dfe224..747b4d2 100644
--- a/php/php.phpdoc/nbproject/project.xml
+++ b/php/php.phpdoc/nbproject/project.xml
@@ -26,6 +26,15 @@
             <code-name-base>org.netbeans.modules.php.phpdoc</code-name-base>
             <module-dependencies>
                 <dependency>
+                    
<code-name-base>org.netbeans.api.annotations.common</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.38</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     
<code-name-base>org.netbeans.modules.extexecution</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -76,6 +85,15 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
+                    
<code-name-base>org.netbeans.modules.project.ant</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>1</release-version>
+                        <specification-version>1.78</specification-version>
+                    </run-dependency>
+                </dependency>
+                <dependency>
                     
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
@@ -134,7 +152,7 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.openide.util.ui</code-name-base>
+                    <code-name-base>org.openide.util</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
@@ -142,19 +160,19 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.openide.util</code-name-base>
+                    <code-name-base>org.openide.util.lookup</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>9.3</specification-version>
+                        <specification-version>8.4</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.openide.util.lookup</code-name-base>
+                    <code-name-base>org.openide.util.ui</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>8.4</specification-version>
+                        <specification-version>9.3</specification-version>
                     </run-dependency>
                 </dependency>
             </module-dependencies>
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocScript.java 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocScript.java
index bd363fd..cbad3d0 100644
--- a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocScript.java
+++ b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocScript.java
@@ -23,6 +23,7 @@ import java.awt.EventQueue;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
@@ -33,16 +34,21 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.api.extexecution.ExecutionDescriptor;
 import org.netbeans.api.extexecution.print.ConvertedLine;
 import org.netbeans.api.extexecution.print.LineConvertor;
+import org.netbeans.modules.php.api.documentation.PhpDocumentations;
 import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
 import org.netbeans.modules.php.api.executable.PhpExecutable;
 import org.netbeans.modules.php.api.executable.PhpExecutableValidator;
 import org.netbeans.modules.php.api.phpmodule.PhpModule;
 import org.netbeans.modules.php.api.util.FileUtils;
+import org.netbeans.modules.php.api.util.StringUtils;
 import org.netbeans.modules.php.api.util.UiUtils;
+import org.netbeans.modules.php.api.validation.ValidationResult;
 import org.netbeans.modules.php.phpdoc.ui.PhpDocPreferences;
+import org.netbeans.modules.php.phpdoc.ui.PhpDocPreferencesValidator;
 import org.netbeans.modules.php.phpdoc.ui.options.PhpDocOptions;
 import org.openide.awt.HtmlBrowser;
 import org.openide.filesystems.FileUtil;
@@ -61,6 +67,8 @@ public final class PhpDocScript {
     public static final String OPTIONS_ID = "PhpDoc"; // NOI18N
     public static final String OPTIONS_SUB_PATH = 
UiUtils.FRAMEWORKS_AND_TOOLS_SUB_PATH + "/" + OPTIONS_ID; // NOI18N
 
+    private static final String PARAM_CONFIG = "--config"; // NOI18N
+
     private static final boolean IS_WINDOWS = Utilities.isWindows();
 
     private final String phpDocPath;
@@ -84,12 +92,57 @@ public final class PhpDocScript {
         return new PhpDocScript(phpDocPath);
     }
 
+    /**
+     * Get the valid PhpDocScript without invalid settings(project properties).
+     *
+     * @param phpModule the PhpModule
+     * @param showCustomizer {@code true} if show the customizer when there are
+     * invalid settings, otherwise {@code false}
+     * @return the valid PhpDocScript if there are not invalid settings,
+     * otherwise {@code null}
+     * @throws InvalidPhpExecutableException if PhpDoc script is not valid
+     */
+    @CheckForNull
+    public static PhpDocScript getForPhpModule(PhpModule phpModule, boolean 
showCustomizer) throws InvalidPhpExecutableException {
+        String message = validatePhpModule(phpModule);
+        if (message != null) { // has an error/warning message
+            if (showCustomizer) {
+                UiUtils.invalidScriptProvided(phpModule, 
PhpDocumentations.CUSTOMIZER_IDENT, message);
+            }
+            return null;
+        }
+        if (!PhpDocPreferences.isEnabled(phpModule)) {
+            return null;
+        }
+        return getDefault();
+    }
+
     public static String getOptionsPath() {
         return UiUtils.OPTIONS_PATH + "/" + OPTIONS_SUB_PATH; // NOI18N
     }
 
-    public static String validate(String composerPath) {
-        return PhpExecutableValidator.validateCommand(composerPath, 
NbBundle.getMessage(PhpDocScript.class, "LBL_PhpDocScript"));
+    @CheckForNull
+    public static String validate(String phpDocPath) {
+        return PhpExecutableValidator.validateCommand(phpDocPath, 
NbBundle.getMessage(PhpDocScript.class, "LBL_PhpDocScript"));
+    }
+
+    @CheckForNull
+    private static String validatePhpModule(PhpModule phpModule) {
+        ValidationResult result = new PhpDocPreferencesValidator()
+                .validatePhpModule(phpModule)
+                .getResult();
+        return validateResult(result);
+    }
+
+    @CheckForNull
+    private static String validateResult(ValidationResult result) {
+        if (result.isFaultless()) {
+            return null;
+        }
+        if (result.hasErrors()) {
+            return result.getFirstError().getMessage();
+        }
+        return result.getFirstWarning().getMessage();
     }
 
     @NbBundle.Messages({
@@ -108,7 +161,7 @@ public final class PhpDocScript {
         Future<Integer> result = new PhpExecutable(phpDocPath)
                 .optionsSubcategory(OPTIONS_SUB_PATH)
                 
.displayName(Bundle.PhpDocScript_run_title(phpModule.getDisplayName()))
-                .additionalParameters(getParameters(sanitizedPhpDocTarget, 
phpModule))
+                .additionalParameters(getAllParameters(sanitizedPhpDocTarget, 
phpModule))
                 .run(getExecutionDescriptor(sanitizedPhpDocTarget));
 
         try {
@@ -145,13 +198,24 @@ public final class PhpDocScript {
         return path;
     }
 
-    private List<String> getParameters(String sanitizedPhpDocTarget, PhpModule 
phpModule) {
+    private List<String> getAllParameters(String sanitizedPhpDocTarget, 
PhpModule phpModule) {
+        List<String> params = new 
ArrayList<>(getDefaultParameters(sanitizedPhpDocTarget, phpModule));
+        if (PhpDocPreferences.isConfigurationEnabled(phpModule)) {
+            String configurationPath = 
PhpDocPreferences.getPhpDocConfigurationPath(phpModule);
+            if (!StringUtils.isEmpty(configurationPath)) {
+                params.add(PARAM_CONFIG);
+                
params.add(sanitizePath(PhpDocPreferences.getPhpDocConfigurationPath(phpModule)));
+            }
+        }
+        return params;
+    }
+
+    private List<String> getDefaultParameters(String sanitizedPhpDocTarget, 
PhpModule phpModule) {
         return Arrays.asList(
                 // command
                 "run", // NOI18N
                 // params
                 "--ansi", // NOI18N
-                // "--progressbar" doesn't exist since PHPDocumentor 3
                 // from
                 "--directory", // NOI18N
                 
sanitizePath(FileUtil.toFile(phpModule.getSourceDirectory()).getAbsolutePath()),
@@ -160,9 +224,11 @@ public final class PhpDocScript {
                 sanitizedPhpDocTarget,
                 // title
                 "--title", // NOI18N
-                PhpDocPreferences.getPhpDocTitle(phpModule));
+                PhpDocPreferences.getPhpDocTitle(phpModule)
+        );
     }
 
+    //~ Inner classes
     private class ErrorFileLineConvertorFactory implements 
ExecutionDescriptor.LineConvertorFactory {
 
         private final String docTarget;
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocumentorProvider.java 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocumentorProvider.java
index 2043cec..d873557 100644
--- 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocumentorProvider.java
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/PhpDocumentorProvider.java
@@ -55,7 +55,10 @@ public final class PhpDocumentorProvider extends 
PhpDocumentationProvider {
     @Override
     public void generateDocumentation(PhpModule phpModule) {
         try {
-            PhpDocScript.getDefault().generateDocumentation(phpModule);
+            PhpDocScript phpDocScript = 
PhpDocScript.getForPhpModule(phpModule, true);
+            if (phpDocScript != null) {
+                phpDocScript.generateDocumentation(phpModule);
+            }
         } catch (InvalidPhpExecutableException ex) {
             UiUtils.invalidScriptProvided(ex.getLocalizedMessage(), 
PhpDocScript.OPTIONS_SUB_PATH);
         }
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferences.java 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferences.java
index 9e3552f..ce902b5 100644
--- 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferences.java
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferences.java
@@ -20,13 +20,19 @@
 package org.netbeans.modules.php.phpdoc.ui;
 
 import java.util.prefs.Preferences;
+import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.modules.php.api.phpmodule.PhpModule;
+import org.netbeans.modules.php.api.util.StringUtils;
+import org.netbeans.spi.project.support.ant.PropertyUtils;
+import org.openide.filesystems.FileUtil;
 
 public final class PhpDocPreferences {
 
     private static final String PHPDOC_ENABLED = "enabled"; // NOI18N
     private static final String PHPDOC_TARGET = "target"; // NOI18N
     private static final String PHPDOC_TITLE = "title"; // NOI18N
+    private static final String PHPDOC_CONFIGURATION_ENABLED = 
"configuration.enabled"; // NOI18N
+    private static final String PHPDOC_CONFIGURATION_PATH = 
"configuration.path"; // NOI18N
 
 
     private PhpDocPreferences() {
@@ -69,6 +75,23 @@ public final class PhpDocPreferences {
         getPreferences(phpModule).put(PHPDOC_TITLE, phpDocTitle);
     }
 
+    public static boolean isConfigurationEnabled(PhpModule phpModule) {
+        return 
getPreferences(phpModule).getBoolean(PHPDOC_CONFIGURATION_ENABLED, false);
+    }
+
+    public static void setConfigurationEnabled(PhpModule phpModule, boolean 
configurationEnabled) {
+        getPreferences(phpModule).putBoolean(PHPDOC_CONFIGURATION_ENABLED, 
configurationEnabled);
+    }
+
+    @CheckForNull
+    public static String getPhpDocConfigurationPath(PhpModule phpModule) {
+        return resolvePath(phpModule, 
getPreferences(phpModule).get(PHPDOC_CONFIGURATION_PATH, null));
+    }
+
+    public static void setPhpDocConfigurationPath(PhpModule phpModule, String 
phpDocConfiguration) {
+        getPreferences(phpModule).put(PHPDOC_CONFIGURATION_PATH, 
phpDocConfiguration);
+    }
+
     private static Preferences getPreferences(PhpModule phpModule) {
         return phpModule.getPreferences(PhpDocPreferences.class, false);
     }
@@ -76,4 +99,12 @@ public final class PhpDocPreferences {
     private static String getDefaultPhpDocTitle(PhpModule phpModule) {
         return phpModule.getDisplayName();
     }
+
+    @CheckForNull
+    private static String resolvePath(PhpModule phpModule, String filePath) {
+        if (!StringUtils.hasText(filePath)) {
+            return null;
+        }
+        return 
PropertyUtils.resolveFile(FileUtil.toFile(phpModule.getProjectDirectory()), 
filePath).getAbsolutePath();
+    }
 }
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferencesValidator.java
 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferencesValidator.java
new file mode 100644
index 0000000..2e9aa2b
--- /dev/null
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/PhpDocPreferencesValidator.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.php.phpdoc.ui;
+
+import org.netbeans.modules.php.api.phpmodule.PhpModule;
+import org.netbeans.modules.php.api.util.FileUtils;
+import org.netbeans.modules.php.api.util.StringUtils;
+import org.netbeans.modules.php.api.validation.ValidationResult;
+import org.openide.util.NbBundle;
+
+public class PhpDocPreferencesValidator {
+
+    private final ValidationResult result = new ValidationResult();
+
+    public ValidationResult getResult() {
+        return result;
+    }
+
+    public PhpDocPreferencesValidator validatePhpModule(PhpModule phpModule) {
+        validateTarget(PhpDocPreferences.getPhpDocTarget(phpModule, false));
+        validateTitle(PhpDocPreferences.getPhpDocTitle(phpModule));
+        
validateConfiguration(PhpDocPreferences.isConfigurationEnabled(phpModule), 
PhpDocPreferences.getPhpDocConfigurationPath(phpModule));
+        return this;
+    }
+
+    @NbBundle.Messages({
+        "PhpDocPreferencesValidator.target.label=Target",
+        "PhpDocPreferencesValidator.message.ask.for.dir=NetBeans will ask for 
the directory before generating documentation.",
+    })
+    public PhpDocPreferencesValidator validateTarget(String targetPath) {
+        validateDirectory(true, targetPath, 
Bundle.PhpDocPreferencesValidator_target_label(), "targetPath"); // NOI18N
+        if (!StringUtils.hasText(targetPath)) {
+            result.addWarning(new ValidationResult.Message("targetPath", 
Bundle.PhpDocPreferencesValidator_message_ask_for_dir())); // NOI18N
+        }
+
+        return this;
+    }
+
+    @NbBundle.Messages("PhpDocPreferencesValidator.message.invalid.title=Title 
must be provided.")
+    public PhpDocPreferencesValidator validateTitle(String title) {
+        if (!StringUtils.hasText(title)) {
+            result.addError(new ValidationResult.Message("title", 
Bundle.PhpDocPreferencesValidator_message_invalid_title())); // NOI18N
+        }
+        return this;
+    }
+
+    @NbBundle.Messages("PhpDocPreferencesValidator.configuration.label=XML 
configuration")
+    public PhpDocPreferencesValidator validateConfiguration(boolean 
configurationEnabled, String configurationPath) {
+        validatePath(configurationEnabled, configurationPath, 
Bundle.PhpDocPreferencesValidator_configuration_label(), "configurationPath"); 
// NOI18N
+        return this;
+    }
+
+    private void validateDirectory(boolean pathEnabled, String path, String 
label, String source) {
+        if (!pathEnabled) {
+            return;
+        }
+        if (StringUtils.hasText(path)) {
+            String error = FileUtils.validateDirectory(label, path, true);
+            if (error != null) {
+                result.addError(new ValidationResult.Message(source, error));
+            }
+        }
+    }
+
+    private void validatePath(boolean pathEnabled, String path, String label, 
String source) {
+        if (!pathEnabled) {
+            return;
+        }
+        String warning = FileUtils.validateFile(label, path, false);
+        if (warning != null) {
+            result.addWarning(new ValidationResult.Message(source, warning));
+        }
+    }
+}
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties
 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties
index 2e802a5..cc3991e 100644
--- 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties
@@ -16,8 +16,10 @@
 # under the License.
 
 LBL_SelectDocFolder=Select a directory for documentation
-MSG_InvalidTitle=Title must be provided.
-MSG_NbWillAskForDir=NetBeans will ask for the directory before generating 
documentation.
 PhpDocPanel.titleLabel.text=Titl&e:
 PhpDocPanel.targetLabel.text=&Target Directory:
 PhpDocPanel.targetButton.text=&Browse...
+PhpDocPanel.configurationCheckBox.text=U&se XML Configuration
+PhpDocPanel.configurationLabel.text=&XML Configuration:
+PhpDocPanel.configurationTextField.text=
+PhpDocPanel.configurationBrowseButton.text=B&rowse...
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.form
 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.form
index 3fcd1a9..6b4d5bb 100644
--- 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.form
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.form
@@ -37,7 +37,7 @@
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="102" alignment="0" attributes="0">
+          <Group type="102" attributes="0">
               <Group type="103" groupAlignment="0" attributes="0">
                   <Component id="targetLabel" alignment="0" min="-2" max="-2" 
attributes="0"/>
                   <Component id="titleLabel" alignment="0" min="-2" max="-2" 
attributes="0"/>
@@ -49,9 +49,21 @@
                       <EmptySpace max="-2" attributes="0"/>
                       <Component id="targetButton" min="-2" max="-2" 
attributes="0"/>
                   </Group>
-                  <Component id="titleTextField" pref="112" max="32767" 
attributes="0"/>
+                  <Component id="titleTextField" max="32767" attributes="0"/>
               </Group>
           </Group>
+          <Group type="102" attributes="0">
+              <Component id="configurationCheckBox" min="-2" max="-2" 
attributes="0"/>
+              <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
+          </Group>
+          <Group type="102" alignment="0" attributes="0">
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="configurationLabel" min="-2" max="-2" 
attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="configurationTextField" max="32767" 
attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="configurationBrowseButton" min="-2" max="-2" 
attributes="0"/>
+          </Group>
       </Group>
     </DimensionLayout>
     <DimensionLayout dim="1">
@@ -67,6 +79,14 @@
                   <Component id="titleLabel" alignment="3" min="-2" max="-2" 
attributes="0"/>
                   <Component id="titleTextField" alignment="3" min="-2" 
max="-2" attributes="0"/>
               </Group>
+              <EmptySpace type="unrelated" max="-2" attributes="0"/>
+              <Component id="configurationCheckBox" min="-2" max="-2" 
attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="configurationLabel" alignment="3" min="-2" 
max="-2" attributes="0"/>
+                  <Component id="configurationTextField" alignment="3" 
min="-2" max="-2" attributes="0"/>
+                  <Component id="configurationBrowseButton" alignment="3" 
min="-2" max="-2" attributes="0"/>
+              </Group>
               <EmptySpace max="32767" attributes="0"/>
           </Group>
       </Group>
@@ -107,5 +127,39 @@
     </Component>
     <Component class="javax.swing.JTextField" name="titleTextField">
     </Component>
+    <Component class="javax.swing.JCheckBox" name="configurationCheckBox">
+      <Properties>
+        <Property name="text" type="java.lang.String" 
editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString 
bundle="org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties" 
key="PhpDocPanel.configurationCheckBox.text" 
replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, 
&quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="configurationLabel">
+      <Properties>
+        <Property name="labelFor" type="java.awt.Component" 
editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="configurationTextField"/>
+        </Property>
+        <Property name="text" type="java.lang.String" 
editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString 
bundle="org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties" 
key="PhpDocPanel.configurationLabel.text" 
replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, 
&quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JTextField" name="configurationTextField">
+      <Properties>
+        <Property name="text" type="java.lang.String" 
editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString 
bundle="org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties" 
key="PhpDocPanel.configurationTextField.text" 
replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, 
&quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JButton" name="configurationBrowseButton">
+      <Properties>
+        <Property name="text" type="java.lang.String" 
editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString 
bundle="org/netbeans/modules/php/phpdoc/ui/customizer/Bundle.properties" 
key="PhpDocPanel.configurationBrowseButton.text" 
replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, 
&quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" 
listener="java.awt.event.ActionListener" 
parameters="java.awt.event.ActionEvent" 
handler="configurationBrowseButtonActionPerformed"/>
+      </Events>
+    </Component>
   </SubComponents>
 </Form>
diff --git 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.java
 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.java
index 03905bb..f6abe6c 100644
--- 
a/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.java
+++ 
b/php/php.phpdoc/src/org/netbeans/modules/php/phpdoc/ui/customizer/PhpDocPanel.java
@@ -22,10 +22,13 @@ package org.netbeans.modules.php.phpdoc.ui.customizer;
 import java.awt.EventQueue;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
 import java.io.File;
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
 import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
@@ -34,10 +37,10 @@ import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import org.netbeans.modules.php.api.phpmodule.PhpModule;
-import org.netbeans.modules.php.api.util.FileUtils;
-import org.netbeans.modules.php.api.util.StringUtils;
+import org.netbeans.modules.php.api.validation.ValidationResult;
 import org.netbeans.modules.php.phpdoc.PhpDocumentorProvider;
 import org.netbeans.modules.php.phpdoc.ui.PhpDocPreferences;
+import org.netbeans.modules.php.phpdoc.ui.PhpDocPreferencesValidator;
 import org.openide.awt.Mnemonics;
 import org.openide.filesystems.FileChooserBuilder;
 import org.openide.filesystems.FileUtil;
@@ -66,10 +69,29 @@ final class PhpDocPanel extends JPanel {
     private void init() {
         targetTextField.setText(PhpDocPreferences.getPhpDocTarget(phpModule, 
false));
         titleTextField.setText(PhpDocPreferences.getPhpDocTitle(phpModule));
+        
configurationTextField.setText(PhpDocPreferences.getPhpDocConfigurationPath(phpModule));
+        
configurationCheckBox.setSelected(PhpDocPreferences.isConfigurationEnabled(phpModule));
+        enableComponents(configurationCheckBox.isSelected(), 
getConfigurationFileComponents());
+        addListeners();
+    }
 
+    private void addListeners() {
         DocumentListener defaultDocumentListener = new 
DefaultDocumentListener();
         
targetTextField.getDocument().addDocumentListener(defaultDocumentListener);
         
titleTextField.getDocument().addDocumentListener(defaultDocumentListener);
+        
configurationTextField.getDocument().addDocumentListener(defaultDocumentListener);
+        configurationCheckBox.addItemListener((ItemEvent e) -> {
+            enableComponents(e.getStateChange() == ItemEvent.SELECTED, 
getConfigurationFileComponents());
+            fireChange();
+        });
+    }
+
+    private JComponent[] getConfigurationFileComponents() {
+        return new JComponent[] {
+            configurationLabel,
+            configurationTextField,
+            configurationBrowseButton
+        };
     }
 
     public void addChangeListener(ChangeListener listener) {
@@ -88,27 +110,33 @@ final class PhpDocPanel extends JPanel {
         return titleTextField.getText().trim();
     }
 
+    private String getPhpDocConfigurationPath() {
+        return configurationTextField.getText().trim();
+    }
+
+    private boolean isPhpDocConfigurationEnabled() {
+        return configurationCheckBox.isSelected();
+    }
+
     boolean isValidData() {
-        return getErrorMessage() == null;
+        ValidationResult result = getValidationResult();
+        return !result.hasErrors();
     }
 
     public String getErrorMessage() {
-        String phpDocTarget = getPhpDocTarget();
-        if (StringUtils.hasText(phpDocTarget)) {
-            String error = FileUtils.validateDirectory(phpDocTarget, true);
-            if (error != null) {
-                return error;
-            }
-        }
-        if (!StringUtils.hasText(getPhpDocTitle())) {
-            return NbBundle.getMessage(PhpDocPanel.class, "MSG_InvalidTitle");
+        ValidationResult result = getValidationResult();
+        ValidationResult.Message error = result.getFirstError();
+        if (error != null) {
+            return error.getMessage();
         }
         return null;
     }
 
     public String getWarningMessage() {
-        if (!StringUtils.hasText(getPhpDocTarget())) {
-            return NbBundle.getMessage(PhpDocPanel.class, 
"MSG_NbWillAskForDir");
+        ValidationResult result = getValidationResult();
+        ValidationResult.Message warning = result.getFirstWarning();
+        if (warning != null) {
+            return warning.getMessage();
         }
         return null;
     }
@@ -116,6 +144,22 @@ final class PhpDocPanel extends JPanel {
     public void storeData() {
         PhpDocPreferences.setPhpDocTarget(phpModule, getPhpDocTarget());
         PhpDocPreferences.setPhpDocTitle(phpModule, getPhpDocTitle());
+        PhpDocPreferences.setPhpDocConfigurationPath(phpModule, 
getPhpDocConfigurationPath());
+        PhpDocPreferences.setConfigurationEnabled(phpModule, 
isPhpDocConfigurationEnabled());
+    }
+
+    private ValidationResult getValidationResult() {
+        return new PhpDocPreferencesValidator()
+                .validateTarget(getPhpDocTarget())
+                .validateTitle(getPhpDocTitle())
+                .validateConfiguration(isPhpDocConfigurationEnabled(), 
getPhpDocConfigurationPath())
+                .getResult();
+    }
+
+    void enableComponents(boolean enabled, JComponent... components) {
+        for (JComponent component : components) {
+            component.setEnabled(enabled);
+        }
     }
 
     void fireChange() {
@@ -136,10 +180,15 @@ final class PhpDocPanel extends JPanel {
         targetButton = new JButton();
         titleLabel = new JLabel();
         titleTextField = new JTextField();
+        configurationCheckBox = new JCheckBox();
+        configurationLabel = new JLabel();
+        configurationTextField = new JTextField();
+        configurationBrowseButton = new JButton();
 
         targetLabel.setLabelFor(targetTextField);
-        Mnemonics.setLocalizedText(targetLabel, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.targetLabel.text"));
-        Mnemonics.setLocalizedText(targetButton, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.targetButton.text"));
+        Mnemonics.setLocalizedText(targetLabel, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.targetLabel.text")); // 
NOI18N
+
+        Mnemonics.setLocalizedText(targetButton, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.targetButton.text")); // 
NOI18N
         targetButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                 targetButtonActionPerformed(evt);
@@ -147,12 +196,25 @@ final class PhpDocPanel extends JPanel {
         });
 
         titleLabel.setLabelFor(titleTextField);
-        Mnemonics.setLocalizedText(titleLabel, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.titleLabel.text"));
+        Mnemonics.setLocalizedText(titleLabel, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.titleLabel.text")); // 
NOI18N
+
+        Mnemonics.setLocalizedText(configurationCheckBox, 
NbBundle.getMessage(PhpDocPanel.class, 
"PhpDocPanel.configurationCheckBox.text")); // NOI18N
+
+        configurationLabel.setLabelFor(configurationTextField);
+        Mnemonics.setLocalizedText(configurationLabel, 
NbBundle.getMessage(PhpDocPanel.class, "PhpDocPanel.configurationLabel.text")); 
// NOI18N
+
+        configurationTextField.setText(NbBundle.getMessage(PhpDocPanel.class, 
"PhpDocPanel.configurationTextField.text")); // NOI18N
+
+        Mnemonics.setLocalizedText(configurationBrowseButton, 
NbBundle.getMessage(PhpDocPanel.class, 
"PhpDocPanel.configurationBrowseButton.text")); // NOI18N
+        configurationBrowseButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent evt) {
+                configurationBrowseButtonActionPerformed(evt);
+            }
+        });
 
         GroupLayout layout = new GroupLayout(this);
         this.setLayout(layout);
-        layout.setHorizontalGroup(
-            layout.createParallelGroup(Alignment.LEADING)
+        layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addGroup(layout.createParallelGroup(Alignment.LEADING)
                     .addComponent(targetLabel)
@@ -163,10 +225,19 @@ final class PhpDocPanel extends JPanel {
                         .addComponent(targetTextField)
                         .addPreferredGap(ComponentPlacement.RELATED)
                         .addComponent(targetButton))
-                    .addComponent(titleTextField, GroupLayout.DEFAULT_SIZE, 
112, Short.MAX_VALUE)))
+                    .addComponent(titleTextField)))
+            .addGroup(layout.createSequentialGroup()
+                .addComponent(configurationCheckBox)
+                .addGap(0, 0, Short.MAX_VALUE))
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(configurationLabel)
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addComponent(configurationTextField)
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addComponent(configurationBrowseButton))
         );
-        layout.setVerticalGroup(
-            layout.createParallelGroup(Alignment.LEADING)
+        layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                     .addComponent(targetLabel)
@@ -176,6 +247,13 @@ final class PhpDocPanel extends JPanel {
                 .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                     .addComponent(titleLabel)
                     .addComponent(titleTextField, GroupLayout.PREFERRED_SIZE, 
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(ComponentPlacement.UNRELATED)
+                .addComponent(configurationCheckBox)
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
+                    .addComponent(configurationLabel)
+                    .addComponent(configurationTextField, 
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, 
GroupLayout.PREFERRED_SIZE)
+                    .addComponent(configurationBrowseButton))
                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
     }// </editor-fold>//GEN-END:initComponents
@@ -193,8 +271,25 @@ final class PhpDocPanel extends JPanel {
         }
     }//GEN-LAST:event_targetButtonActionPerformed
 
+    @NbBundle.Messages("PhpDocPanel.chooser.configuration=Select phpDocumentor 
XML configuration file")
+    private void configurationBrowseButtonActionPerformed(ActionEvent evt) 
{//GEN-FIRST:event_configurationBrowseButtonActionPerformed
+        File configurationFile = new 
FileChooserBuilder(PhpDocumentorProvider.class.getName() + 
PhpDocumentorProvider.PHPDOC_LAST_FOLDER_SUFFIX + phpModule.getName())
+                .setTitle(Bundle.PhpDocPanel_chooser_configuration())
+                .setFilesOnly(true)
+                
.setDefaultWorkingDirectory(FileUtil.toFile(phpModule.getSourceDirectory()))
+                .showOpenDialog();
+        if (configurationFile != null) {
+            configurationFile = FileUtil.normalizeFile(configurationFile);
+            
configurationTextField.setText(configurationFile.getAbsolutePath());
+        }
+    }//GEN-LAST:event_configurationBrowseButtonActionPerformed
+
 
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private JButton configurationBrowseButton;
+    private JCheckBox configurationCheckBox;
+    private JLabel configurationLabel;
+    private JTextField configurationTextField;
     private JButton targetButton;
     private JLabel targetLabel;
     private JTextField targetTextField;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to