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);
}
}
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);
}
});
}
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();
}
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);
}
}
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) {
}
}
}
}
}
Aggregations