Home » Modeling » EMF » TableViewer drag and drop problem
TableViewer drag and drop problem [message #411446] |
Wed, 25 July 2007 21:57  |
Eclipse User |
|
|
|
Hi,
My ecore model has an EClass "Item", and it contains a self reference
"subItems" (0..*, containment). now I need to display top level items with
a jface tableviewer, also I want the rows can be dragged so that users can
change their order. I added code as following:
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
tbv.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(tbv));
tbv.addDropSupport(dndOperations, transfers, new
EditingDomainViewerDropAdapter(editingDomain, tbv));
The problem is when I drop an row onto the other row, the drag source item
disappears because it becomes a sub item of the target item, instead of
moving down under the target item. I can't delete "subItems" reference
because I need it elsewhere.
Any suggestion?
Regards,
Hao
|
|
|
Re: TableViewer drag and drop problem [message #411450 is a reply to message #411446] |
Thu, 26 July 2007 07:52   |
Eclipse User |
|
|
|
Hao,
You could customize the"Item" item provider used specifically for the
table viewer to not return the subItems feature when getChildFeature is
called.
Hao Zhang wrote:
> Hi,
> My ecore model has an EClass "Item", and it contains a self reference
> "subItems" (0..*, containment). now I need to display top level items
> with a jface tableviewer, also I want the rows can be dragged so that
> users can change their order. I added code as following:
>
> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
> tbv.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(tbv));
> tbv.addDropSupport(dndOperations, transfers, new
> EditingDomainViewerDropAdapter(editingDomain, tbv));
>
> The problem is when I drop an row onto the other row, the drag source
> item disappears because it becomes a sub item of the target item,
> instead of moving down under the target item. I can't delete
> "subItems" reference because I need it elsewhere.
>
> Any suggestion?
>
> Regards,
> Hao
>
|
|
|
Re: TableViewer drag and drop problem [message #411495 is a reply to message #411450] |
Thu, 26 July 2007 23:44   |
Eclipse User |
|
|
|
Ed,
I did so but still the same problem, I debugged and found
"costItemItemProvider = new CostItemItemProvider(this)" is called but its
getChildrenFeatures() method is never called which made me once wonder
whether this is the proper way (I'm quite sure my getChildrenFeatures()
method did override):
class TheItemProviderAdapterFactory extends
ModelerItemProviderAdapterFactory {
@Override
public Adapter createCostItemAdapter() {
if (costItemItemProvider == null) {
costItemItemProvider = new CostItemItemProvider(this) {
@Override
public Collection<? extends EStructuralFeature>
getChildrenFeatures(Object object) {
return Collections.EMPTY_LIST;
}
@Override
public String getColumnText(Object object, int columnIndex) {
//...
}
@Override
public Object getColumnImage(Object object, int columnIndex) {
//...
}
};
}
return costItemItemProvider;
}
}
in above codes, "CostItem" is what I mentioned "Item".
Ed Merks wrote:
> Hao,
> You could customize the"Item" item provider used specifically for the
> table viewer to not return the subItems feature when getChildFeature is
> called.
> Hao Zhang wrote:
>> Hi,
>> My ecore model has an EClass "Item", and it contains a self reference
>> "subItems" (0..*, containment). now I need to display top level items
>> with a jface tableviewer, also I want the rows can be dragged so that
>> users can change their order. I added code as following:
>>
>> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
>> Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
>> tbv.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(tbv));
>> tbv.addDropSupport(dndOperations, transfers, new
>> EditingDomainViewerDropAdapter(editingDomain, tbv));
>>
>> The problem is when I drop an row onto the other row, the drag source
>> item disappears because it becomes a sub item of the target item,
>> instead of moving down under the target item. I can't delete
>> "subItems" reference because I need it elsewhere.
>>
>> Any suggestion?
>>
>> Regards,
>> Hao
>>
|
|
|
Re: TableViewer drag and drop problem [message #411509 is a reply to message #411495] |
Fri, 27 July 2007 07:59  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------000302090402030106030507
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Hao,
I'm pretty sure that as a result of *this *attempt to create an
AddCommand in the drag and drop command
protected boolean prepareDropMoveOn()
{
if (isCrossDomain())
{
dragCommand = IdentityCommand.INSTANCE;
dropCommand = UnexecutableCommand.INSTANCE;
}
else
{
dropCommand = *AddCommand*.create(domain, owner, null,
collection);
this method of ItemProviderAdapter is called and that if the
*getChildFeature *method returns a result, the drag and drop command
will try to add to that feature, so try setting a breakpoint in there to
see why the framework is able to create an add command....
protected Command factorAddCommand(EditingDomain domain,
CommandParameter commandParameter)
{
if (commandParameter.getCollection() == null ||
commandParameter.getCollection().isEmpty())
{
return UnexecutableCommand.INSTANCE;
}
final EObject eObject = commandParameter.getEOwner();
final List<Object> list = new
ArrayList<Object>(commandParameter.getCollection());
int index = commandParameter.getIndex();
CompoundCommand addCommand = new
CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL);
while (!list.isEmpty())
{
Iterator<Object> children = list.listIterator();
final Object firstChild = children.next();
*EStructuralFeature childFeature = getChildFeature(eObject,
firstChild);**
*
if (childFeature == null)
{
break;
}
So try setting a breakpoint to see why it's finding a child feature.
Hao Zhang wrote:
> Ed, I did so but still the same problem, I debugged and found
> "costItemItemProvider = new CostItemItemProvider(this)" is called but
> its getChildrenFeatures() method is never called which made me once
> wonder whether this is the proper way (I'm quite sure my
> getChildrenFeatures() method did override):
>
> class TheItemProviderAdapterFactory extends
> ModelerItemProviderAdapterFactory {
>
> @Override
> public Adapter createCostItemAdapter() {
> if (costItemItemProvider == null) {
> costItemItemProvider = new CostItemItemProvider(this) {
> @Override
> public Collection<? extends EStructuralFeature>
> getChildrenFeatures(Object object) {
> return Collections.EMPTY_LIST;
> }
>
> @Override
> public String getColumnText(Object object, int
> columnIndex) {
> //...
> }
>
> @Override
> public Object getColumnImage(Object object, int
> columnIndex) {
> //...
> }
>
> };
> }
>
> return costItemItemProvider;
> }
> }
>
> in above codes, "CostItem" is what I mentioned "Item".
>
> Ed Merks wrote:
>
>> Hao,
>
>> You could customize the"Item" item provider used specifically for
>> the table viewer to not return the subItems feature when
>> getChildFeature is called.
>
>
>> Hao Zhang wrote:
>>> Hi,
>>> My ecore model has an EClass "Item", and it contains a self
>>> reference "subItems" (0..*, containment). now I need to display top
>>> level items with a jface tableviewer, also I want the rows can be
>>> dragged so that users can change their order. I added code as
>>> following:
>>>
>>> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
>>> Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
>>> tbv.addDragSupport(dndOperations, transfers, new
>>> ViewerDragAdapter(tbv));
>>> tbv.addDropSupport(dndOperations, transfers, new
>>> EditingDomainViewerDropAdapter(editingDomain, tbv));
>>>
>>> The problem is when I drop an row onto the other row, the drag
>>> source item disappears because it becomes a sub item of the target
>>> item, instead of moving down under the target item. I can't delete
>>> "subItems" reference because I need it elsewhere.
>>>
>>> Any suggestion?
>>>
>>> Regards,
>>> Hao
>>>
>
>
--------------000302090402030106030507
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hao,<br>
<br>
I'm pretty sure that
|
|
|
Goto Forum:
Current Time: Sat Jul 19 18:41:54 EDT 2025
Powered by FUDForum. Page generated in 0.46462 seconds
|