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 228409
Collapse All | Expand All

(-)a/apisupport.ant/nbproject/project.xml (+4 lines)
Lines 355-360 Link Here
355
                        <compile-dependency/>
355
                        <compile-dependency/>
356
                    </test-dependency>
356
                    </test-dependency>
357
                    <test-dependency>
357
                    <test-dependency>
358
                        <code-name-base>org.netbeans.libs.testng</code-name-base>
359
                        <compile-dependency/>
360
                    </test-dependency>
361
                    <test-dependency>
358
                        <code-name-base>org.netbeans.modules.apisupport.ant</code-name-base>
362
                        <code-name-base>org.netbeans.modules.apisupport.ant</code-name-base>
359
                        <recursive/>
363
                        <recursive/>
360
                    </test-dependency>
364
                    </test-dependency>
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/NbModuleProject.java (+2 lines)
Lines 102-107 Link Here
102
import org.netbeans.modules.apisupport.project.ui.ModuleLogicalView;
102
import org.netbeans.modules.apisupport.project.ui.ModuleLogicalView;
103
import org.netbeans.modules.apisupport.project.ui.ModuleOperations;
103
import org.netbeans.modules.apisupport.project.ui.ModuleOperations;
104
import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl;
104
import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl;
105
import org.netbeans.modules.apisupport.project.ui.customizer.NbModulePackageModifierImplementation;
105
import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties;
106
import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties;
106
import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
107
import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
107
import org.netbeans.modules.apisupport.project.universe.HarnessVersion;
108
import org.netbeans.modules.apisupport.project.universe.HarnessVersion;
Lines 312-317 Link Here
312
        ic.add(new SourceLevelQueryImpl(this));
313
        ic.add(new SourceLevelQueryImpl(this));
313
        //ic.add(new ProjectWhiteListQueryImplementation(this));
314
        //ic.add(new ProjectWhiteListQueryImplementation(this));
314
        ic.add(new ProjectWhiteListQueryImplementation(this));
315
        ic.add(new ProjectWhiteListQueryImplementation(this));
316
        ic.add(new NbModulePackageModifierImplementation(this));
315
        ic.add(helper.createSharabilityQuery2(evaluator(), new String[0], new String[]{
317
        ic.add(helper.createSharabilityQuery2(evaluator(), new String[0], new String[]{
316
                    "${build.dir}", // NOI18N
318
                    "${build.dir}", // NOI18N
317
                }));
319
                }));
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/ExportPackageAction.java (-171 lines)
Lines 1-171 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.modules.apisupport.project.ui.customizer;
43
44
import java.awt.event.ActionEvent;
45
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import java.util.Iterator;
49
import java.util.SortedSet;
50
import javax.swing.AbstractAction;
51
import javax.swing.Action;
52
import org.netbeans.api.project.FileOwnerQuery;
53
import org.netbeans.api.project.Project;
54
import org.netbeans.api.project.ProjectManager;
55
import org.netbeans.modules.apisupport.project.ApisupportAntUtils;
56
import org.netbeans.modules.apisupport.project.NbModuleProject;
57
import org.openide.ErrorManager;
58
import org.openide.awt.ActionID;
59
import org.openide.awt.ActionReference;
60
import org.openide.awt.ActionReferences;
61
import org.openide.awt.ActionRegistration;
62
import org.openide.awt.DynamicMenuContent;
63
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.util.ContextAwareAction;
66
import org.openide.util.Lookup;
67
import org.openide.util.Mutex;
68
import org.openide.util.MutexException;
69
import org.openide.util.NbBundle.Messages;
70
71
/**
72
 * Submenu which permits the user to export or unexport appropriate package.
73
 * Must be locate in NetBeans Module Project.
74
 */
75
@ActionID(
76
        category = "Project",
77
        id = "org.netbeans.modules.apisupport.project.ExportPackageAction")
78
@ActionRegistration(
79
        displayName = "#CTL_ExportPackageAction", lazy = false)
