use of org.eclipse.jface.viewers.ITreeContentProvider in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method computeSaveables.
/**
* helper to compute the saveables for which elements are part of the tree.
* Must be called from a synchronized method.
*
* @return the saveables
*/
private Saveable[] computeSaveables() {
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
Object viewerInput = viewer.getInput();
List result = new ArrayList();
Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
SaveablesProvider[] saveablesProviders = getSaveablesProviders();
for (int i = 0; i < saveablesProviders.length; i++) {
SaveablesProvider saveablesProvider = saveablesProviders[i];
Saveable[] saveables = saveablesProvider.getSaveables();
for (int j = 0; j < saveables.length; j++) {
Saveable saveable = saveables[j];
Object[] elements = saveablesProvider.getElements(saveable);
// the saveable is added to the result if at least one of the
// elements representing the saveable appears in the tree, i.e.
// if its parent chain leads to a root node.
boolean foundRoot = false;
for (int k = 0; !foundRoot && k < elements.length; k++) {
Object element = elements[k];
if (roots.contains(element)) {
result.add(saveable);
foundRoot = true;
} else if (isTreepathContentProvider) {
ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
TreePath[] parentPaths = treePathContentProvider.getParents(element);
for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
TreePath parentPath = parentPaths[l];
for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
if (roots.contains(parentPath.getSegment(m))) {
result.add(saveable);
foundRoot = true;
}
}
}
} else {
while (!foundRoot && element != null) {
if (roots.contains(element)) {
// found a parent chain leading to a root. The
// saveable is part of the tree.
result.add(saveable);
foundRoot = true;
} else {
element = contentProvider.getParent(element);
}
}
}
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project polymap4-core by Polymap4.
the class TreeViewerFrameSource method getParentFrame.
/**
* Returns the parent frame, or <code>null</code> if there is no parent frame.
*
* @param flags a bit-wise OR of the frame source flag constants
* @return the parent frame, or <code>null</code>
*/
protected Frame getParentFrame(int flags) {
Object input = viewer.getInput();
ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
Object parent = provider.getParent(input);
if (parent == null)
return null;
TreeFrame frame = createFrame(parent);
if ((flags & IFrameSource.FULL_CONTEXT) != 0) {
frame.setSelection(viewer.getSelection());
// include current input in expanded set
Object[] expanded = viewer.getExpandedElements();
Object[] newExpanded = new Object[expanded.length + 1];
System.arraycopy(expanded, 0, newExpanded, 0, expanded.length);
newExpanded[newExpanded.length - 1] = input;
frame.setExpandedElements(newExpanded);
}
return frame;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project tdq-studio-se by Talend.
the class ExplainExecution method displayResults.
private void displayResults(final ExplainNode node, final Query query) {
getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
ResultsTab resultsTab = allocateResultsTab(query);
try {
Composite composite = resultsTab.getParent();
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 2;
gLayout.marginLeft = 0;
gLayout.horizontalSpacing = 0;
gLayout.verticalSpacing = 0;
gLayout.marginWidth = 0;
gLayout.marginHeight = 0;
composite.setLayout(gLayout);
composite.setData("parenttab", resultsTab.getTabItem());
Composite pp = new Composite(composite, 0);
pp.setLayout(new FillLayout());
pp.setLayoutData(new GridData(1808));
TableTreeViewer tv = new TableTreeViewer(pp, 0x10800);
Table table = tv.getTableTree().getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tc = new TableColumn(table, 0);
tc.setText("");
tc = new TableColumn(table, 0);
tc.setText("Cost");
tc = new TableColumn(table, 0);
tc.setText("Cardinality");
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(6, 150, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
tableLayout.addColumnData(new ColumnWeightData(1, 50, true));
table.setLayout(tableLayout);
tv.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public Object[] getChildren(Object parentElement) {
return ((ExplainNode) parentElement).getChildren();
}
public Object[] getElements(Object inputElement) {
ExplainNode nd = (ExplainNode) inputElement;
return nd.getChildren();
}
public Object getParent(Object element) {
return ((ExplainNode) element).getParent();
}
public boolean hasChildren(Object element) {
return ((ExplainNode) element).getChildren().length > 0;
}
public void inputChanged(Viewer viewer1, Object obj, Object obj1) {
}
});
tv.setLabelProvider(new TreeLabelProvider() {
});
tv.setInput(node);
tv.refresh();
tv.expandAll();
for (int i = 0; i < table.getColumnCount(); i++) table.getColumn(i).pack();
final ExplainPlanActionGroup actionGroup = new ExplainPlanActionGroup(tv, node.getChildren()[0]);
MenuManager menuManager = new MenuManager("ExplainPlanContextMenu");
menuManager.setRemoveAllWhenShown(true);
org.eclipse.swt.widgets.Menu contextMenu = menuManager.createContextMenu(table);
tv.getControl().setMenu(contextMenu);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
actionGroup.fillContextMenu(manager);
}
});
composite.layout();
composite.redraw();
} catch (Exception e) {
if (resultsTab != null) {
Composite composite = resultsTab.getParent();
String message = e.getMessage();
Label errorLabel = new Label(composite, 4);
errorLabel.setText(message);
errorLabel.setLayoutData(new GridData(4, 128, true, false));
}
SQLExplorerPlugin.error("Error creating explain tab", e);
}
}
});
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class BranchSelectionDialog method createCustomArea.
@Override
protected Control createCustomArea(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));
if (multiMode) {
fTree = new FilteredCheckboxTree(area, 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;
}
};
CachedCheckboxTreeViewer viewer = fTree.getCheckboxTreeViewer();
GridDataFactory.fillDefaults().grab(true, true).applyTo(fTree);
viewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer actViewer, Object oldInput, Object newInput) {
// nothing
}
@Override
public void dispose() {
// nothing
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getElements(Object inputElement) {
return ((List) inputElement).toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
});
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
checkPage();
}
});
viewer.setLabelProvider(new GitLabelProvider());
viewer.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
viewer.setInput(nodes);
preselectBranchMultiMode(nodes, fTree);
} else {
branchesList = new TableViewer(area, this.style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).applyTo(branchesList.getControl());
branchesList.setContentProvider(ArrayContentProvider.getInstance());
branchesList.setLabelProvider(new GitLabelProvider());
branchesList.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
branchesList.setInput(nodes);
preselectBranchSingleMode(nodes, branchesList);
branchesList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
checkPage();
}
});
branchesList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
buttonPressed(OK);
}
});
}
return area;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class GitSynchronizeWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
for (IProject project : ROOT.getProjects()) {
RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
if (repositoryMapping == null)
continue;
Repository repo = repositoryMapping.getRepository();
Set<IProject> projects = resources.get(repo);
if (projects == null) {
projects = new HashSet<>();
resources.put(repo, projects);
}
projects.add(project);
}
treeViewer = new TreeViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
treeViewer.getTree().setLinesVisible(true);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TreeViewerColumn projectsColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
projectsColumn.getColumn().setText(UIText.GitBranchSynchronizeWizardPage_repository);
projectsColumn.getColumn().setImage(repositoryImage);
projectsColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Repository) {
Repository repo = (Repository) element;
// $NON-NLS-1$
String descr = "";
try {
// $NON-NLS-1$ //$NON-NLS-2$
descr += " [" + repo.getBranch() + "]";
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
}
Color decorationsColor = JFaceResources.getColorRegistry().get(JFacePreferences.DECORATIONS_COLOR);
String repoName = repo.getWorkTree().getName();
int repoNameLen = repoName.length();
StyleRange styleRange = new StyleRange(repoNameLen, repoNameLen + descr.length(), decorationsColor, null);
cell.setImage(repositoryImage);
cell.setText(repoName + descr);
cell.setStyleRanges(new StyleRange[] { styleRange });
}
super.update(cell);
}
});
TreeViewerColumn dstColumn = new TreeViewerColumn(treeViewer, SWT.LEAD);
dstColumn.getColumn().setText(UIText.GitBranchSynchronizeWizardPage_destination);
dstColumn.getColumn().setImage(branchImage);
dstColumn.getColumn().setWidth(200);
final ComboBoxCellEditor branchesEditor = new ComboBoxCellEditor(treeViewer.getTree(), new String[0]);
branchesEditor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION);
((CCombo) branchesEditor.getControl()).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CCombo combo = (CCombo) e.widget;
TreeSelection sel = (TreeSelection) treeViewer.getSelection();
int selectedIdx = combo.getSelectionIndex();
Repository repo = (Repository) sel.getFirstElement();
if (selectedIdx != -1) {
selectedBranches.put(repo, combo.getItem(selectedIdx));
setPageComplete(true);
} else {
selectedBranches.put(repo, null);
setPageComplete(false);
}
}
});
dstColumn.setEditingSupport(new EditingSupport(treeViewer) {
@Override
protected void setValue(Object element, Object value) {
int intValue = ((Integer) value).intValue();
if (intValue == -1)
return;
CCombo combo = (CCombo) branchesEditor.getControl();
String branch = combo.getItem(intValue);
selectedBranches.put((Repository) element, branch);
treeViewer.refresh(element, true);
validatePage();
}
@Override
protected Object getValue(Object element) {
String branch = selectedBranches.get(element);
CCombo combo = (CCombo) branchesEditor.getControl();
int index = branch == null ? 0 : combo.indexOf(branch);
return Integer.valueOf(index);
}
@Override
protected CellEditor getCellEditor(Object element) {
Repository repo = (Repository) element;
List<String> refs = new LinkedList<>(repo.getAllRefs().keySet());
List<Ref> additionalRefs;
try {
additionalRefs = repo.getRefDatabase().getAdditionalRefs();
} catch (IOException e) {
additionalRefs = null;
}
if (additionalRefs != null)
for (Ref ref : additionalRefs) refs.add(ref.getName());
Collections.sort(refs, CommonUtils.STRING_ASCENDING_COMPARATOR);
branchesEditor.setItems(refs.toArray(new String[refs.size()]));
return branchesEditor;
}
@Override
protected boolean canEdit(Object element) {
return true;
}
});
dstColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String branch = selectedBranches.get(element);
// $NON-NLS-1$
return branch == null ? "" : branch;
}
});
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// nothing to do
}
@Override
public void dispose() {
// nothing to do
}
@Override
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
});
List<Repository> repositoriesList = new ArrayList<>(resources.keySet());
Collections.sort(repositoriesList, new Comparator<Repository>() {
@Override
public int compare(Repository o1, Repository o2) {
String name1 = o1.getWorkTree().getName();
String name2 = o2.getWorkTree().getName();
return name1.compareToIgnoreCase(name2);
}
});
treeViewer.setInput(repositoriesList.toArray(new Repository[repositoriesList.size()]));
projectsColumn.getColumn().pack();
Composite buttonsComposite = new Composite(composite, SWT.NONE);
layout = new GridLayout(4, false);
layout.numColumns = 1;
layout.marginWidth = 0;
layout.marginHeight = 0;
buttonsComposite.setLayout(layout);
buttonsComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
final Button fetchChanges = new Button(buttonsComposite, SWT.CHECK);
fetchChanges.setText(UIText.GitBranchSynchronizeWizardPage_fetchChangesFromRemote);
fetchChanges.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
forceFetch = fetchChanges.getSelection();
}
});
fetchChanges.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
fetchChanges.setSelection(Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.SYNC_VIEW_FETCH_BEFORE_LAUNCH));
final Button includeLocal = new Button(buttonsComposite, SWT.CHECK);
includeLocal.setText(UIText.GitBranchSynchronizeWizardPage_includeUncommitedChanges);
includeLocal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
shouldIncludeLocal = includeLocal.getSelection();
}
});
includeLocal.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Dialog.applyDialogFont(composite);
setPageComplete(false);
setControl(composite);
}
Aggregations