Java Code Examples for org.eclipse.gef.commands.CompoundCommand#add()

The following examples show how to use org.eclipse.gef.commands.CompoundCommand#add() . 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: ERDiagramAlignmentAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private Command createAlignmentCommand() {
	AlignmentRequest request = new AlignmentRequest(
			RequestConstants.REQ_ALIGN);
	request.setAlignmentRectangle(calculateAlignmentRectangle(request));
	request.setAlignment(alignment);
	List editparts = getOperationSet(request);
	if (editparts.size() < 2)
		return null;

	CompoundCommand command = new CompoundCommand();
	command.setDebugLabel(getText());
	for (int i = 0; i < editparts.size(); i++) {
		EditPart editpart = (EditPart) editparts.get(i);
		command.add(editpart.getCommand(request));
	}
	return command;
}
 
Example 2
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
 FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
 super.executeCurrentCommand();
 FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
 CompoundCommand cc = new CompoundCommand("Check Overlap") ;
 for(IGraphicalEditPart ep : _movingShapes){
	 Location loc = (Location) ((Node) ep.getNotationView()).getLayoutConstraint() ;
	 Point oldLoc = new Point(loc.getX(), loc.getY()) ;
	 Point newLoc = FiguresHelper.handleCompartmentMargin(ep, loc.getX(), loc.getY(),(ep.resolveSemanticElement() instanceof SubProcessEvent)) ;
	 if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
		 cc.add(new ICommandProxy(new SetBoundsCommand(_container.getEditingDomain(), "Check Overlap", new EObjectAdapter(ep.getNotationView()),newLoc))) ;
	 }
 }
 executeCommand(cc) ;
}
 
Example 3
Source File: HorizontalLineAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
private Command alignToStart(int start, List<DiagramWalkerEditPart> list) {
    final CompoundCommand command = new CompoundCommand();

    final ERDiagram diagram = getDiagram();

    for (final AbstractModelEditPart editPart : list) {
        final DiagramWalker nodeElement = (DiagramWalker) editPart.getModel();

        final MoveElementCommand moveCommand =
                new MoveElementCommand(diagram, editPart.getFigure().getBounds(), start, nodeElement.getY(), nodeElement.getWidth(),
                        nodeElement.getHeight(), nodeElement);

        command.add(moveCommand);
    }

    return command.unwrap();
}
 
Example 4
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * creates the command to move the shapes left or right.
 */
protected Command getCommand() {
	if (_container == null) {
		return null;
	}
	CompoundCommand command = new CompoundCommand("Multiple Shape Move");
	TransactionalEditingDomain editingDomain = _container.getEditingDomain();

	Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
	Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
	ZoomManager zoomManager = ((DiagramRootEditPart) 
			getCurrentViewer().getRootEditPart()).getZoomManager();
	spSizeDelta.scale(1/zoomManager.getZoom());

	command.add(_container.getCommand(getSourceRequest()));


	for (IGraphicalEditPart sp : _subProcesses) {
		Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
		spDim.expand(spSizeDelta);
		SetBoundsCommand setBounds = 
			new SetBoundsCommand(editingDomain,"MultipleShape Move", sp, spDim);
		command.add(new ICommandProxy(setBounds));
	}
	return command;
}
 
Example 5
Source File: DragEditPartsTrackerExWithoutCopyWithModKeyPressed.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
	if(getOperationSet().size() > 1){
		FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
		super.executeCurrentCommand();
		FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
		CompoundCommand cc = new CompoundCommand("Check Overlap") ;
		for(Object ep : getOperationSet()){
			if(ep instanceof IGraphicalEditPart){
				IGraphicalEditPart gep = (IGraphicalEditPart) ep ;
				Location loc = (Location) ((Node) ((IGraphicalEditPart) ep).getNotationView()).getLayoutConstraint() ;
				Point oldLoc = new Point(loc.getX(), loc.getY()) ;
				Point newLoc = FiguresHelper.handleCompartmentMargin(gep, loc.getX(), loc.getY(),(gep.resolveSemanticElement() instanceof SubProcessEvent)) ;
				if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
					cc.add(new ICommandProxy(new SetBoundsCommand(gep.getEditingDomain(), "Check Overlap", new EObjectAdapter(gep.getNotationView()),newLoc))) ;
				}
			}
		}
		executeCommand(cc) ;
	}else{
		super.executeCurrentCommand() ;
	}
}
 
