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

(-)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>
(-)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.NbModuleProjectModifierImplementation;
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 NbModuleProjectModifierImplementation(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
                }));
(-)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
}
(-)apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/NbModuleProjectModifierImplementation.java (+133 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.ArrayList;
46
import java.util.Collection;
47
import java.util.Iterator;
48
import java.util.SortedSet;
49
import org.netbeans.api.project.ProjectManager;
50
import org.netbeans.modules.apisupport.project.ApisupportAntUtils;
51
import org.netbeans.modules.apisupport.project.NbModuleProject;
52
import org.netbeans.spi.java.queries.ProjectModifierImplementation;
53
import org.openide.ErrorManager;
54
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.util.Mutex;
57
import org.openide.util.MutexException;
58
59
/**
60
 *
61
 * @author mkozeny
62
 */
63
64
//@ProjectServiceProvider(service = ProjectModifierImplementation.class)
65
public final class NbModuleProjectModifierImplementation implements ProjectModifierImplementation{
66
67
    private final NbModuleProject project;
68
    
69
    /**
70
     * Constructor
71
     * @param project 
72
     */
73
    public NbModuleProjectModifierImplementation(NbModuleProject project) {
74
        this.project = project;
75
    }
76
    
77
    @Override
78
    public Collection<String> getPackagesToExport(Collection<FileObject> selectedPackages) {
79
        if(this.project != null)
80
        {
81
            Collection<String> packages = new ArrayList<String>();
82
            SortedSet<String> availablePublicPackages = ApisupportAntUtils.scanProjectForPackageNames(FileUtil.toFile(this.project.getProjectDirectory()), false);
83
            String packageNameIter = "";
84
            for (Iterator<FileObject> it = selectedPackages.iterator(); it.hasNext();) {
85
                FileObject packageIter = it.next();
86
                if(!availablePublicPackages.contains(packageNameIter = packageIter.getPath().substring(this.project.getSourceDirectory().getPath().length()+1).replace('/', '.'))) {
87
                    continue;
88
                }
89
                packages.add(packageNameIter);
90
            }
91
            return packages;
92
        }
93
        return null;
94
    }
95
96
    @Override
97
    public void exportPackageAction(Collection<String> packagesToExport, boolean export) {
98
        final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project);
99
        CustomizerComponentFactory.PublicPackagesTableModel tableModel = properties.getPublicPackagesModel();
100
            for(String packageIter:packagesToExport) {
101
                for(int i = 0; i < tableModel.getRowCount(); i++) {
102
                    if(tableModel.getValueAt(i, 1).equals(packageIter)) {
103
                        tableModel.setValueAt(export, i, 0);
104
                        break;
105
                    }
106
                }
107
            }
108
            final NbModuleProject nbmProject = this.project;
109
            try {
110
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
111
                @Override public Void run() throws IOException {
112
                    properties.storeProperties();
113
                    ProjectManager.getDefault().saveProject(nbmProject);
114
                    return null;
115
                }
116
            });
117
            } catch (MutexException e) {
118
                ErrorManager.getDefault().notify((IOException)e.getException());
119
            }
120
    }
121
122
    @Override
123
    public boolean isExportSelectedPackages(Collection<String> packagesToExport) {
124
        final SingleModuleProperties properties = SingleModuleProperties.getInstance(this.project);
125
        for (String packageIter:packagesToExport) {
126
            if(!properties.getPublicPackagesModel().getSelectedPackages().contains(packageIter)) {
127
                return true;
128
            }
129
        }
130
        return false;
131
    }
132
133
}

Return to bug 200833