0

我喜欢在调色板的一次拖放中创建两个图形,即在一次拖放中应该创建两个图形,它们都具有单独的 EditPart 和 Model 类。

提前致谢

4

1 回答 1

2

There is multiple ways to make this happen: the easiest is to make you creationFactory return an array or a list of objects. Then, in you

protected Command getCreateCommand(final CreateRequest request) {
   if (request.getNewObject() instanceof List<?>/Object[]) {
     ...
   }
}

or, the other way is to sublcass CreationTool to have a List of creation factories. Then, create a custom request type, for example,

public class MultiCreateRequest extends Request {
    ...    
}

and override getCommand(Request request) dispatching method that it will handle that case:

public Command getCommand(Request request) {
   if (REQ_MULTI_CREATE.equals(request.getType()))
      return getMultiCreateCommand((MultiCreateRequest) request);
}

when subclassing creation tool you should pay you attention to:

Constructor
createTargetRequest() (return MultiCreateRequest)
getCommandName() (return REQ_MULTI_CREATE)
getCreateRequest() (specify)
selectAddedObject(EditPartViewer viewer) (to select all created that way objects)
updateTargetRequest() (specify)

Oh, i've actually came up with the idea, that creation new Tool subclassing TargetingTool is a better idea then subclassing CreationTool. Instead, you can just copy implementation (it's easy actually) and change it as you need.

于 2012-08-23T12:59:13.383 回答