Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9be99dd25d7720baf7dd3203566cbd594f7a21f9 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 *  Copyright (c) 2007, 2010 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.dialogs;

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

/**
 * PropertyPage that shows an IU's properties
 * 
 * @since 3.4
 */
public class IUGeneralInfoPropertyPage extends IUPropertyPage {

	protected Control createIUPage(Composite parent, IInstallableUnit iu) {
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.marginWidth = 0;
		layout.marginHeight = 0;
		composite.setLayout(layout);

		createGeneralSection(composite, iu);
		createDescriptionSection(composite, iu);
		createDocumentationSection(composite, iu);

		return composite;
	}

	private void createGeneralSection(Composite parent, IInstallableUnit iu) {
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginWidth = 0;
		layout.marginHeight = 0;
		composite.setLayout(layout);
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		// Get general info in the default locale
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, iu.getProperty(IInstallableUnit.PROP_NAME, null));
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId());
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString());
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, iu.getProperty(IInstallableUnit.PROP_PROVIDER, null));
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, iu.getProperty(IInstallableUnit.PROP_CONTACT, null));

	}

	private void createDescriptionSection(Composite parent, IInstallableUnit iu) {
		// Get the iu description in the default locale
		String description = iu.getProperty(IInstallableUnit.PROP_DESCRIPTION, null);
		if (description != null && description.length() > 0) {
			Group group = new Group(parent, SWT.NONE);
			group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);
			group.setLayout(new GridLayout());
			group.setLayoutData(new GridData(GridData.FILL_BOTH));

			Text text = new Text(group, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
			GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
			gd.widthHint = computeWidthLimit(text, 80);
			gd.heightHint = 200;
			text.setEditable(false);
			text.setText(description);
			text.setLayoutData(gd);
		}

	}

	private void createDocumentationSection(Composite parent, IInstallableUnit iu) {
		String docURL = iu.getProperty(IInstallableUnit.PROP_DOC_URL);
		if (docURL != null && docURL.length() > 0) {
			final URL url;
			try {
				url = new URL(docURL);
			} catch (MalformedURLException e) {
				return;
			}
			String filename = (url != null) ? url.getFile() : null;
			if (filename != null && (filename.endsWith(".htm") || filename.endsWith(".html"))) { //$NON-NLS-1$ //$NON-NLS-2$
				// create some space
				new Label(parent, SWT.NONE);
				// Now create a link to the documentation
				Label label = new Label(parent, SWT.NONE);
				label.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DocumentationLink);
				Link link = new Link(parent, SWT.LEFT | SWT.WRAP);
				link.setText(NLS.bind("<a>{0}</a>", url.toExternalForm())); //$NON-NLS-1$
				GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
				gd.widthHint = computeWidthLimit(link, 80);
				link.setLayoutData(gd);
				link.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						showURL(url);
					}
				});
			}
		}
	}

	private void addField(Composite parent, String property, String value) {
		if (value != null && value.length() > 0) {
			Label label = new Label(parent, SWT.NONE);
			label.setText(property);

			Text text = new Text(parent, SWT.WRAP | SWT.READ_ONLY);
			text.setText(value);
			// Needed to get the right color on the Mac.
			// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=258112
			text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
			GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
			text.setLayoutData(gd);
		}
	}
}

Back to the top