use of org.whole.lang.reflect.EntityDescriptorEnum in project whole by wholeplatform.
the class GrammarBasedUIUtils method calculateSeparator.
public static String calculateSeparator(IEntity entity) {
EntityDescriptorEnum edEnum = entity.wGetLanguageKit().getEntityDescriptorEnum();
StringBuilder sb = new StringBuilder();
IEntityIterator<IEntity> iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(edEnum.valueOf("Literal"));
iterator.reset(entity);
while (iterator.hasNext()) sb.append(EntityUtils.safeStringValue(iterator.next(), ""));
String separatorText = sb.toString();
return separatorText.trim();
}
use of org.whole.lang.reflect.EntityDescriptorEnum in project whole by wholeplatform.
the class WorkflowsUIContentAssistVisitor method allEntityTypes.
protected boolean allEntityTypes(IEntity entity) {
if (!WorkflowsUtils.isEntityTypeInCreateEntity(entity))
return false;
ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
GroupAction languagesGroup = aef.createGroupAction();
languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
languagesGroup.getText().setValue("workflows.languages");
Actions actions = aef.createActions(0);
WorkflowsEntityFactory wef = WorkflowsEntityFactory.instance;
String actualLanguageURI = "";
String actualEntityName = "";
EntityDescriptor<?> actualED = null;
try {
if (Matcher.matchImpl(StringLiteral, entity)) {
StringLiteral literal = (StringLiteral) entity;
actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(literal.getValue());
actualLanguageURI = actualED.getLanguageKit().getURI();
actualEntityName = actualED.getName();
}
} catch (Exception e) {
}
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)
ed = edEnum.valueOf(0);
StringLiteral prototype = wef.createStringLiteral(CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
}
languagesGroup.setActions(actions);
boolean adeddLanguages = EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, languagesGroup) : mergeResult(languagesGroup);
if (actualED != null) {
GroupAction typenamesGroup = aef.createGroupAction();
typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
typenamesGroup.getText().setValue("workflows.typenames");
actions = aef.createActions(0);
EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
Collections.sort(eds, new Comparator<EntityDescriptor<?>>() {
public int compare(EntityDescriptor<?> ed1, EntityDescriptor<?> ed2) {
return ed1.getName().compareTo(ed2.getName());
}
});
for (EntityDescriptor<?> ed : eds) {
if (ed.equals(actualED))
continue;
StringLiteral prototype = wef.createStringLiteral(CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
}
typenamesGroup.setActions(actions);
adeddLanguages |= EntityUtils.isResolver(entity) ? mergeResult(StringLiteral, typenamesGroup) : mergeResult(typenamesGroup);
}
return adeddLanguages;
}
use of org.whole.lang.reflect.EntityDescriptorEnum in project whole by wholeplatform.
the class XsiDateTimeUtilsTest method testGregorianCalendar.
@Test
public void testGregorianCalendar() {
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(DATATYPES_URI);
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
IDataTypeParser dataTypeParser = languageKit.getDataTypeParser(DataTypeParsers.PERSISTENCE);
EntityDescriptor<?> dateTime = edEnum.valueOf("XSDateTime");
EntityDescriptor<?> date = edEnum.valueOf("XSDate");
EntityDescriptor<?> time = edEnum.valueOf("XSTime");
EntityDescriptor<?> gYearMonth = edEnum.valueOf("XSGYearMonth");
DateTime base = new DateTime(2001, 1, 1, 11, 22, 33, 444, DateTimeZone.UTC);
assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43.999Z", "1990-11-30T12:30:43.999Z");
assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43", "1990-11-30T12:30:43.000Z");
assertEquals(dataTypeParser, base, gYearMonth, "1990-11", "1990-11-01T11:22:33.444Z");
assertEquals(dataTypeParser, base, date, "1990-11-30", "1990-11-30T11:22:33.444Z");
assertEquals(dataTypeParser, base, date, "1990-11-30Z", "1990-11-30T00:00:00.000Z");
assertEquals(dataTypeParser, base, date, "1990-11-30+02:00", "1990-11-29T22:00:00.000Z");
assertEquals(dataTypeParser, base, time, "12:30:43", "2001-01-01T12:30:43.000Z");
assertEquals(dataTypeParser, base, time, "12:30:43.999Z", "1970-01-01T12:30:43.999Z");
}
use of org.whole.lang.reflect.EntityDescriptorEnum 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.EntityDescriptorEnum 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;
}
Aggregations