netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

FTP Synchronization dialog does not close automatically even when "Close Automatically On Success" is checked

Open miraged opened this issue 9 months ago • 1 comments

Apache NetBeans version

Apache NetBeans 28

What happened

The "Synchronization" dialog box, which appears after performing an FTP/Remote synchronization, fails to close automatically upon successful completion. This occurs even when the checkbox "Close Automatically On Success" is explicitly checked.

This issue has been persistent across multiple NetBeans versions (at least 5 different versions tested), suggesting a long-standing bug in the UI handling of this specific dialog.

Language / Project Type / NetBeans Component

No response

How to reproduce

Steps to Reproduce:

  • Set up a PHP project with FTP/Remote synchronization.
  • Perform a "Sync" or "Upload" operation that triggers the Synchronization progress dialog.
  • Check the box "Close Automatically On Success".
  • Wait for the synchronization to finish successfully.

Actual Result: The dialog stays open with the message "Synchronization successfully finished." The user must manually click the "OK" button to dismiss it.

Expected Result: The dialog should close automatically as soon as the progress reaches 100% and the "Success" message is triggered, provided the checkbox is enabled.

Did this work correctly in an earlier version?

Apache NetBeans 24 or earlier

Operating System

System: Windows 11 version 10.0 running on amd64; UTF-8; en_US (nb)

JDK

Java: 25.0.1; OpenJDK 64-Bit Server VM 25.0.1+8-LTS

Apache NetBeans packaging

Community provided installer

Anything else

No response

Are you willing to submit a pull request?

No

miraged avatar Feb 11 '26 09:02 miraged

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:

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:

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:
    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.

miraged avatar Oct 03 '26 11:10 miraged