This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 226998
Collapse All | Expand All

(-)a/ide.branding/options.api/src/org/netbeans/modules/options/export/Bundle_nb.properties (+2 lines)
Lines 2-4 Link Here
2
ImportConfirmationPanel.cbRestart.text=<html>&Restart IDE now<br>(without restart imported settings may not work)</html>
2
ImportConfirmationPanel.cbRestart.text=<html>&Restart IDE now<br>(without restart imported settings may not work)</html>
3
ImportConfirmationPanel.cbRestart.AD=Decide whether restart IDE now or later
3
ImportConfirmationPanel.cbRestart.AD=Decide whether restart IDE now or later
4
ImportConfirmationPanel.cbRestart.AN=Restart IDE now?
4
ImportConfirmationPanel.cbRestart.AN=Restart IDE now?
5
OPT_RestartAfterImport=true
6
(-)a/options.api/apichanges.xml (+22 lines)
Lines 75-80 Link Here
75
<!-- ACTUAL CHANGES BEGIN HERE: -->
75
<!-- ACTUAL CHANGES BEGIN HERE: -->
76
76
77
<changes>
77
<changes>
78
    <change id="Import.restart">
79
        <api name="OptionsAPI"/>
80
        <summary>Should Import Require Restart?</summary>
81
        <version major="1" minor="34"/>
82
        <date day="11" month="3" year="2013"/>
83
        <author login="jtulach"/>
84
        <compatibility addition="yes">
85
            Compared to previous versions, the default changed - now 
86
            the restart is not needed. Applications can change that by using
87
            <a href="architecture-summary.html#branding-OPT_RestartAfterImport">
88
            this branding API</a> and specifying <code>false</code> as the value
89
            of associated key.
90
        </compatibility>
91
        <description>
92
            Should an import of settings require a restart? Some applications 
93
            need that, some don't. There is a 
94
            <a href="architecture-summary.html#branding-OPT_RestartAfterImport">
95
            branding API</a> to control such
96
            behavior now.
97
        </description>
98
        <issue number="226998"/>
99
    </change>
78
    <change id="OptionsDisplayer.openModal">
100
    <change id="OptionsDisplayer.openModal">
79
        <api name="OptionsAPI"/>
101
        <api name="OptionsAPI"/>
80
        <summary>API to control whether the options window should be modal or not when opened</summary>
102
        <summary>API to control whether the options window should be modal or not when opened</summary>
(-)a/options.api/arch.xml (+7 lines)
Lines 1144-1149 Link Here
1144
        can have the following structure
1144
        can have the following structure
1145
        <code>filePattern1#keyPattern1#|filePattern2|filePattern3#keyPattern3</code>.
1145
        <code>filePattern1#keyPattern1#|filePattern2|filePattern3#keyPattern3</code>.
1146
   </api>
1146
   </api>
1147
   <api category="devel" group="branding" name="OPT_RestartAfterImport" type="export">
1148
       By default importing settings (as described by <a href="layer-OptionsExportLayers">OptionsExport</a>
1149
       API does not require restart. Some systems may however support complex
1150
       modifications to the installation structure. Then they should brand the 
1151
       <code>OPT_RestartAfterImport</code> to <code>true</code>. NetBeans IDE
1152
       does require restart after settings import.
1153
   </api>
1147
  </p>
1154
  </p>
1148
 </answer>
1155
 </answer>
1149
1156
(-)a/options.api/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.modules.options.api/1
2
OpenIDE-Module: org.netbeans.modules.options.api/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/options/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/options/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/options/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/options/resources/mf-layer.xml
5
OpenIDE-Module-Specification-Version: 1.33
5
OpenIDE-Module-Specification-Version: 1.34
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
(-)a/options.api/src/org/netbeans/modules/options/export/OptionsChooserPanel.java (-8 / +24 lines)
Lines 76-81 Link Here
76
import org.openide.awt.Mnemonics;
76
import org.openide.awt.Mnemonics;
77
import org.openide.awt.NotificationDisplayer;
77
import org.openide.awt.NotificationDisplayer;
78
import org.openide.filesystems.FileChooserBuilder;
78
import org.openide.filesystems.FileChooserBuilder;
79
import org.openide.filesystems.FileStateInvalidException;
80
import org.openide.filesystems.FileUtil;
79
import org.openide.modules.Places;
81
import org.openide.modules.Places;
80
import org.openide.util.Exceptions;
82
import org.openide.util.Exceptions;
81
import org.openide.util.ImageUtilities;
83
import org.openide.util.ImageUtilities;
Lines 224-229 Link Here
224
        }
