use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class ClassificationMappingParameterPage method createManualTabControl.
private Control createManualTabControl(Composite tabParent) {
// TODO load occurring value sources
Composite tabContent = new Composite(tabParent, SWT.NONE);
tabContent.setLayout(new GridLayout(1, true));
ToolBar toolBar = new ToolBar(tabContent, SWT.NONE);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Composite tableContainer = new Composite(tabContent, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableColumnLayout layout = new TableColumnLayout();
tableContainer.setLayout(layout);
tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
sourceColumn.getColumn().setText("Source value");
layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
sourceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
return entry.getKey().getStringRepresentation();
}
});
TableViewerColumn targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
targetColumn.getColumn().setText("Target value");
layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
targetColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
if (entry.getValue() == null) {
StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
cell.setText(styledString.getString());
cell.setStyleRanges(styledString.getStyleRanges());
} else {
cell.setText(entry.getValue().getStringRepresentation());
cell.setStyleRanges(null);
}
super.update(cell);
}
});
tableViewer.setInput(lookupTable.entrySet());
tableViewer.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
if (cell != null) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
Value oldValue;
Value newValue;
if (cell.getColumnIndex() == 0) {
oldValue = entry.getKey();
newValue = selectValue(sourceProperty, sourceEntity, "Edit source value", "Enter a new source value", oldValue.getStringRepresentation());
} else {
oldValue = entry.getValue();
String initialValue = oldValue == null ? null : oldValue.getStringRepresentation();
newValue = selectValue(targetProperty, targetEntity, "Edit target value", "Enter a target value", initialValue);
}
if (newValue == null)
return;
if (cell.getColumnIndex() == 0) {
if (!newValue.equals(oldValue) && lookupTable.containsKey(newValue)) {
showDuplicateSourceWarning(newValue.getStringRepresentation());
} else {
lookupTable.put(newValue, entry.getValue());
lookupTable.remove(oldValue);
tableViewer.refresh();
}
} else {
entry.setValue(newValue);
tableViewer.update(entry, null);
}
}
}
});
final ToolItem valueAdd = new ToolItem(toolBar, SWT.PUSH);
final ToolItem fillValues = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem loadButton = new ToolItem(toolBar, SWT.PUSH);
saveButton = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem valueRemove = new ToolItem(toolBar, SWT.PUSH);
removeAllButton = new ToolItem(toolBar, SWT.PUSH);
valueAdd.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_ADD));
valueAdd.setToolTipText("Add source value");
valueAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Value newSource = selectValue(sourceProperty, sourceEntity, "Add source value", "Enter a new source value", null);
if (newSource != null) {
if (lookupTable.containsKey(newSource))
showDuplicateSourceWarning(newSource.getStringRepresentation());
else {
lookupTable.put(newSource, null);
removeAllButton.setEnabled(true);
saveButton.setEnabled(true);
tableViewer.refresh();
}
}
}
});
loadButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_OPEN));
loadButton.setToolTipText("Load classification from file");
loadButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableLoadWizard wizard = new LookupTableLoadWizard();
LookupLoadAdvisor advisor = new LookupLoadAdvisor();
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
if (advisor.getLookupTable() != null) {
lookupTable.putAll(advisor.getLookupTable().getTable().asMap());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
}
});
fillValues.setImage(fillValuesIcon);
fillValues.setToolTipText("Attempt to fill source values with enumerations and occurring values.");
fillValues.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// first try enumeration
Enumeration<?> enumeration = sourceProperty.getPropertyType().getConstraint(Enumeration.class);
if (enumeration.getValues() != null) {
addSourceValuesIfNew(enumeration.getValues());
}
// then try occurring values
if (!ovs.updateOccurringValues(sourceEntity)) {
// values already there or not possible
addOccurringSourceValues(ovs.getOccurringValues(sourceEntity));
} else {
// job is running, listener will be notified
}
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
saveButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SAVE));
saveButton.setToolTipText("Save classification to file");
saveButton.setEnabled(false);
saveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableExportWizard wizard = new LookupTableExportWizard();
LookupExportAdvisor advisor = new LookupExportAdvisor(new LookupTableInfoImpl(new LookupTableImpl(lookupTable), "current", "not set"));
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
}
});
valueRemove.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REMOVE));
valueRemove.setToolTipText("Remove classification entry");
valueRemove.setEnabled(false);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
valueRemove.setEnabled(!event.getSelection().isEmpty());
saveButton.setEnabled(!event.getSelection().isEmpty());
}
});
valueRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (tableViewer.getSelection().isEmpty())
return;
Object element = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
lookupTable.remove(entry.getKey());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
removeAllButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TRASH));
removeAllButton.setEnabled(false);
removeAllButton.setToolTipText("Remove complete classification");
removeAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lookupTable.clear();
tableViewer.refresh();
removeAllButton.setEnabled(false);
saveButton.setEnabled(false);
}
});
Label desc = new Label(tabContent, SWT.NONE);
desc.setText("Double click on a table cell to change its value.");
return tabContent;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class ClassificationMappingParameterPage method createFromFileTabControl.
private Control createFromFileTabControl(Composite tabParent) {
// Parent composite for fromFileTab
Composite item2Content = new Composite(tabParent, SWT.NONE);
item2Content.setLayout(new GridLayout());
// Label to descripe what the user should do
Label l = new Label(item2Content, SWT.NONE);
l.setText("Select the project lookup table resource you want to use for the classification:");
// Get the Lookuptable Service
final LookupService lookupService = HaleUI.getServiceProvider().getService(LookupService.class);
// Composite for comboViewerComposite and Button
Composite parent = new Composite(item2Content, SWT.NONE);
parent.setLayout(new GridLayout(2, false));
parent.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
// Description Label
description = new Label(item2Content, SWT.WRAP);
description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
description.setText("");
description.setVisible(false);
// label with warning message
Composite warnComp = new Composite(item2Content, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
Label warnImage = new Label(warnComp, SWT.NONE);
warnImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(warnImage);
Label warn = new Label(warnComp, SWT.WRAP);
warn.setText("Classifications from a file resource will not function in another project where the alignment with the classification is imported or used as a base alignment.\n" + "If unsure, use the 'Explicit' mode instead and use the option to load the classification from a file.");
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(300, SWT.DEFAULT).applyTo(warn);
// Composite for ComboViewer
Composite viewerComposite = new Composite(parent, SWT.NONE);
viewerComposite.setLayout(new FillLayout());
GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
viewerComposite.setLayoutData(GridDataFactory.copyData(layoutData));
// ComboViewer
lookupTableComboViewer = new ComboViewer(viewerComposite, SWT.READ_ONLY);
lookupTableComboViewer.setContentProvider(ArrayContentProvider.getInstance());
lookupTableComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof String) {
return lookupService.getTable((String) element).getName();
}
return null;
}
});
lookupTableComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// Show the description for the selected lookupTable
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
String desc = lookupService.getTable(selection.getFirstElement().toString()).getDescription();
if (desc != null) {
description.setText("Description: " + desc);
} else {
description.setText("");
}
if (!description.isVisible()) {
description.setVisible(true);
}
}
});
lookupTableComboViewer.setInput(lookupService.getTableIDs());
if (selectedLookupTableID != null) {
lookupTableComboViewer.setSelection(new StructuredSelection(selectedLookupTableID), true);
}
// Button to load a lookupTable if no one is loaded
final Button browseButton = new Button(parent, SWT.PUSH);
browseButton.setText("Add...");
browseButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
IOWizardAction action = new IOWizardAction("eu.esdihumboldt.hale.lookup.import");
action.run();
action.dispose();
// Refresh the viewer
lookupTableComboViewer.setInput(lookupService.getTableIDs());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing to do here
}
});
return item2Content;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class ChooseHaleConnectProjectWizardPage method createContent.
/**
* @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#createContent(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createContent(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(new GridLayout(4, false));
keywordFilter = new Text(page, SWT.SEARCH | SWT.ICON_SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
keywordFilter.setMessage("Enter search text here...");
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(keywordFilter);
ownerFilter = new ComboViewer(page);
GridDataFactory.fillDefaults().grab(false, false).applyTo(ownerFilter.getControl());
ownerFilter.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
new Object();
}
@Override
public void dispose() {
//
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof List<?>) {
List<?> elements = (List<?>) inputElement;
return elements.toArray();
} else if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return new Object[] {};
}
});
ownerFilter.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof OwnerFilterEntry) {
return ((OwnerFilterEntry) element).getLabel();
}
return super.getText(element);
}
});
List<OwnerFilterEntry> availableFilters = new ArrayList<>();
availableFilters.add(NULL_FILTER);
availableFilters.add(new OwnerFilterEntry(new Owner[] { new Owner(OwnerType.USER, haleConnect.getSession().getUserId()) }, "My projects"));
List<Owner> orgs = new ArrayList<>();
for (String orgId : haleConnect.getSession().getOrganisationIds()) {
orgs.add(new Owner(OwnerType.ORGANISATION, orgId));
}
if (!orgs.isEmpty()) {
availableFilters.add(new OwnerFilterEntry(orgs.toArray(new Owner[] {}), "My organisations' projects"));
}
ownerFilter.setInput(availableFilters);
ownerFilter.setSelection(new StructuredSelection(NULL_FILTER));
Composite tableComposite = new Composite(page, SWT.NONE);
TableColumnLayout columnLayout = new TableColumnLayout();
tableComposite.setLayout(columnLayout);
projects = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
projects.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
update();
}
});
TableViewerColumn nameColumn = new TableViewerColumn(projects, SWT.LEAD);
nameColumn.getColumn().setText("Project name");
nameColumn.setLabelProvider(new ColumnLabelProvider() {
/**
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof HaleConnectProjectInfo) {
return ((HaleConnectProjectInfo) element).getName();
}
return element.toString();
}
});
columnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(45, 200, true));
TableViewerColumn authorColumn = new TableViewerColumn(projects, SWT.LEAD);
authorColumn.getColumn().setText("Author");
authorColumn.setLabelProvider(new ColumnLabelProvider() {
/**
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof HaleConnectProjectInfo) {
return ((HaleConnectProjectInfo) element).getAuthor();
}
return element.toString();
}
});
columnLayout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(20, 50, true));
TableViewerColumn ownerColumn = new TableViewerColumn(projects, SWT.LEAD);
ownerColumn.getColumn().setText("Owner");
ownerColumn.setLabelProvider(new ColumnLabelProvider() {
/**
* @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof HaleConnectProjectInfo) {
Owner owner = ((HaleConnectProjectInfo) element).getOwner();
if (owner.isUser()) {
try {
HaleConnectUserInfo user = haleConnect.getUserInfo(owner.getId());
if (!StringUtils.isEmpty(user.getFullName())) {
return user.getFullName();
} else if (!StringUtils.isEmpty(user.getScreenName())) {
return user.getScreenName();
} else {
return MessageFormat.format("<user {0}>", user.getUserId());
}
} catch (HaleConnectException e) {
log.error(e.getMessage(), e);
return MessageFormat.format("<user {0}>", owner.getId());
}
} else if (owner.isOrganisation()) {
try {
return haleConnect.getOrganisationInfo(owner.getId()).getName();
} catch (HaleConnectException e) {
log.error(e.getMessage(), e);
return MessageFormat.format("<organisation {0}>", owner.getId());
}
} else {
return "<unknown owner type> ID: " + owner.getId();
}
}
return element.toString();
}
});
columnLayout.setColumnData(ownerColumn.getColumn(), new ColumnWeightData(35, 100, true));
final Table projectsTable = projects.getTable();
projectsTable.setHeaderVisible(true);
projectsTable.setLinesVisible(true);
tableComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).grab(true, true).create());
projects.setContentProvider(ArrayContentProvider.getInstance());
populateProjects();
final ProjectFilter projectFilter = new ProjectFilter(projects);
projects.addFilter(projectFilter);
ownerFilter.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
if (selection.getFirstElement() instanceof OwnerFilterEntry) {
OwnerFilterEntry selectedFilter = (OwnerFilterEntry) selection.getFirstElement();
if (selectedFilter.equals(NULL_FILTER)) {
projectFilter.clearOwnerFilter();
} else {
projectFilter.filterByOwners(Arrays.asList(selectedFilter.getOwner()));
}
}
}
}
});
keywordFilter.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
projectFilter.setSearchText(keywordFilter.getText());
}
});
final Button refresh = new Button(page, SWT.FLAT);
refresh.setText("Refresh");
GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(refresh);
refresh.addSelectionListener(new SelectionAdapter() {
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
populateProjects();
}
});
ownerFilter.getControl().setFocus();
setControl(page);
update();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class InterpolationSettingPage method createContent.
@Override
protected void createContent(Composite page) {
// page.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());
page.setLayout(new GridLayout(1, false));
Group groupError = new Group(page, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(3).applyTo(groupError);
// GridDataFactory.fillDefaults().grab(true, false).applyTo(groupError);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(groupError);
groupError.setText("Interpolated geometries");
// Interpolation algorithm
Label labelAlg = new Label(groupError, SWT.NONE);
labelAlg.setText("Interpolation algorithm: ");
labelAlg.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
algorithms = new ComboViewer(groupError, SWT.READ_ONLY);
algorithms.setContentProvider(ArrayContentProvider.getInstance());
algorithms.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof InterpolationAlgorithmFactory) {
return ((InterpolationAlgorithmFactory) element).getDisplayName();
}
return super.getText(element);
}
});
algorithms.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).create());
algorithms.setInput(InterpolationExtension.getInstance().getFactories());
algorithms.setSelection(new StructuredSelection(InterpolationExtension.getInstance().getFactory(InterpolationHelper.DEFAULT_ALGORITHM)));
algorithms.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateState();
}
});
// label error
Label labelError = new Label(groupError, SWT.NONE);
labelError.setText("Maximum Position Error: ");
labelError.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
error = new Text(groupError, SWT.BORDER | SWT.SINGLE);
error.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
error.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState();
}
});
// label unit
Label labelUnit = new Label(groupError, SWT.NONE);
labelUnit.setText("(unit)");
labelUnit.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
Label positionErrorDesc = new Label(groupError, SWT.NONE);
positionErrorDesc.setText("The maximum positional error is used by the interpolation algorithm to ensure a certain level of accuracy.");
GridDataFactory.fillDefaults().span(3, 1).applyTo(positionErrorDesc);
Group group = new Group(page, SWT.NONE);
group.setLayout(new GridLayout(1, false));
group.setText("Other geometries");
GridDataFactory.fillDefaults().span(3, 1).applyTo(group);
moveToGrid = new Button(group, SWT.CHECK);
moveToGrid.setText("Move all geometries to interpolation grid (if applicable)");
GridDataFactory.fillDefaults().grab(true, false).applyTo(moveToGrid);
// default
moveToGrid.setSelection(false);
Label desc = new Label(group, SWT.NONE);
desc.setText("Moves all geometries coordinates to the interpolation grid to allow for topological consistency with interpolated geometries.");
GridDataFactory.fillDefaults().grab(true, false).applyTo(desc);
// filler
new Label(page, SWT.NONE);
// label with warning message
Composite warnComp = new Composite(page, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
updateState();
setPageComplete(false);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class TypeStructureTray method createContents.
@Override
protected Control createContents(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
// retrieve the types
final Collection<? extends TypeDefinition> types = this.types.getTypes();
// heading
Label caption = new Label(page, SWT.NONE);
switch(schemaSpace) {
case SOURCE:
caption.setText("Source structure");
break;
case TARGET:
caption.setText("Target structure");
break;
}
caption.setFont(JFaceResources.getHeaderFont());
// create tree viewer
PatternFilter patternFilter = new SchemaPatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
final FilteredTree filteredTree = new TreePathFilteredTree(page, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
TreeViewer tree = filteredTree.getViewer();
tree.setUseHashlookup(true);
StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider(tree);
tree.setLabelProvider(labelProvider);
IContentProvider contentProvider = createContentProvider(tree);
tree.setContentProvider(contentProvider);
GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
tree.setComparator(new DefinitionComparator());
// set input
if (types.size() == 1) {
tree.setInput(types.iterator().next());
} else {
tree.setInput(types);
}
/*
* Groovy specific part
*/
// caption
Label example = new Label(page, SWT.NONE);
switch(schemaSpace) {
case SOURCE:
example.setText("Examples: Access variables");
break;
case TARGET:
example.setText("Example: Build instance");
break;
default:
example.setText("Example");
}
// source viewer
final SourceViewer viewer = new SourceViewer(page, null, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
final IColorManager colorManager = new GroovyColorManager();
SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT), null);
viewer.configure(configuration);
GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());
// make sure the color manager is disposed
viewer.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
colorManager.dispose();
}
});
// react to tree selection changes
tree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IDocument doc = new Document();
GroovySourceViewerUtil.setupDocument(doc);
String example = null;
if (!event.getSelection().isEmpty()) {
switch(schemaSpace) {
case SOURCE:
example = createSourceSample(event.getSelection(), types);
break;
case TARGET:
example = createTargetSample(event.getSelection(), types);
break;
}
}
if (example == null || example.isEmpty()) {
switch(schemaSpace) {
case SOURCE:
doc.set("// Please select schema elements to access");
break;
case TARGET:
doc.set("// Please select which schema elements\n// to include in the instance to build");
break;
default:
doc.set("// Please select one or more schema elements");
}
} else {
doc.set(example);
}
viewer.setDocument(doc);
}
});
tree.setSelection(StructuredSelection.EMPTY);
return page;
}
Aggregations