use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTesterTest method containsHibernateSearchLib.
@Test
public void containsHibernateSearchLib() throws MalformedURLException {
ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
ConsoleConfigurationPreferences prefs = mock(ConsoleConfigurationPreferences.class);
when(consoleConfiguration.getPreferences()).thenReturn(prefs);
when(prefs.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
TreePath treePath = new TreePath(new Object[] { consoleConfiguration });
ITreeSelection receiver = new TreeSelection(treePath);
HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
assertTrue(tester.test(receiver, "doesn't matter", null, null));
}
use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class IndexRebuildHandler method execute.
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveMenuSelection(event);
if (sel.isEmpty()) {
return null;
}
ITreeSelection selection = (ITreeSelection) sel;
if (selection.getFirstElement() instanceof ConsoleConfiguration) {
indexRebuildForConfiguration(selection.iterator());
}
if (selection.getFirstElement() instanceof IPersistentClass) {
indexRebuildForPersistentClass((ConsoleConfiguration) selection.getPaths()[0].getFirstSegment(), selection.iterator());
}
return null;
}
use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof ITreeSelection)) {
return false;
}
ITreeSelection selection = (ITreeSelection) receiver;
Set<Object> consoleConfigs = new HashSet<Object>();
for (TreePath path : selection.getPaths()) {
consoleConfigs.add(path.getFirstSegment());
}
return consoleConfigs.size() == 1;
}
use of org.eclipse.jface.viewers.ITreeSelection in project usbdm-eclipse-plugins by podonoghue.
the class PeripheralsInformationPanel method selectionChanged.
/**
* Handles changes in selection of peripheral, register or field in tree view
*
* Updates description in infoPanel
* Attaches change listener to selected element
*
* @param event
*/
public void selectionChanged(SelectionChangedEvent event) {
Object source = event.getSource();
// System.err.println("PeripheralsInformationPanel.selectionChanged(), source = " + source.getClass());
if (source == fPeripheralsTreeViewer) {
ITreeSelection selection = (ITreeSelection) fPeripheralsTreeViewer.getSelection();
Object uModel = selection.getFirstElement();
// Detach from current peripheral
if (fPeripheralModel != null) {
fPeripheralModel.removeListener(this);
fPeripheralModel = null;
}
if ((uModel == null) || !(uModel instanceof BaseModel)) {
fCurrentModel = null;
updateContent();
return;
}
// Save model element to get values/description from
fCurrentModel = (BaseModel) uModel;
// Find peripheral that owns selected model
BaseModel model = fCurrentModel;
if (model instanceof FieldModel) {
// System.err.println("PeripheralsInformationPanel.selectionChanged(), traversing field = " + model);
model = model.getParent();
}
if (model instanceof RegisterModel) {
// System.err.println("PeripheralsInformationPanel.selectionChanged(), traversing register = " + model);
model = model.getParent();
}
if (model instanceof PeripheralModel) {
// Attach listener to peripheral
fPeripheralModel = (PeripheralModel) model;
fPeripheralModel.addListener(this);
// System.err.println("PeripheralsInformationPanel.selectionChanged(), listening to = " + model);
}
// else {
// System.err.println("PeripheralsInformationPanel.selectionChanged(), ignoring = " + model);
// System.err.println("PeripheralsInformationPanel.selectionChanged(), ignoring = " + model.getClass());
// }
updateContent();
}
}
use of org.eclipse.jface.viewers.ITreeSelection in project egit by eclipse.
the class CompareTreeView method getShowInContext.
/*
* @see org.eclipse.ui.part.IShowInSource#getShowInContext()
* @since 2.1
*/
@Override
public ShowInContext getShowInContext() {
IPath repoPath = getRepositoryPath();
ITreeSelection selection = (ITreeSelection) tree.getSelection();
List<IResource> resources = new ArrayList<>();
for (Iterator it = selection.iterator(); it.hasNext(); ) {
Object obj = it.next();
if (obj instanceof IResource)
resources.add((IResource) obj);
else if (obj instanceof PathNode && repoPath != null) {
PathNode pathNode = (PathNode) obj;
IResource resource = ResourceUtil.getResourceForLocation(repoPath.append(pathNode.getRepoRelativePath()), false);
if (resource != null)
resources.add(resource);
}
}
return new ShowInContext(null, new StructuredSelection(resources));
}
Aggregations