Java源码示例:org.eclipse.gef.commands.Command
示例1
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;
}
示例2
private Command createCommand(final List objects, final RGB rgb) {
if (objects.isEmpty()) {
return null;
}
if (!(objects.get(0) instanceof GraphicalEditPart)) {
return null;
}
final CompoundCommand command = new CompoundCommand();
for (int i = 0; i < objects.size(); i++) {
final GraphicalEditPart part = (GraphicalEditPart) objects.get(i);
final Object modelObject = part.getModel();
if (modelObject instanceof ViewableModel) {
command.add(new ChangeBackgroundColorCommand((ViewableModel) modelObject, rgb.red, rgb.green, rgb.blue));
} else if (modelObject instanceof ConnectionElement) {
command.add(new ChangeConnectionColorCommand((ConnectionElement) modelObject, rgb.red, rgb.green, rgb.blue));
}
}
return command;
}
示例3
@Override
protected Command getCreateBendpointCommand(BendpointRequest bendpointrequest) {
final AbstractConnectionEditPart connectionEditPart = (AbstractConnectionEditPart) getHost();
final WalkerConnection connection = (WalkerConnection) connectionEditPart.getModel();
if (connection.getSourceWalker() == connection.getTargetWalker()) {
return null;
}
final Point point = bendpointrequest.getLocation();
getConnection().translateToRelative(point);
final CreateBendpointCommand createBendpointCommand =
new CreateBendpointCommand(connection, point.x, point.y, bendpointrequest.getIndex());
return createBendpointCommand;
}
示例4
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();
}
示例5
@Override
public Command getCommand(Request request) {
if (ERDiagramTransferDragSourceListener.REQUEST_TYPE_PLACE_TABLE.equals(request.getType())) {
final DirectEditRequest editRequest = (DirectEditRequest) request;
final Object feature = editRequest.getDirectEditFeature();
if (feature instanceof ERTable) {
final ERTable ertable = (ERTable) feature;
return new PlaceTableCommand(ertable);
}
if (feature instanceof List) {
@SuppressWarnings("unchecked")
final List<ERTable> list = (List<ERTable>) feature;
return new PlaceTableCommand(list);
}
}
return super.getCommand(request);
}
示例6
/**
* Calls the {@link DropObjectsRequest} on an EditPart.
* @param EP - The EditPart that is to be added to
* @param diagramElements - The Elements that are to be added
*/
@SuppressWarnings("unchecked")
public static void addElementsToEditPart(EditPart EP, Collection<? extends Element> diagramElements) {
List<Element> diagramElementsList;
if(!(diagramElements instanceof List<?>)){
diagramElementsList = (List<Element>) createList(diagramElements);
}else{
diagramElementsList = (List<Element>) diagramElements;
}
if(!diagramElementsList.isEmpty()){
DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
dropObjectsRequest.setObjects(diagramElementsList);
dropObjectsRequest.setLocation(new Point(0,0));
Command commandDrop = EP.getCommand(dropObjectsRequest);
if (commandDrop != null){
commandDrop.execute();
}
}
}
示例7
/**
* @generated
*/
protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
if (CrossflowElementTypes.StreamType_4001 == req.getElementType()) {
return getGEFWrapper(new StreamTypeCreateCommand(req, req.getSource(), req.getTarget()));
}
if (CrossflowElementTypes.StreamInputOf_4005 == req.getElementType()) {
return getGEFWrapper(new StreamInputOfCreateCommand(req, req.getSource(), req.getTarget()));
}
if (CrossflowElementTypes.TaskOutput_4003 == req.getElementType()) {
return null;
}
return null;
}
示例8
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例9
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例10
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例11
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return null;
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例12
protected Command createAddCommand( EditPart parent, EditPart child,
EditPart after )
{
Object parentObj = parent.getModel( );
// Object source = child.getModel( );
Object afterObj = after == null ? null : after.getModel( );
Object childParent = getOperator( child ).getModel( );
if ( parentObj instanceof VirtualCrosstabCellAdapter
&& childParent instanceof CrosstabCellAdapter )
{
CrosstabCellAdapter childAdapter = (CrosstabCellAdapter) childParent;
VirtualCrosstabCellAdapter parentAdapter = (VirtualCrosstabCellAdapter) parentObj;
if ( parentAdapter.getType( ) == VirtualCrosstabCellAdapter.IMMACULATE_TYPE
|| parentAdapter.getType( ) == VirtualCrosstabCellAdapter.MEASURE_TYPE )
{
return UnexecutableCommand.INSTANCE;
}
if ( ICrosstabCellAdapterFactory.CELL_FIRST_LEVEL_HANDLE.equals( childAdapter.getPositionType( ) ) )
{
if ( !( after instanceof FirstLevelHandleDataItemEditPart ) )
{
afterObj = null;
}
if ( parent.getParent( ) == getOperator( child ).getParent( ) )
{
ChangeAreaCommand command = new ChangeAreaCommand( parentAdapter.getDesignElementHandle( ),
childAdapter.getDesignElementHandle( ),
DNDUtil.unwrapToModel( afterObj ) );
command.setType( parentAdapter.getType( ) );
return command;
}
else
{
return UnexecutableCommand.INSTANCE;
}
}
}
return UnexecutableCommand.INSTANCE;
}
示例13
protected Command createAddCommand(EditPart child, EditPart after) {
int index = getHost().getChildren().indexOf(after);
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
AddCommand command = new AddCommand(editingDomain, new EObjectAdapter((View)getHost().getModel()),
new EObjectAdapter((View)child.getModel()), index);
return new ICommandProxy(command);
}
示例14
protected void createEditPolicies( )
{
installEditPolicy( EditPolicy.COMPONENT_ROLE,
new ReportComponentEditPolicy( ) );
installEditPolicy( EditPolicy.LAYOUT_ROLE,
new ReportFlowLayoutEditPolicy( )
{
@Override
protected Command getAddCommand( Request req )
{
return UnexecutableCommand.INSTANCE;
}
@Override
public EditPart getTargetEditPart( Request request )
{
if (REQ_CREATE.equals(request.getType()))
{
if (((ReportItemHandle)getHost( ).getModel( )).getCurrentView( ) != null)
{
return null;
}
}
return super.getTargetEditPart( request );
}
});
}
示例15
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return null;
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例16
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例17
/**
* {@inheritDoc}
*/
@Override
protected Command createChangeConstraintCommand(final ChangeBoundsRequest request, final EditPart child, final Object constraint) {
final ERDiagram diagram = (ERDiagram) getHost().getModel();
final List selectedEditParts = getHost().getViewer().getSelectedEditParts();
if (!(child instanceof NodeElementEditPart)) {
return null;
}
return createChangeConstraintCommand(diagram, selectedEditParts, (NodeElementEditPart) child, (Rectangle) constraint);
}
示例18
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return null;
}
if (ProcessElementTypes.MessageFlow_4002 == req.getElementType()) {
return getGEFWrapper(new MessageFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例19
@Override
public Command getCommand(Request request) {
if (request instanceof ChangeBoundsRequest) {
return createUpdateAllBendpointsCommand((ChangeBoundsRequest) request);
}
return super.getCommand(request);
}
示例20
@Override
protected Command getReconnectSourceCommand(ReconnectRequest reconnectrequest) {
final WalkerConnection connection = (WalkerConnection) reconnectrequest.getConnectionEditPart().getModel();
if (!(connection instanceof Relationship)) {
return null;
}
final Relationship relation = (Relationship) connection;
if (relation.getSourceWalker() == relation.getTargetWalker()) {
return null;
}
final DiagramWalker newSource = ((DiagramWalker) reconnectrequest.getTarget().getModel()).toMaterialize();
if (!relation.getSourceWalker().equals(newSource)) {
return null;
}
final DiagramWalkerEditPart sourceEditPart = (DiagramWalkerEditPart) reconnectrequest.getConnectionEditPart().getSource();
final Point location = new Point(reconnectrequest.getLocation());
final IFigure sourceFigure = sourceEditPart.getFigure();
sourceFigure.translateToRelative(location);
int xp = -1;
int yp = -1;
final Rectangle bounds = sourceFigure.getBounds();
final Rectangle centerRectangle =
new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
if (!centerRectangle.contains(location)) {
final Point point = ERTableEditPart.getIntersectionPoint(location, sourceFigure);
xp = 100 * (point.x - bounds.x) / bounds.width;
yp = 100 * (point.y - bounds.y) / bounds.height;
}
final ReconnectSourceCommand command = new ReconnectSourceCommand(relation, xp, yp);
return command;
}
示例21
/**
* {@inheritDoc}
*/
@Override
protected Command getConnectionCompleteCommand(
CreateConnectionRequest request) {
AbstractCreateConnectionCommand command = (AbstractCreateConnectionCommand) request
.getStartCommand();
NodeElementEditPart targetEditPart = (NodeElementEditPart) request
.getTargetEditPart();
if (command instanceof AbstractCreateRelationCommand) {
if (!(targetEditPart instanceof TableViewEditPart)) {
return null;
}
}
String validatedMessage = command.validate();
if (validatedMessage != null) {
Activator.showErrorDialog(validatedMessage);
return null;
}
command.setTarget(targetEditPart);
if (!command.canExecute()) {
return null;
}
return command;
}
示例22
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return null;
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例23
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例24
@Override
protected Command getDeleteBendpointCommand(BendpointRequest bendpointrequest) {
final WalkerConnection connection = (WalkerConnection) getHost().getModel();
if (connection.getSourceWalker() == connection.getTargetWalker()) {
return null;
}
final DeleteBendpointCommand command = new DeleteBendpointCommand(connection, bendpointrequest.getIndex());
return command;
}
示例25
/**
* Returns command to reorient EReference based link. New link target or source
* should be the domain model element associated with this node.
*
* @generated
*/
protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
switch (getVisualID(req)) {
case StreamInputOfEditPart.VISUAL_ID:
return getGEFWrapper(new StreamInputOfReorientCommand(req));
case TaskOutputEditPart.VISUAL_ID:
return getGEFWrapper(new TaskOutputReorientCommand(req));
}
return super.getReorientReferenceRelationshipCommand(req);
}
示例26
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
removeEditPolicy(EditPolicyRoles.CONNECTION_HANDLES_ROLE);
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ConstrainedToolbarLayoutEditPolicy() {
@Override
protected Command getAutoSizeCommand(Request request) {
return UnexecutableCommand.INSTANCE;
}
});
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new PreferredSizeHandlerEditPolicy());
}
示例27
/**
* Override in order to change the location if a figure overrides another
*/
@Override
protected Command createChangeConstraintCommand(final EditPart child,
final Object constraint) {
final Rectangle newBounds = (Rectangle) constraint;
final View shapeView = (View) child.getModel();
final TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
return new ICommandProxy(new OverlapSetBoundsCommand(editingDomain,
(GraphicalEditPart) child,
getHost(),
new EObjectAdapter(shapeView),
newBounds));
}
示例28
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return getGEFWrapper(new TextAnnotationAttachmentCreateCommand(req, req.getSource(), req.getTarget()));
}
return null;
}
示例29
/**
* @generated
*/
protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.MessageFlow_4002 == req.getElementType()) {
return null;
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return null;
}
return null;
}
示例30
/**
* @generated
*/
protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
if (ProcessElementTypes.SequenceFlow_4001 == req.getElementType()) {
return getGEFWrapper(new SequenceFlowCreateCommand(req, req.getSource(), req.getTarget()));
}
if (ProcessElementTypes.TextAnnotationAttachment_4003 == req.getElementType()) {
return null;
}
return null;
}