Search in sources :

Example 1 with BaseNode

use of org.hibernate.console.node.BaseNode 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)

Example 2 with BaseNode

use of org.hibernate.console.node.BaseNode in project jbosstools-hibernate by jbosstools.

the class HQLScratchpadAction method generateQuery.

/* (non-Javadoc)
	 * @see org.hibernate.eclipse.console.actions.OpenQueryEditorAction#generateQuery(org.eclipse.jface.viewers.TreePath)
	 */
protected String generateQuery(TreePath path) {
    Object node = path.getLastSegment();
    if (node instanceof IPersistentClass) {
        String name = ((IPersistentClass) node).getEntityName();
        // $NON-NLS-1$
        return "from " + name;
    } else if (node instanceof IProperty) {
        String prName = ((IProperty) node).getName();
        IPersistentClass pClass = ((IProperty) node).getPersistentClass();
        // $NON-NLS-1$
        String enName = "";
        if (pClass != null) {
            enName = pClass.getEntityName();
            enName = enName.substring(enName.lastIndexOf('.') + 1);
        } else {
            // Generate script for Component property
            for (int i = path.getSegmentCount() - 2; i > 0; i--) {
                if (path.getSegment(i) instanceof IPersistentClass) {
                    enName = ((IPersistentClass) path.getSegment(i)).getEntityName();
                    enName = enName.substring(enName.lastIndexOf('.') + 1);
                } else if (path.getSegment(i) instanceof IProperty) {
                    // $NON-NLS-1$
                    prName = ((IProperty) path.getSegment(i)).getName() + "." + prName;
                }
            }
        }
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        return "select o." + prName + " from " + enName + " o";
    } else if (node instanceof BaseNode) {
        BaseNode baseNode = (BaseNode) node;
        ConsoleConfiguration consoleConfiguration = baseNode.getConsoleConfiguration();
        if (consoleConfiguration.isSessionFactoryCreated()) {
            return baseNode.getHQL();
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) BaseNode(org.hibernate.console.node.BaseNode) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 BaseNode (org.hibernate.console.node.BaseNode)2 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)2 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)2 FileNotFoundException (java.io.FileNotFoundException)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 Action (org.eclipse.jface.action.Action)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 EditConsoleConfiguration (org.hibernate.eclipse.console.actions.EditConsoleConfiguration)1 OpenMappingAction (org.hibernate.eclipse.console.actions.OpenMappingAction)1