~piastucki/bzr-eclipse/history-view-enhancements

« back to all changes in this revision

Viewing changes to src/org/vcs/bazaar/eclipse/properties/SamplePropertyPage.java

  • Committer: Guillermo Gonzalez
  • Date: 2007-03-14 12:15:50 UTC
  • Revision ID: guillo.gonzo@gmail.com-20070314121550-tltk3b6f3zblf0dh
Initial commit with the new code layout.
Now starts the real work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.vcs.bazaar.eclipse.properties;
2
 
 
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;
14
 
 
15
 
public class SamplePropertyPage extends PropertyPage {
16
 
 
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";
21
 
 
22
 
        private static final int TEXT_FIELD_WIDTH = 50;
23
 
 
24
 
        private Text ownerText;
25
 
 
26
 
        /**
27
 
         * Constructor for SamplePropertyPage.
28
 
         */
29
 
        public SamplePropertyPage() {
30
 
                super();
31
 
        }
32
 
 
33
 
        private void addFirstSection(Composite parent) {
34
 
                Composite composite = createDefaultComposite(parent);
35
 
 
36
 
                //Label for path field
37
 
                Label pathLabel = new Label(composite, SWT.NONE);
38
 
                pathLabel.setText(PATH_TITLE);
39
 
 
40
 
                // Path text field
41
 
                Text pathValueText = new Text(composite, SWT.WRAP | SWT.READ_ONLY);
42
 
                pathValueText.setText(((IResource) getElement()).getFullPath().toString());
43
 
        }
44
 
 
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);
51
 
        }
52
 
 
53
 
        private void addSecondSection(Composite parent) {
54
 
                Composite composite = createDefaultComposite(parent);
55
 
 
56
 
                // Label for owner field
57
 
                Label ownerLabel = new Label(composite, SWT.NONE);
58
 
                ownerLabel.setText(OWNER_TITLE);
59
 
 
60
 
                // Owner text field
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);
65
 
 
66
 
                // Populate owner text field
67
 
                try {
68
 
                        String owner =
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);
74
 
                }
75
 
        }
76
 
 
77
 
        /**
78
 
         * @see PreferencePage#createContents(Composite)
79
 
         */
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);
87
 
 
88
 
                addFirstSection(composite);
89
 
                addSeparator(composite);
90
 
                addSecondSection(composite);
91
 
                return composite;
92
 
        }
93
 
 
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);
99
 
 
100
 
                GridData data = new GridData();
101
 
                data.verticalAlignment = GridData.FILL;
102
 
                data.horizontalAlignment = GridData.FILL;
103
 
                composite.setLayoutData(data);
104
 
 
105
 
                return composite;
106
 
        }
107
 
 
108
 
        protected void performDefaults() {
109
 
                // Populate the owner text field with the default value
110
 
                ownerText.setText(DEFAULT_OWNER);
111
 
        }
112
 
        
113
 
        public boolean performOk() {
114
 
                // store the value in the owner text field
115
 
                try {
116
 
                        ((IResource) getElement()).setPersistentProperty(
117
 
                                new QualifiedName("", OWNER_PROPERTY),
118
 
                                ownerText.getText());
119
 
                } catch (CoreException e) {
120
 
                        return false;
121
 
                }
122
 
                return true;
123
 
        }
124
 
 
125
 
}
 
 
b'\\ No newline at end of file'