This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 226773
Collapse All | Expand All

(-)project.ant/apichanges.xml (+17 lines)
Lines 108-113 Link Here
108
108
109
    <changes>
109
    <changes>
110
110
111
        <change id="license_header_customizer">
112
            <api name="general"/>
113
            <summary>Added <code>CustomizerUtilities.createLicenseHeaderCustomizerPanel</code></summary>
114
            <version major="1" minor="1.53"/>
115
            <date year="2013" month="3" day="14"/>
116
            <author login="mkleint"/>
117
            <compatibility addition="yes">
118
            </compatibility>
119
            <description>
120
                <p>
121
                   <code>CustomizerUtilities.createLicenseHeaderCustomizerPanel()</code> was introduced
122
                   to allow project modules to create license header selection and editing panel.
123
                </p>
124
            </description>
125
            <class package="org.netbeans.spi.project.support.ant.ui" name="CustomizerUtilities"/>
126
            <issue number="226773"/>
127
        </change>        
111
        <change id="createSharabilityQuery2">
128
        <change id="createSharabilityQuery2">
112
            <api name="general"/>
129
            <api name="general"/>
113
            <summary>Added <code>AntProjectHelper.createSharabilityQuery2</code></summary>
130
            <summary>Added <code>AntProjectHelper.createSharabilityQuery2</code></summary>
