Skip to content

Commit

Permalink
511215: Make Favorites a central element
Browse files Browse the repository at this point in the history
Show user notifications / actions in a nicer widget, and show some
popular entries below it, instead of an empty list, where that makes
sense

This replaces the sign-in, empty favorites, unsupported favorites,and
error retry entries with ones that have a similar structure to solution
entries and a highlighted background.

Bug: 511215
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=511215
  • Loading branch information
creckord committed Apr 13, 2017
1 parent 87f6ba9 commit e18e04b
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,17 @@ public void maybeAddCatalogItem(MarketplaceCategory catalogCategory) {
}

public void addCatalogItem(MarketplaceCategory catalogCategory) {
CatalogItem catalogItem = createCategoryItem(catalogCategory);
items.add(catalogItem);
}

private CatalogItem createCategoryItem(MarketplaceCategory catalogCategory) {
CatalogItem catalogItem = new CatalogItem();
catalogItem.setSource(source);
catalogItem.setData(catalogDescriptor);
catalogItem.setId(catalogDescriptor.getUrl().toString());
catalogItem.setCategoryId(catalogCategory.getId());
items.add(catalogItem);
return catalogItem;
}

public UserActionCatalogItem addUserActionItem(MarketplaceCategory catalogCategory, UserAction userAction) {
Expand All @@ -450,7 +455,7 @@ public UserActionCatalogItem addUserActionItem(MarketplaceCategory catalogCatego
catalogItem.setData(data);
catalogItem.setId(catalogDescriptor.getUrl().toString() + "#" + userAction.name()); //$NON-NLS-1$
catalogItem.setCategoryId(catalogCategory.getId());
items.add(catalogItem);
items.add(0, catalogItem);
return catalogItem;
}

Expand Down Expand Up @@ -682,27 +687,40 @@ public ISearchResult call() throws Exception {
} else {
result = marketplaceService.userFavorites(progress.newChild(500));
}
handleSearchResult(catalogCategory, result, progress.newChild(500));
if (result.getNodes().isEmpty()) {
catalogCategory = addPopularItems(progress.newChild(500));
addNoFavoritesItem(catalogCategory);
} else {
handleSearchResult(catalogCategory, result, progress.newChild(500));
}
} catch (NotAuthorizedException e) {
catalogCategory = addPopularItems(progress.newChild(500));
addUserStorageLoginItem(catalogCategory, e.getLocalizedMessage());
} catch (UnsupportedOperationException ex) {
catalogCategory = addPopularItems(progress.newChild(500));
addFavoritesNotSupportedItem(catalogCategory);
} catch (Exception ex) {
//FIXME we should use the wizard page's status line to show errors, but that's unreachable from here...
MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, ex);
addRetryErrorItem(catalogCategory, ex);
}
} else {
catalogCategory = addPopularItems(progress.newChild(1000));
addFavoritesNotSupportedItem(catalogCategory);
}
} finally {
monitor.done();
}
}

private MarketplaceCategory addPopularItems(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 100);
MarketplaceCategory catalogCategory;
popular(progress.newChild(99));
catalogCategory = findMarketplaceCategory(progress.newChild(1));
return catalogCategory;
}

public void refreshUserFavorites(IProgressMonitor monitor) throws CoreException {
final SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_FavoritesRefreshing, 1001);
try {
Expand Down Expand Up @@ -731,10 +749,13 @@ public void refreshUserFavorites(IProgressMonitor monitor) throws CoreException
}
}
} catch (NotAuthorizedException e) {
catalogCategory = addPopularItems(progress.newChild(500));
addUserStorageLoginItem(catalogCategory, e.getLocalizedMessage());
} catch (UnsupportedOperationException ex) {
catalogCategory = addPopularItems(progress.newChild(500));
addFavoritesNotSupportedItem(catalogCategory);
} catch (Exception ex) {
//FIXME we should use the wizard page's status line to show errors, but that's unreachable from here...
MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, ex);
addRetryErrorItem(catalogCategory, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.swt.graphics.Rectangle;
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.Display;
Expand Down Expand Up @@ -95,6 +96,8 @@ public abstract class AbstractMarketplaceDiscoveryItem<T extends CatalogItem> ex

protected static final int SEPARATOR_MARGIN_TOP = 8;

protected static final int BUTTONBAR_MARGIN_TOP = 8;

protected static final int MAX_IMAGE_HEIGHT = 86;

protected static final int MIN_IMAGE_HEIGHT = 64;
Expand Down Expand Up @@ -149,6 +152,8 @@ public abstract class AbstractMarketplaceDiscoveryItem<T extends CatalogItem> ex

private final PropertyChangeListener propertyChangeListener;

private PixelConverter pixelConverter;

public AbstractMarketplaceDiscoveryItem(Composite parent, int style, MarketplaceDiscoveryResources resources,
IMarketplaceWebBrowser browser, final T connector, CatalogViewer viewer) {
super(parent, style, resources, connector);
Expand Down Expand Up @@ -183,6 +188,10 @@ public void widgetDisposed(DisposeEvent e) {
});
}

