use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OpenDiagramActionDelegate method run.
public void run(IAction action) {
ObjectPluginAction objectPluginAction = (ObjectPluginAction) action;
Map<ConsoleConfiguration, Set<IPersistentClass>> mapCC_PCs = new HashMap<ConsoleConfiguration, Set<IPersistentClass>>();
TreePath[] paths = ((TreeSelection) objectPluginAction.getSelection()).getPaths();
for (int i = 0; i < paths.length; i++) {
final Object firstSegment = paths[i].getFirstSegment();
if (!(firstSegment instanceof ConsoleConfiguration)) {
continue;
}
final ConsoleConfiguration consoleConfig = (ConsoleConfiguration) (firstSegment);
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfig);
if (null == setPC) {
setPC = new HashSet<IPersistentClass>();
mapCC_PCs.put(consoleConfig, setPC);
}
Object last_el = paths[i].getLastSegment();
if (last_el instanceof IPersistentClass) {
IPersistentClass persClass = (IPersistentClass) last_el;
setPC.add(persClass);
} else if (last_el instanceof IConfiguration) {
IConfiguration config = (IConfiguration) last_el;
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
} else if (last_el instanceof ConsoleConfiguration) {
IConfiguration config = consoleConfig.getConfiguration();
if (config == null) {
try {
consoleConfig.build();
} catch (Exception he) {
HibernateConsolePlugin.getDefault().showError(HibernateConsolePlugin.getShell(), DiagramViewerMessages.OpenDiagramActionDelegate_could_not_load_configuration + ' ' + consoleConfig.getName(), he);
}
if (consoleConfig.hasConfiguration()) {
consoleConfig.buildMappings();
}
config = consoleConfig.getConfiguration();
}
if (config != null) {
Iterator<IPersistentClass> it = config.getClassMappings();
while (it.hasNext()) {
setPC.add(it.next());
}
}
}
}
for (Iterator<ConsoleConfiguration> it = mapCC_PCs.keySet().iterator(); it.hasNext(); ) {
ConsoleConfiguration consoleConfiguration = it.next();
Set<IPersistentClass> setPC = mapCC_PCs.get(consoleConfiguration);
try {
openEditor(setPC, consoleConfiguration);
} catch (PartInitException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("Can't open mapping view.", e);
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class OrmImageMap method getImageName.
/**
* the image name for hierarchy:
* Property
* @param field
* @return
*/
public static String getImageName(IProperty field, final ConsoleConfiguration cfg) {
// $NON-NLS-1$
String str = "Image_PersistentFieldSimple";
if (field == null) {
return str;
}
final IPersistentClass persistentClass = field.getPersistentClass();
if (persistentClass != null && persistentClass.getVersion() == field) {
// $NON-NLS-1$
str = "Image_PersistentFieldSimple_version";
} else if (persistentClass != null && persistentClass.getIdentifierProperty() == field) {
// $NON-NLS-1$
str = "Image_PersistentFieldSimple_id";
} else if (field.getValue() != null) {
final IValue value = field.getValue();
if (value.isOneToMany()) {
// $NON-NLS-1$
str = "Image_PersistentFieldOne-to-many";
} else if (value.isOneToOne()) {
// $NON-NLS-1$
str = "Image_PersistentFieldOne-to-one";
} else if (value.isManyToOne()) {
// $NON-NLS-1$
str = "Image_PersistentFieldMany-to-one";
} else if (value.isAny()) {
// $NON-NLS-1$
str = "Image_PersistentFieldAny";
} else {
IType type = UtilTypeExtract.getTypeUsingExecContext(value, cfg);
if (type != null && type.isCollectionType()) {
if (value.isPrimitiveArray()) {
// $NON-NLS-1$
str = "Image_Collection_primitive_array";
} else if (value.isArray()) {
// $NON-NLS-1$
str = "Image_Collection_array";
} else if (value.isList()) {
// $NON-NLS-1$
str = "Image_Collection_list";
} else if (value.isSet()) {
// $NON-NLS-1$
str = "Image_Collection_set";
} else if (value.isMap()) {
// $NON-NLS-1$
str = "Image_Collection_map";
} else if (value.isBag()) {
// $NON-NLS-1$
str = "Image_Collection_bag";
} else if (value.isIdentifierBag()) {
// $NON-NLS-1$
str = "Image_Collection_idbag";
} else {
// $NON-NLS-1$
str = "Image_Collection";
}
}
}
} else if ("parent".equals(field.getName())) {
// $NON-NLS-1$
// $NON-NLS-1$
str = "Image_PersistentFieldParent";
}
return str;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class ShapeEditPart method getSelectionColor.
protected Color getSelectionColor() {
Color result = ResourceManager.getInstance().getColor(new RGB(255, 0, 0));
final Object el = getElement();
if (el instanceof IPersistentClass || el instanceof IProperty) {
result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
} else if (el instanceof IValue) {
IValue value = (IValue) el;
if (value.isSimpleValue() || value.isOneToMany()) {
result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
}
} else if (el instanceof ITable || el instanceof IColumn) {
result = ResourceManager.getInstance().getColor(new RGB(66, 173, 247));
}
return result;
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class HbmExporterTest method testList.
public void testList() {
// $NON-NLS-1$
IConfiguration config = getConfigurationFor("pack.A");
// $NON-NLS-1$ //$NON-NLS-2$
checkClassesMaped(config, "pack.A", "pack.B");
// $NON-NLS-1$
IPersistentClass a = config.getClassMapping("pack.A");
// $NON-NLS-1$
IPersistentClass b = config.getClassMapping("pack.B");
// $NON-NLS-1$
IProperty listProp = a.getProperty("list");
assertNotNull(listProp.getValue());
IValue value = listProp.getValue();
assertTrue("Expected to get List-type mapping", value.isList());
assertTrue(value.getCollectionElement().isOneToMany());
assertTrue(value.getCollectionTable().equals(b.getTable()));
assertNotNull(value.getIndex());
assertNotNull(value.getKey());
}
use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass in project jbosstools-hibernate by jbosstools.
the class HbmExporterTest method testMap.
public void testMap() {
// $NON-NLS-1$
IConfiguration config = getConfigurationFor("pack.A");
// $NON-NLS-1$ //$NON-NLS-2$
checkClassesMaped(config, "pack.A", "pack.B");
// $NON-NLS-1$
IPersistentClass a = config.getClassMapping("pack.A");
// $NON-NLS-1$
IPersistentClass b = config.getClassMapping("pack.B");
// $NON-NLS-1$
IProperty mapValue = a.getProperty("mapValue");
assertNotNull(mapValue.getValue());
IValue value = mapValue.getValue();
assertTrue("Expected to get Map-type mapping", value.isMap());
assertTrue(value.getCollectionElement().isOneToMany());
assertTrue(value.getCollectionTable().equals(b.getTable()));
assertNotNull(value.getKey());
// $NON-NLS-1$
assertEquals("string", value.getKey().getType().getName());
}
Aggregations