use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class PojoUtils method toDataEntity.
public static IEntity toDataEntity(Object fromObject, PrimitiveType type, Library library) {
String edName = StringUtils.toUpperCap(type.wStringValue()) + "Data";
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(library.getLanguageURI().wStringValue());
return GenericEntityFactory.instance(RegistryConfigurations.RESOLVER).create(languageKit.getEntityDescriptorEnum().valueOf(edName), fromObject);
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class GrammarBasedUIUtils method createCompositeFigure.
public static IEntityFigure createCompositeFigure(IEntity entity) {
ILanguageKit lk = entity.wGetLanguageKit();
EntityDescriptorEnum edEnum = lk.getEntityDescriptorEnum();
FeatureDescriptorEnum fdEnum = lk.getFeatureDescriptorEnum();
IEntity configuration = Matcher.findAncestor(edEnum.valueOf("CompositePart"), entity);
IEntity multiline = configuration.wGet(fdEnum.valueOf("multiline"));
boolean isMultiline = EntityUtils.safeBooleanValue(multiline, false);
IEntity columns = configuration.wGet(fdEnum.valueOf("columns"));
int columnsNum = EntityUtils.safeIntValue(columns, 0);
IEntity separator = configuration.wGet(fdEnum.valueOf("separator"));
IEntityFigure entityFigure;
if (EntityUtils.isNotResolver(separator)) {
String separatorText = GrammarBasedUIUtils.calculateSeparator(separator);
CompositeFigure compositeFigure = isMultiline ? new StringSeparatedCompositeColumnFigure(separatorText, 10) : new StringSeparatedCompositeRowFigure(separatorText, 10);
if (isMultiline)
compositeFigure.getLayoutManager().withMinorAlignment(Alignment.LEADING);
entityFigure = compositeFigure;
} else if (columnsNum > 0) {
TableFigure tableFigure = new TableFigure(columnsNum);
tableFigure.setBorder(CompositePlaceHolderBorder.OPTIONAL_VERTICAL);
entityFigure = tableFigure;
} else
entityFigure = new CompositeFigure(!isMultiline, true);
return entityFigure;
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class FramesContentAssistVisitor method allEntityTypes.
private boolean allEntityTypes(IEntity entity, EntityDescriptor<?> type) {
if (!EntityUtils.hasParent(entity))
return false;
boolean subtypeTest = false;
ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
GroupAction languagesGroup = aef.createGroupAction();
languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
languagesGroup.getText().setValue("frames.languages");
Actions actions = aef.createActions(0);
FramesEntityFactory fef = FramesEntityFactory.instance;
String actualLanguageURI = "";
String actualEntityName = "";
EntityDescriptor<?> actualED = null;
EntityDescriptor<?> targetED = type;
try {
actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(entity.wStringValue());
actualLanguageURI = actualED.getLanguageKit().getURI();
actualEntityName = actualED.getName();
} catch (Exception e) {
if (DataTypeUtils.getDataKind(entity).isString())
actualEntityName = entity.wStringValue();
}
IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
if (languageKit.getURI().equals(actualLanguageURI))
continue;
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
EntityDescriptor<?> ed = null;
if (actualEntityName.length() > 0)
ed = edEnum.valueOf(actualEntityName);
if (ed == null) {
if (subtypeTest)
ed = edEnum.valueOf(0);
else {
Iterator<EntityDescriptor<?>> iterator = edEnum.values().iterator();
EntityDescriptor<?> nextED;
while (ed == null && iterator.hasNext()) if (!(nextED = iterator.next()).isAbstract())
ed = nextED;
if (ed == null)
continue;
}
}
IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
}
languagesGroup.setActions(actions);
boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetED, languagesGroup) : mergeResult(languagesGroup);
if (actualED != null) {
GroupAction typenamesGroup = aef.createGroupAction();
typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
typenamesGroup.getText().setValue(subtypeTest ? "frames.subtypenames" : "frames.typenames");
actions = aef.createActions(0);
EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
Collections.sort(eds, EnumValueImpl.getByNameComparator());
for (EntityDescriptor<?> ed : eds) {
if (ed.equals(actualED) || (!subtypeTest && ed.isAbstract()))
continue;
IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
}
typenamesGroup.setActions(actions);
addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetED, typenamesGroup) : mergeResult(typenamesGroup);
}
return addedLanguages;
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class AbstractByLanguageOperation method initVisitor.
@Override
protected IVisitor initVisitor(IEntity entity, int normalizedStage) {
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
String languageUri = languageKit.getURI();
IVisitor visitor = null;
if (hasVisitor(languageUri))
visitor = getVisitor(languageUri, normalizedStage);
if (visitor == null)
visitor = getDefaultVisitor(entity, normalizedStage);
return visitor;
}
use of org.whole.lang.reflect.ILanguageKit in project whole by wholeplatform.
the class AbstractByLanguageOperation method setVisitor.
@Override
public IVisitor setVisitor(IEntity entity, int absoluteStage, IVisitor visitor) {
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(entity);
String languageUri = languageKit.getURI();
IVisitor oldVisitor = hasVisitor(languageUri) ? getVisitor(entity, absoluteStage) : null;
int normalizedStage = absoluteStage <= 0 ? 0 : 1;
String uri = ReflectionFactory.getLanguageKit(entity).getURI();
IVisitor[] stagedVisitors = stagedVisitorsMap.get(uri);
if (stagedVisitors == null)
stagedVisitorsMap.put(uri, stagedVisitors = new IVisitor[2]);
stagedVisitors[normalizedStage] = visitor;
return oldVisitor;
}
Aggregations