-
Notifications
You must be signed in to change notification settings - Fork 3
/
UserFavoritesSignInActionItem.java
85 lines (73 loc) · 3.14 KB
/
UserFavoritesSignInActionItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
* Copyright (c) 2010 The Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* The Eclipse Foundation - initial API and implementation
*******************************************************************************/
package org.eclipse.epp.internal.mpc.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUi;
import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiPlugin;
import org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog;
import org.eclipse.epp.internal.mpc.ui.catalog.UserActionCatalogItem;
import org.eclipse.equinox.internal.p2.discovery.model.Icon;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogViewer;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.statushandlers.StatusManager;
public class UserFavoritesSignInActionItem extends AbstractUserActionItem {
public UserFavoritesSignInActionItem(Composite parent, MarketplaceDiscoveryResources resources,
UserActionCatalogItem connector, CatalogViewer viewer) {
super(parent, resources, connector, viewer);
}
@Override
protected String getNameLabelText() {
return Messages.SignInUserActionItem_signInActionLabel;
}
@Override
protected String getDescriptionText() {
UserActionCatalogItem loginItem = getData();
if (loginItem != null && loginItem.getData() != null && !"".equals(loginItem.getData())) { //$NON-NLS-1$
String loginMessage = (String) loginItem.getData();
loginMessage = loginMessage.trim();
return NLS.bind(Messages.SignInUserActionItem_retryLoginLabel, loginMessage);
}
return Messages.UserFavoritesSignInActionItem_SignInDescription;
}
@Override
protected Icon getIcon() {
String path = REGISTRY_SCHEME + MarketplaceClientUiPlugin.ACTION_ICON_LOGIN;
return createIcon(path);
}
@Override
protected String getSublineText() {
return Messages.UserFavoritesSignInActionItem_subline;
}
@Override
protected void createButtons(Composite parent) {
createButton(parent, Messages.UserFavoritesSignInActionItem_SignInButtonText, null, 0);
}
@Override
protected void buttonPressed(int id) {
MarketplaceViewer viewer = (MarketplaceViewer) getViewer();
final MarketplaceCatalog catalog = viewer.getCatalog();
try {
viewer.getWizard().getContainer().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
catalog.userFavorites(true, monitor);
}
});
} catch (InvocationTargetException e) {
MarketplaceClientUi.handle(e.getCause(), StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
} catch (InterruptedException e) {
//ignore
}
viewer.updateContents();
}
}