Home » Eclipse Projects » Rich Client Platform (RCP) » Viewer containing a JTable droppable
| | | |
Re: Viewer containing a JTable droppable [message #462026 is a reply to message #461982] |
Mon, 22 January 2007 09:28 |
Pinard-Legry Guilhaume 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 |
Pinard-Legry Guilhaume 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 |
Thomas Schindl 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 #462315 is a reply to message #462313] |
Fri, 26 January 2007 15:34 |
Thomas Schindl 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
>
|
|
|
Goto Forum:
Current Time: Wed Jan 15 10:52:04 GMT 2025
Powered by FUDForum. Page generated in 0.03721 seconds
|