use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.
the class StyledTreePartFactory method createEditPart.
public EditPart createEditPart(EditPart context, Object modelEntity) {
IEntityPart contextPart = (IEntityPart) context;
IEntity entity = (IEntity) modelEntity;
EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
if (ed.equals(CommonsEntityDescriptorEnum.Resolver))
return new PlaceHolderPart();
else {
IEntityStyling entityStyling = notationStyling.getEntityStyling(this, contextPart, entity);
switch(ed.getEntityKind()) {
case SIMPLE:
return new SimpleEntityStyledTreePart(this, entityStyling);
case COMPOSITE:
return new CompositeEntityStyledTreePart(this, entityStyling);
default:
case DATA:
// TODO test
if (entity.wGetEntityDescriptor().getName().equals("SimpleName") && entity.wGetParent().wGetEntityDescriptor().getName().equals("Feature"))
entity.wGetEntityDescriptor();
switch(notationStyling.getEmbeddingStyle(this, contextPart, entity)) {
case TABLE_CELL:
switch(// TODO replace with styling features
ed.getDataKind()) {
case STRING:
return new LiteralTextualEntityPart();
default:
return new LiteralDataEntityPart();
}
case NONE:
default:
return new DataEntityStyledTreePart(this, entityStyling);
}
}
}
}
use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.
the class ModelMergeViewer method createMergeArea.
protected Control createMergeArea(Composite parent) {
IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
IEclipseContext params = EclipseContextFactory.create();
params.set("parent", parent);
params.set(IImportAsModelDialogFactory.class, factory);
viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, getContext(), params);
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(E4Utils.createSelectionBindings(event, getContext()));
}
});
viewer.getControl().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent event) {
}
@SuppressWarnings("unchecked")
@Override
public void focusGained(FocusEvent event) {
getContext().set(IEntityPartViewer.class, viewer);
getContext().set(ActionRegistry.class, actionRegistry);
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
}
});
viewer.addPartFocusListener(new IPartFocusListener() {
@SuppressWarnings("unchecked")
public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
}
});
E4KeyHandler keyHandler = new E4KeyHandler(getContext());
keyHandler.setParent(new E4NavigationKeyHandler(getContext()));
viewer.setKeyHandler(keyHandler);
viewer.setEntityContents(createDefaultContents());
getContext().set(IEntityPartViewer.class, viewer);
actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, getContext());
actionRegistry.registerWorkbenchActions();
getContext().set(ActionRegistry.class, actionRegistry);
JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, getContext());
contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
viewer.setContextMenu(new ContextMenuProvider(viewer) {
@Override
public void buildContextMenu(IMenuManager menuManager) {
contextMenuProvider.populate(menuManager);
}
});
return parent;
}
use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.
the class CommandFactory method create.
public Command create(PartRequest request) {
IPartRequestHandler handler;
// tries to handle operation with custom handlers
List<IPartRequestHandler> handlerList = handlersMap.get(request.getRequestType());
if (handlerList != null && !handlerList.isEmpty()) {
Iterator<IPartRequestHandler> handlerIterator = handlerList.iterator();
while (handlerIterator.hasNext()) {
handler = (IPartRequestHandler) handlerIterator.next();
if (handler.canHandlePartRequest(request))
return handler.handlePartRequest(request);
}
}
// handle basic requests
if (EntityUtils.isComposite(request.getModelEntity()) && request.getRequestType() == PartRequest.MOVE_CHILD)
return moveIndexedFeature.create(request);
if (request.getRequestType() == PartRequest.MOVE_ORPHAN_CHILD) {
if (EntityUtils.isComposite(request.getModelEntity()))
return orphanIndexedFeature.create(request);
else
return orphanFeature.create(request);
}
if (request.getRequestType() == PartRequest.DELETE) {
if (EntityUtils.isComposite(request.getParentModelEntity()))
return removeIndexedFeature.create(request);
else
// was else if (EntityUtils.isSimple(request.getParentModelEntity()))
return removeFeature.create(request);
}
// handle composite and simple requests
if (isDnDRequest(request)) {
boolean isCompositeAddCommand, isReplaceCommand;
isCompositeAddCommand = isReplaceCommand = request.size() > 0;
IEntity targetEntity = request.getModelEntity();
boolean isCloneRequest = request.getRequestType() == PartRequest.CLONE_CHILD;
HashSet<IEntity> targetEntityAncestors = new HashSet<IEntity>();
GenericTraversalFactory tf = GenericTraversalFactory.instance;
IBinaryVisitor ancestorsVisitor = tf.ancestors(tf.collect(tf.identity(), targetEntityAncestors));
ancestorsVisitor.visit(targetEntity);
for (IEntityPart dndPart : request) {
IEntity dndEntity = dndPart.getModelEntity();
if (targetEntityAncestors.contains(dndEntity) && !isCloneRequest)
return UnexecutableCommand.INSTANCE;
EntityDescriptor<?> dndEntityDescriptor = dndEntity.wGetEntityDescriptor();
isCompositeAddCommand &= EntityUtils.isAddable(targetEntity, dndEntityDescriptor) || EntityUtils.isComposite(targetEntity);
isReplaceCommand &= EntityUtils.isReplaceable(targetEntity, dndEntityDescriptor);
}
if (isCompositeAddCommand)
return createCompositeAddCommand(request);
else if (isReplaceCommand)
return createReplaceCommand(request);
else
return UnexecutableCommand.INSTANCE;
}
return null;
}
use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.
the class CaretUtils method getCaretPositions.
public static int getCaretPositions(IEntityPartViewer viewer, IEntity entity) {
IEntityPart entityPart = viewer.getEditPartRegistry().get(entity);
if (!(entityPart instanceof ITextualEntityPart))
throw new IllegalArgumentException("the entity part is not textual");
ITextualEntityPart targetPart = (ITextualEntityPart) entityPart;
return targetPart.getCaretPositions();
}
use of org.whole.lang.ui.editparts.IEntityPart in project whole by wholeplatform.
the class ActivateToolAction method run.
@Override
public void run() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
boolean clearCaret = Tools.TEXTUAL != tool && Tools.TEXTUAL.isActive(viewer);
if (tool.ensureActive(viewer) && clearCaret) {
IEntity focusEntity = bm.wGet("focusEntity");
IEntityPart focusPart = viewer.getEditPartRegistry().get(focusEntity);
if (focusPart instanceof ITextualEntityPart) {
ITextualEntityPart textualPart = (ITextualEntityPart) focusPart;
textualPart.setCaretVisible(false);
viewer.setSelection(new StructuredSelection(textualPart));
}
}
}
Aggregations