Home » Modeling » EMF » DND create EObject while dragging
|
Re: DND create EObject while dragging [message #907231 is a reply to message #907220] |
Mon, 03 September 2012 15:22 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
In generated editors we normally just do this and the rest takes care of
itself...
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
viewer.addDragSupport(dndOperations, transfers, new
ViewerDragAdapter(viewer));
viewer.addDropSupport(dndOperations, transfers, new
EditingDomainViewerDropAdapter(editingDomain, viewer));
I don't expect the drag source should create new objects. If views
don't update, it's likely that your item provider isn't producing viewer
update notifications for whatever feature you're modifying. You can
enable that via a GenFeature property.
Typically you'd specialize drag and drop behavior by specializing the
item providers createDragAndDropCommand to produces a specialized
command that does whatever you want it to do...
On 03/09/2012 4:57 PM, Missing name Mising name wrote:
> Hello,
>
> I want to support DND into the generated emf editor from a rcp view.
> The rcp view contains a table viewer with a DragSource, works so far.
>
> In the dragStart method I use the generated Factory classes to create
> an object and the cursor changes correct. In general I can add the
> element.
>
> There are two things I don't understand. I only want a copy and no
> link, why doesn't show the cursor a copy cross?
> The other thing is after dropping the element the editor tab shows
> that the file was changed, but there is no change visible.
>
> Here my dragSource code:
> final DragSource source = new DragSource(commandTable,
> SequenceEditor.DRAG_OPERATIONS);
> source.setTransfer(SequenceEditor.DRAG_TYPES);
> source.addDragListener(new DragSourceAdapter() {
> @Override
> public void dragStart(DragSourceEvent event) {
> event.doit = commandTable.getSelectionCount() == 1 ? true :
> false;
> }
>
> @Override
> public void dragSetData(DragSourceEvent event) {
> StructuredSelection s = (StructuredSelection)
> tableViewer.getSelection();
> Object firstElement = s.getFirstElement();
>
> if (firstElement != null && firstElement instanceof
> CommandDefinition) {
> Command command = DataFactoryImpl.eINSTANCE.createCommand();
> CommandData data =
> DataFactoryImpl.eINSTANCE.createCommandData();
> data.setDefinition((CommandDefinition) firstElement);
> command.setCommandData(data);
>
> event.data = command;
> }
> }
> });
>
> Thanks for any advices. :)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: DND create EObject while dragging [message #907255 is a reply to message #907251] |
Mon, 03 September 2012 16:16 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Yes, in general, the methods that create a command can create any
command. But, look closely at what DragAndDropCommand does. In
particular, note that it implements DragAndDropFeedback. That will be
important for giving the feedback you want. Probably you're better to
create a specialized DragAndDropCommand, typically done by specializing
things like prepareDropMoveOn and methods of that form.
On 03/09/2012 6:05 PM, Missing name Mising name wrote:
>>>> I don't expect the drag source should create new objects. If views
>>>> don't update, it's likely that your item provider isn't producing
>>>> viewer update notifications for whatever feature you're modifying.
>>>> You can enable that via a GenFeature property.
>>> Could that the reason, why there is no chance saved?
>> Not likely. If the editor shows dirty that means a command has been
>> executed. So most likely it's an update problem.
> I will investigate that.
>
>>>> Typically you'd specialize drag and drop behavior by specializing
>>>> the item providers createDragAndDropCommand to produces a
>>>> specialized command that does whatever you want it to do...
>>> I don't get which item providers I shall specialize.
>> Generally the one that will become the owner/container for the thing
>> you're dropping. It's often easier to understand things if you set
>> breakpoints and look what happens at runtime. E.g., set a breakpoint
>> ItemProviderAdapter.createDragAndDropCommand and see when it gets
>> called, and for which objects.[/quote]
> Alright, I found the corresponding one.
> Can I overwrite it basically and return for example an AddCommand?
> Because there is no real drag source, which is modified.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: DND create EObject while dragging [message #907258 is a reply to message #907251] |
Mon, 03 September 2012 16:16 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Yes, in general, the methods that create a command can create any
command. But, look closely at what DragAndDropCommand does. In
particular, note that it implements DragAndDropFeedback. That will be
important for giving the feedback you want. Probably you're better to
create a specialized DragAndDropCommand, typically done by specializing
things like prepareDropMoveOn and methods of that form.
On 03/09/2012 6:05 PM, Missing name Mising name wrote:
>>>> I don't expect the drag source should create new objects. If views
>>>> don't update, it's likely that your item provider isn't producing
>>>> viewer update notifications for whatever feature you're modifying.
>>>> You can enable that via a GenFeature property.
>>> Could that the reason, why there is no chance saved?
>> Not likely. If the editor shows dirty that means a command has been
>> executed. So most likely it's an update problem.
> I will investigate that.
>
>>>> Typically you'd specialize drag and drop behavior by specializing
>>>> the item providers createDragAndDropCommand to produces a
>>>> specialized command that does whatever you want it to do...
>>> I don't get which item providers I shall specialize.
>> Generally the one that will become the owner/container for the thing
>> you're dropping. It's often easier to understand things if you set
>> breakpoints and look what happens at runtime. E.g., set a breakpoint
>> ItemProviderAdapter.createDragAndDropCommand and see when it gets
>> called, and for which objects.[/quote]
> Alright, I found the corresponding one.
> Can I overwrite it basically and return for example an AddCommand?
> Because there is no real drag source, which is modified.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: DND create EObject while dragging [message #907264 is a reply to message #907251] |
Mon, 03 September 2012 16:16 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Yes, in general, the methods that create a command can create any
command. But, look closely at what DragAndDropCommand does. In
particular, note that it implements DragAndDropFeedback. That will be
important for giving the feedback you want. Probably you're better to
create a specialized DragAndDropCommand, typically done by specializing
things like prepareDropMoveOn and methods of that form.
On 03/09/2012 6:05 PM, Missing name Mising name wrote:
>>>> I don't expect the drag source should create new objects. If views
>>>> don't update, it's likely that your item provider isn't producing
>>>> viewer update notifications for whatever feature you're modifying.
>>>> You can enable that via a GenFeature property.
>>> Could that the reason, why there is no chance saved?
>> Not likely. If the editor shows dirty that means a command has been
>> executed. So most likely it's an update problem.
> I will investigate that.
>
>>>> Typically you'd specialize drag and drop behavior by specializing
>>>> the item providers createDragAndDropCommand to produces a
>>>> specialized command that does whatever you want it to do...
>>> I don't get which item providers I shall specialize.
>> Generally the one that will become the owner/container for the thing
>> you're dropping. It's often easier to understand things if you set
>> breakpoints and look what happens at runtime. E.g., set a breakpoint
>> ItemProviderAdapter.createDragAndDropCommand and see when it gets
>> called, and for which objects.[/quote]
> Alright, I found the corresponding one.
> Can I overwrite it basically and return for example an AddCommand?
> Because there is no real drag source, which is modified.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | | | |
Re: DND create EObject while dragging [message #910747 is a reply to message #910709] |
Mon, 10 September 2012 10:21 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 10/09/2012 10:58 AM, Missing name Mising name wrote:
> Hello Ed,
>
> it will be a containment reference, where the drag shall be inserted.
Yes, but the new object your created and added a reference to the
original object you started dragging, that reference is presumably not a
containment.
> For activating a copy drag and drop without pressing ctrl I have to
> call the copy methods from the move methods, right?
Depending on which prepareDrop* method from which you return an
executable command, the feedback will correspond, so if you want it to
appear like creating a link, then specialize that one to return an
executable command. It doesn't sound like you need to copy anything.
You just need to add the object you created to the containment reference.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: DND create EObject while dragging [message #911319 is a reply to message #911290] |
Tue, 11 September 2012 10:48 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 11/09/2012 11:54 AM, Missing name Mising name wrote:
> The ReferenceContent using the normal ItemProviders, so I don't know
> how to disable.
> For example here the getChildren method to emphasize my point:
>
> @Override
> public Collection<?> getChildren(Object object) {
> if (object instanceof ReferenceContentImpl &&
> ((ReferenceContentImpl) object).getReference() != null) {
You should never need to cast to an Impl. Use the interface in the API.
> return ((ReferenceContentImpl) object).getReference().getCommands();
> }
>
> return super.getChildren(object);
> }
>
>
> I want to disable the edit of the command only if they are displayed
> under the reference (Sequence element in the picture)
If you show non-containment references as children, you can make use of
the creation of wrappers. You'd need to specialize this to return true
on the object with the non-containment child
protected boolean isWrappingNeeded(Object object)
{
if (wrappingNeeded == null)
{
wrappingNeeded = Boolean.FALSE;
for (EStructuralFeature f : getAnyChildrenFeatures(object))
{
if (f instanceof EAttribute)
{
wrappingNeeded = Boolean.TRUE;
}
}
}
return wrappingNeeded;
And then this should create a delegating wrapper which you can then
specialize so that there are things you can't do for the wrapper that
you normally could via delegation.
protected Object createWrapper(EObject object, EStructuralFeature
feature, Object value, int index)
{
if (!isWrappingNeeded(object)) return value;
if (FeatureMapUtil.isFeatureMap(feature))
{
value = new
FeatureMapEntryWrapperItemProvider((FeatureMap.Entry)value, object,
(EAttribute)feature, index, adapterFactory, getResourceLocator());
}
else if (feature instanceof EAttribute)
{
value = new AttributeValueWrapperItemProvider(value, object,
(EAttribute)feature, index, adapterFactory, getResourceLocator());
}
else if (!((EReference)feature).isContainment())
{
value = new DelegatingWrapperItemProvider(value, object, feature,
index, adapterFactory);
}
return value;
}
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | |
Goto Forum:
Current Time: Wed Sep 25 19:03:10 GMT 2024
Powered by FUDForum. Page generated in 0.06807 seconds
|