/projects/netbeans-7.3/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java
Java | 1031 lines | 835 code | 91 blank | 105 comment | 145 complexity | 8a8265278d05b4efa49aa204ce28a0cf 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-2006 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.apisupport.project.ui.customizer;
- import java.io.CharConversionException;
- import javax.swing.Action;
- import javax.swing.table.TableColumn;
- import org.netbeans.modules.apisupport.project.universe.ClusterUtils;
- import java.awt.EventQueue;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyEditor;
- import java.io.File;
- import java.io.IOException;
- import java.lang.reflect.InvocationTargetException;
- import java.text.Collator;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.MissingResourceException;
- import java.util.Set;
- import java.util.SortedMap;
- import java.util.SortedSet;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import java.util.jar.Manifest;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.ListSelectionModel;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import org.netbeans.api.annotations.common.NullAllowed;
- import org.netbeans.api.java.platform.JavaPlatform;
- import org.netbeans.api.java.platform.PlatformsCustomizer;
- import org.netbeans.api.project.Project;
- import org.netbeans.api.project.ProjectManager;
- import org.netbeans.api.project.ProjectUtils;
- import org.netbeans.modules.apisupport.project.ApisupportAntUtils;
- import org.netbeans.modules.apisupport.project.api.ManifestManager;
- import org.netbeans.modules.apisupport.project.NbModuleProject;
- import org.netbeans.modules.apisupport.project.NbModuleType;
- import org.netbeans.modules.apisupport.project.SuiteProvider;
- import org.netbeans.modules.apisupport.project.api.UIUtil;
- import org.netbeans.modules.apisupport.project.api.Util;
- import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
- import org.netbeans.modules.apisupport.project.suite.SuiteProject;
- import org.netbeans.modules.apisupport.project.ui.ApisupportAntUIUtils;
- import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory;
- import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer;
- import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
- import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo.Provider;
- import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
- import org.netbeans.modules.apisupport.project.universe.ModuleList;
- import org.netbeans.modules.apisupport.project.universe.NbPlatform;
- import org.netbeans.modules.apisupport.project.universe.HarnessVersion;
- import org.netbeans.spi.project.ui.support.ProjectCustomizer;
- import org.netbeans.swing.outline.Outline;
- import org.openide.DialogDisplayer;
- import org.openide.ErrorManager;
- import org.openide.NotifyDescriptor;
- import org.openide.explorer.ExplorerManager;
- import org.openide.filesystems.FileObject;
- import org.openide.filesystems.FileUtil;
- import org.openide.modules.Dependency;
- import org.openide.modules.SpecificationVersion;
- import org.openide.nodes.AbstractNode;
- import org.openide.nodes.Children;
- import org.openide.nodes.Node;
- import org.openide.nodes.PropertySupport;
- import org.openide.nodes.Sheet;
- import org.openide.util.NbBundle;
- import org.openide.util.RequestProcessor;
- import org.openide.util.actions.SystemAction;
- import org.openide.xml.XMLUtil;
- import org.w3c.dom.Element;
- /**
- * Represents <em>Libraries</em> panel in Suite customizer.
- *
- * @author Martin Krauskopf
- */
- public final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite
- implements ExplorerManager.Provider, ChangeListener {
- private final ExplorerManager manager;
- private ModuleEntry[] platformModules;
- Set<ModuleEntry> extraBinaryModules = new HashSet<ModuleEntry>();
- static boolean TEST = false;
- private LibrariesChildren libChildren;
- private boolean extClustersLoaded;
- private AbstractNode realRoot;
- private AbstractNode waitRoot;
- public static final String WAIT_ICON_PATH =
- "org/netbeans/modules/apisupport/project/suite/resources/wait.png"; // NOI18N
- /**
- * Creates new form SuiteCustomizerLibraries
- */
- public SuiteCustomizerLibraries(final SuiteProperties suiteProps, ProjectCustomizer.Category cat) {
- super(suiteProps, SuiteCustomizerLibraries.class, cat);
- initComponents();
- resolveButton.setVisible(false);
- manager = new ExplorerManager();
- waitRoot = new AbstractNode(new Children.Array() {
- @Override
- protected Collection<Node> initCollection() {
- return Collections.singleton((Node) new WaitNode());
- }
- });
- waitRoot.setName(getMessage("LBL_ModuleListClusters"));
- waitRoot.setDisplayName(getMessage("LBL_ModuleListClustersModules"));
- manager.setRootContext(waitRoot);
- refresh();
- view.setProperties(new Node.Property[] { ENABLED_PROP_TEMPLATE, ORIGIN_PROP_TEMPLATE });
- Outline outline = view.getOutline();
- outline.setRootVisible(false);
- outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- TableColumn col = outline.getColumnModel().getColumn(1);
- col.setMinWidth(25);
- col.setMaxWidth(200);
- col.setPreferredWidth(70);
- col = outline.getColumnModel().getColumn(2);
- col.setMinWidth(25);
- col.setMaxWidth(300);
- col.setPreferredWidth(130);
- suiteProps.getBrandingModel().addChangeListener(this);
- suiteProps.addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- if (SuiteProperties.NB_PLATFORM_PROPERTY.equals(evt.getPropertyName())) {
- refresh();
- }
- }
- });
- manager.addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
- Node[] nodes = (Node[]) evt.getNewValue();
- updateButtons(nodes);
- }
- }
- });
- updateButtons(manager.getSelectedNodes());
- javaPlatformCombo.setRenderer(JavaPlatformComponentFactory.javaPlatformListCellRenderer());
- }
- private void addProjectCluster(ClusterInfo ci, boolean showMessages) throws MissingResourceException, IllegalArgumentException {
- Project project = ci.getProject();
- assert project != null;
- SuiteProject thisPrj = getProperties().getProject();
- if (thisPrj.getProjectDirectory().equals(project.getProjectDirectory())) {
- if (showMessages)
- DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
- NbBundle.getMessage(SuiteCustomizerLibraries.class, "MSG_TryingToAddMyself",
- ProjectUtils.getInformation(project).getDisplayName())));
- return;
- }
- if (libChildren.findCluster(ci.getClusterDir()) != null) {
- if (showMessages) {
- DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
- NbBundle.getMessage(SuiteCustomizerLibraries.class, "MSG_AlreadyOnClusterPath",
- ProjectUtils.getInformation(project).getDisplayName())));
- }
- return;
- }
- initNodes();
- ClusterNode cnode;
- NbModuleProvider nmtp = project.getLookup().lookup(NbModuleProvider.class);
- if (nmtp != null) {
- cnode = new ClusterNode(ci, Children.LEAF);
- } else {
- SuiteProvider sprv = project.getLookup().lookup(SuiteProvider.class);
- assert sprv != null;
- cnode = createSuiteNode(ci);
- }
- synchronized (libChildren.extraNodes) {
- libChildren.extraNodes.add(cnode);
- }
- libChildren.setMergedKeys();
- }
- private boolean isExternalCluster(Enabled en) {
- return !en.isLeaf() && en.getProject() == null && !en.isPlatformNode();
- }
- private void updateButtons(Node[] nodes) {
- boolean canRemove = nodes.length > 0;
- boolean canEdit = nodes.length == 1;
- for (Node node : nodes) {
- if (! (node instanceof Enabled)) {
- canRemove = canEdit = false;
- break;
- }
- Enabled en = (Enabled) node;
- canRemove &= en instanceof ClusterNode && ! en.isPlatformNode();
- canEdit &= isExternalCluster(en);
- }
- removeButton.setEnabled(canRemove);
- editButton.setEnabled(canEdit);
- }
- private RequestProcessor.Task refreshTask;
- protected void refresh() {
- refreshJavaPlatforms();
- refreshPlatforms();
- if (refreshTask == null) {
- refreshTask = RP.create(new Runnable() {
- public void run() {
- refreshModules();
- updateDependencyWarnings(true);
- }
- });
- }
- if (TEST) {
- refreshTask.run();
- } else {
- refreshTask.schedule(0);
- }
- updateJavaPlatformEnabled();
- }
- private void addExtCluster(ClusterInfo ci) {
- Set<String> disabledModuleCNB = new HashSet<String>(Arrays.asList(getProperties().getDisabledModules()));
- Children.SortedArray moduleCh = new Children.SortedArray();
- try {
- ModuleList ml = ModuleList.scanCluster(ci.getClusterDir(), null, false, ci);
- moduleCh.setComparator(MODULES_COMPARATOR);
- for (ModuleEntry entry : ml.getAllEntries()) {
- moduleCh.add(new Node[] { new BinaryModuleNode(entry,
- ! disabledModuleCNB.contains(entry.getCodeNameBase()) && ci.isEnabled()) });
- extraBinaryModules.add(entry);
- }
- } catch (IOException e) {
- ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
- }
- initNodes();
- synchronized (libChildren.extraNodes) {
- libChildren.extraNodes.add(new ClusterNode(ci, moduleCh));
- }
- libChildren.setMergedKeys();
- }
- private ClusterNode createSuiteNode(ClusterInfo ci) {
- assert ci.getProject() != null;
- assert ci.getProject().getLookup().lookup(SuiteProvider.class) != null;
- Set<String> disabledModuleCNB = new HashSet<String>(Arrays.asList(getProperties().getDisabledModules()));
- Children.SortedArray moduleCh = new Children.SortedArray();
- moduleCh.setComparator(MODULES_COMPARATOR);
- Set<NbModuleProject> modules = SuiteUtils.getSubProjects(ci.getProject());
- for (NbModuleProject modPrj : modules) {
- if (modPrj.getModuleType() != NbModuleType.SUITE_COMPONENT) {
- continue;
- }
- moduleCh.add(new Node[] { new SuiteComponentNode(modPrj,
- ! disabledModuleCNB.contains(modPrj.getCodeNameBase()) && ci.isEnabled()) });
- }
- return new ClusterNode(ci, moduleCh);
- }
- private final class WaitNode extends AbstractNode {
- public WaitNode() {
- super(Children.LEAF);
- setDisplayName(UIUtil.WAIT_VALUE);
- setIconBaseWithExtension(WAIT_ICON_PATH);
- }
- }
- private void initNodes() {
- if (libChildren == null) {
- libChildren = new LibrariesChildren();
- realRoot = new AbstractNode(libChildren);
- realRoot.setName(getMessage("LBL_ModuleListClusters"));
- realRoot.setDisplayName(getMessage("LBL_ModuleListClustersModules"));
- }
- }
- private void refreshModules() {
- NbPlatform plaf = getProperties().getActivePlatform();
- if (plaf == null) {
- return;
- }
- // create platform modules children first
- platformModules = plaf.getSortedModules();
- initNodes();
- Set<String> disabledModuleCNB = new HashSet<String>(Arrays.asList(getProperties().getDisabledModules()));
- Set<String> enabledClusters = new HashSet<String>(Arrays.asList(getProperties().getEnabledClusters()));
- Map<File, ClusterNode> clusterToNode = new HashMap<File, ClusterNode>();
- synchronized (libChildren.platformNodes) {
- libChildren.platformNodes.clear();
- }
- boolean newPlaf = ((NbPlatform) platformValue.getSelectedItem()).getHarnessVersion().compareTo(HarnessVersion.V67) >= 0;
- for (ModuleEntry platformModule : platformModules) {
- File clusterDirectory = platformModule.getClusterDirectory();
- ClusterNode cluster = clusterToNode.get(clusterDirectory);
- if (cluster == null) {
- Children.SortedArray modules = new Children.SortedArray();
- modules.setComparator(MODULES_COMPARATOR);
- // enablement for pre-6.7 modules, for cluster path it gets resolved in load cluster.path section below
- boolean enabled = (newPlaf && enabledClusters.isEmpty()) || SingleModuleProperties.clusterMatch(enabledClusters, clusterDirectory.getName());
- ClusterInfo ci = ClusterInfo.create(clusterDirectory, true, enabled);
- cluster = new ClusterNode(ci, modules);
- clusterToNode.put(clusterDirectory, cluster);
- synchronized (libChildren.platformNodes) {
- libChildren.platformNodes.add(cluster);
- }
- }
- AbstractNode module = new BinaryModuleNode(platformModule,
- ! disabledModuleCNB.contains(platformModule.getCodeNameBase()) && cluster.isEnabled());
- cluster.getChildren().add(new Node[] { module });
- }
- // next, load cluster.path
- // XXX support "universal" "${nbplatform.active.dir}/*" entry in the cluster.path?
- // meaning "all platform clusters", recognized in harness and in UI;
- // it would allow easy switch among platforms with different clusters; probably not needed
- // update also code of SuiteProjectGenerator#createPlatformProperties
- Set<ClusterInfo> clusterPath = getProperties().getClusterPath();
- if (clusterPath.size() > 0) {
- // cluster.path exists, we enable/disabled platform nodes according to
- // cluster.path, not enabled.clusterPath & disabled.clusterPath
- for (ClusterNode node : libChildren.platformNodes()) {
- if (!clusterPath.contains(node.getClusterInfo())) // must not call setEnabled(true), disabled modules would be enabled
- {
- node.setEnabled(false);
- }
- }
- if (!extClustersLoaded) {
- for (ClusterInfo ci : clusterPath) {
- if (!ci.isPlatformCluster()) {
- if (ci.getProject() != null) {
- addProjectCluster(ci, false);
- } else {
- addExtCluster(ci);
- }
- }
- }
- extClustersLoaded = true;
- }
- } else {
- extClustersLoaded = true; // so that doUpdateDependencyWarnings is called even with empty cluster.path
- }
- libChildren.setMergedKeys();
- }
-
- private void refreshJavaPlatforms() {
- javaPlatformCombo.setModel(JavaPlatformComponentFactory.javaPlatformListModel());
- javaPlatformCombo.setSelectedItem(getProperties().getActiveJavaPlatform());
- }
-
- private void refreshPlatforms() {
- Logger logger = Logger.getLogger(SuiteCustomizerLibraries.class.getName());
- NbPlatform plaf = getProperties().getActivePlatform();
- if (plaf == null) { // #186992
- return;
- }
- logger.log(Level.FINE, "refreshPlatforms --> {0}", plaf.getLabel());
- platformValue.setModel(new PlatformComponentFactory.NbPlatformListModel(plaf)); // refresh
- if (getProperties().getEvaluator().getProperty("nbplatform.active") != null) {
- platformValue.requestFocus();
- } else { // custom local platform, typical with #197038
- platform.setEnabled(false);
- platformValue.setEnabled(false);
- managePlafsButton.setEnabled(false);
- }
- }
-
- @Override
- public void store() {
- // TODO C.P: disable buttons/show button "Upgrade"??? on old harness
- Set<String> enabledClusters = new TreeSet<String>();
- Set<String> disabledModules = new TreeSet<String>();
- List<ClusterInfo> clusterPath = new ArrayList<ClusterInfo>();
- boolean oldPlaf = getProperties().getActivePlatform().getHarnessVersion().compareTo(HarnessVersion.V67) < 0;
- assert refreshTask != null;
- if (! refreshTask.isFinished()) {
- // trying to store before nodes are up-to-date, just bail out
- return;
- }
- for (ClusterNode e : libChildren.platformNodes()) {
- if (e.isEnabled()) {
- if (oldPlaf)
- enabledClusters.add(e.getName());
- else
- clusterPath.add(e.getClusterInfo());
- for (Node module : e.getChildren().getNodes()) {
- Enabled m = (Enabled) module;
- // don't add modules in disabled cluster to disabledModules
- if (! m.isEnabled()) {
- disabledModules.add(m.getName());
- }
- }
- }
- }
- if (oldPlaf) {
- getProperties().setEnabledClusters(enabledClusters.toArray(new String[enabledClusters.size()]));
- } else {
- for (ClusterNode e : libChildren.extraNodes()) {
- clusterPath.add(e.getClusterInfo());
- if (e.isEnabled()) {
- for (Node module : e.getChildren().getNodes()) {
- Enabled m = (Enabled) module;
- // don't add modules in disabled cluster to disabledModules
- if (! m.isEnabled()) {
- disabledModules.add(m.getName());
- }
- }
- }
- }
- getProperties().setClusterPath(clusterPath);
- }
- getProperties().setDisabledModules(disabledModules.toArray(new String[disabledModules.size()]));
- }
-
- /** 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() {
- javaPlatformLabel = new javax.swing.JLabel();
- javaPlatformCombo = new javax.swing.JComboBox();
- javaPlatformButton = new javax.swing.JButton();
- platform = new javax.swing.JLabel();
- platformValue = org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory.getNbPlatformsComboxBox();
- managePlafsButton = new javax.swing.JButton();
- viewLabel = new javax.swing.JLabel();
- view = new org.openide.explorer.view.OutlineView();
- resolveButton = new javax.swing.JButton();
- addProjectButton = new javax.swing.JButton();
- addClusterButton = new javax.swing.JButton();
- removeButton = new javax.swing.JButton();
- editButton = new javax.swing.JButton();
- javaPlatformLabel.setLabelFor(javaPlatformCombo);
- org.openide.awt.Mnemonics.setLocalizedText(javaPlatformLabel, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Java_Platform")); // NOI18N
- javaPlatformCombo.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- javaPlatformComboItemStateChanged(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(javaPlatformButton, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Manage_Java_Platforms")); // NOI18N
- javaPlatformButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- javaPlatformButtonActionPerformed(evt);
- }
- });
- platform.setLabelFor(platformValue);
- org.openide.awt.Mnemonics.setLocalizedText(platform, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_NetBeansPlatform")); // NOI18N
- platformValue.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- platformValueItemStateChanged(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(managePlafsButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "CTL_ManagePlatform_a")); // NOI18N
- managePlafsButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- managePlatforms(evt);
- }
- });
- viewLabel.setLabelFor(view);
- org.openide.awt.Mnemonics.setLocalizedText(viewLabel, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_PlatformModules")); // NOI18N
- view.setBorder(javax.swing.UIManager.getBorder("ScrollPane.border"));
- resolveButton.setForeground(java.awt.Color.red);
- org.openide.awt.Mnemonics.setLocalizedText(resolveButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_ResolveButton")); // NOI18N
- resolveButton.setToolTipText(org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_ResolveButtonTooltip")); // NOI18N
- resolveButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- resolveButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(addProjectButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_AddProject")); // NOI18N
- addProjectButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addProjectButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(addClusterButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_AddCluster")); // NOI18N
- addClusterButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addClusterButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "CTL_RemoveButton")); // NOI18N
- removeButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- removeButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(editButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "CTL_EditButton")); // NOI18N
- editButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- editButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(javaPlatformLabel)
- .addComponent(platform))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(javaPlatformCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, 259, Short.MAX_VALUE)
- .addComponent(platformValue, javax.swing.GroupLayout.Alignment.TRAILING, 0, 259, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(managePlafsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(javaPlatformButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(82, Short.MAX_VALUE)
- .addComponent(resolveButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(addProjectButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(addClusterButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(removeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(editButton))
- .addGroup(layout.createSequentialGroup()
- .addComponent(viewLabel)
- .addContainerGap())
- .addComponent(view, javax.swing.GroupLayout.DEFAULT_SIZE, 632, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(javaPlatformLabel)
- .addComponent(javaPlatformCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(javaPlatformButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(platform)
- .addComponent(platformValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(managePlafsButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(viewLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(view, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(editButton)
- .addComponent(removeButton)
- .addComponent(addClusterButton)
- .addComponent(addProjectButton)
- .addComponent(resolveButton)))
- );
- javaPlatformLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_JavaPlatformLbl")); // NOI18N
- javaPlatformCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_JavaPlatformCombo")); // NOI18N
- javaPlatformButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_JavaPlatformButton")); // NOI18N
- platform.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_PlatformLbl")); // NOI18N
- platformValue.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_PlatformValue")); // NOI18N
- managePlafsButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SuiteCustomizerLibraries.class, "ACSD_ManagePlafsButton")); // NOI18N
- }// </editor-fold>//GEN-END:initComponents
- private void javaPlatformButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaPlatformButtonActionPerformed
- PlatformsCustomizer.showCustomizer((JavaPlatform) javaPlatformCombo.getSelectedItem());
- }//GEN-LAST:event_javaPlatformButtonActionPerformed
- private void javaPlatformComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_javaPlatformComboItemStateChanged
- getProperties().setActiveJavaPlatform((JavaPlatform) javaPlatformCombo.getSelectedItem());
- }//GEN-LAST:event_javaPlatformComboItemStateChanged
-
- private void platformValueItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_platformValueItemStateChanged
- if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
- manager.setRootContext(waitRoot);
- store(); // restore the same enablement of clusters for new platform
- Logger logger = Logger.getLogger(SuiteCustomizerLibraries.class.getName());
- logger.log(Level.FINE, "platformValueItemStateChanged, setting plaf -->" + ((NbPlatform) platformValue.getSelectedItem()).getLabel());
- getProperties().setActivePlatform((NbPlatform) platformValue.getSelectedItem());
- updateJavaPlatformEnabled();
- }
- }//GEN-LAST:event_platformValueItemStateChanged
-
- private void managePlatforms(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_managePlatforms
- NbPlatformCustomizer.showCustomizer();
- refreshPlatforms();
- }//GEN-LAST:event_managePlatforms
- private void addProjectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addProjectButtonActionPerformed
- Project project = ApisupportAntUIUtils.chooseProject(this);
- if (project != null) {
- ClusterInfo.QueryResult res = ClusterInfo.canCreate(project);
- String bundleKey = null;
- switch (res) {
- case NOT_A_NBM_PROJECT:
- bundleKey = "MSG_TryingToAddNonNBModuleOnClusterPath"; // NOI18N
- break;
- case NBORG_PROJECT_NOT_ALLOWED:
- bundleKey = "MSG_TryingToAddNBORGModuleOnClusterPath"; // NOI18N
- break;
- case SUITE_COMP_NOT_ALLOWED:
- SuiteProvider sprv = project.getLookup().lookup(SuiteProvider.class);
- FileObject otherSuiteDir = FileUtil.toFileObject(sprv.getSuiteDirectory());
- NotifyDescriptor.Confirmation confirmation = new NotifyDescriptor.Confirmation(NbBundle.getMessage(SuiteCustomizerLibraries.class, "MSG_AddSuiteInstead", ProjectUtils.getInformation(project).getDisplayName(), ApisupportAntUtils.getDisplayName(otherSuiteDir)), NotifyDescriptor.YES_NO_OPTION);
- DialogDisplayer.getDefault().notify(confirmation);
- if (confirmation.getValue() == NotifyDescriptor.YES_OPTION) {
- try {
- project = ProjectManager.getDefault().findProject(otherSuiteDir);
- assert ClusterInfo.canCreate(project) == ClusterInfo.QueryResult.OK;
- } catch (IOException e) {
- ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
- }
- } else {
- return;
- }
- // fall through to add suite instead
- }
- if (bundleKey != null) {
- DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(
- SuiteCustomizerLibraries.class, bundleKey, ProjectUtils.getInformation(project).getDisplayName())));
- } else {
- addProjectCluster(ClusterInfo.create(project, true), true);
- }
- }
- }//GEN-LAST:event_addProjectButtonActionPerformed
- private void addClusterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClusterButtonActionPerformed
- ClusterInfo ci = EditClusterPanel.showAddDialog(getProperties().getProject());
- if (ci != null) {
- if (libChildren.findCluster(ci.getClusterDir()) != null) {
- DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
- NbBundle.getMessage(SuiteCustomizerLibraries.class, "MSG_ClusterAlreadyOnClusterPath",
- ci.getClusterDir())));
- return;
- }
- addExtCluster(ci);
- }
- }//GEN-LAST:event_addClusterButtonActionPerformed
- private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
- libChildren.removeClusters(manager.getSelectedNodes());
- }//GEN-LAST:event_removeButtonActionPerformed
- private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
- Node[] nodes = manager.getSelectedNodes();
- assert nodes.length == 1;
- ClusterNode node = (ClusterNode) nodes[0];
- assert isExternalCluster(node);
- ClusterInfo ci = EditClusterPanel.showEditDialog(node.getClusterInfo(), getProperties().getProject());
- if (ci != null)
- node.setClusterInfo(ci);
- }//GEN-LAST:event_editButtonActionPerformed
- private void resolveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resolveButtonActionPerformed
- if (resolveFixInfo == null || ! resolveFixInfo.fixable)
- return;
- for (Node node : libChildren.getNodes()) {
- ClusterNode cn = (ClusterNode) node;
- for (Node modNode : cn.getChildren().getNodes()) {
- String cnb = modNode.getName();
- if (resolveFixInfo.toAdd.contains(cnb)) {
- Enabled en = (Enabled) modNode;
- en.setState(EnabledState.FULL_ENABLED, false); // update cluster states only once
- }
- }
- // standalone module cluster
- if (cn.getProject() != null) {
- NbModuleProvider nbmp = cn.getProject().getLookup().lookup(NbModuleProvider.class);
- if (nbmp != null
- && resolveFixInfo.toAdd.contains(nbmp.getCodeNameBase())) {
- NbModuleProject prj = cn.getProject().getLookup().lookup(NbModuleProject.class);
- if (prj == null || prj.getModuleType() == NbModuleType.STANDALONE) {
- assert ! cn.isEnabled();
- ((Enabled) cn).setState(EnabledState.FULL_ENABLED, false); // update cluster states only once
- }
- }
- }
- }
- libChildren.setMergedKeys(); // update cluster states
- resolveButton.setEnabled(false);
- updateDependencyWarnings(false);
- }//GEN-LAST:event_resolveButtonActionPerformed
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton addClusterButton;
- private javax.swing.JButton addProjectButton;
- private javax.swing.JButton editButton;
- private javax.swing.JButton javaPlatformButton;
- private javax.swing.JComboBox javaPlatformCombo;
- private javax.swing.JLabel javaPlatformLabel;
- private javax.swing.JButton managePlafsButton;
- private javax.swing.JLabel platform;
- private javax.swing.JComboBox platformValue;
- private javax.swing.JButton removeButton;
- private javax.swing.JButton resolveButton;
- private org.openide.explorer.view.OutlineView view;
- private javax.swing.JLabel viewLabel;
- // End of variables declaration//GEN-END:variables
-
-
- private static final Comparator<Node> MODULES_COMPARATOR = new Comparator<Node>() {
- Collator COLL = Collator.getInstance();
- public int compare(Node n1, Node n2) {
- return COLL.compare(n1.getDisplayName(), n2.getDisplayName());
- }
- };
-
- public ExplorerManager getExplorerManager() {
- return manager;
- }
-
- public static final Set<String> DISABLED_PLATFORM_MODULES = new TreeSet<String>();
-
- static {
- // Probably not needed for most platform apps, and won't even work under JNLP.
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.autoupdate.services"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.autoupdate.ui"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.autoupdate.cli"); // NOI18N
- // XXX the following would not be shown in regular apps anyway, because they are autoloads,
- // but they *are* shown in JNLP apps because currently even unused autoloads are enabled under JNLP:
- // Just annoying; e.g. shows Runtime tab prominently.
- DISABLED_PLATFORM_MODULES.add("org.openide.execution"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.core.execution"); // NOI18N
- // Similar - unlikely to really be wanted by typical platform apps, and show some GUI.
- /* XXX #107870: currently org.netbeans.core.actions.LogAction needs OW:
- DISABLED_PLATFORM_MODULES.add("org.openide.io"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.core.output2"); // NOI18N
- */
- // this one is useful only for writers of apps showing local disk
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.favorites"); // NOI18N
- // And these are deprecated:
- DISABLED_PLATFORM_MODULES.add("org.openide.compat"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.openide.util.enumerations"); // NOI18N
- // See issue #112931
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.core.kit"); // NOI18N
- // #110085: some more unwanted ones...
- DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.templates"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.libs.jsr223"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.jdesktop.layout"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.openide.options"); // NOI18N
- DISABLED_PLATFORM_MODULES.add("org.netbeans.api.visual"); // NOI18N
-
- }
-
- public void stateChanged(ChangeEvent ev) {
- if (getProperties().getBrandingModel().isBrandingEnabled()) {
- // User is turning on branded mode. Let's take a guess: they want to
- // exclude the usual suspects from the module list. We do not want to set
- // these excludes on a new suite because user might want to use real IDE as the platform
- // (i.e. not be creating an app, but rather be creating some modules for the IDE).
- // Only do this if there are no existing exclusions.
- Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes();
- for (Node cluster : clusters) {
- if (cluster instanceof Enabled) {
- Enabled e = (Enabled) cluster;
- if (!e.isEnabled()) {
- return;
- } else {
- for (Node module : e.getChildren().getNodes()) {
- if (module instanceof Enabled) {
- Enabled m = (Enabled) module;
- if (!m.isEnabled()) {
- return;
- }
- }
- }
- }
- }
- }
- // #64443: prompt first.
- if (!ApisupportAntUIUtils.showAcceptCancelDialog(
- getMessage("SuiteCustomizerLibraries.title.exclude_ide_modules"),
- getMessage("SuiteCustomizerLibraries.text.exclude_ide_modules"),
- getMessage("SuiteCustomizerLibraries.button.exclude"),
- getMessage("SuiteCustomizerLibraries.button.skip"),
- NotifyDescriptor.QUESTION_MESSAGE)) {
- return;
- }
- // OK, continue.
- for (Node cluster : clusters) {
- if (cluster instanceof Enabled) {
- Enabled e = (Enabled) cluster;
- if (e.getName().startsWith("platform")) { // NOI18N
- for (Node module : e.getChildren().getNodes()) {
- if (module instanceof Enabled) {
- Enabled m = (Enabled) module;
- if (DISABLED_PLATFORM_MODULES.contains(m.getName())) {
- m.setEnabled(false);
- }
- }
- }
- } else {
- e.setEnabled(false);
- }
- }
- }
- }
- }
-
- // #70724: internally, cluster nodes have 3 states now
- private enum EnabledState {
- // module / all modules in cluster selected
- FULL_ENABLED,
- // only for libChildren - some but not all modules are enabled
- PART_ENABLED,
- // module / whole cluster disabled
- DISABLED
- }
- private static final SystemAction[] NO_ACTIONS = new SystemAction[0];
- abstract class Enabled extends AbstractNode {
- private EnabledState state;
- Enabled(Children ch, boolean enabled) {
- super(ch);
- setState(enabled ? EnabledState.FULL_ENABLED : EnabledState.DISABLED, false);
-
- Sheet s = Sheet.createDefault();
- Sheet.Set ss = s.get(Sheet.PROPERTIES);
- ss.put(new EnabledProp(this));
- ss.put(new OriginProp(this));
- setSheet(s);
- setIconBaseWithExtension(
- isLeaf() ? NbModuleProject.NB_PROJECT_ICON_PATH : SuiteProject.SUITE_ICON_PATH);
- }
- public @Override String getHtmlDisplayName() {
- if (isDeprecated()) {
- try {
- return "<html><s>" + XMLUtil.toElementContent(getDisplayName()) + "</s>"; // NOI18N
- } catch (CharConversionException ex) {}
- }
- return null;
- }
- @Override
- public Action getPreferredAction() {
- return null;
- }
- @Override
- public SystemAction[] getActions(boolean context) {
- return NO_ACTIONS;
- }
- public void setEnabled(boolean s) {
- setState(s ? EnabledState.FULL_ENABLED : EnabledState.DISABLED, true);
- }
-
- public boolean isEnabled() {
- return state != EnabledState.DISABLED;
- }
- public EnabledState getState() {
- return state;
- }
- public abstract boolean isPlatformNode();
- public abstract String getOrigin();
- protected void setState(EnabledState s, boolean propagate) {
- if (s == state) {
- return;
- }
- state = s;
- Logger logger = Logger.getLogger(EnabledProp.class.getName());
- logger.log(Level.FINE, "Node '" + getName() + "', state="
- + (s==EnabledState.DISABLED ? "disabled" :
- (s==EnabledState.FULL_ENABLED ? "full enabled" : "part enabled")));
- if (propagate) {
- //refresh children
- EnabledState newChildState =
- (s == EnabledState.PART_ENABLED) ? null : s;
- // XXX for (Node nn : standard.getNodes()) {
- for (Node nn : getChildren().getNodes()) {
- if (nn instanceof Enabled) {
- Enabled en = (Enabled) nn;
- // #70724: checking/unchecking cluster node checks/unchecks all children
- if (newChildState != null) {
- en.setState(newChildState, false);
- }
- en.firePropertyChange(null, null, null);
- }
- }
- //refresh parent
- Node n = getParentNode();
- if (n instanceof Enabled) {
- assert s != EnabledState.PART_ENABLED : "Module node should not be passed ENABLED_PARTIALLY state";
- Enabled par = (Enabled) n;
- par.updateClusterState();
- par.firePropertyChange(null, null, null);
- }
- updateDependencyWarnings(false);
- }
- }
- void updateClusterState() {
- if (getChildren() == Children.LEAF)
- return;
- boolean allEnabled = true;
- boolean allDisabled = true;
- for (Node nn : getChildren().getNodes()) {
- if (nn instanceof Enabled) {
- Enabled ch = (Enabled) nn;
- allEnabled &= ch.isEnabled();
- allDisabled &= !ch.isEnabled();
- if (!allEnabled && !allDisabled) {
- break;
- }
- }
- }
- if (allEnabled) {
- setState(EnabledState.FULL_ENABLED, false);
- } else if (allDisabled) {
- setState(EnabledState.DISABLED, false);
- } else {
- setState(EnabledState.PART_ENABLED, false);
- }
- }
- /**
- * @return the project if any is associated
- */
- public abstract Project getProject();
- protected abstract boolean isDeprecated();
- }
- final class SuiteComponentNode extends Enabled {
- private final NbModuleProject project;
- public SuiteComponentNode(NbModuleProject prj, boolean enabled) {
- super(Children.LEAF, enabled);
- this.project = prj;
- final String cnb = prj.getCodeNameBase();
- setName(cnb);
- setDisplayName(ProjectUtils.getInformation(prj).getDisplayName());
- Provider provider = prj.getLookup().lookup(LocalizedBundleInfo.Provider.class);
- if (provider != null) {
- LocalizedBundleInfo bundleInfo = provider.getLocalizedBundleInfo();
- if (bundleInfo != null) {
- setShortDescription(formatEntryDesc(cnb, bundleInfo.getShortDescription()));
- }
- }
- }
- public boolean isDeprecated() {
- return ManifestManager.getInstance(Util.getManifest(project.getManifestFile()), false).isDeprecated();
- }
- @Override
- public boolean isPlatformNode() {
-