Java Code Examples for org.openide.util.NbPreferences#forModule()

The following examples show how to use org.openide.util.NbPreferences#forModule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistorySettings.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void migrate() { 
    // migrate pre 7.2 settings 
    String prevPath = "org/netbeans/modules/localhistory"; // NOI18N
    try {
        if(!NbPreferences.root().nodeExists(prevPath)) {
            return;
        }
        Preferences prev = NbPreferences.root().node(prevPath);
        Preferences cur =  NbPreferences.forModule(HistorySettings.class);
        String[] keys = prev.keys();
        for (String key : keys) {
            String value = prev.get(key, null);
            if(value != null && cur.get(key, null) == null) {
                cur.put(key, value);
            }
        }
        prev.removeNode();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
    
}
 
Example 2
Source File: FormattingSettingsFromNbPreferences.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Preferences getNbPreferences(String mimeType) {
    Preferences prefs = null;

    String className = affectedMimeTypes.get(mimeType);
    if (className != null) {
        ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class);
        if (loader != null) {
            try {
                Class<?> clazz = loader.loadClass(className);
                prefs = NbPreferences.forModule(clazz);
            } catch (ClassNotFoundException ex) {
                // ignore
                LOG.log(Level.FINE, null, ex);
            }
        }
    }

    return prefs;
}
 
Example 3
Source File: InjectSpringBootGenerator.java    From nb-springboot with Apache License 2.0 6 votes vote down vote up
private void createNbActions(FileObject dir) throws IOException {
    if (dir == null) {
        return;
    }
    // retrieve default options from prefs
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    final boolean bForceColor = prefs.getBoolean(PrefConstants.PREF_FORCE_COLOR_OUTPUT, true);
    final boolean bManualRestart = prefs.getBoolean(PrefConstants.PREF_MANUAL_RESTART, false);
    final String strVmOpts = Utils.vmOptsFromPrefs();
    // use template file from Initializr Spring Boot wizard
    FileObject foTmpl = FileUtil.getConfigFile("/Templates/Project/Maven2/initializr-nbactions.xml");
    FileBuilder fb = new FileBuilder(foTmpl, dir)
            .name("nbactions")
            .param("forceColor", bForceColor)
            .param("manualRestart", bManualRestart)
            .param("isBoot2", BasicProjectWizardIterator.BOOTVERSION.startsWith("2"))
            .param("vmOpts", strVmOpts);
    fb.build();
}
 
Example 4
Source File: InstallLibraryTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override
void run() {
    Preferences p = NbPreferences.forModule(InstallLibraryTask.class);
    if (p.getBoolean(KEY, false)) {
        // Only check once (i.e. on first start for a fresh user dir).
        return;
    }
    p.putBoolean(KEY, true);
    // find licenseAcceptedFile
    File licenseAcceptedFile = InstalledFileLocator.getDefault().locate("var/license_accepted", null, false); // NOI18N
    if (licenseAcceptedFile == null) {
        LOG.info("$userdir/var/license_accepted not found => skipping install JUnit.");
        return ;
    }
    try {
        // read content of file
        String content = FileUtil.toFileObject(licenseAcceptedFile).asText();
        LOG.fine("Content of $userdir/var/license_accepted: " + content);
        if (content != null && content.indexOf(JUNIT_APPROVED) != -1) {
            // IDE license accepted, JUnit accpeted => let's install silently
            LOG.fine(" IDE license accepted, JUnit accepted => let's install silently"); 
            JUnitLibraryInstaller.install(true);
        } else if (content != null && content.indexOf(JUNIT_DENIED) != -1) {
            // IDE license accepted but JUnit disapproved => do nothing
            LOG.fine("IDE license accepted but JUnit disapproved => do nothing"); 
        } else {
            // IDE license accepted, JUnit N/A => use prompt & wizard way
            LOG.fine("IDE license accepted, JUnit N/A => use prompt & wizard way"); 
            RP.post(new Runnable() {

                @Override
                public void run() {
                    JUnitLibraryInstaller.install(false);
                }
            });
        }
    } catch (IOException ex) {
        LOG.log(Level.INFO, "while reading " + licenseAcceptedFile, ex);
    }
}
 
Example 5
Source File: ImportManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void dontRemind () {
    Preferences p = NbPreferences.forModule (Installer.class);
    try {
        p.clear ();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace (ex);
    }
}
 
