Search in sources :

Example 51 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.

the class HibernateSearchEnabledPropertyTester 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<ConsoleConfiguration> consoleConfigs = new HashSet<ConsoleConfiguration>();
    for (TreePath path : selection.getPaths()) {
        if (path.getFirstSegment() instanceof ConsoleConfiguration) {
            consoleConfigs.add((ConsoleConfiguration) path.getFirstSegment());
        } else {
            return false;
        }
    }
    for (ConsoleConfiguration consoleConfig : consoleConfigs) {
        boolean isHibernateSearch = false;
        URL[] classPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfig.getPreferences());
        for (URL url : classPathURLs) {
            if (url.getFile().contains("hibernate-search")) {
                isHibernateSearch = true;
                break;
            }
        }
        if (!isHibernateSearch) {
            return false;
        }
    }
    return true;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) TreePath(org.eclipse.jface.viewers.TreePath) URL(java.net.URL) HashSet(java.util.HashSet)

Example 52 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.

the class HibernateSearchEnabledPropertyTesterTest method allMustContainHibernateSearchLib.

@Test
public void allMustContainHibernateSearchLib() throws MalformedURLException {
    ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
    ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
    ConsoleConfigurationPreferences prefs1 = mock(ConsoleConfigurationPreferences.class);
    ConsoleConfigurationPreferences prefs2 = mock(ConsoleConfigurationPreferences.class);
    when(consoleConfiguration1.getPreferences()).thenReturn(prefs1);
    when(consoleConfiguration2.getPreferences()).thenReturn(prefs2);
    when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
    when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "something"), new URL("file", "", "dont-we-need") });
    TreePath treePath = new TreePath(new Object[] { consoleConfiguration1, consoleConfiguration2 });
    ITreeSelection receiver = new TreeSelection(treePath);
    HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
    assertFalse(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 53 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.

the class OneParentConfigPropertyTesterTest method testDifferentConfigs.

@Test
public void testDifferentConfigs() {
    ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
    ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
    TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration1 });
    TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration2 });
    ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
    OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
    assertFalse(propertyTester.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) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) OneParentConfigPropertyTester(org.jboss.tools.hibernate.search.property.testers.OneParentConfigPropertyTester) Test(org.junit.Test)

Example 54 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project ServiceStack.Java by ServiceStack.

the class SelectionTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if ("hasNonEmptyTextSelection".equals(property)) {
        if (!(receiver instanceof ITreeSelection)) {
            return false;
        }
        TreeSelection treeSelection = (TreeSelection) receiver;
        if (!(treeSelection.getFirstElement() instanceof ICompilationUnit)) {
            return false;
        }
        ICompilationUnit compilationUnit = (ICompilationUnit) treeSelection.getFirstElement();
        IResource resource = extractSelection(treeSelection);
        IProject project = resource.getProject();
        IImportDeclaration importDeclaration = compilationUnit.getImport("net.servicestack.client");
        if (importDeclaration == null) {
            return false;
        }
        IFile file = project.getFile(stripFirstDirectoryFromPath(compilationUnit.getPath()));
        InputStream contents = null;
        try {
            contents = file.getContents();
            InputStreamReader is = new InputStreamReader(contents);
            BufferedReader br = new BufferedReader(is);
            String read;
            try {
                for (int i = 0; i < 10; i++) {
                    String line = br.readLine();
                    if (line.trim().startsWith("/* Options:")) {
                        UpdateReferenceCurrentSelection.getInstance().UpdateReferenceFile = file;
                        return true;
                    }
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (contents == null) {
            return false;
        }
        System.out.println("File selected");
    }
    return true;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IImportDeclaration(org.eclipse.jdt.core.IImportDeclaration) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) CoreException(org.eclipse.core.runtime.CoreException) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) BufferedReader(java.io.BufferedReader) IResource(org.eclipse.core.resources.IResource)

Example 55 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project mechanoid by robotoworks.

the class MechanoidWizard method extractSelectionInfo.

private void extractSelectionInfo() {
    if (mSelection.isEmpty()) {
        return;
    }
    if (mSelection instanceof ITreeSelection) {
        ITreeSelection treeSelection = (ITreeSelection) mSelection;
        TreePath[] paths = treeSelection.getPaths();
        if (paths.length > 0) {
            for (int i = 0; i < paths[0].getSegmentCount(); i++) {
                Object segment = paths[0].getSegment(i);
                if (segment instanceof IJavaProject) {
                    mSelectedJavaProject = (IJavaProject) segment;
                    mSelectedProject = mSelectedJavaProject.getProject();
                }
                if (segment instanceof IFolder) {
                    mSelectedFolder = (IFolder) segment;
                }
                if (segment instanceof IProject) {
                    mSelectedProject = (IProject) segment;
                }
            }
        }
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IJavaProject(org.eclipse.jdt.core.IJavaProject) TreePath(org.eclipse.jface.viewers.TreePath) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

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