use of org.eclipse.ui.dialogs.PatternFilter in project linuxtools by eclipse.
the class BrowserView method createPartControl.
@Override
public void createPartControl(Composite parent) {
PatternFilter filter = new PatternFilter();
FilteredTree filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
viewer = filteredTree.getViewer();
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
IHandlerService handlerService = getSite().getService(IHandlerService.class);
collapseHandler = new CollapseAllHandler(getViewer());
handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, collapseHandler);
refreshHandler = new RefreshHandler();
handlerService.activateHandler(RefreshHandler.COMMAND_ID, refreshHandler);
}
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) {
@SuppressWarnings("synthetic-access")
@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) {
item.setGrayed(false);
for (LibraryTree.Library child : ((LibraryTree.Category) item.getData()).getLibraries()) {
if (item.getChecked()) {
child.setVersion(child.getLatest());
} else {
child.setVersion(null);
}
}
for (TreeItem child : item.getItems()) {
child.setChecked(item.getChecked());
if (item.getChecked()) {
child.setText(1, ((LibraryTree.Library) child.getData()).getLatest());
} else {
child.setText(1, emptyString);
}
}
} else {
if (item.getChecked()) {
((LibraryTree.Library) item.getData()).setVersion(((LibraryTree.Library) item.getData()).getLatest());
item.setText(1, ((LibraryTree.Library) item.getData()).getLatest());
} else {
((LibraryTree.Library) item.getData()).setVersion(null);
item.setText(1, emptyString);
}
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);
for (VersionNumber version1 : ((LibraryTree.Library) item.getData()).getVersions()) {
combo.add(version1.toString());
}
// Select the previously selected item from the cell
combo.select(combo.indexOf(item.getText(1)));
// 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) item.getData()).setVersion(combo.getText());
item.setText(1, combo.getText());
// Item selected: end the editing session
combo.dispose();
}
});
}
}
});
}
use of org.eclipse.ui.dialogs.PatternFilter in project mylyn.docs by eclipse.
the class QuickOutlinePopupDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
patternFilter = new PatternFilter();
filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
int heightHint = (filteredTree.getViewer().getTree().getItemHeight() * 12) + Math.max(filteredTree.getFilterControl().getSize().y, 12);
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, heightHint).applyTo(filteredTree);
filteredTree.getViewer().setUseHashlookup(true);
filteredTree.getViewer().setContentProvider(new BaseWorkbenchContentProvider());
filteredTree.getViewer().setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
filteredTree.getViewer().setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
filteredTree.getViewer().getTree().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
handleSelection();
}
public void widgetSelected(SelectionEvent e) {
// nothing to do
}
});
// dispose when escape is pressed
filteredTree.getViewer().getTree().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.character == 0x1B) {
dispose();
}
}
public void keyReleased(KeyEvent e) {
}
});
// single mouse click causes selection
filteredTree.getViewer().getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
Tree tree = filteredTree.getViewer().getTree();
if ((tree.getSelectionCount() < 1) || (e.button != 1)) {
return;
}
// Selection is made in the selection changed listener
Object object = tree.getItem(new Point(e.x, e.y));
TreeItem selection = tree.getSelection()[0];
if (selection.equals(object)) {
handleSelection();
}
}
});
return filteredTree;
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class CommitViewerComparator method createFileSection.
private Section createFileSection(Composite container) {
Section filesSection = toolkit.createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
GridDataFactory.fillDefaults().grab(true, true).applyTo(filesSection);
Composite filesArea = toolkit.createComposite(filesSection);
filesSection.setClient(filesArea);
toolkit.paintBordersFor(filesArea);
GridLayoutFactory.fillDefaults().extendedMargins(2, 2, 2, 2).applyTo(filesArea);
ToolBar filesToolbar = new ToolBar(filesSection, SWT.FLAT);
filesSection.setTextClient(filesToolbar);
PatternFilter patternFilter = new PatternFilter() {
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
if (element instanceof CommitItem) {
CommitItem commitItem = (CommitItem) element;
return wordMatches(commitItem.path);
}
return super.isLeafMatch(viewer, element);
}
};
patternFilter.setIncludeLeadingWildcard(true);
FilteredCheckboxTree resourcesTreeComposite = new FilteredCheckboxTree(filesArea, toolkit, SWT.FULL_SELECTION, patternFilter) {
@Override
protected WorkbenchJob doCreateRefreshJob() {
// workaround for file filter not having an explicit change
// listener
WorkbenchJob filterJob = super.doCreateRefreshJob();
filterJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateFileSectionText();
}
});
}
}
});
return filterJob;
}
};
Tree resourcesTree = resourcesTreeComposite.getViewer().getTree();
resourcesTree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
resourcesTreeComposite.setLayoutData(GridDataFactory.fillDefaults().hint(600, 200).grab(true, true).create());
resourcesTree.addSelectionListener(new CommitItemSelectionListener());
resourcesTree.setHeaderVisible(true);
if (getPreferenceStore().getBoolean(UIPreferences.WARN_BEFORE_COMMITTING) && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT)) {
ignoreErrors = new Button(resourcesTreeComposite, SWT.CHECK);
ignoreErrors.setText(UIText.CommitDialog_IgnoreErrors);
ignoreErrors.setSelection(false);
ignoreErrors.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Button button = (Button) e.getSource();
boolean enable = button.getSelection();
updateMessage();
updateCommitButtons(enable);
}
});
}
TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
statCol.setText(UIText.CommitDialog_Status);
statCol.setWidth(150);
statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));
TreeColumn resourceCol = new TreeColumn(resourcesTree, SWT.LEFT);
resourceCol.setText(UIText.CommitDialog_Path);
resourceCol.setWidth(415);
resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));
filesViewer = resourcesTreeComposite.getCheckboxTreeViewer();
new TreeViewerColumn(filesViewer, statCol).setLabelProvider(createStatusLabelProvider());
new TreeViewerColumn(filesViewer, resourceCol).setLabelProvider(new CommitPathLabelProvider());
ColumnViewerToolTipSupport.enableFor(filesViewer);
filesViewer.setContentProvider(new CommitFileContentProvider());
filesViewer.setUseHashlookup(true);
IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
if (settings.get(SHOW_UNTRACKED_PREF) != null) {
// note, no matter how the dialog settings are, if
// the preferences force us to include untracked files
// we must show them
showUntracked = Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue() || getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
}
filesViewer.addFilter(new CommitItemFilter());
filesViewer.setInput(items.toArray());
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(createContextMenuListener());
filesViewer.getTree().setMenu(menuManager.createContextMenu(filesViewer.getTree()));
filesViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
updateFileSectionText();
}
});
showUntrackedItem = new ToolItem(filesToolbar, SWT.CHECK);
Image showUntrackedImage = UIIcons.UNTRACKED_FILE.createImage();
UIUtils.hookDisposal(showUntrackedItem, showUntrackedImage);
showUntrackedItem.setImage(showUntrackedImage);
showUntrackedItem.setToolTipText(UIText.CommitDialog_ShowUntrackedFiles);
showUntrackedItem.setSelection(showUntracked);
showUntrackedItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showUntracked = showUntrackedItem.getSelection();
filesViewer.refresh(true);
updateFileSectionText();
updateMessage();
}
});
ToolItem checkAllItem = new ToolItem(filesToolbar, SWT.PUSH);
Image checkImage = UIIcons.CHECK_ALL.createImage();
UIUtils.hookDisposal(checkAllItem, checkImage);
checkAllItem.setImage(checkImage);
checkAllItem.setToolTipText(UIText.CommitDialog_SelectAll);
checkAllItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filesViewer.setAllChecked(true);
updateFileSectionText();
updateMessage();
}
});
ToolItem uncheckAllItem = new ToolItem(filesToolbar, SWT.PUSH);
Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
uncheckAllItem.setImage(uncheckImage);
uncheckAllItem.setToolTipText(UIText.CommitDialog_DeselectAll);
uncheckAllItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filesViewer.setAllChecked(false);
updateFileSectionText();
updateMessage();
}
});
if (!allowToChangeSelection) {
amendingItem.setSelection(false);
amendingItem.setEnabled(false);
showUntrackedItem.setSelection(false);
showUntrackedItem.setEnabled(false);
checkAllItem.setEnabled(false);
uncheckAllItem.setEnabled(false);
filesViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (!event.getChecked())
filesViewer.setAllChecked(true);
updateFileSectionText();
}
});
filesViewer.setAllChecked(true);
} else {
final boolean includeUntracked = getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
for (CommitItem item : items) {
if (!preselectAll && !preselectedFiles.contains(item.path))
continue;
if (item.status == Status.ASSUME_UNCHANGED)
continue;
if (!includeUntracked && item.status == Status.UNTRACKED)
continue;
filesViewer.setChecked(item, true);
}
}
statCol.pack();
resourceCol.pack();
return filesSection;
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class GitSelectRepositoryPage method createControl.
@Override
public void createControl(Composite parent) {
Composite main = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).applyTo(main);
GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
// use a filtered tree
FilteredTree tree = new FilteredTree(main, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), true);
tv = tree.getViewer();
GridDataFactory.fillDefaults().grab(true, true).applyTo(tree);
tv.setContentProvider(new RepositoriesViewContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
Object[] elements = super.getElements(inputElement);
if (allowBare) {
return elements;
}
List<Object> result = new ArrayList<>();
for (Object element : elements) {
if (element instanceof RepositoryTreeNode) {
RepositoryTreeNode node = (RepositoryTreeNode) element;
if (node.getRepository() != null && !node.getRepository().isBare()) {
result.add(element);
}
}
}
bareMsg.setVisible(result.size() != elements.length);
return result.toArray();
}
// we never show children, only the Repository nodes
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
});
tv.setLabelProvider(new RepositoriesViewLabelProvider());
Composite tb = new Composite(main, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(tb);
GridDataFactory.fillDefaults().grab(false, true).applyTo(tb);
addRepo = new Button(tb, SWT.PUSH);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(addRepo);
addRepo.setText(UIText.GitSelectRepositoryPage_AddButton);
addRepo.setToolTipText(UIText.GitSelectRepositoryPage_AddTooltip);
addRepo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<String> configuredDirs = util.getConfiguredRepositories();
RepositorySearchWizard wizard = new RepositorySearchWizard(configuredDirs, allowBare);
WizardDialog dlg = new WizardDialog(getShell(), wizard);
if (dlg.open() == Window.OK && !wizard.getDirectories().isEmpty()) {
Set<String> dirs = wizard.getDirectories();
for (String dir : dirs) {
File gitDir = FileUtils.canonicalize(new File(dir));
GerritUtil.tryToAutoConfigureForGerrit(gitDir);
util.addConfiguredRepository(gitDir);
}
checkPage();
}
}
});
if (!allowBare) {
bareMsg = new Composite(main, SWT.NONE);
bareMsg.setLayout(new RowLayout());
bareMsg.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Label imageLabel = new Label(bareMsg, SWT.NONE);
imageLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
Label textLabel = new Label(bareMsg, SWT.WRAP);
textLabel.setText(UIText.GitSelectRepositoryPage_BareRepositoriesHidden);
bareMsg.setVisible(false);
}
tv.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
checkPage();
}
});
tv.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
checkPage();
if (isPageComplete())
getContainer().showPage(getNextPage());
}
});
tv.setInput(util.getConfiguredRepositories());
configChangeListener = new IPreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
Display display = tv.getControl().getDisplay();
display.asyncExec(() -> {
if (!tv.getControl().isDisposed()) {
refreshRepositoryList();
checkPage();
}
});
}
}
};
util.getPreferences().addPreferenceChangeListener(configChangeListener);
// we need to select at least a repository to become complete
setPageComplete(false);
Dialog.applyDialogFont(main);
setControl(main);
}
Aggregations