Example 6
Source File: AbstractBaseSelectionAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
protected void execute(Event event) {
	GraphicalViewer viewer = this.getGraphicalViewer();

	List<Command> commandList = new ArrayList<Command>();

	for (Object object : viewer.getSelectedEditParts()) {
		List<Command> subCommandList = this.getCommand((EditPart) object,
				event);
		commandList.addAll(subCommandList);
	}

	if (!commandList.isEmpty()) {
		CompoundCommand compoundCommand = new CompoundCommand();
		for (Command command : commandList) {
			compoundCommand.add(command);
		}

		this.execute(compoundCommand);
	}
}
 
Example 7
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * creates the command to move the shapes left or right.
 */
protected Command getCommand() {
	if (_container == null) {
		return null;
	}
	CompoundCommand command = new CompoundCommand("Multiple Shape Move");
	TransactionalEditingDomain editingDomain = _container.getEditingDomain();

	Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
	Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
	ZoomManager zoomManager = ((DiagramRootEditPart) 
			getCurrentViewer().getRootEditPart()).getZoomManager();
	spSizeDelta.scale(1/zoomManager.getZoom());
	command.add(_container.getCommand(getSourceRequest()));


	for (IGraphicalEditPart sp : _subProcesses) {
		Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
		spDim.expand(spSizeDelta);
		SetBoundsCommand setBounds = 
			new SetBoundsCommand(editingDomain,"MultipleShape Move", sp, spDim);
		command.add(new ICommandProxy(setBounds));
	}
	return command;
}
 
Example 8
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
	FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
	super.executeCurrentCommand();
	FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
	CompoundCommand cc = new CompoundCommand("Check Overlap") ;
	for(IGraphicalEditPart ep : _movingShapes){
		 Location loc = (Location) ((Node) ep.getNotationView()).getLayoutConstraint() ;
Point oldLoc = new Point(loc.getX(), loc.getY()) ;
Point newLoc = FiguresHelper.handleCompartmentMargin(ep, loc.getX(), loc.getY(),(ep.resolveSemanticElement() instanceof SubProcessEvent)) ;
if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
 cc.add(new ICommandProxy(new SetBoundsCommand(_container.getEditingDomain(), "Check Overlap", new EObjectAdapter(ep.getNotationView()),newLoc))) ;
}
	}
	executeCommand(cc) ;
}
 
Example 9
Source File: ERDiagramAlignmentAction.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private Command createAlignmentCommand() {
    final AlignmentRequest request = new AlignmentRequest(RequestConstants.REQ_ALIGN);
    request.setAlignmentRectangle(calculateAlignmentRectangle(request));
    request.setAlignment(alignment);
    final List editparts = getOperationSet(request);
    if (editparts.size() < 2)
        return null;

    final CompoundCommand command = new CompoundCommand();
    command.setDebugLabel(getText());
    for (int i = 0; i < editparts.size(); i++) {
        final EditPart editpart = (EditPart) editparts.get(i);
        command.add(editpart.getCommand(request));
    }
    return command;
}
 
