### Eclipse Workspace Patch 1.0 #P org.jboss.tools.hibernate.ui Index: plugin.xml =================================================================== --- plugin.xml (revision 43192) +++ plugin.xml (working copy) @@ -56,12 +56,20 @@ --> - + - - + + + + + + + "; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(IdentifierBag bag) { + return "IdBag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(List list) { + return "List <" + list.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(PrimitiveArray primitiveArray) { + return primitiveArray.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Array list) { + return list.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Map map) { + return "Map<" + map.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(OneToMany many) { + return dequalify(many.getReferencedEntityName()); + } + + private String dequalify(String referencedEntityName) { + if(dequalify && referencedEntityName!=null && referencedEntityName.indexOf(".")>=0) { //$NON-NLS-1$ + return referencedEntityName.substring(referencedEntityName.lastIndexOf('.')+1); + } + return referencedEntityName; + } + + public Object accept(Set set) { + return "Set<" + set.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(Any any) { + return "Any"; //$NON-NLS-1$ + } + + public Object accept(SimpleValue value) { + return dequalify(value.getTypeName()); + } + + public Object accept(DependantValue value) { + return null; + } + + public Object accept(Component component) { + return dequalify(component.getComponentClassName()); + } + + public Object accept(ManyToOne mto) { + return dequalify(mto.getReferencedEntityName()); + } + + public Object accept(OneToOne oto) { + return dequalify(oto.getEntityName()); + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/TableWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/TableWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/TableWorkbenchAdapter.java (revision 0) @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Table; + +public class TableWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table t = getTable( wrapper.getItem() ); + + List items = new ArrayList(); + + PrimaryKey primaryKey = t.getPrimaryKey(); + if(primaryKey!=null) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), primaryKey)); + } + + Iterator columnIterator = t.getColumnIterator(); + while ( columnIterator.hasNext() ) { + Column col = (Column) columnIterator.next(); + if(primaryKey==null || !primaryKey.containsColumn(col)) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), col)); // only add non-pk columns here + } + } + + return items.toArray(new Object[items.size()]); + } + + private Table getTable(Object o) { + return (Table) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.TABLE); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table table = getTable(wrapper.getItem()); + //return Table.qualify(table.getCatalog(), table.getSchema(), table.getName(), '.'); + return table.getName(); + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/PersistentClassWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.internal.util.collections.JoinedIterator; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; + +public class PersistentClassWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + Property identifierProperty = pc.getIdentifierProperty(); + List properties = new ArrayList(); + + if(identifierProperty!=null) { + properties.add(identifierProperty); + } + + Iterator propertyClosureIterator = new JoinedIterator(properties.iterator(), pc.getPropertyClosureIterator()); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + BasicWorkbenchAdapter.toArray(propertyClosureIterator, Property.class, null)); + } + + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MAPPEDCLASS); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + return HibernateWorkbenchHelper.getLabelForClassName(pc.getEntityName()); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/ExtensionAdapterFactory.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/ExtensionAdapterFactory.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/ExtensionAdapterFactory.java (revision 0) @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; +import org.hibernate.cfg.Configuration; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Table; +import org.hibernate.mapping.Value; + + +/** + * + * + * @author Dmitry Geraskov (geraskov@gmail.com) + * + */ +public class ExtensionAdapterFactory implements IAdapterFactory { + + private Class[] classes; + private IWorkbenchAdapter[] adapters; + + private Class[] deferredClasses; + private IDeferredWorkbenchAdapter[] deferredAdapters; + + public ExtensionAdapterFactory() { + Map, IDeferredWorkbenchAdapter> deferredMap = new HashMap, IDeferredWorkbenchAdapter>(); + deferredMap.put(Configuration.class, new ConfigurationWorkbenchAdapter()); + deferredMap.put(LazyDatabaseSchema.class, new LazyDatabaseSchemaWorkbenchAdapter()); + + deferredClasses = new Class[deferredMap.size()]; + deferredAdapters = new IDeferredWorkbenchAdapter[deferredMap.size()]; + + int cnt = 0; + for (Map.Entry, IDeferredWorkbenchAdapter> entry : deferredMap.entrySet()) { + deferredClasses[cnt] = entry.getKey(); + deferredAdapters[cnt] = entry.getValue(); + cnt++; + } + + Map, IWorkbenchAdapter> map = new HashMap, IWorkbenchAdapter>(); + map.put(TableContainer.class, new TableContainerWorkbenchAdapter()); + map.put(PersistentClass.class, new PersistentClassWorkbenchAdapter()); + map.put(Property.class, new PropertyWorkbenchAdapter()); + map.put(Value.class, new ValueWorkbenchAdapter()); + map.put(Table.class, new TableWorkbenchAdapter()); + map.put(PrimaryKey.class, new PrimaryKeyWorkbenchAdapter()); + map.put(Column.class, new ColumnWorkbenchAdapter()); + + classes = new Class[map.size()]; + adapters = new IWorkbenchAdapter[map.size()]; + cnt = 0; + for (Map.Entry, IWorkbenchAdapter> entry : map.entrySet()) { + classes[cnt] = entry.getKey(); + adapters[cnt] = entry.getValue(); + cnt++; + } + } + + @SuppressWarnings("rawtypes") + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) adaptableObject; + adaptableObject = wrapper.getItem(); + } + + if(adapterType==IDeferredWorkbenchAdapter.class){ + return getDeferredAdapter( adaptableObject ); + } else if (adapterType==IWorkbenchAdapter.class){ + Object adapter = getAdapter( adaptableObject ); + return adapter != null ? adapter : getDeferredAdapter( adaptableObject ); + } + + return null; + } + + private Object getDeferredAdapter(Object adaptableObject) { + for (int i = 0; i < deferredClasses.length; i++) { + Class clazz = deferredClasses[i]; + if (clazz.isInstance(adaptableObject)) { + return deferredAdapters[i]; + } + } + return null; + } + + private Object getAdapter(Object adaptableObject) { + for (int i = 0; i < classes.length; i++) { + Class clazz = classes[i]; + if (clazz.isInstance(adaptableObject)) { + return adapters[i]; + } + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { IDeferredWorkbenchAdapter.class, IWorkbenchAdapter.class}; + } + + public void registerAdapters(IAdapterManager adapterManager) { + //do nothing + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/PropertyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/PropertyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/PropertyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.Value; +import org.hibernate.mapping.ValueVisitor; + +public class PropertyWorkbenchAdapter implements IWorkbenchAdapter { + + final static Object[] NO_CHILDREN = new Object[0]; + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property p = (Property) wrapper.getItem(); + + Object[] result = (Object[]) p.getValue().accept(new ValueVisitor() { + + public Object accept(OneToOne oto) { + return NO_CHILDREN; + } + + public Object accept(ManyToOne mto) { + return NO_CHILDREN; + } + + @SuppressWarnings("unchecked") + public Object accept(Component component) { + return BasicWorkbenchAdapter.toArray(component.getPropertyIterator(), Property.class, null); + } + + public Object accept(DependantValue value) { + return NO_CHILDREN; + } + + public Object accept(SimpleValue value) { + return NO_CHILDREN; + } + + public Object accept(Any any) { + return NO_CHILDREN; + } + + public Object accept(Set set) { + return NO_CHILDREN; // should it look up the target entity? + } + + public Object accept(OneToMany many) { + return NO_CHILDREN; + } + + public Object accept(Map map) { + return NO_CHILDREN; + } + + public Object accept(Array list) { + return NO_CHILDREN; + } + + public Object accept(PrimitiveArray primitiveArray) { + return NO_CHILDREN; + } + + public Object accept(List list) { + return NO_CHILDREN; + } + + public Object accept(IdentifierBag bag) { + return NO_CHILDREN; + } + + public Object accept(Bag bag) { + return NO_CHILDREN; + } + }); + + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), result); + } + + public ImageDescriptor getImageDescriptor(Object object) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)object; + Property p = (Property) wrapper.getItem(); + + return HibernateWorkbenchHelper.getImageDescriptor(p); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property property = (Property) wrapper.getItem(); + Value value = property.getValue(); + String typeName = (String) value.accept(new TypeNameValueVisitor(true)); + + if (typeName!=null) { + return property.getName() + " : " + typeName; //$NON-NLS-1$ + } + + return property.getName(); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/HibernateWorkbenchHelper.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/HibernateWorkbenchHelper.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/HibernateWorkbenchHelper.java (revision 0) @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Value; +import org.hibernate.util.xpl.StringHelper; + +public class HibernateWorkbenchHelper { + + public static ImageDescriptor getImageDescriptor(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImageDescriptor(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImageDescriptor(iconNameForValue); + } + + public static Image getImage(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImage(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImage(iconNameForValue); + } + + static private String getIconNameForValue(Value value) { + String result; + + result = (String) value.accept(new IconNameValueVisitor()); + + if(result==null) { + result = ImageConstants.UNKNOWNPROPERTY; + } + return result; + } + + public static String getLabelForClassName(String classOrEntityName) { + if(classOrEntityName.indexOf('.')>=0) { + classOrEntityName = StringHelper.unqualify(classOrEntityName); + } + return classOrEntityName; + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/ValueWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/ValueWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/ValueWorkbenchAdapter.java (revision 0) @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; + +public class ValueWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MANYTOONE); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ValueWorkbenchAdapter_value + o.getClass().getName(); + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java =================================================================== --- src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java (revision 43192) +++ src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java (working copy) @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.Map; +import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.osgi.util.NLS; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -38,6 +39,7 @@ import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.internal.StandardServiceRegistryImpl; +import org.jboss.tools.hibernate4_0.console.workbench.ExtensionAdapterFactory; /** * @@ -58,6 +60,8 @@ private ServiceRegistry serviceRegistry; + private static IAdapterFactory adapterFactory = new ExtensionAdapterFactory(); + private Map fakeDrivers = new HashMap(); public HibernateExtension4_0() { @@ -313,4 +317,9 @@ public String getConsoleConfigurationName() { return prefs.getName(); } + + @Override + public IAdapterFactory getAdapterFactory() { + return adapterFactory; + } } \ No newline at end of file Index: src/org/jboss/tools/hibernate4_0/console/workbench/ColumnWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/ColumnWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/ColumnWorkbenchAdapter.java (revision 0) @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.cfg.reveng.JDBCToHibernateTypeHelper; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; + +public class ColumnWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + Column c = (Column) ((HibernateObjectWrapper)o).getItem(); + return getColumnLabel( c ); + } + + static String getColumnLabel(Column c) { + String label = c.getName(); + if(c.getSqlTypeCode()!=null) { + label += " : " + JDBCToHibernateTypeHelper.getJDBCTypeName(c.getSqlTypeCode().intValue()); //$NON-NLS-1$ + } + return label; + } + + public Object getParent(Object o) { + return null; + } + + public boolean isContainer() { + return false; + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.osgi.util.NLS; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.JDBCReaderFactory; +import org.hibernate.cfg.Settings; +import org.hibernate.cfg.reveng.DefaultDatabaseCollector; +import org.hibernate.cfg.reveng.JDBCReader; +import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; +import org.hibernate.console.ConsoleConfiguration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.execution.ExecutionContext; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.HibernateConsolePlugin; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.OverlayImageIcon; +import org.hibernate.eclipse.console.workbench.ProgressListenerMonitor; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.ServiceRegistryBuilder; +import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; +import org.jboss.tools.hibernate4_0.HibernateExtension4_0; + +public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return getChildren(o, new NullProgressMonitor()); + } + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o, final IProgressMonitor monitor) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema( o ); + dbs.setConnected(false); + dbs.setErrorFlag(false); + ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration(); + Object[] res; + try { + DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy()); + + List result = new ArrayList(); + + Iterator>> qualifierEntries = db.getQualifierEntries(); + while (qualifierEntries.hasNext()) { + Map.Entry> entry = qualifierEntries.next(); + List tables = new LinkedList(); + for (Table table : entry.getValue()) { + tables.add(new HibernateObjectWrapper(consoleConfiguration, table)); + } + result.add(new TableContainer(consoleConfiguration, entry.getKey(), tables)); + } + res = toArray(result.iterator(), TableContainer.class, new Comparator() { + public int compare(TableContainer arg0, TableContainer arg1) { + return arg0.getName().compareTo(arg1.getName()); + } + }); + dbs.setConnected(true); + } catch (HibernateException e) { + HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e); + String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage()); + res = new Object[] { out }; + dbs.setErrorFlag(true); + } + return res; + } + + private LazyDatabaseSchema getLazyDatabaseSchema(Object o) { + return (LazyDatabaseSchema) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema(object); + Map imageMap = new HashMap(); + if (dbs.isConnected()) { + imageMap.put(ImageConstants.OVR_DBS_CONNECTED, OverlayImageIcon.BOTTOM_LEFT); + } + if (dbs.getErrorFlag()) { + imageMap.put(ImageConstants.OVR_WARNING, OverlayImageIcon.BOTTOM_LEFT); + } + return new OverlayImageIcon(EclipseImages.getImage(ImageConstants.TABLE), imageMap); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_database; + } + + public Object getParent(Object o) { + return getLazyDatabaseSchema(o).getConsoleConfiguration(); + } + + protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) { + final HibernateExtension4_0 hibernateExtension = (HibernateExtension4_0) consoleConfiguration.getHibernateExtension(); + hibernateExtension.buildWith(null, false); + final Configuration configuration = hibernateExtension.getConfiguration(); + return (DefaultDatabaseCollector) hibernateExtension.execute(new ExecutionContext.Command() { + + public Object execute() { + DefaultDatabaseCollector db = null; + ServiceRegistryBuilder builder = new ServiceRegistryBuilder(); + ServiceRegistry buildServiceRegistry = builder.applySettings(configuration.getProperties()).buildServiceRegistry(); + Settings settings = hibernateExtension.getSettings(configuration, buildServiceRegistry); + try { + JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy, buildServiceRegistry); + db = new DefaultDatabaseCollector(reader.getMetaDataDialect()); + reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor)); + } catch (HibernateException he) { + throw he; + } catch (UnsupportedOperationException he) { + throw new HibernateException(he); + } + finally { + ServiceRegistryBuilder.destroy(buildServiceRegistry); + } + return db; + } + }); + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/TableContainerWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.Comparator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; + +public class TableContainerWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + TableContainer tc = getTableContainer( o ); + return BasicWorkbenchAdapter.toArray(tc.getTables().iterator(), HibernateObjectWrapper.class, new Comparator() { + + public int compare(HibernateObjectWrapper arg0, HibernateObjectWrapper arg1) { + return ((Table)arg0.getItem()).getName().compareTo( + ((Table)arg1.getItem()).getName()); + } + + }); + } + + private TableContainer getTableContainer(Object o) { + return (TableContainer) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.SCHEMA); + } + + public String getLabel(Object o) { + String name = getTableContainer(o).getName(); + return "".equals(name)?HibernateConsoleMessages.TableContainerWorkbenchAdapter_default:name; //$NON-NLS-1$ + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/IconNameValueVisitor.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/IconNameValueVisitor.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/IconNameValueVisitor.java (revision 0) @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.hibernate.console.ImageConstants; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +final class IconNameValueVisitor implements ValueVisitor { + + public Object accept(OneToOne oto) { + return ImageConstants.ONETOONE; + } + + public Object accept(ManyToOne mto) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Component component) { + return ImageConstants.COMPONENT; + } + + public Object accept(DependantValue value) { + return ImageConstants.UNKNOWNPROPERTY; + } + + public Object accept(SimpleValue value) { + return ImageConstants.PROPERTY; + } + + public Object accept(Any any) { + return ImageConstants.PROPERTY; + } + + public Object accept(Set set) { + return ImageConstants.MANYTOONE; + } + + public Object accept(OneToMany many) { + return ImageConstants.ONETOMANY; + } + + public Object accept(Map map) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Array list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(PrimitiveArray primitiveArray) { + return ImageConstants.MANYTOONE; + } + + public Object accept(List list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(IdentifierBag bag) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Bag bag) { + return ImageConstants.MANYTOONE; + } + +} \ No newline at end of file Index: src/org/jboss/tools/hibernate4_0/console/workbench/ConfigurationWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import java.util.Comparator; +import java.util.Iterator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.hibernate.cfg.Configuration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.KnownConfigurations; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.PersistentClass; + +public class ConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Configuration cfg = (Configuration) wrapper.getItem(); + Iterator classMappings = cfg.getClassMappings(); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + toArray(classMappings, PersistentClass.class, new Comparator() { + public int compare(PersistentClass p0, PersistentClass p1) { + String label0 = HibernateWorkbenchHelper.getLabelForClassName(p0.getEntityName()); + String label1 = HibernateWorkbenchHelper.getLabelForClassName(p1.getEntityName()); + return label0.compareTo(label1); + } + + })); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.CONFIGURATION); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ConfigurationWorkbenchAdapter_configuration; + } + + public Object getParent(Object o) { + return KnownConfigurations.getInstance(); + } + + public boolean isContainer() { + return true; + } + + + +} Index: src/org/jboss/tools/hibernate4_0/console/workbench/PrimaryKeyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate4_0/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate4_0/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate4_0.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; + +public class PrimaryKeyWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey t = getPrimaryKey( wrapper.getItem() ); + + if(t.getColumnSpan()==1) { + return new Object[0]; + } else { + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + t.getColumns().toArray(new Column[0])); + } + } + + private PrimaryKey getPrimaryKey(Object o) { + return (PrimaryKey)o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey table = getPrimaryKey(wrapper.getItem()); + if(table.getColumnSpan()==1) { + return ColumnWorkbenchAdapter.getColumnLabel(table.getColumn(0)); + } else { + return HibernateConsoleMessages.PrimaryKeyWorkbenchAdapter_composite_primary_key; + } + } + + public Object getParent(Object o) { + return null; + } + +} #P org.jboss.tools.hibernate3_6 Index: src/org/jboss/tools/hibernate3_6/console/workbench/HibernateWorkbenchHelper.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/HibernateWorkbenchHelper.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/HibernateWorkbenchHelper.java (revision 0) @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Value; +import org.hibernate.util.xpl.StringHelper; + +public class HibernateWorkbenchHelper { + + public static ImageDescriptor getImageDescriptor(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImageDescriptor(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImageDescriptor(iconNameForValue); + } + + public static Image getImage(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImage(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImage(iconNameForValue); + } + + static private String getIconNameForValue(Value value) { + String result; + + result = (String) value.accept(new IconNameValueVisitor()); + + if(result==null) { + result = ImageConstants.UNKNOWNPROPERTY; + } + return result; + } + + public static String getLabelForClassName(String classOrEntityName) { + if(classOrEntityName.indexOf('.')>=0) { + classOrEntityName = StringHelper.unqualify(classOrEntityName); + } + return classOrEntityName; + } + +} Index: src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java =================================================================== --- src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java (revision 43192) +++ src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java (working copy) @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.Map; +import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.osgi.util.NLS; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -35,6 +36,7 @@ import org.hibernate.console.ext.HibernateExtension; import org.hibernate.console.preferences.ConsoleConfigurationPreferences; import org.hibernate.console.preferences.PreferencesClassPathUtils; +import org.jboss.tools.hibernate3_6.console.workbench.ExtensionAdapterFactory; /** * @@ -53,6 +55,8 @@ private SessionFactory sessionFactory; + private static IAdapterFactory adapterFactory = new ExtensionAdapterFactory(); + private Map fakeDrivers = new HashMap(); public HibernateExtension3_6() { @@ -302,4 +306,9 @@ public String getConsoleConfigurationName() { return prefs.getName(); } + + @Override + public IAdapterFactory getAdapterFactory() { + return adapterFactory; + } } \ No newline at end of file Index: src/org/jboss/tools/hibernate3_6/console/workbench/ValueWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/ValueWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/ValueWorkbenchAdapter.java (revision 0) @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; + +public class ValueWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MANYTOONE); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ValueWorkbenchAdapter_value + o.getClass().getName(); + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/ColumnWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/ColumnWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/ColumnWorkbenchAdapter.java (revision 0) @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.cfg.reveng.JDBCToHibernateTypeHelper; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; + +public class ColumnWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + Column c = (Column) ((HibernateObjectWrapper)o).getItem(); + return getColumnLabel( c ); + } + + static String getColumnLabel(Column c) { + String label = c.getName(); + if(c.getSqlTypeCode()!=null) { + label += " : " + JDBCToHibernateTypeHelper.getJDBCTypeName(c.getSqlTypeCode().intValue()); //$NON-NLS-1$ + } + return label; + } + + public Object getParent(Object o) { + return null; + } + + public boolean isContainer() { + return false; + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/ConfigurationWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.Comparator; +import java.util.Iterator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.hibernate.cfg.Configuration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.KnownConfigurations; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.PersistentClass; + +public class ConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Configuration cfg = (Configuration) wrapper.getItem(); + Iterator classMappings = cfg.getClassMappings(); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + toArray(classMappings, PersistentClass.class, new Comparator() { + public int compare(PersistentClass p0, PersistentClass p1) { + String label0 = HibernateWorkbenchHelper.getLabelForClassName(p0.getEntityName()); + String label1 = HibernateWorkbenchHelper.getLabelForClassName(p1.getEntityName()); + return label0.compareTo(label1); + } + + })); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.CONFIGURATION); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ConfigurationWorkbenchAdapter_configuration; + } + + public Object getParent(Object o) { + return KnownConfigurations.getInstance(); + } + + public boolean isContainer() { + return true; + } + + + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/PrimaryKeyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; + +public class PrimaryKeyWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey t = getPrimaryKey( wrapper.getItem() ); + + if(t.getColumnSpan()==1) { + return new Object[0]; + } else { + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + t.getColumns().toArray(new Column[0])); + } + } + + private PrimaryKey getPrimaryKey(Object o) { + return (PrimaryKey)o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey table = getPrimaryKey(wrapper.getItem()); + if(table.getColumnSpan()==1) { + return ColumnWorkbenchAdapter.getColumnLabel(table.getColumn(0)); + } else { + return HibernateConsoleMessages.PrimaryKeyWorkbenchAdapter_composite_primary_key; + } + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.osgi.util.NLS; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.JDBCReaderFactory; +import org.hibernate.cfg.Settings; +import org.hibernate.cfg.reveng.DefaultDatabaseCollector; +import org.hibernate.cfg.reveng.JDBCReader; +import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; +import org.hibernate.connection.ConnectionProvider; +import org.hibernate.console.ConsoleConfiguration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.execution.ExecutionContext; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.HibernateConsolePlugin; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.OverlayImageIcon; +import org.hibernate.eclipse.console.workbench.ProgressListenerMonitor; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; +import org.jboss.tools.hibernate3_6.HibernateExtension3_6; + +public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return getChildren(o, new NullProgressMonitor()); + } + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o, final IProgressMonitor monitor) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema( o ); + dbs.setConnected(false); + dbs.setErrorFlag(false); + ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration(); + Object[] res; + try { + DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy()); + + List result = new ArrayList(); + + Iterator>> qualifierEntries = db.getQualifierEntries(); + while (qualifierEntries.hasNext()) { + Map.Entry> entry = qualifierEntries.next(); + List tables = new LinkedList(); + for (Table table : entry.getValue()) { + tables.add(new HibernateObjectWrapper(consoleConfiguration, table)); + } + result.add(new TableContainer(consoleConfiguration, entry.getKey(), tables)); + } + res = toArray(result.iterator(), TableContainer.class, new Comparator() { + public int compare(TableContainer arg0, TableContainer arg1) { + return arg0.getName().compareTo(arg1.getName()); + } + }); + dbs.setConnected(true); + } catch (HibernateException e) { + HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e); + String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage()); + res = new Object[] { out }; + dbs.setErrorFlag(true); + } + return res; + } + + private LazyDatabaseSchema getLazyDatabaseSchema(Object o) { + return (LazyDatabaseSchema) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema(object); + Map imageMap = new HashMap(); + if (dbs.isConnected()) { + imageMap.put(ImageConstants.OVR_DBS_CONNECTED, OverlayImageIcon.BOTTOM_LEFT); + } + if (dbs.getErrorFlag()) { + imageMap.put(ImageConstants.OVR_WARNING, OverlayImageIcon.BOTTOM_LEFT); + } + return new OverlayImageIcon(EclipseImages.getImage(ImageConstants.TABLE), imageMap); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_database; + } + + public Object getParent(Object o) { + return getLazyDatabaseSchema(o).getConsoleConfiguration(); + } + + protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) { + final HibernateExtension3_6 hibernateExtension = (HibernateExtension3_6) consoleConfiguration.getHibernateExtension(); + hibernateExtension.buildWith(null, false); + final Configuration configuration = hibernateExtension.getConfiguration(); + return (DefaultDatabaseCollector) hibernateExtension.execute(new ExecutionContext.Command() { + + public Object execute() { + DefaultDatabaseCollector db = null; + Settings settings = hibernateExtension.getSettings(configuration); + ConnectionProvider connectionProvider = null; + try { + connectionProvider = settings.getConnectionProvider(); + + JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy); + db = new DefaultDatabaseCollector(reader.getMetaDataDialect()); + reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor)); + } catch (HibernateException he) { + throw he; + } catch (UnsupportedOperationException he) { + throw new HibernateException(he); + } + finally { + if (connectionProvider != null) { + connectionProvider.close(); + } + } + return db; + } + }); + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/IconNameValueVisitor.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/IconNameValueVisitor.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/IconNameValueVisitor.java (revision 0) @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.hibernate.console.ImageConstants; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +final class IconNameValueVisitor implements ValueVisitor { + + public Object accept(OneToOne oto) { + return ImageConstants.ONETOONE; + } + + public Object accept(ManyToOne mto) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Component component) { + return ImageConstants.COMPONENT; + } + + public Object accept(DependantValue value) { + return ImageConstants.UNKNOWNPROPERTY; + } + + public Object accept(SimpleValue value) { + return ImageConstants.PROPERTY; + } + + public Object accept(Any any) { + return ImageConstants.PROPERTY; + } + + public Object accept(Set set) { + return ImageConstants.MANYTOONE; + } + + public Object accept(OneToMany many) { + return ImageConstants.ONETOMANY; + } + + public Object accept(Map map) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Array list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(PrimitiveArray primitiveArray) { + return ImageConstants.MANYTOONE; + } + + public Object accept(List list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(IdentifierBag bag) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Bag bag) { + return ImageConstants.MANYTOONE; + } + +} \ No newline at end of file Index: src/org/jboss/tools/hibernate3_6/console/workbench/TypeNameValueVisitor.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/TypeNameValueVisitor.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/TypeNameValueVisitor.java (revision 0) @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +public class TypeNameValueVisitor implements ValueVisitor { + + /** if true then only return the classname, not the fully qualified classname */ + final boolean dequalify; + + public TypeNameValueVisitor(boolean dequalify) { + this.dequalify=dequalify; + } + + public Object accept(Bag bag) { + return "Bag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(IdentifierBag bag) { + return "IdBag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(List list) { + return "List <" + list.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(PrimitiveArray primitiveArray) { + return primitiveArray.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Array list) { + return list.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Map map) { + return "Map<" + map.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(OneToMany many) { + return dequalify(many.getReferencedEntityName()); + } + + private String dequalify(String referencedEntityName) { + if(dequalify && referencedEntityName!=null && referencedEntityName.indexOf(".")>=0) { //$NON-NLS-1$ + return referencedEntityName.substring(referencedEntityName.lastIndexOf('.')+1); + } + return referencedEntityName; + } + + public Object accept(Set set) { + return "Set<" + set.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(Any any) { + return "Any"; //$NON-NLS-1$ + } + + public Object accept(SimpleValue value) { + return dequalify(value.getTypeName()); + } + + public Object accept(DependantValue value) { + return null; + } + + public Object accept(Component component) { + return dequalify(component.getComponentClassName()); + } + + public Object accept(ManyToOne mto) { + return dequalify(mto.getReferencedEntityName()); + } + + public Object accept(OneToOne oto) { + return dequalify(oto.getEntityName()); + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/PropertyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/PropertyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/PropertyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.Value; +import org.hibernate.mapping.ValueVisitor; + +public class PropertyWorkbenchAdapter implements IWorkbenchAdapter { + + final static Object[] NO_CHILDREN = new Object[0]; + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property p = (Property) wrapper.getItem(); + + Object[] result = (Object[]) p.getValue().accept(new ValueVisitor() { + + public Object accept(OneToOne oto) { + return NO_CHILDREN; + } + + public Object accept(ManyToOne mto) { + return NO_CHILDREN; + } + + @SuppressWarnings("unchecked") + public Object accept(Component component) { + return BasicWorkbenchAdapter.toArray(component.getPropertyIterator(), Property.class, null); + } + + public Object accept(DependantValue value) { + return NO_CHILDREN; + } + + public Object accept(SimpleValue value) { + return NO_CHILDREN; + } + + public Object accept(Any any) { + return NO_CHILDREN; + } + + public Object accept(Set set) { + return NO_CHILDREN; // should it look up the target entity? + } + + public Object accept(OneToMany many) { + return NO_CHILDREN; + } + + public Object accept(Map map) { + return NO_CHILDREN; + } + + public Object accept(Array list) { + return NO_CHILDREN; + } + + public Object accept(PrimitiveArray primitiveArray) { + return NO_CHILDREN; + } + + public Object accept(List list) { + return NO_CHILDREN; + } + + public Object accept(IdentifierBag bag) { + return NO_CHILDREN; + } + + public Object accept(Bag bag) { + return NO_CHILDREN; + } + }); + + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), result); + } + + public ImageDescriptor getImageDescriptor(Object object) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)object; + Property p = (Property) wrapper.getItem(); + + return HibernateWorkbenchHelper.getImageDescriptor(p); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property property = (Property) wrapper.getItem(); + Value value = property.getValue(); + String typeName = (String) value.accept(new TypeNameValueVisitor(true)); + + if (typeName!=null) { + return property.getName() + " : " + typeName; //$NON-NLS-1$ + } + + return property.getName(); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/ExtensionAdapterFactory.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/ExtensionAdapterFactory.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/ExtensionAdapterFactory.java (revision 0) @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; +import org.hibernate.cfg.Configuration; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Table; +import org.hibernate.mapping.Value; + + +/** + * + * + * @author Dmitry Geraskov (geraskov@gmail.com) + * + */ +public class ExtensionAdapterFactory implements IAdapterFactory { + + private Class[] classes; + private IWorkbenchAdapter[] adapters; + + private Class[] deferredClasses; + private IDeferredWorkbenchAdapter[] deferredAdapters; + + public ExtensionAdapterFactory() { + Map, IDeferredWorkbenchAdapter> deferredMap = new HashMap, IDeferredWorkbenchAdapter>(); + deferredMap.put(Configuration.class, new ConfigurationWorkbenchAdapter()); + deferredMap.put(LazyDatabaseSchema.class, new LazyDatabaseSchemaWorkbenchAdapter()); + + deferredClasses = new Class[deferredMap.size()]; + deferredAdapters = new IDeferredWorkbenchAdapter[deferredMap.size()]; + + int cnt = 0; + for (Map.Entry, IDeferredWorkbenchAdapter> entry : deferredMap.entrySet()) { + deferredClasses[cnt] = entry.getKey(); + deferredAdapters[cnt] = entry.getValue(); + cnt++; + } + + Map, IWorkbenchAdapter> map = new HashMap, IWorkbenchAdapter>(); + map.put(TableContainer.class, new TableContainerWorkbenchAdapter()); + map.put(PersistentClass.class, new PersistentClassWorkbenchAdapter()); + map.put(Property.class, new PropertyWorkbenchAdapter()); + map.put(Value.class, new ValueWorkbenchAdapter()); + map.put(Table.class, new TableWorkbenchAdapter()); + map.put(PrimaryKey.class, new PrimaryKeyWorkbenchAdapter()); + map.put(Column.class, new ColumnWorkbenchAdapter()); + + classes = new Class[map.size()]; + adapters = new IWorkbenchAdapter[map.size()]; + cnt = 0; + for (Map.Entry, IWorkbenchAdapter> entry : map.entrySet()) { + classes[cnt] = entry.getKey(); + adapters[cnt] = entry.getValue(); + cnt++; + } + } + + @SuppressWarnings("rawtypes") + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) adaptableObject; + adaptableObject = wrapper.getItem(); + } + + if(adapterType==IDeferredWorkbenchAdapter.class){ + return getDeferredAdapter( adaptableObject ); + } else if (adapterType==IWorkbenchAdapter.class){ + Object adapter = getAdapter( adaptableObject ); + return adapter != null ? adapter : getDeferredAdapter( adaptableObject ); + } + + return null; + } + + private Object getDeferredAdapter(Object adaptableObject) { + for (int i = 0; i < deferredClasses.length; i++) { + Class clazz = deferredClasses[i]; + if (clazz.isInstance(adaptableObject)) { + return deferredAdapters[i]; + } + } + return null; + } + + private Object getAdapter(Object adaptableObject) { + for (int i = 0; i < classes.length; i++) { + Class clazz = classes[i]; + if (clazz.isInstance(adaptableObject)) { + return adapters[i]; + } + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { IDeferredWorkbenchAdapter.class, IWorkbenchAdapter.class}; + } + + public void registerAdapters(IAdapterManager adapterManager) { + //do nothing + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/PersistentClassWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.util.JoinedIterator; + +public class PersistentClassWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + Property identifierProperty = pc.getIdentifierProperty(); + List properties = new ArrayList(); + + if(identifierProperty!=null) { + properties.add(identifierProperty); + } + + Iterator propertyClosureIterator = new JoinedIterator(properties.iterator(), pc.getPropertyClosureIterator()); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + BasicWorkbenchAdapter.toArray(propertyClosureIterator, Property.class, null)); + } + + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MAPPEDCLASS); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + return HibernateWorkbenchHelper.getLabelForClassName(pc.getEntityName()); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/TableWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/TableWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/TableWorkbenchAdapter.java (revision 0) @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Table; + +public class TableWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table t = getTable( wrapper.getItem() ); + + List items = new ArrayList(); + + PrimaryKey primaryKey = t.getPrimaryKey(); + if(primaryKey!=null) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), primaryKey)); + } + + Iterator columnIterator = t.getColumnIterator(); + while ( columnIterator.hasNext() ) { + Column col = (Column) columnIterator.next(); + if(primaryKey==null || !primaryKey.containsColumn(col)) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), col)); // only add non-pk columns here + } + } + + return items.toArray(new Object[items.size()]); + } + + private Table getTable(Object o) { + return (Table) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.TABLE); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table table = getTable(wrapper.getItem()); + //return Table.qualify(table.getCatalog(), table.getSchema(), table.getName(), '.'); + return table.getName(); + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_6/console/workbench/TableContainerWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_6/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_6/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_6.console.workbench; + +import java.util.Comparator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; + +public class TableContainerWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + TableContainer tc = getTableContainer( o ); + return BasicWorkbenchAdapter.toArray(tc.getTables().iterator(), HibernateObjectWrapper.class, new Comparator() { + + public int compare(HibernateObjectWrapper arg0, HibernateObjectWrapper arg1) { + return ((Table)arg0.getItem()).getName().compareTo( + ((Table)arg1.getItem()).getName()); + } + + }); + } + + private TableContainer getTableContainer(Object o) { + return (TableContainer) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.SCHEMA); + } + + public String getLabel(Object o) { + String name = getTableContainer(o).getName(); + return "".equals(name)?HibernateConsoleMessages.TableContainerWorkbenchAdapter_default:name; //$NON-NLS-1$ + } + + public Object getParent(Object o) { + return null; + } + +} #P org.hibernate.eclipse.console Index: src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java (working copy) @@ -69,7 +69,7 @@ @SuppressWarnings("unchecked") - protected static T[] toArray(Iterator iterator, Class clazz, Comparator comparator) { + public static T[] toArray(Iterator iterator, Class clazz, Comparator comparator) { List obj = toList( iterator ); T[] array = obj.toArray((T[])Array.newInstance(clazz, obj.size()) ); Index: src/org/hibernate/eclipse/console/workbench/TableContainer.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/TableContainer.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/TableContainer.java (working copy) @@ -23,19 +23,26 @@ import java.util.List; -import org.hibernate.mapping.Table; +import org.hibernate.console.ConsoleConfiguration; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; -public class TableContainer { +public class TableContainer extends HibernateObjectWrapper{ - private final List tables; + private final List tables; private final String name; - public TableContainer(String name, List
tables) { + public TableContainer(ConsoleConfiguration cc, String name, List tables) { + super(cc, null); this.tables = tables; this.name = name; } + + @Override + public Object getItem() { + return this; + } - public List
getTables() { + public List getTables() { return tables; } Index: src/org/hibernate/eclipse/console/actions/OpenSourceAction.java =================================================================== --- src/org/hibernate/eclipse/console/actions/OpenSourceAction.java (revision 43192) +++ src/org/hibernate/eclipse/console/actions/OpenSourceAction.java (working copy) @@ -30,6 +30,7 @@ import org.hibernate.eclipse.console.HibernateConsoleMessages; import org.hibernate.eclipse.console.HibernateConsolePlugin; import org.hibernate.eclipse.console.utils.ProjectUtils; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -62,6 +63,9 @@ for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; Object lastSegment = path.getLastSegment(); + if (lastSegment instanceof HibernateObjectWrapper) { + lastSegment = ((HibernateObjectWrapper) lastSegment).getItem(); + } PersistentClass persClass = getPersistentClass(lastSegment); ConsoleConfiguration consoleConfig = (ConsoleConfiguration)(path.getSegment(0)); @@ -126,6 +130,9 @@ } } IJavaElement jElement = null; + if (selection instanceof HibernateObjectWrapper) { + selection = ((HibernateObjectWrapper) selection).getItem(); + } if (selection instanceof Property){ final String selectionName =((Property)selection).getName(); final IType typeSave = type; Index: src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java (working copy) @@ -1,48 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.HibernateConsoleMessages; -import org.hibernate.eclipse.console.utils.EclipseImages; - -public class ValueWorkbenchAdapter implements IWorkbenchAdapter { - - public Object[] getChildren(Object o) { - return new Object[0]; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.MANYTOONE); - } - - public String getLabel(Object o) { - return HibernateConsoleMessages.ValueWorkbenchAdapter_value + o.getClass().getName(); - } - - public Object getParent(Object o) { - return null; - } - -} Index: src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java =================================================================== --- src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java (revision 43192) +++ src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java (working copy) @@ -29,6 +29,7 @@ import org.hibernate.eclipse.console.HibernateConsoleMessages; import org.hibernate.eclipse.console.HibernateConsolePlugin; import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -60,6 +61,11 @@ String propCriteria = ""; //$NON-NLS-1$ String enName = ""; //$NON-NLS-1$ Object node = path.getLastSegment(); + //FIXME: workaround to save previous functionality + if (node instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) node; + node = wrapper.getItem(); + } if (node instanceof PersistentClass){ enName = ((PersistentClass)node).getEntityName(); enName = enName.substring(enName.lastIndexOf('.') + 1); @@ -78,11 +84,16 @@ } else { // Generate script for Component property for (int i = path.getSegmentCount() - 1; i > 0; i--) { - if (path.getSegment(i) instanceof PersistentClass){ - enName = ((PersistentClass)path.getSegment(i)).getEntityName(); + Object item = path.getSegment(i); + if (item instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) item; + item = wrapper.getItem(); + } + if (item instanceof PersistentClass){ + enName = ((PersistentClass)item).getEntityName(); enName = enName.substring(enName.lastIndexOf('.') + 1); - } else if (path.getSegment(i) instanceof Property){ - prName = ((Property)path.getSegment(i)).getName(); + } else if (item instanceof Property){ + prName = ((Property)item).getName(); if (prop.getValue().isSimpleValue()) { propCriteria += NLS.bind(projection, prName); } else { Index: src/org/hibernate/eclipse/graph/model/PropertyViewAdapter.java =================================================================== --- src/org/hibernate/eclipse/graph/model/PropertyViewAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/graph/model/PropertyViewAdapter.java (working copy) @@ -29,7 +29,7 @@ import org.eclipse.swt.graphics.Image; import org.hibernate.HibernateException; import org.hibernate.eclipse.console.HibernateConsolePlugin; -import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper; +import org.hibernate.eclipse.graph.HibernateWorkbenchHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.Property; Index: src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java (working copy) @@ -24,10 +24,10 @@ import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy; import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; import org.hibernate.console.ConsoleConfiguration; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; -public class LazyDatabaseSchema { +public class LazyDatabaseSchema extends HibernateObjectWrapper { - private final ConsoleConfiguration ccfg; private final ReverseEngineeringStrategy res; protected boolean connectedFlag = false; protected boolean errorFlag = false; @@ -37,11 +37,12 @@ } public LazyDatabaseSchema(ConsoleConfiguration ccfg, ReverseEngineeringStrategy res) { - this.ccfg = ccfg; + super(ccfg, null); this.res = res; } - public ConsoleConfiguration getConsoleConfiguration() { - return ccfg; + + public Object getItem(){ + return this; } public ReverseEngineeringStrategy getReverseEngineeringStrategy() { Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 43192) +++ META-INF/MANIFEST.MF (working copy) @@ -23,6 +23,7 @@ org.hibernate.eclipse.console.views.properties, org.hibernate.eclipse.console.wizards, org.hibernate.eclipse.console.workbench, + org.hibernate.eclipse.console.workbench.wrapper, org.hibernate.eclipse.console.workbench.xpl, org.hibernate.eclipse.criteriaeditor, org.hibernate.eclipse.facet, Index: src/org/hibernate/eclipse/console/workbench/TypeNameValueVisitor.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/TypeNameValueVisitor.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/TypeNameValueVisitor.java (working copy) @@ -1,112 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.hibernate.mapping.Any; -import org.hibernate.mapping.Array; -import org.hibernate.mapping.Bag; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.DependantValue; -import org.hibernate.mapping.IdentifierBag; -import org.hibernate.mapping.List; -import org.hibernate.mapping.ManyToOne; -import org.hibernate.mapping.Map; -import org.hibernate.mapping.OneToMany; -import org.hibernate.mapping.OneToOne; -import org.hibernate.mapping.PrimitiveArray; -import org.hibernate.mapping.Set; -import org.hibernate.mapping.SimpleValue; -import org.hibernate.mapping.ValueVisitor; - -public class TypeNameValueVisitor implements ValueVisitor { - - /** if true then only return the classname, not the fully qualified classname */ - final boolean dequalify; - - public TypeNameValueVisitor(boolean dequalify) { - this.dequalify=dequalify; - } - - public Object accept(Bag bag) { - return "Bag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ - } - - public Object accept(IdentifierBag bag) { - return "IdBag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ - } - - public Object accept(List list) { - return "List <" + list.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public Object accept(PrimitiveArray primitiveArray) { - return primitiveArray.getElement().accept(this) + "[]"; //$NON-NLS-1$ - } - - public Object accept(Array list) { - return list.getElement().accept(this) + "[]"; //$NON-NLS-1$ - } - - public Object accept(Map map) { - return "Map<" + map.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public Object accept(OneToMany many) { - return dequalify(many.getReferencedEntityName()); - } - - private String dequalify(String referencedEntityName) { - if(dequalify && referencedEntityName!=null && referencedEntityName.indexOf(".")>=0) { //$NON-NLS-1$ - return referencedEntityName.substring(referencedEntityName.lastIndexOf('.')+1); - } - return referencedEntityName; - } - - public Object accept(Set set) { - return "Set<" + set.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public Object accept(Any any) { - return "Any"; //$NON-NLS-1$ - } - - public Object accept(SimpleValue value) { - return dequalify(value.getTypeName()); - } - - public Object accept(DependantValue value) { - return null; - } - - public Object accept(Component component) { - return dequalify(component.getComponentClassName()); - } - - public Object accept(ManyToOne mto) { - return dequalify(mto.getReferencedEntityName()); - } - - public Object accept(OneToOne oto) { - return dequalify(oto.getEntityName()); - } - -} Index: src/org/hibernate/eclipse/graph/TypeNameValueVisitor.java =================================================================== --- src/org/hibernate/eclipse/graph/TypeNameValueVisitor.java (revision 0) +++ src/org/hibernate/eclipse/graph/TypeNameValueVisitor.java (revision 0) @@ -0,0 +1,112 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.hibernate.eclipse.graph; + +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +public class TypeNameValueVisitor implements ValueVisitor { + + /** if true then only return the classname, not the fully qualified classname */ + final boolean dequalify; + + public TypeNameValueVisitor(boolean dequalify) { + this.dequalify=dequalify; + } + + public Object accept(Bag bag) { + return "Bag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(IdentifierBag bag) { + return "IdBag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(List list) { + return "List <" + list.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(PrimitiveArray primitiveArray) { + return primitiveArray.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Array list) { + return list.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Map map) { + return "Map<" + map.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(OneToMany many) { + return dequalify(many.getReferencedEntityName()); + } + + private String dequalify(String referencedEntityName) { + if(dequalify && referencedEntityName!=null && referencedEntityName.indexOf(".")>=0) { //$NON-NLS-1$ + return referencedEntityName.substring(referencedEntityName.lastIndexOf('.')+1); + } + return referencedEntityName; + } + + public Object accept(Set set) { + return "Set<" + set.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(Any any) { + return "Any"; //$NON-NLS-1$ + } + + public Object accept(SimpleValue value) { + return dequalify(value.getTypeName()); + } + + public Object accept(DependantValue value) { + return null; + } + + public Object accept(Component component) { + return dequalify(component.getComponentClassName()); + } + + public Object accept(ManyToOne mto) { + return dequalify(mto.getReferencedEntityName()); + } + + public Object accept(OneToOne oto) { + return dequalify(oto.getEntityName()); + } + +} Index: src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java (working copy) @@ -1,67 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.util.JoinedIterator; - -public class PersistentClassWorkbenchAdapter implements IWorkbenchAdapter { - - @SuppressWarnings("unchecked") - public Object[] getChildren(Object o) { - PersistentClass pc = (PersistentClass) o; - Property identifierProperty = pc.getIdentifierProperty(); - List properties = new ArrayList(); - - if(identifierProperty!=null) { - properties.add(identifierProperty); - } - - Iterator propertyClosureIterator = new JoinedIterator(properties.iterator(), pc.getPropertyClosureIterator()); - return BasicWorkbenchAdapter.toArray(propertyClosureIterator, Property.class, null); - } - - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.MAPPEDCLASS); - } - - public String getLabel(Object o) { - PersistentClass pc = (PersistentClass) o; - return HibernateWorkbenchHelper.getLabelForClassName(pc.getEntityName()); - } - - public Object getParent(Object o) { - return null; - } - - -} Index: src/org/hibernate/eclipse/console/actions/HQLScratchpadAction.java =================================================================== --- src/org/hibernate/eclipse/console/actions/HQLScratchpadAction.java (revision 43192) +++ src/org/hibernate/eclipse/console/actions/HQLScratchpadAction.java (working copy) @@ -28,6 +28,7 @@ import org.hibernate.eclipse.console.HibernateConsoleMessages; import org.hibernate.eclipse.console.HibernateConsolePlugin; import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -52,6 +53,11 @@ */ protected String generateQuery(TreePath path) { Object node = path.getLastSegment(); + //FIXME: workaround to save previous functionality + if (node instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) node; + node = wrapper.getItem(); + } if (node instanceof PersistentClass){ String name = ((PersistentClass)node).getEntityName(); return "from " + name; //$NON-NLS-1$ @@ -65,11 +71,16 @@ } else { // Generate script for Component property for (int i = path.getSegmentCount() - 2; i > 0; i--) { - if (path.getSegment(i) instanceof PersistentClass){ - enName = ((PersistentClass)path.getSegment(i)).getEntityName(); + Object item = path.getSegment(i); + if (item instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) item; + item = wrapper.getItem(); + } + if (item instanceof PersistentClass){ + enName = ((PersistentClass)item).getEntityName(); enName = enName.substring(enName.lastIndexOf('.') + 1); - } else if (path.getSegment(i) instanceof Property){ - prName = ((Property)path.getSegment(i)).getName() + "." + prName; //$NON-NLS-1$ + } else if (item instanceof Property){ + prName = ((Property)item).getName() + "." + prName; //$NON-NLS-1$ } } } Index: src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (working copy) @@ -1,142 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.osgi.util.NLS; -import org.hibernate.HibernateException; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.JDBCReaderFactory; -import org.hibernate.cfg.Settings; -import org.hibernate.cfg.reveng.DefaultDatabaseCollector; -import org.hibernate.cfg.reveng.JDBCReader; -import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; -import org.hibernate.connection.ConnectionProvider; -import org.hibernate.console.ConsoleConfiguration; -import org.hibernate.console.ImageConstants; -import org.hibernate.console.execution.ExecutionContext; -import org.hibernate.eclipse.console.HibernateConsoleMessages; -import org.hibernate.eclipse.console.HibernateConsolePlugin; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Table; - -public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter { - - public Object[] getChildren(Object o) { - return getChildren(o, new NullProgressMonitor()); - } - - @SuppressWarnings("unchecked") - public Object[] getChildren(Object o, final IProgressMonitor monitor) { - LazyDatabaseSchema dbs = getLazyDatabaseSchema( o ); - dbs.setConnected(false); - dbs.setErrorFlag(false); - ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration(); - Object[] res; - try { - DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy()); - - List result = new ArrayList(); - - Iterator>> qualifierEntries = db.getQualifierEntries(); - while (qualifierEntries.hasNext()) { - Map.Entry> entry = qualifierEntries.next(); - result.add(new TableContainer(entry.getKey(), entry.getValue())); - } - res = toArray(result.iterator(), TableContainer.class, new Comparator() { - public int compare(TableContainer arg0, TableContainer arg1) { - return arg0.getName().compareTo(arg1.getName()); - } - }); - dbs.setConnected(true); - } catch (HibernateException e) { - HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e); - String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage()); - res = new Object[] { out }; - dbs.setErrorFlag(true); - } - return res; - } - - private LazyDatabaseSchema getLazyDatabaseSchema(Object o) { - return (LazyDatabaseSchema) o; - } - - public ImageDescriptor getImageDescriptor(Object object) { - LazyDatabaseSchema dbs = getLazyDatabaseSchema(object); - Map imageMap = new HashMap(); - if (dbs.isConnected()) { - imageMap.put(ImageConstants.OVR_DBS_CONNECTED, OverlayImageIcon.BOTTOM_LEFT); - } - if (dbs.getErrorFlag()) { - imageMap.put(ImageConstants.OVR_WARNING, OverlayImageIcon.BOTTOM_LEFT); - } - return new OverlayImageIcon(EclipseImages.getImage(ImageConstants.TABLE), imageMap); - } - - public String getLabel(Object o) { - return HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_database; - } - - public Object getParent(Object o) { - return getLazyDatabaseSchema(o).getConsoleConfiguration(); - } - - protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) { - final Configuration configuration = consoleConfiguration.buildWith(null, false); - return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() { - - public Object execute() { - DefaultDatabaseCollector db = null; - Settings settings = consoleConfiguration.getSettings(configuration); - ConnectionProvider connectionProvider = null; - try { - connectionProvider = settings.getConnectionProvider(); - - JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy); - db = new DefaultDatabaseCollector(reader.getMetaDataDialect()); - reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor)); - } catch (HibernateException he) { - throw he; - } catch (UnsupportedOperationException he) { - throw new HibernateException(he); - } - finally { - if (connectionProvider != null) { - connectionProvider.close(); - } - } - return db; - } - }); - } - -} Index: src/org/hibernate/eclipse/console/actions/OpenMappingAction.java =================================================================== --- src/org/hibernate/eclipse/console/actions/OpenMappingAction.java (revision 43192) +++ src/org/hibernate/eclipse/console/actions/OpenMappingAction.java (working copy) @@ -34,6 +34,7 @@ import org.hibernate.eclipse.console.HibernateConsolePlugin; import org.hibernate.eclipse.console.utils.OpenMappingUtils; import org.hibernate.eclipse.console.utils.ProjectUtils; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -90,7 +91,11 @@ */ public static IEditorPart run(ConsoleConfiguration consoleConfig, TreePath path) throws PartInitException, JavaModelException, FileNotFoundException { - boolean isPropertySel = (path.getLastSegment().getClass() == Property.class); + Object lastSegment = path.getLastSegment(); + if (lastSegment instanceof HibernateObjectWrapper) { + lastSegment = ((HibernateObjectWrapper) lastSegment).getItem(); + } + boolean isPropertySel = (lastSegment.getClass() == Property.class); if (isPropertySel) { Property propertySel = (Property)path.getLastSegment(); PersistentClass persClass = propertySel.getPersistentClass(); @@ -116,6 +121,9 @@ public static IEditorPart run(ConsoleConfiguration consoleConfig, Object selection, Object selectionParent) throws PartInitException, JavaModelException, FileNotFoundException { IEditorPart editorPart = null; IFile file = null; + if (selection instanceof HibernateObjectWrapper) { + selection = ((HibernateObjectWrapper) selection).getItem(); + } if (selection instanceof Property) { Property p = (Property)selection; if (p.getPersistentClass() != null) { Index: src/org/hibernate/eclipse/graph/IconNameValueVisitor.java =================================================================== --- src/org/hibernate/eclipse/graph/IconNameValueVisitor.java (revision 43192) +++ src/org/hibernate/eclipse/graph/IconNameValueVisitor.java (working copy) @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.hibernate.eclipse.console.workbench; +package org.hibernate.eclipse.graph; import org.hibernate.console.ImageConstants; import org.hibernate.mapping.Any; Index: src/org/hibernate/eclipse/console/workbench/IconNameValueVisitor.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/IconNameValueVisitor.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/IconNameValueVisitor.java (working copy) @@ -1,99 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.hibernate.console.ImageConstants; -import org.hibernate.mapping.Any; -import org.hibernate.mapping.Array; -import org.hibernate.mapping.Bag; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.DependantValue; -import org.hibernate.mapping.IdentifierBag; -import org.hibernate.mapping.List; -import org.hibernate.mapping.ManyToOne; -import org.hibernate.mapping.Map; -import org.hibernate.mapping.OneToMany; -import org.hibernate.mapping.OneToOne; -import org.hibernate.mapping.PrimitiveArray; -import org.hibernate.mapping.Set; -import org.hibernate.mapping.SimpleValue; -import org.hibernate.mapping.ValueVisitor; - -final class IconNameValueVisitor implements ValueVisitor { - - public Object accept(OneToOne oto) { - return ImageConstants.ONETOONE; - } - - public Object accept(ManyToOne mto) { - return ImageConstants.MANYTOONE; - } - - public Object accept(Component component) { - return ImageConstants.COMPONENT; - } - - public Object accept(DependantValue value) { - return ImageConstants.UNKNOWNPROPERTY; - } - - public Object accept(SimpleValue value) { - return ImageConstants.PROPERTY; - } - - public Object accept(Any any) { - return ImageConstants.PROPERTY; - } - - public Object accept(Set set) { - return ImageConstants.MANYTOONE; - } - - public Object accept(OneToMany many) { - return ImageConstants.ONETOMANY; - } - - public Object accept(Map map) { - return ImageConstants.MANYTOONE; - } - - public Object accept(Array list) { - return ImageConstants.MANYTOONE; - } - - public Object accept(PrimitiveArray primitiveArray) { - return ImageConstants.MANYTOONE; - } - - public Object accept(List list) { - return ImageConstants.MANYTOONE; - } - - public Object accept(IdentifierBag bag) { - return ImageConstants.MANYTOONE; - } - - public Object accept(Bag bag) { - return ImageConstants.MANYTOONE; - } - -} \ No newline at end of file Index: src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapperActionFilter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapperActionFilter.java (revision 0) +++ src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapperActionFilter.java (revision 0) @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.hibernate.eclipse.console.workbench.wrapper; + +import org.eclipse.ui.IActionFilter; + +/** + * This IActionFilter implementation is used in plugin.xml as follows (see "org.eclipse.ui.popupMenus" extension point for ex.) + * + * + * + * + * + * + * and check whether hibernate object (item) wrapped by HibernateObjectWrapper is a derivative of specified class + * + * @author Dmitry Geraskov (geraskov@gmail.com) + * + */ +class HibernateObjectWrapperActionFilter implements IActionFilter { + + @Override + public boolean testAttribute(Object target, String name, String value) { + if (target instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) target; + if ("class".equals(name)){ //$NON-NLS-1$ + return wrapper.getItemClass().getName().equals(value); + } else if ("instanceOf".equals(name)){ //$NON-NLS-1$ + return wrapper.isDerivativeOf(value); + } + } + return false; + } + +} Index: src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java (working copy) @@ -1,66 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.HibernateConsoleMessages; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PrimaryKey; - -public class PrimaryKeyWorkbenchAdapter implements IWorkbenchAdapter { - - @SuppressWarnings("unchecked") - public Object[] getChildren(Object o) { - PrimaryKey t = getPrimaryKey( o ); - - if(t.getColumnSpan()==1) { - return new Object[0]; - } else { - return t.getColumns().toArray(new Column[0]); - } - } - - private PrimaryKey getPrimaryKey(Object o) { - return (PrimaryKey)o; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); - } - - public String getLabel(Object o) { - PrimaryKey table = getPrimaryKey(o); - if(table.getColumnSpan()==1) { - return ColumnWorkbenchAdapter.getColumnLabel(table.getColumn(0)); - } else { - return HibernateConsoleMessages.PrimaryKeyWorkbenchAdapter_composite_primary_key; - } - } - - public Object getParent(Object o) { - return getPrimaryKey(o).getTable(); - } - -} Index: src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java (working copy) @@ -1,138 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.mapping.Any; -import org.hibernate.mapping.Array; -import org.hibernate.mapping.Bag; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.DependantValue; -import org.hibernate.mapping.IdentifierBag; -import org.hibernate.mapping.List; -import org.hibernate.mapping.ManyToOne; -import org.hibernate.mapping.Map; -import org.hibernate.mapping.OneToMany; -import org.hibernate.mapping.OneToOne; -import org.hibernate.mapping.PrimitiveArray; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Set; -import org.hibernate.mapping.SimpleValue; -import org.hibernate.mapping.Value; -import org.hibernate.mapping.ValueVisitor; - -public class PropertyWorkbenchAdapter implements IWorkbenchAdapter { - - final static Object[] NO_CHILDREN = new Object[0]; - - public Object[] getChildren(Object o) { - Property p = (Property) o; - - Object[] result = (Object[]) p.getValue().accept(new ValueVisitor() { - - public Object accept(OneToOne oto) { - return NO_CHILDREN; - } - - public Object accept(ManyToOne mto) { - return NO_CHILDREN; - } - - @SuppressWarnings("unchecked") - public Object accept(Component component) { - return BasicWorkbenchAdapter.toArray(component.getPropertyIterator(), Property.class, null); - } - - public Object accept(DependantValue value) { - return NO_CHILDREN; - } - - public Object accept(SimpleValue value) { - return NO_CHILDREN; - } - - public Object accept(Any any) { - return NO_CHILDREN; - } - - public Object accept(Set set) { - return NO_CHILDREN; // should it look up the target entity? - } - - public Object accept(OneToMany many) { - return NO_CHILDREN; - } - - public Object accept(Map map) { - return NO_CHILDREN; - } - - public Object accept(Array list) { - return NO_CHILDREN; - } - - public Object accept(PrimitiveArray primitiveArray) { - return NO_CHILDREN; - } - - public Object accept(List list) { - return NO_CHILDREN; - } - - public Object accept(IdentifierBag bag) { - return NO_CHILDREN; - } - - public Object accept(Bag bag) { - return NO_CHILDREN; - } - }); - - return result; - } - - public ImageDescriptor getImageDescriptor(Object object) { - Property property = ((Property)object); - - return HibernateWorkbenchHelper.getImageDescriptor(property); - } - - public String getLabel(Object o) { - Property property = ((Property)o); - Value value = property.getValue(); - String typeName = (String) value.accept(new TypeNameValueVisitor(true)); - - if (typeName!=null) { - return property.getName() + " : " + typeName; //$NON-NLS-1$ - } - - return property.getName(); - } - - public Object getParent(Object o) { - Property p = (Property) o; - return p.getPersistentClass(); - } - - -} Index: src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java (working copy) @@ -1,64 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.Comparator; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.HibernateConsoleMessages; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Table; - -public class TableContainerWorkbenchAdapter implements IWorkbenchAdapter { - - public Object[] getChildren(Object o) { - TableContainer tc = getTableContainer( o ); - return BasicWorkbenchAdapter.toArray(tc.getTables().iterator(), Table.class, new Comparator
() { - - public int compare(Table arg0, Table arg1) { - - return arg0.getName().compareTo(arg1.getName()); - } - - }); - } - - private TableContainer getTableContainer(Object o) { - return (TableContainer) o; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.SCHEMA); - } - - public String getLabel(Object o) { - String name = getTableContainer(o).getName(); - return "".equals(name)?HibernateConsoleMessages.TableContainerWorkbenchAdapter_default:name; //$NON-NLS-1$ - } - - public Object getParent(Object o) { - return null; - } - -} Index: src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java (working copy) @@ -1,77 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.mapping.Table; - -public class TableWorkbenchAdapter implements IWorkbenchAdapter { - - public Object[] getChildren(Object o) { - Table t = getTable( o ); - - List items = new ArrayList(); - - PrimaryKey primaryKey = t.getPrimaryKey(); - if(primaryKey!=null) { - items.add(primaryKey); - } - - Iterator columnIterator = t.getColumnIterator(); - while ( columnIterator.hasNext() ) { - Column col = (Column) columnIterator.next(); - if(primaryKey==null || !primaryKey.containsColumn(col)) { - items.add(col); // only add non-pk columns here - } - } - - return items.toArray(new Object[items.size()]); - } - - private Table getTable(Object o) { - return (Table) o; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.TABLE); - } - - public String getLabel(Object o) { - Table table = getTable(o); - //return Table.qualify(table.getCatalog(), table.getSchema(), table.getName(), '.'); - return table.getName(); - } - - public Object getParent(Object o) { - return null; - } - -} Index: src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java (working copy) @@ -30,35 +30,23 @@ import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.IPropertySource2; -import org.hibernate.cfg.Configuration; import org.hibernate.console.ConsoleConfiguration; import org.hibernate.console.KnownConfigurations; import org.hibernate.console.node.BaseNode; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Table; -import org.hibernate.mapping.Value; public class ConfigurationAdapterFactory implements IAdapterFactory { - private Class[] classes; - private IWorkbenchAdapter[] adapters; + private IWorkbenchAdapter baseNodeAdapter = new BaseNodeWorkbenchAdapter(); private Class[] deferredClasses; private IDeferredWorkbenchAdapter[] deferredAdapters; - public ConfigurationAdapterFactory() { Map, IDeferredWorkbenchAdapter> deferredMap = new HashMap, IDeferredWorkbenchAdapter>(); deferredMap.put(ConsoleConfiguration.class, new ConsoleConfigurationWorkbenchAdapter()); - deferredMap.put(Configuration.class, new ConfigurationWorkbenchAdapter()); deferredMap.put(KnownConfigurations.class, new KnownConfigurationsWorkbenchAdapter()); - deferredMap.put(LazyDatabaseSchema.class, new LazyDatabaseSchemaWorkbenchAdapter()); - deferredMap.put( LazySessionFactory.class, new LazySessionFactoryAdapter() ); - + deferredMap.put(LazySessionFactory.class, new LazySessionFactoryAdapter() ); deferredClasses = new Class[deferredMap.size()]; deferredAdapters = new IDeferredWorkbenchAdapter[deferredMap.size()]; @@ -69,38 +57,17 @@ deferredAdapters[cnt] = entry.getValue(); cnt++; } - - Map, IWorkbenchAdapter> map = new HashMap, IWorkbenchAdapter>(); - map.put(TableContainer.class, new TableContainerWorkbenchAdapter()); - map.put(PersistentClass.class, new PersistentClassWorkbenchAdapter()); - map.put(Property.class, new PropertyWorkbenchAdapter()); - map.put(Value.class, new ValueWorkbenchAdapter()); - map.put(Table.class, new TableWorkbenchAdapter()); - map.put(PrimaryKey.class, new PrimaryKeyWorkbenchAdapter()); - map.put(Column.class, new ColumnWorkbenchAdapter()); - map.put(BaseNode.class, new BaseNodeWorkbenchAdapter()); - - - - classes = new Class[map.size()]; - adapters = new IWorkbenchAdapter[map.size()]; - cnt = 0; - for (Map.Entry, IWorkbenchAdapter> entry : map.entrySet()) { - classes[cnt] = entry.getKey(); - adapters[cnt] = entry.getValue(); - cnt++; - } } @SuppressWarnings("rawtypes") public Object getAdapter(Object adaptableObject, Class adapterType) { - if(adapterType==IDeferredWorkbenchAdapter.class){ + if(adapterType == IDeferredWorkbenchAdapter.class){ return getDeferredAdapter( adaptableObject ); - } else if (adapterType==IWorkbenchAdapter.class){ + } else if (adapterType == IWorkbenchAdapter.class){ Object adapter = getAdapter( adaptableObject ); return adapter != null ? adapter : getDeferredAdapter( adaptableObject ); } - if(adapterType==IPropertySource2.class || adapterType==IPropertySource.class) { + if(adapterType == IPropertySource2.class || adapterType == IPropertySource.class) { return getPropertySource(adaptableObject); } return null; @@ -122,24 +89,19 @@ } private Object getAdapter(Object adaptableObject) { - for (int i = 0; i < classes.length; i++) { - Class clazz = classes[i]; - if (clazz.isInstance(adaptableObject)) { - return adapters[i]; - } - } + if (BaseNode.class.isInstance(adaptableObject)){ + return baseNodeAdapter; + } return null; } public Class[] getAdapterList() { - return new Class[] { IDeferredWorkbenchAdapter.class, IWorkbenchAdapter.class, IPropertySource.class, IPropertySource2.class }; + return new Class[] { IDeferredWorkbenchAdapter.class, IWorkbenchAdapter.class, + IPropertySource.class, IPropertySource2.class}; } public void registerAdapters(IAdapterManager adapterManager) { - for (int i = 0; i < classes.length; i++) { - Class clazz = classes[i]; - adapterManager.registerAdapters(this, clazz); - } + adapterManager.registerAdapters(this, BaseNode.class); for (int i = 0; i < deferredClasses.length; i++) { Class clazz = deferredClasses[i]; adapterManager.registerAdapters(this, clazz); Index: src/org/hibernate/eclipse/graph/EntityGraphView.java =================================================================== --- src/org/hibernate/eclipse/graph/EntityGraphView.java (revision 43192) +++ src/org/hibernate/eclipse/graph/EntityGraphView.java (working copy) @@ -27,6 +27,7 @@ import org.hibernate.eclipse.console.ConsolePreferencesConstants; import org.hibernate.eclipse.console.HibernateConsolePlugin; import org.hibernate.eclipse.console.views.KnownConfigurationsView; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.eclipse.graph.model.ConfigurationViewAdapter; import org.hibernate.eclipse.graph.parts.ConfigurationEditPart; @@ -49,6 +50,9 @@ protected void selectionChanged(IStructuredSelection ss) { Object o = ss.getFirstElement(); + if (o instanceof HibernateObjectWrapper) { + o = ((HibernateObjectWrapper) o).getItem(); + } if (o instanceof Configuration) { viewer.setContents(new ConfigurationViewAdapter((Configuration) o)); boolean b = HibernateConsolePlugin.getDefault().getPluginPreferences().getBoolean(ConsolePreferencesConstants.ENTITY_MODEL_LAYOUT); Index: src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java =================================================================== --- src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java (revision 43192) +++ src/org/hibernate/eclipse/console/views/KnownConfigurationsView.java (working copy) @@ -58,6 +58,7 @@ import org.hibernate.eclipse.console.actions.EditConsoleConfiguration; import org.hibernate.eclipse.console.actions.OpenMappingAction; import org.hibernate.eclipse.console.viewers.xpl.MTreeViewer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.eclipse.console.workbench.xpl.AnyAdaptableLabelProvider; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -196,6 +197,9 @@ TreePath[] paths = ((TreeSelection)selection).getPaths(); TreePath path = paths[0]; Object last = path.getLastSegment(); + if (last instanceof HibernateObjectWrapper) { + last = ((HibernateObjectWrapper) firstElement).getItem(); + } ConsoleConfiguration consoleConfig = (ConsoleConfiguration)(path.getSegment(0)); if (last instanceof PersistentClass || last.getClass() == Property.class){ try { Index: src/org/hibernate/eclipse/console/workbench/TableModelList.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/TableModelList.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/TableModelList.java (working copy) @@ -1,77 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.ArrayList; -import java.util.List; -import java.util.Observable; - -/** simple list to be used in e.g. tables */ -public abstract class TableModelList extends Observable { - - final protected List filters; - - public TableModelList() { - this(new ArrayList()); - } - - public TableModelList(List queryParameterList) { - filters = queryParameterList; - } - - public void moveUp(Object tf) { - move( tf, -1 ); - } - - private void move(Object tf, int shift) { - int i = filters.indexOf(tf); - - if(i>=0) { - if(i+shift=0) { - filters.remove(i); - filters.add(i+shift, tf); - } - } - setChanged(); - notifyObservers(); - } - - public void moveDown(Object tf) { - move( tf, 1 ); - } - - protected void add(Object tf) { - filters.add(tf); - setChanged(); - notifyObservers(); - } - - protected void remove(Object tf) { - filters.remove(tf); - setChanged(); - notifyObservers(); - } - - public List getList() { - return filters; - } -} Index: src/org/hibernate/eclipse/graph/HibernateWorkbenchHelper.java =================================================================== --- src/org/hibernate/eclipse/graph/HibernateWorkbenchHelper.java (revision 43192) +++ src/org/hibernate/eclipse/graph/HibernateWorkbenchHelper.java (working copy) @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.hibernate.eclipse.console.workbench; +package org.hibernate.eclipse.graph; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; Index: src/org/hibernate/eclipse/graph/parts/PersistentClassEditPart.java =================================================================== --- src/org/hibernate/eclipse/graph/parts/PersistentClassEditPart.java (revision 43192) +++ src/org/hibernate/eclipse/graph/parts/PersistentClassEditPart.java (working copy) @@ -27,7 +27,7 @@ import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPolicy; -import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper; +import org.hibernate.eclipse.graph.HibernateWorkbenchHelper; import org.hibernate.eclipse.graph.figures.PersistentClassFigure; import org.hibernate.eclipse.graph.model.PersistentClassViewAdapter; import org.hibernate.eclipse.graph.model.PropertyViewAdapter; Index: src/org/hibernate/eclipse/console/workbench/HibernateWorkbenchHelper.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/HibernateWorkbenchHelper.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/HibernateWorkbenchHelper.java (working copy) @@ -1,76 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Value; -import org.hibernate.util.xpl.StringHelper; - -public class HibernateWorkbenchHelper { - - public static ImageDescriptor getImageDescriptor(Property property) { - if(property==null) return null; - if(property.getPersistentClass()!=null) { - if(property.getPersistentClass().getIdentifierProperty()==property) { - return EclipseImages.getImageDescriptor(ImageConstants.IDPROPERTY); - } - } - String iconNameForValue = getIconNameForValue(property.getValue()); - - return EclipseImages.getImageDescriptor(iconNameForValue); - } - - public static Image getImage(Property property) { - if(property==null) return null; - if(property.getPersistentClass()!=null) { - if(property.getPersistentClass().getIdentifierProperty()==property) { - return EclipseImages.getImage(ImageConstants.IDPROPERTY); - } - } - String iconNameForValue = getIconNameForValue(property.getValue()); - - return EclipseImages.getImage(iconNameForValue); - } - - static private String getIconNameForValue(Value value) { - String result; - - result = (String) value.accept(new IconNameValueVisitor()); - - if(result==null) { - result = ImageConstants.UNKNOWNPROPERTY; - } - return result; - } - - public static String getLabelForClassName(String classOrEntityName) { - if(classOrEntityName.indexOf('.')>=0) { - classOrEntityName = StringHelper.unqualify(classOrEntityName); - } - return classOrEntityName; - } - -} Index: src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapper.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapper.java (revision 0) +++ src/org/hibernate/eclipse/console/workbench/wrapper/HibernateObjectWrapper.java (revision 0) @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.hibernate.eclipse.console.workbench.wrapper; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.ui.IActionFilter; +import org.hibernate.console.ConsoleConfiguration; + +/** + * + * @author Dmitry Geraskov (geraskov@gmail.com) + * + */ +public class HibernateObjectWrapper implements IAdaptable { + + private ConsoleConfiguration cc; + + private Object item; + + //this map holds "allParents" for each class we need + //seems no need to use weak reference here + private static Map, Set> allParents = new HashMap, Set>(); + + private static final HibernateObjectWrapperActionFilter hiberanateActionFilter = new HibernateObjectWrapperActionFilter(); + + public HibernateObjectWrapper(ConsoleConfiguration cc, Object item){ + this.cc = cc; + this.item = item; + } + + public ConsoleConfiguration getConsoleConfiguration() { + return cc; + } + + public Object getItem(){ + return item; + } + + public Class getItemClass(){ + return getItem().getClass(); + } + + /** + * + * @param superClass + * @return true if item's class is a derivative of the superClass + */ + public boolean isDerivativeOf(String superClass){ + if (allParents.containsKey(getItemClass())){ + Set set = new HashSet(); + collectParentClasses(getItemClass(), set); + allParents.put(getItemClass(), set); + } + return allParents.get(getItemClass()).contains(superClass); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IActionFilter.class){ + return hiberanateActionFilter; + } + IAdapterFactory factory = getAdapterFactory(); + //TODO not sure we should check factory.getAdapterList() here + return factory != null ? factory.getAdapter(getItem(), adapter) : null; + } + + protected IAdapterFactory getAdapterFactory(){ + return cc.getHibernateExtension().getAdapterFactory(); + } + + private void collectParentClasses(Class clazz, Set parentClasses){ + if (clazz != null){ + if (allParents.containsKey(clazz)){//short circuit + parentClasses.addAll(allParents.get(clazz)); + } else { + boolean newlyAdded = parentClasses.add(clazz.getName()); + if (newlyAdded){ + collectParentClasses(clazz.getSuperclass(), parentClasses);//add superclass hierarchy + for (Class interfacee : clazz.getInterfaces()) {//add interfaces hierarchy + collectParentClasses(interfacee, parentClasses); + } + } + } + } + } + + public static Object[] wrap(ConsoleConfiguration cc, Object[] items){ + HibernateObjectWrapper[] res = new HibernateObjectWrapper[items.length]; + for (int i = 0; i < items.length; i++) { + res[i] = new HibernateObjectWrapper(cc, items[i]); + } + return res; + } + +} Index: src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java (working copy) @@ -1,62 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.hibernate.cfg.reveng.JDBCToHibernateTypeHelper; -import org.hibernate.console.ImageConstants; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.Column; - -public class ColumnWorkbenchAdapter implements IWorkbenchAdapter { - - public Object[] getChildren(Object o) { - return new Object[0]; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); - } - - public String getLabel(Object o) { - Column c = (Column) o; - return getColumnLabel( c ); - } - - static String getColumnLabel(Column c) { - String label = c.getName(); - if(c.getSqlTypeCode()!=null) { - label += " : " + JDBCToHibernateTypeHelper.getJDBCTypeName(c.getSqlTypeCode().intValue()); //$NON-NLS-1$ - } - return label; - } - - public Object getParent(Object o) { - return null; - } - - public boolean isContainer() { - return false; - } - -} Index: src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java =================================================================== --- src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java (revision 43192) +++ src/org/hibernate/eclipse/console/views/ConfigurationsViewActionGroup.java (working copy) @@ -43,6 +43,7 @@ import org.hibernate.eclipse.console.actions.OpenSourceAction; import org.hibernate.eclipse.console.actions.RefreshAction; import org.hibernate.eclipse.console.actions.RenameAction; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -157,6 +158,9 @@ return; } Object first = selection.getFirstElement(); + if (first instanceof HibernateObjectWrapper) { + first = ((HibernateObjectWrapper) first).getItem(); + } menu.add(new Separator(GROUP_PRIMAL_EDITORS)); menu.appendToGroup(GROUP_PRIMAL_EDITORS, hqlEditorAction); menu.appendToGroup(GROUP_PRIMAL_EDITORS, criteriaEditorAction); Index: src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/ConfigurationWorkbenchAdapter.java (working copy) @@ -1,70 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.hibernate.eclipse.console.workbench; - -import java.util.Comparator; -import java.util.Iterator; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.hibernate.cfg.Configuration; -import org.hibernate.console.ImageConstants; -import org.hibernate.console.KnownConfigurations; -import org.hibernate.eclipse.console.HibernateConsoleMessages; -import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.mapping.PersistentClass; - -public class ConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter { - - @SuppressWarnings("unchecked") - public Object[] getChildren(Object o) { - Configuration cfg = (Configuration) o; - Iterator classMappings = cfg.getClassMappings(); - return toArray(classMappings, PersistentClass.class, new Comparator() { - - public int compare(PersistentClass p0, PersistentClass p1) { - String label0 = HibernateWorkbenchHelper.getLabelForClassName(p0.getEntityName()); - String label1 = HibernateWorkbenchHelper.getLabelForClassName(p1.getEntityName()); - return label0.compareTo(label1); - } - - }); - } - - public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.CONFIGURATION); - } - - public String getLabel(Object o) { - return HibernateConsoleMessages.ConfigurationWorkbenchAdapter_configuration; - } - - public Object getParent(Object o) { - return KnownConfigurations.getInstance(); - } - - public boolean isContainer() { - return true; - } - - - -} Index: src/org/hibernate/eclipse/console/workbench/DeferredContentProvider.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/DeferredContentProvider.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/DeferredContentProvider.java (working copy) @@ -89,10 +89,13 @@ } protected IDeferredWorkbenchAdapter getAdapter(Object element) { - if (element instanceof IDeferredWorkbenchAdapter) { - return (IDeferredWorkbenchAdapter) element; + Object adapter = null; + if (element instanceof IAdaptable) { + adapter = ((IAdaptable) element).getAdapter(IDeferredWorkbenchAdapter.class); } - Object adapter = Platform.getAdapterManager().getAdapter(element, IDeferredWorkbenchAdapter.class); + if (adapter == null){ + adapter = Platform.getAdapterManager().getAdapter(element, IDeferredWorkbenchAdapter.class); + } return (IDeferredWorkbenchAdapter) adapter; } Index: src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java (revision 43192) +++ src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java (working copy) @@ -23,12 +23,12 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; -import org.hibernate.cfg.Configuration; import org.hibernate.console.ConsoleConfiguration; import org.hibernate.console.ImageConstants; import org.hibernate.console.KnownConfigurations; import org.hibernate.eclipse.console.HibernateConsoleMessages; import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; public class ConsoleConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter { @@ -53,25 +53,14 @@ }*/ - Configuration configuration = ccfg.getConfiguration(); Object o1; - if(configuration!=null) { - o1 = configuration; + if(ccfg.getHibernateExtension().hasConfiguration()) { + o1 = new HibernateObjectWrapper(ccfg, ccfg.getHibernateExtension().getConfiguration()); } else { o1 = HibernateConsoleMessages.ConsoleConfigurationWorkbenchAdapter_empty_configuration; } - /*Object o2; - - if(sfError==null) { - NodeFactory fac = new NodeFactory(ccfg); - ConfigurationEntitiesNode cfgNode = fac.createConfigurationEntitiesNode("Session factory"); - o2 = cfgNode; - } else { - o2 = sfError; - }*/ - - return new Object[] { o1, new LazySessionFactory(ccfg), new LazyDatabaseSchema(ccfg) }; + return new Object[] {o1, new LazySessionFactory(ccfg), new LazyDatabaseSchema(ccfg) }; } private ConsoleConfiguration getConsoleConfiguration(Object o) { #P org.hibernate.eclipse Index: src/org/hibernate/console/ext/HibernateExtension.java =================================================================== --- src/org/hibernate/console/ext/HibernateExtension.java (revision 43192) +++ src/org/hibernate/console/ext/HibernateExtension.java (working copy) @@ -10,6 +10,7 @@ ******************************************************************************/ package org.hibernate.console.ext; +import org.eclipse.core.runtime.IAdapterFactory; import org.hibernate.console.QueryInputModel; import org.hibernate.console.QueryPage; import org.hibernate.console.execution.ExecutionContext.Command; @@ -44,10 +45,10 @@ //FIXME remove this method public boolean hasConfiguration(); - /* + //FIXME remove this method public Object getConfiguration(); - //FIXME remove this method + /*//FIXME remove this method public Object getSessionFactory(); //FIXME remove this method */ @@ -60,4 +61,6 @@ public String getConsoleConfigurationName(); + public IAdapterFactory getAdapterFactory(); + } Index: src/org/hibernate/console/ConsoleConfiguration.java =================================================================== --- src/org/hibernate/console/ConsoleConfiguration.java (revision 43192) +++ src/org/hibernate/console/ConsoleConfiguration.java (working copy) @@ -52,6 +52,8 @@ import org.hibernate.tool.hbm2x.StringUtils; public class ConsoleConfiguration implements ExecutionContextHolder { + + public static final String DEFAULT_HIBERNATE_VERSION = "3.5"; //$NON-NLS-1$ private ExecutionContext executionContext; private ConsoleConfigClassLoader classLoader = null; @@ -68,7 +70,7 @@ private HibernateExtension extension; private void loadHibernateExtension(){ - String version = hibernateVersion == null ? "3.5" : hibernateVersion;//3.5 is a default version + String version = hibernateVersion == null ? DEFAULT_HIBERNATE_VERSION : hibernateVersion; HibernateExtensionDefinition def = HibernateExtensionManager.findHibernateExtensionDefinition(version); if (def != null){ HibernateExtension hibernateExtension = def.createHibernateExtensionInstance(); #P org.jboss.tools.hibernate.jpt.ui Index: .settings/org.eclipse.jdt.core.prefs =================================================================== --- .settings/org.eclipse.jdt.core.prefs (revision 43192) +++ .settings/org.eclipse.jdt.core.prefs (working copy) @@ -1,6 +1,13 @@ -#Fri Apr 01 10:54:40 EEST 2011 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -9,6 +16,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore @@ -62,3 +70,4 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 #P org.hibernate.eclipse.console.test Index: src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java =================================================================== --- src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java (revision 43192) +++ src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java (working copy) @@ -16,10 +16,12 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.model.IWorkbenchAdapter; import org.hibernate.console.ConsoleConfiguration; import org.hibernate.eclipse.console.actions.OpenSourceAction; import org.hibernate.eclipse.console.test.ConsoleTestMessages; import org.hibernate.eclipse.console.test.utils.Utils; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -42,30 +44,38 @@ final Object[] persClasses = getPersistenceClasses(false); final ConsoleConfiguration consCFG = getConsoleConfig(); for (int i = 0; i < persClasses.length; i++) { - assertTrue(persClasses[i] instanceof PersistentClass); - PersistentClass persClass = (PersistentClass) persClasses[i]; + assertTrue(persClasses[i] instanceof HibernateObjectWrapper); + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)persClasses[i]; + PersistentClass persClass = (PersistentClass) wrapper.getItem(); String fullyQualifiedName = persClass.getClassName(); // test PersistentClasses - openTest(persClass, consCFG, fullyQualifiedName); - Object[] fields = pcWorkbenchAdapter.getChildren(persClass); + openTest(wrapper, consCFG, fullyQualifiedName); + IWorkbenchAdapter adapter = getAdapter(wrapper); + assertNotNull(adapter); + Object[] fields = adapter.getChildren(wrapper); for (int j = 0; j < fields.length; j++) { - if (fields[j].getClass() != Property.class) { + assertTrue(fields[j] instanceof HibernateObjectWrapper); + HibernateObjectWrapper propWrapepr = (HibernateObjectWrapper)fields[j]; + if (propWrapepr.getItemClass() != Property.class) { continue; } + Property property = (Property)propWrapepr.getItem(); fullyQualifiedName = persClass.getClassName(); // test Properties - openTest(fields[j], consCFG, fullyQualifiedName); - if (fields[j] instanceof Property - && ((Property)fields[j]).isComposite()) { - fullyQualifiedName =((Component)((Property) fields[j]).getValue()).getComponentClassName(); - - Object[] compProperties = propertyWorkbenchAdapter.getChildren(fields[j]); + openTest(propWrapepr, consCFG, fullyQualifiedName); + if (property.isComposite()) { + fullyQualifiedName =((Component)property.getValue()).getComponentClassName(); + IWorkbenchAdapter propAdapter = getAdapter(fields[j]); + assertNotNull(propAdapter); + Object[] compProperties = propAdapter.getChildren(fields[j]); for (int k = 0; k < compProperties.length; k++) { - if (compProperties[k].getClass() != Property.class) { + assertTrue(compProperties[k] instanceof HibernateObjectWrapper); + HibernateObjectWrapper compRrop = (HibernateObjectWrapper)compProperties[k]; + if (compRrop.getItemClass() != Property.class) { continue; } //test Composite properties - openTest(compProperties[k], consCFG, fullyQualifiedName); + openTest(compRrop, consCFG, fullyQualifiedName); } } } Index: src/org/hibernate/eclipse/console/test/mappingproject/CheckConsoleConfigTest.java =================================================================== --- src/org/hibernate/eclipse/console/test/mappingproject/CheckConsoleConfigTest.java (revision 43192) +++ src/org/hibernate/eclipse/console/test/mappingproject/CheckConsoleConfigTest.java (working copy) @@ -10,6 +10,7 @@ ******************************************************************************/ package org.hibernate.eclipse.console.test.mappingproject; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; /** @@ -28,7 +29,8 @@ Object[] persClasses = getPersistenceClasses(true); assertTrue(persClasses.length > 0); for (int i = 0; i < persClasses.length; i++) { - assertTrue(persClasses[i] instanceof PersistentClass); + assertTrue(persClasses[i] instanceof HibernateObjectWrapper); + assertTrue(((HibernateObjectWrapper)persClasses[i]).getItem() instanceof PersistentClass); } } } Index: src/org/hibernate/eclipse/console/test/mappingproject/BaseTestSetCase.java =================================================================== --- src/org/hibernate/eclipse/console/test/mappingproject/BaseTestSetCase.java (revision 43192) +++ src/org/hibernate/eclipse/console/test/mappingproject/BaseTestSetCase.java (working copy) @@ -18,15 +18,15 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; import org.hibernate.InvalidMappingException; -import org.hibernate.cfg.Configuration; import org.hibernate.console.ConsoleConfiguration; import org.hibernate.console.KnownConfigurations; import org.hibernate.eclipse.console.test.ConsoleTestMessages; -import org.hibernate.eclipse.console.workbench.ConfigurationWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.ConfigurationAdapterFactory; import org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter; -import org.hibernate.eclipse.console.workbench.PersistentClassWorkbenchAdapter; -import org.hibernate.eclipse.console.workbench.PropertyWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; /** * @author vy (vyemialyanchyk@gmail.com) @@ -40,12 +40,8 @@ protected IPackageFragment testPackage = null; final static protected ConsoleConfigurationWorkbenchAdapter ccWorkbenchAdapter = new ConsoleConfigurationWorkbenchAdapter(); - - final static protected ConfigurationWorkbenchAdapter configWorkbenchAdapter = new ConfigurationWorkbenchAdapter(); - - final static protected PersistentClassWorkbenchAdapter pcWorkbenchAdapter = new PersistentClassWorkbenchAdapter(); - final static protected PropertyWorkbenchAdapter propertyWorkbenchAdapter = new PropertyWorkbenchAdapter(); + final static protected ConfigurationAdapterFactory factory = new ConfigurationAdapterFactory(); public BaseTestSetCase() { } @@ -79,8 +75,10 @@ configs = ccWorkbenchAdapter.getChildren(consCFG); assertNotNull(configs); assertEquals(3, configs.length); - assertTrue(configs[0] instanceof Configuration); - persClasses = configWorkbenchAdapter.getChildren(configs[0]); + assertTrue(configs[0] instanceof HibernateObjectWrapper); + IWorkbenchAdapter adapter = getAdapter(configs[0]); + assertNotNull(adapter); + persClasses = adapter.getChildren(configs[0]); } catch (InvalidMappingException ex) { String out = NLS.bind(ConsoleTestMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testPackage.getElementName(), ex.getMessage() }); @@ -88,6 +86,14 @@ } return persClasses; } + + protected IWorkbenchAdapter getAdapter(Object adaptable){ + IWorkbenchAdapter adapter = (IWorkbenchAdapter) factory.getAdapter(adaptable, IDeferredWorkbenchAdapter.class); + if (adapter == null){ + adapter = (IWorkbenchAdapter) factory.getAdapter(adaptable, IWorkbenchAdapter.class); + } + return adapter; + } public ConsoleConfiguration getConsoleConfig() { KnownConfigurations knownConfigurations = KnownConfigurations.getInstance(); Index: src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java =================================================================== --- src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java (revision 43192) +++ src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagramTest.java (working copy) @@ -16,6 +16,7 @@ import org.hibernate.console.ConsoleConfiguration; import org.hibernate.eclipse.console.test.ConsoleTestMessages; import org.hibernate.eclipse.console.test.utils.Utils; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; import org.jboss.tools.hibernate.ui.view.OpenDiagramActionDelegate; @@ -36,8 +37,9 @@ final Object[] persClasses = getPersistenceClasses(false); final ConsoleConfiguration consCFG = getConsoleConfig(); for (int i = 0; i < persClasses.length; i++) { - assertTrue(persClasses[i] instanceof PersistentClass); - PersistentClass persClass = (PersistentClass) persClasses[i]; + assertTrue(persClasses[i] instanceof HibernateObjectWrapper); + assertTrue(((HibernateObjectWrapper)persClasses[i]).getItem() instanceof PersistentClass); + PersistentClass persClass = (PersistentClass)((HibernateObjectWrapper)persClasses[i]).getItem(); IEditorPart editor = null; Throwable ex = null; Index: src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java =================================================================== --- src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java (revision 43192) +++ src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java (working copy) @@ -16,10 +16,12 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.model.IWorkbenchAdapter; import org.hibernate.console.ConsoleConfiguration; import org.hibernate.eclipse.console.actions.OpenMappingAction; import org.hibernate.eclipse.console.test.ConsoleTestMessages; import org.hibernate.eclipse.console.test.utils.Utils; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -41,33 +43,44 @@ final ConsoleConfiguration consCFG = getConsoleConfig(); final String testClass = "class"; //$NON-NLS-1$ for (int i = 0; i < persClasses.length; i++) { - assertTrue(persClasses[i] instanceof PersistentClass); - PersistentClass persClass = (PersistentClass) persClasses[i]; - openTest(persClass, consCFG); - Object[] props = pcWorkbenchAdapter.getChildren(persClass); + assertTrue(persClasses[i] instanceof HibernateObjectWrapper); + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)persClasses[i]; + assertTrue(wrapper.getItem() instanceof PersistentClass); + openTest(wrapper, consCFG); + IWorkbenchAdapter adapter = getAdapter(wrapper); + assertNotNull(adapter); + Object[] props = adapter.getChildren(wrapper); for (int j = 0; j < props.length; j++) { - if (props[j].getClass() != Property.class) { + assertTrue(props[j] instanceof HibernateObjectWrapper); + HibernateObjectWrapper propWrapper = (HibernateObjectWrapper)props[j]; + if (propWrapper.getItemClass() != Property.class) { continue; } - openTest(props[j], consCFG); - Object[] compProperties = propertyWorkbenchAdapter.getChildren(props[j]); + openTest(propWrapper, consCFG); + IWorkbenchAdapter propAdapter = getAdapter(propWrapper); + assertNotNull(adapter); + Object[] compProperties = propAdapter.getChildren(propWrapper); for (int k = 0; k < compProperties.length; k++) { + assertTrue(compProperties[k] instanceof HibernateObjectWrapper); + HibernateObjectWrapper compRrop = (HibernateObjectWrapper)compProperties[k]; //test Composite properties - if (compProperties[k].getClass() != Property.class) { + if (compRrop.getItemClass() != Property.class) { continue; } - final Property prop = (Property)compProperties[k]; + final Property prop = (Property)compRrop.getItem(); if (testClass.equals(prop.getNodeName()) || testClass.equals(prop.getName())) { continue; } - openPropertyTest((Property)compProperties[k], (Property) props[j], consCFG); + openPropertyTest(compRrop, propWrapper, consCFG); } } } //close all editors } - private void openPropertyTest(Property compositeProperty, Property parentProperty, ConsoleConfiguration consCFG){ + private void openPropertyTest(HibernateObjectWrapper compositePropertyWrapper, HibernateObjectWrapper parentPropertyWrapper, ConsoleConfiguration consCFG){ + Property compositeProperty = (Property) compositePropertyWrapper.getItem(); + Property parentProperty = (Property) parentPropertyWrapper.getItem(); IEditorPart editor = null; Throwable ex = null; try { @@ -80,10 +93,12 @@ System.err.println(out); fail(out); } - Object[] compProperties = propertyWorkbenchAdapter.getChildren(compositeProperty); + IWorkbenchAdapter adapter = getAdapter(compositePropertyWrapper); + assertNotNull(adapter); + Object[] compProperties = adapter.getChildren(compositePropertyWrapper); for (int k = 0; k < compProperties.length; k++) { //test Composite properties - assertTrue(compProperties[k] instanceof Property); + assertTrue(((HibernateObjectWrapper)compProperties[k]).getItem() instanceof Property); // use only first level to time safe //openPropertyTest((Property)compProperties[k], compositeProperty, consCFG); } #P org.jboss.tools.hibernate3_5 Index: src/org/jboss/tools/hibernate3_5/console/workbench/PrimaryKeyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/PrimaryKeyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; + +public class PrimaryKeyWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey t = getPrimaryKey( wrapper.getItem() ); + + if(t.getColumnSpan()==1) { + return new Object[0]; + } else { + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + t.getColumns().toArray(new Column[0])); + } + } + + private PrimaryKey getPrimaryKey(Object o) { + return (PrimaryKey)o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PrimaryKey table = getPrimaryKey(wrapper.getItem()); + if(table.getColumnSpan()==1) { + return ColumnWorkbenchAdapter.getColumnLabel(table.getColumn(0)); + } else { + return HibernateConsoleMessages.PrimaryKeyWorkbenchAdapter_composite_primary_key; + } + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/PropertyWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/PropertyWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/PropertyWorkbenchAdapter.java (revision 0) @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.Value; +import org.hibernate.mapping.ValueVisitor; + +public class PropertyWorkbenchAdapter implements IWorkbenchAdapter { + + final static Object[] NO_CHILDREN = new Object[0]; + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property p = (Property) wrapper.getItem(); + + Object[] result = (Object[]) p.getValue().accept(new ValueVisitor() { + + public Object accept(OneToOne oto) { + return NO_CHILDREN; + } + + public Object accept(ManyToOne mto) { + return NO_CHILDREN; + } + + @SuppressWarnings("unchecked") + public Object accept(Component component) { + return BasicWorkbenchAdapter.toArray(component.getPropertyIterator(), Property.class, null); + } + + public Object accept(DependantValue value) { + return NO_CHILDREN; + } + + public Object accept(SimpleValue value) { + return NO_CHILDREN; + } + + public Object accept(Any any) { + return NO_CHILDREN; + } + + public Object accept(Set set) { + return NO_CHILDREN; // should it look up the target entity? + } + + public Object accept(OneToMany many) { + return NO_CHILDREN; + } + + public Object accept(Map map) { + return NO_CHILDREN; + } + + public Object accept(Array list) { + return NO_CHILDREN; + } + + public Object accept(PrimitiveArray primitiveArray) { + return NO_CHILDREN; + } + + public Object accept(List list) { + return NO_CHILDREN; + } + + public Object accept(IdentifierBag bag) { + return NO_CHILDREN; + } + + public Object accept(Bag bag) { + return NO_CHILDREN; + } + }); + + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), result); + } + + public ImageDescriptor getImageDescriptor(Object object) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)object; + Property p = (Property) wrapper.getItem(); + + return HibernateWorkbenchHelper.getImageDescriptor(p); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Property property = (Property) wrapper.getItem(); + Value value = property.getValue(); + String typeName = (String) value.accept(new TypeNameValueVisitor(true)); + + if (typeName!=null) { + return property.getName() + " : " + typeName; //$NON-NLS-1$ + } + + return property.getName(); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/HibernateWorkbenchHelper.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/HibernateWorkbenchHelper.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/HibernateWorkbenchHelper.java (revision 0) @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Value; +import org.hibernate.util.xpl.StringHelper; + +public class HibernateWorkbenchHelper { + + public static ImageDescriptor getImageDescriptor(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImageDescriptor(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImageDescriptor(iconNameForValue); + } + + public static Image getImage(Property property) { + if(property==null) return null; + if(property.getPersistentClass()!=null) { + if(property.getPersistentClass().getIdentifierProperty()==property) { + return EclipseImages.getImage(ImageConstants.IDPROPERTY); + } + } + String iconNameForValue = getIconNameForValue(property.getValue()); + + return EclipseImages.getImage(iconNameForValue); + } + + static private String getIconNameForValue(Value value) { + String result; + + result = (String) value.accept(new IconNameValueVisitor()); + + if(result==null) { + result = ImageConstants.UNKNOWNPROPERTY; + } + return result; + } + + public static String getLabelForClassName(String classOrEntityName) { + if(classOrEntityName.indexOf('.')>=0) { + classOrEntityName = StringHelper.unqualify(classOrEntityName); + } + return classOrEntityName; + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 0) @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.osgi.util.NLS; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.JDBCReaderFactory; +import org.hibernate.cfg.Settings; +import org.hibernate.cfg.reveng.DefaultDatabaseCollector; +import org.hibernate.cfg.reveng.JDBCReader; +import org.hibernate.cfg.reveng.ReverseEngineeringStrategy; +import org.hibernate.connection.ConnectionProvider; +import org.hibernate.console.ConsoleConfiguration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.execution.ExecutionContext; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.HibernateConsolePlugin; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.OverlayImageIcon; +import org.hibernate.eclipse.console.workbench.ProgressListenerMonitor; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; +import org.jboss.tools.hibernate3_5.HibernateExtension3_5; + +public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return getChildren(o, new NullProgressMonitor()); + } + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o, final IProgressMonitor monitor) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema( o ); + dbs.setConnected(false); + dbs.setErrorFlag(false); + ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration(); + Object[] res; + try { + DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy()); + + List result = new ArrayList(); + + Iterator>> qualifierEntries = db.getQualifierEntries(); + while (qualifierEntries.hasNext()) { + Map.Entry> entry = qualifierEntries.next(); + List tables = new LinkedList(); + for (Table table : entry.getValue()) { + tables.add(new HibernateObjectWrapper(consoleConfiguration, table)); + } + result.add(new TableContainer(consoleConfiguration, entry.getKey(), tables)); + } + res = toArray(result.iterator(), TableContainer.class, new Comparator() { + public int compare(TableContainer arg0, TableContainer arg1) { + return arg0.getName().compareTo(arg1.getName()); + } + }); + dbs.setConnected(true); + } catch (HibernateException e) { + HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e); + String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage()); + res = new Object[] { out }; + dbs.setErrorFlag(true); + } + return res; + } + + private LazyDatabaseSchema getLazyDatabaseSchema(Object o) { + return (LazyDatabaseSchema) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + LazyDatabaseSchema dbs = getLazyDatabaseSchema(object); + Map imageMap = new HashMap(); + if (dbs.isConnected()) { + imageMap.put(ImageConstants.OVR_DBS_CONNECTED, OverlayImageIcon.BOTTOM_LEFT); + } + if (dbs.getErrorFlag()) { + imageMap.put(ImageConstants.OVR_WARNING, OverlayImageIcon.BOTTOM_LEFT); + } + return new OverlayImageIcon(EclipseImages.getImage(ImageConstants.TABLE), imageMap); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_database; + } + + public Object getParent(Object o) { + return getLazyDatabaseSchema(o).getConsoleConfiguration(); + } + + protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) { + final HibernateExtension3_5 hibernateExtension = (HibernateExtension3_5) consoleConfiguration.getHibernateExtension(); + hibernateExtension.buildWith(null, false); + final Configuration configuration = hibernateExtension.getConfiguration(); + return (DefaultDatabaseCollector) hibernateExtension.execute(new ExecutionContext.Command() { + + public Object execute() { + DefaultDatabaseCollector db = null; + Settings settings = hibernateExtension.getSettings(configuration); + ConnectionProvider connectionProvider = null; + try { + connectionProvider = settings.getConnectionProvider(); + + JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy); + db = new DefaultDatabaseCollector(reader.getMetaDataDialect()); + reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor)); + } catch (HibernateException he) { + throw he; + } catch (UnsupportedOperationException he) { + throw new HibernateException(he); + } + finally { + if (connectionProvider != null) { + connectionProvider.close(); + } + } + return db; + } + }); + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/ColumnWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/ColumnWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/ColumnWorkbenchAdapter.java (revision 0) @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.cfg.reveng.JDBCToHibernateTypeHelper; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; + +public class ColumnWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.COLUMN); + } + + public String getLabel(Object o) { + Column c = (Column) ((HibernateObjectWrapper)o).getItem(); + return getColumnLabel( c ); + } + + static String getColumnLabel(Column c) { + String label = c.getName(); + if(c.getSqlTypeCode()!=null) { + label += " : " + JDBCToHibernateTypeHelper.getJDBCTypeName(c.getSqlTypeCode().intValue()); //$NON-NLS-1$ + } + return label; + } + + public Object getParent(Object o) { + return null; + } + + public boolean isContainer() { + return false; + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/ExtensionAdapterFactory.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/ExtensionAdapterFactory.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/ExtensionAdapterFactory.java (revision 0) @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; +import org.hibernate.cfg.Configuration; +import org.hibernate.eclipse.console.workbench.LazyDatabaseSchema; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Table; +import org.hibernate.mapping.Value; + + +/** + * + * + * @author Dmitry Geraskov (geraskov@gmail.com) + * + */ +public class ExtensionAdapterFactory implements IAdapterFactory { + + private Class[] classes; + private IWorkbenchAdapter[] adapters; + + private Class[] deferredClasses; + private IDeferredWorkbenchAdapter[] deferredAdapters; + + public ExtensionAdapterFactory() { + Map, IDeferredWorkbenchAdapter> deferredMap = new HashMap, IDeferredWorkbenchAdapter>(); + deferredMap.put(Configuration.class, new ConfigurationWorkbenchAdapter()); + deferredMap.put(LazyDatabaseSchema.class, new LazyDatabaseSchemaWorkbenchAdapter()); + + deferredClasses = new Class[deferredMap.size()]; + deferredAdapters = new IDeferredWorkbenchAdapter[deferredMap.size()]; + + int cnt = 0; + for (Map.Entry, IDeferredWorkbenchAdapter> entry : deferredMap.entrySet()) { + deferredClasses[cnt] = entry.getKey(); + deferredAdapters[cnt] = entry.getValue(); + cnt++; + } + + Map, IWorkbenchAdapter> map = new HashMap, IWorkbenchAdapter>(); + map.put(TableContainer.class, new TableContainerWorkbenchAdapter()); + map.put(PersistentClass.class, new PersistentClassWorkbenchAdapter()); + map.put(Property.class, new PropertyWorkbenchAdapter()); + map.put(Value.class, new ValueWorkbenchAdapter()); + map.put(Table.class, new TableWorkbenchAdapter()); + map.put(PrimaryKey.class, new PrimaryKeyWorkbenchAdapter()); + map.put(Column.class, new ColumnWorkbenchAdapter()); + + classes = new Class[map.size()]; + adapters = new IWorkbenchAdapter[map.size()]; + cnt = 0; + for (Map.Entry, IWorkbenchAdapter> entry : map.entrySet()) { + classes[cnt] = entry.getKey(); + adapters[cnt] = entry.getValue(); + cnt++; + } + } + + @SuppressWarnings("rawtypes") + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof HibernateObjectWrapper) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper) adaptableObject; + adaptableObject = wrapper.getItem(); + } + + if(adapterType==IDeferredWorkbenchAdapter.class){ + return getDeferredAdapter( adaptableObject ); + } else if (adapterType==IWorkbenchAdapter.class){ + Object adapter = getAdapter( adaptableObject ); + return adapter != null ? adapter : getDeferredAdapter( adaptableObject ); + } + + return null; + } + + private Object getDeferredAdapter(Object adaptableObject) { + for (int i = 0; i < deferredClasses.length; i++) { + Class clazz = deferredClasses[i]; + if (clazz.isInstance(adaptableObject)) { + return deferredAdapters[i]; + } + } + return null; + } + + private Object getAdapter(Object adaptableObject) { + for (int i = 0; i < classes.length; i++) { + Class clazz = classes[i]; + if (clazz.isInstance(adaptableObject)) { + return adapters[i]; + } + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { IDeferredWorkbenchAdapter.class, IWorkbenchAdapter.class}; + } + + public void registerAdapters(IAdapterManager adapterManager) { + //do nothing + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/ConfigurationWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/ConfigurationWorkbenchAdapter.java (revision 0) @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.Comparator; +import java.util.Iterator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.hibernate.cfg.Configuration; +import org.hibernate.console.ImageConstants; +import org.hibernate.console.KnownConfigurations; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.PersistentClass; + +public class ConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Configuration cfg = (Configuration) wrapper.getItem(); + Iterator classMappings = cfg.getClassMappings(); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + toArray(classMappings, PersistentClass.class, new Comparator() { + public int compare(PersistentClass p0, PersistentClass p1) { + String label0 = HibernateWorkbenchHelper.getLabelForClassName(p0.getEntityName()); + String label1 = HibernateWorkbenchHelper.getLabelForClassName(p1.getEntityName()); + return label0.compareTo(label1); + } + + })); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.CONFIGURATION); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ConfigurationWorkbenchAdapter_configuration; + } + + public Object getParent(Object o) { + return KnownConfigurations.getInstance(); + } + + public boolean isContainer() { + return true; + } + + + +} Index: src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java (revision 43192) +++ src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java (working copy) @@ -28,10 +28,10 @@ import org.eclipse.swt.graphics.Image; import org.hibernate.console.ImageConstants; import org.hibernate.eclipse.console.utils.EclipseImages; -import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper; import org.hibernate.tool.ide.completion.HQLCompletionProposal; import org.hibernate.tool.ide.completion.IHQLCompletionRequestor; import org.hibernate.util.StringHelper; +import org.jboss.tools.hibernate3_5.console.workbench.HibernateWorkbenchHelper; public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor { Index: src/org/jboss/tools/hibernate3_5/console/workbench/TypeNameValueVisitor.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/TypeNameValueVisitor.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/TypeNameValueVisitor.java (revision 0) @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +public class TypeNameValueVisitor implements ValueVisitor { + + /** if true then only return the classname, not the fully qualified classname */ + final boolean dequalify; + + public TypeNameValueVisitor(boolean dequalify) { + this.dequalify=dequalify; + } + + public Object accept(Bag bag) { + return "Bag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(IdentifierBag bag) { + return "IdBag <" + bag.getElement().accept(this) + ">"; //$NON-NLS-1$//$NON-NLS-2$ + } + + public Object accept(List list) { + return "List <" + list.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(PrimitiveArray primitiveArray) { + return primitiveArray.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Array list) { + return list.getElement().accept(this) + "[]"; //$NON-NLS-1$ + } + + public Object accept(Map map) { + return "Map<" + map.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(OneToMany many) { + return dequalify(many.getReferencedEntityName()); + } + + private String dequalify(String referencedEntityName) { + if(dequalify && referencedEntityName!=null && referencedEntityName.indexOf(".")>=0) { //$NON-NLS-1$ + return referencedEntityName.substring(referencedEntityName.lastIndexOf('.')+1); + } + return referencedEntityName; + } + + public Object accept(Set set) { + return "Set<" + set.getElement().accept(this) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public Object accept(Any any) { + return "Any"; //$NON-NLS-1$ + } + + public Object accept(SimpleValue value) { + return dequalify(value.getTypeName()); + } + + public Object accept(DependantValue value) { + return null; + } + + public Object accept(Component component) { + return dequalify(component.getComponentClassName()); + } + + public Object accept(ManyToOne mto) { + return dequalify(mto.getReferencedEntityName()); + } + + public Object accept(OneToOne oto) { + return dequalify(oto.getEntityName()); + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/IconNameValueVisitor.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/IconNameValueVisitor.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/IconNameValueVisitor.java (revision 0) @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.hibernate.console.ImageConstants; +import org.hibernate.mapping.Any; +import org.hibernate.mapping.Array; +import org.hibernate.mapping.Bag; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.DependantValue; +import org.hibernate.mapping.IdentifierBag; +import org.hibernate.mapping.List; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Map; +import org.hibernate.mapping.OneToMany; +import org.hibernate.mapping.OneToOne; +import org.hibernate.mapping.PrimitiveArray; +import org.hibernate.mapping.Set; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.ValueVisitor; + +final class IconNameValueVisitor implements ValueVisitor { + + public Object accept(OneToOne oto) { + return ImageConstants.ONETOONE; + } + + public Object accept(ManyToOne mto) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Component component) { + return ImageConstants.COMPONENT; + } + + public Object accept(DependantValue value) { + return ImageConstants.UNKNOWNPROPERTY; + } + + public Object accept(SimpleValue value) { + return ImageConstants.PROPERTY; + } + + public Object accept(Any any) { + return ImageConstants.PROPERTY; + } + + public Object accept(Set set) { + return ImageConstants.MANYTOONE; + } + + public Object accept(OneToMany many) { + return ImageConstants.ONETOMANY; + } + + public Object accept(Map map) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Array list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(PrimitiveArray primitiveArray) { + return ImageConstants.MANYTOONE; + } + + public Object accept(List list) { + return ImageConstants.MANYTOONE; + } + + public Object accept(IdentifierBag bag) { + return ImageConstants.MANYTOONE; + } + + public Object accept(Bag bag) { + return ImageConstants.MANYTOONE; + } + +} \ No newline at end of file Index: src/org/jboss/tools/hibernate3_5/console/workbench/PersistentClassWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/PersistentClassWorkbenchAdapter.java (revision 0) @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.util.JoinedIterator; + +public class PersistentClassWorkbenchAdapter implements IWorkbenchAdapter { + + @SuppressWarnings("unchecked") + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + Property identifierProperty = pc.getIdentifierProperty(); + List properties = new ArrayList(); + + if(identifierProperty!=null) { + properties.add(identifierProperty); + } + + Iterator propertyClosureIterator = new JoinedIterator(properties.iterator(), pc.getPropertyClosureIterator()); + return HibernateObjectWrapper.wrap(wrapper.getConsoleConfiguration(), + BasicWorkbenchAdapter.toArray(propertyClosureIterator, Property.class, null)); + } + + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MAPPEDCLASS); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + PersistentClass pc = (PersistentClass) wrapper.getItem(); + return HibernateWorkbenchHelper.getLabelForClassName(pc.getEntityName()); + } + + public Object getParent(Object o) { + return null; + } + + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/TableContainerWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/TableContainerWorkbenchAdapter.java (revision 0) @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.Comparator; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter; +import org.hibernate.eclipse.console.workbench.TableContainer; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Table; + +public class TableContainerWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + TableContainer tc = getTableContainer( o ); + return BasicWorkbenchAdapter.toArray(tc.getTables().iterator(), HibernateObjectWrapper.class, new Comparator() { + + public int compare(HibernateObjectWrapper arg0, HibernateObjectWrapper arg1) { + return ((Table)arg0.getItem()).getName().compareTo( + ((Table)arg1.getItem()).getName()); + } + + }); + } + + private TableContainer getTableContainer(Object o) { + return (TableContainer) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.SCHEMA); + } + + public String getLabel(Object o) { + String name = getTableContainer(o).getName(); + return "".equals(name)?HibernateConsoleMessages.TableContainerWorkbenchAdapter_default:name; //$NON-NLS-1$ + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java =================================================================== --- src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java (revision 43192) +++ src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java (working copy) @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Red Hat, Inc. + * Copyright (c) 2011-2012 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.Map; +import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.osgi.util.NLS; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -37,6 +38,7 @@ import org.hibernate.console.preferences.ConsoleConfigurationPreferences; import org.hibernate.console.preferences.PreferencesClassPathUtils; import org.hibernate.eclipse.libs.FakeDelegatingDriver; +import org.jboss.tools.hibernate3_5.console.workbench.ExtensionAdapterFactory; /** * @@ -45,6 +47,8 @@ */ public class HibernateExtension3_5 implements HibernateExtension { + public static final String ID = "3.5"; + private ConsoleConfigClassLoader classLoader = null; private ExecutionContext executionContext; @@ -55,6 +59,8 @@ private SessionFactory sessionFactory; + private static IAdapterFactory adapterFactory = new ExtensionAdapterFactory(); + private Map fakeDrivers = new HashMap(); public HibernateExtension3_5() { @@ -62,7 +68,7 @@ @Override public String getHibernateVersion() { - return "3.5"; + return ID; } @Override @@ -300,4 +306,9 @@ public String getConsoleConfigurationName() { return prefs.getName(); } + + @Override + public IAdapterFactory getAdapterFactory() { + return adapterFactory; + } } Index: src/org/jboss/tools/hibernate3_5/console/workbench/TableWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/TableWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/TableWorkbenchAdapter.java (revision 0) @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.utils.EclipseImages; +import org.hibernate.eclipse.console.workbench.wrapper.HibernateObjectWrapper; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Table; + +public class TableWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table t = getTable( wrapper.getItem() ); + + List items = new ArrayList(); + + PrimaryKey primaryKey = t.getPrimaryKey(); + if(primaryKey!=null) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), primaryKey)); + } + + Iterator columnIterator = t.getColumnIterator(); + while ( columnIterator.hasNext() ) { + Column col = (Column) columnIterator.next(); + if(primaryKey==null || !primaryKey.containsColumn(col)) { + items.add(new HibernateObjectWrapper(wrapper.getConsoleConfiguration(), col)); // only add non-pk columns here + } + } + + return items.toArray(new Object[items.size()]); + } + + private Table getTable(Object o) { + return (Table) o; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.TABLE); + } + + public String getLabel(Object o) { + HibernateObjectWrapper wrapper = (HibernateObjectWrapper)o; + Table table = getTable(wrapper.getItem()); + //return Table.qualify(table.getCatalog(), table.getSchema(), table.getName(), '.'); + return table.getName(); + } + + public Object getParent(Object o) { + return null; + } + +} Index: src/org/jboss/tools/hibernate3_5/console/workbench/ValueWorkbenchAdapter.java =================================================================== --- src/org/jboss/tools/hibernate3_5/console/workbench/ValueWorkbenchAdapter.java (revision 0) +++ src/org/jboss/tools/hibernate3_5/console/workbench/ValueWorkbenchAdapter.java (revision 0) @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.hibernate3_5.console.workbench; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.hibernate.console.ImageConstants; +import org.hibernate.eclipse.console.HibernateConsoleMessages; +import org.hibernate.eclipse.console.utils.EclipseImages; + +public class ValueWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + return new Object[0]; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return EclipseImages.getImageDescriptor(ImageConstants.MANYTOONE); + } + + public String getLabel(Object o) { + return HibernateConsoleMessages.ValueWorkbenchAdapter_value + o.getClass().getName(); + } + + public Object getParent(Object o) { + return null; + } + +}