Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 212238
Collapse All | Expand All

(-)java.api.common/apichanges.xml (+19 lines)
 Lines 107-112    Link Here 
107
    <changes>
107
    <changes>
108
        <change id="jre-profiles">
108
        <change id="jre-profiles">
109
            <api name="java-api-common"/>
109
            <api name="java-api-common"/>
110
            <summary>Added PlatformFilter interface.</summary>
111
            <version major="1" minor="47"/>
112
            <date day="23" month="4" year="2013"/>
113
            <author login="psomol"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                <p>
117
                    Added interface <code>PlatformFilter</code> to enable filtering out
118
                    Java Platforms from UI lists. The primary usecase is to enable
119
                    projects that are extensions of SE project to hook into project
120
                    UI provided by SE project. More specifically, FX projects need
121
                    to hide non-FX platforms in Project Properties panels belonging to SE.
122
                </p>
123
            </description>
124
            <class package="org.netbeans.modules.java.api.common.ui" name="PlatformFilter"/>
125
            <issue number="212238"/>
126
        </change>
127
        <change id="jre-profiles">
128
            <api name="java-api-common"/>
110
            <summary>Added UI support for JRE profiles.</summary>
129
            <summary>Added UI support for JRE profiles.</summary>
111
            <version major="1" minor="45"/>
130
            <version major="1" minor="45"/>
112
            <date day="4" month="3" year="2013"/>
131
            <date day="4" month="3" year="2013"/>
(-)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
(-)java.api.common/src/org/netbeans/modules/java/api/common/ui/PlatformFilter.java (+62 lines)
Added 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.ui;
43
44
import org.netbeans.api.java.platform.JavaPlatform;
45
46
/**
47
 * Platform filter is to be used in platform lists (e.g., in combo boxes).
48
 * Projects should be able to register implementation in lookup, to restrict
49
 * lists of platforms to only platforms fulfilling project's needs. This mechanism
50
 * is useful in projects that extend the SE Project and need to hook into the
51
 * underlying SE UI infrastructure.
52
 * 
53
 * @author psomol
54
 */
55
public interface PlatformFilter {
56
    
57
    /**
58
     * Returns true if platform fulfills whatever condition is implemented
59
     */
60
    boolean accept(JavaPlatform platform);
61
    
62
}
(-)java.api.common/src/org/netbeans/modules/java/api/common/ui/PlatformUiSupport.java (-10 / +44 lines)
 Lines 85-91    Link Here 
85
85
86
/**
86
/**
87
 * Support class for {@link JavaPlatform} manipulation in project customizer.
87
 * Support class for {@link JavaPlatform} manipulation in project customizer.
88
 * @author Tomas Zezula, Tomas Mysik
88
 * @author Tomas Zezula, Tomas Mysik, Petr Somol
89
 */
89
 */
