use of org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor in project statecharts by Yakindu.
the class UpdateAnnotationsOnCreationCommand method doExecuteWithResult.
@SuppressWarnings("unchecked")
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
final Object parent = request.getExtendedData().get(TREE_NODE_PARENT);
if (parent != null && parent instanceof IGraphicalEditPart) {
final IGraphicalEditPart parentEditPart = (IGraphicalEditPart) parent;
final List<IGraphicalEditPart> editPartList = TreeLayoutUtil.getOrderedTreeChildren(parentEditPart);
// Look if creation is done in context of merging elements, remove
// elements to merge and update
// annotation of elements.
final Object object = request.getExtendedData().get(ELEMENTS_TO_MERGE);
if (object != null && object instanceof List<?>) {
final List<IGraphicalEditPart> elements = (List<IGraphicalEditPart>) object;
editPartList.removeAll(elements);
final List<View> viewList = TreeLayoutUtil.getViews(elements);
TreeLayoutUtil.setTreeNodesPositionAnnotation(viewList);
}
final int position = TreeLayoutUtil.getNewTreeNodePosition(request.getLocation(), editPartList);
if (position != -1 && !request.getViewDescriptors().isEmpty()) {
final ViewDescriptor viewDescriptor = request.getViewDescriptors().get(0);
final View newView = (View) viewDescriptor.getAdapter(View.class);
final List<View> viewList = TreeLayoutUtil.getViews(editPartList);
if (position == viewList.size()) {
viewList.add(newView);
} else {
viewList.add(position, newView);
}
TreeLayoutUtil.setTreeNodesPositionAnnotation(viewList);
TreeLayoutUtil.setTreeNodeParentAnnotation(newView, parentEditPart.getNotationView());
return CommandResult.newOKCommandResult();
}
}
return CommandResult.newErrorCommandResult(new ExecutionException("ParentTreeNode EditPart not found."));
}
use of org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor in project statecharts by Yakindu.
the class StateCompartmentCreationEditPolicy method getCreateCommand.
@Override
protected Command getCreateCommand(CreateViewRequest request) {
StateEditPart parent = (StateEditPart) getHost().getParent();
BooleanValueStyle isInline = GMFNotationUtil.getBooleanValueStyle(parent.getNotationView(), DiagramPartitioningUtil.INLINE_STYLE);
if (isInline != null && !isInline.isBooleanValue())
return UnexecutableCommand.INSTANCE;
List<? extends ViewDescriptor> viewDescriptors = request.getViewDescriptors();
for (ViewDescriptor viewDescriptor : viewDescriptors) {
String semanticHint = viewDescriptor.getSemanticHint();
if (ViewType.NOTE.equals(semanticHint) || ViewType.NOTEATTACHMENT.equals(semanticHint) || ViewType.TEXT.equals(semanticHint)) {
return UnexecutableCommand.INSTANCE;
}
}
return super.getCreateCommand(request);
}
Aggregations