(-)project.ant/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
3
OpenIDE-Module-Specification-Version: 1.52
3
OpenIDE-Module-Specification-Version: 1.53
4
OpenIDE-Module-Layer: org/netbeans/modules/project/ant/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/project/ant/resources/mf-layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
6
OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class
6
OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class
(-)project.ant/nbproject/project.xml (+9 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.modules.project.ant</code-name-base>
50
            <code-name-base>org.netbeans.modules.project.ant</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.jdesktop.layout</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.25</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
53
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
62
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
54
                    <build-prerequisite/>
63
                    <build-prerequisite/>
55
                    <compile-dependency/>
64
                    <compile-dependency/>
(-)project.ant/src/org/netbeans/spi/project/support/ant/ui/Bundle.properties (+5 lines)
Line 0 Link Here
1
LicenseHeadersPanel.rbGlobal.text=Use global license
2
LicenseHeadersPanel.rbProject.text=Use project location
3
LicenseHeadersPanel.lblLicense.text=License header
4
LicenseHeadersPanel.btnProject.text=Browse...
5
LicenseHeadersPanel.btnGlobal.text=Edit global licenses
(-)project.ant/src/org/netbeans/spi/project/support/ant/ui/CustomizerUtilities.java (+121 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.spi.project.support.ant.ui;
44
45
import javax.swing.JComponent;
46
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
47
import org.openide.filesystems.FileObject;
48
49
/**
50
 * set of factory methods to create customizer panels
51
 * @author mkleint
52
 * @since 1.53
53
 */
54
public final class CustomizerUtilities {
55
56
    
57
    /**
58
     * for given category and data handler, create a component showing license header editing panel. To be used within <code>ProjectCustomizer.CompositeCategoryProvider</code>.
59
     * @param category
60
     * @param handler
61
     * @return 
62
     * @since 1.53
63
     */
64
    public static JComponent createLicenseHeaderCustomizerPanel(ProjectCustomizer.Category category, LicensePanelContentHandler handler) {
65
        return new LicenseHeadersPanel(category, handler);
66
    }
67
            
68
    
69
    /**
70
     * handle data inputs and outputs in the license headers customizer panel.
71
     * @since 1.53
72
     */
73
    public static interface LicensePanelContentHandler {
74
        /**
75
         * raw, unevaluated value points to the file in project space containing the header,
76
         * if present takes precedence over <code>getGlobalLicenseName()</code>
77
         * 
78
         * @return value or null if the value is unknown/doesn't exist
79
         */
80
        String getProjectLicenseLocation();
81
        
82
        /**
83
         * value of pointing to the global license header in the IDE.
84
         * @return 
85
         */
86
        String getGlobalLicenseName();
87
        
88
        /**
89
         * take the value from <code>getProjectLicenseLocation</code> and evaluate it to FileObject
90
         * 
91
         * @param path
92
         * @return FileObject instance if found, otherwise null
93
         */
94
        FileObject resolveProjectLocation(String path);
95
        
96
        /**
97
         * new value for project location, null value allowed and is meant to remove the value (to effectively use the global license)
98
         * @param newLocation 
99
         */
100
        void setProjectLicenseLocation(String newLocation);
101
        
102
        /**
103
         * set new value of global license template
104
         * @param newName 
105
         */
106
        void setGlobalLicenseName(String newName);
107
108
        /**
109
         * if no <code>getProjectLicenseLocation</code> is returned, this method will return the default project location.
110
         * @return 
111
         */
112
        public String getDefaultProjectLicenseLocation();
113
114
        /**
115
         * set the user edited content of the license header file in project space.
116
         * @param text 
117
         */
118
        void setProjectLicenseContent(String text);
119
120
    }            
121
}
(-)project.ant/src/org/netbeans/spi/project/support/ant/ui/LicenseHeadersPanel.form (+144 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <NonVisualComponents>
5
    <Component class="javax.swing.ButtonGroup" name="buttonGroup1">
6
    </Component>
7
  </NonVisualComponents>
8
  <AuxValues>
9
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
10
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
11
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
12
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
13
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
14
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
15
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
16
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
17
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
18
  </AuxValues>
19
20
  <Layout>
21
    <DimensionLayout dim="0">
22
      <Group type="103" groupAlignment="0" attributes="0">
23
          <Group type="102" attributes="0">
24
              <EmptySpace min="-2" max="-2" attributes="0"/>
25
              <Group type="103" groupAlignment="0" attributes="0">
26
                  <Component id="rbProject" alignment="0" min="-2" max="-2" attributes="0"/>
27
                  <Component id="rbGlobal" alignment="0" min="-2" max="-2" attributes="0"/>
28
              </Group>
29
              <EmptySpace min="-2" max="-2" attributes="0"/>
30
              <Group type="103" groupAlignment="0" attributes="0">
31
                  <Component id="comGlobal" alignment="0" max="32767" attributes="0"/>
32
                  <Component id="txtProject" alignment="0" max="32767" attributes="0"/>
33
              </Group>
34
              <EmptySpace min="-2" max="-2" attributes="0"/>
35
              <Group type="103" groupAlignment="0" attributes="0">
36
                  <Component id="btnGlobal" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
37
                  <Component id="btnProject" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
38
              </Group>
39
          </Group>
40
          <Group type="102" alignment="0" attributes="0">
41
              <EmptySpace min="-2" pref="35" max="-2" attributes="0"/>
42
              <Group type="103" groupAlignment="0" attributes="0">
43
                  <Group type="102" alignment="1" attributes="0">
44
                      <Component id="jScrollPane2" pref="0" max="32767" attributes="0"/>
45
                      <EmptySpace max="-2" attributes="0"/>
46
                  </Group>
47
                  <Group type="102" alignment="0" attributes="0">
48
                      <Component id="lblLicense" min="-2" max="-2" attributes="0"/>
49
                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
50
                  </Group>
51
              </Group>
52
          </Group>
53
      </Group>
54
    </DimensionLayout>
55
    <DimensionLayout dim="1">
56
      <Group type="103" groupAlignment="0" attributes="0">
57
          <Group type="102" alignment="0" attributes="0">
58
              <EmptySpace max="-2" attributes="0"/>
59
              <Group type="103" groupAlignment="3" attributes="0">
60
                  <Component id="rbGlobal" alignment="3" min="-2" max="-2" attributes="0"/>
61
                  <Component id="comGlobal" alignment="3" min="-2" max="-2" attributes="0"/>
62
                  <Component id="btnGlobal" alignment="3" min="-2" max="-2" attributes="0"/>
63
              </Group>
64
              <EmptySpace max="-2" attributes="0"/>
65
              <Group type="103" groupAlignment="3" attributes="0">
66
                  <Component id="rbProject" alignment="3" min="-2" max="-2" attributes="0"/>
67
                  <Component id="txtProject" alignment="3" min="-2" max="-2" attributes="0"/>
68
                  <Component id="btnProject" alignment="3" min="-2" max="-2" attributes="0"/>
69
              </Group>
70
              <EmptySpace max="-2" attributes="0"/>
71
              <Component id="lblLicense" min="-2" max="-2" attributes="0"/>
72
              <EmptySpace max="-2" attributes="0"/>
73
              <Component id="jScrollPane2" pref="195" max="32767" attributes="0"/>
74
              <EmptySpace max="-2" attributes="0"/>
75
          </Group>
76
      </Group>
77
    </DimensionLayout>
78
  </Layout>
79
  <SubComponents>
80
    <Component class="javax.swing.JRadioButton" name="rbGlobal">
81
      <Properties>
82
        <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
83
          <ComponentRef name="buttonGroup1"/>
84
        </Property>
85
        <Property name="selected" type="boolean" value="true"/>
86
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
87
          <ResourceString bundle="org/netbeans/spi/project/support/ant/ui/Bundle.properties" key="LicenseHeadersPanel.rbGlobal.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
88
        </Property>
89
      </Properties>
90
    </Component>
91
    <Component class="javax.swing.JRadioButton" name="rbProject">
92
      <Properties>
93
        <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
94
          <ComponentRef name="buttonGroup1"/>
95
        </Property>
96
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
97
          <ResourceString bundle="org/netbeans/spi/project/support/ant/ui/Bundle.properties" key="LicenseHeadersPanel.rbProject.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
98
        </Property>
99
      </Properties>
100
    </Component>
101
    <Component class="javax.swing.JComboBox" name="comGlobal">
102
    </Component>
103
    <Component class="javax.swing.JButton" name="btnGlobal">
104
      <Properties>
105
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
106
          <ResourceString bundle="org/netbeans/spi/project/support/ant/ui/Bundle.properties" key="LicenseHeadersPanel.btnGlobal.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
107
        </Property>
108
      </Properties>
109
      <Events>
110
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnGlobalActionPerformed"/>
111
      </Events>
112
    </Component>
113
    <Component class="javax.swing.JTextField" name="txtProject">
114
    </Component>
115
    <Component class="javax.swing.JButton" name="btnProject">
116
      <Properties>
117
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
118
          <ResourceString bundle="org/netbeans/spi/project/support/ant/ui/Bundle.properties" key="LicenseHeadersPanel.btnProject.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
119
        </Property>
120
      </Properties>
121
    </Component>
122
    <Component class="javax.swing.JLabel" name="lblLicense">
123
      <Properties>
124
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
125
          <ResourceString bundle="org/netbeans/spi/project/support/ant/ui/Bundle.properties" key="LicenseHeadersPanel.lblLicense.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
126
        </Property>
127
      </Properties>
128
    </Component>
129
    <Container class="javax.swing.JScrollPane" name="jScrollPane2">
130
      <AuxValues>
131
        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
132
      </AuxValues>
133
134
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
135
      <SubComponents>
136
        <Component class="javax.swing.JEditorPane" name="epLicense">
137
          <Properties>
138
            <Property name="contentType" type="java.lang.String" value="text/x-freemarker" noResource="true"/>
139
          </Properties>
140
        </Component>
141
      </SubComponents>
142
    </Container>
143
  </SubComponents>
144
</Form>
(-)project.ant/src/org/netbeans/spi/project/support/ant/ui/LicenseHeadersPanel.java (+469 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.project.support.ant.ui;
43
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.io.IOException;
47
import javax.swing.Action;
48
import javax.swing.DefaultComboBoxModel;
49
import javax.swing.event.DocumentEvent;
50
import javax.swing.event.DocumentListener;
51
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
52
import org.openide.filesystems.FileAttributeEvent;
53
import org.openide.filesystems.FileChangeAdapter;
54
import org.openide.filesystems.FileEvent;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileRenameEvent;
57
import org.openide.filesystems.FileUtil;
58
import org.openide.util.Exceptions;
59
60
/**
61
 *
62
 * @author mkleint
63
 */
64
class LicenseHeadersPanel extends javax.swing.JPanel {
65
66
    private static final String defaultProjectLicense = 
67
"<#if licenseFirst??>\n" +
68
"${licenseFirst}\n" +
69
"</#if>\n" +
70
"${licensePrefix}Here comes the text of your license\n" +
71
"${licensePrefix}Each line should be prefixed with ${licensePrefix}\n" +
72
"<#if licenseLast??>\n" +
73
"${licenseLast}\n" +
74
"</#if>";
75
    private final CustomizerUtilities.LicensePanelContentHandler handler;
76
    private final ProjectCustomizer.Category category;
77
    private final FileChangeAdapter fslistener;
78
    private final DocumentListener editorListener;
79
    /**
80
     * Creates new form LicenseHeadersPanel
81
     */
82
    LicenseHeadersPanel(ProjectCustomizer.Category category, CustomizerUtilities.LicensePanelContentHandler handler) {
83
        this.handler = handler;
84
        this.category = category;
85
        
86
        initComponents();
87
        
88
        btnProject.setVisible(false); //how to implement browse??
89
        
90
        
91
        editorListener = new DocumentListener() {
92
93
            @Override
94
            public void insertUpdate(DocumentEvent e) {
95
                LicenseHeadersPanel.this.handler.setProjectLicenseContent(epLicense.getText());
96
            }
97
98
            @Override
99
            public void removeUpdate(DocumentEvent e) {
100
                LicenseHeadersPanel.this.handler.setProjectLicenseContent(epLicense.getText());
101
            }
102
103
            @Override
104
            public void changedUpdate(DocumentEvent e) {
105
                LicenseHeadersPanel.this.handler.setProjectLicenseContent(epLicense.getText());
106
            }
107
        };
108
        
109
        loadGlobalLicenses();
110
        initValues();
111
        txtProject.getDocument().addDocumentListener(new DocumentListener() {
112
113
            @Override
114
            public void insertUpdate(DocumentEvent e) {
115
                changedUpdate(e);
116
            }
117
118
            @Override
119
            public void removeUpdate(DocumentEvent e) {
120
                changedUpdate(e);
121
            }
122
123
            @Override
124
            public void changedUpdate(DocumentEvent e) {
125
                LicenseHeadersPanel.this.handler.setProjectLicenseLocation(txtProject.getText().trim());
126
                setTextToProjectLicense();
127
            }
128
        });
129
        
130
        rbGlobal.addActionListener(new ActionListener() {
131
132
            @Override
133
            public void actionPerformed(ActionEvent e) {
134
                txtProject.setEnabled(false);
135
                epLicense.setEditable(false);
136
                btnProject.setEnabled(false);
137
                comGlobal.setEnabled(true);
138
                LicenseHeadersPanel.this.category.setErrorMessage(null);
139
                epLicense.getDocument().removeDocumentListener(editorListener);
140
                LicenseHeadersPanel.this.handler.setProjectLicenseContent(null);
141
                setTextToGlobalLicense();
142
                LicenseHeadersPanel.this.handler.setProjectLicenseLocation(null);
143
            }
144
        });
145
        rbProject.addActionListener(new ActionListener() {
146
147
            @Override
148
            public void actionPerformed(ActionEvent e) {
149
                txtProject.setEnabled(true);
150
                epLicense.setEditable(true);
151
                btnProject.setEnabled(true);
152
                comGlobal.setEnabled(false);
153
                epLicense.getDocument().addDocumentListener(editorListener);
154
                
155
                LicenseHeadersPanel.this.handler.setProjectLicenseLocation(txtProject.getText().trim());
156
                setTextToProjectLicense();
157
            }
158
159
        });
160
        comGlobal.addActionListener(new ActionListener() {
161
            @Override
162
            public void actionPerformed(ActionEvent e) {
163
164
                setTextToGlobalLicense();
165
                GlobalItem item = (GlobalItem) comGlobal.getSelectedItem();
166
                LicenseHeadersPanel.this.handler.setGlobalLicenseName(item.getName());
167
            }
168
169
        });
170
        FileObject root = FileUtil.getConfigFile("Templates/Licenses");
171
        fslistener = new FileChangeAdapter() {
172
            @Override
173
            public void fileDataCreated(FileEvent fe) {
174
                reloadGlobalTemplatesCombo();
175
            }
176
177
            @Override
178
            public void fileDeleted(FileEvent fe) {
179
                reloadGlobalTemplatesCombo();
180
            }
181
182
            @Override
183
            public void fileRenamed(FileRenameEvent fe) {
184
                reloadGlobalTemplatesCombo();
185
            }
186
187
            @Override
188
            public void fileAttributeChanged(FileAttributeEvent fe) {
189
                if ("displayName".equals(fe.getName())) {
190
                    reloadGlobalTemplatesCombo();
191
                }
192
            }
193
            
194
            @Override
195
            public void fileChanged(FileEvent fe) {
196
                if (rbGlobal.isSelected()) {
197
                    setTextToGlobalLicense();
198
                }
199
            }
200
        };
201
        root.addRecursiveListener(FileUtil.weakFileChangeListener(fslistener, root));
202
        
203
    }
204
    
205
    
206
    
207
    private void reloadGlobalTemplatesCombo() {
208
        category.setErrorMessage(null);
209
        GlobalItem item = (GlobalItem) comGlobal.getSelectedItem();
210
        String selection = item != null ? item.getName() : null;
211
        loadGlobalLicenses();
212
        if (selection != null) {
213
            boolean found = selectComboBoxItem(selection, rbGlobal.isSelected());
214
            if (!found) {
215
                category.setErrorMessage("The project's license with name '" + selection + "' was not found in IDE's license headers.");
216
            }
217
        }
218
    }
219
220
221
    /**
222
     * This method is called from within the constructor to initialize the form.
223
     * WARNING: Do NOT modify this code. The content of this method is always
224
     * regenerated by the Form Editor.
225
     */
226
    @SuppressWarnings("unchecked")
227
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
228
    private void initComponents() {
229
230
        buttonGroup1 = new javax.swing.ButtonGroup();
231
        rbGlobal = new javax.swing.JRadioButton();
232
        rbProject = new javax.swing.JRadioButton();
233
        comGlobal = new javax.swing.JComboBox();
234
        btnGlobal = new javax.swing.JButton();
235
        txtProject = new javax.swing.JTextField();
236
        btnProject = new javax.swing.JButton();
237
        lblLicense = new javax.swing.JLabel();
238
        jScrollPane2 = new javax.swing.JScrollPane();
239
        epLicense = new javax.swing.JEditorPane();
240
241
        buttonGroup1.add(rbGlobal);
242
        rbGlobal.setSelected(true);
243
        org.openide.awt.Mnemonics.setLocalizedText(rbGlobal, org.openide.util.NbBundle.getMessage(LicenseHeadersPanel.class, "LicenseHeadersPanel.rbGlobal.text")); // NOI18N
244
245
        buttonGroup1.add(rbProject);
246
        org.openide.awt.Mnemonics.setLocalizedText(rbProject, org.openide.util.NbBundle.getMessage(LicenseHeadersPanel.class, "LicenseHeadersPanel.rbProject.text")); // NOI18N
247
248
        org.openide.awt.Mnemonics.setLocalizedText(btnGlobal, org.openide.util.NbBundle.getMessage(LicenseHeadersPanel.class, "LicenseHeadersPanel.btnGlobal.text")); // NOI18N
249
        btnGlobal.addActionListener(new java.awt.event.ActionListener() {
250
            public void actionPerformed(java.awt.event.ActionEvent evt) {
251
                btnGlobalActionPerformed(evt);
252
            }
253
        });
254
255
        org.openide.awt.Mnemonics.setLocalizedText(btnProject, org.openide.util.NbBundle.getMessage(LicenseHeadersPanel.class, "LicenseHeadersPanel.btnProject.text")); // NOI18N
256
257
        org.openide.awt.Mnemonics.setLocalizedText(lblLicense, org.openide.util.NbBundle.getMessage(LicenseHeadersPanel.class, "LicenseHeadersPanel.lblLicense.text")); // NOI18N
258
259
        epLicense.setContentType("text/x-freemarker"); // NOI18N
260
        jScrollPane2.setViewportView(epLicense);
261
262
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
263
        this.setLayout(layout);
264
        layout.setHorizontalGroup(
265
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
266
            .add(layout.createSequentialGroup()
267
                .addContainerGap()
268
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
269
                    .add(rbProject)
270
                    .add(rbGlobal))
271
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
272
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
273
                    .add(comGlobal, 0, 221, Short.MAX_VALUE)
274
                    .add(txtProject))
275
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
276
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
277
                    .add(btnGlobal)
278
                    .add(btnProject)))
279
            .add(layout.createSequentialGroup()
280
                .add(35, 35, 35)
281
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
282
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
283
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
284
                        .addContainerGap())
285
                    .add(layout.createSequentialGroup()
286
                        .add(lblLicense)
287
                        .add(0, 0, Short.MAX_VALUE))))
288
        );
289
290
        layout.linkSize(new java.awt.Component[] {btnGlobal, btnProject}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
291
292
        layout.setVerticalGroup(
293
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
294
            .add(layout.createSequentialGroup()
295
                .addContainerGap()
296
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
297
                    .add(rbGlobal)
298
                    .add(comGlobal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
299
                    .add(btnGlobal))
300
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
301
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
302
                    .add(rbProject)
303
                    .add(txtProject, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
304
                    .add(btnProject))
305
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
306
                .add(lblLicense)
307
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
308
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
309
                .addContainerGap())
310
        );
311
    }// </editor-fold>//GEN-END:initComponents
312
313
    private void btnGlobalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGlobalActionPerformed
314
        // TODO add your handling code here:
315
        Action action = FileUtil.getConfigObject("Actions/System/org-netbeans-modules-favorites-templates-TemplatesAction.instance", Action.class);
316
        if (action != null) {
317
            action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "perform"));
