/projects/netbeans-7.3/java.hints.ui/src/org/netbeans/modules/java/hints/spiimpl/options/HintsPanel.java
Java | 1058 lines | 849 code | 127 blank | 82 comment | 76 complexity | e6dc48edab9cd7e353e3f68011d697f7 MD5 | raw file
- /*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 1997-2011 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-2011 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.java.hints.spiimpl.options;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.MissingResourceException;
- import java.util.ResourceBundle;
- import java.util.Set;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import java.util.concurrent.atomic.AtomicBoolean;
- import java.util.prefs.Preferences;
- import javax.swing.AbstractAction;
- import javax.swing.ButtonGroup;
- import javax.swing.ButtonModel;
- import javax.swing.JCheckBox;
- import javax.swing.JLabel;
- import javax.swing.JMenuItem;
- import javax.swing.JOptionPane;
- import javax.swing.JPopupMenu;
- import javax.swing.JTree;
- import javax.swing.KeyStroke;
- import javax.swing.SwingUtilities;
- import javax.swing.event.ChangeListener;
- import javax.swing.event.TreeSelectionEvent;
- import javax.swing.event.TreeSelectionListener;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.StyledDocument;
- import javax.swing.tree.DefaultMutableTreeNode;
- import javax.swing.tree.DefaultTreeCellRenderer;
- import javax.swing.tree.DefaultTreeModel;
- import javax.swing.tree.MutableTreeNode;
- import javax.swing.tree.TreeCellRenderer;
- import javax.swing.tree.TreeNode;
- import javax.swing.tree.TreePath;
- import javax.swing.tree.TreeSelectionModel;
- import org.netbeans.api.annotations.common.NullAllowed;
- import org.netbeans.modules.analysis.spi.Analyzer.CustomizerContext;
- import org.netbeans.modules.java.hints.analysis.AnalyzerImpl;
- import org.netbeans.modules.java.hints.spiimpl.RulesManager;
- import org.netbeans.modules.java.hints.spiimpl.refactoring.Configuration;
- import org.netbeans.modules.java.hints.spiimpl.refactoring.ConfigurationRenderer;
- import org.netbeans.modules.java.hints.spiimpl.refactoring.ConfigurationsComboModel;
- import org.netbeans.modules.java.hints.spiimpl.refactoring.Utilities;
- import org.openide.filesystems.FileObject;
- import org.openide.loaders.DataObjectNotFoundException;
- import org.openide.util.Exceptions;
- import org.openide.util.NbBundle;
- import org.netbeans.modules.java.hints.providers.spi.HintMetadata;
- import org.netbeans.modules.java.hints.providers.spi.HintMetadata.Options;
- import org.netbeans.modules.java.hints.spiimpl.options.HintsPanelLogic.HintCategory;
- import org.netbeans.modules.java.hints.spiimpl.refactoring.Utilities.ClassPathBasedHintWrapper;
- import org.netbeans.modules.options.editor.spi.OptionsFilter;
- import org.netbeans.modules.options.editor.spi.OptionsFilter.Acceptor;
- import org.openide.cookies.EditorCookie;
- import org.openide.filesystems.FileUtil;
- import org.openide.loaders.DataFolder;
- import org.openide.loaders.DataObject;
- import org.openide.text.CloneableEditorSupport;
- import org.openide.text.NbDocument;
- import org.openide.util.NbBundle.Messages;
- import org.openide.util.RequestProcessor;
- public final class HintsPanel extends javax.swing.JPanel {
-
- private static final String DELETE = "delete";
- private static final String DECLARATIVE_HINT_TEMPLATE_LOCATION = "org-netbeans-modules-java-hints/templates/Inspection.hint";
- private final static RequestProcessor WORKER = new RequestProcessor(HintsPanel.class.getName(), 1, false, false);
- private HintsPanelLogic logic;
- private DefaultTreeModel errorTreeModel;
- private final AtomicBoolean initialized = new AtomicBoolean(false);
- private final ClassPathBasedHintWrapper cpBased;
- private final QueryStatus queryStatus;
- //AWT only:
- private HintMetadata toSelect = null;
-
- DefaultMutableTreeNode extraNode = new DefaultMutableTreeNode(NbBundle.getMessage(HintsPanel.class, "CTL_DepScanning")); //NOI18N
- private boolean hasNewHints;
- private boolean confirmed;
-
- @Messages("LBL_Loading=Loading...")
- HintsPanel(@NullAllowed final OptionsFilter filter) {
- this.cpBased = null;
- this.queryStatus = QueryStatus.SHOW_QUERIES;
- WORKER.post(new Runnable() {
- @Override
- public void run() {
- RulesManager.getInstance();
-
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- HintsPanel.this.removeAll();
- HintsPanel.this.init(filter, true, false, false, true);
- buttonsPanel.setVisible(false);
- searchPanel.setVisible(false);
- configurationsPanel.setVisible(false);
- }
- });
- }
- });
- setLayout(new GridBagLayout());
- add(new JLabel(Bundle.LBL_Loading()), new GridBagConstraints());
- }
- public HintsPanel(Configuration preselected, ClassPathBasedHintWrapper cpBased) {
- this.cpBased = cpBased;
- this.queryStatus = QueryStatus.ONLY_ENABLED;
- init(null, false, true, true, true);
- configCombo.setSelectedItem(preselected);
- }
- public HintsPanel(HintMetadata preselected, @NullAllowed final CustomizerContext<?, ?> cc, ClassPathBasedHintWrapper cpBased) {
- this.cpBased = cpBased;
- this.queryStatus = cc == null ? QueryStatus.NEVER : QueryStatus.SHOW_QUERIES;
- init(null, false, false, cc == null, false);
- select(preselected);
- configurationsPanel.setVisible(false);
-
- if (cc != null) {
- errorTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
- @Override public void valueChanged(TreeSelectionEvent e) {
- HintMetadata hm = getSelectedHint();
- if (hm != null) {
- cc.setSelectedId(AnalyzerImpl.ID_JAVA_HINTS_PREFIX + hm.id);
- }
- }
- });
- }
- }
- public HintsPanel(Preferences configurations, ClassPathBasedHintWrapper cpBased) {
- this.cpBased = cpBased;
- this.queryStatus = QueryStatus.SHOW_QUERIES;
- init(null, false, false, false, true);
- setOverlayPreferences(configurations);
- configurationsPanel.setVisible(false);
- }
- public void setOverlayPreferences(Preferences configurations) {
- logic.setOverlayPreferences(configurations);
- }
- public boolean hasNewHints() {
- return hasNewHints;
- }
-
- private org.netbeans.modules.java.hints.spiimpl.refactoring.OptionsFilter optionsFilter;
-
- private void setModel(DefaultTreeModel errorTreeModel) {
- if (optionsFilter!=null) {
- optionsFilter.installFilteringModel(errorTree, errorTreeModel, new AcceptorImpl());
- } else {
- errorTree.setModel(errorTreeModel);
- }
- }
-
- private void init(@NullAllowed OptionsFilter filter, boolean inOptionsDialog, boolean useConfigCombo, boolean showOkCancel, boolean showCheckBoxes) {
- initComponents();
- scriptScrollPane.setVisible(false);
- optionsFilter = null;
- if (!inOptionsDialog && filter==null) {
- optionsFilter = new org.netbeans.modules.java.hints.spiimpl.refactoring.OptionsFilter(
- searchTextField.getDocument(), new Runnable() {
-
- @Override
- public void run() {
- }
- }
- );
- }
- configCombo.setModel(new ConfigurationsComboModel(true));
- configCombo.setRenderer(new ConfigurationRenderer());
- if (useConfigCombo || inOptionsDialog) {
- configCombo.setSelectedItem(null);
- }
-
- descriptionTextArea.setContentType("text/html"); // NOI18N
-
- scriptTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-javahints"));
- scriptTextArea.setEditable(true);
-
- // if( "Windows".equals(UIManager.getLookAndFeel().getID()) ) //NOI18N
- // setOpaque( false );
-
- errorTree.setCellRenderer(showCheckBoxes? new CheckBoxRenderer() : new JLabelRenderer());
- errorTree.setRootVisible( false );
- errorTree.setShowsRootHandles( true );
- errorTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
-
- errorTree.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- handleClick(e);
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- handleClick(e);
- }
-
- private void handleClick(MouseEvent e) {
- if (e.isPopupTrigger()) {
- Point p = e.getPoint();
- TreePath path = errorTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
- if (path != null) {
- DefaultMutableTreeNode o = (DefaultMutableTreeNode) path.getLastPathComponent();
- if (o.getUserObject() instanceof HintMetadata) {
- HintMetadata hint = (HintMetadata) o.getUserObject();
- if (hint.category.equals(HintCategory.CUSTOM_CATEGORY)) {
- JPopupMenu popup = new JPopupMenu();
- popup.add(new JMenuItem(new RenameHint(o, hint, path)));
- popup.add(new JMenuItem(new RemoveHint(o, hint)));
- popup.show(errorTree, e.getX(), e.getY());
- }
- }
- }
- }
- }
- });
-
- errorTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
- errorTree.getActionMap().put(DELETE, new RemoveHint(null, null));
- toProblemCheckBox.setVisible(false);
-
- Collection<? extends HintMetadata> hints = inOptionsDialog?filterCustom(RulesManager.getInstance().readHints(null, null, null).keySet()):Utilities.getBatchSupportedHints(cpBased).keySet();
- errorTreeModel = constructTM(hints, inOptionsDialog);
- if (filter != null) {
- ((OptionsFilter) filter).installFilteringModel(errorTree, errorTreeModel, new AcceptorImpl());
- } else {
- setModel(errorTreeModel);
- }
- initialized.set(true);
- update(inOptionsDialog);
-
- if (toSelect != null) {
- select(toSelect, true);
-
- toSelect = null;
- }
-
- boolean editEnabled = showOkCancel && FileUtil.getConfigFile(DECLARATIVE_HINT_TEMPLATE_LOCATION)!=null;
- newButton.setVisible(editEnabled);
- importButton.setVisible(false);
- exportButton.setVisible(false);
- editScriptButton.setVisible(editEnabled);
- editingButtons.setVisible(false);
-
- severityComboBox.setVisible(useConfigCombo || inOptionsDialog);
- severityLabel.setVisible(useConfigCombo || inOptionsDialog);
- okButton.setVisible(showOkCancel);
- cancelButton.setVisible(showOkCancel);
- validate();
- }
-
-
- /** 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() {
- java.awt.GridBagConstraints gridBagConstraints;
- jSplitPane1 = new javax.swing.JSplitPane();
- treePanel = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- errorTree = new EditableJTree();
- detailsPanel = new javax.swing.JPanel();
- optionsPanel = new javax.swing.JPanel();
- severityLabel = new javax.swing.JLabel();
- severityComboBox = new javax.swing.JComboBox();
- toProblemCheckBox = new javax.swing.JCheckBox();
- customizerPanel = new javax.swing.JPanel();
- descriptionPanel = new javax.swing.JPanel();
- descriptionScrollPane = new javax.swing.JScrollPane();
- descriptionTextArea = new javax.swing.JEditorPane();
- descriptionLabel = new javax.swing.JLabel();
- editingButtons = new javax.swing.JPanel();
- saveButton = new javax.swing.JButton();
- cancelEdit = new javax.swing.JButton();
- openInEditor = new javax.swing.JButton();
- scriptScrollPane = new javax.swing.JScrollPane();
- scriptTextArea = new javax.swing.JEditorPane();
- buttonsPanel = new javax.swing.JPanel();
- newButton = new javax.swing.JButton();
- importButton = new javax.swing.JButton();
- exportButton = new javax.swing.JButton();
- okButton = new javax.swing.JButton();
- editScriptButton = new javax.swing.JButton();
- cancelButton = new javax.swing.JButton();
- configurationsPanel = new javax.swing.JPanel();
- configLabel = new javax.swing.JLabel();
- configCombo = new javax.swing.JComboBox();
- searchPanel = new javax.swing.JPanel();
- refactoringsLabel = new javax.swing.JLabel();
- searchLabel = new javax.swing.JLabel();
- searchTextField = new javax.swing.JTextField();
- setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
- setLayout(new java.awt.GridBagLayout());
- jSplitPane1.setBorder(null);
- jSplitPane1.setDividerLocation(320);
- treePanel.setOpaque(false);
- treePanel.setLayout(new java.awt.BorderLayout());
- errorTree.setEditable(true);
- jScrollPane1.setViewportView(errorTree);
- errorTree.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.errorTree.AccessibleContext.accessibleName")); // NOI18N
- errorTree.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.errorTree.AccessibleContext.accessibleDescription")); // NOI18N
- treePanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
- jSplitPane1.setLeftComponent(treePanel);
- detailsPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 6, 0, 0));
- detailsPanel.setOpaque(false);
- optionsPanel.setOpaque(false);
- optionsPanel.setLayout(new java.awt.GridBagLayout());
- severityLabel.setLabelFor(severityComboBox);
- org.openide.awt.Mnemonics.setLocalizedText(severityLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "CTL_ShowAs_Label")); // NOI18N
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 0;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
- gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
- optionsPanel.add(severityLabel, gridBagConstraints);
- severityLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.severityLabel.AccessibleContext.accessibleDescription")); // NOI18N
- severityComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- optionsPanel.add(severityComboBox, new java.awt.GridBagConstraints());
- severityComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(HintsPanel.class, "AN_Show_As_Combo")); // NOI18N
- severityComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(HintsPanel.class, "AD_Show_As_Combo")); // NOI18N
- org.openide.awt.Mnemonics.setLocalizedText(toProblemCheckBox, org.openide.util.NbBundle.getMessage(HintsPanel.class, "CTL_InTasklist_CheckBox")); // NOI18N
- toProblemCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridwidth = 3;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
- optionsPanel.add(toProblemCheckBox, gridBagConstraints);
- customizerPanel.setOpaque(false);
- customizerPanel.setLayout(new java.awt.BorderLayout());
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 3;
- gridBagConstraints.gridwidth = 3;
- gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
- optionsPanel.add(customizerPanel, gridBagConstraints);
- descriptionPanel.setOpaque(false);
- descriptionPanel.setLayout(new java.awt.GridBagLayout());
- descriptionTextArea.setEditable(false);
- descriptionTextArea.setPreferredSize(new java.awt.Dimension(100, 50));
- descriptionScrollPane.setViewportView(descriptionTextArea);
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 1;
- gridBagConstraints.gridwidth = 4;
- gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- descriptionPanel.add(descriptionScrollPane, gridBagConstraints);
- descriptionLabel.setLabelFor(descriptionTextArea);
- org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "CTL_Description_Border")); // NOI18N
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 0;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- descriptionPanel.add(descriptionLabel, gridBagConstraints);
- org.openide.awt.Mnemonics.setLocalizedText(saveButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.saveButton.text")); // NOI18N
- saveButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- saveButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(cancelEdit, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.cancelEdit.text")); // NOI18N
- cancelEdit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cancelEditActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(openInEditor, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.openInEditor.text")); // NOI18N
- openInEditor.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- openInEditorActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout editingButtonsLayout = new javax.swing.GroupLayout(editingButtons);
- editingButtons.setLayout(editingButtonsLayout);
- editingButtonsLayout.setHorizontalGroup(
- editingButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, editingButtonsLayout.createSequentialGroup()
- .addComponent(openInEditor)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
- .addComponent(saveButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(cancelEdit))
- );
- editingButtonsLayout.setVerticalGroup(
- editingButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(editingButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(openInEditor)
- .addComponent(cancelEdit)
- .addComponent(saveButton))
- );
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridwidth = 4;
- gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
- descriptionPanel.add(editingButtons, gridBagConstraints);
- scriptTextArea.setEditable(false);
- scriptTextArea.setPreferredSize(new java.awt.Dimension(100, 50));
- scriptScrollPane.setViewportView(scriptTextArea);
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 1;
- gridBagConstraints.gridwidth = 4;
- gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- descriptionPanel.add(scriptScrollPane, gridBagConstraints);
- javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel);
- detailsPanel.setLayout(detailsPanelLayout);
- detailsPanelLayout.setHorizontalGroup(
- detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(descriptionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- detailsPanelLayout.setVerticalGroup(
- detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(detailsPanelLayout.createSequentialGroup()
- .addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
- .addGap(12, 12, 12)
- .addComponent(descriptionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
- );
- jSplitPane1.setRightComponent(detailsPanel);
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 2;
- gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- add(jSplitPane1, gridBagConstraints);
- org.openide.awt.Mnemonics.setLocalizedText(newButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.newButton.text")); // NOI18N
- newButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- newButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(importButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.importButton.text")); // NOI18N
- org.openide.awt.Mnemonics.setLocalizedText(exportButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.exportButton.text")); // NOI18N
- org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.okButton.text")); // NOI18N
- okButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- okButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(editScriptButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.editScriptButton.text")); // NOI18N
- editScriptButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- editScriptButtonActionPerformed(evt);
- }
- });
- org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.cancelButton.text")); // NOI18N
- cancelButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cancelButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout buttonsPanelLayout = new javax.swing.GroupLayout(buttonsPanel);
- buttonsPanel.setLayout(buttonsPanelLayout);
- buttonsPanelLayout.setHorizontalGroup(
- buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(buttonsPanelLayout.createSequentialGroup()
- .addComponent(newButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(importButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(exportButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 329, Short.MAX_VALUE)
- .addComponent(editScriptButton)
- .addGap(35, 35, 35)
- .addComponent(okButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(cancelButton))
- );
- buttonsPanelLayout.setVerticalGroup(
- buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(buttonsPanelLayout.createSequentialGroup()
- .addGap(5, 5, 5)
- .addGroup(buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(newButton)
- .addComponent(importButton)
- .addComponent(exportButton)
- .addComponent(editScriptButton)
- .addComponent(cancelButton)
- .addComponent(okButton)))
- );
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 3;
- gridBagConstraints.gridwidth = 2;
- gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
- add(buttonsPanel, gridBagConstraints);
- org.openide.awt.Mnemonics.setLocalizedText(configLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.configLabel.text")); // NOI18N
- configCombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- configComboActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout configurationsPanelLayout = new javax.swing.GroupLayout(configurationsPanel);
- configurationsPanel.setLayout(configurationsPanelLayout);
- configurationsPanelLayout.setHorizontalGroup(
- configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(configurationsPanelLayout.createSequentialGroup()
- .addComponent(configLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(configCombo, 0, 642, Short.MAX_VALUE))
- );
- configurationsPanelLayout.setVerticalGroup(
- configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(configurationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(configLabel)
- .addComponent(configCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
- add(configurationsPanel, gridBagConstraints);
- org.openide.awt.Mnemonics.setLocalizedText(refactoringsLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.refactoringsLabel.text")); // NOI18N
- searchLabel.setLabelFor(searchTextField);
- org.openide.awt.Mnemonics.setLocalizedText(searchLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.searchLabel.text")); // NOI18N
- javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
- searchPanel.setLayout(searchPanelLayout);
- searchPanelLayout.setHorizontalGroup(
- searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, searchPanelLayout.createSequentialGroup()
- .addComponent(refactoringsLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 493, Short.MAX_VALUE)
- .addComponent(searchLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- searchPanelLayout.setVerticalGroup(
- searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(searchPanelLayout.createSequentialGroup()
- .addGap(5, 5, 5)
- .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(searchLabel)
- .addComponent(refactoringsLabel)))
- );
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 1;
- gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
- add(searchPanel, gridBagConstraints);
- getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.AccessibleContext.accessibleName")); // NOI18N
- getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(HintsPanel.class, "HintsPanel.AccessibleContext.accessibleDescription")); // NOI18N
- }// </editor-fold>//GEN-END:initComponents
-
- private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
- applyChanges();
- confirmed = true;
- getRootPane().getParent().setVisible(false);
- }//GEN-LAST:event_okButtonActionPerformed
-
- private void configComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configComboActionPerformed
- if (configCombo.getSelectedItem() instanceof ActionListener) {
- ((ActionListener) configCombo.getSelectedItem()).actionPerformed(evt);
- }
- if (queryStatus == QueryStatus.ONLY_ENABLED) {
- errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
- setModel(errorTreeModel);
- if (logic != null) {
- logic.errorTreeModel = errorTreeModel;
- }
- }
- }//GEN-LAST:event_configComboActionPerformed
- private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
- try {
- FileObject tempFO = FileUtil.getConfigFile(DECLARATIVE_HINT_TEMPLATE_LOCATION); // NOI18N
- FileObject folderFO = FileUtil.getConfigFile("rules");
- if (folderFO == null) {
- folderFO = FileUtil.getConfigRoot().createFolder("rules");
- }
- DataFolder folder = (DataFolder) DataObject.find(folderFO);
- DataObject template = DataObject.find(tempFO);
- DataObject newIfcDO = template.createFromTemplate(folder, null);
- RulesManager.getInstance().reload();
- cpBased.reset();
- errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
- setModel(errorTreeModel);
- logic.errorTreeModel = errorTreeModel;
- HintMetadata newHint = getHintByName(newIfcDO.getPrimaryFile().getNameExt());
- HintsSettings.setEnabled(logic.getCurrentPrefernces(newHint.id), true);
- select(newHint);
- hasNewHints = true;
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- }//GEN-LAST:event_newButtonActionPerformed
- private String customHintCodeBeforeEditing;
- private boolean wasModified;
-
- private void editScriptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editScriptButtonActionPerformed
- descriptionScrollPane.setVisible(false);
- scriptScrollPane.setVisible(true);
- editScriptButton.setVisible(false);
- editingButtons.setVisible(true);
- optionsPanel.setVisible(false);
- org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "CTL_Script_Border"));
- DataObject dob = getDataObject(getSelectedHint());
- EditorCookie ec = dob.getCookie(EditorCookie.class);
- try {
- final StyledDocument doc = ec.openDocument();
- doc.render(new Runnable() {
- @Override public void run() {
- try {
- customHintCodeBeforeEditing = doc.getText(0, doc.getLength());
- } catch (BadLocationException ex) {
- Exceptions.printStackTrace(ex);
- customHintCodeBeforeEditing = null;
- }
- }
- });
- wasModified = DataObject.getRegistry().getModifiedSet().contains(dob);
- scriptTextArea.setDocument(doc);
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- newButton.setEnabled(false);
- searchTextField.setEnabled(false);
- configCombo.setEnabled(false);
- errorTree.setEnabled(false);
- okButton.setEnabled(false);
- validate();
- }//GEN-LAST:event_editScriptButtonActionPerformed
- private void cancelEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelEditActionPerformed
- descriptionScrollPane.setVisible(true);
- scriptScrollPane.setVisible(false);
- optionsPanel.setVisible(true);
- editingButtons.setVisible(false);
- editScriptButton.setVisible(true);
- org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(HintsPanel.class, "CTL_Description_Border"));
- if (customHintCodeBeforeEditing != null) {
- DataObject dob = getDataObject(getSelectedHint());
- EditorCookie ec = dob.getCookie(EditorCookie.class);
- try {
- final StyledDocument doc = ec.openDocument();
- NbDocument.runAtomic(doc, new Runnable() {
- @Override public void run() {
- try {
- doc.remove(0, doc.getLength());
- doc.insertString(0, customHintCodeBeforeEditing, null);
- } catch (BadLocationException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- });
- customHintCodeBeforeEditing = null;
- if (!wasModified) ec.saveDocument();
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
- okButton.setEnabled(true);
- newButton.setEnabled(true);
- searchTextField.setEnabled(true);
- configCombo.setEnabled(true);
- errorTree.setEnabled(true);
- logic.valueChanged(null);
- }//GEN-LAST:event_cancelEditActionPerformed
- private void openInEditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openInEditorActionPerformed
- applyChanges();
- getRootPane().getParent().getParent().setVisible(false);
- DataObject dob = getDataObject(getSelectedHint());
- EditorCookie ec = dob.getCookie(EditorCookie.class);
- ec.open();
- }//GEN-LAST:event_openInEditorActionPerformed
- private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
- final HintMetadata selectedHint = getSelectedHint();
- final String selectedHintId = selectedHint.id;
- DataObject dob = getDataObject(selectedHint);
- EditorCookie ec = dob.getCookie(EditorCookie.class);
- try {
- ec.saveDocument();
- } catch (IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- RulesManager.getInstance().reload();
- cpBased.reset();
- errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
- setModel(errorTreeModel);
- select(getHintByName(selectedHintId));
- customHintCodeBeforeEditing = null;
- cancelEditActionPerformed(evt);
- hasNewHints = true;
- }//GEN-LAST:event_saveButtonActionPerformed
- private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
- getRootPane().getParent().setVisible(false);
- }//GEN-LAST:event_cancelButtonActionPerformed
-
- private HintMetadata getHintByName(String name) {
- for (HintMetadata meta:Utilities.getBatchSupportedHints(cpBased).keySet()) {
- if (meta.id.startsWith(name)) {
- return meta;
- }
- }
- return null;
- }
- synchronized void update(boolean inOptionsDialog) {
- if (!initialized.get()) return;
- if ( logic != null ) {
- logic.disconnect();
- }
- logic = new HintsPanelLogic();
- logic.connect(errorTree, errorTreeModel, severityLabel, severityComboBox, toProblemCheckBox, customizerPanel, descriptionTextArea, configCombo, editScriptButton, inOptionsDialog);
- }
-
- void cancel() {
- if (!initialized.get()) return;
- logic.disconnect();
- logic = null;
- }
-
- boolean isChanged() {
- return logic != null ? logic.isChanged() : false;
- }
-
- void applyChanges() {
- if (!initialized.get()) return;
- logic.applyChanges();
- logic.disconnect();
- logic = null;
- }
- public boolean isConfirmed() {
- return confirmed;
- }
-
- class JLabelRenderer implements TreeCellRenderer {
-
- private JLabel renderer = new JLabel();
- private DefaultTreeCellRenderer dr = new DefaultTreeCellRenderer();
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
- renderer.setBackground(selected ? dr.getBackgroundSelectionColor() : dr.getBackgroundNonSelectionColor());
- renderer.setForeground(selected ? dr.getTextSelectionColor() : dr.getTextNonSelectionColor());
- renderer.setFont(renderer.getFont().deriveFont(Font.PLAIN));
- renderer.setOpaque(true);
- Object data = ((DefaultMutableTreeNode) value).getUserObject();
- if (data instanceof HintCategory) {
- HintCategory cat = ((HintCategory) data);
- renderer.setText(cat.displayName);
- } else if (data instanceof HintMetadata) {
- HintMetadata treeRule = (HintMetadata) data;
- if (treeRule.options.contains(Options.QUERY)) {
- renderer.setFont(renderer.getFont().deriveFont(Font.ITALIC));
- }
- renderer.setText(treeRule.displayName);
- } else {
- renderer.setText(value.toString());
- }
- return renderer;
- }
- }
-
- class CheckBoxRenderer implements TreeCellRenderer {
-
- private final TristateCheckBox renderer = new TristateCheckBox();
- private final DefaultTreeCellRenderer dr = new DefaultTreeCellRenderer();
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
- renderer.setBackground(selected ? dr.getBackgroundSelectionColor() : dr.getBackgroundNonSelectionColor());
- renderer.setForeground(selected ? dr.getTextSelectionColor() : dr.getTextNonSelectionColor());
- renderer.setFont(renderer.getFont().deriveFont(Font.PLAIN));
- Object data = ((DefaultMutableTreeNode) value).getUserObject();
- if (data instanceof HintCategory) {
- HintCategory cat = ((HintCategory) data);
- renderer.setText(cat.displayName);
- if (logic != null) {
- renderer.setState(logic.isSelected((DefaultMutableTreeNode) value));
- }
- } else if (data instanceof HintMetadata) {
- HintMetadata treeRule = (HintMetadata) data;
- if (treeRule.options.contains(Options.QUERY)) {
- renderer.setFont(renderer.getFont().deriveFont(Font.ITALIC));
- }
- renderer.setText(treeRule.displayName);
- if (logic != null) {
- renderer.setSelected(logic.isEnabled(treeRule));
- }
- } else {
- renderer.setText(value.toString());
- if (value == extraNode && logic != null) {
- renderer.setSelected(logic.getCurrentDependencyTracking() != DepScanningSettings.DependencyTracking.DISABLED);
- }
- }
- return renderer;
- }
- }
- enum State {
- SELECTED, NOT_SELECTED, OTHER;
- };
- private static class TristateCheckBox extends JCheckBox {
- private final TristateDecorator model;
- public TristateCheckBox() {
- super(null, null);
- model = new TristateDecorator(getModel());
- setModel(model);
- setState(State.OTHER);
- }
- /** No one may add mouse listeners, not even Swing! */
- @Override
- public void addMouseListener(MouseListener l) { }
- /**
- * Set the new state to either SELECTED, NOT_SELECTED or
- * OTHER.
- */
- public void setState(State state) { model.setState(state); }
- /** Return the current state, which is determined by the
- * selection status of the model. */
- public State getState() { return model.getState(); }
- @Override
- public void setSelected(boolean b) {
- if (b) {
- setState(State.SELECTED);
- } else {
- setState(State.NOT_SELECTED);
- }
- }
- /**
- * Exactly which Design Pattern is this? Is it an Adapter,
- * a Proxy or a Decorator? In this case, my vote lies with the
- * Decorator, because we are extending functionality and
- * "decorating" the original model with a more powerful model.
- */
- private class TristateDecorator implements ButtonModel {
- private final ButtonModel other;
- private TristateDecorator(ButtonModel other) {
- this.other = other;
- }
- private void setState(State state) {
- if (state == State.NOT_SELECTED) {
- other.setArmed(false);
- setPressed(false);
- setSelected(false);
- } else if (state == State.SELECTED) {
- other.setArmed(false);
- setPressed(false);
- setSelected(true);
- } else { // either "null" or OTHER
- other.setArmed(true);
- setPressed(true);
- setSelected(true);
- }
- }
- /**
- * The current state is embedded in the selection / armed
- * state of the model.
- *
- * We return the SELECTED state when the checkbox is selected
- * but not armed, DONT_CARE state when the checkbox is
- * selected and armed (grey) and NOT_SELECTED when the
- * checkbox is deselected.
- */
- private State getState() {
- if (isSelected() && !isArmed()) {
- // normal black tick
- return State.SELECTED;
- } else if (isSelected() && isArmed()) {
- // don't care grey tick
- return State.OTHER;
- } else {
- // normal deselected
- return State.NOT_SELECTED;
- }
- }
- /** Filter: No one may change the armed status except us. */
- public void setArmed(boolean b) {
- }
- /** We disable focusing on the component when it is not
- * enabled. */
- public void setEnabled(boolean b) {
- setFocusable(b);
- other.setEnabled(b);
- }
- /** All these methods simply delegate to the "other" model
- * that is being decorated. */
- public boolean isArmed() { return other.isArmed(); }
- public boolean isSelected() { return other.isSelected(); }
- public boolean isEnabled() { return other.isEnabled(); }
- public boolean isPressed() { return other.isPressed(); }
- public boolean isRollover() { return other.isRollover(); }
- public void setSelected(boolean b) { other.setSelected(b); }
- public void setPressed(boolean b) { other.setPressed(b); }
- public void setRollover(boolean b) { other.setRollover(b); }
- public void setMnemonic(int key) { other.setMnemonic(key); }
- public int getMnemonic() { return other.getMnemonic(); }
- public void setActionCommand(String s) {
- other.setActionCommand(s);
- }
- public String getActionCommand() {
- return other.getActionCommand();
- }
- public void setGroup(ButtonGroup group) {
- other.setGroup(group);
- }
- public void addActionListener(ActionListener l) {
- other.addActionListener(l);
- }
- public void removeActionListener(ActionListener l