226
        }
225
    }
227
    }
226
228
229
    @NbBundle.Messages({
230
        "OPT_RestartAfterImport=false"
231
    })
227
    /** Shows panel for import of options. */
232
    /** Shows panel for import of options. */
228
    public static void showImportDialog() {
233
    public static void showImportDialog() {
229
        LOGGER.fine("showImportDialog");  //NOI18N
234
        LOGGER.fine("showImportDialog");  //NOI18N
Lines 244-254 Link Here
244
                null);
249
                null);
245
        dd.createNotificationLineSupport();
250
        dd.createNotificationLineSupport();
246
        dd.setValid(false);
251
        dd.setValid(false);
252
        boolean ok;
253
        final boolean willRestart = "true".equals(Bundle.OPT_RestartAfterImport()); // NOI18N
247
        final ImportConfirmationPanel confirmationPanel = new ImportConfirmationPanel();
254
        final ImportConfirmationPanel confirmationPanel = new ImportConfirmationPanel();
248
        dd.setButtonListener(new ActionListener() {
255
        dd.setButtonListener(new ActionListener() {
249
250
            public void actionPerformed(ActionEvent e) {
256
            public void actionPerformed(ActionEvent e) {
251
                if (e.getSource() == DialogDescriptor.OK_OPTION) {
257
                if (willRestart && e.getSource() == DialogDescriptor.OK_OPTION) {
252
                    // show confirmation dialog when user click OK
258
                    // show confirmation dialog when user click OK
253
                    confirmationPanel.showConfirmation();
259
                    confirmationPanel.showConfirmation();
254
                }
260
                }
Lines 256-267 Link Here
256
        });
262
        });
257
        optionsChooserPanel.setDialogDescriptor(dd);
263
        optionsChooserPanel.setDialogDescriptor(dd);
258
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
264
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
259
265
        ok = DialogDescriptor.OK_OPTION.equals(dd.getValue());
260
        if (DialogDescriptor.OK_OPTION.equals(dd.getValue())) {
266
        if (willRestart) {
261
            if (!confirmationPanel.confirmed()) {
267
            if (!confirmationPanel.confirmed()) {
262
                LOGGER.fine("Import canceled.");  //NOI18N
268
                LOGGER.fine("Import canceled.");  //NOI18N
263
                return;
269
                ok = false;
264
            }
270
            }
271
        }
272
273
        if (ok) {
265
            // do import
274
            // do import
266
            File targetUserdir = Places.getUserDirectory();
275
            File targetUserdir = Places.getUserDirectory();
267
            try {
276
            try {
Lines 274-282 Link Here
274
                return;
283
                return;
275
            }
284
            }
276
            LOGGER.fine("Import finished.");  //NOI18N
285
            LOGGER.fine("Import finished.");  //NOI18N
277
            // restart IDE
286
            if (willRestart) { // NOI18N
278
            LifecycleManager.getDefault().markForRestart();
287
                // restart IDE
279
            LifecycleManager.getDefault().exit();
288
                LifecycleManager.getDefault().markForRestart();
289
                LifecycleManager.getDefault().exit();
290
            }
291
            try {
292
                FileUtil.getConfigRoot().getFileSystem().refresh(true);
293
            } catch (FileStateInvalidException ex) {
294
                Exceptions.printStackTrace(ex);
295
            }
280
        }
296
        }
281
    }
297
    }
282
298
(-)a/options.api/src/org/netbeans/modules/options/export/OptionsExportModel.java (-43 / +33 lines)
Lines 43-48 Link Here
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.io.FileInputStream;
45
import java.io.FileInputStream;
46
import java.io.FileNotFoundException;
46
import java.io.FileOutputStream;
47
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.io.IOException;
48
import java.io.InputStream;
49
import java.io.InputStream;
Lines 175-219 Link Here
175
    void doImport(File targetUserdir) throws IOException {
176
    void doImport(File targetUserdir) throws IOException {
176
        LOGGER.fine("Copying from: " + source + "\n    to: " + targetUserdir);  //NOI18N
177
        LOGGER.fine("Copying from: " + source + "\n    to: " + targetUserdir);  //NOI18N
177
        this.targetUserdir = targetUserdir;
178
        this.targetUserdir = targetUserdir;
178
        FileUtil.getConfigRoot().addRecursiveListener(new FileChangeListener() {
179
180
            @Override
181
            public void fileFolderCreated(FileEvent fe) {
182
                String path = fe.getFile().getPath();
183
                Preferences pref = Preferences.userRoot().node(path);
184
            }
185
186
            @Override
187
            public void fileDataCreated(FileEvent fe) {
188
                String path = fe.getFile().getPath();
189
                Preferences pref = NbPreferences.root().node("config").node(path);
190
            }
191
192
            @Override
193
            public void fileChanged(FileEvent fe) {
194
                String path = fe.getFile().getPath();
195
                Preferences pref = NbPreferences.root().node("config").node(path);
196
            }
197
198
            @Override
199
            public void fileDeleted(FileEvent fe) {
200
                String path = fe.getFile().getPath();
201
                Preferences pref = NbPreferences.root().node("config").node(path);
202
                try {
203
                    pref.removeNode();
204
                } catch (BackingStoreException ex) {
205
                    Exceptions.printStackTrace(ex);
206
                }
207
            }
208
209
            @Override
210
            public void fileRenamed(FileRenameEvent fe) {
211
            }
212
213
            @Override
214
            public void fileAttributeChanged(FileAttributeEvent fe) {
215
            }
216
        });
217
        copyFiles();
179
        copyFiles();
218
    }
180
    }
