Search in sources :

Example 1 with IEditorKit

use of org.whole.lang.reflect.IEditorKit in project whole by wholeplatform.

the class JFaceMenuBuilder method addNotationsItem.

public void addNotationsItem() {
    IBindingManager bm = getBindings();
    IMenuManager menu = createMenu(NOTATION_LABEL, getNotationsVisibleWhen());
    addItem(menu);
    if (!HandlersBehavior.isValidFocusEntityPart(bm))
        return;
    IEntity focusEntity = bm.wGet("focusEntity");
    IEditorKit selectedEditorKit = focusEntity.wGetEditorKit();
    for (IEditorKit editorKit : ReflectionFactory.getEditorKits(focusEntity.wGetLanguageKit().getURI())) {
        if (!editorKit.canApply(focusEntity.wGetLanguageKit()))
            continue;
        IUpdatableAction action = actionRegistry.getSelectNotationAction(editorKit);
        action.setChecked(editorKit == selectedEditorKit);
        menu.add(action);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IEditorKit(org.whole.lang.reflect.IEditorKit) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 2 with IEditorKit

use of org.whole.lang.reflect.IEditorKit in project whole by wholeplatform.

the class SelectNotationHandler method execute.

@Execute
public void execute(@Optional @Named(EDITORKIT_ID_PARAMETER_ID) String editorKitId, @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, final IEntityPartViewer viewer, UISynchronize synchronize) {
    IEditorKit editorKit = ReflectionFactory.getEditorKit(editorKitId);
    final IEntity focusEntity = bm.wGet("focusEntity");
    focusEntity.wGetModel().setEditorKit(editorKit);
    ModelTransactionCommand command = new ModelTransactionCommand(focusEntity);
    try {
        command.begin();
        IEntity fragmentRoot = EntityUtils.getLanguageFragmentRoot(focusEntity);
        viewer.rebuildNotation(fragmentRoot);
        command.commit();
        if (command.canUndo())
            viewer.getEditDomain().getCommandStack().execute(command);
    } catch (Exception e) {
        command.rollbackIfNeeded();
    }
    synchronize.asyncExec(new Runnable() {

        public void run() {
            viewer.selectAndReveal(focusEntity);
        }
    });
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) IEditorKit(org.whole.lang.reflect.IEditorKit) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 3 with IEditorKit

use of org.whole.lang.reflect.IEditorKit in project whole by wholeplatform.

the class AbstractEntity method wGetEditorKit.

public IEditorKit wGetEditorKit() {
    ILanguageKit languageKit = wGetEntityDescriptor().getLanguageKit();
    IFragmentModel model = wGetActualModel();
    if (model != NullFragmentModel.instance) {
        IEditorKit editorKit = model.getEditorKit();
        if (editorKit.canApply(languageKit))
            return editorKit;
    }
    return languageKit.getDefaultEditorKit();
// return model != NullFragmentModel.instance ? model.getEditorKit() : languageKit.getDefaultEditorKit();
}
Also used : IEditorKit(org.whole.lang.reflect.IEditorKit) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 4 with IEditorKit

use of org.whole.lang.reflect.IEditorKit in project whole by wholeplatform.

the class WholeEditPartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object object) {
    try {
        IEntity entity = (IEntity) object;
        IEntity modelEntity = entity.wGetAdaptee(false);
        IEditorKit editorKit = modelEntity.wGetEditorKit();
        if (currentEditorKit != editorKit) {
            currentEditorKit = (IGEFEditorKit) editorKit;
            currentPartFactory = partFactoryMap.get(currentEditorKit);
            if (currentPartFactory == null)
                partFactoryMap.put(currentEditorKit, currentPartFactory = currentEditorKit.getPartFactory());
        }
        EditPart part = currentPartFactory.createEditPart(context, modelEntity);
        part.setModel(entity);
        return part;
    } catch (Exception e) {
        throw new IllegalArgumentException("Illegal model entity: " + object + " in context: " + context, e);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) EditPart(org.eclipse.gef.EditPart) IEditorKit(org.whole.lang.reflect.IEditorKit)

Example 5 with IEditorKit

use of org.whole.lang.reflect.IEditorKit in project whole by wholeplatform.

the class ActionRegistry method registerKeyActions.

public void registerKeyActions(AbstractKeyHandler keyHandler) {
    keyHandler.put(KeySequence.getInstance(KeyStroke.getInstance(SWT.F2)), true, actionFactory.createDirectEditAction());
    for (IEditorKit editorKit : ReflectionFactory.getEditorKits()) {
        for (ILanguageKit lk : ReflectionFactory.getLanguageKits(false)) {
            if (!editorKit.canApply(lk))
                continue;
            for (Object[] textAction : E4Utils.textActionsFor(lk, ((IGEFEditorKit) editorKit).getActionFactory().textActions())) {
                KeySequence keySequence = (KeySequence) textAction[0];
                Class<IUpdatableAction> actionClass = (Class<IUpdatableAction>) textAction[2];
                try {
                    IUpdatableAction action = actionClass.getConstructor(IEclipseContext.class).newInstance(context);
                    keyHandler.put(editorKit, keySequence, true, action);
                } catch (Exception e) {
                }
            }
        }
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IGEFEditorKit(org.whole.lang.ui.editor.IGEFEditorKit) IEditorKit(org.whole.lang.reflect.IEditorKit) IUpdatableAction(org.whole.lang.ui.actions.IUpdatableAction) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Aggregations

IEditorKit (org.whole.lang.reflect.IEditorKit)5 IEntity (org.whole.lang.model.IEntity)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 IUpdatableAction (org.whole.lang.ui.actions.IUpdatableAction)2 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 EditPart (org.eclipse.gef.EditPart)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)1 IGEFEditorKit (org.whole.lang.ui.editor.IGEFEditorKit)1