Java Code Examples for org.eclipse.gmf.runtime.common.core.command.CommandResult#newErrorCommandResult()

The following examples show how to use org.eclipse.gmf.runtime.common.core.command.CommandResult#newErrorCommandResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSemanticModification.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Executes the modification in a transactional command.
 */
public void modify() {
	if (! isApplicable()) throw new IllegalStateException("Modification " + getClass().getSimpleName() + " is not executable.");
	
	final EObject semanticObject = getTargetView().getElement();
	AbstractTransactionalCommand refactoringCommand = new AbstractTransactionalCommand(
			TransactionUtil.getEditingDomain(semanticObject), getClass().getName(), Collections.EMPTY_LIST) {
		@Override
		protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
				throws ExecutionException {
			try {
				AbstractSemanticModification.this.execute(semanticObject, getTargetView());
			} catch (Exception ex) {
				ex.printStackTrace();
				return CommandResult.newErrorCommandResult(ex);
			}
			return CommandResult.newOKCommandResult();
		}
	};
	executeCommand(refactoringCommand, semanticObject.eResource());
}
 
Example 2
Source File: OverlapSetBoundsCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
    if (adapter == null) {
        return CommandResult.newErrorCommandResult("SetBoundsCommand: viewAdapter does not adapt to IView.class");
    }
    final View view = (View) adapter.getAdapter(View.class);
    final Point location = bounds.getLocation();
    if (location != null) {
        Point newLoc = location.getCopy();
        if (FiguresHelper.AVOID_OVERLAP_ENABLE) {
            newLoc = findValidLocation(newLoc);
            if (!newLoc.equals(handleMargins(newLoc))) { //Still overlapping
                return CommandResult.newCancelledCommandResult();
            }
        }
        ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(newLoc.x));
        ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(newLoc.y));
    }
    final Dimension size = bounds.getSize();
    if (size != null) {
        ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getSize_Width(), Integer.valueOf(size.width));
        ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getSize_Height(), Integer.valueOf(size.height));
    }
    return CommandResult.newOKCommandResult();
}
 
Example 3
Source File: ExtractAsCallActivityTransactionalCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    List<?> selectedEditParts = editor.getDiagramGraphicalViewer().getSelectedEditParts();
    List<IGraphicalEditPart> selectedGraphicalEditParts = new ArrayList<IGraphicalEditPart>();
    for (Object ep : selectedEditParts) {
        if (ep instanceof IGraphicalEditPart) {
            selectedGraphicalEditParts.add((IGraphicalEditPart) ep);
        }
    }
    List<IGraphicalEditPart> parts = GMFTools.addMissingConnectionsAndBoundaries(selectedGraphicalEditParts);
    List<String> errors = evaluateErrors(parts);
    if (!errors.isEmpty()) {
        return CommandResult.newErrorCommandResult(createErrorMessage(errors));
    } else {
        extractAsCallActivity(parts);
    }
    return CommandResult.newOKCommandResult();
}
 
Example 4
Source File: DomainChangeCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
	try {
		Statechart statechart = (Statechart) DiagramPartitioningUtil.getSharedDomain().getResourceSet()
				.getEObject(EcoreUtil.getURI(referencedStatechart), true);
		(statechart).setDomainID(validDomain);
	} catch (Exception ex) {
		return CommandResult.newErrorCommandResult(ex);
	}
	return CommandResult.newOKCommandResult();
}
 
Example 5
Source File: UpdateAnnotationsOnMoveCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
		IAdaptable info) throws ExecutionException {

	final View parentView = TreeLayoutUtil.getTreeNodeParentView(editPart
			.getNotationView());

	if (parentView != null) {
		final IGraphicalEditPart parentEditPart = (IGraphicalEditPart) editPart
				.findEditPart(editPart.getParent(), parentView.getElement());
		if (parentEditPart != null) {
			final List<IGraphicalEditPart> treeChildren = new ArrayList<IGraphicalEditPart>(

			TreeLayoutUtil.getOrderedTreeChildren(parentEditPart));
			if (!treeChildren.isEmpty()) {
				final int oldPos = treeChildren.indexOf(editPart);
				final int newPos = layoutConstraint.getTreeInnerRankIndex();

				if (newPos != -1) {
					if (oldPos != newPos) {
						final IGraphicalEditPart element = treeChildren
								.get(oldPos);
						treeChildren.remove(oldPos);
						treeChildren.add(newPos, element);
						TreeLayoutUtil
								.setTreeNodesPositionAnnotation(TreeLayoutUtil
										.getViews(treeChildren));
					}
				}
				return CommandResult.newOKCommandResult();
			}

		}
	}
	return CommandResult
			.newErrorCommandResult("Parent view or parent edit part not found!");
}
 
Example 6
Source File: InitializeTreeNodeAnnotationsCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
		IAdaptable info) throws ExecutionException {
	if (CommandUtil.executeUndoableOperation(
			annotateElements(TreeLayoutUtil
					.getOrderedTreeChildren(treeRootNodeEditPart))).isOK()) {
		return CommandResult.newOKCommandResult();
	}
	return CommandResult.newErrorCommandResult(new ExecutionException(
			"Error while annotating model elements!"));
}
 
Example 7
Source File: SetTreeNodesPositionAnnotationCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
		IAdaptable info) throws ExecutionException {

	if (viewElements != null) {
		TreeLayoutUtil.setTreeNodesPositionAnnotation(viewElements);
		return CommandResult.newOKCommandResult();
	}

	return CommandResult
			.newErrorCommandResult("SetTreeNodesPositionAnnotationCommand: viewElements is null!");
}