use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class EntityAssistCompositeContributionItem method createTextActions.
protected List<IAction> createTextActions(ILanguageKit lk, IEntity targetEntity) {
List<IAction> textActions = new ArrayList<IAction>();
IGEFEditorKit editorKit = (IGEFEditorKit) (targetEntity.wGetLanguageKit().equals(lk) ? ReflectionFactory.getEditorKit(targetEntity) : lk.getDefaultEditorKit());
for (Object[] textAction : E4Utils.textActionsFor(lk, ((IGEFEditorKit) editorKit).getActionFactory().textActions())) {
EntityDescriptor<?> ed = (EntityDescriptor<?>) textAction[1];
if (Matcher.matchImpl(ed, targetEntity)) {
@SuppressWarnings("unchecked") Class<IUpdatableAction> actionClass = (Class<IUpdatableAction>) textAction[2];
try {
IUpdatableAction action = actionClass.getConstructor(IEclipseContext.class).newInstance(contextProvider.getContext());
action.update();
if (action.isEnabled())
textActions.add(action);
} catch (Exception e) {
}
}
}
return textActions;
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class HandlersBehavior method replaceEntity.
public static void replaceEntity(IBindingManager bm) {
IEntity focusEntity = bm.wGet("focusEntity");
EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
if (bm.wIsSet("featureDescriptor"))
focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
IEntity replacement = GenericEntityFactory.instance.create(ed);
transformer.transform(focusEntity.wGetAdaptee(false), replacement);
focusEntity.wGetParent().wSet(focusEntity, replacement);
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class HandlersBehavior method addEntity.
public static void addEntity(IBindingManager bm) {
IEntity focusEntity = bm.wGet("focusEntity");
EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
if (bm.wIsSet("featureDescriptor"))
focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
IEntity child = GenericEntityFactory.instance.create(ed);
// FIXME make configurable
if (CommonsEntityDescriptorEnum.Variable.isLanguageSupertypeOf(ed))
child.wGet(CommonsFeatureDescriptorEnum.varType).wSetValue(focusEntity.wGetEntityDescriptor(0));
if (bm.wIsSet("hilightPosition"))
focusEntity.wAdd(bm.wIntValue("hilightPosition"), child);
else
focusEntity.wAdd(child);
}
use of org.whole.lang.reflect.EntityDescriptor 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.EntityDescriptor in project whole by wholeplatform.
the class QueriesUtils method sort.
public static IEntity sort(IEntity entity) {
if (entity.wGetEntityDescriptor().getCompositeKind().isOrdered()) {
List<IEntity> entityList = (List<IEntity>) entity;
IEntity[] array = entityList.toArray(new IEntity[entity.wSize()]);
entityList.clear();
Arrays.sort(array, new Comparator<IEntity>() {
public int compare(IEntity e1, IEntity e2) {
IEntity e1Adaptee = e1.wGetAdaptee(false);
IEntity e2Adaptee = e2.wGetAdaptee(false);
EntityDescriptor<?> e1Ed = e1Adaptee.wGetEntityDescriptor();
EntityDescriptor<?> e2Ed = e2Adaptee.wGetEntityDescriptor();
if (e1Ed != e2Ed)
return 0;
switch(e1Ed.getEntityKind()) {
case DATA:
return DataTypeUtils.compare(e1Adaptee, e2Adaptee);
default:
case COMPOSITE:
return 0;
case SIMPLE:
boolean idBased = false;
List<FeatureDescriptor> entityFeatureDescriptors = e1Ed.getEntityFeatureDescriptors();
for (FeatureDescriptor fd : entityFeatureDescriptors) {
if (fd.isId()) {
idBased = true;
int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
if (result != 0)
return result;
}
}
if (idBased)
return 0;
for (FeatureDescriptor fd : entityFeatureDescriptors) {
int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
if (result != 0)
return result;
}
return 0;
}
}
});
for (IEntity child : array) entity.wAdd(child);
return entity;
} else
return entity;
}
Aggregations