80
@ActionReferences({
81
    @ActionReference(path = "Projects/package/Actions", position = 100),
82
})
83
@Messages({"CTL_UnexportPackageAction=Unexport Package","CTL_ExportPackageAction=Export Package"})
84
public final class ExportPackageAction extends AbstractAction implements ContextAwareAction{
85
86
    @Override
87
    public void actionPerformed(ActionEvent ev) {
88
        //well, since someone can assign a shortcut ti the action, the invokation is unvaiodable, make it noop        
89
        //assert false : "Action should never be called without a context";
90
    }
91
92
    @Override
93
    public Action createContextAwareInstance(Lookup actionContext) {
94
        Collection<FileObject> selectedPackages = (Collection<FileObject>) actionContext.lookupAll(FileObject.class);
95
        Project project = FileOwnerQuery.getOwner(selectedPackages.iterator().hasNext()?selectedPackages.iterator().next():null);
96
        NbModuleProject nbmProject = null;
97
        if((nbmProject = project.getLookup().lookup(NbModuleProject.class)) != null)
98
        {
99
            Collection<String> packages = new ArrayList<String>();
100
            SortedSet<String> availablePublicPackages = ApisupportAntUtils.scanProjectForPackageNames(FileUtil.toFile(nbmProject.getProjectDirectory()), false);
101
            final SingleModuleProperties properties = SingleModuleProperties.getInstance(nbmProject);
102
            String packageNameIter = "";
103
            boolean export = false;
104
            for (Iterator<FileObject> it = selectedPackages.iterator(); it.hasNext();) {
105
                FileObject packageIter = it.next();
106
                if(!availablePublicPackages.contains(packageNameIter = packageIter.getPath().substring(nbmProject.getSourceDirectory().getPath().length()+1).replace('/', '.'))) {
107
                    continue;
108
                }
109
                packages.add(packageNameIter);
110
                if(!properties.getPublicPackagesModel().getSelectedPackages().contains(packageNameIter) && !export) {
111
                    export = true;
112
                }
113
            }
114
            return new ContextAction(!packages.isEmpty(), nbmProject, packages, properties, export);
115
        }
116
        return new ContextAction(false);
117
    }
118
119
    /**
120
     * The particular instance of this action for a given package(s).
121
     */
122
    private static final class ContextAction extends AbstractAction {
123
124
        private NbModuleProject nbmProject;
125
        
126
        private final SingleModuleProperties properties;
127
        
128
        private Collection<String> packages;
129
        
130
        private boolean export;
131
        
132
        public ContextAction(boolean enabled) {
133
            this(enabled, null, null, null, true);
134
        }
135
        
136
        public ContextAction(boolean enabled, NbModuleProject nbmProject, Collection<String> packages, SingleModuleProperties properties, boolean export) {
137
            super(export?Bundle.CTL_ExportPackageAction():Bundle.CTL_UnexportPackageAction());
138
            this.nbmProject = nbmProject;
139
            this.packages = packages;
140
            this.properties = properties;
141
            this.export = export;
142
            this.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
143
            this.setEnabled(enabled);
144
        }
145
        
146
        @Override
147
        public void actionPerformed(ActionEvent evt) {
148
            CustomizerComponentFactory.PublicPackagesTableModel tableModel = properties.getPublicPackagesModel();
149
            for(String packageIter:this.packages) {
150
                for(int i = 0; i < tableModel.getRowCount(); i++) {
151
                    if(tableModel.getValueAt(i, 1).equals(packageIter)) {
152
                        tableModel.setValueAt(this.export, i, 0);
153
                        break;
154
                    }
155
                }
156
            }
157
            try {
158
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
159
                @Override public Void run() throws IOException {
160
                    properties.storeProperties();
161
                    ProjectManager.getDefault().saveProject(nbmProject);
162
                    return null;
163
                }
164
            });
165
            } catch (MutexException e) {
166
                ErrorManager.getDefault().notify((IOException)e.getException());
167
            }
168
        }
169
        
170
    }
171
}
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/NbModulePackageModifierImplementation.java (+116 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.modules.apisupport.project.ui.customizer;
43
44
import java.io.IOException;
45
import java.util.Collection;
46
import org.netbeans.api.project.ProjectManager;
47
import org.netbeans.modules.apisupport.project.ApisupportAntUtils;
48
import org.netbeans.modules.apisupport.project.NbModuleProject;
49
import org.netbeans.modules.java.api.common.ant.PackageModifierImplementation;
50
import org.openide.ErrorManager;
51
import org.openide.filesystems.FileUtil;
52
import org.openide.util.Mutex;
53
import org.openide.util.MutexException;
54
55
/**
56
 *
57
 * @author mkozeny
58
 */
59
60
//@ProjectServiceProvider(service = PackageModifierImplementation.class)
61
public final class NbModulePackageModifierImplementation implements PackageModifierImplementation{
62
63
    private final NbModuleProject project;
64
    
65
    /**
66
     * Constructor
67
     * @param project 
68
     */
69
    public NbModulePackageModifierImplementation(NbModuleProject project) {
70
        this.project = project;
71
    }
72
    
73
    @Override
74
    public Collection<String> getAllPackages() {
75
        if(this.project != null) {
76
            return ApisupportAntUtils.scanProjectForPackageNames(FileUtil.toFile(this.project.getProjectDirectory()), false);
77
        }
78
        return null;
79
    }
80
    
81
    @Override
82
    public Collection<String> getPublicPackages() {
83
        if(this.project != null) {
84
            final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project);
85
            return properties.getPublicPackagesModel().getSelectedPackages();
86
        }
87
        return null;
88
    }
89
90
    @Override
91
    public void exportPackageAction(Collection<String> packagesToExport, boolean export) {
92
        final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project);
93
        CustomizerComponentFactory.PublicPackagesTableModel tableModel = properties.getPublicPackagesModel();
94
            for(String packageIter:packagesToExport) {
95
                for(int i = 0; i < tableModel.getRowCount(); i++) {
96
                    if(tableModel.getValueAt(i, 1).equals(packageIter)) {
97
                        tableModel.setValueAt(export, i, 0);
98
                        break;
99
                    }
100
                }
101
            }
102
            final NbModuleProject nbmProject = this.project;
103
            try {
104
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
105
                @Override public Void run() throws IOException {
106
                    properties.storeProperties();
107
                    ProjectManager.getDefault().saveProject(nbmProject);
108
                    return null;
109
                }
110
            });
