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);
}
}
}
}
}
};
}
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);
}
}
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 "";
}
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);
}
}
}
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);
}
}
}
Aggregations