Example 10
Source File: ColumnSelectionHandlesEditPolicy.java    From erflute with Apache License 2.0 6 votes vote down vote up
public static Command createMoveColumnGroupCommand(DirectEditRequest editRequest, TableView newTableView, int index) {
    final ColumnGroup columnGroup =
            (ColumnGroup) ((Map<?, ?>) editRequest.getDirectEditFeature())
                    .get(ERDiagramTransferDragSourceListener.MOVE_COLUMN_GROUP_PARAM_GROUP);
    final TableView oldTableView =
            (TableView) ((Map<?, ?>) editRequest.getDirectEditFeature())
                    .get(ERDiagramTransferDragSourceListener.MOVE_COLUMN_GROUP_PARAM_PARENT);
    if (newTableView == oldTableView) {
        return new ChangeColumnOrderCommand(newTableView, columnGroup, index);
    }
    final CompoundCommand command = new CompoundCommand();
    final TableView copyOldTableView = oldTableView.copyData();
    for (final ERColumn column : copyOldTableView.getColumns()) {
        if (column == columnGroup) {
            copyOldTableView.removeColumn(column);
            break;
        }
    }
    final ChangeTableViewPropertyCommand sourceTableCommand = new ChangeTableViewPropertyCommand(oldTableView, copyOldTableView);
    command.add(sourceTableCommand);
    if (!newTableView.getColumns().contains(columnGroup)) {
        command.add(new AddColumnGroupCommand(newTableView, columnGroup, index));
    }
    return command.unwrap();
}
 
Example 11
Source File: CamelEditorDropTargetListener.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private List<Command> createRefreshingPropertiesCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node) {
    if (selectedNode.getObject().getProperty().getItem() instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) selectedNode.getObject().getProperty().getItem();
        // command used to set job
        String value = processItem.getProperty().getId();
        PropertyChangeCommand command4 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_PROCESS.getName(), value);
        cc.add(command4);
        PropertyChangeCommand command5 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_CONTEXT.getName(),
                processItem.getProcess().getDefaultContext());
        cc.add(command5);
    }
    return null;
}
 
Example 12
Source File: CustomResizableEditPolicyEx.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Command getMoveCommand(final ChangeBoundsRequest request) {
    if (request.getEditParts() != null && !request.getEditParts().isEmpty() && request.getEditParts().get(0) instanceof CustomLaneEditPart) {
        return null;// DON'T MOVE A LANE
    }

    if (!request.getEditParts().isEmpty() && request.getEditParts().get(0) instanceof CustomSubProcessEvent2EditPart && checkOverlapOtherFigures(request)
            && request.getEditParts() != null) {
        return null; // DON'T MOVE A SUBPROCESS EVENT IF LOCATION NOT VALID
    }

    final CompoundCommand cc = new CompoundCommand("Move");
    cc.add(super.getMoveCommand(request));
    if (request.getEditParts() != null && !request.getEditParts().isEmpty()) {
        for (final Object ep : request.getEditParts()) {
            if (ep instanceof SubProcessEvent2EditPart) {
                for (final Object c : ((SubProcessEvent2EditPart) ep).getChildren()) {
                    if (c instanceof CustomSubprocessEventCompartmentEditPart) {
                        final ChangeBoundsRequest childRequest = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
                        final List eps = new ArrayList();
                        for (final Object child : ((CustomSubprocessEventCompartmentEditPart) c).getChildren()) {
                            eps.add(child);
                        }
                        childRequest.setEditParts(eps);
                        childRequest.setMoveDelta(request.getMoveDelta());
                        final HashMap<Object, Object> map = new HashMap<Object, Object>();
                        map.put(MOVE_COMPARTMENT_CHILDREN, MOVE_COMPARTMENT_CHILDREN);
                        childRequest.setExtendedData(map);
                        if (!eps.isEmpty()) {
                            cc.add(((CustomSubprocessEventCompartmentEditPart) c).getCommand(childRequest));
                        }
                    }
                }
            }
        }
    }
    return cc.unwrap();

}
 
Example 13
Source File: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected Command getAddCommand( Request req )
{
	EditPart parent = getHost( );
	ChangeBoundsRequest request = (ChangeBoundsRequest) req;
	List editParts = request.getEditParts( );
	CompoundCommand command = new CompoundCommand( );
	for ( int i = 0; i < editParts.size( ); i++ )
	{
		EditPart child = (EditPart) editParts.get( i );
		command.add( createAddCommand( parent,
				child,
				getInsertionReference( request ) ) );
	}
	return command.unwrap( );
}
 
Example 14
Source File: VerticalLineAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
private Command alignToStart(int start, List<DiagramWalkerEditPart> list) {
    final CompoundCommand command = new CompoundCommand();

    for (final DiagramWalkerEditPart editPart : list) {
        final DiagramWalker nodeElement = (DiagramWalker) editPart.getModel();

        final MoveElementCommand moveCommand =
                new MoveElementCommand(getDiagram(), editPart.getFigure().getBounds(), nodeElement.getX(), start,
                        nodeElement.getWidth(), nodeElement.getHeight(), nodeElement);

        command.add(moveCommand);
    }

    return command.unwrap();
}
 
Example 15
Source File: ViewEditPart.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static CompoundCommand createChangeViewPropertyCommand(ERDiagram diagram, ERView view, ERView copyView) {
    final CompoundCommand command = new CompoundCommand();

    final ChangeTableViewPropertyCommand changeViewPropertyCommand = new ChangeTableViewPropertyCommand(view, copyView);
    command.add(changeViewPropertyCommand);

    return command;
}
 
Example 16
Source File: ColorAndFontPropertySection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Command getCommand(Request request) {
	List operationSet = getInput();
	Iterator editParts = operationSet.iterator();
	CompoundCommand command = new CompoundCommand("Change Font");
	while (editParts.hasNext()) {
		EditPart editPart = (EditPart) editParts.next();
		Command curCommand = editPart.getCommand(request);
		if (curCommand != null) {
			command.add(curCommand);
		}
	}
	return command.isEmpty() || command.size() != operationSet.size() ? UnexecutableCommand.INSTANCE
			: (Command) command;
}
 
Example 17
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Command getCommand(Request request) {
	if (!RequestConstants.REQ_RESIZE.equals(request.getType())
			&& !RequestConstants.REQ_MOVE.equals(request.getType())) {
		return null;
	}

	if (request instanceof SetPreferredSizeRequest) {
		showSourceFeedback(request);
	}

	ChangeBoundsRequest cbr = (ChangeBoundsRequest) request;
	CompoundCommand result = new CompoundCommand();

	// Update Bounds of the container hierarchy
	if (containerHierachy != null) {
		for (IGraphicalEditPart currentContainer : containerHierachy) {
			IFigure figure = currentContainer.getFigure();
			SetBoundsCommand boundsCommand = new SetBoundsCommand(getHost().getEditingDomain(),
					DiagramUIMessages.SetLocationCommand_Label_Resize,
					new EObjectAdapter(currentContainer.getNotationView()), figure.getBounds());
			result.add(new ICommandProxy(boundsCommand));
			FixedBendpointEditPolicy editPolicy = (FixedBendpointEditPolicy) currentContainer
					.getEditPolicy(FixedBendpointEditPolicy.ROLE);
			if (editPolicy != null) {
				Command command = editPolicy.getCommand(cbr);
				result.add(command);
			}

			// Update child bounds of elements that stand in the way...
			List<IGraphicalEditPart> children = currentContainer.getParent().getChildren();
			for (IGraphicalEditPart childPart : children) {
				if (cbr.getEditParts().contains(childPart))
					continue;
				IFigure childFigure = childPart.getFigure();
				if (childPart == currentContainer)
					continue;
				SetBoundsCommand childBoundsCommand = new SetBoundsCommand(getHost().getEditingDomain(),
						DiagramUIMessages.SetLocationCommand_Label_Resize,
						new EObjectAdapter(childPart.getNotationView()), childFigure.getBounds());
				result.add(new ICommandProxy(childBoundsCommand));
			}
		}
	}
	return result;
}
 