90
public final class PlatformUiSupport {
90
public final class PlatformUiSupport {
91
91
 Lines 109-114    Link Here 
109
109
110
110
111
    /**
111
    /**
112
     * Create a {@link ComboBoxModel} of Java platforms.
113
     * The model listens on the {@link JavaPlatformManager} and update its
114
     * state according to the changes.
115
     * @param activePlatform the active project's platform, can be <code>null</code>.
116
     * @param filter project specific filter to filter-out platforms that are not usable in given context
117
     * @return {@link ComboBoxModel}.
118
     */
119
    public static ComboBoxModel createPlatformComboBoxModel(String activePlatform, Collection<? extends PlatformFilter> filters) {
120
        return new PlatformComboBoxModel(activePlatform, filters);
121
    }
122
123
124
    /**
112
     * Create a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel}
125
     * Create a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel}
113
     * created by the {@link PlatformUiSupport#createPlatformComboBoxModel(String)} method.
126
     * created by the {@link PlatformUiSupport#createPlatformComboBoxModel(String)} method.
114
     * @return {@link ListCellRenderer}.
127
     * @return {@link ListCellRenderer}.
 Lines 612-622    Link Here 
612
        private String initialPlatform;
625
        private String initialPlatform;
613
        private PlatformKey selectedPlatform;
626
        private PlatformKey selectedPlatform;
614
        private boolean inUpdate;
627
        private boolean inUpdate;
628
        private Collection<? extends PlatformFilter> filters;
615
629
616
        public PlatformComboBoxModel(String initialPlatform) {
630
        public PlatformComboBoxModel(String initialPlatform) {
631
            this(initialPlatform, null);
632
        }
633
634
        public PlatformComboBoxModel(String initialPlatform, Collection<? extends PlatformFilter> filters) {
617
            this.pm = JavaPlatformManager.getDefault();
635
            this.pm = JavaPlatformManager.getDefault();
618
            this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm));
636
            this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm));
619
            this.initialPlatform = initialPlatform;
637
            this.initialPlatform = initialPlatform;
638
            this.filters = filters;
620
        }
639
        }
621
640
622
        public int getSize() {
641
        public int getSize() {
 Lines 668-674    Link Here 
668
                Set<PlatformKey> orderedNames = new TreeSet<PlatformKey>();
687
                Set<PlatformKey> orderedNames = new TreeSet<PlatformKey>();
669
                boolean activeFound = false;
688
                boolean activeFound = false;
670
                for (JavaPlatform platform : platforms) {
689
                for (JavaPlatform platform : platforms) {
671
                    if (platform.getInstallFolders().size() > 0) {
690
                    boolean accepted = true;
691
                    if(filters != null) {
692
                        for(PlatformFilter filter : filters) {
693
                            if(!filter.accept(platform)) {
694
                                accepted = false;
695
                                break;
696
                            }
697
                        }
698
                    }
699
                    if (accepted && platform.getInstallFolders().size() > 0) {
672
                        PlatformKey pk = new PlatformKey(platform);
700
                        PlatformKey pk = new PlatformKey(platform);
673
                        orderedNames.add(pk);
701
                        orderedNames.add(pk);
674
                        if (!activeFound && initialPlatform != null) {
702
                        if (!activeFound && initialPlatform != null) {
 Lines 684-698    Link Here 
684
                    }
712
                    }
685
                }
713
                }
686
                if (!activeFound) {
714
                if (!activeFound) {
687
                    if (initialPlatform == null) {
715
                    if(orderedNames.isEmpty()) {
688
                        if (selectedPlatform == null || !orderedNames.contains(selectedPlatform)) {
716
                        LOGGER.warning("PlatformComboBoxModel: All platforms filtered out. Adding default platform although it is not accepted by all PlatformFilters."); // NOI18N
689
                            selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
717
                        selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
690
                        }
718
                        orderedNames.add(selectedPlatform);
691
                    } else {
719
                    } else {
692
                        PlatformKey pk = new PlatformKey(initialPlatform);
720
                        if (initialPlatform == null) {
693
                        orderedNames.add(pk);
721
                            if (selectedPlatform == null || !orderedNames.contains(selectedPlatform)) {
694
                        if (selectedPlatform == null) {
722
                                selectedPlatform = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
695
                            selectedPlatform = pk;
723
                            }
724
                        } else {
725
                            PlatformKey pk = new PlatformKey(initialPlatform);
726
                            orderedNames.add(pk);
727
                            if (selectedPlatform == null) {
728
                                selectedPlatform = pk;
729
                            }
696
                        }
730
                        }
697
                    }
731
                    }
698
                }
732
                }
(-)java.api.common/test/unit/src/org/netbeans/modules/java/api/common/ui/PlatformFilterTest.java (+284 lines)
Added 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.ui;
43
44
import org.netbeans.modules.java.api.common.ui.PlatformFilter;
45
import java.beans.PropertyChangeListener;
46
import java.io.File;
47
import java.net.URL;
48
import java.util.ArrayList;
49
import java.util.Collection;
50
import java.util.Collections;
51
import java.util.List;
52
import java.util.Map;
53
import org.netbeans.api.java.classpath.ClassPath;
54
import org.netbeans.api.java.platform.JavaPlatform;
55
import org.netbeans.api.java.platform.Specification;
56
import org.netbeans.api.project.Project;
57
import org.netbeans.junit.NbTestCase;
58
import org.netbeans.modules.java.platform.JavaPlatformProvider;
59
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
60
import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.modules.SpecificationVersion;
64
import org.openide.util.Lookup;
65
import org.openide.util.lookup.Lookups;
66
import org.openide.util.test.MockLookup;
67
68
69
public class PlatformFilterTest extends NbTestCase {
70
    
71
    private static final String PRESERVE = "ToBePreserved";
72
    private static final String FILTEROUT = "ToBeFilteredOut";
73
    private MockProject prj1;
74
    private MockProject prj2;
75
    private JavaPlatform platform1;
76
    private JavaPlatform platform2;
77
    private JavaPlatform platform3;
78
    
79
    public PlatformFilterTest(final String name) {
80
        super(name);
81
    }
82
83
    @Override
84
    protected void setUp() throws Exception {
85
        super.setUp();
86
        platform1 = new TestPlatform("DefaultPlatform" + PRESERVE);
87
        platform2 = new TestPlatform("Platform" + PRESERVE);
88
        platform3 = new TestPlatform("Platform" + FILTEROUT);
89
        MockLookup.setInstances(
90
                AntBasedTestUtil.testAntBasedProjectType(),
91
                new PlatformFilterTest.TestPlatformProvider(
92
                    platform1,
93
                    platform2,
94
                    platform3
95
                ));
96
        clearWorkDir();
97
        final FileObject projectDir1 = FileUtil.createFolder(
98
                new File(getWorkDir(),"project1"));  //NOI18N
99
        prj1 = new PlatformFilterTest.MockProject(projectDir1);
100
        final FileObject projectDir2 = FileUtil.createFolder(
101
                new File(getWorkDir(),"project2"));  //NOI18N
102
        prj2 = new PlatformFilterTest.MockProjectExtended(projectDir2);
103
    }    
104
105
    public void testMockProject1() {
106
        Collection<JavaPlatform> platforms = prj1.getAvailablePlatforms();
107
        assertEquals(platforms.size(), 3);
108
        assertTrue(platforms.contains(platform1));
109
        assertTrue(platforms.contains(platform2));
110
        assertTrue(platforms.contains(platform3));
111
    }
112
    
113
    public void testMockProject2() {
114
        Collection<JavaPlatform> platforms = prj2.getAvailablePlatforms();
115
        assertEquals(platforms.size(), 2);
116
        assertTrue(platforms.contains(platform1));
117
        assertTrue(platforms.contains(platform2));
118
        assertFalse(platforms.contains(platform3));
119
    }
120
121
    private static class MockProject implements Project {
122
        
123
        private final FileObject projectDir;
124
        
125
        MockProject(final FileObject projectDir) {
126
            assert projectDir != null;
127
            this.projectDir = projectDir;
128
        }
129
        
130
        public Collection<JavaPlatform> getAvailablePlatforms() {
131
            List<JavaPlatform> result = new ArrayList<>();
132
            final Collection<? extends PlatformFilter> filters = getLookup().lookupAll(PlatformFilter.class);
133
            JavaPlatform[] platforms = TestPlatformProvider.getDefault().getInstalledPlatforms();
134
            if(platforms != null)  {
135
                for(int i = 0; i < platforms.length; i++) {
136
                    boolean accepted = true;
137
                    if(filters != null) {
138
                        for(PlatformFilter filter : filters) {
139
                            if(!filter.accept(platforms[i])) {
140
                                accepted = false;
141
                                break;
142
                            }
143
                        }
144
                    }
145
                    if(accepted) {
146
                        result.add(platforms[i]);
147
                    }
148
                }
149
            }
150
            return result;
151
        }
152
153
        @Override
154
        public FileObject getProjectDirectory() {
155
            return projectDir;
156
        }
157
158
        @Override
159
        public Lookup getLookup() {
160
            return Lookups.fixed(this);
161
        }        
162
        
163
    }
164
    
165
    private static class MockProjectExtended extends MockProject {
166
              
167
        MockProjectExtended(final FileObject projectDir) {
168
            super(projectDir);
169
        }
170
171
        @Override
172
        public Lookup getLookup() {
173
            return Lookups.fixed(this, getFilter());
174
        }        
175
176
        private PlatformFilter getFilter() {
177
            return new PlatformFilter() {
178
                @Override
179
                public boolean accept(JavaPlatform platform) {
180
                    return !platform.getDisplayName().endsWith(FILTEROUT);
181
                }
182
            };
183
        }
184
185
    }
186
    
187
    
188
    private static class TestPlatformProvider implements JavaPlatformProvider {
189
190
        private JavaPlatform[] platforms;
191
        
192
        public static JavaPlatformProvider getDefault() {
193
            return MockLookup.getDefault().lookup(JavaPlatformProvider.class);
194
        }
195
196
        public TestPlatformProvider(JavaPlatform... platforms) {
197
            if(platforms.length == 0) {
198
                this.platforms = new JavaPlatform[]{new TestPlatform("DefaultPlatform")};
199
            } else {
200
                this.platforms = platforms;
201
            }
202
        }
203
        
204
        @Override
205
        public void removePropertyChangeListener(PropertyChangeListener listener) {
206
        }
207
208
        @Override
209
        public void addPropertyChangeListener(PropertyChangeListener listener) {
210
        }
211
212
        @Override
213
        public JavaPlatform[] getInstalledPlatforms()  {
214
            return platforms;
215
        }
216
217
        @Override
218
        public JavaPlatform getDefaultPlatform()  {
219
            if (platforms.length == 0) {
220
                platforms = new JavaPlatform[]{new TestPlatform("DefaultPlatform")};
221
            }
222
            return platforms[0];
223
        }
224
    }
225
226
    private static class TestPlatform extends JavaPlatform {
227
228
        private String name;
229
        
230
        public TestPlatform(String name) {
231
            this.name = name;
232
        }
233
        
234
        @Override
235
        public FileObject findTool(String toolName) {
236
            return null;
237
        }
238
239
        @Override
240
        public String getVendor() {
241
            return "me";
242
        }
243
244
        @Override
245
        public ClassPath getStandardLibraries() {
246
            return ClassPathSupport.createClassPath(new URL[0]);
247
        }
248
249
        @Override
250
        public Specification getSpecification() {
251
            return new Specification("j2se", new SpecificationVersion("1.7"));
252
        }
253
254
        @Override
255
        public ClassPath getSourceFolders() {
256
            return null;
257
        }
258
259
        @Override
260
        public Map<String, String> getProperties() {
261
            return Collections.singletonMap("platform.ant.name", getDisplayName());
262
        }
263
264
        @Override
265
        public List<URL> getJavadocFolders() {
266
            return null;
267
        }
268
269
        @Override
270
        public Collection<FileObject> getInstallFolders() {
271
            return null;
272
        }
273
274
        @Override
275
        public String getDisplayName() {
276
            return name == null ? "DefaultTestPlatform" : name;
277
        }
278
279
        @Override
280
        public ClassPath getBootstrapLibraries() {
281
            return ClassPathSupport.createClassPath(new URL[0]);
282
        }
283
    }
284
}
(-)java.j2seproject/nbproject/project.xml (-1 / +1 lines)
 Lines 142-148    Link Here 
142
                    <compile-dependency/>
142
                    <compile-dependency/>
143
                    <run-dependency>
143
                    <run-dependency>
144
                        <release-version>0-1</release-version>
144
                        <release-version>0-1</release-version>
145
                        <specification-version>1.45</specification-version>
145
                        <specification-version>1.47</specification-version>
146
                    </run-dependency>
146
                    </run-dependency>
147
                </dependency>
147
                </dependency>
148
                <dependency>
148
                <dependency>
(-)java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java (-1 / +5 lines)
 Lines 58-63    Link Here 
58
import java.nio.charset.UnsupportedCharsetException;
58
import java.nio.charset.UnsupportedCharsetException;
59
import java.util.ArrayList;
59
import java.util.ArrayList;
60
import java.util.Arrays;
60
import java.util.Arrays;
61
import java.util.Collection;
61
import java.util.Collections;
62
import java.util.Collections;
62
import java.util.Comparator;
63
import java.util.Comparator;
63
import java.util.Enumeration;
64
import java.util.Enumeration;
 Lines 90-95    Link Here 
90
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport;
91
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport;
91
import org.netbeans.modules.java.api.common.project.ProjectProperties;
92
import org.netbeans.modules.java.api.common.project.ProjectProperties;
92
import org.netbeans.modules.java.api.common.project.ui.ClassPathUiSupport;
93
import org.netbeans.modules.java.api.common.project.ui.ClassPathUiSupport;
94
import org.netbeans.modules.java.api.common.ui.PlatformFilter;
93
import org.netbeans.modules.java.api.common.project.ui.customizer.ClassPathListCellRenderer;
95
import org.netbeans.modules.java.api.common.project.ui.customizer.ClassPathListCellRenderer;
94
import org.netbeans.modules.java.api.common.project.ui.customizer.SourceRootsUi;
96
import org.netbeans.modules.java.api.common.project.ui.customizer.SourceRootsUi;
95
import org.netbeans.modules.java.api.common.ui.PlatformUiSupport;
97
import org.netbeans.modules.java.api.common.ui.PlatformUiSupport;
 Lines 341-347    Link Here 
341
        RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_CLASSPATH)));
343
        RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_CLASSPATH)));
342
        RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_TEST_CLASSPATH)));
344
        RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.RUN_TEST_CLASSPATH)));
343
        ENDORSED_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.ENDORSED_CLASSPATH)));
345
        ENDORSED_CLASSPATH_MODEL = ClassPathUiSupport.createListModel(cs.itemsIterator(projectProperties.get(ProjectProperties.ENDORSED_CLASSPATH)));
344
        PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM));
346
        final Collection<? extends PlatformFilter> filters = project.getLookup().lookupAll(PlatformFilter.class);
347
        PLATFORM_MODEL = filters == null ? PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)) :
348
                PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM), filters);
345
        PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer();
349
        PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer();
346
        JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET));
350
        JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET));
347
        JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer ();
351
        JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer ();
(-)javafx2.project/nbproject/project.xml (-1 / +1 lines)
 Lines 73-79    Link Here 
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>0-1</release-version>
75
                        <release-version>0-1</release-version>
76
                        <specification-version>1.24</specification-version>
76
                        <specification-version>1.47</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
(-)javafx2.project/src/org/netbeans/modules/javafx2/project/JFXProjectPlatformFilter.java (+124 lines)
Added 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.javafx2.project;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.annotations.common.NullAllowed;
46
import org.netbeans.api.java.platform.JavaPlatform;
47
import org.netbeans.modules.java.api.common.ui.PlatformFilter;
48
import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator;
49
import org.netbeans.spi.project.ProjectServiceProvider;
50
import org.netbeans.spi.project.support.ant.EditableProperties;
51
import org.netbeans.spi.project.support.ant.PropertyUtils;
52
import org.openide.util.Lookup;
53
import org.openide.util.Parameters;
54
55
/**
56
 *
57
 * @author Petr Somol
58
 */
59
@ProjectServiceProvider(service=PlatformFilter.class, projectType={"org-netbeans-modules-java-j2seproject"}) // NOI18N
60
public class JFXProjectPlatformFilter implements PlatformFilter {
61
62
    private static final String PLATFORM_ANT_NAME = "platform.ant.name"; // NOI18N
63
    private static final String PLATFORM_PREFIX = "platforms"; // NOI18N
64
    private static final String JAVAFX_SDK_PREFIX = "javafx.sdk.home"; // NOI18N
65
    private static final String JAVAFX_RUNTIME_PREFIX = "javafx.runtime.home"; // NOI18N
66
67
    private final J2SEPropertyEvaluator eval;
68
69
    public JFXProjectPlatformFilter(Lookup lkp) {
70
        Parameters.notNull("lkp", lkp); //NOI18N
71
        this.eval = lkp.lookup(J2SEPropertyEvaluator.class);
72
        Parameters.notNull("eval", eval);   //NOI18N
73
    }
74
    
75
    @Override
76
    public boolean accept(final JavaPlatform platform) {
77
        if(platform != null) {
78
            if(isFXProject(eval)) {
79
                if(isJavaFXEnabled(platform)) {
80
                    return true;
81
                }
82
                return false;
83
            }
84
            return true;
85
        }
86
        return false;
87
    }
88
    
89
    /**
90
     * Determines whether given Java Platform supports JavaFX
91
     * (copied from JavaFXPlatformUtils to prevent load on startup)
92
     * 
93
     * @param IDE java platform instance
94
     * @return is JavaFX supported
95
     */
96
    private static boolean isJavaFXEnabled(@NonNull final JavaPlatform platform) {
97
        Parameters.notNull("platform", platform); // NOI18N
98
        String platformName = platform.getProperties().get(PLATFORM_ANT_NAME);
99
        EditableProperties properties = PropertyUtils.getGlobalProperties();
100
        String sdkPath = properties.get(PLATFORM_PREFIX + '.' + platformName + '.' + JAVAFX_SDK_PREFIX);
101
        String runtimePath = properties.get(PLATFORM_PREFIX + '.' + platformName + '.' + JAVAFX_RUNTIME_PREFIX);
102
        return sdkPath != null && runtimePath != null;
103
    }
104
105
    /**
106
     * Checks whether the project represented by its evaluator is a FX project
107
     * 
108
     * @param eval
109
     * @return 
110
     */
111
    private static boolean isFXProject(@NonNull final J2SEPropertyEvaluator eval) {
112
        //Don't use JFXProjectProperties.isTrue to prevent JFXProjectProperties from being loaded
113
        //JFXProjectProperties.JAVAFX_ENABLED is inlined by compliler
114
        return isTrue(eval.evaluator().getProperty(JFXProjectProperties.JAVAFX_ENABLED));
115
    }
116
117
    private static boolean isTrue(@NullAllowed final String value) {
118
        return  value != null && (
119
           "true".equalsIgnoreCase(value) ||    //NOI18N
120
           "yes".equalsIgnoreCase(value) ||     //NOI18N
121
           "on".equalsIgnoreCase(value));       //NOI18N
122
    }
123
124
}
(-)javafx2.project/src/org/netbeans/modules/javafx2/project/api/JavaFXProjectUtils.java (-1 / +11 lines)
 Lines 41-51    Link Here 
41
 */
41
 */
42
package org.netbeans.modules.javafx2.project.api;
42
package org.netbeans.modules.javafx2.project.api;
43
43
44
import java.util.Arrays;
44
import javax.swing.ComboBoxModel;
45
import javax.swing.ComboBoxModel;
45
import javax.swing.ListCellRenderer;
46
import javax.swing.ListCellRenderer;
46
import org.netbeans.api.java.platform.JavaPlatform;
47
import org.netbeans.api.java.platform.JavaPlatform;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.Project;
49
import org.netbeans.modules.java.api.common.ui.PlatformFilter;
48
import org.netbeans.modules.java.api.common.ui.PlatformUiSupport;
50
import org.netbeans.modules.java.api.common.ui.PlatformUiSupport;
51
import org.netbeans.modules.javafx2.platform.api.JavaFXPlatformUtils;
49
import org.netbeans.modules.javafx2.project.J2SEProjectType;
52
import org.netbeans.modules.javafx2.project.J2SEProjectType;
50
import org.netbeans.modules.javafx2.project.JFXProjectUtils;
53
import org.netbeans.modules.javafx2.project.JFXProjectUtils;
51
import org.netbeans.modules.javafx2.project.ui.PlatformsComboBoxModel;
54
import org.netbeans.modules.javafx2.project.ui.PlatformsComboBoxModel;
 Lines 53-58    Link Here 
53
/**
56
/**
54
 * 
57
 * 
55
 * @author Anton Chechel
58
 * @author Anton Chechel
59
 * @author Petr Somol
56
 */
60
 */
57
public final class JavaFXProjectUtils {
61
public final class JavaFXProjectUtils {
58
62
 Lines 67-73    Link Here 
67
    }
71
    }
68
72
69
    public static ComboBoxModel createPlatformComboBoxModel() {
73
    public static ComboBoxModel createPlatformComboBoxModel() {
70
        return new PlatformsComboBoxModel(PlatformUiSupport.createPlatformComboBoxModel("default_platform")); // NOI18N
74
        return new PlatformsComboBoxModel(PlatformUiSupport.createPlatformComboBoxModel("default_platform",  // NOI18N
75
                Arrays.<PlatformFilter>asList(new PlatformFilter() {
76
                    @Override
77
                    public boolean accept(JavaPlatform platform) {
78
                        return JavaFXPlatformUtils.isJavaFXEnabled(platform);
79
                    }                    
80
                })));
71
    }
81
    }
72
82
73
    public static ListCellRenderer createPlatformListCellRenderer() {
83
    public static ListCellRenderer createPlatformListCellRenderer() {

Return to bug 212238
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo