Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to create a comlex list
How to create a comlex list [message #502937] Thu, 10 December 2009 11:05 Go to next message
Eclipse UserFriend
Originally posted by: niels.lippke.airpas.com

Hi all,

I need to display kind of a list in our application.
Each item in the list is a composite describing the item with some labels,
images, etc.
If some of you are familiar with MS Outlook it is similar to their inbox
view.

Now my first approach is using a gridlayout with one column an putting the
composites into it. To achieve the list-effect (e.g. selection) I attached
some mouse and keyboard listeners to it. but this has a lot of drawbacks. As
for example I need to attach those listeners to any control in the each
composite, otherwise the composite doesn't catch the events. And setting a
background color to the composite as selection indicator works but is really
slow (> 1s).

I also played around with a one column table. But this has also some
drawbacks like setting the correct line height, preventing a focus lost on
the table if the user hits the composite, ...

I'm quite uninspired what the best way is to create such a component.

Does anyone have an idea?

Regards, Niels
Re: How to create a comlex list [message #503073 is a reply to message #502937] Thu, 10 December 2009 19:05 Go to previous messageGo to next message
Austin Riddle is currently offline Austin RiddleFriend
Messages: 128
Registered: July 2009
Senior Member
Hello Niels,

I have had the same issues in the past, but opted for the more straightforward approach of using tables and forms. However, following your existing train of thought, here is a quick-and-dirty example that uses a separate composite to handle events for the selected item:

---------------------------------------
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setText(Messages.getString("Inbox"));
toolkit.decorateFormHeading(form.getForm());
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);

TableWrapData td = new TableWrapData();
Section ec = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.TREE_NODE|Section.LEFT_TEXT_CLIENT_ALIGNMENT);
ec.setExpanded(true);
Composite itemHead = toolkit.createComposite(ec, SWT.NONE);
FillLayout fLayout = new FillLayout();
itemHead.setLayout(fLayout);
ec.setText("Today");

Composite sectionClient = toolkit.createComposite(ec);
fLayout = new FillLayout();
fLayout.marginWidth = 0;
sectionClient.setLayout(fLayout);

Composite outlookFormComp = new Composite(sectionClient, SWT.NONE);
GridLayout gridLayout = new GridLayout(1,true);
gridLayout.verticalSpacing = gridLayout.horizontalSpacing = gridLayout.marginWidth = gridLayout.marginHeight = 0;
outlookFormComp.setLayout(gridLayout);

for (int i = 0; i < 5; i++) {
final Composite itemContainer = new Composite(outlookFormComp, SWT.NONE);
itemContainer.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
itemContainer.setLayout(null);
final Composite eventReceiver = new Composite(itemContainer, SWT.NONE);
eventReceiver.setToolTipText("Email tooltip");
final Composite item = new Composite(itemContainer, SWT.BORDER);
eventReceiver.setData("target_item",item);
GridLayout itemLayout = new GridLayout(3,false);
item.setLayout(itemLayout);
itemLayout.marginWidth = itemLayout.marginHeight = 0;

Label iconLbl = new Label(item, SWT.NONE);
GridData gridData = new GridData(SWT.LEFT,SWT.FILL,false,false);
iconLbl.setLayoutData(gridData);
try {
iconLbl.setImage(Graphics.getImage("envelope",new URL(" http://www.thegarden.com/media/insider_email/mail_envelope_i con.gif").openStream()));
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}

Label iLbl = new Label(item, SWT.NONE);
iLbl.setAlignment(SWT.LEFT);
iLbl.setText("email@eclipse.org");
gridData = new GridData(SWT.LEFT,SWT.FILL,true,false);
iLbl.setLayoutData(gridData);

Label dLbl = new Label(item, SWT.NONE);
dLbl.setText("10:34am");
gridData = new GridData(SWT.RIGHT,SWT.FILL,false,false);
dLbl.setLayoutData(gridData);


Label sLbl = new Label(item, SWT.NONE);
sLbl.setText("Announcing RAP 1.3M4");
gridData = new GridData(SWT.FILL,SWT.FILL,true,false);
gridData.horizontalIndent = 23;
gridData.horizontalSpan = 2;
sLbl.setLayoutData(gridData);

Label aLbl = new Label(item, SWT.NONE);
gridData = new GridData(SWT.RIGHT,SWT.FILL,false,false);
aLbl.setLayoutData(gridData);
try {
aLbl.setImage(Graphics.getImage("attach",new URL(" http://www.native-instruments.com/forum/images/ni_misc/paper clip.gif").openStream()));
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}

eventReceiver.addMouseListener(new MouseAdapter()
{
@Override
public void mouseUp(MouseEvent e)
{
if (selComp != null) {
selComp.setBackground(null);
Composite targetComp = (Composite)selComp.getData("target_item");
targetComp.setForeground(null);
selComp.moveAbove(targetComp);
}
selComp = eventReceiver;
eventReceiver.setBackground(Display.getCurrent().getSystemCo lor(SWT.COLOR_LIST_SELECTION));
Composite targetComp = (Composite)eventReceiver.getData("target_item");
eventReceiver.moveBelow(targetComp);
}
});
itemContainer.addControlListener(new ControlAdapter()
{
@Override
public void controlResized(ControlEvent e)
{
Point sz = item.computeSize(itemContainer.getSize().x,SWT.DEFAULT);
item.setSize(sz);
eventReceiver.setSize(sz);
}
});
}
ec.setSeparatorControl(toolkit.createSeparator(ec, SWT.HORIZONTAL));
ec.setClient(sectionClient);
td = new TableWrapData(TableWrapData.FILL_GRAB);
ec.setLayoutData(td);
ec.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
form.reflow(true);
}
});

ec = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.TREE_NODE|Section.LEFT_TEXT_CLIENT_ALIGNMENT);
ec.setSeparatorControl(toolkit.createSeparator(ec, SWT.HORIZONTAL));
ec.setText("Yesterday"); //$NON-NLS-1$
ec.setExpanded(true);
toolkit.paintBordersFor(form.getBody());
}
Re: How to create a comlex list [message #503149 is a reply to message #503073] Fri, 11 December 2009 02:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: niels.lippke.airpas.com

Hi Austin,

using an overlayed composite for the event handling is an interesting
option.
Thank you very much!

Niels
Re: How to create a comlex list [message #503204 is a reply to message #503149] Fri, 11 December 2009 11:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: niels.lippke.airpas.com

Hmm, what are the requirements for this to work? I tried to reproduce it in
my form, but either the evenReceiver or the item component is visible,
whatever is above the other.. The topmost always hides the one below. :(
It also doesn't work if I rip out the section in your sample. But I don't
see the context...



"Niels Lippke" <niels.lippke@airpas.com> schrieb im Newsbeitrag
news:hfstim$rk8$1@build.eclipse.org...
> Hi Austin,
>
> using an overlayed composite for the event handling is an interesting
> option.
> Thank you very much!
>
> Niels
Re: How to create a comlex list [message #503230 is a reply to message #503204] Fri, 11 December 2009 13:21 Go to previous message
Eclipse UserFriend
Originally posted by: niels.lippke.airpas.com

Ah, I see. By setting a correct background mode & removing images and
colors - it finally works.

Regards,

Niels
Previous Topic:Firefox 2.x has problems with displaying Text widgets on business/fancy themes
Next Topic:Detecting page reload of the browser
Goto Forum:
  


Current Time: Tue Dec 07 01:38:04 GMT 2021

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

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

Back to the top