diff -r 88aa0cbd3ea5 ide.branding/options.api/src/org/netbeans/modules/options/export/Bundle_nb.properties --- a/ide.branding/options.api/src/org/netbeans/modules/options/export/Bundle_nb.properties Mon Mar 04 18:32:55 2013 +0100 +++ b/ide.branding/options.api/src/org/netbeans/modules/options/export/Bundle_nb.properties Mon Mar 04 21:12:10 2013 +0100 @@ -2,3 +2,5 @@ ImportConfirmationPanel.cbRestart.text=&Restart IDE now
(without restart imported settings may not work) ImportConfirmationPanel.cbRestart.AD=Decide whether restart IDE now or later ImportConfirmationPanel.cbRestart.AN=Restart IDE now? +OPT_RestartAfterImport=true + diff -r 88aa0cbd3ea5 options.api/apichanges.xml --- a/options.api/apichanges.xml Mon Mar 04 18:32:55 2013 +0100 +++ b/options.api/apichanges.xml Mon Mar 04 21:12:10 2013 +0100 @@ -75,6 +75,28 @@ + + + Should Import Require Restart? + + + + + Compared to previous versions, the default changed - now + the restart is not needed. Applications can change that by using + + this branding API and specifying false as the value + of associated key. + + + Should an import of settings require a restart? Some applications + need that, some don't. There is a + + branding API to control such + behavior now. + + + API to control whether the options window should be modal or not when opened diff -r 88aa0cbd3ea5 options.api/arch.xml --- a/options.api/arch.xml Mon Mar 04 18:32:55 2013 +0100 +++ b/options.api/arch.xml Mon Mar 04 21:12:10 2013 +0100 @@ -1144,6 +1144,13 @@ can have the following structure filePattern1#keyPattern1#|filePattern2|filePattern3#keyPattern3. + + By default importing settings (as described by OptionsExport + API does not require restart. Some systems may however support complex + modifications to the installation structure. Then they should brand the + OPT_RestartAfterImport to true. NetBeans IDE + does require restart after settings import. +