Example 6
Source File: BootPrefsPanel.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
void load() {
    // read settings and initialize GUI
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    txInitializrUrl.setText(prefs.get(PrefConstants.PREF_INITIALIZR_URL, PrefConstants.DEFAULT_INITIALIZR_URL));
    txVmOpts.setText(prefs.get(PrefConstants.PREF_VM_OPTS, ""));
    spInitializrTimeout.setValue(prefs.getInt(PrefConstants.PREF_INITIALIZR_TIMEOUT, 30));
    chColorOutput.setSelected(prefs.getBoolean(PrefConstants.PREF_FORCE_COLOR_OUTPUT, true));
    chDevtoolsTrigger.setSelected(prefs.getBoolean(PrefConstants.PREF_MANUAL_RESTART, false));
    chVmOptsLaunch.setSelected(prefs.getBoolean(PrefConstants.PREF_VM_OPTS_LAUNCH, true));
    chDeprSortLast.setSelected(prefs.getBoolean(PrefConstants.PREF_DEPR_SORT_LAST, true));
    chDeprErrorShow.setSelected(prefs.getBoolean(PrefConstants.PREF_DEPR_ERROR_SHOW, true));
    chArrayNotation.setSelected(prefs.getBoolean(PrefConstants.PREF_ARRAY_NOTATION, false));
    cbDtMismatch.setSelectedIndex(prefs.getInt(PrefConstants.PREF_HLIGHT_LEV_DTMISMATCH, 2));
    cbDupl.setSelectedIndex(prefs.getInt(PrefConstants.PREF_HLIGHT_LEV_DUPLICATES, 1));
    cbSynErr.setSelectedIndex(prefs.getInt(PrefConstants.PREF_HLIGHT_LEV_SYNERR, 2));
    cbUnknown.setSelectedIndex(prefs.getInt(PrefConstants.PREF_HLIGHT_LEV_UNKNOWN, 1));
    cbDeprecated.setSelectedIndex(prefs.getInt(PrefConstants.PREF_HLIGHT_LEV_DEPRECATED, 1));
    // listen to changes in form fields and call controller.changed()
    // Register listener on the textFields to detect changes
    txInitializrUrl.getDocument().addDocumentListener(this);
    txVmOpts.getDocument().addDocumentListener(this);
    spInitializrTimeout.addChangeListener(this);
    chColorOutput.addActionListener(this);
    chDevtoolsTrigger.addActionListener(this);
    chVmOptsLaunch.addActionListener(this);
    chDeprSortLast.addActionListener(this);
    chDeprErrorShow.addActionListener(this);
    cbDtMismatch.addActionListener(this);
    cbDupl.addActionListener(this);
    cbSynErr.addActionListener(this);
    cbUnknown.addActionListener(this);
    cbDeprecated.addActionListener(this);
}
 
Example 7
Source File: ToggleFreezeGraphViewAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent event) {
    graphFrozen = !PreferenceUtilites.isGraphViewFrozen();

    // update the preference and icon
    final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
    prefs.put(ApplicationPreferenceKeys.FREEZE_GRAPH_VIEW, String.valueOf(graphFrozen));
    putValue(Action.NAME, graphFrozen
            ? NbBundle.getMessage(ToggleFreezeGraphViewAction.class, "CTL_UnfreezeGraphViewListenerAction")
            : NbBundle.getMessage(ToggleFreezeGraphViewAction.class, "CTL_FreezeGraphViewListenerAction"));
    putValue(Action.SMALL_ICON, graphFrozen ? ICON_ON : ICON_OFF);
}
 
Example 8
Source File: ErrorCheckingSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void setErrorCheckingEnabledForMimetype(String mimeType, boolean enabled) {
    Preferences prefs = NbPreferences.forModule(ErrorCheckingSupport.class);
    Preferences user = prefs.node(ErrorCheckingSupport.class.getName());
    if (isHtmlMimeType(mimeType) && enabled) {
        user.remove(mimeType);
    } else {
        user.putBoolean(mimeType, enabled);
    }
}
 
Example 9
Source File: GraphOptionsPanelController.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void update() {
    final Preferences prefs = NbPreferences.forModule(GraphPreferenceKeys.class);
    final GraphOptionsPanel graphOptionsPanel = getPanel();

    // grabbing blaze size from preferences file, reverting to default if none found
    graphOptionsPanel.setBlazeSize(prefs.getInt(GraphPreferenceKeys.BLAZE_SIZE, GraphPreferenceKeys.BLAZE_SIZE_DEFAULT));
    graphOptionsPanel.setBlazeOpacity(prefs.getInt(GraphPreferenceKeys.BLAZE_OPACITY, GraphPreferenceKeys.BLAZE_OPACITY_DEFAULT));

}
 
