in uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/AnnotationPropertyPage.java [398:627]
protected Control createContents(Composite parent) {
// Set a size to fix UIMA-2115
setSize(new Point(350, 350));
TypeSystem typeSystem = getTypeSystem();
if (typeSystem == null) {
isTypeSystemPresent = false;
Label message = new Label(parent, SWT.NONE);
message.setText("Please set a valid typesystem file first.");
return message;
}
Composite base = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
base.setLayout(layout);
// type text
Label typeText = new Label(base, SWT.NONE);
typeText.setText("Annotation types:");
GridData typeTextGridData = new GridData();
typeTextGridData.horizontalSpan = 2;
typeText.setLayoutData(typeTextGridData);
// type list
mTypeList = new TableViewer(base, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
GridData typeListGridData = new GridData();
typeListGridData.horizontalAlignment = SWT.FILL;
typeListGridData.grabExcessVerticalSpace = true;
typeListGridData.verticalAlignment = SWT.FILL;
typeListGridData.verticalSpan = 2;
mTypeList.getControl().setLayoutData(typeListGridData);
mTypeList.getTable().setHeaderVisible(true);
TableViewerColumn typeColumn = new TableViewerColumn(mTypeList, SWT.LEFT);
typeColumn.getColumn().setText("Type");
typeColumn.getColumn().setWidth(250);
typeColumn.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Type type = (Type) cell.getElement();
cell.setText(type.getName());
}
});
TableViewerColumn layerColumn = new TableViewerColumn(mTypeList, SWT.LEFT);
layerColumn.getColumn().setText("Layer");
layerColumn.getColumn().setWidth(50);
layerColumn.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Type type = (Type) cell.getElement();
AnnotationStyle style = getWorkingCopyAnnotationStyle(type);
cell.setText(Integer.toString(style.getLayer()));
}
});
Type annotationType = typeSystem.getType(CAS.TYPE_NAME_ANNOTATION);
List<Type> types = typeSystem.getProperlySubsumedTypes(annotationType);
for (Type type : types) {
// inserts objects with type Type
mTypeList.add(type);
}
mTypeList.add(annotationType);
mTypeList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
itemSelected();
}
});
Composite settingsComposite = new Composite(base, SWT.NONE);
GridLayout settingsLayout = new GridLayout();
settingsLayout.numColumns = 2;
settingsComposite.setLayout(settingsLayout);
// text style combo
Label styleText = new Label(settingsComposite, SWT.READ_ONLY);
styleText.setText("Style:");
// style combo
mStyleCombo = new Combo(settingsComposite, SWT.READ_ONLY | SWT.DROP_DOWN);
mStyleCombo.setEnabled(false);
mStyleCombo.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
AnnotationStyle style = getWorkingCopyAnnotationStyle(getSelectedType());
AnnotationStyle newStyle = new AnnotationStyle(style.getAnnotation(),
AnnotationStyle.Style.valueOf(mStyleCombo.getText()), style.getColor(),
style.getLayer(), style.getConfiguration());
updateCustomStyleControl(newStyle, getSelectedType());
// Is there a nice way to do this ?!
if (styleConfigurationWidget.isVisible()) {
String configString = styleConfigurationWidget.getConfiguration();
if (configString != null) {
newStyle = new AnnotationStyle(newStyle.getAnnotation(), newStyle.getStyle(),
newStyle.getColor(), newStyle.getLayer(), configString);
}
}
setAnnotationStyle(newStyle);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// called when enter is pressed, not needed
}
});
AnnotationStyle.Style possibleStyles[] = AnnotationStyle.Style.values();
for (AnnotationStyle.Style style : possibleStyles) {
mStyleCombo.add(style.name());
}
// text color label
Label colorText = new Label(settingsComposite, SWT.NONE);
colorText.setText("Color:");
mColorSelector = new ColorSelector(settingsComposite);
mColorSelector.setEnabled(false);
mColorSelector.addListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
AnnotationStyle style = getWorkingCopyAnnotationStyle(getSelectedType());
RGB colorRGB = mColorSelector.getColorValue();
Color color = new Color(colorRGB.red, colorRGB.green, colorRGB.blue);
setAnnotationStyle(new AnnotationStyle(style.getAnnotation(), style.getStyle(), color,
style.getLayer(), style.getConfiguration()));
}
});
moveLayerUpButton = new Button(settingsComposite, SWT.NONE);
moveLayerUpButton.setText("Move layer up");
GridDataFactory.fillDefaults().span(2, 1).applyTo(moveLayerUpButton);
moveLayerUpButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
AnnotationStyle style = getWorkingCopyAnnotationStyle(getSelectedType());
setAnnotationStyle(new AnnotationStyle(style.getAnnotation(),
AnnotationStyle.Style.valueOf(mStyleCombo.getText()), style.getColor(),
style.getLayer() + 1, style.getConfiguration()));
mTypeList.update(getSelectedType(), null);
}
});
moveLayerDownButton = new Button(settingsComposite, SWT.NONE);
moveLayerDownButton.setText("Move layer down");
GridDataFactory.fillDefaults().span(2, 1).applyTo(moveLayerDownButton);
moveLayerDownButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
AnnotationStyle style = getWorkingCopyAnnotationStyle(getSelectedType());
if (style.getLayer() - 1 >= 0) {
setAnnotationStyle(new AnnotationStyle(style.getAnnotation(),
AnnotationStyle.Style.valueOf(mStyleCombo.getText()), style.getColor(),
style.getLayer() - 1, style.getConfiguration()));
mTypeList.update(getSelectedType(), null);
}
}
});
// Insert style dependent configuration widget
styleConfigurationWidget = new TagStyleConfigWidget(settingsComposite);
GridDataFactory.fillDefaults().span(2, 1).applyTo(styleConfigurationWidget);
styleConfigurationWidget.setVisible(false);
styleConfigurationWidget.addListener(new CustomStyleConfigChangeListener() {
@Override
public void styleChanged(String configuration) {
AnnotationStyle style = getWorkingCopyAnnotationStyle(getSelectedType());
setAnnotationStyle(new AnnotationStyle(style.getAnnotation(), style.getStyle(),
style.getColor(), style.getLayer(), configuration));
}
});
// There is always at least the AnnotationFS type
mTypeList.getTable().select(0);
if (mTypeList.getTable().getSelectionIndex() != -1) {
itemSelected();
}
return base;
}