111
            } catch (MutexException e) {
112
                ErrorManager.getDefault().notify((IOException)e.getException());
113
            }
114
    }
115
    
116
}
(-)a/java.api.common/apichanges.xml (+19 lines)
Lines 105-110 Link Here
105
105
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <changes>
107
    <changes>
108
        <change id="api-package-modification">
109
            <api name="java-api-common"/>
110
            <summary>New API <code>PackageModificationImplementation</code></summary>
111
            <version major="1" minor="47"/>
112
            <date day="10" month="4" year="2013"/>
113
            <author login="mkozeny"/>
114
            <compatibility semantic="compatible" source="compatible" binary="compatible"/>
115
            <description>
116
                <p>
117
                    Added new API <code>PackageModificationImplementation</code>, which provides methods
118
                    for getting all available packages (<code>getPackagesToExport</code>)
119
                    and all public packages (<code>getPublicPackages</code>),
120
                    (un)exporting them (<code>exportPackageAction</code>).
121
                    This API is used by <code>ExportPackageAction</code> located in non-public package <code>org.netbeans.modules.java.api.common.impl</code>
122
                    which is action implemented for exporting package(s) from NetBeans Module Project.
123
                </p>
124
            </description>
125
            <issue number="202329"/>
126
        </change>
108
        <change id="jre-profiles">
127
        <change id="jre-profiles">
109
            <api name="java-api-common"/>
128
            <api name="java-api-common"/>
110
            <summary>Added UI support for JRE profiles.</summary>
129
            <summary>Added UI support for JRE profiles.</summary>
