Option to show the configuration dialog to specify enabled hints.
1.1 --- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Thu Jun 21 09:54:39 2012 +0200
1.2 +++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java Thu Jun 21 09:56:13 2012 +0200
1.3 @@ -39,6 +39,9 @@
1.4
1.5 package org.netbeans.modules.jackpot30.cmdline;
1.6
1.7 +import java.awt.BorderLayout;
1.8 +import java.awt.event.ActionEvent;
1.9 +import java.awt.event.ActionListener;
1.10 import java.io.BufferedWriter;
1.11 import java.io.File;
1.12 import java.io.FileOutputStream;
1.13 @@ -46,6 +49,7 @@
1.14 import java.io.OutputStreamWriter;
1.15 import java.io.PrintStream;
1.16 import java.io.Writer;
1.17 +import java.lang.reflect.InvocationTargetException;
1.18 import java.net.URL;
1.19 import java.util.ArrayList;
1.20 import java.util.Arrays;
1.21 @@ -61,8 +65,14 @@
1.22 import java.util.concurrent.atomic.AtomicBoolean;
1.23 import java.util.logging.Level;
1.24 import java.util.logging.Logger;
1.25 +import java.util.prefs.BackingStoreException;
1.26 import java.util.prefs.Preferences;
1.27 import java.util.regex.Pattern;
1.28 +import javax.swing.JCheckBox;
1.29 +import javax.swing.JDialog;
1.30 +import javax.swing.JOptionPane;
1.31 +import javax.swing.JPanel;
1.32 +import javax.swing.SwingUtilities;
1.33 import javax.swing.event.ChangeListener;
1.34 import joptsimple.ArgumentAcceptingOptionSpec;
1.35 import joptsimple.OptionException;
1.36 @@ -86,7 +96,9 @@
1.37 import org.netbeans.modules.java.hints.spiimpl.batch.ProgressHandleWrapper;
1.38 import org.netbeans.modules.java.hints.spiimpl.batch.ProgressHandleWrapper.ProgressHandleAbstraction;
1.39 import org.netbeans.modules.java.hints.spiimpl.batch.Scopes;
1.40 +import org.netbeans.modules.java.hints.spiimpl.options.HintsPanel;
1.41 import org.netbeans.modules.java.hints.spiimpl.options.HintsSettings;
1.42 +import org.netbeans.modules.java.hints.spiimpl.refactoring.Utilities.ClassPathBasedHintWrapper;
1.43 import org.netbeans.modules.java.source.parsing.JavaPathRecognizer;
1.44 import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
1.45 import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
1.46 @@ -98,6 +110,7 @@
1.47 import org.openide.filesystems.FileObject;
1.48 import org.openide.filesystems.FileStateInvalidException;
1.49 import org.openide.filesystems.FileUtil;
1.50 +import org.openide.util.Exceptions;
1.51 import org.openide.util.Lookup;
1.52 import org.openide.util.NbPreferences;
1.53 import org.openide.util.RequestProcessor;
1.54 @@ -141,6 +154,7 @@
1.55 parser.accepts("help", "prints this help");
1.56 parser.accepts(OPTION_NO_APPLY, "do not apply changes - only print locations were the hint would be applied");
1.57 parser.accepts(OPTION_APPLY, "apply changes");
1.58 + parser.accepts("show-gui", "show configuration dialog");
1.59
1.60 OptionSet parsed;
1.61
1.62 @@ -157,6 +171,34 @@
1.63 return 0;
1.64 }
1.65
1.66 + if (parsed.has("show-gui")) {
1.67 + if (parsed.has(configFile)) {
1.68 + final File settingsFile = parsed.valueOf(configFile);
1.69 + try {
1.70 + SwingUtilities.invokeAndWait(new Runnable() {
1.71 + @Override public void run() {
1.72 + try {
1.73 + showGUICustomizer(settingsFile);
1.74 + } catch (IOException ex) {
1.75 + Exceptions.printStackTrace(ex);
1.76 + } catch (BackingStoreException ex) {
1.77 + Exceptions.printStackTrace(ex);
1.78 + }
1.79 + }
1.80 + });
1.81 + } catch (InterruptedException ex) {
1.82 + Exceptions.printStackTrace(ex);
1.83 + } catch (InvocationTargetException ex) {
1.84 + Exceptions.printStackTrace(ex);
1.85 + }
1.86 +
1.87 + return 0;
1.88 + } else {
1.89 + System.err.println("show-gui requires config-file");
1.90 + return 1;
1.91 + }
1.92 + }
1.93 +
1.94 if (!parsed.has("debug")) {
1.95 prepareLoggers();
1.96 }
1.97 @@ -568,6 +610,37 @@
1.98 return ClassPathSupport.createClassPath(rootURLs.toArray(new URL[0]));
1.99 }
1.100
1.101 + private static void showGUICustomizer(File settings) throws IOException, BackingStoreException {
1.102 + final Preferences p = XMLHintPreferences.from(settings);
1.103 + JPanel hintPanel = new HintsPanel(p.node("settings"), new ClassPathBasedHintWrapper());
1.104 + final JCheckBox runDeclarativeHints = new JCheckBox("Run Declarative Rules");
1.105 +
1.106 + runDeclarativeHints.setToolTipText("Should the declarative rules found on classpath be run?");
1.107 + runDeclarativeHints.setSelected(p.getBoolean("runDeclarative", true));
1.108 + runDeclarativeHints.addActionListener(new ActionListener() {
1.109 + @Override public void actionPerformed(ActionEvent e) {
1.110 + p.putBoolean("runDeclarative", runDeclarativeHints.isSelected());
1.111 + }
1.112 + });
1.113 +
1.114 + JPanel customizer = new JPanel(new BorderLayout());
1.115 +
1.116 + customizer.add(hintPanel, BorderLayout.CENTER);
1.117 + customizer.add(runDeclarativeHints, BorderLayout.SOUTH);
1.118 + JOptionPane jop = new JOptionPane(customizer, JOptionPane.PLAIN_MESSAGE);
1.119 + JDialog dialog = jop.createDialog("Select Hints");
1.120 +
1.121 + jop.selectInitialValue();
1.122 + dialog.setVisible(true);
1.123 + dialog.dispose();
1.124 +
1.125 + Object result = jop.getValue();
1.126 +
1.127 + if (result.equals(JOptionPane.OK_OPTION)) {
1.128 + p.flush();
1.129 + }
1.130 + }
1.131 +
1.132 @ServiceProvider(service=Lookup.class)
1.133 public static final class LookupProviderImpl extends ProxyLookup {
1.134