Search in sources :

Example 96 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 97 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernatePropertyPage method loadValues.

public void loadValues() {
    IProject project = getProject();
    IScopeContext scope = new ProjectScope(project);
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    if (node != null) {
        initEnableHibernate = node.getBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, false);
        enableHibernate.setSelection(initEnableHibernate);
        String cfg = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, project.getName());
        ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(cfg);
        if (configuration == null) {
            selectedConfiguration.select(0);
            details.setEnabled(false);
        } else {
            initConsoleConfiguration = cfg;
            selectedConfiguration.setText(cfg);
        }
        initNamingStrategy = node.getBoolean(HibernatePropertiesConstants.NAMING_STRATEGY_ENABLED, true);
        enableNamingStrategy.setSelection(initNamingStrategy);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) EditConsoleConfiguration(org.hibernate.eclipse.console.actions.EditConsoleConfiguration) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Preferences(org.osgi.service.prefs.Preferences) IProject(org.eclipse.core.resources.IProject)

Example 98 with ConsoleConfiguration

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

Example 99 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction 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];
        ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (path.getSegment(0));
        try {
            run(consoleConfig, path);
        } catch (JavaModelException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_cannot_find_mapping_file, e);
        } catch (PartInitException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_cannot_open_mapping_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.OpenMappingAction_cannot_find_mapping_file, e);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) FileNotFoundException(java.io.FileNotFoundException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 100 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class BuildSessionFactoryAction method doRun.

protected void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        try {
            Object node = i.next();
            if (node instanceof ConsoleConfiguration) {
                ConsoleConfiguration config = (ConsoleConfiguration) node;
                if (config.isSessionFactoryCreated()) {
                    config.reset();
                } else {
                    config.build();
                    config.buildSessionFactory();
                }
                updateState(config);
            }
        } catch (HibernateConsoleRuntimeException he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.BuildSessionFactoryAction_exception_while_start_hibernate, he);
        } catch (UnsupportedClassVersionError ucve) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.BuildSessionFactoryAction_start_hibernate_resulted, ucve);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6