Search in sources :

Example 96 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof XSDSimpleTypeDefinition) {
            std = (XSDSimpleTypeDefinition) selection.getFirstElement();
        } else {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDSimpleTypeDefinition) {
                    std = (XSDSimpleTypeDefinition) (tPath.getSegment(i));
                }
            }
        }
        /**
         * totalDigits, fractionDigits, maxInclusive, maxExclusive, minInclusive, minExclusive
         */
        if (facetName.equals("pattern")) {
            // $NON-NLS-1$
            editPattern();
        } else if (facetName.equals("enumeration")) {
            // $NON-NLS-1$
            editEnumeration();
        } else if (facetName.equals("length")) {
            // $NON-NLS-1$
            editLength();
        } else if (facetName.equals("minLength")) {
            // $NON-NLS-1$
            editMinLength();
        } else if (facetName.equals("maxLength")) {
            // $NON-NLS-1$
            editMaxLength();
        } else if (facetName.equals("totalDigits")) {
            // $NON-NLS-1$
            editTotalDigits();
        } else if (facetName.equals("fractionDigits")) {
            // $NON-NLS-1$
            editFractionDigits();
        } else if (facetName.equals("maxInclusive")) {
            // $NON-NLS-1$
            editMaxInclusive();
        } else if (facetName.equals("maxExclusive")) {
            // $NON-NLS-1$
            editMaxExclusive();
        } else if (facetName.equals("minInclusive")) {
            // $NON-NLS-1$
            editMinInclusive();
        } else if (facetName.equals("minExclusive")) {
            // $NON-NLS-1$
            editMinExclusive();
        } else if (facetName.equals("whiteSpace")) {
            // $NON-NLS-1$
            editWhiteSpace();
        } else {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditFacetAction_ErrorMsg1, facetName));
            return Status.CANCEL_STATUS;
        }
        std.updateElement();
        page.getTreeViewer().refresh(true);
        page.markDirty();
        page.refresh();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditFacetAction_ErrorMsg2, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 97 with TreePath

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

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

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

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

the class KnownConfigurationsView method makeActions.

/**
 */
private void makeActions() {
    this.actionGroup = new ConfigurationsViewActionGroup(this, viewer);
    this.doubleAction = new Action() {

        public void run() {
            // TODO: make action dependent on having a connected console configuration!
            ISelection selection = viewer.getSelection();
            if (selection == null || selection.isEmpty()) {
                return;
            }
            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
            if (firstElement instanceof ConsoleConfiguration) {
                new EditConsoleConfiguration((ConsoleConfiguration) firstElement).run();
            } else if (firstElement instanceof BaseNode) {
                BaseNode node = (BaseNode) firstElement;
                ConsoleConfiguration consoleConfiguration = node.getConsoleConfiguration();
                if (consoleConfiguration.isSessionFactoryCreated()) {
                    String hql = node.getHQL();
                    // open HQL Editor
                    HibernateConsolePlugin.getDefault().openScratchHQLEditor(consoleConfiguration.getName(), hql);
                /**
                 * /
                 *						// execute query and show results in
                 *						// Hibernate Query result view - commented cause old version
                 *						if(StringHelper.isNotEmpty( hql )) {
                 *							try {
                 *								if (getSite() != null && getSite().getPage() != null) {
                 *									getSite().getPage().showView(QueryPageTabView.ID);
                 *								}
                 *							} catch (PartInitException e) {
                 *								HibernateConsolePlugin.getDefault().logErrorMessage("Can't show QueryPageTabView.", e);	//$NON-NLS-1$
                 *							}
                 *							consoleConfiguration.executeHQLQuery( hql );
                 *						}
                 *						/*
                 */
                }
            } else if (selection instanceof TreeSelection) {
                TreePath[] paths = ((TreeSelection) selection).getPaths();
                TreePath path = paths[0];
                Object last = path.getLastSegment();
                ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
                if (last instanceof IPersistentClass || (last instanceof IProperty && ((IProperty) last).classIsPropertyClass())) {
                    try {
                        OpenMappingAction.run(consoleConfig, path);
                    } catch (PartInitException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    } catch (JavaModelException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    } catch (FileNotFoundException e) {
                        // $NON-NLS-1$
                        HibernateConsolePlugin.getDefault().logErrorMessage("Can't find mapping file.", e);
                    }
                } else {
                    for (int i = 0; i < paths.length; i++) {
                        if (viewer.getExpandedState(paths[i])) {
                            viewer.collapseToLevel(paths[i], 1);
                        } else {
                            viewer.expandToLevel(paths[i], 1);
                        }
                    }
                }
            }
        }
    };
}
Also used : Action(org.eclipse.jface.action.Action) OpenMappingAction(org.hibernate.eclipse.console.actions.OpenMappingAction) JavaModelException(org.eclipse.jdt.core.JavaModelException) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) BaseNode(org.hibernate.console.node.BaseNode) FileNotFoundException(java.io.FileNotFoundException) 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) ISelection(org.eclipse.jface.viewers.ISelection) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) PartInitException(org.eclipse.ui.PartInitException)

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