| [news.eclipse.tools.emf] Re: Use of Copy, Paste Command |
What I was getting at with my second sentence was that CopyTo/PasteFromClipboard commands are high level commands that simply use lower level commands (CopyCommand and Add/SetCommand) to do the work. Drag-and-drop also uses the lower level CopyCommand, MoveCommand, AddCommand, RemoveCommand and/or SetCommand, as appropriate, to do its work. All of these lower level commands can also be used to manipulate a model directly (just not through the default UI).
So, if you add your special behavior to the clipboard commands, it won't solve the problem for drag-and-drop, etc. Cut/Paste wouldn't work either, with your approach. It is a very special purpose solution. A better approach would be to make AddCommand do your extra checking... but that means that you need to make sure that the thing being added has all the information you need to do the check. Unless you put it in the model, I think you'll end up overriding a lot of code before it will all hang together.
Frank.
Balaji wrote:
Frank, In a wrapper object for the copy which you put on the
clipboard?). What if the same thing is done using a copy and add command instead
of via the clipboard? Yes. I was hoping to subclass the copy helper and add a variable to store the container of the source object. I don't want to store the container information of my objects in my model. Is there any other way to solve this problem? I can't understand your second sentence. "What if the same thing is done using a copy and add command instead of via the clipboard" - Can you please elaborate on that. ThanksBalaji"Frank Budinsky" <frankb@xxxxxxxxxx> wrote in message news:3F54DA28.616C71F1@xxxxxxxxxx...> Balaji,
>
> It sounds kind of kludgy to enforce this kind of restriction by passing some
> information from a copy command to a paste command (where would you store the
> original's eContainer? In a wrapper object for the copy which you put on the
> clipboard?). What if the same thing is done using a copy and add command instead
> of via the clipboard?
>
> I think that ideally the model should be designed in such a way that the copied
> model object itself has all the necessary state information (maybe it's a
> specific subclass) that controls its suitability for adding at one place or
> another.
>
> Frank.
>
>
> Balaji wrote:
>
> > All,
> > I use my own copy and paste command to copy / paste objects using EMF
> > commands. I had to validate the owner on which the object is pasted.
> > for e.g. A contains a list of B objects.
> > If B's parent is a (instance of A), then B can be pasted only to a.
> >
> > To accomplish this, I need to know the eContainer of B. But the
> > PasteFromClipboardCommand does not provide me with the eContainer of the
> > object copied.
> >
> > command.append
> >
> > (new CommandWrapper()
> >
> > {
> >
> > protected Command createCommand()
> >
> > {
> >
> > // Command copyCommand = CopyCommand.create(domain, domain.getClipboard());
> >
> > CompoundCommand compoundCommand = new CompoundCommand();
> >
> > Collection objectsToBePasted = copyCommand.getResult();
> >
> > ...
> >
> > }
> >
> > The objectsToBePasted has information regarding the object but not the
> > container. What is the recommended approach in this case. Should I store the
> > eContainer of the owner when it is copied and use it when it is pasted ?.
> >
> > Thanks
> >
> > Balaji
>