Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Viewer containing a JTable droppable
Viewer containing a JTable droppable [message #461645] Mon, 15 January 2007 11:56 Go to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,

I created a Viewer containing a javax.swing.JTable (using SWT_AWT).
I tried to add a drop support on this viewer, but with no result :/

------//------
In my viewer constructor, I did:

Control composite = new Composite(parent, SWT.NO_BACKGROUND
| SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame((Composite) composite);
Panel panel = new Panel(new BorderLayout()) {
public void update(java.awt.Graphics g) {
paint(g);
}
};
frame.add(panel);
JRootPane root = new JRootPane();
panel.add(root);
java.awt.Container contentPane = root.getContentPane();

contentPane.add(component);

this.control = composite;

the method public Control getControl() returns this.control.

------//------

In the createPartControl of my viewerPart I did:

JTable table =...;

viewer = new TableViewer(parent, SWT.NONE, table);

int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer
getTransfer() };
viewer.addDropSupport(ops, transfers, new TableDropAdapater(viewer));

------//------

The dragEnter method of the DropAdapter is never called...

Am I doing something wrong?

Thanks Guilhaume
Re: Viewer containing a JTable droppable [message #461787 is a reply to message #461645] Wed, 17 January 2007 08:21 Go to previous messageGo to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Hi all,

Does somebody has any idea about that?
I am quite stuck with that

Thanks

Guilhaume
Re: Viewer containing a JTable droppable [message #461974 is a reply to message #461787] Fri, 19 January 2007 13:25 Go to previous messageGo to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Hi all

This is an important issue for me, and I didn't find anything anywhere
about this.

Am I misunderstanding the way to achieve a drop on a JTable?

Thanks

Guilhaume
Re: Viewer containing a JTable droppable [message #461982 is a reply to message #461645] Fri, 19 January 2007 15:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Pinard-Legry Guilhaume schrieb:
> Hi,
>
> I created a Viewer containing a javax.swing.JTable (using SWT_AWT).
> I tried to add a drop support on this viewer, but with no result :/
>
> ------//------
> In my viewer constructor, I did:
>
> Control composite = new Composite(parent, SWT.NO_BACKGROUND
> | SWT.EMBEDDED);
> Frame frame = SWT_AWT.new_Frame((Composite) composite);
> Panel panel = new Panel(new BorderLayout()) {
> public void update(java.awt.Graphics g) {
> paint(g);
> }
> };
> frame.add(panel);
> JRootPane root = new JRootPane();
> panel.add(root);
> java.awt.Container contentPane = root.getContentPane();
>
> contentPane.add(component);
>
> this.control = composite;
>
> the method public Control getControl() returns this.control.
>
> ------//------
>
> In the createPartControl of my viewerPart I did:
>
> JTable table =...;
>
> viewer = new TableViewer(parent, SWT.NONE, table);
>
> int ops = DND.DROP_COPY | DND.DROP_MOVE;
> Transfer[] transfers = new Transfer[] { LocalSelectionTransfer
> getTransfer() };
> viewer.addDropSupport(ops, transfers, new TableDropAdapater(viewer));
>
> ------//------
>

Sorry but I can't follow you here where from do you have a table viewer
class with such a contructor. Is this a home grown viewer? Please post a
standalone snippet where we can reproduce the problem locally on our system.

Tom
Re: Viewer containing a JTable droppable [message #462026 is a reply to message #461982] Mon, 22 January 2007 09:28 Go to previous messageGo to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Tom Schindl wrote:

> Sorry but I can't follow you here where from do you have a table viewer
> class with such a contructor. Is this a home grown viewer? Please post a
> standalone snippet where we can reproduce the problem locally on our system.

> Tom

Hi

of course: here you have:

--------// JTableViewer.java //---------------
package sample.jtable;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JRootPane;

import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;

public class JTableViewer extends StructuredViewer {

private Control control;

public JTableViewer(Composite parent, int style, JComponent component) {
super();

Control composite = new Composite(parent, SWT.NO_BACKGROUND
| SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame((Composite) composite);
Panel panel = new Panel(new BorderLayout()) {

private static final long serialVersionUID = -5327043823430217452L;

public void update(java.awt.Graphics g) {
paint(g);
}
};
frame.add(panel);
JRootPane root = new JRootPane();
panel.add(root);
java.awt.Container contentPane = root.getContentPane();

contentPane.add(component);

control = composite;
}

public Control getControl() {
return control;
}

protected Widget doFindInputItem(Object element) {
return null;
}

protected Widget doFindItem(Object element) {
return null;
}

protected void doUpdateItem(Widget item, Object element, boolean fullMap)
{
}

protected List getSelectionFromWidget() {
return null;
}

protected void internalRefresh(Object element) {
}

public void reveal(Object element) {
}

protected void setSelectionToWidget(List l, boolean reveal) {
}

}


----------------// JTableViewPart.java //-------

package sample.jtable;

import ilog.views.util.swt.IlvEventThreadUtil;

import javax.swing.JTable;

import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class JTableViewPart extends ViewPart {
public static final String ID = JTableViewPart.class.getName();

private JTableViewer viewer;

static {
IlvEventThreadUtil.enableAWTThreadRedirect();
}

public void createPartControl(Composite parent) {

String[] columnNames = { "First Name", "Last Name", "Sport",
"# of Years", "Vegetarian" };

Object[][] data = {
{ "Mary", "Campione", "Snowboarding", new Integer(5),
new Boolean(false) },
{ "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
{ "Kathy", "Walrath", "Knitting", new Integer(2),
new Boolean(false) },
{ "Sharon", "Zakhour", "Speed reading", new Integer(20),
new Boolean(true) },
{ "Philip", "Milne", "Pool", new Integer(10),
new Boolean(false) } };

JTable table = new JTable(data, columnNames);


viewer = new JTableViewer(parent, SWT.NONE, table);

int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer
.getTransfer() };
viewer.addDropSupport(ops, transfers, new JTableDropAdapater(viewer));

}

public void setFocus() {
viewer.getControl().setFocus();
}
}


--------------// JTableDropAdapter.java //-----------

package sample.jtable;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;

public class JTableDropAdapater extends ViewerDropAdapter {

protected JTableDropAdapater(Viewer viewer) {
super(viewer);
}

public boolean performDrop(Object data) {
return true;
}

public boolean validateDrop(Object target, int operation,
TransferData transferType) {
return true;
}

public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
System.out.println("ScheduleDropAdapater.dragEnter called");
}

public void dragLeave(DropTargetEvent event) {
super.dragLeave(event);
System.out.println("ScheduleDropAdapater.dragLeave called");
}

public void dragOver(DropTargetEvent event) {
super.dragOver(event);
System.out.println("ScheduleDropAdapater.dragOver called");
}
}


I hope this clarifies a bit my request.

Thanks for your efforts.

Guilhaume
Re: Viewer containing a JTable droppable [message #462304 is a reply to message #462026] Fri, 26 January 2007 08:51 Go to previous messageGo to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,

does the following code help understanding my request?

Thnaks

Guilhaume

> --------// JTableViewer.java //---------------
> package sample.jtable;

> import java.awt.BorderLayout;
> import java.awt.Frame;
> import java.awt.Panel;
> import java.util.List;

> import javax.swing.JComponent;
> import javax.swing.JRootPane;

> import org.eclipse.jface.viewers.StructuredViewer;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.awt.SWT_AWT;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Widget;

> public class JTableViewer extends StructuredViewer {

> private Control control;

> public JTableViewer(Composite parent, int style, JComponent component) {
> super();

> Control composite = new Composite(parent, SWT.NO_BACKGROUND
> | SWT.EMBEDDED);
> Frame frame = SWT_AWT.new_Frame((Composite) composite);
> Panel panel = new Panel(new BorderLayout()) {

> private static final long serialVersionUID = -5327043823430217452L;

> public void update(java.awt.Graphics g) {
> paint(g);
> }
> };
> frame.add(panel);
> JRootPane root = new JRootPane();
> panel.add(root);
> java.awt.Container contentPane = root.getContentPane();

> contentPane.add(component);

> control = composite;
> }

> public Control getControl() {
> return control;
> }

> protected Widget doFindInputItem(Object element) {
> return null;
> }

> protected Widget doFindItem(Object element) {
> return null;
> }

> protected void doUpdateItem(Widget item, Object element, boolean fullMap)
> {
> }

> protected List getSelectionFromWidget() {
> return null;
> }

> protected void internalRefresh(Object element) {
> }

> public void reveal(Object element) {
> }

> protected void setSelectionToWidget(List l, boolean reveal) {
> }

> }


> ----------------// JTableViewPart.java //-------

> package sample.jtable;

> import ilog.views.util.swt.IlvEventThreadUtil;

> import javax.swing.JTable;

> import org.eclipse.jface.util.LocalSelectionTransfer;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.dnd.DND;
> import org.eclipse.swt.dnd.Transfer;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.ui.part.ViewPart;

> public class JTableViewPart extends ViewPart {
> public static final String ID = JTableViewPart.class.getName();

> private JTableViewer viewer;

> static {
> IlvEventThreadUtil.enableAWTThreadRedirect();
> }

> public void createPartControl(Composite parent) {

> String[] columnNames = { "First Name", "Last Name", "Sport",
> "# of Years", "Vegetarian" };

> Object[][] data = {
> { "Mary", "Campione", "Snowboarding", new Integer(5),
> new Boolean(false) },
> { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
> { "Kathy", "Walrath", "Knitting", new Integer(2),
> new Boolean(false) },
> { "Sharon", "Zakhour", "Speed reading", new Integer(20),
> new Boolean(true) },
> { "Philip", "Milne", "Pool", new Integer(10),
> new Boolean(false) } };

> JTable table = new JTable(data, columnNames);


> viewer = new JTableViewer(parent, SWT.NONE, table);

> int ops = DND.DROP_COPY | DND.DROP_MOVE;
> Transfer[] transfers = new Transfer[] { LocalSelectionTransfer
> .getTransfer() };
> viewer.addDropSupport(ops, transfers, new JTableDropAdapater(viewer));

> }

> public void setFocus() {
> viewer.getControl().setFocus();
> }
> }


> --------------// JTableDropAdapter.java //-----------

> package sample.jtable;

> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.viewers.ViewerDropAdapter;
> import org.eclipse.swt.dnd.DropTargetEvent;
> import org.eclipse.swt.dnd.TransferData;

> public class JTableDropAdapater extends ViewerDropAdapter {

> protected JTableDropAdapater(Viewer viewer) {
> super(viewer);
> }

> public boolean performDrop(Object data) {
> return true;
> }

> public boolean validateDrop(Object target, int operation,
> TransferData transferType) {
> return true;
> }

> public void dragEnter(DropTargetEvent event) {
> super.dragEnter(event);
> System.out.println("ScheduleDropAdapater.dragEnter called");
> }

> public void dragLeave(DropTargetEvent event) {
> super.dragLeave(event);
> System.out.println("ScheduleDropAdapater.dragLeave called");
> }

> public void dragOver(DropTargetEvent event) {
> super.dragOver(event);
> System.out.println("ScheduleDropAdapater.dragOver called");
> }
> }


> I hope this clarifies a bit my request.

> Thanks for your efforts.

> Guilhaume
Re: Viewer containing a JTable droppable [message #462307 is a reply to message #462304] Fri, 26 January 2007 10:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I hope I can wrap my head around this problem on the weekend but I don't
think that I can be of big help the times I did Swing programming are a
long time ago. The only thing I can suggest to you is to use real
SWT-Controls and not Swing components.

I'm sure there's a reason that you are using Swing inside SWT but maybe
you should reajust your decision and use JFace-TableViewer which build
upon a real SWT-Table or if this widget set is not rich enough checkout
the controls from Nebula which will get JFace-Viewer support after M5 is
out.

Why are you using Swing?

Tom

Pinard-Legry Guilhaume schrieb:
> Hi,
>
> does the following code help understanding my request?
>
> Thnaks
> Guilhaume
>
>> --------// JTableViewer.java //---------------
>> package sample.jtable;
>
>> import java.awt.BorderLayout;
>> import java.awt.Frame;
>> import java.awt.Panel;
>> import java.util.List;
>
>> import javax.swing.JComponent;
>> import javax.swing.JRootPane;
>
>> import org.eclipse.jface.viewers.StructuredViewer;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.awt.SWT_AWT;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Control;
>> import org.eclipse.swt.widgets.Widget;
>
>> public class JTableViewer extends StructuredViewer {
>
>> private Control control;
>
>> public JTableViewer(Composite parent, int style, JComponent
>> component) {
>> super();
>
>> Control composite = new Composite(parent, SWT.NO_BACKGROUND
>> | SWT.EMBEDDED);
>> Frame frame = SWT_AWT.new_Frame((Composite) composite);
>> Panel panel = new Panel(new BorderLayout()) {
>
>> private static final long serialVersionUID =
>> -5327043823430217452L;
>
>> public void update(java.awt.Graphics g) {
>> paint(g);
>> }
>> };
>> frame.add(panel);
>> JRootPane root = new JRootPane();
>> panel.add(root);
>> java.awt.Container contentPane = root.getContentPane();
>
>> contentPane.add(component);
>
>> control = composite;
>> }
>
>> public Control getControl() {
>> return control;
>> }
>
>> protected Widget doFindInputItem(Object element) {
>> return null;
>> }
>
>> protected Widget doFindItem(Object element) {
>> return null;
>> }
>
>> protected void doUpdateItem(Widget item, Object element, boolean
>> fullMap) {
>> }
>
>> protected List getSelectionFromWidget() {
>> return null;
>> }
>
>> protected void internalRefresh(Object element) {
>> }
>
>> public void reveal(Object element) {
>> }
>
>> protected void setSelectionToWidget(List l, boolean reveal) {
>> }
>
>> }
>
>
>> ----------------// JTableViewPart.java //-------
>
>> package sample.jtable;
>
>> import ilog.views.util.swt.IlvEventThreadUtil;
>
>> import javax.swing.JTable;
>
>> import org.eclipse.jface.util.LocalSelectionTransfer;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.dnd.DND;
>> import org.eclipse.swt.dnd.Transfer;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.ui.part.ViewPart;
>
>> public class JTableViewPart extends ViewPart {
>> public static final String ID = JTableViewPart.class.getName();
>
>> private JTableViewer viewer;
>
>> static {
>> IlvEventThreadUtil.enableAWTThreadRedirect();
>> }
>
>> public void createPartControl(Composite parent) {
>
>> String[] columnNames = { "First Name", "Last Name", "Sport",
>> "# of Years", "Vegetarian" };
>
>> Object[][] data = {
>> { "Mary", "Campione", "Snowboarding", new Integer(5),
>> new Boolean(false) },
>> { "Alison", "Huml", "Rowing", new Integer(3), new
>> Boolean(true) },
>> { "Kathy", "Walrath", "Knitting", new Integer(2),
>> new Boolean(false) },
>> { "Sharon", "Zakhour", "Speed reading", new Integer(20),
>> new Boolean(true) },
>> { "Philip", "Milne", "Pool", new Integer(10),
>> new Boolean(false) } };
>
>> JTable table = new JTable(data, columnNames);
>
>
>> viewer = new JTableViewer(parent, SWT.NONE, table);
>
>> int ops = DND.DROP_COPY | DND.DROP_MOVE;
>> Transfer[] transfers = new Transfer[] { LocalSelectionTransfer
>> .getTransfer() };
>> viewer.addDropSupport(ops, transfers, new
>> JTableDropAdapater(viewer));
>
>> }
>
>> public void setFocus() {
>> viewer.getControl().setFocus();
>> }
>> }
>
>
>> --------------// JTableDropAdapter.java //-----------
>
>> package sample.jtable;
>
>> import org.eclipse.jface.viewers.Viewer;
>> import org.eclipse.jface.viewers.ViewerDropAdapter;
>> import org.eclipse.swt.dnd.DropTargetEvent;
>> import org.eclipse.swt.dnd.TransferData;
>
>> public class JTableDropAdapater extends ViewerDropAdapter {
>
>> protected JTableDropAdapater(Viewer viewer) {
>> super(viewer);
>> }
>
>> public boolean performDrop(Object data) {
>> return true;
>> }
>
>> public boolean validateDrop(Object target, int operation,
>> TransferData transferType) {
>> return true;
>> }
>
>> public void dragEnter(DropTargetEvent event) {
>> super.dragEnter(event);
>> System.out.println("ScheduleDropAdapater.dragEnter called");
>> }
>
>> public void dragLeave(DropTargetEvent event) {
>> super.dragLeave(event);
>> System.out.println("ScheduleDropAdapater.dragLeave called");
>> }
>
>> public void dragOver(DropTargetEvent event) {
>> super.dragOver(event);
>> System.out.println("ScheduleDropAdapater.dragOver called");
>> }
>> }
>
>
>> I hope this clarifies a bit my request.
>
>> Thanks for your efforts.
>
>> Guilhaume
>
Re: Viewer containing a JTable droppable [message #462313 is a reply to message #462307] Fri, 26 January 2007 15:09 Go to previous messageGo to next message
Pinard-Legry Guilhaume is currently offline Pinard-Legry GuilhaumeFriend
Messages: 11
Registered: July 2009
Junior Member
Hi Tom,

In fact I am using swing because I am developping an RCP application
including already-built swing components, and here, a schedule chart.
It is made of a Jtable and a Jcomponent, and I put this complex component
in a viewer (as I did in the sample for the single jtable).

When I hide the jtable of my schedule chart, the viewer becomes droppable.
If I show back the JTable, the viewer is not droppable anymore.

I shown it with the simple sample.

Thus I cannot replace the swing JTable with the JFace-TableViewer :(

IMHO it looks like a bug (but I'm not sure).
perhaps there a need to register a bug report (but I don't know how to do
that).

Thanks for the time you are spending on this issue.

Cheers

Guilhaume


Tom Schindl wrote:

> Hi,

> I hope I can wrap my head around this problem on the weekend but I don't
> think that I can be of big help the times I did Swing programming are a
> long time ago. The only thing I can suggest to you is to use real
> SWT-Controls and not Swing components.

> I'm sure there's a reason that you are using Swing inside SWT but maybe
> you should reajust your decision and use JFace-TableViewer which build
> upon a real SWT-Table or if this widget set is not rich enough checkout
> the controls from Nebula which will get JFace-Viewer support after M5 is
> out.

> Why are you using Swing?

> Tom
Re: Viewer containing a JTable droppable [message #462315 is a reply to message #462313] Fri, 26 January 2007 15:34 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

You can also try to ask at the SWT-Newsgroup because this all sounds
like a bug in SWT and it's SWT_AWT-Bridge.

Fileing bugs isn't really a problem. Go to
https://bugs.eclipse.org/bugs/ and register an account, then file the
bug against Component SWT on
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform

One more thing I'm not sure I understand is why you wrap up your JTable
with a StructuredViewer what's the purpose of this, don't get me wrong
you can easily do all this but what's the profit of it. Swing-Components
are already MVC based and there's no need to but one more MVC-layer
above it.

Tom

Pinard-Legry Guilhaume schrieb:
> Hi Tom,
>
> In fact I am using swing because I am developping an RCP application
> including already-built swing components, and here, a schedule chart.
> It is made of a Jtable and a Jcomponent, and I put this complex
> component in a viewer (as I did in the sample for the single jtable).
>
> When I hide the jtable of my schedule chart, the viewer becomes droppable.
> If I show back the JTable, the viewer is not droppable anymore.
>
> I shown it with the simple sample.
>
> Thus I cannot replace the swing JTable with the JFace-TableViewer :(
>
> IMHO it looks like a bug (but I'm not sure).
> perhaps there a need to register a bug report (but I don't know how to
> do that).
>
> Thanks for the time you are spending on this issue.
>
> Cheers
>
> Guilhaume
>
>
> Tom Schindl wrote:
>
>> Hi,
>
>> I hope I can wrap my head around this problem on the weekend but I
>> don't think that I can be of big help the times I did Swing
>> programming are a long time ago. The only thing I can suggest to you
>> is to use real SWT-Controls and not Swing components.
>
>> I'm sure there's a reason that you are using Swing inside SWT but
>> maybe you should reajust your decision and use JFace-TableViewer which
>> build upon a real SWT-Table or if this widget set is not rich enough
>> checkout the controls from Nebula which will get JFace-Viewer support
>> after M5 is out.
>
>> Why are you using Swing?
>
>> Tom
>
Previous Topic:[Jobs] JobErrorDialog does not appear in 3.3
Next Topic:Need help with product configuration
Goto Forum:
  


Current Time: Wed Jan 15 11:11:17 GMT 2025

Powered by FUDForum. Page generated in 0.04305 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top