1
package org.vcs.bazaar.eclipse.properties;
3
import org.eclipse.core.resources.IResource;
4
import org.eclipse.core.runtime.CoreException;
5
import org.eclipse.core.runtime.QualifiedName;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.layout.GridData;
8
import org.eclipse.swt.layout.GridLayout;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Control;
11
import org.eclipse.swt.widgets.Label;
12
import org.eclipse.swt.widgets.Text;
13
import org.eclipse.ui.dialogs.PropertyPage;
15
public class SamplePropertyPage extends PropertyPage {
17
private static final String PATH_TITLE = "Path:";
18
private static final String OWNER_TITLE = "&Owner:";
19
private static final String OWNER_PROPERTY = "OWNER";
20
private static final String DEFAULT_OWNER = "John Doe";
22
private static final int TEXT_FIELD_WIDTH = 50;
24
private Text ownerText;
27
* Constructor for SamplePropertyPage.
29
public SamplePropertyPage() {
33
private void addFirstSection(Composite parent) {
34
Composite composite = createDefaultComposite(parent);
36
//Label for path field
37
Label pathLabel = new Label(composite, SWT.NONE);
38
pathLabel.setText(PATH_TITLE);
41
Text pathValueText = new Text(composite, SWT.WRAP | SWT.READ_ONLY);
42
pathValueText.setText(((IResource) getElement()).getFullPath().toString());
45
private void addSeparator(Composite parent) {
46
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
47
GridData gridData = new GridData();
48
gridData.horizontalAlignment = GridData.FILL;
49
gridData.grabExcessHorizontalSpace = true;
50
separator.setLayoutData(gridData);
53
private void addSecondSection(Composite parent) {
54
Composite composite = createDefaultComposite(parent);
56
// Label for owner field
57
Label ownerLabel = new Label(composite, SWT.NONE);
58
ownerLabel.setText(OWNER_TITLE);
61
ownerText = new Text(composite, SWT.SINGLE | SWT.BORDER);
62
GridData gd = new GridData();
63
gd.widthHint = convertWidthInCharsToPixels(TEXT_FIELD_WIDTH);
64
ownerText.setLayoutData(gd);
66
// Populate owner text field
69
((IResource) getElement()).getPersistentProperty(
70
new QualifiedName("", OWNER_PROPERTY));
71
ownerText.setText((owner != null) ? owner : DEFAULT_OWNER);
72
} catch (CoreException e) {
73
ownerText.setText(DEFAULT_OWNER);
78
* @see PreferencePage#createContents(Composite)
80
protected Control createContents(Composite parent) {
81
Composite composite = new Composite(parent, SWT.NONE);
82
GridLayout layout = new GridLayout();
83
composite.setLayout(layout);
84
GridData data = new GridData(GridData.FILL);
85
data.grabExcessHorizontalSpace = true;
86
composite.setLayoutData(data);
88
addFirstSection(composite);
89
addSeparator(composite);
90
addSecondSection(composite);
94
private Composite createDefaultComposite(Composite parent) {
95
Composite composite = new Composite(parent, SWT.NULL);
96
GridLayout layout = new GridLayout();
97
layout.numColumns = 2;
98
composite.setLayout(layout);
100
GridData data = new GridData();
101
data.verticalAlignment = GridData.FILL;
102
data.horizontalAlignment = GridData.FILL;
103
composite.setLayoutData(data);
108
protected void performDefaults() {
109
// Populate the owner text field with the default value
110
ownerText.setText(DEFAULT_OWNER);
113
public boolean performOk() {
114
// store the value in the owner text field
116
((IResource) getElement()).setPersistentProperty(
117
new QualifiedName("", OWNER_PROPERTY),
118
ownerText.getText());
119
} catch (CoreException e) {
b'\\ No newline at end of file'