use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class EditMappableTypesPage method createControl.
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
parent.setLayout(new GridLayout());
// create filtered tree
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
return new CheckboxTreeViewer(parent, style);
}
};
// configure viewer
viewer = (CheckboxTreeViewer) tree.getViewer();
contentProvider = new NSTypeTreeContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setComparator(new DefinitionComparator());
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object doubleClicked = selection.getFirstElement();
if (doubleClicked instanceof String)
viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
else {
boolean newState = !checkStateProvider.isChecked(doubleClicked);
viewer.setChecked(doubleClicked, newState);
checkStateOfTypeChanged((TypeDefinition) doubleClicked, newState);
}
}
});
viewer.setLabelProvider(definitionLabels);
// because elements filtered by FilteredTree lose their checked state:
checkStateProvider = new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
if (element instanceof String) {
Object[] children = contentProvider.getChildren(element);
boolean containsChecked = false;
boolean containsUnchecked = false;
for (Object child : children) {
if (isChecked(child))
containsChecked = true;
else
containsUnchecked = true;
if (containsChecked && containsUnchecked)
return true;
}
}
return false;
}
@Override
public boolean isChecked(Object element) {
if (element instanceof String) {
for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
return true;
return false;
}
return ((TypeDefinition) element).getConstraint(MappingRelevantFlag.class).isEnabled() != changedTypes.contains(element);
}
};
viewer.setCheckStateProvider(checkStateProvider);
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getElement() instanceof String) {
// update children
viewer.setGrayed(event.getElement(), false);
for (Object child : contentProvider.getChildren(event.getElement())) {
// if (mappedTypeFilter.select(viewer, event.getElement(), child)) {
if (checkStateProvider.isChecked(child) != event.getChecked()) {
viewer.setChecked(child, event.getChecked());
checkStateOfTypeChanged((TypeDefinition) child, event.getChecked());
}
// }
}
viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
// only two levels, no need to update any parents or
// children's children
} else {
// if (mappedTypeFilter.select(viewer, null, event.getElement()))
checkStateOfTypeChanged((TypeDefinition) event.getElement(), event.getChecked());
// else if (!event.getChecked())
// viewer.setChecked(event.getElement(), true);
}
}
});
// // filter types which are used in the current alignment
// viewer.addFilter(mappedTypeFilter);
// set input to all types in the given index
viewer.setInput(typeIndex.getTypes());
// expand all except XMLSchema
viewer.expandAll();
viewer.setExpandedState("http://www.w3.org/2001/XMLSchema", false);
// set control
setControl(viewer.getControl());
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class CodeListSelectionDialog method createViewer.
/**
* @see AbstractViewerSelectionDialog#createViewer(Composite)
*/
@Override
protected TreeViewer createViewer(Composite parent) {
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
tree.getViewer().setComparator(new CodeListComparator());
// set filter to only accept code list selection (must be set after
// pattern filter is created)
setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof CodeListRef;
}
} });
return tree.getViewer();
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class NewRelationPage method createViewer.
/**
* @see ViewerWizardSelectionPage#createViewer(Composite)
*/
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
PatternFilter filter = new PatternFilter();
filter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
viewer = tree.getViewer();
viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
// no input needed, but we have to set something
viewer.setInput(Boolean.TRUE);
// set focus on viewer control to prevent odd behavior
viewer.getControl().setFocus();
// expand selection
viewer.expandAll();
// selection context
contextProvider = new HALEContextProvider(viewer, null);
// help update on page shown
if (getContainer() instanceof IPageChangeProvider) {
((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {
@Override
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == NewRelationPage.this) {
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
}
}
}
});
}
// help update on selection change
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IContext context = getHelpContext();
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
}
// update the help
if (context != null) {
TrayDialog trayDialog = (TrayDialog) getContainer();
if (trayDialog.getTray() != null) {
// if the tray is already open, update the help
performHelp();
}
}
}
});
// load page configuration
// XXX would be better if called from outside
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
restore(ps.getConfigurationService());
return new Pair<StructuredViewer, Control>(viewer, tree);
}
use of org.eclipse.ui.dialogs.PatternFilter 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;
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class InstanceValidationReportDetailsPage method createControls.
/**
* @see CustomReportDetailsPage#createControls(Composite)
*/
@Override
public Control createControls(Composite parent) {
// filtered tree sets itself GridData, so set layout to gridlayout
parent.setLayout(GridLayoutFactory.fillDefaults().create());
// create pattern filter for FilteredTree
PatternFilter filter = new TreePathPatternFilter();
filter.setIncludeLeadingWildcard(true);
// create FilteredTree
FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
treeViewer = filteredTree.getViewer();
// set content provider
contentProvider = new InstanceValidationReportDetailsContentProvider();
treeViewer.setContentProvider(contentProvider);
// set label provider
treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
// set comparator
treeViewer.setComparator(new ViewerComparator() {
/**
* @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
*/
@Override
public int category(Object element) {
if (element instanceof QName || element instanceof Definition<?>)
// Path
return 0;
else if (element instanceof String)
// Category
return 1;
else
// InstanceValidationMessage
return 2;
}
});
// add menu on right-click
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
if (getValidSelection() == null)
return;
// selection is valid, offer link to transformed data view
manager.add(new ShowExampleAction());
}
});
// remove previous menus
menuMgr.setRemoveAllWhenShown(true);
// add menu to tree
treeViewer.getTree().setMenu(menu);
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
showSelectionInDataView();
}
});
Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
return filteredTree;
}
Aggregations