diff -r 88aa0cbd3ea5 options.api/manifest.mf --- a/options.api/manifest.mf Mon Mar 04 18:32:55 2013 +0100 +++ b/options.api/manifest.mf Mon Mar 04 21:12:10 2013 +0100 @@ -2,6 +2,6 @@ OpenIDE-Module: org.netbeans.modules.options.api/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/options/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/options/resources/mf-layer.xml -OpenIDE-Module-Specification-Version: 1.33 +OpenIDE-Module-Specification-Version: 1.34 AutoUpdate-Show-In-Client: false AutoUpdate-Essential-Module: true diff -r 88aa0cbd3ea5 options.api/src/org/netbeans/modules/options/export/OptionsChooserPanel.java --- a/options.api/src/org/netbeans/modules/options/export/OptionsChooserPanel.java Mon Mar 04 18:32:55 2013 +0100 +++ b/options.api/src/org/netbeans/modules/options/export/OptionsChooserPanel.java Mon Mar 04 21:12:10 2013 +0100 @@ -76,6 +76,8 @@ import org.openide.awt.Mnemonics; import org.openide.awt.NotificationDisplayer; import org.openide.filesystems.FileChooserBuilder; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileUtil; import org.openide.modules.Places; import org.openide.util.Exceptions; import org.openide.util.ImageUtilities; @@ -224,6 +226,9 @@ } } + @NbBundle.Messages({ + "OPT_RestartAfterImport=false" + }) /** Shows panel for import of options. */ public static void showImportDialog() { LOGGER.fine("showImportDialog"); //NOI18N @@ -244,11 +249,12 @@ null); dd.createNotificationLineSupport(); dd.setValid(false); + boolean ok; + final boolean willRestart = "true".equals(Bundle.OPT_RestartAfterImport()); // NOI18N final ImportConfirmationPanel confirmationPanel = new ImportConfirmationPanel(); dd.setButtonListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (e.getSource() == DialogDescriptor.OK_OPTION) { + if (willRestart && e.getSource() == DialogDescriptor.OK_OPTION) { // show confirmation dialog when user click OK confirmationPanel.showConfirmation(); } @@ -256,12 +262,15 @@ }); optionsChooserPanel.setDialogDescriptor(dd); DialogDisplayer.getDefault().createDialog(dd).setVisible(true); - - if (DialogDescriptor.OK_OPTION.equals(dd.getValue())) { + ok = DialogDescriptor.OK_OPTION.equals(dd.getValue()); + if (willRestart) { if (!confirmationPanel.confirmed()) { LOGGER.fine("Import canceled."); //NOI18N - return; + ok = false; } + } + + if (ok) { // do import File targetUserdir = Places.getUserDirectory(); try { @@ -274,9 +283,16 @@ return; } LOGGER.fine("Import finished."); //NOI18N - // restart IDE - LifecycleManager.getDefault().markForRestart(); - LifecycleManager.getDefault().exit(); + if (willRestart) { // NOI18N + // restart IDE + LifecycleManager.getDefault().markForRestart(); + LifecycleManager.getDefault().exit(); + } + try { + FileUtil.getConfigRoot().getFileSystem().refresh(true); + } catch (FileStateInvalidException ex) { + Exceptions.printStackTrace(ex); + } } } diff -r 88aa0cbd3ea5 options.api/src/org/netbeans/modules/options/export/OptionsExportModel.java --- a/options.api/src/org/netbeans/modules/options/export/OptionsExportModel.java Mon Mar 04 18:32:55 2013 +0100 +++ b/options.api/src/org/netbeans/modules/options/export/OptionsExportModel.java Mon Mar 04 21:12:10 2013 +0100 @@ -43,6 +43,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -175,45 +176,6 @@ void doImport(File targetUserdir) throws IOException { LOGGER.fine("Copying from: " + source + "\n to: " + targetUserdir); //NOI18N this.targetUserdir = targetUserdir; - FileUtil.getConfigRoot().addRecursiveListener(new FileChangeListener() { - - @Override - public void fileFolderCreated(FileEvent fe) { - String path = fe.getFile().getPath(); - Preferences pref = Preferences.userRoot().node(path); - } - - @Override - public void fileDataCreated(FileEvent fe) { - String path = fe.getFile().getPath(); - Preferences pref = NbPreferences.root().node("config").node(path); - } - - @Override - public void fileChanged(FileEvent fe) { - String path = fe.getFile().getPath(); - Preferences pref = NbPreferences.root().node("config").node(path); - } - - @Override - public void fileDeleted(FileEvent fe) { - String path = fe.getFile().getPath(); - Preferences pref = NbPreferences.root().node("config").node(path); - try { - pref.removeNode(); - } catch (BackingStoreException ex) { - Exceptions.printStackTrace(ex); - } - } - - @Override - public void fileRenamed(FileRenameEvent fe) { - } - - @Override - public void fileAttributeChanged(FileAttributeEvent fe) { - } - }); copyFiles(); } @@ -225,7 +187,7 @@ try { ensureParent(targetZipFile); // Create the ZIP file - zipOutputStream = new ZipOutputStream(new FileOutputStream(targetZipFile)); + zipOutputStream = new ZipOutputStream(createOutputStream(targetZipFile)); copyFiles(); createProductInfo(zipOutputStream); // Complete the ZIP file @@ -869,7 +831,7 @@ if (includeKeys.isEmpty() && excludeKeys.isEmpty()) { // copy entire file try { - out = new FileOutputStream(targetFile); + out = createOutputStream(targetFile); copyFile(relativePath, out); } finally { if (out != null) { @@ -915,7 +877,7 @@ } OutputStream out = null; try { - out = new FileOutputStream(targetFile); + out = createOutputStream(targetFile); targetProperties.store(out); } finally { if (out != null) { @@ -1041,7 +1003,7 @@ ZipOutputStream out = null; try { // Create the ZIP file - out = new ZipOutputStream(new FileOutputStream(targetFile)); + out = new ZipOutputStream(createOutputStream(targetFile)); // Compress the files for (String relativePath : relativePaths) { LOGGER.finest("Adding to zip: " + relativePath); //NOI18N @@ -1091,4 +1053,32 @@ // Complete the entry out.closeEntry(); } + + private static OutputStream createOutputStream(File file) throws IOException { + if (containsConfig(file)) { + file = file.getCanonicalFile(); + File root = FileUtil.toFile(FileUtil.getConfigRoot()); + String filePath = file.getPath(); + String rootPath = root.getPath(); + if (filePath.startsWith(rootPath)) { + String res = filePath.substring(rootPath.length()).replace(File.separatorChar, '/'); + FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), res); + if (fo != null) { + return fo.getOutputStream(); + } + } + } + return new FileOutputStream(file); + } + private static boolean containsConfig(File file) { + for (;;) { + if (file == null) { + return false; + } + if (file.getName().equals("config")) { + return true; + } + file = file.getParentFile(); + } + } }