miraged commented on issue #9201:
URL: https://github.com/apache/netbeans/issues/9201#issuecomment-5968733961
### Detailed Technical Analysis & Proposed Implementation
After investigating the FTP/SFTP synchronization workflow in Apache NetBeans
(specifically within the `php.project` and `web.clientproject` remote
synchronization modules), here is a complete breakdown of why the
**"Synchronization Options / Confirm Options"** dialog keeps reappearing
despite checking the *"Remember choice"* option, along with a concrete code
proposal for a fix.
---
### Root Cause Analysis
1. **Volatile Session Scope during Manual Sync (`remote.upload=MANUALLY`):**
When a project is set to manual upload (`remote.upload=MANUALLY`),
NetBeans treats each upload or synchronization action as an isolated, ad-hoc
runtime event. Checking the "Remember choice" checkbox writes the preference to
an in-memory runtime cache (`SyncOptions`). Once the transfer operation
finishes or the IDE state resets, this state is discarded instead of being
persisted to disk.
2. **Bypassing Project-Level Persistence:**
The option state is never saved to the project's private properties
(`nbproject/private/private.properties`). Consequently, every manual sync
action triggers the GUI controller to re-evaluate whether options are
remembered, defaulting to `false` on every fresh trigger.
3. **Operation Type Discrepancies:**
The sync controller evaluates custom profiles based on fine-grained
operation types (e.g., `EXPLICIT_UPLOAD` for single file actions vs.
`PROJECT_SYNC` for full tree syncs). Remembering a choice for single-file
transfers does not suppress the popup when performing multi-file or full
project syncs.
---
### Proposed Architectural Solution
To resolve this permanently, we need to:
1. Store suppression flags directly in the project's private preferences
store (`nbproject/private/private.properties`).
2. Check these preferences **prior** to rendering the `DialogDescriptor` UI.
3. Automatically apply the saved default action when dialog suppression is
enabled.
---
### Code Implementation Proposal
Below is a complete implementation example demonstrating how to encapsulate
persistent preferences and suppress the dialog in the synchronization workflow.
#### 1. Preference Handler (`RemoteSyncPreferences.java`)
Encapsulates reading and writing synchronization preferences to
`nbproject/private/private.properties`:
```java
package org.netbeans.modules.php.project.remote.sync;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import java.util.prefs.Preferences;
/**
* Handles persistent storage of remote synchronization dialog options in
private properties.
*/
public final class RemoteSyncPreferences {
public static final String PROP_SUPPRESS_SYNC_DIALOG =
"remote.sync.suppress.dialog"; // NOI18N
public static final String PROP_DEFAULT_SYNC_ACTION =
"remote.sync.default.action"; // NOI18N
public enum SyncAction {
OVERWRITE_REMOTE,
OVERWRITE_LOCAL,
SKIP
}
private RemoteSyncPreferences() {}
/**
* Retrieves the project's private preference node (stored in
nbproject/private/private.properties).
*/
private static Preferences getPrivatePreferences(Project project) {
return ProjectUtils.Preferences.getPreferences(project,
RemoteSyncPreferences.class, false);
}
public static boolean isDialogSuppressed(Project project) {
return
getPrivatePreferences(project).getBoolean(PROP_SUPPRESS_SYNC_DIALOG, false);
}
public static SyncAction getDefaultSyncAction(Project project) {
String actionStr =
getPrivatePreferences(project).get(PROP_DEFAULT_SYNC_ACTION,
SyncAction.OVERWRITE_REMOTE.name());
try {
return SyncAction.valueOf(actionStr);
} catch (IllegalArgumentException e) {
return SyncAction.OVERWRITE_REMOTE;
}
}
public static void saveSyncPreferences(Project project, boolean
suppressDialog, SyncAction defaultAction) {
Preferences prefs = getPrivatePreferences(project);
prefs.putBoolean(PROP_SUPPRESS_SYNC_DIALOG, suppressDialog);
if (defaultAction != null) {
prefs.put(PROP_DEFAULT_SYNC_ACTION, defaultAction.name());
}
}
public static void clearSyncPreferences(Project project) {
Preferences prefs = getPrivatePreferences(project);
prefs.remove(PROP_SUPPRESS_SYNC_DIALOG);
prefs.remove(PROP_DEFAULT_SYNC_ACTION);
}
}
```
#### 2. Synchronization Controller Integration (`SyncController.java`)
Updates the UI invocation logic to bypass dialog creation when suppression
is enabled:
```java
package org.netbeans.modules.php.project.remote.sync;
import org.netbeans.api.project.Project;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.util.NbBundle;
public class SyncController {
private final Project project;
public SyncController(Project project) {
this.project = project;
}
/**
* Entry point for processing manual synchronization requests.
*/
public void processManualSync() {
// Step 1: Pre-flight check for saved persistent preferences
if (RemoteSyncPreferences.isDialogSuppressed(project)) {
RemoteSyncPreferences.SyncAction defaultAction =
RemoteSyncPreferences.getDefaultSyncAction(project);
executeSync(defaultAction);
return;
}
// Step 2: Build and present the UI dialog if not suppressed
SyncOptionsPanel panel = new SyncOptionsPanel();
DialogDescriptor descriptor = new DialogDescriptor(
panel,
NbBundle.getMessage(SyncController.class,
"LBL_SyncOptions_Title"), // "Synchronization Options"
true,
DialogDescriptor.OK_CANCEL_OPTION,
DialogDescriptor.OK_OPTION,
null
);
if (DialogDisplayer.getDefault().notify(descriptor) ==
DialogDescriptor.OK_OPTION) {
boolean remember = panel.isRememberCheckBoxSelected();
RemoteSyncPreferences.SyncAction selectedAction =
panel.getSelectedSyncAction();
// Step 3: Persist choice to
nbproject/private/private.properties if requested
if (remember) {
RemoteSyncPreferences.saveSyncPreferences(project, true,
selectedAction);
}
executeSync(selectedAction);
}
}
private void executeSync(RemoteSyncPreferences.SyncAction action) {
// Background thread transfer execution
}
}
```
---
### Expected Outcome
1. When a user selects **"Remember selection"**, the setting is written to
`nbproject/private/private.properties` as:
```properties
remote.sync.suppress.dialog=true
remote.sync.default.action=OVERWRITE_REMOTE
```
2. Subsequent manual FTP upload or sync requests check this setting first
and execute immediately without prompting.
3. Users can reset or change this behavior anytime by clearing the private
property or adjusting settings under **Project Properties -> Run
Configuration**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists