Search in sources :

Example 11 with ITreeSelection

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));
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) URL(java.net.URL) HibernateSearchEnabledPropertyTester(org.jboss.tools.hibernate.search.property.testers.HibernateSearchEnabledPropertyTester) Test(org.junit.Test)

Example 12 with ITreeSelection

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;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ISelection(org.eclipse.jface.viewers.ISelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 13 with ITreeSelection

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;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) HashSet(java.util.HashSet)

Example 14 with ITreeSelection

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();
    }
}
Also used : RegisterModel(net.sourceforge.usbdm.peripherals.model.RegisterModel) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) BaseModel(net.sourceforge.usbdm.peripherals.model.BaseModel) PeripheralModel(net.sourceforge.usbdm.peripherals.model.PeripheralModel) FieldModel(net.sourceforge.usbdm.peripherals.model.FieldModel)

Example 15 with ITreeSelection

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));
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IPath(org.eclipse.core.runtime.IPath) ShowInContext(org.eclipse.ui.part.ShowInContext) ArrayList(java.util.ArrayList) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) Iterator(java.util.Iterator) AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IResource(org.eclipse.core.resources.IResource)

Aggregations

ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)56 TreePath (org.eclipse.jface.viewers.TreePath)17 ISelection (org.eclipse.jface.viewers.ISelection)16 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 ArrayList (java.util.ArrayList)7 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)7 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)7 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)5 IProject (org.eclipse.core.resources.IProject)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 Test (org.junit.Test)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)3 URL (java.net.URL)3 HashSet (java.util.HashSet)3