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
Handle Favorite URLs in drop adapter by opening Import Favorites wizard

Bug: 493913
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=493913
  • Loading branch information
creckord committed Mar 17, 2017
1 parent cf0f0f0 commit a0c632d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
Expand Up @@ -169,6 +169,10 @@ protected void proceedInstallation(String url) {
}
}

protected void proceedFavorites(String url) {
MarketplaceUrlHandler.triggerFavorites(url);
}

private class MarketplaceDropTargetListener extends DropTargetAdapter {

@Override
Expand Down Expand Up @@ -228,7 +232,11 @@ private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
return !isDrop;
}
final String url = getUrl(e.data);
if (!MarketplaceUrlHandler.isPotentialSolution(url)) {
if (MarketplaceUrlHandler.isPotentialSolution(url)) {
return true;
} else if (MarketplaceUrlHandler.isPotentialFavoritesList(url)) {
return true;
} else {
traceInvalidEventData(e);
return false;
}
Expand Down Expand Up @@ -270,15 +278,24 @@ public void drop(DropTargetEvent event) {
return;
}
final String url = getUrl(event.data);
//http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=1640500
if (MarketplaceUrlHandler.isPotentialSolution(url)) {
//http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=1640500
DropTarget source = (DropTarget) event.getSource();
Display display = source.getDisplay();
display.asyncExec(new Runnable() {
public void run() {
proceedInstallation(url);
}
});
} else if (MarketplaceUrlHandler.isPotentialFavoritesList(url)) {
//https://marketplace.eclipse.org/user/xxx/favorites
DropTarget source = (DropTarget) event.getSource();
Display display = source.getDisplay();
display.asyncExec(new Runnable() {
public void run() {
proceedFavorites(url);
}
});
} else {
traceInvalidEventData(event);
}
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.epp.internal.mpc.core.util.URLUtil;
import org.eclipse.epp.internal.mpc.ui.CatalogRegistry;
import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUi;
import org.eclipse.epp.internal.mpc.ui.commands.ImportFavoritesWizardCommand;
import org.eclipse.epp.internal.mpc.ui.commands.MarketplaceWizardCommand;
import org.eclipse.epp.mpc.core.model.INode;
import org.eclipse.osgi.util.NLS;
Expand Down Expand Up @@ -61,6 +62,8 @@ public abstract class MarketplaceUrlHandler {

private static final Pattern NODE_URL_PATTERN = Pattern.compile("(?:^|/)node/([^/#?]+)"); //$NON-NLS-1$

private static final Pattern FAVORITES_URL_PATTERN = Pattern.compile("(?:^|/)user/([^/#?]+)/favorites(/?[#?].*)?$"); //$NON-NLS-1$

public static class SolutionInstallationInfo {

private String requestUrl;
Expand Down Expand Up @@ -121,21 +124,26 @@ public static SolutionInstallationInfo createSolutionInstallInfo(String url) {
state = query.get(MPC_STATE);
}
if (installId != null) {
CatalogDescriptor descriptor = CatalogRegistry.getInstance().findCatalogDescriptor(url);
if (descriptor == null) {
try {
descriptor = new CatalogDescriptor(URLUtil.toURL(url), DESCRIPTOR_HINT);
} catch (MalformedURLException e) {
return null;
}
}
CatalogDescriptor descriptor = findCatalogDescriptor(url, true);
SolutionInstallationInfo info = new SolutionInstallationInfo(installId, state, descriptor);
info.setRequestUrl(url);
return info;
}
return null;
}

private static CatalogDescriptor findCatalogDescriptor(String url, boolean allowUnknown) {
CatalogDescriptor descriptor = CatalogRegistry.getInstance().findCatalogDescriptor(url);
if (descriptor == null && allowUnknown) {
try {
descriptor = new CatalogDescriptor(URLUtil.toURL(url), DESCRIPTOR_HINT);
} catch (MalformedURLException e) {
return null;
}
}
return descriptor;
}

public static String getMPCState(String url) {
Map<String, String> query = parseQuery(url);
return query == null ? null : query.get(MPC_STATE);
Expand Down Expand Up @@ -168,6 +176,10 @@ public static boolean isPotentialSolution(String url) {
return url != null && url.contains(MPC_INSTALL);
}

public static boolean isPotentialFavoritesList(String url) {
return url != null && FAVORITES_URL_PATTERN.matcher(url).find();
}

public static void triggerInstall(SolutionInstallationInfo info) {
if (info.getRequestUrl() != null) {
MarketplaceClientUi.getLog().log(
Expand Down Expand Up @@ -197,6 +209,20 @@ public static void triggerInstall(SolutionInstallationInfo info) {
}
}

public static void triggerFavorites(String favoritesUrl) {
CatalogDescriptor catalogDescriptor = findCatalogDescriptor(favoritesUrl, true);
ImportFavoritesWizardCommand command = new ImportFavoritesWizardCommand();
command.setSelectedCatalogDescriptor(catalogDescriptor);
command.setFavoritesUrl(favoritesUrl);
try {
command.execute(new ExecutionEvent());
} catch (ExecutionException e) {
IStatus status = MarketplaceClientCore.computeStatus(e,
Messages.MarketplaceUrlHandler_cannotOpenMarketplaceWizard);
MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
}
}

public boolean handleUri(String uri) {
if (isPotentialSolution(uri)) {
SolutionInstallationInfo installInfo = createSolutionInstallInfo(uri);
Expand Down

0 comments on commit a0c632d

Please sign in to comment.