318
        } else {
319
            Exceptions.printStackTrace(new Exception("Actions/System/org-netbeans-modules-favorites-templates-TemplatesAction.instance not found"));
320
        }
321
    }//GEN-LAST:event_btnGlobalActionPerformed
322
323
    // Variables declaration - do not modify//GEN-BEGIN:variables
324
    private javax.swing.JButton btnGlobal;
325
    private javax.swing.JButton btnProject;
326
    private javax.swing.ButtonGroup buttonGroup1;
327
    private javax.swing.JComboBox comGlobal;
328
    private javax.swing.JEditorPane epLicense;
329
    private javax.swing.JScrollPane jScrollPane2;
330
    private javax.swing.JLabel lblLicense;
331
    private javax.swing.JRadioButton rbGlobal;
332
    private javax.swing.JRadioButton rbProject;
333
    private javax.swing.JTextField txtProject;
334
    // End of variables declaration//GEN-END:variables
335
336
    
337
    private void loadGlobalLicenses() {
338
        FileObject root = FileUtil.getConfigFile("Templates/Licenses");
339
        DefaultComboBoxModel<GlobalItem> model = new DefaultComboBoxModel<GlobalItem>();
340
        for (FileObject fo : root.getChildren()) {
341
            if (fo.getAttribute("template") == null) {
342
                continue;
343
            }
344
            String displayName = (String) fo.getAttribute("displayName");
345
            if (displayName == null) {
346
                displayName = fo.getName();
347
                if (displayName.startsWith("license-")) {
348
                   displayName = displayName.substring("license-".length());
349
                }
350
            }
351
            model.addElement(new GlobalItem(displayName, fo));
352
        }
353
        comGlobal.setModel(model);
354
    }
