Search in sources :

Example 1 with ViewDescriptor

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."));
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) View(org.eclipse.gmf.runtime.notation.View) ViewDescriptor(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor)

Example 2 with ViewDescriptor

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);
}
Also used : StateEditPart(org.yakindu.sct.ui.editor.editparts.StateEditPart) BooleanValueStyle(org.eclipse.gmf.runtime.notation.BooleanValueStyle) ViewDescriptor(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor)

Aggregations

ViewDescriptor (org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor)2 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 BooleanValueStyle (org.eclipse.gmf.runtime.notation.BooleanValueStyle)1 View (org.eclipse.gmf.runtime.notation.View)1 StateEditPart (org.yakindu.sct.ui.editor.editparts.StateEditPart)1