From c765feba37ede5fed87fb08fff8250e3fb97d085 Mon Sep 17 00:00:00 2001 From: Deepika Udayagiri Date: Mon, 4 May 2026 15:17:40 +0530 Subject: [PATCH 1/3] Import Workspace List from previous application installation. - with loggers(DO NOT DELETE) --- .../internal/ide/ChooseWorkspaceDialog.java | 814 +++++++++++++++++- .../ui/internal/ide/IDEWorkbenchMessages.java | 4 + .../internal/ide/WorkspaceImportDialog.java | 485 +++++++++++ .../ui/internal/ide/messages.properties | 4 + 4 files changed, 1299 insertions(+), 8 deletions(-) create mode 100644 bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java index 0c06c773625..c8c950b72a4 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corporation and others. + * Copyright (c) 2004, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,8 @@ package org.eclipse.ui.internal.ide; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.InvalidPathException; @@ -25,20 +27,26 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Properties; import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.eclipse.core.runtime.IProduct; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.JFaceColors; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.util.Geometry; @@ -72,6 +80,7 @@ import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.osgi.framework.FrameworkUtil; /** @@ -81,6 +90,8 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog { private static final String TILDE = "~"; //$NON-NLS-1$ + private static final String RECENT_WORKSPACES = "RECENT_WORKSPACES"; //$NON-NLS-1$ + private static final String OPEN_FOLDER_EMOJI = new String( new byte[] { (byte) 0xF0, (byte) 0x9F, (byte) 0x93, (byte) 0x82 }, StandardCharsets.UTF_8); @@ -100,6 +111,17 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog { private Button defaultButton; + // private boolean hasShownImportPrompt = false; + private static final String PLUGIN_ID = FrameworkUtil.getBundle(ChooseWorkspaceDialog.class).getSymbolicName(); + private void log(int severity, String message, Throwable t) { + Platform.getLog(FrameworkUtil.getBundle(getClass())).log(new Status(severity, PLUGIN_ID, message, t)); + } + private void logInfo(String msg) { + log(IStatus.INFO, msg, null); + } + private void logError(String msg, Throwable t) { + log(IStatus.ERROR, msg, t); + } /** * Create a modal dialog on the argument shell, using and updating the @@ -185,12 +207,11 @@ protected Control createDialogArea(Composite parent) { getTitleImageLabel().setVisible(false); } - // Should only create the Recent Workspaces Composite if Recent - // workspaces exist - boolean createRecentWorkspacesComposite = false; - if (launchData.getRecentWorkspaces()[0] != null) { - createRecentWorkspacesComposite = true; - } + // Will create Recent Workspaces Composite always. + boolean createRecentWorkspacesComposite = true; +// if (launchData.getRecentWorkspaces()[0] != null) { +// createRecentWorkspacesComposite = true; +// } createWorkspaceBrowseRow(composite); if (!suppressAskAgain) { createShowDialogButton(composite); @@ -205,6 +226,14 @@ protected Control createDialogArea(Composite parent) { @Override protected void createButtonsForButtonBar(Composite parent) { + // create "Import..." button first followed by Launch, Cancel + Button importButton = createButton(parent, IDialogConstants.CLIENT_ID + 1, + IDEWorkbenchMessages.ChooseWorkspaceDialog_importLabel, false); + importButton.setToolTipText(IDEWorkbenchMessages.ChooseWorkspaceDialog_importTooltip); + importButton.addListener(SWT.Selection, e -> { + showImportWorkspacesDialog(); + }); + // create OK and Cancel buttons by default createButton(parent, IDialogConstants.OK_ID, IDEWorkbenchMessages.ChooseWorkspaceDialog_launchLabel, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); @@ -364,7 +393,59 @@ private void createRecentWorkspacesComposite(final Composite composite) { toggle.addListener(SWT.MouseDown, toggleListener); label.addListener(SWT.MouseDown, toggleListener); - List recentWorkspaces = getRecentWorkspaces(); + logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before launchData size: " //$NON-NLS-1$ + + (launchData.getRecentWorkspaces() != null ? launchData.getRecentWorkspaces().length : 0)); + String[] workspacesArray = launchData.getRecentWorkspaces(); + List recentWorkspaces = (workspacesArray != null && workspacesArray.length > 0) + ? filterDuplicatedPaths(workspacesArray) + : new ArrayList<>(); + + // NEW CODE: Check if recent workspaces list is empty +// if (recentWorkspaces == null || recentWorkspaces.isEmpty()) { + // Show message in the panel + if (recentWorkspaces == null || recentWorkspaces.isEmpty()) { + Label emptyLabel = new Label(panel, SWT.WRAP); + emptyLabel.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_noRecentWorkspaceFound); + emptyLabel.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); + } else { + Label moreLabel = new Label(panel, SWT.WRAP); + moreLabel.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_addMoreRecentWorkspaces); + moreLabel.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); + } +// link kind of logic for "Import..." starts +// Link importLink = new Link(panel, SWT.WRAP); +// importLink.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); +// importLink.setText("Import..."); //$NON-NLS-1$ +// importLink.addSelectionListener(new SelectionAdapter() { +// @Override +// public void widgetSelected(SelectionEvent e) { +// showImportWorkspacesDialog(); // ALWAYS allow manual import +// } +// }); +//link kind of logic for "Import..." ends + +// DO NOT DELETE +// // Show a prompt dialog when the dialog opens, but only ONCE +// Shell shell = getShell(); +// if (shell != null && !shell.isDisposed() && !hasShownImportPrompt) { +// hasShownImportPrompt = true; // Set flag to prevent showing again +// shell.getDisplay().asyncExec(() -> { +// // Check again if still empty before showing prompt +// // This prevents showing prompt if workspaces were already imported +// List currentWorkspaces = getRecentWorkspaces(); +// if (currentWorkspaces == null || currentWorkspaces.isEmpty()) { +// showImportWorkspacesPromptDialog(); +// } +// }); +// } +//DO NOT DELETE + + // Force layout BEFORE return (important) +// panel.layout(true); +// recentWorkspacesForm.layout(true, true); +// recentWorkspacesLinks = new HashMap<>(); +// return; +// } recentWorkspacesLinks = new HashMap<>(recentWorkspaces.size()); Map uniqueWorkspaceNames = createUniqueWorkspaceNameMap(); @@ -400,6 +481,719 @@ public void widgetSelected(SelectionEvent e) { }); link.setMenu(menu); } + logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before recentWorkspaces size: " //$NON-NLS-1$ + + recentWorkspaces.size()); + panel.layout(true); + recentWorkspacesForm.layout(true, true); + } + +// DO NOT DELETE +// /** +// * Shows a prompt dialog asking if user wants to import workspaces User can +// * choose to import or cancel and proceed with new workspace +// */ +// private void showImportWorkspacesPromptDialog() { +// Shell shell = getShell(); +// if (shell == null || shell.isDisposed()) { +// return; +// } +// +// // Double-check that workspaces are still empty before showing dialog +// List recentWorkspaces = getRecentWorkspaces(); +// if (recentWorkspaces != null && !recentWorkspaces.isEmpty()) { +// // Workspaces were imported somehow, don't show the dialog +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesPromptDialog] recentWorkspaces is empty so returning"); //$NON-NLS-1$ +// return; +// } +// +// // Create a confirmation dialog +// MessageDialog dialog = new MessageDialog(shell, "No Recent Workspaces", // Title //$NON-NLS-1$ +// null, // Dialog title image +// "No recent workspaces found.\n\nWould you like to import workspaces from a previous Eclipse installation?\n\n", //$NON-NLS-1$ +// // "No recent workspaces found.\n\nWould you like to import workspaces from a +// // previous Eclipse installation?\n\n" / + "• Click 'Import' to browse and +// // import workspaces from a previous Eclipse installation\n" / + "• Click +// // 'Cancel' to proceed with creating a new workspace", // Message +// MessageDialog.QUESTION, // Dialog type +// new String[] { "Import...", "Cancel" }, // Button labels //$NON-NLS-1$ //$NON-NLS-2$ +// 1 // Default button index (Cancel) - so Cancel is the default +// ) { +// @Override +// protected void buttonPressed(int buttonId) { +// if (buttonId == 0) { // Import Workspaces button clicked +// close(); +// // Open directory chooser to select previous Eclipse installation +// DirectoryDialog dirDialog = new DirectoryDialog(shell); +// dirDialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ +// dirDialog.setMessage( +// "Select the directory of a previous Eclipse installation to import its workspaces:"); //$NON-NLS-1$ +// String selectedDir = dirDialog.open(); +// +// if (selectedDir != null) { +// // Import workspaces and refresh +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesPromptDialog] call from importAndRefreshWorkspaces()"); //$NON-NLS-1$ +// importAndRefreshWorkspaces(selectedDir); +// } +// // If user cancels the directory dialog, just close it and do nothing +// // The main dialog remains open and user can proceed with new workspace +// } else { +// // Cancel button clicked - just close this dialog and let user proceed +// close(); +// } +// } +// }; +// dialog.open(); +// } +// +// /** +// * Imports workspaces from selected Eclipse installation and refreshes the UI +// */ +// private void importAndRefreshWorkspaces(String eclipseInstallPath) { +// Shell shell = getShell(); +// if (shell == null || shell.isDisposed()) { +// return; +// } +// +// shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); +// +// try { +// // Find and import workspaces from the selected Eclipse installation +// List importedWorkspaces = importWorkspacesFromEclipseInstallation(eclipseInstallPath); +// +// System.out.println( +// "Found " + (importedWorkspaces != null ? importedWorkspaces.size() : 0) + " workspaces to import"); //$NON-NLS-1$ //$NON-NLS-2$ +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Found " //$NON-NLS-1$ +// + (importedWorkspaces != null ? importedWorkspaces.size() : 0) + " workspaces to import"); //$NON-NLS-1$ +// +// if (importedWorkspaces != null && !importedWorkspaces.isEmpty()) { +// // Get current workspaces using getRecentWorkspaces() (reads from launchData) +// List currentWorkspaces = getRecentWorkspaces(); +// System.out.println("Current workspaces before merge: " //$NON-NLS-1$ +// + (currentWorkspaces != null ? currentWorkspaces.size() : 0)); +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Current workspaces before merge: " //$NON-NLS-1$ +// + (currentWorkspaces != null ? currentWorkspaces.size() : 0)); +// +// // Create a modifiable copy +// List mergedWorkspaces = new ArrayList<>(); +// if (currentWorkspaces != null && !currentWorkspaces.isEmpty()) { +// mergedWorkspaces.addAll(currentWorkspaces); +// } +// +// // Add imported workspaces that aren't already present +// for (String workspace : importedWorkspaces) { +// if (!mergedWorkspaces.contains(workspace)) { +// mergedWorkspaces.add(0, workspace); // Add at beginning to show as most recent +// System.out.println("Added workspace: " + workspace); //$NON-NLS-1$ +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Added workspace: " + workspace); //$NON-NLS-1$ +// } else { +// System.out.println("Workspace already exists: " + workspace); //$NON-NLS-1$ +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Workspace already exists: " //$NON-NLS-1$ +// + workspace); +// } +// } +// +// System.out.println("Merged workspaces count: " + mergedWorkspaces.size()); //$NON-NLS-1$ +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Merged workspaces count: " //$NON-NLS-1$ +// + mergedWorkspaces.size()); +// +// // Update launchData directly with the string array +// updateLaunchDataWorkspaces(mergedWorkspaces); +// +// // Also save to preferences for persistence when Eclipse restarts +// saveRecentWorkspacesToPreferences(mergedWorkspaces); +// +// // Verify the update worked by checking getRecentWorkspaces() again +// List verifyWorkspaces = getRecentWorkspaces(); +// System.out.println("Verification - workspaces after update: " //$NON-NLS-1$ +// + (verifyWorkspaces != null ? verifyWorkspaces.size() : 0)); +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Verification - workspaces after update: " //$NON-NLS-1$ +// + (verifyWorkspaces != null ? verifyWorkspaces.size() : 0)); +// if (verifyWorkspaces != null) { +// for (String ws : verifyWorkspaces) { +// System.out.println(" Verified workspace: " + ws); //$NON-NLS-1$ +// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Verified workspace: " + ws); //$NON-NLS-1$ +// } +// } +// +// // Refresh the UI +// refreshRecentWorkspacesComposite(); +// +// // Show success message only if workspaces were actually imported +// if (verifyWorkspaces != null && !verifyWorkspaces.isEmpty()) { +// MessageDialog.openInformation(shell, "Workspaces Imported", String.format( //$NON-NLS-1$ +// "Successfully imported %d workspace(s) from the previous installation.\n\nYou can now select one of the imported workspaces or continue with a new workspace.", //$NON-NLS-1$ +// importedWorkspaces.size())); +// } else { +// MessageDialog.openWarning(shell, "Workspaces Not Saved", //$NON-NLS-1$ +// "Workspaces were found but could not be saved. Please check the error log."); //$NON-NLS-1$ +// } +// } else { +// // Show warning if no workspaces found +// MessageDialog.openWarning(shell, "No Workspaces Found", //$NON-NLS-1$ +// "No workspaces could be found in the selected Eclipse installation.\n\nPlease select a valid Eclipse installation directory or proceed with creating a new workspace."); //$NON-NLS-1$ +// } +// } finally { +// shell.setCursor(null); +// } +// } +// DO NOT DELETE + + /** + * NEW METHOD: Show dialog to import workspaces from previous installation + */ +// version 2 + private void showImportWorkspacesDialog() { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] START"); //$NON-NLS-1$ + + DirectoryDialog dialog = new DirectoryDialog(getShell()); + dialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ + dialog.setMessage("Select the directory of a previous Eclipse installation"); //$NON-NLS-1$ + + String selectedDir = dialog.open(); + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected directory: " + selectedDir); //$NON-NLS-1$ + + if (selectedDir == null) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled directory selection"); //$NON-NLS-1$ + return; + } + + // Step 1: Detect workspaces + List detected = importWorkspaces(selectedDir); + + if (detected == null) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Detected list is NULL"); //$NON-NLS-1$ + return; + } + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Detected workspaces count: " + detected.size()); //$NON-NLS-1$ + + for (String ws : detected) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Detected workspace: " + ws); //$NON-NLS-1$ + } + + if (detected.isEmpty()) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ No workspaces found after detection"); //$NON-NLS-1$ + MessageDialog.openWarning(getShell(), "No Workspaces Found", "No workspaces found in selected directory."); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + + // Step 2: Open selection dialog + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Opening WorkspaceImportDialog"); //$NON-NLS-1$ + WorkspaceImportDialog selectionDialog = new WorkspaceImportDialog(getShell(), detected, selectedDir, this, + Arrays.asList(launchData.getRecentWorkspaces())); + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Dialog created"); //$NON-NLS-1$ + + int result = Window.CANCEL; + try { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to call open()"); //$NON-NLS-1$ + result = selectionDialog.open(); + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Dialog open() returned: " + result); //$NON-NLS-1$ + } catch (Exception e) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Exception while opening dialog: " //$NON-NLS-1$ + + e.getMessage()); + e.printStackTrace(); + } + if (result != Window.OK) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled selection dialog"); //$NON-NLS-1$ + return; + } + + List selected = selectionDialog.getSelected(); + if (selected == null) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Selected list is NULL"); //$NON-NLS-1$ + return; + } + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected count: " + selected.size()); //$NON-NLS-1$ + + for (String ws : selected) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected workspace: " + ws); //$NON-NLS-1$ + } + + if (selected.isEmpty()) { + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ No workspaces selected"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), "Nothing Selected", "No workspaces selected."); //$NON-NLS-1$ //$NON-NLS-2$ + return; + } + + // Step 3: Merge + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Merging selected workspaces"); //$NON-NLS-1$ + mergeSelectedWorkspaces(selected); + logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] END"); //$NON-NLS-1$ + } + + private void mergeSelectedWorkspaces(List selected) { + + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] START"); //$NON-NLS-1$ + + if (selected == null) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] ❌ Selected list is NULL"); //$NON-NLS-1$ + return; + } + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Incoming selected size: " + selected.size()); //$NON-NLS-1$ + + Set merged = new LinkedHashSet<>(); + + // Step 1: Existing workspaces + String[] existing = launchData.getRecentWorkspaces(); + + if (existing == null) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Existing workspaces is NULL"); //$NON-NLS-1$ + } else { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Existing count: " + existing.length); //$NON-NLS-1$ + + for (String ws : existing) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Checking existing: " + ws); //$NON-NLS-1$ + if (ws == null) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping NULL existing"); //$NON-NLS-1$ + continue; + } + + File f = new File(ws); + if (!f.exists()) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping invalid existing: " + ws); //$NON-NLS-1$ + continue; + } + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Adding existing: " + ws); //$NON-NLS-1$ + merged.add(ws); + } + } + + // Step 2: Add selected + for (String ws : selected) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Processing selected: " + ws); //$NON-NLS-1$ + + if (ws == null) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping NULL selected"); //$NON-NLS-1$ + continue; + } + + File f = new File(ws); + if (!f.exists()) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping invalid selected: " + ws); //$NON-NLS-1$ + continue; + } + + if (merged.contains(ws)) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Duplicate ignored: " + ws); //$NON-NLS-1$ + } else { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Adding selected: " + ws); //$NON-NLS-1$ + merged.add(ws); + } + } + + // Step 3: Final list + List result = new ArrayList<>(merged); + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Final merged size: " + result.size()); //$NON-NLS-1$ + + for (String ws : result) { + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Final workspace: " + ws); //$NON-NLS-1$ + } + + // Step 4: Persist + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Updating launchData"); //$NON-NLS-1$ + launchData.setRecentWorkspaces(result.toArray(new String[0])); + + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Saving to preferences"); //$NON-NLS-1$ + saveRecentWorkspacesToPreferences(result); + + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Refreshing UI"); //$NON-NLS-1$ + refreshRecentWorkspacesComposite(); + + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Showing confirmation dialog"); //$NON-NLS-1$ + + MessageDialog.openInformation(getShell(), "Workspaces Updated", //$NON-NLS-1$ + "Imported " + selected.size() + " workspace(s)."); //$NON-NLS-1$ //$NON-NLS-2$ + logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] END"); //$NON-NLS-1$ + } +// version 2 +// version 1 starts. +// private void showImportWorkspacesDialog() { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] === START ==="); //$NON-NLS-1$ +// +// DirectoryDialog dialog = new DirectoryDialog(getShell()); +// dialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ +// dialog.setMessage("Select the directory of a previous Eclipse installation to import its workspaces:"); //$NON-NLS-1$ +// String selectedDir = dialog.open(); +// +// if (selectedDir == null) { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled directory selection"); //$NON-NLS-1$ +// return; +// } +// +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected directory: " + selectedDir); //$NON-NLS-1$ +// +// // Find and import workspaces from the selected Eclipse installation +// List importedWorkspaces = importWorkspacesFromEclipseInstallation(selectedDir); +// +// if (importedWorkspaces == null || importedWorkspaces.isEmpty()) { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No workspaces found in selected installation"); //$NON-NLS-1$ +// MessageDialog.openWarning(getShell(), "No Workspaces Found", //$NON-NLS-1$ +// "No workspaces could be found in the selected Eclipse installation."); //$NON-NLS-1$ +// return; +// } +// +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Imported workspaces count: " //$NON-NLS-1$ +// + importedWorkspaces.size()); +// +// String[] currentWorkspacesArray = launchData.getRecentWorkspaces(); +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Current workspaces count: " //$NON-NLS-1$ +// + (currentWorkspacesArray != null ? currentWorkspacesArray.length : 0)); +// +// // Quick check if there's anything to add +// boolean hasNewWorkspaces = false; +// if (currentWorkspacesArray != null) { +// for (String imported : importedWorkspaces) { +// if (imported != null && imported.length() > 0) { +// boolean exists = false; +// for (String current : currentWorkspacesArray) { +// if (imported.equals(current)) { +// exists = true; +// break; +// } +// } +// if (!exists && new File(imported).exists()) { +// hasNewWorkspaces = true; +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] New workspace found: " + imported); //$NON-NLS-1$ +// break; +// } +// } +// } +// } else if (!importedWorkspaces.isEmpty()) { +// hasNewWorkspaces = true; +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No current workspaces, all imported are new"); //$NON-NLS-1$ +// } +// +// // Return early if nothing new to add +// if (!hasNewWorkspaces) { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No new workspaces to add, returning early"); //$NON-NLS-1$ +// MessageDialog.openInformation(getShell(), "No New Workspaces", //$NON-NLS-1$ +// "All workspaces from the previous installation are already in your recent workspaces list."); //$NON-NLS-1$ +// return; +// } +// +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Proceeding with merge, has new workspaces: true"); //$NON-NLS-1$ +// +// // Only proceed with merge if there are new workspaces +// int initialCapacity = (currentWorkspacesArray != null ? currentWorkspacesArray.length : 0) +// + importedWorkspaces.size(); +// Set uniqueWorkspacesSet = new LinkedHashSet<>(initialCapacity); +// +// // Add current workspaces +// int removedCount = 0; +// if (currentWorkspacesArray != null) { +// for (int i = 0; i < currentWorkspacesArray.length; i++) { +// String ws = currentWorkspacesArray[i]; +// if (ws != null && ws.length() > 0) { +// File wsFile = new File(ws); +// if (wsFile.exists()) { +// uniqueWorkspacesSet.add(ws); +// } else { +// removedCount++; +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Removing non-existent workspace: " //$NON-NLS-1$ +// + ws); +// } +// } +// } +// } +// +// // Add new imported workspaces +// int addedCount = 0; +// for (int i = 0; i < importedWorkspaces.size(); i++) { +// String ws = importedWorkspaces.get(i); +// if (ws != null && ws.length() > 0) { +// File wsFile = new File(ws); +// if (wsFile.exists() && uniqueWorkspacesSet.add(ws)) { +// addedCount++; +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Adding workspace: " + ws); //$NON-NLS-1$ +// } +// } +// } +// +// List mergedWorkspaces = new ArrayList<>(uniqueWorkspacesSet); +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] mergedWorkspaces.size(): " //$NON-NLS-1$ +// + mergedWorkspaces.size()); +// +// if (mergedWorkspaces.isEmpty()) { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No valid workspaces after merge"); //$NON-NLS-1$ +// MessageDialog.openWarning(getShell(), "No Valid Workspaces", "No valid workspaces found."); //$NON-NLS-1$ //$NON-NLS-2$ +// return; +// } +// +// // Update in-memory first + //// try { / java.lang.reflect.Field field = + /// launchData.getClass().getDeclaredField("recentWorkspaces"); //$NON-NLS-1$ / + /// field.setAccessible(true); / field.set(launchData, + /// mergedWorkspaces.toArray(new String[0])); / + /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Updated + /// launchData via reflection, launchData.getRecentWorkspaces().length: " + /// //$NON-NLS-1$ / + launchData.getRecentWorkspaces().length); / } catch + /// (Exception e) { / + /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Reflection + /// failed, using setter: " //$NON-NLS-1$ / + e.getMessage()); / + /// launchData.setRecentWorkspaces(mergedWorkspaces.toArray(new String[0])); / } +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Before updating launchData without reflection, launchData.getRecentWorkspaces().length: " //$NON-NLS-1$ +// + launchData.getRecentWorkspaces().length); +// launchData.setRecentWorkspaces(mergedWorkspaces.toArray(new String[0])); // instead of reflection +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Updated launchData without reflection, launchData.getRecentWorkspaces().length: " //$NON-NLS-1$ +// + launchData.getRecentWorkspaces().length); +// +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to save to preferences"); //$NON-NLS-1$ +// // Single file write +// saveRecentWorkspacesToPreferences(mergedWorkspaces); +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Saved preferences"); //$NON-NLS-1$ +// +// // Update UI immediately +// if (recentWorkspacesForm != null && !recentWorkspacesForm.isDisposed()) { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Refreshing UI in normal thread"); //$NON-NLS-1$ +// refreshRecentWorkspacesComposite(); + //// getShell().getDisplay().asyncExec(() -> { / if (recentWorkspacesForm != + /// null && !recentWorkspacesForm.isDisposed()) { / + /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to enter + /// refreshRecentWorkspacesComposite() in UI thread"); //$NON-NLS-1$ / + /// refreshRecentWorkspacesComposite(); / } / }); +// } else { +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] recentWorkspacesForm is null or disposed, cannot refresh"); //$NON-NLS-1$ +// } +// +// String message = String.format("Imported %d new workspace(s).", addedCount); //$NON-NLS-1$ +// if (removedCount > 0) { +// message += String.format("\nRemoved %d non-existent workspace(s).", removedCount); //$NON-NLS-1$ +// } +// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] === END, " + message); //$NON-NLS-1$ +// MessageDialog.openInformation(getShell(), "Workspaces Updated", message); //$NON-NLS-1$ +// } +// version 1 ends + + private List importWorkspaces(File directory) { + logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] START: " + directory); //$NON-NLS-1$ + // capture return value + List result = importWorkspacesFromEclipseInstallation(directory.getAbsolutePath()); + if (result == null) { + logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] ❌ result is NULL"); //$NON-NLS-1$ + result = new ArrayList<>(); + } + logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] END size=" + result.size()); //$NON-NLS-1$ + return result; + } + + public List importWorkspaces(String path) { + logInfo("[ChooseWorkspaceDialog][importWorkspaces(String)] path=" + path); //$NON-NLS-1$ + return importWorkspaces(new File(path)); // ✅ now VALID + } + + /** + * NEW METHOD: Method to save workspaces to preferences + */ + private void saveRecentWorkspacesToPreferences(List workspaces) { +/* logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Entered saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + if (workspaces == null || workspaces.isEmpty()) { + store.setValue(RECENT_WORKSPACES, ""); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] returning..."); //$NON-NLS-1$ + return; + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < workspaces.size(); i++) { + if (i > 0) { + sb.append("\n"); //$NON-NLS-1$ + } + sb.append(workspaces.get(i)); + } + store.setValue(RECENT_WORKSPACES, sb.toString()); + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Properly exiting saveRecentWorkspacesToPreferences(), sb.toString(): " //$NON-NLS-1$ + + sb.toString()); +// original implementation. +*/ + + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Entered saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + if (workspaces == null || workspaces.isEmpty()) { + store.setValue(RECENT_WORKSPACES, ""); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] looks like workspaces is empty or null so returning"); //$NON-NLS-1$ + return; + } + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] About to build sb"); //$NON-NLS-1$ +// StringBuilder sb = new StringBuilder(); +// for (int i = 0; i < mergedWorkspaces.size(); i++) { +// if (i > 0) { +// sb.append("\n"); //$NON-NLS-1$ +// } +// sb.append(mergedWorkspaces.get(i)); +// } +// store.setValue(RECENT_WORKSPACES, sb.toString()); + try { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < workspaces.size(); i++) { + String ws = workspaces.get(i); + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Processing workspace index " + i //$NON-NLS-1$ + + ": " //$NON-NLS-1$ + + ws); + if (ws == null) { + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] NULL workspace found at index " //$NON-NLS-1$ + + i); + continue; + } + if (i > 0) { + sb.append("\n"); //$NON-NLS-1$ + } + sb.append(ws); + } +// store.setValue(RECENT_WORKSPACES, sb.toString()); // option 1 +// IEclipsePreferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.ui.ide"); //$NON-NLS-1$ +// prefs.put(RECENT_WORKSPACES, sb.toString()); +// prefs.flush(); // option 2 + if (Platform.getInstanceLocation().isSet()) { + store.setValue(RECENT_WORKSPACES, sb.toString()); + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] references updated, sb.toString(): " //$NON-NLS-1$ + + sb.toString()); + } else { + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Instance location not set yet. Skipping preference save."); //$NON-NLS-1$ + } // option 3 + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] references updated, sb.toString(): " //$NON-NLS-1$ + + sb.toString()); + } catch (Exception e) { + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] EXCEPTION in saving preferences: " //$NON-NLS-1$ + + e.getMessage()); + e.printStackTrace(); + } + logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Exiting from saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ + } + + /** + * NEW METHOD: Method to import workspaces from previous Eclipse installation + */ + private List importWorkspacesFromEclipseInstallation(String eclipseInstallPath) { + List workspaces = new ArrayList<>(); + + System.out.println("Looking for workspaces in: " + eclipseInstallPath); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Looking for workspaces in: " + eclipseInstallPath); //$NON-NLS-1$ + // Try to find workspaces from the previous installation + // Look for the configuration/.settings/org.eclipse.ui.ide.prefs file + File configDir = new File(eclipseInstallPath, "configuration"); //$NON-NLS-1$ + File settingsDir = new File(configDir, ".settings"); //$NON-NLS-1$ + File recentWorkspacesFile = new File(settingsDir, "org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ + + System.out.println("Looking for preferences file at: " + recentWorkspacesFile.getAbsolutePath()); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Looking for preferences file at: " //$NON-NLS-1$ + + recentWorkspacesFile.getAbsolutePath()); + if (recentWorkspacesFile.exists()) { + System.out.println("Found preferences file"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found preferences file"); //$NON-NLS-1$ + try { + // Parse the preferences file to extract recent workspaces + Properties props = new Properties(); + try (FileInputStream fis = new FileInputStream(recentWorkspacesFile)) { + props.load(fis); + } + + String recentWorkspacesValue = props.getProperty("RECENT_WORKSPACES"); //$NON-NLS-1$ + System.out.println("RECENT_WORKSPACES value: " + recentWorkspacesValue); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] RECENT_WORKSPACES value: " + recentWorkspacesValue); //$NON-NLS-1$ + if (recentWorkspacesValue != null && !recentWorkspacesValue.isEmpty()) { + // Parse the workspaces (format is paths separated by newlines) + String[] workspacePaths = recentWorkspacesValue.split("\\n"); //$NON-NLS-1$ + for (String path : workspacePaths) { + path = path.trim(); + if (!path.isEmpty()) { + File wsFile = new File(path); + if (wsFile.exists()) { + workspaces.add(path); + System.out.println("Found existing workspace: " + path); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found existing workspace: " + path); //$NON-NLS-1$ + } else { + System.out.println("Workspace path does not exist: " + path); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Workspace path does not exist: " //$NON-NLS-1$ + + path); + } + } + } + } else { + System.out.println("RECENT_WORKSPACES property is empty or null"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] RECENT_WORKSPACES property is empty or null"); //$NON-NLS-1$ + } + } catch (IOException e) { + System.err.println("Error reading preferences file: " + e.getMessage()); //$NON-NLS-1$ + logError("[ChooseWorkspaceDialog][importWorkspaces] Error reading preferences file: ", e); //$NON-NLS-1$ + e.printStackTrace(); + } + } else { + System.out.println("Preferences file not found at: " + recentWorkspacesFile.getAbsolutePath()); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Preferences file not found at: " //$NON-NLS-1$ + + recentWorkspacesFile.getAbsolutePath()); + + // Try alternative location + File alternativePrefs = new File(eclipseInstallPath, + ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ + System.out.println("Checking alternative location: " + alternativePrefs.getAbsolutePath()); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Checking alternative location: " //$NON-NLS-1$ + + alternativePrefs.getAbsolutePath()); + if (alternativePrefs.exists()) { + System.out.println("Found alternative preferences file"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found alternative preferences file"); //$NON-NLS-1$ + // Parse it similarly... + } + } + + System.out.println("Total workspaces found: " + workspaces.size()); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][importWorkspaces] Total workspaces found: " + workspaces.size()); //$NON-NLS-1$ + return workspaces; + } + + /** + * NEW METHOD: Method to refresh the recent workspaces composite after import + */ + private void refreshRecentWorkspacesComposite() { + System.out.println("Entering refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Entering refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ + + // Get the parent composite + Composite parent = recentWorkspacesForm.getParent(); + if (parent != null && !parent.isDisposed()) { + // Store current expansion state + boolean wasExpanded = launchData.isShowRecentWorkspaces(); + + // Dispose the old form + recentWorkspacesForm.dispose(); + + // Recreate the recent workspaces section + createRecentWorkspacesComposite(parent); + + // Force layout update + parent.layout(true); + parent.getShell().layout(true); + + // Ensure expansion state is restored + if (recentWorkspacesForm != null && !recentWorkspacesForm.isDisposed()) { + // Find the expandable composite and set its state + // Control[] children = recentWorkspacesForm.getBody().getChildren(); // + // recentWorkspacesForm became composite instead of form + Control[] children = recentWorkspacesForm.getChildren(); + for (Control child : children) { + if (child instanceof ExpandableComposite) { + ((ExpandableComposite) child).setExpanded(wasExpanded); + break; + } + } + } + + Shell shell = parent.getShell(); + if (shell != null && !shell.isDisposed()) { + shell.layout(true, true); + shell.redraw(); + shell.update(); + // Resize dialog properly + Point size = getInitialSize(); + shell.setBounds(getConstrainedShellBounds( + new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y))); + } + + System.out.println("Refresh completed"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Refresh completed"); //$NON-NLS-1$ + } else { + System.out.println("Parent composite is null or disposed"); //$NON-NLS-1$ + logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Parent composite is null or disposed"); //$NON-NLS-1$ + } + logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Exiting refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ } /** @@ -764,6 +1558,10 @@ private List getRecentWorkspaces() { * @return The set of paths without duplicates. */ public static List filterDuplicatedPaths(String[] paths) { + if (paths == null || paths.length == 0) { + return Collections.emptyList(); + } + Set normalizedPaths = new HashSet<>(); List recentWorkspaces = new ArrayList<>(); for (String workspace : paths) { diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java index 09eb0bc9531..d6a76f8d4a5 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java @@ -1014,10 +1014,14 @@ public class IDEWorkbenchMessages extends NLS { public static String ChooseWorkspaceDialog_workspaceEntryLabel; public static String ChooseWorkspaceDialog_browseLabel; public static String ChooseWorkspaceDialog_browseTooltip; + public static String ChooseWorkspaceDialog_importLabel; + public static String ChooseWorkspaceDialog_importTooltip; public static String ChooseWorkspaceDialog_launchLabel; public static String ChooseWorkspaceDialog_directoryBrowserTitle; public static String ChooseWorkspaceDialog_directoryBrowserMessage; public static String ChooseWorkspaceDialog_removeWorkspaceSelection; + public static String ChooseWorkspaceDialog_noRecentWorkspaceFound; + public static String ChooseWorkspaceDialog_addMoreRecentWorkspaces; public static String ChooseWorkspaceDialog_recentWorkspaces; public static String ChooseWorkspaceDialog_ResolvedAbsolutePath; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java new file mode 100644 index 00000000000..61d4888c53f --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java @@ -0,0 +1,485 @@ +/******************************************************************************* + * Copyright (c) 2026 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.ide; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; + +/** + * @since 3.4 + * + */ +public class WorkspaceImportDialog extends TitleAreaDialog { + + private List input; + private String baseInstallPath; + private CheckboxTableViewer viewer; + private List selected = new ArrayList<>(); + private List existingWorkspaces; + private Text locationText; + private ChooseWorkspaceDialog parentDialog; + + private Set checkedElements = new LinkedHashSet<>(); + + public WorkspaceImportDialog(Shell parentShell, List input, String baseInstallPath, + ChooseWorkspaceDialog parentDialog, List existingWorkspaces) { + super(parentShell); + this.input = input; + this.baseInstallPath = baseInstallPath; + this.parentDialog = parentDialog; + this.existingWorkspaces = existingWorkspaces; + logInfo("[WorkspaceImportDialog][ctor] Existing count: " + existingWorkspaces.size()); //$NON-NLS-1$ + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Import Workspaces"); // Window title //$NON-NLS-1$ + logInfo("[WorkspaceImportDialog][configureShell] Title set"); //$NON-NLS-1$ + } + + @Override + public void create() { + super.create(); + setTitle("Import Workspaces"); //$NON-NLS-1$ + setMessage("Select workspaces to import."); //$NON-NLS-1$ + logInfo("[WorkspaceImportDialog][create] Title + Message set"); //$NON-NLS-1$ + } + + private void logInfo(String msg) { + System.out.println(msg); // or route to your logger + } + + @Override + protected Control createDialogArea(Composite parent) { + + logInfo("[WorkspaceImportDialog][createDialogArea] START"); //$NON-NLS-1$ + + Composite container = (Composite) super.createDialogArea(parent); + container.setLayout(new GridLayout(1, false)); + + // FIX ORDER + logInfo("[WorkspaceImportDialog] -> createLocationRow()"); //$NON-NLS-1$ + createLocationRow(container); + + logInfo("[WorkspaceImportDialog] -> createFilter()"); //$NON-NLS-1$ + createFilter(container); + + logInfo("[WorkspaceImportDialog] -> createTable()"); //$NON-NLS-1$ + createTable(container); + + logInfo("[WorkspaceImportDialog] -> loadInitialInput()"); //$NON-NLS-1$ + loadInitialInput(); + + logInfo("[WorkspaceImportDialog] -> createButtons()"); //$NON-NLS-1$ + createButtons(container); + + logInfo("[WorkspaceImportDialog][createDialogArea] END"); //$NON-NLS-1$ + return container; + } + + private void createLocationRow(Composite parent) { + logInfo("[WorkspaceImportDialog][createLocationRow] START"); //$NON-NLS-1$ + + Composite row = new Composite(parent, SWT.NONE); + row.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + row.setLayout(new GridLayout(3, false)); + + new Label(row, SWT.NONE).setText("Workspace location:"); //$NON-NLS-1$ + + locationText = new Text(row, SWT.BORDER); + locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + if (baseInstallPath != null) { + locationText.setText(baseInstallPath); + logInfo("[WorkspaceImportDialog] Using baseInstallPath: " + baseInstallPath); //$NON-NLS-1$ + } + + Button browse = new Button(row, SWT.PUSH); + browse.setText("Browse..."); //$NON-NLS-1$ + browse.addListener(SWT.Selection, e -> { + + logInfo("[WorkspaceImportDialog][Browse] CLICKED"); //$NON-NLS-1$ + + DirectoryDialog dlg = new DirectoryDialog(parent.getShell()); + dlg.setText("Select Eclipse Installation"); //$NON-NLS-1$ + dlg.setMessage("Select installation directory"); //$NON-NLS-1$ + + String selected = dlg.open(); + + logInfo("[WorkspaceImportDialog][Browse] Selected: " + selected); //$NON-NLS-1$ + + if (selected != null) { + locationText.setText(selected); + + // reload workspaces + reloadWorkspaces(selected); + } + }); + logInfo("[WorkspaceImportDialog][createLocationRow] END"); //$NON-NLS-1$ + } + + private void createFilter(Composite parent) { + logInfo("[WorkspaceImportDialog][createFilter] START"); //$NON-NLS-1$ + // Add ICON_CANCEL + Text filter = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); + filter.setMessage("type filter text"); //$NON-NLS-1$ + filter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + logInfo("[WorkspaceImportDialog][createFilter] Search field with clear icon created"); //$NON-NLS-1$ + + // FILTER LOGIC + filter.addModifyListener(e -> { + String raw = filter.getText(); + logInfo("[WorkspaceImportDialog][createFilter] Raw: '" + raw + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + + if (raw == null || raw.trim().isEmpty()) { + logInfo("[WorkspaceImportDialog][createFilter] Clearing filter"); //$NON-NLS-1$ + viewer.resetFilters(); + } else { + String txt = raw.toLowerCase().replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$ + logInfo("[WorkspaceImportDialog][createFilter] Applying filter: " + txt); //$NON-NLS-1$ + viewer.setFilters(new ViewerFilter[] { new ViewerFilter() { + @Override + public boolean select(Viewer v, Object p, Object el) { + String value = el.toString().toLowerCase(); + return value.contains(txt); + } + } + }); + } + viewer.refresh(); + // CRITICAL: restore check state AFTER refresh + viewer.setCheckedElements(checkedElements.toArray()); + logInfo("[WorkspaceImportDialog][createFilter] Check state restored"); //$NON-NLS-1$ + }); + + // HANDLE CLEAR BUTTON CLICK + filter.addListener(SWT.DefaultSelection, e -> { + logInfo("[WorkspaceImportDialog][createFilter] ❌ Clear (X) clicked"); //$NON-NLS-1$ + filter.setText(""); // triggers modify listener → resets filter //$NON-NLS-1$ + }); + logInfo("[WorkspaceImportDialog][createFilter] END"); //$NON-NLS-1$ + } + + private void loadInitialInput() { + logInfo("[WorkspaceImportDialog][loadInitialInput] START"); //$NON-NLS-1$ + + if (input == null) { + logInfo("[WorkspaceImportDialog][loadInitialInput] ❌ input is NULL"); //$NON-NLS-1$ + return; + } + + List filtered = new ArrayList<>(); + for (String ws : input) { + if (ws == null || ws.trim().isEmpty()) { + logInfo("[WorkspaceImportDialog][loadInitialInput] Skipping NULL/empty"); //$NON-NLS-1$ + continue; + } + + if (existingWorkspaces != null && existingWorkspaces.contains(ws)) { + logInfo("[WorkspaceImportDialog][loadInitialInput] Skipping already existing: " + ws); //$NON-NLS-1$ + continue; + } + + filtered.add(ws); + } + logInfo("[WorkspaceImportDialog][loadInitialInput] Final size: " + filtered.size()); //$NON-NLS-1$ + + for (String ws : filtered) { + logInfo("[WorkspaceImportDialog][loadInitialInput] Adding: " + ws); //$NON-NLS-1$ + } + + // SET INPUT + viewer.setInput(filtered); + + // CHECK ALL by default + checkedElements.clear(); + checkedElements.addAll(filtered); + + viewer.setCheckedElements(checkedElements.toArray()); + + viewer.refresh(); + logInfo("[WorkspaceImportDialog][loadInitialInput] END"); //$NON-NLS-1$ + } + + private void createTable(Composite parent) { + logInfo("[WorkspaceImportDialog][createTable] START"); //$NON-NLS-1$ + + try { + viewer = CheckboxTableViewer.newCheckList(parent, + SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SHADOW_IN); + logInfo("[WorkspaceImportDialog][createTable] Viewer created"); //$NON-NLS-1$ + + Table table = viewer.getTable(); + + table.setHeaderVisible(true); + table.setLinesVisible(true); + + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.minimumHeight = 250; + table.setLayoutData(gd); + logInfo("[WorkspaceImportDialog][createTable] GridData applied with min height"); //$NON-NLS-1$ + + logInfo("[WorkspaceImportDialog][createTable] Table configured"); //$NON-NLS-1$ + + // Column 1 + TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE); + col1.getColumn().setText("Workspace"); //$NON-NLS-1$ + col1.getColumn().setWidth(200); + + col1.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + String name = new File((String) element).getName(); + logInfo("[WorkspaceImportDialog][col1] getText: " + name); //$NON-NLS-1$ + return name; + } + }); + + // Column 2 + TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE); + col2.getColumn().setText("Path"); //$NON-NLS-1$ + col2.getColumn().setWidth(400); + + col2.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + logInfo("[WorkspaceImportDialog][col2] path: " + element); //$NON-NLS-1$ + return (String) element; + } + }); + + viewer.setContentProvider(ArrayContentProvider.getInstance()); + logInfo("[WorkspaceImportDialog][createTable] Content provider set"); //$NON-NLS-1$ + + // INPUT LOGGING + if (input == null) { + logInfo("[WorkspaceImportDialog][createTable] ❌ input is NULL"); //$NON-NLS-1$ + } else { + logInfo("[WorkspaceImportDialog][createTable] input size: " + input.size()); //$NON-NLS-1$ + for (String s : input) { + logInfo("[WorkspaceImportDialog][createTable] input: " + s); //$NON-NLS-1$ + } + } + +// // FILTER VALID +// Set valid = new LinkedHashSet<>(); +// +// if (input != null) { +// for (String s : input) { +// +// if (s == null) { +// logInfo("[WorkspaceImportDialog][createTable] skipping NULL"); //$NON-NLS-1$ +// continue; +// } +// +// File f = new File(s); +// +// if (!f.exists()) { +// logInfo("[WorkspaceImportDialog][createTable] skipping not exists: " + s); //$NON-NLS-1$ +// continue; +// } +// +// if (!f.isDirectory()) { +// logInfo("[WorkspaceImportDialog][createTable] skipping not dir: " + s); //$NON-NLS-1$ +// continue; +// } +// +// logInfo("[WorkspaceImportDialog][createTable] VALID: " + s); //$NON-NLS-1$ +// valid.add(s); +// } +// } +// logInfo("[WorkspaceImportDialog][createTable] valid size: " + valid.size()); //$NON-NLS-1$ +// +// List finalList = new ArrayList<>(valid); +// +// for (String s : finalList) { +// logInfo("[WorkspaceImportDialog][createTable] FINAL LIST: " + s); //$NON-NLS-1$ +// } + + viewer.addCheckStateListener(event -> { + String element = (String) event.getElement(); + + if (event.getChecked()) { + checkedElements.add(element); + logInfo("[CheckState] CHECKED: " + element); //$NON-NLS-1$ + } else { + checkedElements.remove(element); + logInfo("[CheckState] UNCHECKED: " + element); //$NON-NLS-1$ + } + }); +// viewer.setInput(finalList); +// logInfo("[WorkspaceImportDialog][createTable] viewer.setInput DONE"); //$NON-NLS-1$ +// +// viewer.refresh(); +// logInfo("[WorkspaceImportDialog][createTable] viewer.refresh DONE"); //$NON-NLS-1$ +// +// viewer.setAllChecked(true); +// logInfo("[WorkspaceImportDialog][createTable] viewer.setAllChecked DONE"); //$NON-NLS-1$ + } catch (Exception e) { + logInfo("[WorkspaceImportDialog][createTable] ❌ Exception: " + e.getMessage()); //$NON-NLS-1$ + e.printStackTrace(); + } + logInfo("[WorkspaceImportDialog][createTable] END"); //$NON-NLS-1$ + } + + private void createButtons(Composite parent) { + logInfo("[WorkspaceImportDialog][createButtons] START"); //$NON-NLS-1$ + try { + Composite bar = new Composite(parent, SWT.NONE); + bar.setLayout(new GridLayout(2, false)); + + // Select All (VISIBLE ONLY) + Button selectAll = new Button(bar, SWT.PUSH); + selectAll.setText("Select All"); //$NON-NLS-1$ + selectAll.addListener(SWT.Selection, e -> { + logInfo("[WorkspaceImportDialog][createButtons] Select All (VISIBLE) clicked"); //$NON-NLS-1$ + if (viewer == null) { + logInfo("[WorkspaceImportDialog][createButtons] ❌ viewer NULL"); //$NON-NLS-1$ + return; + } + + TableItem[] items = viewer.getTable().getItems(); + logInfo("[SelectAll] Visible items count: " + items.length); //$NON-NLS-1$ + for (TableItem item : items) { + Object data = item.getData(); + if (data instanceof String) { + viewer.setChecked(data, true); + checkedElements.add((String) data); + logInfo("[SelectAll] CHECKED: " + data); //$NON-NLS-1$ + } + } + }); + + // Deselect All (VISIBLE ONLY) + Button deselectAll = new Button(bar, SWT.PUSH); + deselectAll.setText("Deselect All"); //$NON-NLS-1$ + deselectAll.addListener(SWT.Selection, e -> { + logInfo("[WorkspaceImportDialog][createButtons] Deselect All (VISIBLE) clicked"); //$NON-NLS-1$ + if (viewer == null) { + logInfo("[WorkspaceImportDialog][createButtons] ❌ viewer NULL"); //$NON-NLS-1$ + return; + } + + TableItem[] items = viewer.getTable().getItems(); + logInfo("[DeselectAll] Visible items count: " + items.length); //$NON-NLS-1$ + for (TableItem item : items) { + Object data = item.getData(); + if (data instanceof String) { + viewer.setChecked(data, false); + checkedElements.remove(data); + logInfo("[DeselectAll] UNCHECKED: " + data); //$NON-NLS-1$ + } + } + }); + } catch (Exception e) { + logInfo("[WorkspaceImportDialog][createButtons] ❌ Exception: " + e.getMessage()); //$NON-NLS-1$ + e.printStackTrace(); + } + logInfo("[WorkspaceImportDialog][createButtons] END"); //$NON-NLS-1$ + } + + @Override + protected void okPressed() { + logInfo("[WorkspaceImportDialog][okPressed] START"); //$NON-NLS-1$ + + if (viewer == null) { + logInfo("[WorkspaceImportDialog][okPressed] ❌ viewer is NULL"); //$NON-NLS-1$ + super.okPressed(); + return; + } + + Object[] checked = viewer.getCheckedElements(); + + logInfo("[WorkspaceImportDialog][okPressed] checked count: " + checked.length); //$NON-NLS-1$ + + for (Object o : checked) { + logInfo("[WorkspaceImportDialog][okPressed] selected: " + o); //$NON-NLS-1$ + selected.add((String) o); + } + + logInfo("[WorkspaceImportDialog][okPressed] END"); //$NON-NLS-1$ + + super.okPressed(); + } + + public List getSelected() { + return selected; + } + + private void reloadWorkspaces(String newPath) { + logInfo("[WorkspaceImportDialog][reloadWorkspaces] START: " + newPath); //$NON-NLS-1$ + + if (parentDialog == null) { + logInfo("[WorkspaceImportDialog][reloadWorkspaces] ❌ parentDialog NULL"); //$NON-NLS-1$ + return; + } + + List rawList = parentDialog.importWorkspaces(newPath); + if (rawList == null) { + logInfo("[WorkspaceImportDialog][reloadWorkspaces] ❌ rawList NULL"); //$NON-NLS-1$ + return; + } + + List filtered = new ArrayList<>(); + for (String ws : rawList) { + + if (ws == null || ws.trim().isEmpty()) { + continue; + } + + if (existingWorkspaces != null && existingWorkspaces.contains(ws)) { + logInfo("[WorkspaceImportDialog][reloadWorkspaces] Skipping existing: " + ws); //$NON-NLS-1$ + continue; + } + + filtered.add(ws); + } + + logInfo("[WorkspaceImportDialog][reloadWorkspaces] Filtered size: " + filtered.size()); //$NON-NLS-1$ + viewer.setInput(filtered); + + // ALWAYS check all after browse + checkedElements.clear(); + checkedElements.addAll(filtered); + + viewer.setCheckedElements(checkedElements.toArray()); + + viewer.refresh(); + logInfo("[WorkspaceImportDialog][reloadWorkspaces] END"); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties index 8b887cae9eb..cd97a0f72c2 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties @@ -1038,11 +1038,15 @@ ChooseWorkspaceDialog_defaultProductName = This product ChooseWorkspaceDialog_workspaceEntryLabel=&Workspace: ChooseWorkspaceDialog_browseLabel=&Browse... ChooseWorkspaceDialog_browseTooltip=Open file dialog to choose a directory as workspace to store preferences and development artifacts. +ChooseWorkspaceDialog_importLabel=&Import... +ChooseWorkspaceDialog_importTooltip=Import workspaces from existing application installation. ChooseWorkspaceDialog_launchLabel=&Launch ChooseWorkspaceDialog_directoryBrowserTitle=Select Workspace Directory ChooseWorkspaceDialog_directoryBrowserMessage=Select the workspace directory to use. ChooseWorkspaceDialog_removeWorkspaceSelection=Remove from launcher selection ChooseWorkspaceDialog_recentWorkspaces=&Recent Workspaces +ChooseWorkspaceDialog_noRecentWorkspaceFound=No recent workspaces found. You can import from previous installation or create a new workspace. +ChooseWorkspaceDialog_addMoreRecentWorkspaces=Add recent workspaces from another application installation. ChooseWorkspaceDialog_ResolvedAbsolutePath=Full path: {0} ChooseWorkspaceDialog_TildeNonExpandedWarning=\u26A0\uFE0F '~' is not expanded, full path: {0} ChooseWorkspaceDialog_InvalidPathWarning=\u26A0\uFE0F The path is invalid on this system: {0} From 39e6eac20b2b9d337783ecae289c2eb5b3a8bf85 Mon Sep 17 00:00:00 2001 From: Deepika Udayagiri Date: Thu, 7 May 2026 23:30:44 +0530 Subject: [PATCH 2/3] Removed loggers and respective 'for' loops needed for debugging. --- .../internal/ide/ChooseWorkspaceDialog.java | 602 ++---------------- .../ui/internal/ide/IDEWorkbenchMessages.java | 2 + .../internal/ide/WorkspaceImportDialog.java | 177 +---- .../ui/internal/ide/messages.properties | 2 +- 4 files changed, 57 insertions(+), 726 deletions(-) diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java index c8c950b72a4..aad2eb1af94 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java @@ -207,18 +207,13 @@ protected Control createDialogArea(Composite parent) { getTitleImageLabel().setVisible(false); } - // Will create Recent Workspaces Composite always. - boolean createRecentWorkspacesComposite = true; -// if (launchData.getRecentWorkspaces()[0] != null) { -// createRecentWorkspacesComposite = true; -// } createWorkspaceBrowseRow(composite); if (!suppressAskAgain) { createShowDialogButton(composite); } - if (createRecentWorkspacesComposite) { - createRecentWorkspacesComposite(composite); - } + + // Will create Recent Workspaces Composite always. + createRecentWorkspacesComposite(composite); Dialog.applyDialogFont(composite); return composite; @@ -393,59 +388,19 @@ private void createRecentWorkspacesComposite(final Composite composite) { toggle.addListener(SWT.MouseDown, toggleListener); label.addListener(SWT.MouseDown, toggleListener); - logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before launchData size: " //$NON-NLS-1$ - + (launchData.getRecentWorkspaces() != null ? launchData.getRecentWorkspaces().length : 0)); - String[] workspacesArray = launchData.getRecentWorkspaces(); - List recentWorkspaces = (workspacesArray != null && workspacesArray.length > 0) - ? filterDuplicatedPaths(workspacesArray) - : new ArrayList<>(); - - // NEW CODE: Check if recent workspaces list is empty -// if (recentWorkspaces == null || recentWorkspaces.isEmpty()) { - // Show message in the panel - if (recentWorkspaces == null || recentWorkspaces.isEmpty()) { +// logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before launchData size: " //$NON-NLS-1$ +// + (launchData.getRecentWorkspaces() != null ? launchData.getRecentWorkspaces().length : 0)); + List recentWorkspaces = filterDuplicatedPaths(launchData.getRecentWorkspaces()); + + // Check if recent workspaces list is empty + if (recentWorkspaces.isEmpty()) { Label emptyLabel = new Label(panel, SWT.WRAP); emptyLabel.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_noRecentWorkspaceFound); - emptyLabel.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); } else { Label moreLabel = new Label(panel, SWT.WRAP); moreLabel.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_addMoreRecentWorkspaces); - moreLabel.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); } -// link kind of logic for "Import..." starts -// Link importLink = new Link(panel, SWT.WRAP); -// importLink.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); -// importLink.setText("Import..."); //$NON-NLS-1$ -// importLink.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent e) { -// showImportWorkspacesDialog(); // ALWAYS allow manual import -// } -// }); -//link kind of logic for "Import..." ends - -// DO NOT DELETE -// // Show a prompt dialog when the dialog opens, but only ONCE -// Shell shell = getShell(); -// if (shell != null && !shell.isDisposed() && !hasShownImportPrompt) { -// hasShownImportPrompt = true; // Set flag to prevent showing again -// shell.getDisplay().asyncExec(() -> { -// // Check again if still empty before showing prompt -// // This prevents showing prompt if workspaces were already imported -// List currentWorkspaces = getRecentWorkspaces(); -// if (currentWorkspaces == null || currentWorkspaces.isEmpty()) { -// showImportWorkspacesPromptDialog(); -// } -// }); -// } -//DO NOT DELETE - // Force layout BEFORE return (important) -// panel.layout(true); -// recentWorkspacesForm.layout(true, true); -// recentWorkspacesLinks = new HashMap<>(); -// return; -// } recentWorkspacesLinks = new HashMap<>(recentWorkspaces.size()); Map uniqueWorkspaceNames = createUniqueWorkspaceNameMap(); @@ -481,556 +436,135 @@ public void widgetSelected(SelectionEvent e) { }); link.setMenu(menu); } - logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before recentWorkspaces size: " //$NON-NLS-1$ - + recentWorkspaces.size()); - panel.layout(true); - recentWorkspacesForm.layout(true, true); +// logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before recentWorkspaces size: " //$NON-NLS-1$ +// + recentWorkspaces.size()); +// panel.layout(true); +// recentWorkspacesForm.layout(true, true); } -// DO NOT DELETE -// /** -// * Shows a prompt dialog asking if user wants to import workspaces User can -// * choose to import or cancel and proceed with new workspace -// */ -// private void showImportWorkspacesPromptDialog() { -// Shell shell = getShell(); -// if (shell == null || shell.isDisposed()) { -// return; -// } -// -// // Double-check that workspaces are still empty before showing dialog -// List recentWorkspaces = getRecentWorkspaces(); -// if (recentWorkspaces != null && !recentWorkspaces.isEmpty()) { -// // Workspaces were imported somehow, don't show the dialog -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesPromptDialog] recentWorkspaces is empty so returning"); //$NON-NLS-1$ -// return; -// } -// -// // Create a confirmation dialog -// MessageDialog dialog = new MessageDialog(shell, "No Recent Workspaces", // Title //$NON-NLS-1$ -// null, // Dialog title image -// "No recent workspaces found.\n\nWould you like to import workspaces from a previous Eclipse installation?\n\n", //$NON-NLS-1$ -// // "No recent workspaces found.\n\nWould you like to import workspaces from a -// // previous Eclipse installation?\n\n" / + "• Click 'Import' to browse and -// // import workspaces from a previous Eclipse installation\n" / + "• Click -// // 'Cancel' to proceed with creating a new workspace", // Message -// MessageDialog.QUESTION, // Dialog type -// new String[] { "Import...", "Cancel" }, // Button labels //$NON-NLS-1$ //$NON-NLS-2$ -// 1 // Default button index (Cancel) - so Cancel is the default -// ) { -// @Override -// protected void buttonPressed(int buttonId) { -// if (buttonId == 0) { // Import Workspaces button clicked -// close(); -// // Open directory chooser to select previous Eclipse installation -// DirectoryDialog dirDialog = new DirectoryDialog(shell); -// dirDialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ -// dirDialog.setMessage( -// "Select the directory of a previous Eclipse installation to import its workspaces:"); //$NON-NLS-1$ -// String selectedDir = dirDialog.open(); -// -// if (selectedDir != null) { -// // Import workspaces and refresh -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesPromptDialog] call from importAndRefreshWorkspaces()"); //$NON-NLS-1$ -// importAndRefreshWorkspaces(selectedDir); -// } -// // If user cancels the directory dialog, just close it and do nothing -// // The main dialog remains open and user can proceed with new workspace -// } else { -// // Cancel button clicked - just close this dialog and let user proceed -// close(); -// } -// } -// }; -// dialog.open(); -// } -// -// /** -// * Imports workspaces from selected Eclipse installation and refreshes the UI -// */ -// private void importAndRefreshWorkspaces(String eclipseInstallPath) { -// Shell shell = getShell(); -// if (shell == null || shell.isDisposed()) { -// return; -// } -// -// shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); -// -// try { -// // Find and import workspaces from the selected Eclipse installation -// List importedWorkspaces = importWorkspacesFromEclipseInstallation(eclipseInstallPath); -// -// System.out.println( -// "Found " + (importedWorkspaces != null ? importedWorkspaces.size() : 0) + " workspaces to import"); //$NON-NLS-1$ //$NON-NLS-2$ -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Found " //$NON-NLS-1$ -// + (importedWorkspaces != null ? importedWorkspaces.size() : 0) + " workspaces to import"); //$NON-NLS-1$ -// -// if (importedWorkspaces != null && !importedWorkspaces.isEmpty()) { -// // Get current workspaces using getRecentWorkspaces() (reads from launchData) -// List currentWorkspaces = getRecentWorkspaces(); -// System.out.println("Current workspaces before merge: " //$NON-NLS-1$ -// + (currentWorkspaces != null ? currentWorkspaces.size() : 0)); -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Current workspaces before merge: " //$NON-NLS-1$ -// + (currentWorkspaces != null ? currentWorkspaces.size() : 0)); -// -// // Create a modifiable copy -// List mergedWorkspaces = new ArrayList<>(); -// if (currentWorkspaces != null && !currentWorkspaces.isEmpty()) { -// mergedWorkspaces.addAll(currentWorkspaces); -// } -// -// // Add imported workspaces that aren't already present -// for (String workspace : importedWorkspaces) { -// if (!mergedWorkspaces.contains(workspace)) { -// mergedWorkspaces.add(0, workspace); // Add at beginning to show as most recent -// System.out.println("Added workspace: " + workspace); //$NON-NLS-1$ -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Added workspace: " + workspace); //$NON-NLS-1$ -// } else { -// System.out.println("Workspace already exists: " + workspace); //$NON-NLS-1$ -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Workspace already exists: " //$NON-NLS-1$ -// + workspace); -// } -// } -// -// System.out.println("Merged workspaces count: " + mergedWorkspaces.size()); //$NON-NLS-1$ -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Merged workspaces count: " //$NON-NLS-1$ -// + mergedWorkspaces.size()); -// -// // Update launchData directly with the string array -// updateLaunchDataWorkspaces(mergedWorkspaces); -// -// // Also save to preferences for persistence when Eclipse restarts -// saveRecentWorkspacesToPreferences(mergedWorkspaces); -// -// // Verify the update worked by checking getRecentWorkspaces() again -// List verifyWorkspaces = getRecentWorkspaces(); -// System.out.println("Verification - workspaces after update: " //$NON-NLS-1$ -// + (verifyWorkspaces != null ? verifyWorkspaces.size() : 0)); -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Verification - workspaces after update: " //$NON-NLS-1$ -// + (verifyWorkspaces != null ? verifyWorkspaces.size() : 0)); -// if (verifyWorkspaces != null) { -// for (String ws : verifyWorkspaces) { -// System.out.println(" Verified workspace: " + ws); //$NON-NLS-1$ -// logInfo("[ChooseWorkspaceDialog][importAndRefreshWorkspaces] Verified workspace: " + ws); //$NON-NLS-1$ -// } -// } -// -// // Refresh the UI -// refreshRecentWorkspacesComposite(); -// -// // Show success message only if workspaces were actually imported -// if (verifyWorkspaces != null && !verifyWorkspaces.isEmpty()) { -// MessageDialog.openInformation(shell, "Workspaces Imported", String.format( //$NON-NLS-1$ -// "Successfully imported %d workspace(s) from the previous installation.\n\nYou can now select one of the imported workspaces or continue with a new workspace.", //$NON-NLS-1$ -// importedWorkspaces.size())); -// } else { -// MessageDialog.openWarning(shell, "Workspaces Not Saved", //$NON-NLS-1$ -// "Workspaces were found but could not be saved. Please check the error log."); //$NON-NLS-1$ -// } -// } else { -// // Show warning if no workspaces found -// MessageDialog.openWarning(shell, "No Workspaces Found", //$NON-NLS-1$ -// "No workspaces could be found in the selected Eclipse installation.\n\nPlease select a valid Eclipse installation directory or proceed with creating a new workspace."); //$NON-NLS-1$ -// } -// } finally { -// shell.setCursor(null); -// } -// } -// DO NOT DELETE - /** - * NEW METHOD: Show dialog to import workspaces from previous installation + * Show dialog to import workspaces from previous installation */ -// version 2 private void showImportWorkspacesDialog() { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] START"); //$NON-NLS-1$ - DirectoryDialog dialog = new DirectoryDialog(getShell()); dialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ dialog.setMessage("Select the directory of a previous Eclipse installation"); //$NON-NLS-1$ String selectedDir = dialog.open(); - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected directory: " + selectedDir); //$NON-NLS-1$ - if (selectedDir == null) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled directory selection"); //$NON-NLS-1$ return; } - // Step 1: Detect workspaces + // 1. Detect workspaces List detected = importWorkspaces(selectedDir); - - if (detected == null) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Detected list is NULL"); //$NON-NLS-1$ - return; - } - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Detected workspaces count: " + detected.size()); //$NON-NLS-1$ - - for (String ws : detected) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Detected workspace: " + ws); //$NON-NLS-1$ - } - if (detected.isEmpty()) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ No workspaces found after detection"); //$NON-NLS-1$ MessageDialog.openWarning(getShell(), "No Workspaces Found", "No workspaces found in selected directory."); //$NON-NLS-1$ //$NON-NLS-2$ return; } - // Step 2: Open selection dialog - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Opening WorkspaceImportDialog"); //$NON-NLS-1$ + // 2. Open selection dialog WorkspaceImportDialog selectionDialog = new WorkspaceImportDialog(getShell(), detected, selectedDir, this, Arrays.asList(launchData.getRecentWorkspaces())); - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Dialog created"); //$NON-NLS-1$ - int result = Window.CANCEL; - try { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to call open()"); //$NON-NLS-1$ - result = selectionDialog.open(); - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Dialog open() returned: " + result); //$NON-NLS-1$ - } catch (Exception e) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Exception while opening dialog: " //$NON-NLS-1$ - + e.getMessage()); - e.printStackTrace(); - } - if (result != Window.OK) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled selection dialog"); //$NON-NLS-1$ +// int result = Window.CANCEL; +// try { +// result = selectionDialog.open(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// if (result != Window.OK) { +// return; +// } + if (selectionDialog.open() != Window.OK) { return; } List selected = selectionDialog.getSelected(); - if (selected == null) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ Selected list is NULL"); //$NON-NLS-1$ - return; - } - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected count: " + selected.size()); //$NON-NLS-1$ - - for (String ws : selected) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected workspace: " + ws); //$NON-NLS-1$ - } - if (selected.isEmpty()) { - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] ❌ No workspaces selected"); //$NON-NLS-1$ MessageDialog.openInformation(getShell(), "Nothing Selected", "No workspaces selected."); //$NON-NLS-1$ //$NON-NLS-2$ return; } - // Step 3: Merge - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Merging selected workspaces"); //$NON-NLS-1$ + // 3. Merge mergeSelectedWorkspaces(selected); - logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] END"); //$NON-NLS-1$ } private void mergeSelectedWorkspaces(List selected) { - - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] START"); //$NON-NLS-1$ - if (selected == null) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] ❌ Selected list is NULL"); //$NON-NLS-1$ return; } - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Incoming selected size: " + selected.size()); //$NON-NLS-1$ Set merged = new LinkedHashSet<>(); - - // Step 1: Existing workspaces + // 1. Existing workspaces String[] existing = launchData.getRecentWorkspaces(); - if (existing == null) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Existing workspaces is NULL"); //$NON-NLS-1$ - } else { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Existing count: " + existing.length); //$NON-NLS-1$ - + if (existing != null) { for (String ws : existing) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Checking existing: " + ws); //$NON-NLS-1$ if (ws == null) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping NULL existing"); //$NON-NLS-1$ continue; } File f = new File(ws); if (!f.exists()) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping invalid existing: " + ws); //$NON-NLS-1$ continue; } - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Adding existing: " + ws); //$NON-NLS-1$ merged.add(ws); } } - // Step 2: Add selected + // 2. Add selected for (String ws : selected) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Processing selected: " + ws); //$NON-NLS-1$ - if (ws == null) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping NULL selected"); //$NON-NLS-1$ continue; } File f = new File(ws); if (!f.exists()) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Skipping invalid selected: " + ws); //$NON-NLS-1$ continue; } - if (merged.contains(ws)) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Duplicate ignored: " + ws); //$NON-NLS-1$ - } else { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Adding selected: " + ws); //$NON-NLS-1$ - merged.add(ws); - } + merged.add(ws); } - // Step 3: Final list + // 3. Final list List result = new ArrayList<>(merged); - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Final merged size: " + result.size()); //$NON-NLS-1$ - - for (String ws : result) { - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Final workspace: " + ws); //$NON-NLS-1$ - } - - // Step 4: Persist - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Updating launchData"); //$NON-NLS-1$ + // 4. Persist launchData.setRecentWorkspaces(result.toArray(new String[0])); - - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Saving to preferences"); //$NON-NLS-1$ saveRecentWorkspacesToPreferences(result); - - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Refreshing UI"); //$NON-NLS-1$ refreshRecentWorkspacesComposite(); - - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] Showing confirmation dialog"); //$NON-NLS-1$ - MessageDialog.openInformation(getShell(), "Workspaces Updated", //$NON-NLS-1$ "Imported " + selected.size() + " workspace(s)."); //$NON-NLS-1$ //$NON-NLS-2$ - logInfo("[ChooseWorkspaceDialog][mergeSelectedWorkspaces] END"); //$NON-NLS-1$ } -// version 2 -// version 1 starts. -// private void showImportWorkspacesDialog() { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] === START ==="); //$NON-NLS-1$ -// -// DirectoryDialog dialog = new DirectoryDialog(getShell()); -// dialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ -// dialog.setMessage("Select the directory of a previous Eclipse installation to import its workspaces:"); //$NON-NLS-1$ -// String selectedDir = dialog.open(); -// -// if (selectedDir == null) { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] User cancelled directory selection"); //$NON-NLS-1$ -// return; -// } -// -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Selected directory: " + selectedDir); //$NON-NLS-1$ -// -// // Find and import workspaces from the selected Eclipse installation -// List importedWorkspaces = importWorkspacesFromEclipseInstallation(selectedDir); -// -// if (importedWorkspaces == null || importedWorkspaces.isEmpty()) { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No workspaces found in selected installation"); //$NON-NLS-1$ -// MessageDialog.openWarning(getShell(), "No Workspaces Found", //$NON-NLS-1$ -// "No workspaces could be found in the selected Eclipse installation."); //$NON-NLS-1$ -// return; -// } -// -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Imported workspaces count: " //$NON-NLS-1$ -// + importedWorkspaces.size()); -// -// String[] currentWorkspacesArray = launchData.getRecentWorkspaces(); -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Current workspaces count: " //$NON-NLS-1$ -// + (currentWorkspacesArray != null ? currentWorkspacesArray.length : 0)); -// -// // Quick check if there's anything to add -// boolean hasNewWorkspaces = false; -// if (currentWorkspacesArray != null) { -// for (String imported : importedWorkspaces) { -// if (imported != null && imported.length() > 0) { -// boolean exists = false; -// for (String current : currentWorkspacesArray) { -// if (imported.equals(current)) { -// exists = true; -// break; -// } -// } -// if (!exists && new File(imported).exists()) { -// hasNewWorkspaces = true; -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] New workspace found: " + imported); //$NON-NLS-1$ -// break; -// } -// } -// } -// } else if (!importedWorkspaces.isEmpty()) { -// hasNewWorkspaces = true; -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No current workspaces, all imported are new"); //$NON-NLS-1$ -// } -// -// // Return early if nothing new to add -// if (!hasNewWorkspaces) { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No new workspaces to add, returning early"); //$NON-NLS-1$ -// MessageDialog.openInformation(getShell(), "No New Workspaces", //$NON-NLS-1$ -// "All workspaces from the previous installation are already in your recent workspaces list."); //$NON-NLS-1$ -// return; -// } -// -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Proceeding with merge, has new workspaces: true"); //$NON-NLS-1$ -// -// // Only proceed with merge if there are new workspaces -// int initialCapacity = (currentWorkspacesArray != null ? currentWorkspacesArray.length : 0) -// + importedWorkspaces.size(); -// Set uniqueWorkspacesSet = new LinkedHashSet<>(initialCapacity); -// -// // Add current workspaces -// int removedCount = 0; -// if (currentWorkspacesArray != null) { -// for (int i = 0; i < currentWorkspacesArray.length; i++) { -// String ws = currentWorkspacesArray[i]; -// if (ws != null && ws.length() > 0) { -// File wsFile = new File(ws); -// if (wsFile.exists()) { -// uniqueWorkspacesSet.add(ws); -// } else { -// removedCount++; -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Removing non-existent workspace: " //$NON-NLS-1$ -// + ws); -// } -// } -// } -// } -// -// // Add new imported workspaces -// int addedCount = 0; -// for (int i = 0; i < importedWorkspaces.size(); i++) { -// String ws = importedWorkspaces.get(i); -// if (ws != null && ws.length() > 0) { -// File wsFile = new File(ws); -// if (wsFile.exists() && uniqueWorkspacesSet.add(ws)) { -// addedCount++; -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Adding workspace: " + ws); //$NON-NLS-1$ -// } -// } -// } -// -// List mergedWorkspaces = new ArrayList<>(uniqueWorkspacesSet); -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] mergedWorkspaces.size(): " //$NON-NLS-1$ -// + mergedWorkspaces.size()); -// -// if (mergedWorkspaces.isEmpty()) { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] No valid workspaces after merge"); //$NON-NLS-1$ -// MessageDialog.openWarning(getShell(), "No Valid Workspaces", "No valid workspaces found."); //$NON-NLS-1$ //$NON-NLS-2$ -// return; -// } -// -// // Update in-memory first - //// try { / java.lang.reflect.Field field = - /// launchData.getClass().getDeclaredField("recentWorkspaces"); //$NON-NLS-1$ / - /// field.setAccessible(true); / field.set(launchData, - /// mergedWorkspaces.toArray(new String[0])); / - /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Updated - /// launchData via reflection, launchData.getRecentWorkspaces().length: " - /// //$NON-NLS-1$ / + launchData.getRecentWorkspaces().length); / } catch - /// (Exception e) { / - /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Reflection - /// failed, using setter: " //$NON-NLS-1$ / + e.getMessage()); / - /// launchData.setRecentWorkspaces(mergedWorkspaces.toArray(new String[0])); / } -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Before updating launchData without reflection, launchData.getRecentWorkspaces().length: " //$NON-NLS-1$ -// + launchData.getRecentWorkspaces().length); -// launchData.setRecentWorkspaces(mergedWorkspaces.toArray(new String[0])); // instead of reflection -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Updated launchData without reflection, launchData.getRecentWorkspaces().length: " //$NON-NLS-1$ -// + launchData.getRecentWorkspaces().length); -// -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to save to preferences"); //$NON-NLS-1$ -// // Single file write -// saveRecentWorkspacesToPreferences(mergedWorkspaces); -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Saved preferences"); //$NON-NLS-1$ -// -// // Update UI immediately -// if (recentWorkspacesForm != null && !recentWorkspacesForm.isDisposed()) { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] Refreshing UI in normal thread"); //$NON-NLS-1$ -// refreshRecentWorkspacesComposite(); - //// getShell().getDisplay().asyncExec(() -> { / if (recentWorkspacesForm != - /// null && !recentWorkspacesForm.isDisposed()) { / - /// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] About to enter - /// refreshRecentWorkspacesComposite() in UI thread"); //$NON-NLS-1$ / - /// refreshRecentWorkspacesComposite(); / } / }); -// } else { -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] recentWorkspacesForm is null or disposed, cannot refresh"); //$NON-NLS-1$ -// } -// -// String message = String.format("Imported %d new workspace(s).", addedCount); //$NON-NLS-1$ -// if (removedCount > 0) { -// message += String.format("\nRemoved %d non-existent workspace(s).", removedCount); //$NON-NLS-1$ -// } -// logInfo("[ChooseWorkspaceDialog][showImportWorkspacesDialog] === END, " + message); //$NON-NLS-1$ -// MessageDialog.openInformation(getShell(), "Workspaces Updated", message); //$NON-NLS-1$ -// } -// version 1 ends private List importWorkspaces(File directory) { - logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] START: " + directory); //$NON-NLS-1$ // capture return value List result = importWorkspacesFromEclipseInstallation(directory.getAbsolutePath()); if (result == null) { - logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] ❌ result is NULL"); //$NON-NLS-1$ result = new ArrayList<>(); } - logInfo("[ChooseWorkspaceDialog][importWorkspaces(File)] END size=" + result.size()); //$NON-NLS-1$ return result; } public List importWorkspaces(String path) { - logInfo("[ChooseWorkspaceDialog][importWorkspaces(String)] path=" + path); //$NON-NLS-1$ return importWorkspaces(new File(path)); // ✅ now VALID } /** - * NEW METHOD: Method to save workspaces to preferences + * Method to save workspaces to preferences */ private void saveRecentWorkspacesToPreferences(List workspaces) { -/* logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Entered saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); if (workspaces == null || workspaces.isEmpty()) { store.setValue(RECENT_WORKSPACES, ""); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] returning..."); //$NON-NLS-1$ return; } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < workspaces.size(); i++) { - if (i > 0) { - sb.append("\n"); //$NON-NLS-1$ - } - sb.append(workspaces.get(i)); - } - store.setValue(RECENT_WORKSPACES, sb.toString()); - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Properly exiting saveRecentWorkspacesToPreferences(), sb.toString(): " //$NON-NLS-1$ - + sb.toString()); -// original implementation. -*/ - - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Entered saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ - IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); - if (workspaces == null || workspaces.isEmpty()) { - store.setValue(RECENT_WORKSPACES, ""); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] looks like workspaces is empty or null so returning"); //$NON-NLS-1$ - return; - } - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] About to build sb"); //$NON-NLS-1$ -// StringBuilder sb = new StringBuilder(); -// for (int i = 0; i < mergedWorkspaces.size(); i++) { -// if (i > 0) { -// sb.append("\n"); //$NON-NLS-1$ -// } -// sb.append(mergedWorkspaces.get(i)); -// } -// store.setValue(RECENT_WORKSPACES, sb.toString()); try { StringBuilder sb = new StringBuilder(); for (int i = 0; i < workspaces.size(); i++) { String ws = workspaces.get(i); - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Processing workspace index " + i //$NON-NLS-1$ - + ": " //$NON-NLS-1$ - + ws); if (ws == null) { - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] NULL workspace found at index " //$NON-NLS-1$ - + i); continue; } if (i > 0) { @@ -1038,47 +572,30 @@ private void saveRecentWorkspacesToPreferences(List workspaces) { } sb.append(ws); } -// store.setValue(RECENT_WORKSPACES, sb.toString()); // option 1 -// IEclipsePreferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.ui.ide"); //$NON-NLS-1$ -// prefs.put(RECENT_WORKSPACES, sb.toString()); -// prefs.flush(); // option 2 + if (Platform.getInstanceLocation().isSet()) { store.setValue(RECENT_WORKSPACES, sb.toString()); - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] references updated, sb.toString(): " //$NON-NLS-1$ - + sb.toString()); } else { logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Instance location not set yet. Skipping preference save."); //$NON-NLS-1$ - } // option 3 - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] references updated, sb.toString(): " //$NON-NLS-1$ - + sb.toString()); + } } catch (Exception e) { - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] EXCEPTION in saving preferences: " //$NON-NLS-1$ - + e.getMessage()); e.printStackTrace(); } - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Exiting from saveRecentWorkspacesToPreferences()"); //$NON-NLS-1$ } /** - * NEW METHOD: Method to import workspaces from previous Eclipse installation + * Method to import workspaces from previous Eclipse installation */ private List importWorkspacesFromEclipseInstallation(String eclipseInstallPath) { List workspaces = new ArrayList<>(); - System.out.println("Looking for workspaces in: " + eclipseInstallPath); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Looking for workspaces in: " + eclipseInstallPath); //$NON-NLS-1$ // Try to find workspaces from the previous installation // Look for the configuration/.settings/org.eclipse.ui.ide.prefs file File configDir = new File(eclipseInstallPath, "configuration"); //$NON-NLS-1$ File settingsDir = new File(configDir, ".settings"); //$NON-NLS-1$ File recentWorkspacesFile = new File(settingsDir, "org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ - System.out.println("Looking for preferences file at: " + recentWorkspacesFile.getAbsolutePath()); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Looking for preferences file at: " //$NON-NLS-1$ - + recentWorkspacesFile.getAbsolutePath()); if (recentWorkspacesFile.exists()) { - System.out.println("Found preferences file"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found preferences file"); //$NON-NLS-1$ try { // Parse the preferences file to extract recent workspaces Properties props = new Properties(); @@ -1087,8 +604,6 @@ private List importWorkspacesFromEclipseInstallation(String eclipseInsta } String recentWorkspacesValue = props.getProperty("RECENT_WORKSPACES"); //$NON-NLS-1$ - System.out.println("RECENT_WORKSPACES value: " + recentWorkspacesValue); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] RECENT_WORKSPACES value: " + recentWorkspacesValue); //$NON-NLS-1$ if (recentWorkspacesValue != null && !recentWorkspacesValue.isEmpty()) { // Parse the workspaces (format is paths separated by newlines) String[] workspacePaths = recentWorkspacesValue.split("\\n"); //$NON-NLS-1$ @@ -1098,54 +613,28 @@ private List importWorkspacesFromEclipseInstallation(String eclipseInsta File wsFile = new File(path); if (wsFile.exists()) { workspaces.add(path); - System.out.println("Found existing workspace: " + path); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found existing workspace: " + path); //$NON-NLS-1$ - } else { - System.out.println("Workspace path does not exist: " + path); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Workspace path does not exist: " //$NON-NLS-1$ - + path); } } } - } else { - System.out.println("RECENT_WORKSPACES property is empty or null"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] RECENT_WORKSPACES property is empty or null"); //$NON-NLS-1$ } } catch (IOException e) { - System.err.println("Error reading preferences file: " + e.getMessage()); //$NON-NLS-1$ - logError("[ChooseWorkspaceDialog][importWorkspaces] Error reading preferences file: ", e); //$NON-NLS-1$ e.printStackTrace(); } } else { - System.out.println("Preferences file not found at: " + recentWorkspacesFile.getAbsolutePath()); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Preferences file not found at: " //$NON-NLS-1$ - + recentWorkspacesFile.getAbsolutePath()); - // Try alternative location File alternativePrefs = new File(eclipseInstallPath, ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ - System.out.println("Checking alternative location: " + alternativePrefs.getAbsolutePath()); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Checking alternative location: " //$NON-NLS-1$ - + alternativePrefs.getAbsolutePath()); if (alternativePrefs.exists()) { - System.out.println("Found alternative preferences file"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Found alternative preferences file"); //$NON-NLS-1$ // Parse it similarly... } } - - System.out.println("Total workspaces found: " + workspaces.size()); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][importWorkspaces] Total workspaces found: " + workspaces.size()); //$NON-NLS-1$ return workspaces; } /** - * NEW METHOD: Method to refresh the recent workspaces composite after import + * Method to refresh the recent workspaces composite after import */ private void refreshRecentWorkspacesComposite() { - System.out.println("Entering refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Entering refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ - // Get the parent composite Composite parent = recentWorkspacesForm.getParent(); if (parent != null && !parent.isDisposed()) { @@ -1186,14 +675,7 @@ private void refreshRecentWorkspacesComposite() { shell.setBounds(getConstrainedShellBounds( new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y))); } - - System.out.println("Refresh completed"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Refresh completed"); //$NON-NLS-1$ - } else { - System.out.println("Parent composite is null or disposed"); //$NON-NLS-1$ - logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Parent composite is null or disposed"); //$NON-NLS-1$ } - logInfo("[ChooseWorkspaceDialog][refreshRecentWorkspacesComposite] Exiting refreshRecentWorkspacesComposite()"); //$NON-NLS-1$ } /** @@ -1545,8 +1027,7 @@ protected boolean isResizable() { } private List getRecentWorkspaces() { - String[] workspaces = launchData.getRecentWorkspaces(); - return filterDuplicatedPaths(workspaces); + return filterDuplicatedPaths(launchData.getRecentWorkspaces()); } /** @@ -1571,8 +1052,7 @@ public static List filterDuplicatedPaths(String[] paths) { if (workspace.startsWith(File.separator)) { normalizedPath = File.separator + normalizedPath; } - boolean nonDuplicate = normalizedPaths.add(normalizedPath); - if (nonDuplicate) { + if (normalizedPaths.add(normalizedPath)) { recentWorkspaces.add(workspace); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java index d6a76f8d4a5..475036ac2a1 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java @@ -1031,6 +1031,8 @@ public class IDEWorkbenchMessages extends NLS { public static String ChooseWorkspaceDialog_NotWriteablePathWarning; public static String ChooseWorkspaceDialog_useDefaultMessage; + public static String WorkspaceImportDialog_browseLabel; + public static String ChooseWorkspaceWithSettingsDialog_SettingsGroupName; public static String ChooseWorkspaceWithSettingsDialog_ProblemsTransferTitle; public static String ChooseWorkspaceWithSettingsDialog_TransferFailedMessage; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java index 61d4888c53f..a7c40269501 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java @@ -62,14 +62,12 @@ public WorkspaceImportDialog(Shell parentShell, List input, String baseI this.baseInstallPath = baseInstallPath; this.parentDialog = parentDialog; this.existingWorkspaces = existingWorkspaces; - logInfo("[WorkspaceImportDialog][ctor] Existing count: " + existingWorkspaces.size()); //$NON-NLS-1$ } @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Import Workspaces"); // Window title //$NON-NLS-1$ - logInfo("[WorkspaceImportDialog][configureShell] Title set"); //$NON-NLS-1$ } @Override @@ -77,101 +75,66 @@ public void create() { super.create(); setTitle("Import Workspaces"); //$NON-NLS-1$ setMessage("Select workspaces to import."); //$NON-NLS-1$ - logInfo("[WorkspaceImportDialog][create] Title + Message set"); //$NON-NLS-1$ } - private void logInfo(String msg) { - System.out.println(msg); // or route to your logger - } +// private void logInfo(String msg) { +// System.out.println(msg); // or route to your logger +// } @Override protected Control createDialogArea(Composite parent) { - - logInfo("[WorkspaceImportDialog][createDialogArea] START"); //$NON-NLS-1$ - Composite container = (Composite) super.createDialogArea(parent); container.setLayout(new GridLayout(1, false)); - // FIX ORDER - logInfo("[WorkspaceImportDialog] -> createLocationRow()"); //$NON-NLS-1$ createLocationRow(container); - - logInfo("[WorkspaceImportDialog] -> createFilter()"); //$NON-NLS-1$ createFilter(container); - - logInfo("[WorkspaceImportDialog] -> createTable()"); //$NON-NLS-1$ createTable(container); - - logInfo("[WorkspaceImportDialog] -> loadInitialInput()"); //$NON-NLS-1$ loadInitialInput(); - - logInfo("[WorkspaceImportDialog] -> createButtons()"); //$NON-NLS-1$ createButtons(container); - - logInfo("[WorkspaceImportDialog][createDialogArea] END"); //$NON-NLS-1$ return container; } private void createLocationRow(Composite parent) { - logInfo("[WorkspaceImportDialog][createLocationRow] START"); //$NON-NLS-1$ - Composite row = new Composite(parent, SWT.NONE); row.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); row.setLayout(new GridLayout(3, false)); new Label(row, SWT.NONE).setText("Workspace location:"); //$NON-NLS-1$ - locationText = new Text(row, SWT.BORDER); locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); if (baseInstallPath != null) { locationText.setText(baseInstallPath); - logInfo("[WorkspaceImportDialog] Using baseInstallPath: " + baseInstallPath); //$NON-NLS-1$ } Button browse = new Button(row, SWT.PUSH); - browse.setText("Browse..."); //$NON-NLS-1$ + browse.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_browseLabel); browse.addListener(SWT.Selection, e -> { - - logInfo("[WorkspaceImportDialog][Browse] CLICKED"); //$NON-NLS-1$ - DirectoryDialog dlg = new DirectoryDialog(parent.getShell()); dlg.setText("Select Eclipse Installation"); //$NON-NLS-1$ dlg.setMessage("Select installation directory"); //$NON-NLS-1$ - - String selected = dlg.open(); - - logInfo("[WorkspaceImportDialog][Browse] Selected: " + selected); //$NON-NLS-1$ - - if (selected != null) { - locationText.setText(selected); - + String selectedPath = dlg.open(); + if (selectedPath != null) { + locationText.setText(selectedPath); // reload workspaces - reloadWorkspaces(selected); + reloadWorkspaces(selectedPath); } }); - logInfo("[WorkspaceImportDialog][createLocationRow] END"); //$NON-NLS-1$ } private void createFilter(Composite parent) { - logInfo("[WorkspaceImportDialog][createFilter] START"); //$NON-NLS-1$ // Add ICON_CANCEL Text filter = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); filter.setMessage("type filter text"); //$NON-NLS-1$ filter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - logInfo("[WorkspaceImportDialog][createFilter] Search field with clear icon created"); //$NON-NLS-1$ // FILTER LOGIC filter.addModifyListener(e -> { String raw = filter.getText(); - logInfo("[WorkspaceImportDialog][createFilter] Raw: '" + raw + "'"); //$NON-NLS-1$ //$NON-NLS-2$ - if (raw == null || raw.trim().isEmpty()) { - logInfo("[WorkspaceImportDialog][createFilter] Clearing filter"); //$NON-NLS-1$ viewer.resetFilters(); } else { String txt = raw.toLowerCase().replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$ - logInfo("[WorkspaceImportDialog][createFilter] Applying filter: " + txt); //$NON-NLS-1$ viewer.setFilters(new ViewerFilter[] { new ViewerFilter() { @Override public boolean select(Viewer v, Object p, Object el) { @@ -182,46 +145,32 @@ public boolean select(Viewer v, Object p, Object el) { }); } viewer.refresh(); - // CRITICAL: restore check state AFTER refresh + // Restore check state AFTER refresh viewer.setCheckedElements(checkedElements.toArray()); - logInfo("[WorkspaceImportDialog][createFilter] Check state restored"); //$NON-NLS-1$ }); // HANDLE CLEAR BUTTON CLICK filter.addListener(SWT.DefaultSelection, e -> { - logInfo("[WorkspaceImportDialog][createFilter] ❌ Clear (X) clicked"); //$NON-NLS-1$ filter.setText(""); // triggers modify listener → resets filter //$NON-NLS-1$ }); - logInfo("[WorkspaceImportDialog][createFilter] END"); //$NON-NLS-1$ } private void loadInitialInput() { - logInfo("[WorkspaceImportDialog][loadInitialInput] START"); //$NON-NLS-1$ - if (input == null) { - logInfo("[WorkspaceImportDialog][loadInitialInput] ❌ input is NULL"); //$NON-NLS-1$ return; } List filtered = new ArrayList<>(); for (String ws : input) { if (ws == null || ws.trim().isEmpty()) { - logInfo("[WorkspaceImportDialog][loadInitialInput] Skipping NULL/empty"); //$NON-NLS-1$ continue; } if (existingWorkspaces != null && existingWorkspaces.contains(ws)) { - logInfo("[WorkspaceImportDialog][loadInitialInput] Skipping already existing: " + ws); //$NON-NLS-1$ continue; } - filtered.add(ws); } - logInfo("[WorkspaceImportDialog][loadInitialInput] Final size: " + filtered.size()); //$NON-NLS-1$ - - for (String ws : filtered) { - logInfo("[WorkspaceImportDialog][loadInitialInput] Adding: " + ws); //$NON-NLS-1$ - } // SET INPUT viewer.setInput(filtered); @@ -229,32 +178,22 @@ private void loadInitialInput() { // CHECK ALL by default checkedElements.clear(); checkedElements.addAll(filtered); - viewer.setCheckedElements(checkedElements.toArray()); - viewer.refresh(); - logInfo("[WorkspaceImportDialog][loadInitialInput] END"); //$NON-NLS-1$ } private void createTable(Composite parent) { - logInfo("[WorkspaceImportDialog][createTable] START"); //$NON-NLS-1$ - try { viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SHADOW_IN); - logInfo("[WorkspaceImportDialog][createTable] Viewer created"); //$NON-NLS-1$ Table table = viewer.getTable(); - table.setHeaderVisible(true); table.setLinesVisible(true); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumHeight = 250; table.setLayoutData(gd); - logInfo("[WorkspaceImportDialog][createTable] GridData applied with min height"); //$NON-NLS-1$ - - logInfo("[WorkspaceImportDialog][createTable] Table configured"); //$NON-NLS-1$ // Column 1 TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE); @@ -265,7 +204,6 @@ private void createTable(Composite parent) { @Override public String getText(Object element) { String name = new File((String) element).getName(); - logInfo("[WorkspaceImportDialog][col1] getText: " + name); //$NON-NLS-1$ return name; } }); @@ -278,87 +216,26 @@ public String getText(Object element) { col2.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { - logInfo("[WorkspaceImportDialog][col2] path: " + element); //$NON-NLS-1$ return (String) element; } }); viewer.setContentProvider(ArrayContentProvider.getInstance()); - logInfo("[WorkspaceImportDialog][createTable] Content provider set"); //$NON-NLS-1$ - - // INPUT LOGGING - if (input == null) { - logInfo("[WorkspaceImportDialog][createTable] ❌ input is NULL"); //$NON-NLS-1$ - } else { - logInfo("[WorkspaceImportDialog][createTable] input size: " + input.size()); //$NON-NLS-1$ - for (String s : input) { - logInfo("[WorkspaceImportDialog][createTable] input: " + s); //$NON-NLS-1$ - } - } - -// // FILTER VALID -// Set valid = new LinkedHashSet<>(); -// -// if (input != null) { -// for (String s : input) { -// -// if (s == null) { -// logInfo("[WorkspaceImportDialog][createTable] skipping NULL"); //$NON-NLS-1$ -// continue; -// } -// -// File f = new File(s); -// -// if (!f.exists()) { -// logInfo("[WorkspaceImportDialog][createTable] skipping not exists: " + s); //$NON-NLS-1$ -// continue; -// } -// -// if (!f.isDirectory()) { -// logInfo("[WorkspaceImportDialog][createTable] skipping not dir: " + s); //$NON-NLS-1$ -// continue; -// } -// -// logInfo("[WorkspaceImportDialog][createTable] VALID: " + s); //$NON-NLS-1$ -// valid.add(s); -// } -// } -// logInfo("[WorkspaceImportDialog][createTable] valid size: " + valid.size()); //$NON-NLS-1$ -// -// List finalList = new ArrayList<>(valid); -// -// for (String s : finalList) { -// logInfo("[WorkspaceImportDialog][createTable] FINAL LIST: " + s); //$NON-NLS-1$ -// } - viewer.addCheckStateListener(event -> { String element = (String) event.getElement(); if (event.getChecked()) { checkedElements.add(element); - logInfo("[CheckState] CHECKED: " + element); //$NON-NLS-1$ } else { checkedElements.remove(element); - logInfo("[CheckState] UNCHECKED: " + element); //$NON-NLS-1$ } }); -// viewer.setInput(finalList); -// logInfo("[WorkspaceImportDialog][createTable] viewer.setInput DONE"); //$NON-NLS-1$ -// -// viewer.refresh(); -// logInfo("[WorkspaceImportDialog][createTable] viewer.refresh DONE"); //$NON-NLS-1$ -// -// viewer.setAllChecked(true); -// logInfo("[WorkspaceImportDialog][createTable] viewer.setAllChecked DONE"); //$NON-NLS-1$ } catch (Exception e) { - logInfo("[WorkspaceImportDialog][createTable] ❌ Exception: " + e.getMessage()); //$NON-NLS-1$ e.printStackTrace(); } - logInfo("[WorkspaceImportDialog][createTable] END"); //$NON-NLS-1$ } private void createButtons(Composite parent) { - logInfo("[WorkspaceImportDialog][createButtons] START"); //$NON-NLS-1$ try { Composite bar = new Composite(parent, SWT.NONE); bar.setLayout(new GridLayout(2, false)); @@ -367,20 +244,16 @@ private void createButtons(Composite parent) { Button selectAll = new Button(bar, SWT.PUSH); selectAll.setText("Select All"); //$NON-NLS-1$ selectAll.addListener(SWT.Selection, e -> { - logInfo("[WorkspaceImportDialog][createButtons] Select All (VISIBLE) clicked"); //$NON-NLS-1$ if (viewer == null) { - logInfo("[WorkspaceImportDialog][createButtons] ❌ viewer NULL"); //$NON-NLS-1$ return; } TableItem[] items = viewer.getTable().getItems(); - logInfo("[SelectAll] Visible items count: " + items.length); //$NON-NLS-1$ for (TableItem item : items) { Object data = item.getData(); if (data instanceof String) { viewer.setChecked(data, true); checkedElements.add((String) data); - logInfo("[SelectAll] CHECKED: " + data); //$NON-NLS-1$ } } }); @@ -389,51 +262,39 @@ private void createButtons(Composite parent) { Button deselectAll = new Button(bar, SWT.PUSH); deselectAll.setText("Deselect All"); //$NON-NLS-1$ deselectAll.addListener(SWT.Selection, e -> { - logInfo("[WorkspaceImportDialog][createButtons] Deselect All (VISIBLE) clicked"); //$NON-NLS-1$ if (viewer == null) { - logInfo("[WorkspaceImportDialog][createButtons] ❌ viewer NULL"); //$NON-NLS-1$ return; } TableItem[] items = viewer.getTable().getItems(); - logInfo("[DeselectAll] Visible items count: " + items.length); //$NON-NLS-1$ for (TableItem item : items) { Object data = item.getData(); if (data instanceof String) { viewer.setChecked(data, false); checkedElements.remove(data); - logInfo("[DeselectAll] UNCHECKED: " + data); //$NON-NLS-1$ } } }); } catch (Exception e) { - logInfo("[WorkspaceImportDialog][createButtons] ❌ Exception: " + e.getMessage()); //$NON-NLS-1$ e.printStackTrace(); } - logInfo("[WorkspaceImportDialog][createButtons] END"); //$NON-NLS-1$ } @Override protected void okPressed() { - logInfo("[WorkspaceImportDialog][okPressed] START"); //$NON-NLS-1$ - if (viewer == null) { - logInfo("[WorkspaceImportDialog][okPressed] ❌ viewer is NULL"); //$NON-NLS-1$ super.okPressed(); return; } + selected.clear(); Object[] checked = viewer.getCheckedElements(); - - logInfo("[WorkspaceImportDialog][okPressed] checked count: " + checked.length); //$NON-NLS-1$ - for (Object o : checked) { - logInfo("[WorkspaceImportDialog][okPressed] selected: " + o); //$NON-NLS-1$ selected.add((String) o); } - - logInfo("[WorkspaceImportDialog][okPressed] END"); //$NON-NLS-1$ - +// for (Object o : checked) { +// selected.add((String) o); +// } super.okPressed(); } @@ -442,44 +303,32 @@ public List getSelected() { } private void reloadWorkspaces(String newPath) { - logInfo("[WorkspaceImportDialog][reloadWorkspaces] START: " + newPath); //$NON-NLS-1$ - if (parentDialog == null) { - logInfo("[WorkspaceImportDialog][reloadWorkspaces] ❌ parentDialog NULL"); //$NON-NLS-1$ return; } List rawList = parentDialog.importWorkspaces(newPath); if (rawList == null) { - logInfo("[WorkspaceImportDialog][reloadWorkspaces] ❌ rawList NULL"); //$NON-NLS-1$ return; } List filtered = new ArrayList<>(); for (String ws : rawList) { - if (ws == null || ws.trim().isEmpty()) { continue; } if (existingWorkspaces != null && existingWorkspaces.contains(ws)) { - logInfo("[WorkspaceImportDialog][reloadWorkspaces] Skipping existing: " + ws); //$NON-NLS-1$ continue; } - filtered.add(ws); } - logInfo("[WorkspaceImportDialog][reloadWorkspaces] Filtered size: " + filtered.size()); //$NON-NLS-1$ viewer.setInput(filtered); - // ALWAYS check all after browse checkedElements.clear(); checkedElements.addAll(filtered); - viewer.setCheckedElements(checkedElements.toArray()); - viewer.refresh(); - logInfo("[WorkspaceImportDialog][reloadWorkspaces] END"); //$NON-NLS-1$ } } \ No newline at end of file diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties index cd97a0f72c2..87ad7aabbb4 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties @@ -1060,7 +1060,7 @@ ChooseWorkspaceWithSettingsDialog_SaveSettingsFailed=Could not save settings ChooseWorkspaceWithSettingsDialog_ClassCreationFailed= Could not instantiate {0} ChooseWorkspaceWithSettingsDialog_copySettingsDecoLabel=Target workspace exists. Existing values will be overwritten. - +WorkspaceImportDialog_browseLabel=&Browse... IDEApplication_workspaceMandatoryTitle=Workspace is Mandatory IDEApplication_workspaceMandatoryMessage=IDEs need a valid workspace. Restart without the @none option. From 979ee9898bda40edc1735c34219ad95b66da3bf8 Mon Sep 17 00:00:00 2001 From: Deepika Udayagiri Date: Fri, 8 May 2026 15:26:07 +0530 Subject: [PATCH 3/3] Updated to popup dialogs when selected installation doesnt have any workspaces or has already imported workspaces, add javadoc, update removeWorkspaceFromLauncher(). --- .../internal/ide/ChooseWorkspaceDialog.java | 275 ++++++++--------- .../ui/internal/ide/IDEWorkbenchMessages.java | 25 ++ .../internal/ide/WorkspaceImportDialog.java | 278 ++++++++++-------- .../ui/internal/ide/messages.properties | 28 +- 4 files changed, 333 insertions(+), 273 deletions(-) diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java index aad2eb1af94..1d3e7619160 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java @@ -38,9 +38,7 @@ import java.util.stream.Collectors; import org.eclipse.core.runtime.IProduct; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; @@ -80,7 +78,6 @@ import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.osgi.framework.FrameworkUtil; /** @@ -90,6 +87,8 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog { private static final String TILDE = "~"; //$NON-NLS-1$ + private static final String EMPTY = ""; //$NON-NLS-1$ + private static final String RECENT_WORKSPACES = "RECENT_WORKSPACES"; //$NON-NLS-1$ private static final String OPEN_FOLDER_EMOJI = new String( @@ -111,18 +110,6 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog { private Button defaultButton; - // private boolean hasShownImportPrompt = false; - private static final String PLUGIN_ID = FrameworkUtil.getBundle(ChooseWorkspaceDialog.class).getSymbolicName(); - private void log(int severity, String message, Throwable t) { - Platform.getLog(FrameworkUtil.getBundle(getClass())).log(new Status(severity, PLUGIN_ID, message, t)); - } - private void logInfo(String msg) { - log(IStatus.INFO, msg, null); - } - private void logError(String msg, Throwable t) { - log(IStatus.ERROR, msg, t); - } - /** * Create a modal dialog on the argument shell, using and updating the * argument data object. @@ -212,7 +199,7 @@ protected Control createDialogArea(Composite parent) { createShowDialogButton(composite); } - // Will create Recent Workspaces Composite always. + // Create Recent Workspaces Composite always. createRecentWorkspacesComposite(composite); Dialog.applyDialogFont(composite); @@ -297,14 +284,13 @@ private void removeWorkspaceFromLauncher(String workspace, Combo combo) { recentWorkpaces.remove(workspace); launchData.setRecentWorkspaces(recentWorkpaces.toArray(new String[0])); launchData.writePersistedData(); - // Remove Workspace Composite - recentWorkspacesLinks.get(workspace).dispose(); + + // Remove Workspace link recentWorkspacesLinks.remove(workspace); - if (recentWorkspacesLinks.isEmpty()) { - recentWorkspacesForm.dispose(); - } - getShell().layout(); - initializeBounds(); + + // Refresh Recent Workspaces section + refreshRecentWorkspacesComposite(); + // Remove Workspace from combobox combo.remove(workspace); if (combo.getText().equals(workspace) || combo.getText().isEmpty()) { @@ -328,9 +314,9 @@ protected void cancelPressed() { } /** - * The Recent Workspaces area of the dialog is only shown if Recent - * Workspaces are defined. It provides a faster way to launch a specific - * Workspace + * Creates the Recent Workspaces section in the launcher dialog. Displays + * previously used workspaces and provides options to select, remove, and import + * workspaces. */ private void createRecentWorkspacesComposite(final Composite composite) { recentWorkspacesForm = new Composite(composite, SWT.NONE); @@ -388,8 +374,6 @@ private void createRecentWorkspacesComposite(final Composite composite) { toggle.addListener(SWT.MouseDown, toggleListener); label.addListener(SWT.MouseDown, toggleListener); -// logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before launchData size: " //$NON-NLS-1$ -// + (launchData.getRecentWorkspaces() != null ? launchData.getRecentWorkspaces().length : 0)); List recentWorkspaces = filterDuplicatedPaths(launchData.getRecentWorkspaces()); // Check if recent workspaces list is empty @@ -436,19 +420,15 @@ public void widgetSelected(SelectionEvent e) { }); link.setMenu(menu); } -// logInfo("[ChooseWorkspaceDialog][createRecentWorkspacesComposite] Before recentWorkspaces size: " //$NON-NLS-1$ -// + recentWorkspaces.size()); -// panel.layout(true); -// recentWorkspacesForm.layout(true, true); } /** - * Show dialog to import workspaces from previous installation + * Opens a dialog to import workspaces from a previous Eclipse installation. */ private void showImportWorkspacesDialog() { DirectoryDialog dialog = new DirectoryDialog(getShell()); - dialog.setText("Select Previous Eclipse Installation"); //$NON-NLS-1$ - dialog.setMessage("Select the directory of a previous Eclipse installation"); //$NON-NLS-1$ + dialog.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_importPreviousInstallationWindowTitle); + dialog.setMessage(IDEWorkbenchMessages.ChooseWorkspaceDialog_importPreviousInstallationWindowMessage); String selectedDir = dialog.open(); if (selectedDir == null) { @@ -458,40 +438,56 @@ private void showImportWorkspacesDialog() { // 1. Detect workspaces List detected = importWorkspaces(selectedDir); if (detected.isEmpty()) { - MessageDialog.openWarning(getShell(), "No Workspaces Found", "No workspaces found in selected directory."); //$NON-NLS-1$ //$NON-NLS-2$ + MessageDialog.openWarning(getShell(), IDEWorkbenchMessages.ChooseWorkspaceDialog_noWorkspacesFoundTitle, + IDEWorkbenchMessages.ChooseWorkspaceDialog_noWorkspacesFoundMessage); return; } - // 2. Open selection dialog - WorkspaceImportDialog selectionDialog = new WorkspaceImportDialog(getShell(), detected, selectedDir, this, - Arrays.asList(launchData.getRecentWorkspaces())); - -// int result = Window.CANCEL; -// try { -// result = selectionDialog.open(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// if (result != Window.OK) { -// return; -// } + // 2. Remove already imported workspaces + List existing = filterDuplicatedPaths(launchData.getRecentWorkspaces()); + List filtered = new ArrayList<>(); + + for (String ws : detected) { + if (!existing.contains(ws)) { + filtered.add(ws); + } + } + + // 3. All workspaces already imported + if (filtered.isEmpty()) { + MessageDialog.openInformation(getShell(), IDEWorkbenchMessages.ChooseWorkspaceDialog_noNewWorkspacesTitle, + IDEWorkbenchMessages.ChooseWorkspaceDialog_noNewWorkspacesMessage); + return; + } + + // 4. Open selection dialog + WorkspaceImportDialog selectionDialog = new WorkspaceImportDialog(getShell(), filtered, selectedDir, this, + existing); + if (selectionDialog.open() != Window.OK) { return; } List selected = selectionDialog.getSelected(); - if (selected.isEmpty()) { - MessageDialog.openInformation(getShell(), "Nothing Selected", "No workspaces selected."); //$NON-NLS-1$ //$NON-NLS-2$ + if (selected == null || selected.isEmpty()) { + MessageDialog.openInformation(getShell(), IDEWorkbenchMessages.ChooseWorkspaceDialog_nothingSelectedTitle, + IDEWorkbenchMessages.ChooseWorkspaceDialog_nothingSelectedMessage); return; } - // 3. Merge + // 5. Merge mergeSelectedWorkspaces(selected); } + /** + * Merges selected workspaces with existing recent workspaces, removes + * duplicates, persists the updated list, and refreshes the recent workspaces + * UI. + * + * @param selected the workspaces selected for import + */ private void mergeSelectedWorkspaces(List selected) { - if (selected == null) { + if (selected == null || selected.isEmpty()) { return; } @@ -501,30 +497,17 @@ private void mergeSelectedWorkspaces(List selected) { if (existing != null) { for (String ws : existing) { - if (ws == null) { - continue; - } - - File f = new File(ws); - if (!f.exists()) { - continue; + if (ws != null && new File(ws).exists()) { + merged.add(ws); } - merged.add(ws); } } // 2. Add selected for (String ws : selected) { - if (ws == null) { - continue; - } - - File f = new File(ws); - if (!f.exists()) { - continue; + if (ws != null && new File(ws).exists()) { + merged.add(ws); } - - merged.add(ws); } // 3. Final list @@ -533,6 +516,7 @@ private void mergeSelectedWorkspaces(List selected) { launchData.setRecentWorkspaces(result.toArray(new String[0])); saveRecentWorkspacesToPreferences(result); refreshRecentWorkspacesComposite(); + MessageDialog.openInformation(getShell(), "Workspaces Updated", //$NON-NLS-1$ "Imported " + selected.size() + " workspace(s)."); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -540,23 +524,23 @@ private void mergeSelectedWorkspaces(List selected) { private List importWorkspaces(File directory) { // capture return value List result = importWorkspacesFromEclipseInstallation(directory.getAbsolutePath()); - if (result == null) { - result = new ArrayList<>(); - } - return result; + return result != null ? result : Collections.emptyList(); } public List importWorkspaces(String path) { - return importWorkspaces(new File(path)); // ✅ now VALID + return importWorkspaces(new File(path)); } /** - * Method to save workspaces to preferences + * Saves the recent workspace list to the preference store. + * + * @param workspaces the workspaces to persist */ private void saveRecentWorkspacesToPreferences(List workspaces) { IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + if (workspaces == null || workspaces.isEmpty()) { - store.setValue(RECENT_WORKSPACES, ""); //$NON-NLS-1$ + store.setValue(RECENT_WORKSPACES, EMPTY); return; } @@ -575,106 +559,87 @@ private void saveRecentWorkspacesToPreferences(List workspaces) { if (Platform.getInstanceLocation().isSet()) { store.setValue(RECENT_WORKSPACES, sb.toString()); - } else { - logInfo("[ChooseWorkspaceDialog][saveRecentWorkspacesToPreferences] Instance location not set yet. Skipping preference save."); //$NON-NLS-1$ } +// else { +// MessageDialog.openInformation(getShell(), "saveRecentWorkspacesToPreferences", //$NON-NLS-1$ +// "Instance location not set yet. Skipping preference save."); //$NON-NLS-1$ +// } } catch (Exception e) { e.printStackTrace(); } } /** - * Method to import workspaces from previous Eclipse installation + * Imports recent workspaces from a previous Eclipse installation by reading the + * Eclipse preference file. + * + * @param eclipseInstallPath the Eclipse installation directory + * @return the list of detected workspace paths */ private List importWorkspacesFromEclipseInstallation(String eclipseInstallPath) { List workspaces = new ArrayList<>(); - // Try to find workspaces from the previous installation - // Look for the configuration/.settings/org.eclipse.ui.ide.prefs file - File configDir = new File(eclipseInstallPath, "configuration"); //$NON-NLS-1$ - File settingsDir = new File(configDir, ".settings"); //$NON-NLS-1$ - File recentWorkspacesFile = new File(settingsDir, "org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ - - if (recentWorkspacesFile.exists()) { - try { - // Parse the preferences file to extract recent workspaces - Properties props = new Properties(); - try (FileInputStream fis = new FileInputStream(recentWorkspacesFile)) { - props.load(fis); - } + File recentWorkspacesFile = new File(new File(new File(eclipseInstallPath, "configuration"), ".settings"), //$NON-NLS-1$ //$NON-NLS-2$ + "org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ - String recentWorkspacesValue = props.getProperty("RECENT_WORKSPACES"); //$NON-NLS-1$ - if (recentWorkspacesValue != null && !recentWorkspacesValue.isEmpty()) { - // Parse the workspaces (format is paths separated by newlines) - String[] workspacePaths = recentWorkspacesValue.split("\\n"); //$NON-NLS-1$ - for (String path : workspacePaths) { - path = path.trim(); - if (!path.isEmpty()) { - File wsFile = new File(path); - if (wsFile.exists()) { - workspaces.add(path); - } - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } else { - // Try alternative location + if (!recentWorkspacesFile.exists()) { File alternativePrefs = new File(eclipseInstallPath, ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs"); //$NON-NLS-1$ - if (alternativePrefs.exists()) { - // Parse it similarly... + if (!alternativePrefs.exists()) { + return workspaces; + } + recentWorkspacesFile = alternativePrefs; + } + + try { + Properties props = new Properties(); + try (FileInputStream fis = new FileInputStream(recentWorkspacesFile)) { + props.load(fis); + } + + String recentWorkspacesValue = props.getProperty("RECENT_WORKSPACES"); //$NON-NLS-1$ + if (recentWorkspacesValue == null || recentWorkspacesValue.isEmpty()) { + return workspaces; + } + + for (String path : recentWorkspacesValue.split("\\n")) { //$NON-NLS-1$ + String trimmedPath = path.trim(); + if (!trimmedPath.isEmpty() && new File(trimmedPath).exists()) { + workspaces.add(trimmedPath); + } } + } catch (IOException e) { + e.printStackTrace(); } return workspaces; } /** - * Method to refresh the recent workspaces composite after import + * Refreshes the recent workspaces UI after workspace import and updates the + * dialog layout and size. */ private void refreshRecentWorkspacesComposite() { - // Get the parent composite + if (recentWorkspacesForm == null || recentWorkspacesForm.isDisposed()) { + return; + } Composite parent = recentWorkspacesForm.getParent(); - if (parent != null && !parent.isDisposed()) { - // Store current expansion state - boolean wasExpanded = launchData.isShowRecentWorkspaces(); - - // Dispose the old form - recentWorkspacesForm.dispose(); - - // Recreate the recent workspaces section - createRecentWorkspacesComposite(parent); - - // Force layout update - parent.layout(true); - parent.getShell().layout(true); - - // Ensure expansion state is restored - if (recentWorkspacesForm != null && !recentWorkspacesForm.isDisposed()) { - // Find the expandable composite and set its state - // Control[] children = recentWorkspacesForm.getBody().getChildren(); // - // recentWorkspacesForm became composite instead of form - Control[] children = recentWorkspacesForm.getChildren(); - for (Control child : children) { - if (child instanceof ExpandableComposite) { - ((ExpandableComposite) child).setExpanded(wasExpanded); - break; - } - } - } + if (parent == null || parent.isDisposed()) { + return; + } - Shell shell = parent.getShell(); - if (shell != null && !shell.isDisposed()) { - shell.layout(true, true); - shell.redraw(); - shell.update(); - // Resize dialog properly - Point size = getInitialSize(); - shell.setBounds(getConstrainedShellBounds( - new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y))); - } + recentWorkspacesForm.dispose(); + createRecentWorkspacesComposite(parent); + parent.layout(true, true); + + Shell shell = parent.getShell(); + if (shell != null && !shell.isDisposed()) { + shell.layout(true, true); + shell.redraw(); + shell.update(); + + Point size = getInitialSize(); + shell.setBounds(getConstrainedShellBounds( + new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y))); } } @@ -786,7 +751,7 @@ protected String getUnexpectedPathHint() { return NLS.bind(IDEWorkbenchMessages.ChooseWorkspaceDialog_NotWriteablePathWarning, normalisedPath); } } - return ""; //$NON-NLS-1$ + return EMPTY; } /** the returned value may be wrong **/ diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java index 475036ac2a1..ba1141dde6d 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java @@ -1017,6 +1017,14 @@ public class IDEWorkbenchMessages extends NLS { public static String ChooseWorkspaceDialog_importLabel; public static String ChooseWorkspaceDialog_importTooltip; public static String ChooseWorkspaceDialog_launchLabel; + public static String ChooseWorkspaceDialog_importPreviousInstallationWindowTitle; + public static String ChooseWorkspaceDialog_importPreviousInstallationWindowMessage; + public static String ChooseWorkspaceDialog_noWorkspacesFoundTitle; + public static String ChooseWorkspaceDialog_noWorkspacesFoundMessage; + public static String ChooseWorkspaceDialog_noNewWorkspacesTitle; + public static String ChooseWorkspaceDialog_noNewWorkspacesMessage; + public static String ChooseWorkspaceDialog_nothingSelectedTitle; + public static String ChooseWorkspaceDialog_nothingSelectedMessage; public static String ChooseWorkspaceDialog_directoryBrowserTitle; public static String ChooseWorkspaceDialog_directoryBrowserMessage; public static String ChooseWorkspaceDialog_removeWorkspaceSelection; @@ -1031,7 +1039,24 @@ public class IDEWorkbenchMessages extends NLS { public static String ChooseWorkspaceDialog_NotWriteablePathWarning; public static String ChooseWorkspaceDialog_useDefaultMessage; + public static String WorkspaceImportDialog_dialogName; + public static String WorkspaceImportDialog_dialogTitle; + public static String WorkspaceImportDialog_dialogMessage; + public static String WorkspaceImportDialog_installationPath; + public static String WorkspaceImportDialog_typeFilterText; public static String WorkspaceImportDialog_browseLabel; + public static String WorkspaceImportDialog_browseTooltip; + public static String WorkspaceImportDialog_selectPreviousInstallationText; + public static String WorkspaceImportDialog_selectPreviousInstallationMessage; + public static String WorkspaceImportDialog_noWorkspaceFoundTitle; + public static String WorkspaceImportDialog_noWorkspaceFoundMessage; + public static String WorkspaceImportDialog_noNewWorkspacesTitle; + public static String WorkspaceImportDialog_noNewWorkspacesMessage; + public static String WorkspaceImportDialog_tableColumn1; + public static String WorkspaceImportDialog_tableColumn2; + public static String WorkspaceImportDialog_selectAllLabel; + public static String WorkspaceImportDialog_deselectAllLabel; + public static String ChooseWorkspaceWithSettingsDialog_SettingsGroupName; public static String ChooseWorkspaceWithSettingsDialog_ProblemsTransferTitle; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java index a7c40269501..ca17d04ca66 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkspaceImportDialog.java @@ -15,10 +15,12 @@ import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -40,11 +42,12 @@ import org.eclipse.swt.widgets.Text; /** - * @since 3.4 - * + * Dialog for importing workspaces from a previous Eclipse installation. + * Displays valid workspaces and allows users to select workspaces to import + * into the launcher. */ public class WorkspaceImportDialog extends TitleAreaDialog { - + private static final String EMPTY = ""; //$NON-NLS-1$ private List input; private String baseInstallPath; private CheckboxTableViewer viewer; @@ -55,6 +58,16 @@ public class WorkspaceImportDialog extends TitleAreaDialog { private Set checkedElements = new LinkedHashSet<>(); + /** + * Creates a dialog for importing workspaces from a previous Eclipse + * installation. + * + * @param parentShell the parent shell + * @param input the list of valid workspaces + * @param baseInstallPath the selected Eclipse installation path + * @param parentDialog the parent workspace launcher dialog + * @param existingWorkspaces the list of already imported workspaces + */ public WorkspaceImportDialog(Shell parentShell, List input, String baseInstallPath, ChooseWorkspaceDialog parentDialog, List existingWorkspaces) { super(parentShell); @@ -67,20 +80,20 @@ public WorkspaceImportDialog(Shell parentShell, List input, String baseI @Override protected void configureShell(Shell shell) { super.configureShell(shell); - shell.setText("Import Workspaces"); // Window title //$NON-NLS-1$ + shell.setText(IDEWorkbenchMessages.WorkspaceImportDialog_dialogName); } @Override public void create() { super.create(); - setTitle("Import Workspaces"); //$NON-NLS-1$ - setMessage("Select workspaces to import."); //$NON-NLS-1$ + setTitle(IDEWorkbenchMessages.WorkspaceImportDialog_dialogTitle); + setMessage(IDEWorkbenchMessages.WorkspaceImportDialog_dialogMessage); } -// private void logInfo(String msg) { -// System.out.println(msg); // or route to your logger -// } - + /** + * Creates the main dialog area and initializes the workspace import UI + * components. + */ @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); @@ -94,25 +107,27 @@ protected Control createDialogArea(Composite parent) { return container; } + /** + * Creates the installation path input row with browse support for selecting an + * application installation directory. + */ private void createLocationRow(Composite parent) { Composite row = new Composite(parent, SWT.NONE); row.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); row.setLayout(new GridLayout(3, false)); - new Label(row, SWT.NONE).setText("Workspace location:"); //$NON-NLS-1$ + new Label(row, SWT.NONE).setText(IDEWorkbenchMessages.WorkspaceImportDialog_installationPath); locationText = new Text(row, SWT.BORDER); locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - - if (baseInstallPath != null) { - locationText.setText(baseInstallPath); - } + locationText.setText(baseInstallPath != null ? baseInstallPath : EMPTY); Button browse = new Button(row, SWT.PUSH); - browse.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_browseLabel); + browse.setText(IDEWorkbenchMessages.WorkspaceImportDialog_browseLabel); + browse.setToolTipText(IDEWorkbenchMessages.WorkspaceImportDialog_browseTooltip); browse.addListener(SWT.Selection, e -> { DirectoryDialog dlg = new DirectoryDialog(parent.getShell()); - dlg.setText("Select Eclipse Installation"); //$NON-NLS-1$ - dlg.setMessage("Select installation directory"); //$NON-NLS-1$ + dlg.setText(IDEWorkbenchMessages.WorkspaceImportDialog_selectPreviousInstallationText); + dlg.setMessage(IDEWorkbenchMessages.WorkspaceImportDialog_selectPreviousInstallationMessage); String selectedPath = dlg.open(); if (selectedPath != null) { locationText.setText(selectedPath); @@ -122,19 +137,23 @@ private void createLocationRow(Composite parent) { }); } + /** + * Creates the workspace filter text field and applies filtering to the + * workspace table viewer. + */ private void createFilter(Composite parent) { // Add ICON_CANCEL Text filter = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL); - filter.setMessage("type filter text"); //$NON-NLS-1$ + filter.setMessage(IDEWorkbenchMessages.WorkspaceImportDialog_typeFilterText); filter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // FILTER LOGIC filter.addModifyListener(e -> { String raw = filter.getText(); - if (raw == null || raw.trim().isEmpty()) { + if (raw.trim().isEmpty()) { viewer.resetFilters(); } else { - String txt = raw.toLowerCase().replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$ + String txt = raw.toLowerCase().replace("*", EMPTY); //$NON-NLS-1$ viewer.setFilters(new ViewerFilter[] { new ViewerFilter() { @Override public boolean select(Viewer v, Object p, Object el) { @@ -145,16 +164,20 @@ public boolean select(Viewer v, Object p, Object el) { }); } viewer.refresh(); - // Restore check state AFTER refresh + // Restore check state after refresh viewer.setCheckedElements(checkedElements.toArray()); }); - // HANDLE CLEAR BUTTON CLICK + // Handle clear button click filter.addListener(SWT.DefaultSelection, e -> { - filter.setText(""); // triggers modify listener → resets filter //$NON-NLS-1$ + filter.setText(EMPTY); }); } + /** + * Loads and filters the initial workspace input into the table viewer and + * selects all entries by default. + */ private void loadInitialInput() { if (input == null) { return; @@ -172,7 +195,7 @@ private void loadInitialInput() { filtered.add(ws); } - // SET INPUT + // Set input viewer.setInput(filtered); // CHECK ALL by default @@ -182,102 +205,99 @@ private void loadInitialInput() { viewer.refresh(); } + /** + * Creates the workspace table viewer with check-box support and initializes its + * columns and selection handling. + */ private void createTable(Composite parent) { - try { - viewer = CheckboxTableViewer.newCheckList(parent, - SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SHADOW_IN); - - Table table = viewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.minimumHeight = 250; - table.setLayoutData(gd); - - // Column 1 - TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE); - col1.getColumn().setText("Workspace"); //$NON-NLS-1$ - col1.getColumn().setWidth(200); - - col1.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - String name = new File((String) element).getName(); - return name; - } - }); + viewer = CheckboxTableViewer.newCheckList(parent, + SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SHADOW_IN); + + Table table = viewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.minimumHeight = 250; + table.setLayoutData(gd); + + // Column 1 - workspace + TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE); + col1.getColumn().setText(IDEWorkbenchMessages.WorkspaceImportDialog_tableColumn1); + col1.getColumn().setWidth(200); + + col1.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return new File((String) element).getName(); + } + }); - // Column 2 - TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE); - col2.getColumn().setText("Path"); //$NON-NLS-1$ - col2.getColumn().setWidth(400); + // Column 2 - path + TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE); + col2.getColumn().setText(IDEWorkbenchMessages.WorkspaceImportDialog_tableColumn2); + col2.getColumn().setWidth(400); - col2.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - return (String) element; - } - }); + col2.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return (String) element; + } + }); - viewer.setContentProvider(ArrayContentProvider.getInstance()); - viewer.addCheckStateListener(event -> { - String element = (String) event.getElement(); + viewer.setContentProvider(ArrayContentProvider.getInstance()); + viewer.addCheckStateListener(event -> { + String element = (String) event.getElement(); - if (event.getChecked()) { - checkedElements.add(element); - } else { - checkedElements.remove(element); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } + if (event.getChecked()) { + checkedElements.add(element); + } else { + checkedElements.remove(element); + } + }); } + /** + * Creates the Select All and Deselect All buttons for managing workspace + * selections in the table viewer. + */ private void createButtons(Composite parent) { - try { - Composite bar = new Composite(parent, SWT.NONE); - bar.setLayout(new GridLayout(2, false)); - - // Select All (VISIBLE ONLY) - Button selectAll = new Button(bar, SWT.PUSH); - selectAll.setText("Select All"); //$NON-NLS-1$ - selectAll.addListener(SWT.Selection, e -> { - if (viewer == null) { - return; - } + Composite bar = new Composite(parent, SWT.NONE); + bar.setLayout(new GridLayout(2, false)); + + // Select All (VISIBLE ONLY) + Button selectAll = new Button(bar, SWT.PUSH); + selectAll.setText(IDEWorkbenchMessages.WorkspaceImportDialog_selectAllLabel); + selectAll.addListener(SWT.Selection, e -> { + if (viewer == null) { + return; + } - TableItem[] items = viewer.getTable().getItems(); - for (TableItem item : items) { - Object data = item.getData(); - if (data instanceof String) { - viewer.setChecked(data, true); - checkedElements.add((String) data); - } - } - }); - - // Deselect All (VISIBLE ONLY) - Button deselectAll = new Button(bar, SWT.PUSH); - deselectAll.setText("Deselect All"); //$NON-NLS-1$ - deselectAll.addListener(SWT.Selection, e -> { - if (viewer == null) { - return; + TableItem[] items = viewer.getTable().getItems(); + for (TableItem item : items) { + Object data = item.getData(); + if (data instanceof String) { + viewer.setChecked(data, true); + checkedElements.add((String) data); } + } + }); - TableItem[] items = viewer.getTable().getItems(); - for (TableItem item : items) { - Object data = item.getData(); - if (data instanceof String) { - viewer.setChecked(data, false); - checkedElements.remove(data); - } - } - }); - } catch (Exception e) { - e.printStackTrace(); - } + // Deselect All (VISIBLE ONLY) + Button deselectAll = new Button(bar, SWT.PUSH); + deselectAll.setText(IDEWorkbenchMessages.WorkspaceImportDialog_deselectAllLabel); + deselectAll.addListener(SWT.Selection, e -> { + if (viewer == null) { + return; + } + + TableItem[] items = viewer.getTable().getItems(); + for (TableItem item : items) { + Object data = item.getData(); + viewer.setChecked(data, false); + checkedElements.remove(data); + } + }); } @Override @@ -292,9 +312,6 @@ protected void okPressed() { for (Object o : checked) { selected.add((String) o); } -// for (Object o : checked) { -// selected.add((String) o); -// } super.okPressed(); } @@ -302,15 +319,34 @@ public List getSelected() { return selected; } + /** + * Reloads and refreshes the workspace list for the selected Eclipse + * installation path. + *

