Search in sources :

Example 1 with IResource

use of org.whole.lang.resources.IResource in project whole by wholeplatform.

the class ActionsCompositeContributionItem method getItems.

@Override
protected IContributionItem[] getItems() {
    Object selection = contextProvider.getContext().get(ESelectionService.class).getSelection();
    if (!(selection instanceof IBindingManager) || !((IBindingManager) selection).wIsSet("self"))
        return new IContributionItem[0];
    IBindingManager bm = (IBindingManager) selection;
    String languageURI = bm.wGet("self").wGetLanguageKit().getURI();
    Map<GuardedAction, String> actionsMap = new HashMap<GuardedAction, String>();
    IResourceRegistry<Resource> registry = ActionsRegistry.instance();
    for (IResource resource : registry.getResources(false)) {
        LanguageActionFactory actionsModule = resource.getEntity();
        URI targetLanguage = actionsModule.getTargetLanguage();
        if (DataTypeUtils.getDataKind(targetLanguage).isString() && !languageURI.equals(targetLanguage.getValue()))
            continue;
        for (GuardedAction guardedAction : Matcher.findAll(ActionsEntityDescriptorEnum.GuardedAction, getActions(actionsModule), false)) {
            String actionName = guardedAction.getName().getValue();
            String functionUri = resource.getURI() + '#' + actionName;
            actionsMap.put(guardedAction, functionUri);
        }
    }
    List<IAction> actions = new ArrayList<IAction>();
    List<GuardedAction> guardedActions = new ArrayList<GuardedAction>(actionsMap.keySet());
    Collections.sort(guardedActions, new Comparator<GuardedAction>() {

        public int compare(GuardedAction a1, GuardedAction a2) {
            return a1.getName().getValue().compareTo(a2.getName().getValue());
        }
    });
    for (GuardedAction guardedAction : guardedActions) {
        String actionName = guardedAction.getName().getValue();
        String functionUri = actionsMap.get(guardedAction);
        IUpdatableAction action = contextProvider.getActionRegistry().getActionFactory().createActionCallAction(actionName, isAnalyze(), guardedAction.getEnablerPredicate(), functionUri);
        action.update();
        actions.add(action);
    }
    List<IContributionItem> items = new ArrayList<IContributionItem>();
    HierarchicalFillMenuStrategy.instance().fillMenu(ActionListContainer.create(items), ActionSet.create(actions.toArray(new IAction[actions.size()])), 0, actions.size());
    return items.toArray(new IContributionItem[items.size()]);
}
Also used : LanguageActionFactory(org.whole.lang.actions.model.LanguageActionFactory) GuardedAction(org.whole.lang.actions.model.GuardedAction) IAction(org.eclipse.jface.action.IAction) HashMap(java.util.HashMap) IContributionItem(org.eclipse.jface.action.IContributionItem) Resource(org.whole.lang.resources.Resource) IResource(org.whole.lang.resources.IResource) ArrayList(java.util.ArrayList) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) URI(org.whole.lang.actions.model.URI) IBindingManager(org.whole.lang.bindings.IBindingManager) IResource(org.whole.lang.resources.IResource)

Example 2 with IResource

use of org.whole.lang.resources.IResource in project whole by wholeplatform.

the class FunctionNamePart method getQualifierPart.

protected String getQualifierPart(String qname) {
    String uri = ResourceUtils.getResourcePart(qname);
    IResource resource = FunctionLibraryRegistry.instance().getResource(uri, false, null);
    return resource != null ? resource.getName() : uri;
}
Also used : IResource(org.whole.lang.resources.IResource)

Example 3 with IResource

use of org.whole.lang.resources.IResource in project whole by wholeplatform.

the class ReusablesInterpreterVisitor method visit.

@Override
public void visit(Registry entity) {
    entity.getRegistryUri().accept(this);
    String registryId = getResult().wStringValue();
    if (!ResourceRegistry.hasRegistry(registryId))
        throw new WholeIllegalArgumentException("Undefined registry " + registryId).withSourceEntity(entity).withBindings(getBindings());
    IResourceRegistry<IResource> registry = ResourceRegistry.getRegistry(registryId);
    entity.getUri().accept(this);
    String uri = getResult().wStringValue();
    if (ResourceUtils.hasFragmentPart(uri) && registry instanceof CompoundResourceRegistry) {
        CompoundResourceRegistry<IResource> compoundRegistry = (CompoundResourceRegistry<IResource>) registry;
        setResult(compoundRegistry.getFunctionModel(uri, true, getBindings()));
    } else
        setResult(registry.getResourceModel(uri, true, getBindings()));
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) CompoundResourceRegistry(org.whole.lang.resources.CompoundResourceRegistry) IResource(org.whole.lang.resources.IResource)

Example 4 with IResource

use of org.whole.lang.resources.IResource in project whole by wholeplatform.

the class LabelPart method getQualifierPart.

protected String getQualifierPart(String qname) {
    String uri = ResourceUtils.getResourcePart(qname);
    IResourceRegistry<Resource> registry = ActionsRegistry.instance();
    IResource resource = registry.getResource(uri, false, null);
    return resource != null ? resource.getName() : uri;
}
Also used : Resource(org.whole.lang.resources.Resource) IResource(org.whole.lang.resources.IResource) IResource(org.whole.lang.resources.IResource)

Example 5 with IResource

use of org.whole.lang.resources.IResource in project whole by wholeplatform.

the class ActionsVisibleWhen method isVisible.

@Override
public boolean isVisible(IBindingManager bm) {
    if (!HandlersBehavior.isValidEntityPartSelection(bm, false))
        return false;
    String languageURI = bm.wGet("self").wGetLanguageKit().getURI();
    IResourceRegistry<Resource> registry = ActionsRegistry.instance();
    for (IResource resource : registry.getResources(false)) {
        LanguageActionFactory actionsModule = resource.getEntity();
        URI targetLanguage = actionsModule.getTargetLanguage();
        if (DataTypeUtils.getDataKind(targetLanguage).isString() && !languageURI.equals(targetLanguage.getValue()))
            continue;
        IEntityIterator<GuardedAction> iterator = IteratorFactory.<GuardedAction>childMatcherIterator().withPattern(ActionsEntityDescriptorEnum.GuardedAction);
        iterator.reset(getActions(actionsModule));
        if (iterator.hasNext())
            return true;
    }
    return false;
}
Also used : LanguageActionFactory(org.whole.lang.actions.model.LanguageActionFactory) GuardedAction(org.whole.lang.actions.model.GuardedAction) Resource(org.whole.lang.resources.Resource) IResource(org.whole.lang.resources.IResource) URI(org.whole.lang.actions.model.URI) IResource(org.whole.lang.resources.IResource)

Aggregations

IResource (org.whole.lang.resources.IResource)7 Resource (org.whole.lang.resources.Resource)4 ArrayList (java.util.ArrayList)2 GuardedAction (org.whole.lang.actions.model.GuardedAction)2 LanguageActionFactory (org.whole.lang.actions.model.LanguageActionFactory)2 URI (org.whole.lang.actions.model.URI)2 HashMap (java.util.HashMap)1 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)1 IAction (org.eclipse.jface.action.IAction)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 CompoundResourceRegistry (org.whole.lang.resources.CompoundResourceRegistry)1 IUpdatableAction (org.whole.lang.ui.actions.IUpdatableAction)1 Schema (org.whole.lang.xsd.model.Schema)1