Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5e15bef61226e0dc59ead8e6726723ba5ad5c2d9 (plain) (blame)
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
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2010 Tasktop Technologies 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.equinox.internal.p2.ui.discovery.wizards;

import org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory;
import org.eclipse.equinox.internal.p2.ui.discovery.util.GradientCanvas;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

/**
 * @author Steffen Pingel
 */
public class CategoryItem<T extends CatalogCategory> extends AbstractDiscoveryItem<T> {

	public CategoryItem(Composite parent, int style, DiscoveryResources resources, T category) {
		super(parent, style, resources, category);
		createContent(category);
	}

	protected boolean hasTooltip(final CatalogCategory category) {
		return category.getOverview() != null && category.getOverview().getSummary() != null && category.getOverview().getSummary().length() > 0;
	}

	private void createContent(T category) {
		setLayout(new FillLayout());

		final GradientCanvas categoryHeaderContainer = new GradientCanvas(this, SWT.NONE);
		categoryHeaderContainer.setSeparatorVisible(true);
		categoryHeaderContainer.setSeparatorAlignment(SWT.TOP);
		categoryHeaderContainer.setBackgroundGradient(new Color[] {resources.getGradientBeginColor(), resources.getGradientEndColor()}, new int[] {100}, true);
		categoryHeaderContainer.putColor(GradientCanvas.H_BOTTOM_KEYLINE1, resources.getGradientBeginColor());
		categoryHeaderContainer.putColor(GradientCanvas.H_BOTTOM_KEYLINE2, resources.getGradientEndColor());

		//GridDataFactory.fillDefaults().span(2, 1).applyTo(categoryHeaderContainer);
		GridLayoutFactory.fillDefaults().numColumns(3).margins(5, 5).equalWidth(false).applyTo(categoryHeaderContainer);

		Label iconLabel = new Label(categoryHeaderContainer, SWT.NULL);
		if (category.getIcon() != null) {
			iconLabel.setImage(resources.getIconImage(category.getSource(), category.getIcon(), 48, true));
		}
		iconLabel.setBackground(null);
		GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).span(1, 2).applyTo(iconLabel);

		Label nameLabel = new Label(categoryHeaderContainer, SWT.NULL);
		nameLabel.setFont(resources.getHeaderFont());
		nameLabel.setText(category.getName());
		nameLabel.setBackground(null);

		GridDataFactory.fillDefaults().grab(true, false).applyTo(nameLabel);
		if (hasTooltip(category)) {
			ToolBar toolBar = new ToolBar(categoryHeaderContainer, SWT.FLAT);
			toolBar.setBackground(null);
			ToolItem infoButton = new ToolItem(toolBar, SWT.PUSH);
			infoButton.setImage(resources.getInfoImage());
			infoButton.setToolTipText(Messages.ConnectorDiscoveryWizardMainPage_tooltip_showOverview);
			hookTooltip(toolBar, infoButton, categoryHeaderContainer, nameLabel, category.getSource(), category.getOverview(), null);
			GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(toolBar);
		} else {
			new Label(categoryHeaderContainer, SWT.NULL).setText(" "); //$NON-NLS-1$
		}
		if (category.getDescription() != null) {
			Label description = new Label(categoryHeaderContainer, SWT.WRAP);
			GridDataFactory.fillDefaults().grab(true, false).span(2, 1).hint(100, SWT.DEFAULT).applyTo(description);
			description.setBackground(null);
			description.setText(category.getDescription());
		}
	}

	@Override
	protected void refresh() {
		// ignore

	}

}

Back to the top