Example 10
Source File: UserDirectoryAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
    final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
    final String userDir = ApplicationPreferenceKeys.getUserDir(prefs);
    try {
        Desktop.getDesktop().open(new File(userDir));
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 11
Source File: WhereUsedPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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() {

    buttonGroup = new javax.swing.ButtonGroup();
    innerPanel = new javax.swing.JPanel();
    scope = new org.netbeans.modules.refactoring.spi.ui.ScopePanel(WhereUsedPanel.class.getCanonicalName().replace('.', '-'), NbPreferences.forModule(WhereUsedPanel.class), "whereUsed.scope", parent);
    jLabel1 = new javax.swing.JLabel();

    innerPanel.setLayout(new java.awt.BorderLayout());

    jLabel1.setLabelFor(scope);
    org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(WhereUsedPanel.class, "LBL_Scope")); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addGap(0, 0, 0)
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(scope, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
            .addGap(0, 0, 0))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(scope, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGap(0, 0, 0))
    );
}
 
Example 12
Source File: FeedbackSurvey.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean showDialog(URL whereTo) {
    String msg = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Message");
    String tit = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Title");
    String yes = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Yes");
    String later = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Later");
    String never = NbBundle.getMessage(FeedbackSurvey.class, "MSG_FeedbackSurvey_Never");
    
    NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.QUESTION_MESSAGE);
    nd.setTitle(tit);
    //Object[] buttons = { yes, later, never };
    JButton yesButton = new JButton();
    yesButton.getAccessibleContext().setAccessibleDescription( 
            NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Yes"));
    Mnemonics.setLocalizedText(yesButton, yes);
    JButton laterButton = new JButton();
    laterButton.getAccessibleContext().setAccessibleDescription( 
            NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Later"));
    Mnemonics.setLocalizedText(laterButton, later);
    JButton neverButton = new JButton();
    neverButton.getAccessibleContext().setAccessibleDescription( 
            NbBundle.getMessage(FeedbackSurvey.class, "ACSD_FeedbackSurvey_Never"));
    Mnemonics.setLocalizedText(neverButton, never);
    Object[] buttons = { yesButton, laterButton, neverButton };
    nd.setOptions(buttons);
    Object res = DialogDisplayer.getDefault().notify(nd);
    
    if (res == yesButton) {
        HtmlBrowser.URLDisplayer.getDefault().showURL(whereTo);
        return true;
    } else {
        if( res == neverButton ) {
            Preferences prefs = NbPreferences.forModule(FeedbackSurvey.class);
            prefs.putInt("feedback.survey.show.count", (int)bundledInt("MSG_FeedbackSurvey_AskTimes")); // NOI18N
        }
        return false;
    }
}
 
Example 13
Source File: InternalSourceAppearance.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
boolean currentSettingsDirty() {
    if (settingsPanel == null) return false;
    
    Preferences settings = NbPreferences.forModule(InternalSourceAppearance.class);
    if (!currentFontName().equals(savedFontName(settings))) return true;
    if (currentFontStyle() != savedFontStyle(settings)) return true;
    if (currentFontSize() != savedFontSize(settings)) return true;
    
    return false;
}
 
Example 14
Source File: RecentParameterValuesNGTest.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Test of saveToPreferences method, of class RecentParameterValues.
 */
@Test
public void testSaveToPreferences() {
    final Preferences prefs = NbPreferences.forModule(RecentParameterValuesKey.class);
    prefs.put(RecentParameterValuesKey.RECENT_VALUES, recentValues);
    RecentParameterValues.loadFromPreference();
    RecentParameterValues.saveToPreferences();
    final List<String> result = RecentParameterValues.getRecentValues("TestChainer.planets");
    final String expResult = "Mercury\\nVenus\\n✓ Earth\\nMars\\nJupiter\\nSaturn\\nUranus\\nNeptune\\nCoruscant";
    Assert.assertEquals(result.get(0), expResult);
}
 
Example 15
Source File: DiffSidebarManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
Preferences getPreferences() {
    return NbPreferences.forModule(DiffSidebarManager.class);
}
 
Example 16
Source File: BugzillaConfig.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Preferences getPreferences() {
    return NbPreferences.forModule(BugzillaConfig.class);
}
 
Example 17
Source File: DefaultRestDirectory.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public Path getRESTDirectory() {
    final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
    return Paths.get(ApplicationPreferenceKeys.getUserDir(prefs), "REST");
}
 
Example 18
Source File: ModuleUISettings.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Preferences prefs() {
    return NbPreferences.forModule(ModuleUISettings.class);
}
 
Example 19
Source File: SQLOptions.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Preferences getPreferences() {
    return NbPreferences.forModule(SQLOptions.class);
}
 
Example 20
Source File: GrailsSettings.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Preferences getPreferences() {
    return NbPreferences.forModule(GrailsSettings.class);
}