use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class AbstractFeatureTypesPage method createContent.
@Override
protected void createContent(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(new GridLayout(1, false));
// create filtered tree
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(page, 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 FeatureTypeTreeContentProvider();
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((QName) doubleClicked, newState);
}
}
});
viewer.setLabelProvider(new FeatureTypeTreeLabelProvider());
// 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 selected.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 (checkStateProvider.isChecked(child) != event.getChecked()) {
viewer.setChecked(child, event.getChecked());
checkStateOfTypeChanged((QName) 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 {
checkStateOfTypeChanged((QName) event.getElement(), event.getChecked());
}
}
});
setControl(page);
// initial update
updateState(selected);
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class TypeDefinitionDialog method createViewer.
@Override
protected TreeViewer createViewer(Composite parent) {
// create viewer
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 DefinitionComparator());
return tree.getViewer();
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class WebTemplatesDialog method createViewer.
@Override
protected TreeViewer createViewer(Composite parent) {
layout = new TreeColumnLayout();
PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true) {
@Override
protected Control createTreeControl(Composite parent, int style) {
Control c = super.createTreeControl(parent, style);
c.setLayoutData(null);
c.getParent().setLayout(layout);
return c;
}
};
return tree.getViewer();
}
use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.
the class DefaultReportDetailsPage 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 PatternFilter();
// create FilteredTree
FilteredTree filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
treeViewer = filteredTree.getViewer();
// set content provider
treeViewer.setContentProvider(new ReportTreeContentProvider());
// set label provider
treeViewer.setLabelProvider(new ReportTreeLabelProvider() {
@Override
public MessageType getMessageType(Message message) {
// the current message type
return messageType;
}
});
// 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 (treeViewer.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
Object o = selection.getFirstElement();
if (o instanceof Message) {
Message m = (Message) o;
// check if a stacktrace exists
if (m.getStackTrace() != null && !m.getStackTrace().equals("")) {
// add Action to the menu
manager.add(new ShowStackTraceAction("Show Stack Trace", null, m));
}
}
}
}
});
// remove previous menus
menuMgr.setRemoveAllWhenShown(true);
// add menu to viewer
treeViewer.getTree().setMenu(menu);
// open stacktrace on double click
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
TreeSelection o = (TreeSelection) event.getSelection();
if (o.getFirstElement() instanceof Message) {
Message m = (Message) o.getFirstElement();
DefaultReportDetailsPage.this.onDoubleClick(m);
}
}
});
return filteredTree;
}
use of org.eclipse.ui.dialogs.PatternFilter in project arduino-eclipse-plugin by Sloeber.
the class LibrarySelectionPage method createTree.
public void createTree(Composite parent) {
// filtering applied to all columns
PatternFilter filter = new PatternFilter() {
@Override
protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
boolean isMatch = false;
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
isMatch |= wordMatches(labelText);
}
return isMatch;
}
};
this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true, true) {
@Override
protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
viewer1.setCheckStateProvider(new LibraryCheckProvider());
viewer1.setLabelProvider(new LibraryLabelProvider());
viewer1.setContentProvider(new LibraryContentProvider());
return viewer1;
}
};
this.viewer = this.tree.getViewer();
this.viewer.setInput(this.libs);
TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
name.setWidth(400);
TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
version.setWidth(100);
// create the editor and set its attributes
this.editor = new TreeEditor(this.viewer.getTree());
this.editor.horizontalAlignment = SWT.LEFT;
this.editor.grabHorizontal = true;
this.editor.setColumn(1);
// this ensures the tree labels are displayed correctly
this.viewer.refresh(true);
// enable tooltips
ColumnViewerToolTipSupport.enableFor(this.viewer);
// tree interactions listener
this.viewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (LibrarySelectionPage.this.editor.getEditor() != null) {
LibrarySelectionPage.this.editor.getEditor().dispose();
}
final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
if (item != null && event.detail == SWT.CHECK) {
if (item.getData() instanceof LibraryTree.Category) {
Category category = ((LibraryTree.Category) item.getData());
item.setGrayed(false);
for (LibraryTree.Library child : category.getLibraries()) {
if (item.getChecked()) {
child.setVersion(child.getLatest());
} else {
child.setVersion((ArduinoLibraryVersion) null);
}
}
for (TreeItem child : item.getItems()) {
child.setChecked(item.getChecked());
child.setText(1, ((LibraryTree.Library) child.getData()).getVersionString());
}
} else {
if (item.getData() instanceof LibraryTree.Library) {
Library lib = ((LibraryTree.Library) item.getData());
if (item.getChecked()) {
lib.setVersion(lib.getLatest());
} else {
lib.setVersion((ArduinoLibraryVersion) null);
}
item.setText(0, lib.getName());
item.setText(1, lib.getVersionString());
verifySubtreeCheckStatus(item.getParentItem());
}
}
}
if (item != null && item.getItemCount() == 0 && item.getChecked()) {
// Create the dropdown and add data to it
final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
Library selectedLib = ((LibraryTree.Library) item.getData());
for (ArduinoLibraryVersion version1 : selectedLib.getVersions()) {
combo.add(version1.getVersion().toString());
}
ArduinoLibraryVersion displayVersion = selectedLib.getVersion();
if (displayVersion == null) {
displayVersion = selectedLib.getLatest();
selectedLib.setVersion(displayVersion);
item.setText(0, selectedLib.getName());
}
combo.select(combo.indexOf(displayVersion.getVersion().toString()));
// Compute the width for the editor
// Also, compute the column width, so that the dropdown fits
// Set the focus on the dropdown and set into the editor
combo.setFocus();
LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
// Add a listener to set the selected item back into the
// cell
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event1) {
LibraryTree.Library lib = (LibraryTree.Library) item.getData();
lib.setVersion(new VersionNumber(combo.getText()));
item.setText(1, lib.getVersionString());
item.setText(0, lib.getName());
// Item selected: end the editing session
combo.dispose();
}
});
}
}
});
}
Aggregations