This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
/
MetsProjectNaturePropertiesSection.java
178 lines (150 loc) · 6.25 KB
/
MetsProjectNaturePropertiesSection.java
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Copyright 2010 The University of North Carolina at Chapel Hill
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package unc.lib.cdr.workbench.views;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import unc.lib.cdr.workbench.project.MetsProjectNature;
public class MetsProjectNaturePropertiesSection extends AbstractPropertySection {
@SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(MetsProjectNaturePropertiesSection.class);
IProject project = null;
MetsProjectNature nature = null;
Group stagingGroup = null;
Text stagingBaseText = null;
Text stagingStatusText = null;
Group metsGroup = null;
Text manifestText = null;
Text describedStatusText = null;
public MetsProjectNaturePropertiesSection() {
// TODO Auto-generated constructor stub
}
/**
* @see org.eclipse.ui.views.properties.tabbed.ISection#setInput(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
@Override
public void setInput(IWorkbenchPart part, ISelection s) {
super.setInput(part, s);
Assert.isTrue(s instanceof IStructuredSelection);
Object fs = ((IStructuredSelection) s).getFirstElement();
if (fs instanceof IProject) {
this.project = (IProject)fs;
this.nature = MetsProjectNature.get(project);
}
Assert.isTrue(this.nature != null);
}
/**
* @see org.eclipse.ui.views.properties.tabbed.ISection#shouldUseExtraSpace()
*/
@Override
public boolean shouldUseExtraSpace() {
return false;
}
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite outer = getWidgetFactory().createFlatFormComposite(parent);
outer.setLayout(new GridLayout());
metsGroup = getWidgetFactory().createGroup(outer, "METS Manifest");
metsGroup.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false));
FormLayout layout = new FormLayout();
metsGroup.setLayout(layout);
FormData data;
int secondTab = 150;
CLabel l1 = getWidgetFactory().createCLabel(metsGroup, "Location");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
l1.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
manifestText = getWidgetFactory().createText(metsGroup, "", SWT.READ_ONLY);
manifestText.setLayoutData(data);
CLabel l2 = getWidgetFactory().createCLabel(metsGroup, "Status");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(l1, ITabbedPropertyConstants.VSPACE);
l2.setLayoutData(data);
describedStatusText = getWidgetFactory().createText(metsGroup, "", SWT.READ_ONLY);
data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(l1, ITabbedPropertyConstants.VSPACE);
describedStatusText.setLayoutData(data);
stagingGroup = getWidgetFactory().createGroup(outer, "Staging");
stagingGroup.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false));
FormLayout layout2 = new FormLayout();
stagingGroup.setLayout(layout2);
CLabel sl = getWidgetFactory().createCLabel(stagingGroup, "Location");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(l2, ITabbedPropertyConstants.VSPACE);
sl.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(l2, ITabbedPropertyConstants.VSPACE);
stagingBaseText = getWidgetFactory().createText(stagingGroup, "", SWT.READ_ONLY);
stagingBaseText.setLayoutData(data);
CLabel hl = getWidgetFactory().createCLabel(stagingGroup, "Status");
data = new FormData();
data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
data.top = new FormAttachment(sl, ITabbedPropertyConstants.VSPACE);
hl.setLayoutData(data);
// TODO add a refresh status button
data = new FormData();
data.left = new FormAttachment(0, secondTab);
data.top = new FormAttachment(sl, ITabbedPropertyConstants.VSPACE);
stagingStatusText = getWidgetFactory().createText(stagingGroup, "", SWT.READ_ONLY);
stagingStatusText.setLayoutData(data);
manifestText.pack();
describedStatusText.pack();
stagingBaseText.pack();
stagingStatusText.pack();
metsGroup.pack();
stagingGroup.pack();
}
@Override
public void refresh() {
manifestText.setText(nature.getMetsResource().getURI().toFileString());
describedStatusText.setText(nature.getDescriptionStatus());
stagingBaseText.setText(nature.getStagingBase().toString());
stagingStatusText.setText(nature.getStagingStatus());
manifestText.pack();
describedStatusText.pack();
stagingBaseText.pack();
stagingStatusText.pack();
metsGroup.pack();
stagingGroup.pack();
}
}