355
    
356
    private void setTextToGlobalLicense() {
357
        GlobalItem item = (GlobalItem) comGlobal.getSelectedItem();
358
        if (item == null) {
359
            epLicense.setText("");
360
        } else {
361
            try {
362
                if (item.fileObject != null) {
363
                    epLicense.setText(item.fileObject.asText());
364
                } else {
365
                   epLicense.setText("<License header template not found for name '" + item.getName() + "'>"); 
366
                }
367
            } catch (IOException ex) {
368
                Exceptions.printStackTrace(ex);
369
            }
370
        }
371
    }
372
    
373
    private void setTextToProjectLicense() {
374
        category.setErrorMessage(null);
375
        String path = txtProject.getText();
376
        FileObject fo = handler.resolveProjectLocation(path);
377
        if (fo != null) {
378
            try {
379
                epLicense.setText(fo.asText());
380
            } catch (IOException ex) {
381
                Exceptions.printStackTrace(ex);
382
            }
383
        } else {
384
            category.setErrorMessage("File at path '" + path + "' doesn't exist.");
385
            epLicense.setText(defaultProjectLicense);
386
        }
387
        
388
    }
389
    
390
    
391
392
    private void initValues() {
393
        String name = handler.getGlobalLicenseName();
394
        String path = handler.getProjectLicenseLocation();
395
        if (name == null) {
396
            name = "default";
397
        }
398
        boolean found = selectComboBoxItem(name, true);
399
        if (path == null) {
400
            path = handler.getDefaultProjectLicenseLocation();
401
            txtProject.setText(path);
402
            rbGlobal.setSelected(true); //has to come last
403
            if (!found) {
404
                category.setErrorMessage("The project's license with name '" + name + "' was not found in IDE's license headers.");
405
            }
406
        } else {
407
            txtProject.setText(path);
408
            rbProject.setSelected(true); //has to come last
409
            setTextToProjectLicense();
410
            epLicense.getDocument().addDocumentListener(editorListener);
411
        }
412
    }
