use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class SourceBranchPage method createControl.
@Override
public void createControl(final Composite parent) {
final Composite panel = new Composite(parent, SWT.NULL);
final GridLayout layout = new GridLayout();
layout.numColumns = 1;
panel.setLayout(layout);
label = new Label(panel, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
FilteredCheckboxTree fTree = new FilteredCheckboxTree(panel, null, SWT.NONE, new PatternFilter()) {
/*
* Overridden to check page when refreshing is done.
*/
@Override
protected WorkbenchJob doCreateRefreshJob() {
WorkbenchJob refreshJob = super.doCreateRefreshJob();
refreshJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
checkPage();
}
});
}
}
});
return refreshJob;
}
};
refsViewer = fTree.getCheckboxTreeViewer();
ITreeContentProvider provider = new ITreeContentProvider() {
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// nothing
}
@Override
public void dispose() {
// nothing
}
@Override
public Object[] getElements(Object input) {
return ((List) input).toArray();
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
};
refsViewer.setContentProvider(provider);
refsViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (((Ref) element).getName().startsWith(Constants.R_HEADS))
return ((Ref) element).getName().substring(Constants.R_HEADS.length());
return ((Ref) element).getName();
}
@Override
public Image getImage(Object element) {
return RepositoryTreeNodeType.REF.getIcon();
}
});
refsViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
checkPage();
}
});
final Composite bPanel = new Composite(panel, SWT.NONE);
bPanel.setLayout(new RowLayout());
selectB = new Button(bPanel, SWT.PUSH);
selectB.setText(UIText.SourceBranchPage_selectAll);
selectB.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refsViewer.setAllChecked(true);
checkPage();
}
});
unselectB = new Button(bPanel, SWT.PUSH);
unselectB.setText(UIText.SourceBranchPage_selectNone);
unselectB.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refsViewer.setAllChecked(false);
checkPage();
}
});
bPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Dialog.applyDialogFont(panel);
setControl(panel);
checkPage();
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class GitProjectsImportPage method createProjectsList.
/**
* Create the checkbox list for the found projects.
*
* @param workArea
*/
private void createProjectsList(Composite workArea) {
Label title = new Label(workArea, SWT.NONE);
title.setText(UIText.WizardProjectsImportPage_ProjectsListTitle);
Composite listComposite = new Composite(workArea, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.makeColumnsEqualWidth = false;
listComposite.setLayout(layout);
listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
PatternFilter filter = new PatternFilter() {
@Override
public boolean isElementVisible(Viewer viewer, Object element) {
if (getCheckedProjects().contains(element))
return true;
if (element instanceof ProjectRecord) {
ProjectRecord p = (ProjectRecord) element;
if (wordMatches(p.getProjectName()))
return true;
String projectPath = p.getProjectSystemFile().getParent();
if (projectPath.startsWith(lastPath)) {
String distinctPath = projectPath.substring(lastPath.length());
return wordMatches(distinctPath);
} else {
return wordMatches(projectPath);
}
}
return false;
}
};
filter.setIncludeLeadingWildcard(true);
FilteredCheckboxTree filteredTree = new FilteredCheckboxTree(listComposite, null, SWT.NONE, filter);
filteredTree.setInitialText(UIText.WizardProjectsImportPage_filterText);
projectsList = filteredTree.getCheckboxTreeViewer();
GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
projectsList.getControl().setLayoutData(listData);
projectsList.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
ProjectRecord element = (ProjectRecord) event.getElement();
if (isProjectInWorkspace(element.getProjectName())) {
projectsList.setChecked(element, false);
}
enableSelectAllButtons();
}
});
// a bug in the CachedCheckboxTreeView requires us to not return null
final Object[] children = new Object[0];
projectsList.setContentProvider(new ITreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
return children;
}
@Override
public Object[] getElements(Object inputElement) {
return selectedProjects;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public void dispose() {
// ignore
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
});
projectsList.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
checkPageComplete();
}
});
projectsList.setLabelProvider(new ProjectLabelProvider());
projectsList.setInput(this);
projectsList.setComparator(new ViewerComparator());
createSelectionButtons(listComposite);
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class FilteredBranchesWidget method create.
Control create(Composite parent) {
Composite area = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(area);
area.setLayout(new GridLayout(1, false));
PatternFilter filter = new PatternFilter() {
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
TreeViewer treeViewer = (TreeViewer) viewer;
int numberOfColumns = treeViewer.getTree().getColumnCount();
boolean isMatch = false;
for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
ColumnLabelProvider labelProvider = (ColumnLabelProvider) treeViewer.getLabelProvider(columnIndex);
String labelText = labelProvider.getText(element);
isMatch |= wordMatches(labelText);
}
return isMatch;
}
};
filter.setIncludeLeadingWildcard(true);
final FilteredTree tree = new FilteredTree(area, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true);
tree.setQuickSelectionMode(true);
branchesViewer = tree.getViewer();
branchesViewer.getTree().setLinesVisible(false);
branchesViewer.getTree().setHeaderVisible(true);
comparator = new BranchComparator();
branchesViewer.setComparator(comparator);
DecoratedBranchLabelProvider nameLabelProvider = new DecoratedBranchLabelProvider(gfRepo.getRepository(), prefix);
TreeColumn nameColumn = createColumn(UIText.BranchSelectionTree_NameColumn, branchesViewer, nameLabelProvider);
TreeColumn idColumn = createColumn(UIText.BranchSelectionTree_IdColumn, branchesViewer, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Ref) {
ObjectId objectId = ((Ref) element).getObjectId();
if (objectId == null) {
// $NON-NLS-1$
return "";
}
return objectId.abbreviate(7).name();
}
return super.getText(element);
}
});
ColumnLabelProvider dateLabelProvider = new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Ref) {
String name = ((Ref) element).getName().substring(Constants.R_HEADS.length());
RevCommit revCommit = gfRepo.findHead(name);
if (revCommit == null) {
// $NON-NLS-1$
return "";
}
return getDateFormatter().formatDate(revCommit.getCommitterIdent());
}
return super.getText(element);
}
};
TreeColumn dateColumn = createColumn(UIText.FilteredBranchesWidget_lastModified, branchesViewer, dateLabelProvider);
setSortedColumn(dateColumn, dateLabelProvider);
TreeColumn msgColumn = createColumn(UIText.BranchSelectionTree_MessageColumn, branchesViewer, new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Ref) {
String name = ((Ref) element).getName().substring(Constants.R_HEADS.length());
RevCommit revCommit = gfRepo.findHead(name);
if (revCommit == null) {
// $NON-NLS-1$
return "";
}
return revCommit.getShortMessage();
}
return super.getText(element);
}
});
GridDataFactory.fillDefaults().grab(true, true).applyTo(branchesViewer.getControl());
branchesViewer.setContentProvider(new BranchListContentProvider());
branchesViewer.setInput(refs);
// Layout tree for maximum width of message column
TreeColumnLayout layout = new TreeColumnLayout();
nameColumn.pack();
layout.setColumnData(nameColumn, new ColumnWeightData(0, nameColumn.getWidth()));
idColumn.pack();
layout.setColumnData(idColumn, new ColumnWeightData(0, idColumn.getWidth()));
dateColumn.pack();
layout.setColumnData(dateColumn, new ColumnWeightData(0, dateColumn.getWidth()));
layout.setColumnData(msgColumn, new ColumnWeightData(100));
branchesViewer.getTree().getParent().setLayout(layout);
branchesViewer.addFilter(createFilter());
return area;
}
use of org.eclipse.ui.dialogs.PatternFilter in project egit by eclipse.
the class ReflogView method createPartControl.
@Override
public void createPartControl(Composite parent) {
dateFormatter = PreferenceBasedDateFormatter.create();
GridLayoutFactory.fillDefaults().applyTo(parent);
toolkit = new FormToolkit(parent.getDisplay());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
form = toolkit.createForm(parent);
Image repoImage = UIIcons.REPOSITORY.createImage();
UIUtils.hookDisposal(form, repoImage);
Image commitImage = UIIcons.CHANGESET.createImage();
UIUtils.hookDisposal(form, commitImage);
form.setImage(repoImage);
form.setText(UIText.StagingView_NoSelectionTitle);
GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
toolkit.decorateFormHeading(form);
GridLayoutFactory.fillDefaults().applyTo(form.getBody());
Composite tableComposite = toolkit.createComposite(form.getBody());
tableComposite.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
final TreeColumnLayout layout = new TreeColumnLayout();
FilteredTree filteredTree = new FilteredTree(tableComposite, SWT.NONE | SWT.BORDER | SWT.FULL_SELECTION, new PatternFilter(), true) {
@Override
protected void createControl(Composite composite, int treeStyle) {
super.createControl(composite, treeStyle);
treeComposite.setLayout(layout);
}
};
toolkit.adapt(filteredTree);
refLogTableTreeViewer = filteredTree.getViewer();
refLogTableTreeViewer.getTree().setLinesVisible(true);
refLogTableTreeViewer.getTree().setHeaderVisible(true);
refLogTableTreeViewer.setContentProvider(new ReflogViewContentProvider());
ColumnViewerToolTipSupport.enableFor(refLogTableTreeViewer);
TreeViewerColumn toColumn = createColumn(layout, UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
toColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().abbreviate(7).name();
}
return null;
}
@Override
public String getToolTipText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().name();
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof ReflogEntry) {
return commitImage;
}
return null;
}
});
TreeViewerColumn commitMessageColumn = createColumn(layout, UIText.ReflogView_CommitMessageColumnHeader, 40, SWT.LEFT);
commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
RevCommit c = getCommit(entry);
// $NON-NLS-1$
return c == null ? "" : c.getShortMessage();
} else if (element instanceof IWorkbenchAdapter) {
return ((IWorkbenchAdapter) element).getLabel(element);
}
return null;
}
private RevCommit getCommit(final ReflogEntry entry) {
try (RevWalk walk = new RevWalk(getRepository())) {
walk.setRetainBody(true);
return walk.parseCommit(entry.getNewId());
} catch (IOException ignored) {
// ignore
return null;
}
}
});
TreeViewerColumn dateColumn = createColumn(layout, UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
dateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
final PersonIdent who = entry.getWho();
return dateFormatter.formatDate(who);
}
return null;
}
@Override
public Image getImage(Object element) {
return null;
}
});
TreeViewerColumn messageColumn = createColumn(layout, UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
messageColumn.setLabelProvider(new ColumnLabelProvider() {
private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getComment();
}
return null;
}
@Override
public Image getImage(Object element) {
if (!(element instanceof ReflogEntry)) {
return null;
}
String comment = ((ReflogEntry) element).getComment();
if (// $NON-NLS-1$ //$NON-NLS-2$
comment.startsWith("commit:") || comment.startsWith("commit (initial):"))
return (Image) resourceManager.get(UIIcons.COMMIT);
if (// $NON-NLS-1$
comment.startsWith("commit (amend):"))
return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
if (// $NON-NLS-1$
comment.startsWith("pull"))
return (Image) resourceManager.get(UIIcons.PULL);
if (// $NON-NLS-1$
comment.startsWith("clone"))
return (Image) resourceManager.get(UIIcons.CLONEGIT);
if (// $NON-NLS-1$
comment.startsWith("rebase"))
return (Image) resourceManager.get(UIIcons.REBASE);
if (// $NON-NLS-1$
comment.startsWith("merge"))
return (Image) resourceManager.get(UIIcons.MERGE);
if (// $NON-NLS-1$
comment.startsWith("fetch"))
return (Image) resourceManager.get(UIIcons.FETCH);
if (// $NON-NLS-1$
comment.startsWith("branch"))
return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
if (// $NON-NLS-1$
comment.startsWith("checkout"))
return (Image) resourceManager.get(UIIcons.CHECKOUT);
return null;
}
@Override
public void dispose() {
resourceManager.dispose();
super.dispose();
}
});
new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection sel, boolean activate) {
handleOpen(sel, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
if (selection.isEmpty())
return;
Repository repo = getRepository();
if (repo == null)
return;
try (RevWalk walk = new RevWalk(repo)) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
ReflogEntry entry = (ReflogEntry) element;
ObjectId id = entry.getNewId();
if (id == null || id.equals(ObjectId.zeroId()))
id = entry.getOldId();
if (id != null && !id.equals(ObjectId.zeroId()))
CommitEditor.openQuiet(new RepositoryCommit(repo, walk.parseCommit(id)), activateOnOpen);
}
} catch (IOException e) {
Activator.logError(UIText.ReflogView_ErrorOnOpenCommit, e);
}
}
};
uiPrefsListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
dateFormatter = PreferenceBasedDateFormatter.create();
refLogTableTreeViewer.refresh();
}
}
};
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
selectionChangedListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
if (input instanceof IFileEditorInput)
reactOnSelection(new StructuredSelection(((IFileEditorInput) input).getFile()));
} else
reactOnSelection(selection);
}
};
IWorkbenchPartSite site = getSite();
ISelectionService service = CommonUtils.getService(site, ISelectionService.class);
service.addPostSelectionListener(selectionChangedListener);
// Use current selection to populate reflog view
UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
site.setSelectionProvider(new RepositorySelectionProvider(refLogTableTreeViewer, () -> getRepository()));
addRefsChangedListener = Repository.getGlobalListenerList().addRefsChangedListener(this);
// Toolbar
IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> getRepository(), repo -> reactOnSelection(new StructuredSelection(repo)));
toolbar.add(switchRepositoriesAction);
getViewSite().getActionBars().updateActionBars();
// register context menu
MenuManager menuManager = new MenuManager();
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Tree tree = refLogTableTreeViewer.getTree();
tree.setMenu(menuManager.createContextMenu(tree));
MenuManager resetManager = ResetMenu.createMenu(getSite());
menuManager.add(resetManager);
getSite().registerContextMenu(POPUP_MENU_ID, menuManager, refLogTableTreeViewer);
}
use of org.eclipse.ui.dialogs.PatternFilter in project bndtools by bndtools.
the class RunDescriptorTargetLocationPage method getProjectTreeFilters.
private ViewerFilter[] getProjectTreeFilters() {
PatternFilter bndrunFilter = new PatternFilter() {
@Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
return element instanceof IFile && FILE_EXTENSION.equals(((IFile) element).getFileExtension());
}
@Override
public boolean isElementSelectable(Object element) {
return element instanceof IFile;
}
};
bndrunFilter.setPattern("*");
return new ViewerFilter[] { bndrunFilter };
}
Aggregations