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