Skip to content

Commit

Permalink
493913: Add drag&drop support for favorites list URL
Browse files Browse the repository at this point in the history
Remember dialog bounds

Bug: 493913
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=493913
  • Loading branch information
creckord committed Mar 30, 2017
1 parent b0adc02 commit 09b16d4
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.epp.internal.mpc.ui.wizards;

import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiPlugin;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.IPageChangedListener;
import org.eclipse.jface.dialogs.IPageChangingListener;
import org.eclipse.jface.dialogs.PageChangedEvent;
Expand Down Expand Up @@ -226,4 +228,54 @@ public String getCancelButtonLabel(IWizardPage page) {
return IDialogConstants.CANCEL_LABEL;
}

@Override
protected IDialogSettings getDialogBoundsSettings() {
Class<? extends AbstractMarketplaceWizardDialog> dialogClass = getClass();
return getDialogBoundsSettings(dialogClass, getParentShell() != null, true);
}

protected static IDialogSettings getDialogBoundsSettings(
Class<? extends AbstractMarketplaceWizardDialog> dialogClass, boolean relative, boolean create) {
String sectionName = dialogClass.getName() + "_dialogBounds." + (relative ? "relative" : "absolute"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

IDialogSettings settings = MarketplaceClientUiPlugin.getInstance().getDialogSettings();
IDialogSettings section = settings.getSection(sectionName);
if (section == null && create) {
section = settings.addNewSection(sectionName);
IDialogSettings companionSettings = getDialogBoundsSettings(dialogClass, !relative, false);
if (companionSettings != null) {
copyInitialSize(companionSettings, settings);
}
}
return section;
}

@Override
protected int getDialogBoundsStrategy() {
return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE;
}

static void copyInitialSize(IDialogSettings sourceSettings, IDialogSettings targetSettings) {
copySettings(sourceSettings, targetSettings, "DIALOG_WIDTH"); //$NON-NLS-1$
copySettings(sourceSettings, targetSettings, "DIALOG_HEIGHT"); //$NON-NLS-1$
copySettings(sourceSettings, targetSettings, "DIALOG_FONT_NAME"); //$NON-NLS-1$
}

static void copyInitialLocation(IDialogSettings sourceSettings, IDialogSettings targetSettings) {
copySettings(sourceSettings, targetSettings, "DIALOG_X_ORIGIN"); //$NON-NLS-1$
copySettings(sourceSettings, targetSettings, "DIALOG_Y_ORIGIN"); //$NON-NLS-1$
}

static void setInitialLocation(int x, int y, IDialogSettings targetSettings) {
targetSettings.put("DIALOG_X_ORIGIN", x); //$NON-NLS-1$
targetSettings.put("DIALOG_Y_ORIGIN", y); //$NON-NLS-1$
}

static void copySettings(IDialogSettings sourceSettings, IDialogSettings targetSettings, String key) {
String value = sourceSettings.get(key);
if (value != null) {
targetSettings.put(key, value);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,22 @@ protected void importFavorites(MarketplaceDiscoveryStrategy marketplaceStrategy)
protected void preDiscovery() {
discoveryError = null;
}

@Override
protected void handleDiscoveryError(CoreException ex) throws CoreException {
discoveryError = importFavoritesPage.handleDiscoveryError(getFavoritesReference(), ex);
discoveryError = ImportFavoritesPage.handleDiscoveryError(getFavoritesReference(), ex);
}

@Override
protected void postDiscovery() {
final String errorMessage = this.discoveryError;
this.discoveryError = null;
importFavoritesPage.setDiscoveryError(errorMessage);
}
});
int result = new ImportFavoritesWizardDialog(wizard.getShell(), importFavoritesWizard).open();
ImportFavoritesWizardDialog importWizard = new ImportFavoritesWizardDialog(wizard.getShell(), importFavoritesWizard);

int result = importWizard.open();
if (result == Window.OK) {
MarketplacePage catalogPage = wizard.getCatalogPage();
catalogPage.setActiveTab(ContentType.FAVORITES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

import org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.DiscoveryWizard;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ImportFavoritesWizard extends DiscoveryWizard {

Expand All @@ -21,7 +26,7 @@ public class ImportFavoritesWizard extends DiscoveryWizard {

public ImportFavoritesWizard(MarketplaceCatalog catalog, MarketplaceCatalogConfiguration configuration, IMarketplaceWebBrowser browser) {
super(catalog, configuration);
setWindowTitle("Import Favorites List");
setWindowTitle(Messages.ImportFavoritesWizard_title);
this.importFavoritesPage = new ImportFavoritesPage(catalog, browser);
}

Expand All @@ -33,7 +38,30 @@ public void addPages() {
@Override
public boolean performFinish() {
importFavoritesPage.performImport();
return importFavoritesPage.getErrorMessage() == null;
boolean result = importFavoritesPage.getErrorMessage() == null;
if (result) {
showFavoritesInMarketplace();
}
return result;
}

private void showFavoritesInMarketplace() {
Display display = null;
Rectangle bounds = null;
IWizardContainer container = getContainer();
if (container instanceof WizardDialog) {
Shell shell = ((WizardDialog) container).getShell();
if (shell != null && !shell.isDisposed()) {
bounds = shell.getBounds();
display = shell.getDisplay();
}
}
showFavoritesInMarketplace(display, bounds);
}

private void showFavoritesInMarketplace(Display display, Rectangle bounds) {
// ignore

}

public ImportFavoritesPage getImportFavoritesPage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.epp.internal.mpc.ui.wizards;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -24,4 +25,37 @@ public ImportFavoritesWizardDialog(Shell parentShell, IWizard newWizard) {
public String getFinishButtonLabel(IWizardPage page) {
return Messages.ImportFavoritesWizardDialog_FinishButtonLabel;
}

@Override
protected IDialogSettings getDialogBoundsSettings() {
boolean relative = getParentShell() != null;
IDialogSettings settings = getDialogBoundsSettings(getClass(), relative, false);
if (settings == null) {
//This tries to be smart in intializing its defaults:
//- if there are settings for the opposite mode (!relative), take the size from there
//- initialize the relative position to be slightly to the bottom left
//- if there are settings for the main Marketplace wizard dialog, take the initial position
// from there for absolute position
//- if we don't have an initial size yet, take the Marketplace wizard size, which should be
// a good match
settings = getDialogBoundsSettings(getClass(), relative, true);
if (relative) {
setInitialLocation(80, 80, settings);
}
IDialogSettings marketplaceWizardSettings = getDialogBoundsSettings(MarketplaceWizardDialog.class, false,
false);
if (marketplaceWizardSettings != null) {
if (!relative) {
copyInitialLocation(marketplaceWizardSettings, settings);
}
IDialogSettings companionSettings = getDialogBoundsSettings(getClass(), !relative, false);
//If we had companion settings, the call to getDialogBoundsSettings(..., true) would have
//already initialized them
if (companionSettings == null) {
copyInitialSize(marketplaceWizardSettings, settings);
}
}
}
return settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Messages extends NLS {

public static String ImportFavoritesPage_Description;

public static String ImportFavoritesWizard_title;

public static String ImportFavoritesWizardDialog_FinishButtonLabel;

public static String ImportFavoritesPage_Title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ImportFavoritesActionLink_noFavoritesFoundAtUrl=No favorites list found at {0}
ImportFavoritesActionLink_noFavoritesFoundForUser=No favorites list found for {0}
ImportFavoritesPage_conflictErrorMessage=Failed to update your favorites, because they were changed on the server in the meantime.\nPress 'Next' to try again.
ImportFavoritesPage_Description=Import another user's favorite Marketplace entries into your own Favorites list
ImportFavoritesWizard_title=Import Favorites List
ImportFavoritesWizardDialog_FinishButtonLabel=&Import
ImportFavoritesPage_Title=Import Favorites List
ImportFavoritesPage_unauthorizedErrorMessage=You need to log in to proceed. Press 'Next' to try again.
Expand Down

0 comments on commit 09b16d4

Please sign in to comment.