+ * Displays appropriate messages when: + *

    + *
  • no workspaces are found
  • + *
  • all valid workspaces are already imported
  • + *
+ * Updates the table viewer with newly detected workspaces and restores checked + * state. + * + * @param newPath the Eclipse installation path to scan for workspaces + */ private void reloadWorkspaces(String newPath) { if (parentDialog == null) { return; } List rawList = parentDialog.importWorkspaces(newPath); - if (rawList == null) { - return; - } + // No prefs file or no valid workspaces + if (rawList.isEmpty()) { + MessageDialog.openWarning(getShell(), IDEWorkbenchMessages.WorkspaceImportDialog_noWorkspaceFoundTitle, + IDEWorkbenchMessages.WorkspaceImportDialog_noWorkspaceFoundMessage); + viewer.setInput(Collections.emptyList()); + viewer.refresh(); + return; + } List filtered = new ArrayList<>(); for (String ws : rawList) { @@ -324,6 +360,16 @@ private void reloadWorkspaces(String newPath) { filtered.add(ws); } + // All valid workspaces are already imported + if (filtered.isEmpty()) { + MessageDialog.openInformation(getShell(), IDEWorkbenchMessages.WorkspaceImportDialog_noNewWorkspacesTitle, + IDEWorkbenchMessages.WorkspaceImportDialog_noNewWorkspacesMessage); + viewer.setInput(Collections.emptyList()); + checkedElements.clear(); + viewer.refresh(); + return; + } + viewer.setInput(filtered); // ALWAYS check all after browse checkedElements.clear(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties index 87ad7aabbb4..4f4d47c2f9b 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties @@ -1041,6 +1041,14 @@ ChooseWorkspaceDialog_browseTooltip=Open file dialog to choose a directory as wo ChooseWorkspaceDialog_importLabel=&Import... ChooseWorkspaceDialog_importTooltip=Import workspaces from existing application installation. ChooseWorkspaceDialog_launchLabel=&Launch +ChooseWorkspaceDialog_importPreviousInstallationWindowTitle=Select Previous Application Installation +ChooseWorkspaceDialog_importPreviousInstallationWindowMessage=Select the directory of a previous application installation. +ChooseWorkspaceDialog_noWorkspacesFoundTitle=No Workspaces Found +ChooseWorkspaceDialog_noWorkspacesFoundMessage=No workspaces found in selected installation path. +ChooseWorkspaceDialog_noNewWorkspacesTitle=No New Workspaces +ChooseWorkspaceDialog_noNewWorkspacesMessage=All valid workspaces are already imported. +ChooseWorkspaceDialog_nothingSelectedTitle=Nothing Selected +ChooseWorkspaceDialog_nothingSelectedMessage=No workspaces selected to import. ChooseWorkspaceDialog_directoryBrowserTitle=Select Workspace Directory ChooseWorkspaceDialog_directoryBrowserMessage=Select the workspace directory to use. ChooseWorkspaceDialog_removeWorkspaceSelection=Remove from launcher selection @@ -1053,6 +1061,24 @@ ChooseWorkspaceDialog_InvalidPathWarning=\u26A0\uFE0F The path is invalid on thi ChooseWorkspaceDialog_NotWriteablePathWarning=\u26A0\uFE0F The path may not be writable by the current user: {0} ChooseWorkspaceDialog_useDefaultMessage=&Use this as the default and do not ask again +WorkspaceImportDialog_dialogName=Import Workspaces +WorkspaceImportDialog_dialogTitle=Select existing application installation +WorkspaceImportDialog_dialogMessage=Select workspaces to import +WorkspaceImportDialog_installationPath=Previous application installation: +WorkspaceImportDialog_typeFilterText=type filter text +WorkspaceImportDialog_browseLabel=&Browse... +WorkspaceImportDialog_browseTooltip=Open file dialog to choose previous application installation +WorkspaceImportDialog_selectPreviousInstallationText=Select An Application Installation +WorkspaceImportDialog_selectPreviousInstallationMessage=Select an application installation. +WorkspaceImportDialog_noWorkspaceFoundTitle=No Workspaces Found +WorkspaceImportDialog_noWorkspaceFoundMessage=No workspaces found in the selected installation path. +WorkspaceImportDialog_noNewWorkspacesTitle=No New Workspaces +WorkspaceImportDialog_noNewWorkspacesMessage=All valid workspaces are already imported. +WorkspaceImportDialog_tableColumn1=Workspace +WorkspaceImportDialog_tableColumn2=Path +WorkspaceImportDialog_selectAllLabel=&Select All +WorkspaceImportDialog_deselectAllLabel=&Deselect All + ChooseWorkspaceWithSettingsDialog_SettingsGroupName=&Copy Settings ChooseWorkspaceWithSettingsDialog_ProblemsTransferTitle=Problems Transferring Settings ChooseWorkspaceWithSettingsDialog_TransferFailedMessage=Settings transfer failed @@ -1060,8 +1086,6 @@ ChooseWorkspaceWithSettingsDialog_SaveSettingsFailed=Could not save settings ChooseWorkspaceWithSettingsDialog_ClassCreationFailed= Could not instantiate {0} ChooseWorkspaceWithSettingsDialog_copySettingsDecoLabel=Target workspace exists. Existing values will be overwritten. -WorkspaceImportDialog_browseLabel=&Browse... - IDEApplication_workspaceMandatoryTitle=Workspace is Mandatory IDEApplication_workspaceMandatoryMessage=IDEs need a valid workspace. Restart without the @none option. IDEApplication_workspaceInUseTitle=Workspace Unavailable