219
181
Lines 225-231 Link Here
225
        try {
187
        try {
226
            ensureParent(targetZipFile);
188
            ensureParent(targetZipFile);
227
            // Create the ZIP file
189
            // Create the ZIP file
228
            zipOutputStream = new ZipOutputStream(new FileOutputStream(targetZipFile));
190
            zipOutputStream = new ZipOutputStream(createOutputStream(targetZipFile));
229
            copyFiles();
191
            copyFiles();
230
            createProductInfo(zipOutputStream);
192
            createProductInfo(zipOutputStream);
231
            // Complete the ZIP file
193
            // Complete the ZIP file
Lines 869-875 Link Here
869
            if (includeKeys.isEmpty() && excludeKeys.isEmpty()) {
831
            if (includeKeys.isEmpty() && excludeKeys.isEmpty()) {
870
                // copy entire file
832
                // copy entire file
871
                try {
833
                try {
872
                    out = new FileOutputStream(targetFile);
834
                    out = createOutputStream(targetFile);
873
                    copyFile(relativePath, out);
835
                    copyFile(relativePath, out);
874
                } finally {
836
                } finally {
875
                    if (out != null) {
837
                    if (out != null) {
Lines 915-921 Link Here
915
        }
877
        }
916
        OutputStream out = null;
878
        OutputStream out = null;
917
        try {
879
        try {
918
            out = new FileOutputStream(targetFile);
880
            out = createOutputStream(targetFile);
919
            targetProperties.store(out);
881
            targetProperties.store(out);
920
        } finally {
882
        } finally {
921
            if (out != null) {
883
            if (out != null) {
Lines 1041-1047 Link Here
1041
        ZipOutputStream out = null;
1003
        ZipOutputStream out = null;
1042
        try {
1004
        try {
1043
            // Create the ZIP file
1005
            // Create the ZIP file
1044
            out = new ZipOutputStream(new FileOutputStream(targetFile));
1006
            out = new ZipOutputStream(createOutputStream(targetFile));
1045
            // Compress the files
1007
            // Compress the files
1046
            for (String relativePath : relativePaths) {
1008
            for (String relativePath : relativePaths) {
1047
                LOGGER.finest("Adding to zip: " + relativePath);  //NOI18N
1009
                LOGGER.finest("Adding to zip: " + relativePath);  //NOI18N
Lines 1091-1094 Link Here
1091
        // Complete the entry
1053
        // Complete the entry
1092
        out.closeEntry();
1054
        out.closeEntry();
1093
    }
1055
    }
1056
    
1057
    private static OutputStream createOutputStream(File file) throws IOException {
1058
        if (containsConfig(file)) {
1059
            file = file.getCanonicalFile();
1060
            File root = FileUtil.toFile(FileUtil.getConfigRoot());
1061
            String filePath = file.getPath();
1062
            String rootPath = root.getPath();
1063
            if (filePath.startsWith(rootPath)) {
1064
                String res = filePath.substring(rootPath.length()).replace(File.separatorChar, '/');
1065
                FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), res);
1066
                if (fo != null) {
1067
                    return fo.getOutputStream();
1068
                }
1069
            }
1070
        }
1071
        return new FileOutputStream(file);
1072
    }
1073
    private static boolean containsConfig(File file) {
1074
        for (;;) {
1075
            if (file == null) {
1076
                return false;
1077
            }
1078
            if (file.getName().equals("config")) {
1079
                return true;
1080
            }
1081
            file = file.getParentFile();
1082
        }
1083
    }
1094
}
1084
}

Return to bug 226998