/projects/netbeans-7.3/web.jsf/src/org/netbeans/modules/web/jsf/wizards/JSFConfigurationPanelVisual.java
Java | 969 lines | 790 code | 94 blank | 85 comment | 140 complexity | dc9660eaed5c055bf21ff519cdcfcc77 MD5 | raw file
- /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
- *
- * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
- * Other names may be trademarks of their respective owners.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common
- * Development and Distribution License("CDDL") (collectively, the
- * "License"). You may not use this file except in compliance with the
- * License. You can obtain a copy of the License at
- * http://www.netbeans.org/cddl-gplv2.html
- * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
- * specific language governing permissions and limitations under the
- * License. When distributing the software, include this License Header
- * Notice in each file and include the License file at
- * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the GPL Version 2 section of the License file that
- * accompanied this code. If applicable, add the following below the
- * License Header, with the fields enclosed by brackets [] replaced by
- * your own identifying information:
- * "Portions Copyrighted [year] [name of copyright owner]"
- *
- * Contributor(s):
- *
- * The Original Software is NetBeans. The Initial Developer of the Original
- * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
- * Microsystems, Inc. All Rights Reserved.
- *
- * If you wish your version of this file to be governed by only the CDDL
- * or only the GPL Version 2, indicate your decision by adding
- * "[Contributor] elects to include this software in this distribution
- * under the [CDDL or GPL Version 2] license." If you do not indicate a
- * single choice of license, a recipient has the option to distribute
- * your version of this file under either the CDDL, the GPL Version 2 or
- * to extend the choice of license to its licensees as provided above.
- * However, if you add GPL Version 2 code and therefore, elected the GPL
- * Version 2 license, then the option applies only if the new code is
- * made subject to such option by the copyright holder.
- */
- package org.netbeans.modules.web.jsf.wizards;
- import java.awt.Component;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.File;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URI;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import java.util.Vector;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.util.regex.Pattern;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JFileChooser;
- import javax.swing.JTable;
- import javax.swing.ListSelectionModel;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import javax.swing.event.DocumentListener;
- import javax.swing.event.TableModelEvent;
- import javax.swing.event.TableModelListener;
- import javax.swing.filechooser.FileFilter;
- import javax.swing.table.AbstractTableModel;
- import javax.swing.table.DefaultTableCellRenderer;
- import javax.swing.table.TableCellRenderer;
- import org.netbeans.api.annotations.common.CheckForNull;
- import org.netbeans.api.j2ee.core.Profile;
- import org.netbeans.api.java.classpath.ClassPath;
- import org.netbeans.api.project.FileOwnerQuery;
- import org.netbeans.api.project.Project;
- import org.netbeans.api.project.libraries.Library;
- import org.netbeans.api.project.libraries.LibraryManager;
- import org.netbeans.modules.j2ee.common.Util;
- import org.netbeans.modules.j2ee.deployment.common.api.ConfigurationException;
- import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
- import org.netbeans.modules.j2ee.deployment.common.api.Version;
- import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
- import org.netbeans.modules.j2ee.deployment.devmodules.api.InstanceRemovedException;
- import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
- import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerInstance;
- import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
- import org.netbeans.modules.j2ee.deployment.plugins.api.ServerLibrary;
- import org.netbeans.modules.j2ee.deployment.plugins.api.ServerLibraryDependency;
- import org.netbeans.modules.web.api.webmodule.ExtenderController;
- import org.netbeans.modules.web.api.webmodule.ExtenderController.Properties;
- import org.netbeans.modules.web.jsf.JSFUtils;
- import org.netbeans.modules.web.jsf.api.facesmodel.JSFVersion;
- import org.netbeans.modules.web.jsf.spi.components.JsfComponentCustomizer;
- import org.netbeans.modules.web.jsf.spi.components.JsfComponentImplementation;
- import org.netbeans.modules.web.jsf.spi.components.JsfComponentProvider;
- import org.netbeans.modules.web.jsf.wizards.JSFConfigurationPanel.LibraryType;
- import org.netbeans.modules.web.jsf.wizards.JSFConfigurationPanel.PreferredLanguage;
- import org.netbeans.spi.java.classpath.ClassPathProvider;
- import org.openide.DialogDescriptor;
- import org.openide.DialogDisplayer;
- import org.openide.WizardDescriptor;
- import org.openide.filesystems.URLMapper;
- import org.openide.util.*;
- import org.openide.util.lookup.Lookups;
- /**
- *
- * @author Petr Pisl, Radko Najman, alexeybutenko, Martin Fousek
- */
- public class JSFConfigurationPanelVisual extends javax.swing.JPanel implements HelpCtx.Provider, DocumentListener {
- private static final RequestProcessor RP = new RequestProcessor("JSF worker", 1);
- private static final Logger LOG = Logger.getLogger(JSFConfigurationPanelVisual.class.getName());
- private static final String JSF_SERVLET_NAME="Faces Servlet"; //NOI18N
- private String jsfServletName=null;
- private JSFConfigurationPanel panel;
- private boolean isFrameworkAddition;
- private boolean inCustomizer;
- private final List<LibraryItem> jsfLibraries = new ArrayList<LibraryItem>();
- // private final List<JsfComponentDescriptor> componentsLibraries = new ArrayList<JsfComponentDescriptor>();
- private final Map<JSFVersion, List<JsfComponentImplementation>> componentsMap = new HashMap<JSFVersion, List<JsfComponentImplementation>>();
- /**
- * Do not modify it directly, use setJsfVersion method
- */
- private JSFVersion currentJSFVersion = null;
- private final Set<ServerLibraryItem> serverJsfLibraries = new TreeSet<ServerLibraryItem>();
- private volatile boolean libsInitialized;
- private volatile boolean jsfComponentsInitialized;
- private String serverInstanceID;
- private final List<PreferredLanguage> preferredLanguages = new ArrayList<PreferredLanguage>();
- private String currentServerInstanceID;
- private boolean isWebLogicServer = false;
- // Jsf component libraries related
- private JSFComponentsTableModel jsfComponentsTableModel;
- private TreeMap<String, JsfComponentCustomizer> jsfComponentCustomizers = new TreeMap<String, JsfComponentCustomizer>();
- private static final Collection<? extends JsfComponentProvider> jsfComponentProviders =
- new ArrayList<JsfComponentProvider>(Lookups.forPath(JsfComponentProvider.COMPONENTS_PATH).
- lookupResult(JsfComponentProvider.class).allInstances());
- private final ChangeSupport changeSupport = new ChangeSupport(this);
- /** Libraries excluded from panel's {@link #jsfLibraries}. Libraries offered as registered in the IDE. */
- private static final Set<String> EXCLUDE_FROM_REGISTERED_LIBS = new HashSet<String>(Arrays.asList(
- "javaee-web-api-6.0", //NOI18N
- "javaee-api-6.0", //NOI18N
- "jsp-compilation", //NOI18N
- "jsp-compilation-syscp", //NOI18N
- "javaee-api-5.0")); //NOI18N
- /**
- * Creates new form JSFConfigurationPanelVisual.
- * @param panel panel to which is this visual component binded
- * @param isFrameworkAddition {@code true} if it's addition of JSF framework, {@code false} otherwise
- * @param inCustomizer {@code true} if the panel is called in customizer, {@code false} otherwise
- */
- public JSFConfigurationPanelVisual(JSFConfigurationPanel panel, boolean isFrameworkAddition, boolean inCustomizer) {
- this.panel = panel;
- this.isFrameworkAddition = isFrameworkAddition;
- this.inCustomizer = inCustomizer;
- this.jsfComponentsTableModel = new JSFComponentsTableModel();
- initComponents();
- tURLPattern.getDocument().addDocumentListener(this);
- cbPackageJars.setVisible(false);
- // update JSF components list
- jsfComponentsTable.setModel(jsfComponentsTableModel);
- JsfComponentsTableCellRenderer renderer = new JsfComponentsTableCellRenderer();
- renderer.setBooleanRenderer(jsfComponentsTable.getDefaultRenderer(Boolean.class));
- renderer.setJButtonRenderer(new JTableButtonRenderer());
- jsfComponentsTable.setDefaultRenderer(JsfComponentImplementation.class, renderer);
- jsfComponentsTable.setDefaultRenderer(Boolean.class, renderer);
- jsfComponentsTable.setDefaultRenderer(JButton.class, renderer);
- jsfComponentsTable.addMouseListener(new JsfComponentsMouseListener());
- jsfComponentsTableModel.addTableModelListener(new JsfComponentsTableModelListener());
- initJsfComponentTableVisualProperties(jsfComponentsTable);
- panel.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- changeSupport.fireChange();
- }
- });
- }
- @Override
- public void addNotify() {
- super.addNotify();
- initLibraries();
- initJsfComponentsLibraries();
- // in customizer preselected included JSF library
- if (!isFrameworkAddition) {
- preselectJsfLibrary();
- }
- if (!isFrameworkAddition) {
- enableComponents(false);
- } else {
- updateLibrary();
- }
- }
- private void preselectJsfLibrary() {
- Runnable jsfLibararyUiSwitcher = new Runnable() {
- @Override
- public void run() {
- // searching in IDE registered JSF libraries
- Project project = FileOwnerQuery.getOwner(panel.getWebModule().getDocumentBase());
- ClassPathProvider cpp = project.getLookup().lookup(ClassPathProvider.class);
- ClassPath compileClassPath = cpp.findClassPath(panel.getWebModule().getDocumentBase(), ClassPath.COMPILE);
- compileClassPath.entries();
- for (ClassPath.Entry entry : compileClassPath.entries()) {
- for (final LibraryItem jsfLibrary : jsfLibraries) {
- try {
- List<URI> cps = jsfLibrary.getLibrary().getURIContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH);
- for (URI uri : cps) {
- if (entry.getRoot() != null
- && entry.getRoot().equals(URLMapper.findFileObject(uri.toURL()))) {
- Mutex.EVENT.readAccess(new Runnable() {
- @Override
- public void run() {
- rbRegisteredLibrary.setSelected(true);
- enableComponents(false);
- cbLibraries.setSelectedItem(jsfLibrary.getLibrary().getDisplayName());
- }
- });
- return;
- }
- }
- } catch (MalformedURLException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- }
- // searching in server registered JSF libraries
- J2eeModuleProvider jmp = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class);
- Set<ServerLibraryDependency> deps = getServerDependencies(jmp);
- for (ServerLibraryDependency serverLibraryDependency : deps) {
- if (serverLibraryDependency.getName().startsWith("jsf")) { //NOI18N
- ServerLibraryItem candidate = null;
- for (final ServerLibraryItem serverLibraryItem : serverJsfLibraries) {
- if (serverLibraryItem.getLibrary() != null) {
- Version implVersion = serverLibraryItem.getLibrary().getImplementationVersion();
- Version specVersion = serverLibraryItem.getLibrary().getSpecificationVersion();
- if ((implVersion != null && implVersion.equals(serverLibraryDependency.getImplementationVersion()))
- || specVersion != null && specVersion.equals(serverLibraryDependency.getSpecificationVersion())) {
- selectServerLibraryItem(serverLibraryItem);
- return;
- }
- } else {
- // IDE didn't recognize library correctly
- candidate = serverLibraryItem;
- }
- }
- if (candidate != null) {
- selectServerLibraryItem(candidate);
- }
- }
- }
- }
- private void selectServerLibraryItem(final ServerLibraryItem item) {
- Mutex.EVENT.readAccess(new Runnable() {
- @Override
- public void run() {
- rbServerLibrary.setSelected(true);
- enableComponents(false);
- serverLibraries.setSelectedItem(item);
- }
- });
- }
- };
- RP.post(jsfLibararyUiSwitcher);
- }
- private static Set<ServerLibraryDependency> getServerDependencies(J2eeModuleProvider jmp) {
- try {
- return jmp.getConfigSupport().getLibraries();
- } catch (ConfigurationException e) {
- return Collections.emptySet();
- }
- }
- public void addChangeListener(ChangeListener listener) {
- changeSupport.addChangeListener(listener);
- }
- public void removeChangeListener(ChangeListener listener) {
- changeSupport.removeChangeListener(listener);
- }
- void initLibraries() {
- long time = System.currentTimeMillis();
- if (libsInitialized) {
- return;
- }
- // init server libraries first
- initServerLibraries(false);
- final Vector<String> registeredItems = new Vector<String>();
- jsfLibraries.clear();
- final Runnable libraryFinder = new Runnable() {
- @Override
- public void run() {
- synchronized (this) {
- long time = System.currentTimeMillis();
- List<URL> content;
- for (Library library : LibraryManager.getDefault().getLibraries()) {
- if (!"j2se".equals(library.getType())) { // NOI18N
- continue;
- }
- if (library.getName().startsWith("facelets-") && !library.getName().endsWith("el-api") //NOI18N
- && !library.getName().endsWith("jsf-ri") && !library.getName().endsWith("myfaces")) { //NOI18N
- String displayName = library.getDisplayName();
- registeredItems.add(displayName);
- //TODO XX Add correct version
- jsfLibraries.add(new LibraryItem(library, JSFVersion.JSF_1_2));
- }
- content = library.getContent("classpath"); //NOI18N
- try {
- if (Util.containsClass(content, JSFUtils.FACES_EXCEPTION)
- && !EXCLUDE_FROM_REGISTERED_LIBS.contains(library.getName())) {
- registeredItems.add(library.getDisplayName());
- boolean isJSF12 = Util.containsClass(content, JSFUtils.JSF_1_2__API_SPECIFIC_CLASS);
- boolean isJSF20 = Util.containsClass(content, JSFUtils.JSF_2_0__API_SPECIFIC_CLASS);
- boolean isJSF21 = Util.containsClass(content, JSFUtils.JSF_2_1__API_SPECIFIC_CLASS);
- if (isJSF21) {
- jsfLibraries.add(new LibraryItem(library, JSFVersion.JSF_2_1));
- } else if (isJSF20) {
- jsfLibraries.add(new LibraryItem(library, JSFVersion.JSF_2_0));
- } else if (isJSF12) {
- jsfLibraries.add(new LibraryItem(library, JSFVersion.JSF_1_2));
- } else {
- jsfLibraries.add(new LibraryItem(library, JSFVersion.JSF_1_1));
- }
- }
- } catch (IOException exception) {
- LOG.log(Level.INFO, "", exception);
- }
- }
- // if maven, exclude user defined libraries
- if (panel.isMaven()) {
- removeUserDefinedLibraries(registeredItems);
- }
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- setRegisteredLibraryModel(registeredItems);
- updatePreferredLanguages();
- updateJsfComponents();
- }
- });
- LOG.log(Level.FINEST, "Time spent in initLibraries in Runnable = {0} ms", (System.currentTimeMillis()-time)); //NOI18N
- }
- }
- };
- RP.post(libraryFinder);
- libsInitialized = true;
- // repaint();
- LOG.log(Level.FINEST, "Time spent in {0} initLibraries = {1} ms", new Object[]{this.getClass().getName(), System.currentTimeMillis()-time}); //NOI18N
- }
- private void initJsfComponentsLibraries() {
- if (jsfComponentsInitialized)
- return;
- List<JsfComponentImplementation> jsfComponentDescriptors = new ArrayList<JsfComponentImplementation>();
- for (JsfComponentProvider provider: jsfComponentProviders) {
- jsfComponentDescriptors.addAll(provider.getJsfComponents());
- }
- for (JSFVersion jsfVersion : JSFVersion.values()) {
- List<JsfComponentImplementation> list = componentsMap.get(jsfVersion);
- if (list == null) {
- list = new ArrayList<JsfComponentImplementation>();
- componentsMap.put(jsfVersion, list);
- }
- for (JsfComponentImplementation jsfImplementation : jsfComponentDescriptors) {
- if (jsfImplementation.getJsfVersion().contains(jsfVersion)) {
- list.add(jsfImplementation);
- }
- }
- }
- jsfComponentsInitialized = true;
- if (currentJSFVersion != null) {
- updateJsfComponentsModel(currentJSFVersion);
- }
- }
- private void removeUserDefinedLibraries(Vector<String> registeredItems) {
- for (LibraryItem item : jsfLibraries) {
- Map<String, String> properties = item.getLibrary().getProperties();
- if (!properties.containsKey("maven-dependencies") //NOI18N
- || properties.get("maven-dependencies").trim().isEmpty()) { //NOI18N
- registeredItems.remove(item.getLibrary().getDisplayName());
- }
- }
- }
- private void initServerLibraries(boolean updateUI) {
- serverJsfLibraries.clear();
- synchronized (this) {
- Set<JSFVersion> found = new HashSet<JSFVersion>();
- if (isServerRegistered(serverInstanceID)) {
- try {
- ServerInstance.LibraryManager libManager = Deployment.getDefault().getServerInstance(serverInstanceID).getLibraryManager();
- if (libManager != null) {
- Set<ServerLibrary> libs = new HashSet<ServerLibrary>();
- libs.addAll(libManager.getDeployedLibraries());
- libs.addAll(libManager.getDeployableLibraries());
- for (ServerLibrary lib : libs) {
- // FIXME optimize
- if ("JavaServer Faces".equals(lib.getSpecificationTitle())) { // NOI18N
- if (Version.fromJsr277NotationWithFallback("2.1").equals(lib.getSpecificationVersion())) { //NOI18N
- serverJsfLibraries.add(new ServerLibraryItem(lib, JSFVersion.JSF_2_1));
- found.add(JSFVersion.JSF_2_1);
- } else if (Version.fromJsr277NotationWithFallback("2.0").equals(lib.getSpecificationVersion())) { // NOI18N
- serverJsfLibraries.add(new ServerLibraryItem(lib, JSFVersion.JSF_2_0));
- found.add(JSFVersion.JSF_2_0);
- } else if (Version.fromJsr277NotationWithFallback("1.2").equals(lib.getSpecificationVersion())) { // NOI18N
- serverJsfLibraries.add(new ServerLibraryItem(lib, JSFVersion.JSF_1_2));
- found.add(JSFVersion.JSF_1_2);
- } else if (Version.fromJsr277NotationWithFallback("1.1").equals(lib.getSpecificationVersion())) { // NOI18N
- serverJsfLibraries.add(new ServerLibraryItem(lib, JSFVersion.JSF_1_1));
- found.add(JSFVersion.JSF_1_1);
- } else {
- LOG.log(Level.INFO, "Unknown JSF version {0}", lib.getSpecificationVersion());
- }
- }
- }
- }
- } catch (InstanceRemovedException ex) {
- LOG.log(Level.INFO, null, ex);
- // use the old way
- }
- }
- File[] cp;
- J2eePlatform platform = null;
- try {
- if (isServerRegistered(serverInstanceID)) { //NOI18N
- platform = Deployment.getDefault().getServerInstance(serverInstanceID).getJ2eePlatform();
- }
- } catch (InstanceRemovedException ex) {
- platform = null;
- LOG.log(Level.INFO, org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "SERVER_INSTANCE_REMOVED"), ex);
- }
- // j2eeplatform can be null, when the target server is not accessible.
- if (platform != null) {
- cp = platform.getClasspathEntries();
- } else {
- cp = new File[0];
- }
- try {
- // XXX: there should be a utility class for this:
- boolean isJSF = Util.containsClass(Arrays.asList(cp), JSFUtils.FACES_EXCEPTION);
- boolean isJSF12 = Util.containsClass(Arrays.asList(cp), JSFUtils.JSF_1_2__API_SPECIFIC_CLASS);
- boolean isJSF20 = Util.containsClass(Arrays.asList(cp), JSFUtils.JSF_2_0__API_SPECIFIC_CLASS);
- boolean isJSF21 = Util.containsClass(Arrays.asList(cp), JSFUtils.JSF_2_1__API_SPECIFIC_CLASS);
- JSFVersion jsfVersion = null;
- if (isJSF21) {
- jsfVersion = JSFVersion.JSF_2_1;
- } else if (isJSF20) {
- jsfVersion = JSFVersion.JSF_2_0;
- } else if (isJSF12) {
- jsfVersion = JSFVersion.JSF_1_2;
- } else if (isJSF) {
- jsfVersion = JSFVersion.JSF_1_1;
- }
- if (jsfVersion != null && !found.contains(jsfVersion)) {
- serverJsfLibraries.add(new ServerLibraryItem(null, jsfVersion));
- }
- } catch (IOException ex) {
- LOG.log(Level.INFO, "", ex);
- }
- setServerLibraryModel(serverJsfLibraries);
- if (updateUI) {
- //updatePreferredLanguages();
- }
- }
- }
- private static boolean isServerRegistered(String serverInstanceID) {
- if (serverInstanceID != null && !"".equals(serverInstanceID) && !"DEV-NULL".equals(serverInstanceID)) {
- return true;
- }
- return false;
- }
- private void setRegisteredLibraryModel(Vector<String> items) {
- long time = System.currentTimeMillis();
- cbLibraries.setModel(new DefaultComboBoxModel(items));
- if (items.size() == 0) {
- rbRegisteredLibrary.setEnabled(false);
- cbLibraries.setEnabled(false);
- rbNewLibrary.setSelected(true);
- panel.setLibrary((Library) null);
- } else if (items.size() != 0 && panel.getLibraryType() == LibraryType.USED){
- if (isFrameworkAddition) {
- rbRegisteredLibrary.setEnabled(true);
- cbLibraries.setEnabled(true);
- }
- rbRegisteredLibrary.setSelected(true);
- if (jsfLibraries.size() > 0){
- panel.setLibrary(jsfLibraries.get(cbLibraries.getSelectedIndex()).getLibrary());
- setJsfVersion(jsfLibraries.get(cbLibraries.getSelectedIndex()).getVersion());
- }
- }
- // libsInitialized = true;
- repaint();
- LOG.finest("Time spent in "+this.getClass().getName() +" setLibraryModel = "+(System.currentTimeMillis()-time) +" ms"); //NOI18N
- }
- private void setServerLibraryModel(Collection<ServerLibraryItem> items) {
- serverLibraries.setModel(new DefaultComboBoxModel(items.toArray()));
- if (items.isEmpty()) {
- rbServerLibrary.setEnabled(false);
- serverLibraries.setEnabled(false);
- rbRegisteredLibrary.setSelected(true);
- panel.setServerLibrary((ServerLibrary) null);
- } else if (!items.isEmpty() && panel.getLibraryType() == LibraryType.SERVER){
- if (isFrameworkAddition) {
- rbServerLibrary.setEnabled(true);
- serverLibraries.setEnabled(true);
- }
- rbServerLibrary.setSelected(true);
- if (!serverJsfLibraries.isEmpty()) {
- ServerLibraryItem item = (ServerLibraryItem) serverLibraries.getSelectedItem();
- if (item != null) {
- panel.setServerLibrary(item.getLibrary());
- setJsfVersion(item.getVersion());
- }
- }
- }
- repaint();
- }
- /**
- * Init Preferred Languages check box with "JSP" and/or "Facelets"
- * according to choosen library
- */
- private void updatePreferredLanguages() {
- boolean faceletsPresent = false;
- Library jsfLibrary = null;
- LibraryType libraryType = panel.getLibraryType();
- if (libraryType == null) {
- return;
- }
- if (libraryType == LibraryType.USED) {
- if (!libsInitialized) {
- initLibraries();
- }
- jsfLibrary = panel.getLibrary();
- } else if (libraryType == LibraryType.NEW) {
- if (panel.getNewLibraryName() != null) {
- jsfLibrary = LibraryManager.getDefault().getLibrary(panel.getNewLibraryName());
- }
- } else if (libraryType == LibraryType.SERVER) {
- //XXX: need to find lib version
- ServerLibraryItem item = (ServerLibraryItem) serverLibraries.getSelectedItem();
- if (item != null
- && (item.getVersion() == JSFVersion.JSF_2_0 || item.getVersion() == JSFVersion.JSF_2_1)) {
- faceletsPresent = true;
- }
- }
- if (jsfLibrary != null) {
- if (jsfLibraries.get(cbLibraries.getSelectedIndex()).getVersion() == JSFVersion.JSF_2_0
- || jsfLibraries.get(cbLibraries.getSelectedIndex()).getVersion() == JSFVersion.JSF_2_1) {
- faceletsPresent = true;
- } else {
- List<URL> content = jsfLibrary.getContent("classpath"); //NOI18N
- try {
- faceletsPresent = Util.containsClass(content, "com.sun.facelets.Facelet") || //NOI18N
- Util.containsClass(content, "com.sun.faces.facelets.Facelet"); //NOI18N
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- preferredLanguages.clear();
- preferredLanguages.add(PreferredLanguage.JSP);
- if (faceletsPresent) {
- if (isFrameworkAddition) {
- panel.setEnableFacelets(true);
- }
- if (panel.isEnableFacelets()) {
- preferredLanguages.add(0, PreferredLanguage.Facelets);
- } else {
- preferredLanguages.add(PreferredLanguage.Facelets);
- }
- } else {
- panel.setEnableFacelets(false);
- }
- cbPreferredLang.setModel(new DefaultComboBoxModel(preferredLanguages.toArray()));
- repaint();
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- jsfTabbedPane = new javax.swing.JTabbedPane();
- libPanel = new javax.swing.JPanel();
- rbServerLibrary = new javax.swing.JRadioButton();
- rbRegisteredLibrary = new javax.swing.JRadioButton();
- cbLibraries = new javax.swing.JComboBox();
- rbNewLibrary = new javax.swing.JRadioButton();
- lDirectory = new javax.swing.JLabel();
- customBundleTextField = new javax.swing.JTextField();
- jbBrowse = new javax.swing.JButton();
- lVersion = new javax.swing.JLabel();
- jtNewLibraryName = new javax.swing.JTextField();
- serverLibraries = new javax.swing.JComboBox();
- cbPackageJars = new javax.swing.JCheckBox();
- confPanel = new javax.swing.JPanel();
- lURLPattern = new javax.swing.JLabel();
- tURLPattern = new javax.swing.JTextField();
- cbPreferredLang = new javax.swing.JComboBox();
- jLabel1 = new javax.swing.JLabel();
- componentsPanel = new javax.swing.JPanel();
- jsfComponentsLabel = new javax.swing.JLabel();
- jsfComponentsScrollPane = new javax.swing.JScrollPane();
- jsfComponentsTable = new javax.swing.JTable();
- setLayout(new java.awt.CardLayout());
- jsfTabbedPane.setMinimumSize(new java.awt.Dimension(106, 62));
- jsfTabbedPane.setPreferredSize(new java.awt.Dimension(483, 210));
- libPanel.setAlignmentX(0.2F);
- libPanel.setAlignmentY(0.2F);
- buttonGroup1.add(rbServerLibrary);
- rbServerLibrary.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_rbNoAppend").charAt(0));
- java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle"); // NOI18N
- rbServerLibrary.setText(bundle.getString("LBL_Any_Library")); // NOI18N
- rbServerLibrary.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- rbServerLibraryItemStateChanged(evt);
- }
- });
- buttonGroup1.add(rbRegisteredLibrary);
- rbRegisteredLibrary.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_rbRegLibs").charAt(0));
- rbRegisteredLibrary.setSelected(true);
- rbRegisteredLibrary.setText(bundle.getString("LBL_REGISTERED_LIBRARIES")); // NOI18N
- rbRegisteredLibrary.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- rbRegisteredLibraryItemStateChanged(evt);
- }
- });
- cbLibraries.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Search Libraries..." }));
- cbLibraries.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cbLibrariesActionPerformed(evt);
- }
- });
- buttonGroup1.add(rbNewLibrary);
- rbNewLibrary.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_rbCrNewLib").charAt(0));
- rbNewLibrary.setText(bundle.getString("LBL_CREATE_NEW_LIBRARY")); // NOI18N
- rbNewLibrary.setToolTipText(bundle.getString("MSG_CreatingLibraries")); // NOI18N
- rbNewLibrary.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- rbNewLibraryItemStateChanged(evt);
- }
- });
- lDirectory.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_lJSFDir").charAt(0));
- lDirectory.setLabelFor(customBundleTextField);
- lDirectory.setText(bundle.getString("LBL_INSTALL_DIR")); // NOI18N
- lDirectory.setToolTipText(bundle.getString("HINT_JSF_Directory")); // NOI18N
- customBundleTextField.setToolTipText(bundle.getString("HINT_JSF_Directory")); // NOI18N
- customBundleTextField.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- customBundleTextFieldKeyPressed(evt);
- }
- });
- jbBrowse.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_Browse").charAt(0));
- jbBrowse.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_Browse")); // NOI18N
- jbBrowse.setToolTipText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "HINT_JSF_BROWSE_BTN")); // NOI18N
- jbBrowse.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jbBrowseActionPerformed(evt);
- }
- });
- lVersion.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_lJSFVer").charAt(0));
- lVersion.setLabelFor(jtNewLibraryName);
- lVersion.setText(bundle.getString("LBL_VERSION")); // NOI18N
- lVersion.setToolTipText(bundle.getString("HINT_Version")); // NOI18N
- jtNewLibraryName.setToolTipText(bundle.getString("HINT_Version")); // NOI18N
- jtNewLibraryName.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyReleased(java.awt.event.KeyEvent evt) {
- jtNewLibraryNameKeyReleased(evt);
- }
- });
- serverLibraries.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- serverLibrariesActionPerformed(evt);
- }
- });
- cbPackageJars.setSelected(true);
- cbPackageJars.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "CB_Package_JARs")); // NOI18N
- javax.swing.GroupLayout libPanelLayout = new javax.swing.GroupLayout(libPanel);
- libPanel.setLayout(libPanelLayout);
- libPanelLayout.setHorizontalGroup(
- libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(libPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(rbNewLibrary, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
- .addGroup(libPanelLayout.createSequentialGroup()
- .addGap(22, 22, 22)
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(cbPackageJars)
- .addComponent(lVersion)
- .addComponent(lDirectory))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 206, Short.MAX_VALUE))
- .addGroup(libPanelLayout.createSequentialGroup()
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(rbServerLibrary, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(rbRegisteredLibrary, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(cbLibraries, 0, 316, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libPanelLayout.createSequentialGroup()
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jtNewLibraryName, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
- .addComponent(customBundleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jbBrowse))
- .addComponent(serverLibraries, 0, 295, Short.MAX_VALUE))))
- .addContainerGap())
- );
- libPanelLayout.setVerticalGroup(
- libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(rbServerLibrary)
- .addComponent(serverLibraries, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(rbRegisteredLibrary)
- .addComponent(cbLibraries, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(rbNewLibrary)
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jbBrowse)
- .addComponent(customBundleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(lDirectory))
- .addGroup(libPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jtNewLibraryName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(lVersion))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(cbPackageJars)
- .addContainerGap(22, Short.MAX_VALUE))
- );
- cbPackageJars.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_PackageJarToWar")); // NOI18N
- jsfTabbedPane.addTab(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_TAB_Libraries"), libPanel); // NOI18N
- lURLPattern.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_lURLPattern").charAt(0));
- lURLPattern.setLabelFor(tURLPattern);
- lURLPattern.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_URL_Pattern")); // NOI18N
- tURLPattern.setText(panel.getFacesMapping());
- cbPreferredLang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- cbPreferredLang.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cbPreferredLangActionPerformed(evt);
- }
- });
- jLabel1.setLabelFor(cbPreferredLang);
- jLabel1.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_PREFERRED_LANGUAGE")); // NOI18N
- javax.swing.GroupLayout confPanelLayout = new javax.swing.GroupLayout(confPanel);
- confPanel.setLayout(confPanelLayout);
- confPanelLayout.setHorizontalGroup(
- confPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(confPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(confPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(confPanelLayout.createSequentialGroup()
- .addComponent(lURLPattern)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(tURLPattern, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))
- .addGroup(confPanelLayout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(cbPreferredLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- );
- confPanelLayout.setVerticalGroup(
- confPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(confPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(confPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(lURLPattern)
- .addComponent(tURLPattern, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(33, 33, 33)
- .addGroup(confPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(cbPreferredLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(98, 98, 98))
- );
- tURLPattern.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_Mapping")); // NOI18N
- jsfTabbedPane.addTab(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_TAB_Configuration"), confPanel); // NOI18N
- jsfComponentsLabel.setText(getJsfComponentsLabelText());
- jsfComponentsTable.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jsfComponentsScrollPane.setViewportView(jsfComponentsTable);
- javax.swing.GroupLayout componentsPanelLayout = new javax.swing.GroupLayout(componentsPanel);
- componentsPanel.setLayout(componentsPanelLayout);
- componentsPanelLayout.setHorizontalGroup(
- componentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(componentsPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(componentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jsfComponentsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
- .addComponent(jsfComponentsLabel))
- .addContainerGap())
- );
- componentsPanelLayout.setVerticalGroup(
- componentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(componentsPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jsfComponentsLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jsfComponentsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
- .addContainerGap())
- );
- jsfTabbedPane.addTab(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_TAB_Components"), componentsPanel); // NOI18N
- add(jsfTabbedPane, "card10");
- jsfTabbedPane.getAccessibleContext().setAccessibleName("");
- }// </editor-fold>//GEN-END:initComponents
- private void rbServerLibraryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbServerLibraryItemStateChanged
- updateLibrary();
- if (rbServerLibrary.isSelected()) {
- panel.fireChangeEvent();
- }
- }//GEN-LAST:event_rbServerLibraryItemStateChanged
- private void jtNewLibraryNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtNewLibraryNameKeyReleased
- panel.setNewLibraryName(jtNewLibraryName.getText().trim());
- }//GEN-LAST:event_jtNewLibraryNameKeyReleased
- private void rbNewLibraryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbNewLibraryItemStateChanged
- updateLibrary();
- if (rbNewLibrary.isSelected()) {
- panel.fireChangeEvent();
- }
- }//GEN-LAST:event_rbNewLibraryItemStateChanged
- private void cbLibrariesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbLibrariesActionPerformed
- panel.setLibrary(jsfLibraries.get(cbLibraries.getSelectedIndex()).getLibrary());
- setJsfVersion(jsfLibraries.get(cbLibraries.getSelectedIndex()).getVersion());
- updatePreferredLanguages();
- }//GEN-LAST:event_cbLibrariesActionPerformed
- private void rbRegisteredLibraryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbRegisteredLibraryItemStateChanged
- updateLibrary();
- if (rbRegisteredLibrary.isSelected()) {
- panel.fireChangeEvent();
- }
- }//GEN-LAST:event_rbRegisteredLibraryItemStateChanged
- private void jbBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBrowseActionPerformed
- JFileChooser chooser = new JFileChooser();
- chooser.setDialogTitle(NbBundle.getMessage(JSFConfigurationPanelVisual.class,"LBL_SelectLibraryLocation")); //NOI18N
- chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- chooser.setFileFilter(new FileFilter() {
- @Override
- public boolean accept(File f) {
- if (f.getName().endsWith(".jar") || f.isDirectory()) { //N0I18N
- return true;
- }
- return false;
- }
- @Override
- public String getDescription() {
- return NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_FileTypeInChooser"); //NOI18N
- }
- });
- chooser.setCurrentDirectory(new File(customBundleTextField.getText().trim()));
- if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
- File selectedEntry = chooser.getSelectedFile();
- customBundleTextField.setText(selectedEntry.getAbsolutePath());
- setN