413
414
    private boolean selectComboBoxItem(String name, boolean setText) {
415
        boolean found = false;
416
        DefaultComboBoxModel model = (DefaultComboBoxModel) comGlobal.getModel();
417
        for (int i = 0; i < model.getSize(); i++) {
418
            GlobalItem gi = (GlobalItem) model.getElementAt(i);
419
            if (gi.getName().equals(name)) {
420
                comGlobal.setSelectedItem(gi);
421
                found = true;
422
                if (setText) {
423
                    setTextToGlobalLicense();
424
                }
425
                break;
426
            }
427
        }
428
        if (!found) {
429
            GlobalItem itm = new GlobalItem(name, null);
430
            model.insertElementAt(itm, 0);
431
            comGlobal.setSelectedItem(itm);
432
            if (setText) {
433
                setTextToGlobalLicense();
434
            }
435
        }
436
        return found;
437
    }
438
439
    
440
    private class GlobalItem {
441
        
442
        final String displayName;
443
        final FileObject fileObject;
444
445
        public GlobalItem(String name, FileObject fileObject) {
446
            this.displayName = name;
447
            this.fileObject = fileObject;
448
        }
449
        
450
        public String getName() {
451
            if (fileObject == null) {
452
                return displayName;
453
            }
454
            String name = fileObject.getName();
455
            if (name.startsWith("license-")) {
456
                name = name.substring("license-".length());
457
            }
458
            return name;
459
        }
460
461
        @Override
462
        public String toString() {
463
            return displayName;
464
        }
465
    }
466
    
467
    
468
    
469
}

Return to bug 226773