(-)a/java.api.common/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.46
4
OpenIDE-Module-Specification-Version: 1.47
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/ant/PackageModifierImplementation.java (+73 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.modules.java.api.common.ant;
43
44
import java.util.Collection;
45
import org.netbeans.api.annotations.common.NonNull;
46
47
/**
48
 * Provide API for manipulating with project packages.
49
 * @author mkozeny
50
 * @since 1.47
51
 */
52
public interface PackageModifierImplementation {
53
    
54
    /**
55
     * Returns collection of all available packages to export or to unexport
56
     * @return collection of all packages which are possible to export or to unexport
57
     */
58
    public @NonNull Collection<String> getAllPackages();
59
    
60
    /**
61
     * Returns collection of public packages
62
     * @return collection of public packages
63
     */
64
    public @NonNull Collection<String> getPublicPackages();
65
    
66
    /**
67
     * Do the export or unexport of passed set of packages
68
     * @param packagesToExport set of packages to export or to unexport
69
     * @param export whether passed set of packages should be export or unexport
70
     */
71
    public void exportPackageAction(@NonNull Collection<String> packagesToExport, boolean export);
72
    
73
}
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/impl/ExportPackageAction.java (+165 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.modules.java.api.common.impl;
43
44
import java.awt.event.ActionEvent;
45
import java.util.ArrayList;
46
import java.util.Collection;
47
import java.util.Iterator;
48
import javax.swing.AbstractAction;
49
import javax.swing.Action;
50
import org.netbeans.api.project.FileOwnerQuery;
51
import org.netbeans.api.project.Project;
52
import org.netbeans.modules.java.api.common.ant.PackageModifierImplementation;
53
import org.openide.awt.ActionID;
54
import org.openide.awt.ActionReference;
55
import org.openide.awt.ActionReferences;
56
import org.openide.awt.ActionRegistration;
57
import org.openide.awt.DynamicMenuContent;
58
import org.openide.filesystems.FileObject;
59
import org.openide.util.ContextAwareAction;
60
import org.openide.util.Lookup;
61
import org.openide.util.NbBundle.Messages;
62
63
/**
64
 * Submenu which permits the user to export or unexport appropriate package.
65
 * Must be locate in NetBeans Module Project.
66
 */
67
@ActionID(
68
        category = "Project",
69
        id = "org.netbeans.modules.apisupport.project.ExportPackageAction")
70
@ActionRegistration(
71
        displayName = "#CTL_ExportPackageAction", lazy = false)
72
@ActionReferences({
73
    @ActionReference(path = "Projects/package/Actions", position = 100),
74
})
75
@Messages({"CTL_UnexportPackageAction=Unexport Package","CTL_ExportPackageAction=Export Package"})
76
public final class ExportPackageAction extends AbstractAction implements ContextAwareAction{
77
78
    @Override
79
    public void actionPerformed(ActionEvent ev) {
80
        //well, since someone can assign a shortcut ti the action, the invokation is unvaiodable, make it noop        
81
        //assert false : "Action should never be called without a context";
82
    }
83
84
    @Override
85
    public Action createContextAwareInstance(Lookup actionContext) {
86
        if(actionContext != null) {
87
            Collection<? extends FileObject> selectedPackagesLookup = actionContext.lookupAll(FileObject.class);
88
            Collection<FileObject> selectedPackages = new ArrayList<>();
89
            for(FileObject packageIter:selectedPackagesLookup) {
90
                selectedPackages.add(packageIter);
91
            }
92
            Iterator<FileObject> selectedPackagesIterator = selectedPackages.iterator();
93
            Project project = null;
94
            if(selectedPackagesIterator.hasNext()) {
95
                project = FileOwnerQuery.getOwner(selectedPackagesIterator.next());
96
                if(project != null) {
97
                    while(selectedPackagesIterator.hasNext()) {
98
                        Project tmpProject = FileOwnerQuery.getOwner(selectedPackagesIterator.next());
99
                        if(!project.equals(tmpProject)) {
100
                            return new ExportPackageAction.ContextAction();
101
                        }
102
                    }
103
                } else {
104
                    return new ExportPackageAction.ContextAction();
105
                }
106
            }
107
            PackageModifierImplementation pmi = null;
108
            if((pmi = project.getLookup().lookup(PackageModifierImplementation.class)) != null) {
109
                Collection<String> allPackages = pmi.getAllPackages();
110
                Collection<String> packagesToExport = new ArrayList<>();
111
                String selectedPackageNameIter = "";
112
                for(FileObject selectedPkgIter:selectedPackages) {
113
                    if(allPackages.contains(
114
                            selectedPackageNameIter = selectedPkgIter.getPath()
115
                            .substring(project.getProjectDirectory().getPath().length()+5).replace('/', '.'))) {
116
                        packagesToExport.add(selectedPackageNameIter);
117
                    }
118
                }
119
                Collection<String> publicPackages = pmi.getPublicPackages();
120
                boolean export = false;
121
                for(String exportPkgIter:packagesToExport) {
122
                    if(!publicPackages.contains(exportPkgIter)) {
123
                        export = true;
124
                        break;
125
                    }
126
                }
127
                return new ExportPackageAction.ContextAction(pmi, packagesToExport, export);
128
            }
129
        }
130
        return new ExportPackageAction.ContextAction();
131
    }
132
133
    /**
134
     * The particular instance of this action for a given package(s).
135
     */
136
    private static final class ContextAction extends AbstractAction {
137
138
        private Collection<String> packagesToExport; 
139
        private boolean export;
140
        private PackageModifierImplementation pmi;
141
        
142
        public ContextAction() {
143
            this(true, false);
144
        }
145
        
146
        public ContextAction(PackageModifierImplementation pmi, Collection<String> packagesToExport, boolean export) {
147
            this(export, packagesToExport!=null && !packagesToExport.isEmpty());
148
            this.pmi = pmi;
149
            this.packagesToExport = packagesToExport;
150
            this.export = export;
151
        }
152
        
153
        private ContextAction(boolean export, boolean enable) {
154
            super(export?Bundle.CTL_ExportPackageAction():Bundle.CTL_UnexportPackageAction());
155
            this.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
156
            this.setEnabled(enable);
157
        }
158
        
159
        @Override
160
        public void actionPerformed(ActionEvent evt) {
161
            pmi.exportPackageAction(packagesToExport, export);
162
        }
163
        
164
    }
165
}

Return to bug 228409