protected PixelConverter getPixelConverter() {
return pixelConverter;
}

protected void createContent() {
createContent(this);
createSeparator(this);
Expand All @@ -193,6 +202,7 @@ protected boolean alignIconWithName() {
}

protected void createContent(Composite parent) {
pixelConverter = new PixelConverter(parent);
GridLayoutFactory.swtDefaults()
.numColumns(4)
.equalWidth(false)
Expand Down Expand Up @@ -234,7 +244,6 @@ private void createIconContainer(Composite parent) {
.minSize(MAX_IMAGE_WIDTH, MIN_IMAGE_HEIGHT)
.span(1, alignIconWithName() ? 4 : 3)
.applyTo(checkboxContainer);
PixelConverter pixelConverter = new PixelConverter(checkboxContainer);
GridLayoutFactory.fillDefaults()
.margins(0, 0)
.numColumns(1)
Expand Down Expand Up @@ -268,7 +277,7 @@ protected void createDescription(Composite parent) {
.span(3, 1)
.hint(100, SWT.DEFAULT)
.applyTo(description);
String descriptionText = connector.getDescription();
String descriptionText = getDescriptionText();
int maxDescriptionLength = 162;
if (descriptionText == null) {
descriptionText = ""; //$NON-NLS-1$
Expand Down Expand Up @@ -315,6 +324,10 @@ protected void createDescription(Composite parent) {
createInfoLink(description);
}

protected String getDescriptionText() {
return connector.getDescription();
}

protected void createNameLabel(Composite parent) {
nameLabel = new Label(parent, SWT.WRAP);
setWidgetId(nameLabel, WIDGET_ID_NAME);
Expand Down Expand Up @@ -343,6 +356,13 @@ protected String getNameLabelText() {

protected abstract void createSocialButtons(Composite parent);

protected Label createButtonBarSpacer(Composite parent) {
Label spacer = new Label(parent, SWT.NONE);
spacer.setText(" ");//$NON-NLS-1$
GridDataFactory.fillDefaults().indent(0, BUTTONBAR_MARGIN_TOP).align(SWT.CENTER, SWT.FILL).applyTo(spacer);
return spacer;
}

private INode getCatalogItemNode() {
Object data = connector.getData();
if (data instanceof INode) {
Expand Down Expand Up @@ -383,15 +403,19 @@ protected void createIconControl(Composite checkboxContainer) {
GridDataFactory.swtDefaults()
.align(SWT.CENTER, SWT.BEGINNING).grab(true, true)
.applyTo(iconLabel);
if (connector.getIcon() != null) {
provideIconImage(iconLabel, connector.getSource(), connector.getIcon(), 64, true);
if (getIcon() != null) {
provideIconImage(iconLabel, connector.getSource(), getIcon(), 64, true);
} else {
iconLabel.setImage(MarketplaceClientUiPlugin.getInstance()
.getImageRegistry()
.get(MarketplaceClientUiPlugin.NO_ICON_PROVIDED));
}
}

protected Icon getIcon() {
return connector.getIcon();
}

private void provideIconImage(final Label iconLabel, AbstractCatalogSource source, Icon icon, int size,
boolean fallback) {
if (iconLabel == null) {
Expand Down Expand Up @@ -763,4 +787,19 @@ public void handleEvent(Event event) {
protected CatalogViewer getViewer() {
return viewer;
}

static GridDataFactory createButtonLayoutData(Button button, PixelConverter pixelConverter) {
GridDataFactory dataFactory = GridDataFactory.defaultsFor(button).align(SWT.END, SWT.CENTER).grab(true, true);
int minWidth = pixelConverter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
int maxWidth = button.getDisplay().getBounds().width / 5;
Point preferredSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

int widthHint = Math.max(minWidth, preferredSize.x);
widthHint = Math.min(widthHint, maxWidth);
minWidth = Math.min(preferredSize.x, maxWidth);

dataFactory.hint(widthHint, SWT.DEFAULT);
dataFactory.minSize(minWidth, SWT.DEFAULT);
return dataFactory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*******************************************************************************
* 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 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.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public abstract class AbstractUserActionItem extends AbstractMarketplaceDiscoveryItem<UserActionCatalogItem> {

public AbstractUserActionItem(Composite parent, MarketplaceDiscoveryResources resources,
UserActionCatalogItem connector, CatalogViewer viewer) {
super(parent, SWT.NONE, resources, null, connector, viewer);
//TODO we need a better color definition for this...
setBackground(viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
}

protected void createButtons(Composite parent) {
// ignore
}

@Override
protected abstract Icon getIcon();

@Override
protected abstract String getDescriptionText();

@Override
protected abstract String getNameLabelText();

protected String getSublineText() {
return null;
}

@Override
protected void createTagsLabel(Composite parent) {
// we'll abuse this to create a 2-row container for action buttons that shows up
// below the description and to the right of the icon, instead of creating an extra
// row below
createButtonBar(parent);
}

protected void createButtonBar(Composite parent) {
createButtonBar(parent, getSublineText() == null ? 2 : 1);
}

@Override
protected void createProviderLabel(Composite parent) {
createSublineLabel(parent);
}

protected StyledText createSublineLabel(Composite parent) {
String sublineText = getSublineText();
if (sublineText == null) {
return null;
}

StyledText subline = StyledTextHelper.createStyledTextLabel(parent);

subline.setEditable(false);
GridDataFactory.fillDefaults()
.indent(DESCRIPTION_MARGIN_LEFT, DESCRIPTION_MARGIN_TOP)
.span(3, 1)
.align(SWT.BEGINNING, SWT.CENTER)
.grab(true, false)
.applyTo(subline);
// always disabled color to make it less prominent
subline.setForeground(resources.getColorDisabled());
subline.setText(sublineText);
StyleRange range = new StyleRange(0, subline.getText().length(), subline.getForeground(), null, SWT.ITALIC);
subline.setStyleRange(range);
return subline;
}

protected void createButtonBar(Composite parent, int vSpan) {
Label spacer = createButtonBarSpacer(parent);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).span(1, vSpan).applyTo(spacer);

Composite buttonContainer = new Composite(parent, SWT.NONE);
buttonContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
GridDataFactory.swtDefaults()
.indent(0, BUTTONBAR_MARGIN_TOP)
.align(SWT.END, SWT.END)
.grab(false, false)
.span(2, vSpan)
.applyTo(buttonContainer);
GridLayoutFactory.fillDefaults().numColumns(0).equalWidth(true).applyTo(buttonContainer);

createButtons(buttonContainer);
}

protected Button createButton(Composite parent, String text, String tooltipText, int id) {
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH | SWT.BOLD);
button.setText(text);
if (tooltipText != null) {
button.setToolTipText(tooltipText);
}
button.setFont(JFaceResources.getFontRegistry().getBold("")); //$NON-NLS-1$
button.setData(Integer.valueOf(id));
createButtonLayoutData(button, getPixelConverter()).align(SWT.END, SWT.END)
.grab(false, false)
.applyTo(button);

button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
buttonPressed(((Integer) e.widget.getData()).intValue());
}
});
return button;
}

protected void buttonPressed(int id) {

}

@Override
protected void createInstallButtons(Composite parent) {
// ignore
}

@Override
protected void createInstallInfo(Composite parent) {
// ignore
}

@Override
protected void createSocialButtons(Composite parent) {
// ignore
}

@Override
protected void searchForProvider(String searchTerm) {
// ignore
}

@Override
protected void searchForTag(String tag) {
// ignore
}

@Override
protected void createSeparator(Composite parent) {
// ignore
}

}
Loading

0 comments on commit e18e04b

Please sign in to comment.