Author: dgeraskov
Date: 2012-02-01 08:06:03 -0500 (Wed, 01 Feb 2012)
New Revision: 38366
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BaseNodeWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java
Log:
https://issues.jboss.org/browse/JBIDE-10135
Do not use deferred adapter where not necessary
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BaseNodeWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BaseNodeWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BaseNodeWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -22,16 +22,15 @@
package org.hibernate.eclipse.console.workbench;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
+import org.eclipse.ui.model.IWorkbenchAdapter;
import org.hibernate.console.node.BaseNode;
import org.hibernate.eclipse.console.utils.EclipseImages;
-public class BaseNodeWorkbenchAdapter extends BasicWorkbenchAdapter implements
- IDeferredWorkbenchAdapter {
+public class BaseNodeWorkbenchAdapter implements IWorkbenchAdapter {
public Object[] getChildren(Object o) {
BaseNode bn = (BaseNode) o;
- return toArray(bn.children(),BaseNode.class);
+ return BasicWorkbenchAdapter.toArray(bn.children(),BaseNode.class);
}
public ImageDescriptor getImageDescriptor(Object object) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/BasicWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -69,7 +69,7 @@
@SuppressWarnings("unchecked")
- protected <T> T[] toArray(Iterator<? extends T> iterator, Class<T>
clazz, Comparator<? super T> comparator) {
+ protected static <T> T[] toArray(Iterator<? extends T> iterator,
Class<T> clazz, Comparator<? super T> comparator) {
List<T> obj = toList( iterator );
T[] array = obj.toArray((T[])Array.newInstance(clazz, obj.size()) );
@@ -79,7 +79,7 @@
return array;
}
- private <T> List<T> toList(Iterator<? extends T> iterator) {
+ private static <T> List<T> toList(Iterator<? extends T> iterator) {
List<T> obj = new ArrayList<T>();
while ( iterator.hasNext() ) {
obj.add(iterator.next());
@@ -87,7 +87,7 @@
return obj;
}
- protected Object[] toArray(Enumeration<?> enumeration, Class<?> clazz) {
+ protected static Object[] toArray(Enumeration<?> enumeration, Class<?>
clazz) {
List<Object> obj = new ArrayList<Object>();
while ( enumeration.hasMoreElements() ) {
obj.add(enumeration.nextElement());
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ColumnWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -22,15 +22,16 @@
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 extends BasicWorkbenchAdapter {
+public class ColumnWorkbenchAdapter implements IWorkbenchAdapter {
public Object[] getChildren(Object o) {
- return NO_CHILDREN;
+ return new Object[0];
}
public ImageDescriptor getImageDescriptor(Object object) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -44,42 +44,62 @@
public class ConfigurationAdapterFactory implements IAdapterFactory {
private Class<?>[] classes;
- private IDeferredWorkbenchAdapter[] adapters;
+ private IWorkbenchAdapter[] adapters;
+ private Class<?>[] deferredClasses;
+ private IDeferredWorkbenchAdapter[] deferredAdapters;
+
public ConfigurationAdapterFactory() {
- Map<Class<?>, IDeferredWorkbenchAdapter> map = new
HashMap<Class<?>, IDeferredWorkbenchAdapter>();
+ Map<Class<?>, IDeferredWorkbenchAdapter> deferredMap = new
HashMap<Class<?>, IDeferredWorkbenchAdapter>();
- map.put(ConsoleConfiguration.class, new ConsoleConfigurationWorkbenchAdapter());
- map.put(Configuration.class, new ConfigurationWorkbenchAdapter());
- map.put(KnownConfigurations.class, new KnownConfigurationsWorkbenchAdapter());
+ 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() );
+
+
+ deferredClasses = new Class[deferredMap.size()];
+ deferredAdapters = new IDeferredWorkbenchAdapter[deferredMap.size()];
+
+ int cnt = 0;
+ for (Map.Entry<Class<?>, IDeferredWorkbenchAdapter> entry :
deferredMap.entrySet()) {
+ deferredClasses[cnt] = entry.getKey();
+ deferredAdapters[cnt] = entry.getValue();
+ cnt++;
+ }
+
+ Map<Class<?>, IWorkbenchAdapter> map = new HashMap<Class<?>,
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(BaseNode.class, new BaseNodeWorkbenchAdapter());
- map.put(LazyDatabaseSchema.class, new LazyDatabaseSchemaWorkbenchAdapter());
- map.put( LazySessionFactory.class, new LazySessionFactoryAdapter() );
- map.put(TableContainer.class, new TableContainerWorkbenchAdapter());
map.put(Table.class, new TableWorkbenchAdapter());
map.put(PrimaryKey.class, new PrimaryKeyWorkbenchAdapter());
- map.put(Column.class, new ColumnWorkbenchAdapter());
+ map.put(Column.class, new ColumnWorkbenchAdapter());
+ map.put(BaseNode.class, new BaseNodeWorkbenchAdapter());
+
+
classes = new Class[map.size()];
- adapters = new IDeferredWorkbenchAdapter[map.size()];
-
- int cnt = 0;
- for (Map.Entry<Class<?>, IDeferredWorkbenchAdapter> entry : map.entrySet())
{
+ adapters = new IWorkbenchAdapter[map.size()];
+ cnt = 0;
+ for (Map.Entry<Class<?>, IWorkbenchAdapter> entry : map.entrySet()) {
classes[cnt] = entry.getKey();
adapters[cnt] = entry.getValue();
cnt++;
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
- if((adapterType==IDeferredWorkbenchAdapter.class ||
adapterType==IWorkbenchAdapter.class)) {
- return getAdapter( adaptableObject );
- }
+ if(adapterType==IDeferredWorkbenchAdapter.class){
+ return getDeferredAdapter( adaptableObject );
+ } else if (adapterType==IWorkbenchAdapter.class){
+ Object adapter = getAdapter( adaptableObject );
+ return adapter != null ? adapter : getDeferredAdapter( adaptableObject );
+ }
if(adapterType==IPropertySource2.class || adapterType==IPropertySource.class) {
return getPropertySource(adaptableObject);
}
@@ -90,6 +110,16 @@
private Object getPropertySource(Object adaptableObject) {
return null;//new GenericPropertySource(adaptableObject);
}
+
+ 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++) {
@@ -109,7 +139,11 @@
for (int i = 0; i < classes.length; i++) {
Class<?> clazz = classes[i];
adapterManager.registerAdapters(this, clazz);
- }
+ }
+ for (int i = 0; i < deferredClasses.length; i++) {
+ Class<?> clazz = deferredClasses[i];
+ adapterManager.registerAdapters(this, clazz);
+ }
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PersistentClassWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -26,13 +26,14 @@
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 extends BasicWorkbenchAdapter {
+public class PersistentClassWorkbenchAdapter implements IWorkbenchAdapter {
@SuppressWarnings("unchecked")
public Object[] getChildren(Object o) {
@@ -45,7 +46,7 @@
}
Iterator<Property> propertyClosureIterator = new
JoinedIterator(properties.iterator(), pc.getPropertyClosureIterator());
- return toArray(propertyClosureIterator, Property.class, null);
+ return BasicWorkbenchAdapter.toArray(propertyClosureIterator, Property.class, null);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PrimaryKeyWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -22,19 +22,21 @@
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 extends BasicWorkbenchAdapter {
+public class PrimaryKeyWorkbenchAdapter implements IWorkbenchAdapter {
+ @SuppressWarnings("unchecked")
public Object[] getChildren(Object o) {
PrimaryKey t = getPrimaryKey( o );
if(t.getColumnSpan()==1) {
- return NO_CHILDREN;
+ return new Object[0];
} else {
return t.getColumns().toArray(new Column[0]);
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/PropertyWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -22,7 +22,7 @@
package org.hibernate.eclipse.console.workbench;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
+import org.eclipse.ui.model.IWorkbenchAdapter;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Array;
import org.hibernate.mapping.Bag;
@@ -41,8 +41,9 @@
import org.hibernate.mapping.Value;
import org.hibernate.mapping.ValueVisitor;
-public class PropertyWorkbenchAdapter extends BasicWorkbenchAdapter implements
- IDeferredWorkbenchAdapter {
+public class PropertyWorkbenchAdapter implements IWorkbenchAdapter {
+
+ final static Object[] NO_CHILDREN = new Object[0];
public Object[] getChildren(Object o) {
Property p = (Property) o;
@@ -57,8 +58,9 @@
return NO_CHILDREN;
}
+ @SuppressWarnings("unchecked")
public Object accept(Component component) {
- return toArray(component.getPropertyIterator(), Property.class, null);
+ return BasicWorkbenchAdapter.toArray(component.getPropertyIterator(), Property.class,
null);
}
public Object accept(DependantValue value) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableContainerWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -24,16 +24,17 @@
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 extends BasicWorkbenchAdapter {
+public class TableContainerWorkbenchAdapter implements IWorkbenchAdapter {
public Object[] getChildren(Object o) {
TableContainer tc = getTableContainer( o );
- return toArray(tc.getTables().iterator(), Table.class, new Comparator<Table>() {
+ return BasicWorkbenchAdapter.toArray(tc.getTables().iterator(), Table.class, new
Comparator<Table>() {
public int compare(Table arg0, Table arg1) {
@@ -60,5 +61,4 @@
return null;
}
-
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/TableWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -26,13 +26,14 @@
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 extends BasicWorkbenchAdapter {
+public class TableWorkbenchAdapter implements IWorkbenchAdapter {
public Object[] getChildren(Object o) {
Table t = getTable( o );
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java 2012-02-01
12:56:05 UTC (rev 38365)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ValueWorkbenchAdapter.java 2012-02-01
13:06:03 UTC (rev 38366)
@@ -22,13 +22,12 @@
package org.hibernate.eclipse.console.workbench;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
+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 extends BasicWorkbenchAdapter implements
- IDeferredWorkbenchAdapter {
+public class ValueWorkbenchAdapter implements IWorkbenchAdapter {
public Object[] getChildren(Object o) {
return new Object[0];