Search in sources :

Example 26 with TreePath

use of org.eclipse.jface.viewers.TreePath 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 27 with TreePath

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

the class OneParentConfigPropertyTesterTest method testSameConfig.

@Test
public void testSameConfig() {
    ConsoleConfiguration consoleConfiguration = mock(ConsoleConfiguration.class);
    TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration });
    TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration });
    ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
    OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
    assertTrue(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 28 with TreePath

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

the class OpenQueryEditorAction method doRun.

protected boolean doRun(TreePath[] paths) {
    boolean showed = false;
    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i];
        ConsoleConfiguration config = (ConsoleConfiguration) path.getSegment(0);
        try {
            openQueryEditor(config, generateQuery(path));
            showed = true;
        } catch (Exception he) {
            HibernateConsolePlugin.getDefault().showError(null, HibernateConsoleMessages.OpenQueryEditorAction_exception_open_hql_editor, he);
        }
    }
    return showed;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) TreePath(org.eclipse.jface.viewers.TreePath)

Example 29 with TreePath

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

the class OpenSourceAction method run.

public void run() {
    IStructuredSelection sel = getStructuredSelection();
    if (!(sel instanceof TreeSelection)) {
        return;
    }
    TreePath[] paths = ((TreeSelection) sel).getPaths();
    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i];
        Object lastSegment = path.getLastSegment();
        IPersistentClass persClass = getPersistentClass(lastSegment);
        ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
        String fullyQualifiedName = null;
        if (lastSegment instanceof IProperty) {
            Object prevSegment = path.getParentPath().getLastSegment();
            if (prevSegment instanceof IProperty && ((IProperty) prevSegment).isComposite()) {
                fullyQualifiedName = ((IValue) ((IProperty) prevSegment).getValue()).getComponentClassName();
            }
        }
        if (fullyQualifiedName == null && persClass != null) {
            fullyQualifiedName = persClass.getClassName();
        }
        try {
            run(consoleConfig, lastSegment, fullyQualifiedName);
        } catch (JavaModelException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
        } catch (PartInitException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_open_source_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenSourceAction_cannot_find_source_file, e);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) FileNotFoundException(java.io.FileNotFoundException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) TreePath(org.eclipse.jface.viewers.TreePath) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 30 with TreePath

use of org.eclipse.jface.viewers.TreePath in project nebula.widgets.nattable by eclipse.

the class NavigationPart method postConstruct.

@PostConstruct
public void postConstruct(Composite parent) {
    final TreeViewer navTreeViewer = new TreeViewer(parent);
    final NavContentProvider contentProvider = new NavContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            Set<String> topLevelElements = new LinkedHashSet<>();
            String[] examplePaths = (String[]) inputElement;
            for (final String examplePath : examplePaths) {
                String parentPath = "";
                String absolutePath = "";
                // remove the package name for the tree structure
                String path = examplePath;
                if (examplePath.startsWith(INatExample.TUTORIAL_EXAMPLES_PREFIX)) {
                    path = examplePath.replace(INatExample.BASE_PATH, "");
                } else if (examplePath.startsWith(INatExample.CLASSIC_EXAMPLES_PREFIX)) {
                    path = examplePath.replace(INatExample.CLASSIC_BASE_PATH, "");
                } else if (examplePath.startsWith(E4_EXAMPLES_PREFIX)) {
                    path = examplePath.replace(E4_BASE_PATH, "");
                }
                final StringTokenizer tok = new StringTokenizer(path, "/");
                while (tok.hasMoreTokens()) {
                    final String pathElement = tok.nextToken();
                    if (parentPath.length() == 0) {
                        topLevelElements.add("/" + pathElement);
                    }
                    absolutePath += "/" + pathElement;
                    final Collection<String> children = getChildren(parentPath);
                    children.add(absolutePath);
                    parentPath = absolutePath;
                }
            }
            return topLevelElements.toArray();
        }
    };
    navTreeViewer.setContentProvider(contentProvider);
    navTreeViewer.setLabelProvider(new NavLabelProvider(contentProvider) {

        @Override
        public String getText(Object element) {
            String str = (String) element;
            if (!contentProvider.hasChildren(element)) {
                INatExample example = getExample(str);
                return example.getName();
            }
            int lastSlashIndex = str.lastIndexOf('/');
            if (lastSlashIndex < 0) {
                return format(str);
            } else {
                return format(str.substring(lastSlashIndex + 1));
            }
        }
    });
    navTreeViewer.setInput(getExamplePaths());
    navTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeSelection selection = (TreeSelection) event.getSelection();
            for (TreePath path : selection.getPaths()) {
                // check for item - if node expand/collapse, if child open
                if (contentProvider.hasChildren(path.getLastSegment().toString())) {
                    boolean expanded = navTreeViewer.getExpandedState(path);
                    navTreeViewer.setExpandedState(path, !expanded);
                } else {
                    openExampleInTab(path.getLastSegment().toString());
                }
            }
        }
    });
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    parent.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(navTreeViewer.getControl());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TreeViewer(org.eclipse.jface.viewers.TreeViewer) NavLabelProvider(org.eclipse.nebula.widgets.nattable.examples.runner.NavLabelProvider) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) StringTokenizer(java.util.StringTokenizer) GridLayout(org.eclipse.swt.layout.GridLayout) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) INatExample(org.eclipse.nebula.widgets.nattable.examples.INatExample) NavContentProvider(org.eclipse.nebula.widgets.nattable.examples.runner.NavContentProvider) PostConstruct(javax.annotation.PostConstruct)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5