Example 18
Source File: CustomCreationEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Command getReparentCommand(final ChangeBoundsRequest request) {
	final CompoundCommand cc = new CompoundCommand();
	if(getHost() instanceof ITextAwareEditPart){
		return UnexecutableCommand.INSTANCE;
	}
	if(request.getExtendedData().get("DELETE_FROM_LANE") != null){
		return super.getReparentCommand(request);
	}
	if(getHost() instanceof CustomPoolCompartmentEditPart
			&& request.getEditParts().get(0) != null
			&& ((EditPart) request.getEditParts().get(0)).getParent() instanceof CustomLaneCompartmentEditPart){
		return UnexecutableCommand.INSTANCE;
	}

	if(getHost() instanceof CustomSubprocessEventCompartmentEditPart
			&& request.getEditParts().get(0) != null){
		for(final Object child : request.getEditParts()){
			if(child instanceof IGraphicalEditPart){
				if(!((IGraphicalEditPart) child).getTargetConnections().isEmpty() ||
						!((IGraphicalEditPart) child).getSourceConnections().isEmpty()){
					return  UnexecutableCommand.INSTANCE;
				} else {
					if (child instanceof StartTimerEvent2EditPart
							&& !(((IGraphicalEditPart) child).getParent() instanceof CustomSubprocessEventCompartmentEditPart)
							&& !((IGraphicalEditPart)child).getParent().equals(getHost())){
						final Command editCommand = editTimerEventValue((IGraphicalEditPart)child);
						if (editCommand.canExecute()){
							cc.add(editCommand);
						}
					}
				}
			}
	}
	}
	if(getHost() instanceof CustomSubProcessEvent2EditPart){
		return  UnexecutableCommand.INSTANCE;
	}

	if(getHost() instanceof CustomLaneEditPart){
		if( request.getLocation() != null){
			return   UnexecutableCommand.INSTANCE;
		}

	}
	cc.add(super.getReparentCommand(request));
	return cc;
}
 
Example 19
Source File: RestResponseSchemaController.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
@Override
public Command createComboCommand(SelectionEvent event) {
	//Change the body type according to selected return body type
	Command changePropertyCommand = super.createComboCommand(event);
	Object newReturnType = null;
	if (changePropertyCommand != null) {
		newReturnType = ((PropertyChangeCommand) changePropertyCommand).getNewValue();
	}
	if (newReturnType == null) {
		return null;
	}
	
	//get old metadata column
	List<IMetadataTable> metadataList = ((INode) elem).getMetadataList();
	IMetadataTable oldMetadataTable = null;
	if (metadataList != null && metadataList.size() > 0) {
		oldMetadataTable = metadataList.get(0);
	} else {
		metadataList = new ArrayList<IMetadataTable>();
		((INode) elem).setMetadataList(metadataList);
	}
	
	//create new metadata column
	IMetadataTable newMetadataTable = oldMetadataTable == null ? new MetadataTable()
			: oldMetadataTable.clone();
	List<IMetadataColumn> listColumns = newMetadataTable.getListColumns();
	if (listColumns == null) {
		listColumns = new ArrayList<IMetadataColumn>();
		newMetadataTable.setListColumns(listColumns);
	}
	IMetadataColumn bodyColumn = listColumns.size() > 0 ? listColumns
			.get(0) : new MetadataColumn();
	bodyColumn.setId("body");
	bodyColumn.setTalendType(newReturnType.toString());
	listColumns.clear();
	listColumns.add(bodyColumn);
	metadataList.clear();
	metadataList.add(newMetadataTable);

	//construct change metadata command
	ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(
			(INode) elem, null, oldMetadataTable, newMetadataTable);

	//construct compound command by combining above 2 commands
	CompoundCommand compoundCommand = new CompoundCommand();
	compoundCommand.add(changePropertyCommand);
	compoundCommand.add(changeMetadataCommand);

	return compoundCommand;
}
 
Example 20
Source File: VerticalLineAction.java    From ermasterr with Apache License 2.0 3 votes vote down vote up
private Command alignToStart(final int start, final List<NodeElementEditPart> list) {
    final CompoundCommand command = new CompoundCommand();

    for (final NodeElementEditPart editPart : list) {
        final NodeElement nodeElement = (NodeElement) editPart.getModel();

        final MoveElementCommand moveCommand = new MoveElementCommand(getDiagram(), editPart.getFigure().getBounds(), nodeElement.getX(), start, nodeElement.getWidth(), nodeElement.getHeight(), nodeElement);

        command.add(moveCommand);
    }

    return command.unwrap();
}