Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Row-wise table editing
Row-wise table editing [message #64712] Fri, 19 June 2009 08:15 Go to next message
Eclipse UserFriend
Originally posted by: m.kasid.gmail.com

Hi,

Is there a support to have different editors on different rows of Nebula
grid? Currently, we can have editors (text, combo etc.) on columns and this
would mean it will display the same editor for that column in all the
rows...My requirement is something kind of a Transposed table. Is it
possible with Nebula Grid?

Thanks
Mustufa
Re: Row-wise table editing [message #64736 is a reply to message #64712] Fri, 19 June 2009 08:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Yes this is supported using JFace 3.3 API named EditingSupport where you
are asked every time for an editor before displaying it.

You can simply use the code from
http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
This is a general rule everything available from JFace upstream is
available in the Nebula-Grid-Viewer (with small exception when it comes
to Grid-TreeViewer) else it is a bug and needs fixing.

Tom

Mustufa Kasidwala schrieb:
> Hi,
>
> Is there a support to have different editors on different rows of Nebula
> grid? Currently, we can have editors (text, combo etc.) on columns and this
> would mean it will display the same editor for that column in all the
> rows...My requirement is something kind of a Transposed table. Is it
> possible with Nebula Grid?
>
> Thanks
> Mustufa
>
>
Re: Row-wise table editing [message #64758 is a reply to message #64736] Fri, 19 June 2009 08:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m.kasid.gmail.com

Hi Tom,

Thanks for the reply. Yes i did went through the idea you provided in this
article. I can see that you are using Model which is represented in Rows,
although this is the obvious approach of TableViewer/Nebul Grid, my
requirement extends further to the fact that I need Model represented by
Columns rather than rows. Is that possible using the inbuild JFace APIs? or
i will have to do something manually to manage the Model input/output ?

Consider a normal Nebula Grid editor but Rows will take place of Columns and
vice-versa.

Thanks
Mustufa
"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fi0u$sh9$1@build.eclipse.org...
> Hi,
>
> Yes this is supported using JFace 3.3 API named EditingSupport where you
> are asked every time for an editor before displaying it.
>
> You can simply use the code from
> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
> This is a general rule everything available from JFace upstream is
> available in the Nebula-Grid-Viewer (with small exception when it comes
> to Grid-TreeViewer) else it is a bug and needs fixing.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi,
>>
>> Is there a support to have different editors on different rows of Nebula
>> grid? Currently, we can have editors (text, combo etc.) on columns and
>> this
>> would mean it will display the same editor for that column in all the
>> rows...My requirement is something kind of a Transposed table. Is it
>> possible with Nebula Grid?
>>
>> Thanks
>> Mustufa
>>
>>
Re: Row-wise table editing [message #64781 is a reply to message #64758] Fri, 19 June 2009 08:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Sorry I don't get the problem. Whenever the viewer wants to show an
editor he asks the EditingSupport for one.

Based on the information provided to you (you know the column and you
get the domain-object representing the row) you can switch your editor
for every single cell.

Are you asking for a viewer where the Columns are the dynamic part
instead of the rows? Then this is not possible but you should be able to
handle this at the model part by transforming your column domain model
into a row model and feeding it into the viewer. But you original
question was about something completely different so I'm not sure I
understood your problem.

Tom

Mustufa Kasidwala schrieb:
> Hi Tom,
>
> Thanks for the reply. Yes i did went through the idea you provided in this
> article. I can see that you are using Model which is represented in Rows,
> although this is the obvious approach of TableViewer/Nebul Grid, my
> requirement extends further to the fact that I need Model represented by
> Columns rather than rows. Is that possible using the inbuild JFace APIs? or
> i will have to do something manually to manage the Model input/output ?
>
> Consider a normal Nebula Grid editor but Rows will take place of Columns and
> vice-versa.
>
> Thanks
> Mustufa
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:h1fi0u$sh9$1@build.eclipse.org...
>> Hi,
>>
>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>> are asked every time for an editor before displaying it.
>>
>> You can simply use the code from
>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>> This is a general rule everything available from JFace upstream is
>> available in the Nebula-Grid-Viewer (with small exception when it comes
>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>
>> Tom
>>
>> Mustufa Kasidwala schrieb:
>>> Hi,
>>>
>>> Is there a support to have different editors on different rows of Nebula
>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>> this
>>> would mean it will display the same editor for that column in all the
>>> rows...My requirement is something kind of a Transposed table. Is it
>>> possible with Nebula Grid?
>>>
>>> Thanks
>>> Mustufa
>>>
>>>
>
>
Re: Row-wise table editing [message #64804 is a reply to message #64781] Fri, 19 June 2009 09:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m.kasid.gmail.com

Hi Tom,

I think you got my question that I want a viewer where Columns are the
dynamic part. Sorry for the confusion. The previous question was related to
this one as i want dynamic columns plus different editor on each row.

Your suggestion about transforming Column model to Row model could be
explored (it will too complicated though). I was just looking if there is
some inbuilt facility already provided by Nebula Grid.

Anyways, Thanks a lot for the answers.

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fjhu$hmj$1@build.eclipse.org...
> Hi,
>
> Sorry I don't get the problem. Whenever the viewer wants to show an
> editor he asks the EditingSupport for one.
>
> Based on the information provided to you (you know the column and you
> get the domain-object representing the row) you can switch your editor
> for every single cell.
>
> Are you asking for a viewer where the Columns are the dynamic part
> instead of the rows? Then this is not possible but you should be able to
> handle this at the model part by transforming your column domain model
> into a row model and feeding it into the viewer. But you original
> question was about something completely different so I'm not sure I
> understood your problem.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi Tom,
>>
>> Thanks for the reply. Yes i did went through the idea you provided in
>> this
>> article. I can see that you are using Model which is represented in Rows,
>> although this is the obvious approach of TableViewer/Nebul Grid, my
>> requirement extends further to the fact that I need Model represented by
>> Columns rather than rows. Is that possible using the inbuild JFace APIs?
>> or
>> i will have to do something manually to manage the Model input/output ?
>>
>> Consider a normal Nebula Grid editor but Rows will take place of Columns
>> and
>> vice-versa.
>>
>> Thanks
>> Mustufa
>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>> news:h1fi0u$sh9$1@build.eclipse.org...
>>> Hi,
>>>
>>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>>> are asked every time for an editor before displaying it.
>>>
>>> You can simply use the code from
>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>> This is a general rule everything available from JFace upstream is
>>> available in the Nebula-Grid-Viewer (with small exception when it comes
>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>
>>> Tom
>>>
>>> Mustufa Kasidwala schrieb:
>>>> Hi,
>>>>
>>>> Is there a support to have different editors on different rows of
>>>> Nebula
>>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>>> this
>>>> would mean it will display the same editor for that column in all the
>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>> possible with Nebula Grid?
>>>>
>>>> Thanks
>>>> Mustufa
>>>>
>>>>
>>
>>
Re: Row-wise table editing [message #64830 is a reply to message #64804] Fri, 19 June 2009 10:49 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070401020909050409020601
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi,

There no such support for this but IMHO transforming a Row-Model into
Column-Model isn't a problem. Using reflection this is done quite easily
in a generic manner.

I just gave it a try and came up with the snippet attached to this mail
and available from our snippets collection.

Tom

Mustufa Kasidwala schrieb:
> Hi Tom,
>
> I think you got my question that I want a viewer where Columns are the
> dynamic part. Sorry for the confusion. The previous question was related to
> this one as i want dynamic columns plus different editor on each row.
>
> Your suggestion about transforming Column model to Row model could be
> explored (it will too complicated though). I was just looking if there is
> some inbuilt facility already provided by Nebula Grid.
>
> Anyways, Thanks a lot for the answers.
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:h1fjhu$hmj$1@build.eclipse.org...
>> Hi,
>>
>> Sorry I don't get the problem. Whenever the viewer wants to show an
>> editor he asks the EditingSupport for one.
>>
>> Based on the information provided to you (you know the column and you
>> get the domain-object representing the row) you can switch your editor
>> for every single cell.
>>
>> Are you asking for a viewer where the Columns are the dynamic part
>> instead of the rows? Then this is not possible but you should be able to
>> handle this at the model part by transforming your column domain model
>> into a row model and feeding it into the viewer. But you original
>> question was about something completely different so I'm not sure I
>> understood your problem.
>>
>> Tom
>>
>> Mustufa Kasidwala schrieb:
>>> Hi Tom,
>>>
>>> Thanks for the reply. Yes i did went through the idea you provided in
>>> this
>>> article. I can see that you are using Model which is represented in Rows,
>>> although this is the obvious approach of TableViewer/Nebul Grid, my
>>> requirement extends further to the fact that I need Model represented by
>>> Columns rather than rows. Is that possible using the inbuild JFace APIs?
>>> or
>>> i will have to do something manually to manage the Model input/output ?
>>>
>>> Consider a normal Nebula Grid editor but Rows will take place of Columns
>>> and
>>> vice-versa.
>>>
>>> Thanks
>>> Mustufa
>>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>>> news:h1fi0u$sh9$1@build.eclipse.org...
>>>> Hi,
>>>>
>>>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>>>> are asked every time for an editor before displaying it.
>>>>
>>>> You can simply use the code from
>>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>>> This is a general rule everything available from JFace upstream is
>>>> available in the Nebula-Grid-Viewer (with small exception when it comes
>>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>>
>>>> Tom
>>>>
>>>> Mustufa Kasidwala schrieb:
>>>>> Hi,
>>>>>
>>>>> Is there a support to have different editors on different rows of
>>>>> Nebula
>>>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>>>> this
>>>>> would mean it will display the same editor for that column in all the
>>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>>> possible with Nebula Grid?
>>>>>
>>>>> Thanks
>>>>> Mustufa
>>>>>
>>>>>
>>>
>
>


--------------070401020909050409020601
Content-Type: text/plain;
name="GridViewerSnippet7.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="GridViewerSnippet7.java"

LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioKICogQ29weXJpZ2h0IChjKSAy MDA5IFRvbSBT
Y2hpbmRsIGFuZCBvdGhlcnMuCiAqIEFsbCByaWdodHMgcmVzZXJ2ZWQuIFRo aXMgcHJvZ3Jh
bSBhbmQgdGhlIGFjY29tcGFueWluZyBtYXRlcmlhbHMKICogYXJlIG1hZGUg YXZhaWxhYmxl
IHVuZGVyIHRoZSB0ZXJtcyBvZiB0aGUgRWNsaXBzZSBQdWJsaWMgTGljZW5z ZSB2MS4wCiAq
IHdoaWNoIGFjY29tcGFuaWVzIHRoaXMgZGlzdHJpYnV0aW9uLCBhbmQgaXMg YXZhaWxhYmxl
IGF0CiAqIGh0dHA6Ly93d3cuZWNsaXBzZS5vcmcvbGVnYWwvZXBsLXYxMC5o dG1sCiAqCiAq
IENvbnRyaWJ1dG9yczoKICogICAgIFRvbSBTY2hpbmRsIC0gaW5pdGlhbCBB UEkgYW5kIGlt
cGxlbWVudGF0aW9uCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpwYWNr YWdlIG9yZy5l
Y2xpcHNlLnN3dC5uZWJ1bGEuc25pcHBldHMuZ3JpZC52aWV3ZXI7CgppbXBv cnQgamF2YS5i
ZWFucy5CZWFuSW5mbzsKaW1wb3J0IGphdmEuYmVhbnMuSW50cm9zcGVjdGlv bkV4Y2VwdGlv
bjsKaW1wb3J0IGphdmEuYmVhbnMuSW50cm9zcGVjdG9yOwppbXBvcnQgamF2 YS5iZWFucy5Q
cm9wZXJ0eURlc2NyaXB0b3I7CmltcG9ydCBqYXZhLnRleHQuTnVtYmVyRm9y bWF0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CWlmICghZGlzcGxheS5y ZWFkQW5kRGlz
cGF0Y2goKSkgewoJCQkJCWRpc3BsYXkuc2xlZXAoKTsKCQkJCX0KCQkJfQoK CQkJZGlzcGxh
eS5kaXNwb3NlKCk7CgkJfSBjYXRjaCAoRXhjZXB0aW9uIGUpIHsKCQkJZS5w cmludFN0YWNr
VHJhY2UoKTsKCQl9Cgl9Cgp9
--------------070401020909050409020601--
Re: Row-wise table editing [message #64878 is a reply to message #64830] Fri, 19 June 2009 12:00 Go to previous message
Eclipse UserFriend
Originally posted by: m.kasid.gmail.com

Thanks Tom,

This seems to be helpful in understanding the Column-Row transformation.

Thanks,

Mustufa

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fqg3$brs$1@build.eclipse.org...
> Hi,
>
> There no such support for this but IMHO transforming a Row-Model into
> Column-Model isn't a problem. Using reflection this is done quite easily
> in a generic manner.
>
> I just gave it a try and came up with the snippet attached to this mail
> and available from our snippets collection.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi Tom,
>>
>> I think you got my question that I want a viewer where Columns are the
>> dynamic part. Sorry for the confusion. The previous question was related
>> to
>> this one as i want dynamic columns plus different editor on each row.
>>
>> Your suggestion about transforming Column model to Row model could be
>> explored (it will too complicated though). I was just looking if there is
>> some inbuilt facility already provided by Nebula Grid.
>>
>> Anyways, Thanks a lot for the answers.
>>
>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>> news:h1fjhu$hmj$1@build.eclipse.org...
>>> Hi,
>>>
>>> Sorry I don't get the problem. Whenever the viewer wants to show an
>>> editor he asks the EditingSupport for one.
>>>
>>> Based on the information provided to you (you know the column and you
>>> get the domain-object representing the row) you can switch your editor
>>> for every single cell.
>>>
>>> Are you asking for a viewer where the Columns are the dynamic part
>>> instead of the rows? Then this is not possible but you should be able to
>>> handle this at the model part by transforming your column domain model
>>> into a row model and feeding it into the viewer. But you original
>>> question was about something completely different so I'm not sure I
>>> understood your problem.
>>>
>>> Tom
>>>
>>> Mustufa Kasidwala schrieb:
>>>> Hi Tom,
>>>>
>>>> Thanks for the reply. Yes i did went through the idea you provided in
>>>> this
>>>> article. I can see that you are using Model which is represented in
>>>> Rows,
>>>> although this is the obvious approach of TableViewer/Nebul Grid, my
>>>> requirement extends further to the fact that I need Model represented
>>>> by
>>>> Columns rather than rows. Is that possible using the inbuild JFace
>>>> APIs?
>>>> or
>>>> i will have to do something manually to manage the Model input/output ?
>>>>
>>>> Consider a normal Nebula Grid editor but Rows will take place of
>>>> Columns
>>>> and
>>>> vice-versa.
>>>>
>>>> Thanks
>>>> Mustufa
>>>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>>>> news:h1fi0u$sh9$1@build.eclipse.org...
>>>>> Hi,
>>>>>
>>>>> Yes this is supported using JFace 3.3 API named EditingSupport where
>>>>> you
>>>>> are asked every time for an editor before displaying it.
>>>>>
>>>>> You can simply use the code from
>>>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>>>> This is a general rule everything available from JFace upstream is
>>>>> available in the Nebula-Grid-Viewer (with small exception when it
>>>>> comes
>>>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>>>
>>>>> Tom
>>>>>
>>>>> Mustufa Kasidwala schrieb:
>>>>>> Hi,
>>>>>>
>>>>>> Is there a support to have different editors on different rows of
>>>>>> Nebula
>>>>>> grid? Currently, we can have editors (text, combo etc.) on columns
>>>>>> and
>>>>>> this
>>>>>> would mean it will display the same editor for that column in all the
>>>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>>>> possible with Nebula Grid?
>>>>>>
>>>>>> Thanks
>>>>>> Mustufa
>>>>>>
>>>>>>
>>>>
>>
>>
>
>


------------------------------------------------------------ --------------------


> /*********************************************************** ********************
> * Copyright (c) 2009 Tom Schindl and others.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * Tom Schindl - initial API and implementation
> ************************************************************ *******************/
> package org.eclipse.swt.nebula.snippets.grid.viewer;
>
> import java.beans.BeanInfo;
> import java.beans.IntrospectionException;
> import java.beans.Introspector;
> import java.beans.PropertyDescriptor;
> import java.text.NumberFormat;
> import java.text.ParseException;
> import java.text.SimpleDateFormat;
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.List;
> import org.eclipse.jface.resource.ImageDescriptor;
> import org.eclipse.jface.resource.ImageRegistry;
> import org.eclipse.jface.viewers.CellEditor;
> import org.eclipse.jface.viewers.ColumnLabelProvider;
> import org.eclipse.jface.viewers.ColumnViewer;
> import org.eclipse.jface.viewers.EditingSupport;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.TextCellEditor;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.VerifyEvent;
> import org.eclipse.swt.events.VerifyListener;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> /**
> * Creating a viewer where columns are dynamic
> *
> * @author Tom Schindl <tom.schindl@bestsolution.at>
> */
> public class GridViewerSnippet7 {
> private static class Committer {
> private String name;
> private Date birthday;
> private int commits;
> private int bugs;
>
> public Committer(String name, Date birthday, int commits, int bugs) {
> this.name = name;
> this.birthday = birthday;
> this.commits = commits;
> this.bugs = bugs;
> }
>
> public String getName() {
> return name;
> }
>
> @SuppressWarnings("unused")
> public void setName(String name) {
> this.name = name;
> }
>
> @SuppressWarnings("unused")
> public int getCommits() {
> return commits;
> }
>
> @SuppressWarnings("unused")
> public void setCommits(int commits) {
> this.commits = commits;
> }
>
> @SuppressWarnings("unused")
> public int getBugs() {
> return bugs;
> }
>
> @SuppressWarnings("unused")
> public void setBugs(int bugs) {
> this.bugs = bugs;
> }
>
> @SuppressWarnings("unused")
> public Date getBirthday() {
> return birthday;
> }
>
> @SuppressWarnings("unused")
> public void setBirthday(Date birthday) {
> this.birthday = birthday;
> }
> }
>
> private static interface IMediator {
> public Object getValue(int index);
>
> public void setValue(int index, Object value);
>
> public Class<?> getType(int index);
>
> public String getPropertyName();
> }
>
> private static class Mediator implements IMediator {
> private List<Object> domainObjects;
> private String propertyName;
> private PropertyDescriptor descriptor;
>
> public Mediator(List<?> domainObjects, String propertyName) {
> this.domainObjects = new ArrayList<Object>(domainObjects);
> this.propertyName = propertyName;
>
> BeanInfo beanInfo;
> try {
> beanInfo = Introspector.getBeanInfo(domainObjects.get(0)
> .getClass());
> PropertyDescriptor[] propertyDescriptors = beanInfo
> .getPropertyDescriptors();
>
> for (int i = 0; i < propertyDescriptors.length; i++) {
> PropertyDescriptor descriptor = propertyDescriptors[i];
> if (descriptor.getName().equals(propertyName)) {
> this.descriptor = descriptor;
> break;
> }
> }
> } catch (IntrospectionException e) {
> e.printStackTrace();
> }
> }
>
> public Object getValue(int index) {
> try {
> if (domainObjects.size() > index) {
> return descriptor.getReadMethod().invoke(
> domainObjects.get(index), new Object[0]);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> return null;
> }
>
> public void setValue(int index, Object value) {
> try {
> if (domainObjects.size() > index) {
> descriptor.getWriteMethod().invoke(
> domainObjects.get(index), value);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public Class<?> getType(int index) {
> return descriptor.getPropertyType();
> }
>
> public String getPropertyName() {
> return propertyName;
> }
> }
>
> private static class LabelProviderImpl extends ColumnLabelProvider {
> private int colIndex;
>
> public LabelProviderImpl(int colIndex) {
> this.colIndex = colIndex;
> }
>
> @Override
> public String getText(Object element) {
> IMediator m = (IMediator) element;
> if (m.getType(colIndex) == int.class) {
> return NumberFormat.getIntegerInstance().format(
> m.getValue(colIndex));
> } else if (m.getType(colIndex) == Date.class) {
> return new SimpleDateFormat("yyyy-MM-dd").format(
> m.getValue(colIndex));
> }
> return super.getText(element);
> }
>
> }
>
> private static class ContentProvider implements IStructuredContentProvider
> {
> private String[] attributes;
> private List<IMediator> mediators = new ArrayList<IMediator>();
>
> public ContentProvider(String... attributes) {
> this.attributes = attributes;
> }
>
> public Object[] getElements(Object inputElement) {
> return mediators.toArray();
> }
>
> public void dispose() {
>
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
> {
> mediators = new ArrayList<IMediator>();
>
> if (newInput != null && newInput instanceof List<?>) {
> for (String attribute : attributes) {
> mediators.add(new Mediator((List<?>) newInput, attribute));
> }
> }
> }
> }
>
> private static class EditingSupportImpl extends EditingSupport {
>
> private int colIndex;
>
> private TextCellEditor integerEditor;
> private TextCellEditor dateEditor;
>
> public EditingSupportImpl(ColumnViewer viewer, int colIndex) {
> super(viewer);
> this.colIndex = colIndex;
> this.integerEditor = new TextCellEditor((Composite) viewer
> .getControl(), SWT.NONE);
> ((Text) this.integerEditor.getControl())
> .addVerifyListener(new VerifyListener() {
>
> public void verifyText(VerifyEvent e) {
> String string = e.text;
> char[] chars = new char[string.length()];
> string.getChars(0, chars.length, chars, 0);
> for (int i = 0; i < chars.length; i++) {
> if (!('0' <= chars[i] && chars[i] <= '9')) {
> e.doit = false;
> return;
> }
> }
> }
> });
> this.dateEditor = new TextCellEditor((Composite) viewer
> .getControl(), SWT.NONE);
> ((Text) this.dateEditor.getControl())
> .addVerifyListener(new VerifyListener() {
>
> public void verifyText(VerifyEvent e) {
> String string = e.text;
> char[] chars = new char[string.length()];
> string.getChars(0, chars.length, chars, 0);
> for (int i = 0; i < chars.length; i++) {
> if (!( ('0' <= chars[i] && chars[i] <= '9') || chars[i] == '-' ) ) {
> e.doit = false;
> return;
> }
> }
> }
> });
> }
>
> @Override
> protected boolean canEdit(Object element) {
> return true;
> }
>
> @Override
> protected CellEditor getCellEditor(Object element) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> return integerEditor;
> } else if (m.getType(colIndex) == Date.class) {
> return dateEditor;
> }
>
> return null;
> }
>
> @Override
> protected Object getValue(Object element) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> return m.getValue(colIndex) + "";
> } else if (m.getType(colIndex) == Date.class) {
> return new SimpleDateFormat("yyyy-MM-dd").format(m
> .getValue(colIndex));
> }
>
> return null;
> }
>
> @Override
> protected void setValue(Object element, Object value) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> try {
> m.setValue(colIndex, Integer.parseInt(value.toString()));
> } catch (NumberFormatException e) {
> e.printStackTrace();
> }
>
> } else if (m.getType(colIndex) == Date.class) {
> try {
> m.setValue(colIndex, new SimpleDateFormat("yyyy-MM-dd")
> .parse(value.toString()));
> } catch (ParseException e) {
> e.printStackTrace();
> }
> }
>
> getViewer().update(element, null);
> }
> }
>
> public static void main(String[] args) {
> try {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
>
> final ImageRegistry reg = new ImageRegistry(display);
> reg.put("ICON", ImageDescriptor.createFromFile(
> GridViewerSnippet6.class, "th_vertical.gif"));
>
> GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION
> | SWT.H_SCROLL | SWT.V_SCROLL);
> v.getGrid().setLinesVisible(true);
> v.getGrid().setHeaderVisible(true);
> v.setContentProvider(new ContentProvider("birthday", "commits",
> "bugs"));
> v.getGrid().setRowHeaderVisible(true);
> v.setRowHeaderLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> String propertyName = ((Mediator) element)
> .getPropertyName();
> return propertyName;
> }
>
> });
>
> List<Committer> committers = new ArrayList<Committer>();
> committers.add(new Committer("Tom Schindl", new Date(), 10, 5));
> committers
> .add(new Committer("Boris Bokowski", new Date(), 1000, 35));
>
> int i = 0;
> for (Committer committer : committers) {
> GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
> column.setEditingSupport(new EditingSupportImpl(v, i));
> column.setLabelProvider(new LabelProviderImpl(i));
> column.getColumn().setText(committer.getName());
> column.getColumn().setWidth(200);
> i++;
> }
>
> v.setInput(committers);
>
> shell.setSize(500, 200);
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
>
> display.dispose();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
Re: Row-wise table editing [message #595230 is a reply to message #64712] Fri, 19 June 2009 08:25 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Yes this is supported using JFace 3.3 API named EditingSupport where you
are asked every time for an editor before displaying it.

You can simply use the code from
http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
This is a general rule everything available from JFace upstream is
available in the Nebula-Grid-Viewer (with small exception when it comes
to Grid-TreeViewer) else it is a bug and needs fixing.

Tom

Mustufa Kasidwala schrieb:
> Hi,
>
> Is there a support to have different editors on different rows of Nebula
> grid? Currently, we can have editors (text, combo etc.) on columns and this
> would mean it will display the same editor for that column in all the
> rows...My requirement is something kind of a Transposed table. Is it
> possible with Nebula Grid?
>
> Thanks
> Mustufa
>
>
Re: Row-wise table editing [message #595242 is a reply to message #64736] Fri, 19 June 2009 08:36 Go to previous message
Mustufa Kasidwala is currently offline Mustufa KasidwalaFriend
Messages: 60
Registered: July 2009
Member
Hi Tom,

Thanks for the reply. Yes i did went through the idea you provided in this
article. I can see that you are using Model which is represented in Rows,
although this is the obvious approach of TableViewer/Nebul Grid, my
requirement extends further to the fact that I need Model represented by
Columns rather than rows. Is that possible using the inbuild JFace APIs? or
i will have to do something manually to manage the Model input/output ?

Consider a normal Nebula Grid editor but Rows will take place of Columns and
vice-versa.

Thanks
Mustufa
"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fi0u$sh9$1@build.eclipse.org...
> Hi,
>
> Yes this is supported using JFace 3.3 API named EditingSupport where you
> are asked every time for an editor before displaying it.
>
> You can simply use the code from
> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
> This is a general rule everything available from JFace upstream is
> available in the Nebula-Grid-Viewer (with small exception when it comes
> to Grid-TreeViewer) else it is a bug and needs fixing.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi,
>>
>> Is there a support to have different editors on different rows of Nebula
>> grid? Currently, we can have editors (text, combo etc.) on columns and
>> this
>> would mean it will display the same editor for that column in all the
>> rows...My requirement is something kind of a Transposed table. Is it
>> possible with Nebula Grid?
>>
>> Thanks
>> Mustufa
>>
>>
Re: Row-wise table editing [message #595248 is a reply to message #64758] Fri, 19 June 2009 08:51 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Sorry I don't get the problem. Whenever the viewer wants to show an
editor he asks the EditingSupport for one.

Based on the information provided to you (you know the column and you
get the domain-object representing the row) you can switch your editor
for every single cell.

Are you asking for a viewer where the Columns are the dynamic part
instead of the rows? Then this is not possible but you should be able to
handle this at the model part by transforming your column domain model
into a row model and feeding it into the viewer. But you original
question was about something completely different so I'm not sure I
understood your problem.

Tom

Mustufa Kasidwala schrieb:
> Hi Tom,
>
> Thanks for the reply. Yes i did went through the idea you provided in this
> article. I can see that you are using Model which is represented in Rows,
> although this is the obvious approach of TableViewer/Nebul Grid, my
> requirement extends further to the fact that I need Model represented by
> Columns rather than rows. Is that possible using the inbuild JFace APIs? or
> i will have to do something manually to manage the Model input/output ?
>
> Consider a normal Nebula Grid editor but Rows will take place of Columns and
> vice-versa.
>
> Thanks
> Mustufa
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:h1fi0u$sh9$1@build.eclipse.org...
>> Hi,
>>
>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>> are asked every time for an editor before displaying it.
>>
>> You can simply use the code from
>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>> This is a general rule everything available from JFace upstream is
>> available in the Nebula-Grid-Viewer (with small exception when it comes
>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>
>> Tom
>>
>> Mustufa Kasidwala schrieb:
>>> Hi,
>>>
>>> Is there a support to have different editors on different rows of Nebula
>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>> this
>>> would mean it will display the same editor for that column in all the
>>> rows...My requirement is something kind of a Transposed table. Is it
>>> possible with Nebula Grid?
>>>
>>> Thanks
>>> Mustufa
>>>
>>>
>
>
Re: Row-wise table editing [message #595265 is a reply to message #64781] Fri, 19 June 2009 09:03 Go to previous message
Mustufa Kasidwala is currently offline Mustufa KasidwalaFriend
Messages: 60
Registered: July 2009
Member
Hi Tom,

I think you got my question that I want a viewer where Columns are the
dynamic part. Sorry for the confusion. The previous question was related to
this one as i want dynamic columns plus different editor on each row.

Your suggestion about transforming Column model to Row model could be
explored (it will too complicated though). I was just looking if there is
some inbuilt facility already provided by Nebula Grid.

Anyways, Thanks a lot for the answers.

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fjhu$hmj$1@build.eclipse.org...
> Hi,
>
> Sorry I don't get the problem. Whenever the viewer wants to show an
> editor he asks the EditingSupport for one.
>
> Based on the information provided to you (you know the column and you
> get the domain-object representing the row) you can switch your editor
> for every single cell.
>
> Are you asking for a viewer where the Columns are the dynamic part
> instead of the rows? Then this is not possible but you should be able to
> handle this at the model part by transforming your column domain model
> into a row model and feeding it into the viewer. But you original
> question was about something completely different so I'm not sure I
> understood your problem.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi Tom,
>>
>> Thanks for the reply. Yes i did went through the idea you provided in
>> this
>> article. I can see that you are using Model which is represented in Rows,
>> although this is the obvious approach of TableViewer/Nebul Grid, my
>> requirement extends further to the fact that I need Model represented by
>> Columns rather than rows. Is that possible using the inbuild JFace APIs?
>> or
>> i will have to do something manually to manage the Model input/output ?
>>
>> Consider a normal Nebula Grid editor but Rows will take place of Columns
>> and
>> vice-versa.
>>
>> Thanks
>> Mustufa
>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>> news:h1fi0u$sh9$1@build.eclipse.org...
>>> Hi,
>>>
>>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>>> are asked every time for an editor before displaying it.
>>>
>>> You can simply use the code from
>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>> This is a general rule everything available from JFace upstream is
>>> available in the Nebula-Grid-Viewer (with small exception when it comes
>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>
>>> Tom
>>>
>>> Mustufa Kasidwala schrieb:
>>>> Hi,
>>>>
>>>> Is there a support to have different editors on different rows of
>>>> Nebula
>>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>>> this
>>>> would mean it will display the same editor for that column in all the
>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>> possible with Nebula Grid?
>>>>
>>>> Thanks
>>>> Mustufa
>>>>
>>>>
>>
>>
Re: Row-wise table editing [message #595274 is a reply to message #64804] Fri, 19 June 2009 10:49 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070401020909050409020601
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi,

There no such support for this but IMHO transforming a Row-Model into
Column-Model isn't a problem. Using reflection this is done quite easily
in a generic manner.

I just gave it a try and came up with the snippet attached to this mail
and available from our snippets collection.

Tom

Mustufa Kasidwala schrieb:
> Hi Tom,
>
> I think you got my question that I want a viewer where Columns are the
> dynamic part. Sorry for the confusion. The previous question was related to
> this one as i want dynamic columns plus different editor on each row.
>
> Your suggestion about transforming Column model to Row model could be
> explored (it will too complicated though). I was just looking if there is
> some inbuilt facility already provided by Nebula Grid.
>
> Anyways, Thanks a lot for the answers.
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:h1fjhu$hmj$1@build.eclipse.org...
>> Hi,
>>
>> Sorry I don't get the problem. Whenever the viewer wants to show an
>> editor he asks the EditingSupport for one.
>>
>> Based on the information provided to you (you know the column and you
>> get the domain-object representing the row) you can switch your editor
>> for every single cell.
>>
>> Are you asking for a viewer where the Columns are the dynamic part
>> instead of the rows? Then this is not possible but you should be able to
>> handle this at the model part by transforming your column domain model
>> into a row model and feeding it into the viewer. But you original
>> question was about something completely different so I'm not sure I
>> understood your problem.
>>
>> Tom
>>
>> Mustufa Kasidwala schrieb:
>>> Hi Tom,
>>>
>>> Thanks for the reply. Yes i did went through the idea you provided in
>>> this
>>> article. I can see that you are using Model which is represented in Rows,
>>> although this is the obvious approach of TableViewer/Nebul Grid, my
>>> requirement extends further to the fact that I need Model represented by
>>> Columns rather than rows. Is that possible using the inbuild JFace APIs?
>>> or
>>> i will have to do something manually to manage the Model input/output ?
>>>
>>> Consider a normal Nebula Grid editor but Rows will take place of Columns
>>> and
>>> vice-versa.
>>>
>>> Thanks
>>> Mustufa
>>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>>> news:h1fi0u$sh9$1@build.eclipse.org...
>>>> Hi,
>>>>
>>>> Yes this is supported using JFace 3.3 API named EditingSupport where you
>>>> are asked every time for an editor before displaying it.
>>>>
>>>> You can simply use the code from
>>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>>> This is a general rule everything available from JFace upstream is
>>>> available in the Nebula-Grid-Viewer (with small exception when it comes
>>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>>
>>>> Tom
>>>>
>>>> Mustufa Kasidwala schrieb:
>>>>> Hi,
>>>>>
>>>>> Is there a support to have different editors on different rows of
>>>>> Nebula
>>>>> grid? Currently, we can have editors (text, combo etc.) on columns and
>>>>> this
>>>>> would mean it will display the same editor for that column in all the
>>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>>> possible with Nebula Grid?
>>>>>
>>>>> Thanks
>>>>> Mustufa
>>>>>
>>>>>
>>>
>
>


--------------070401020909050409020601
Content-Type: text/plain;
name="GridViewerSnippet7.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="GridViewerSnippet7.java"

LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioKICogQ29weXJpZ2h0IChjKSAy MDA5IFRvbSBT
Y2hpbmRsIGFuZCBvdGhlcnMuCiAqIEFsbCByaWdodHMgcmVzZXJ2ZWQuIFRo aXMgcHJvZ3Jh
bSBhbmQgdGhlIGFjY29tcGFueWluZyBtYXRlcmlhbHMKICogYXJlIG1hZGUg YXZhaWxhYmxl
IHVuZGVyIHRoZSB0ZXJtcyBvZiB0aGUgRWNsaXBzZSBQdWJsaWMgTGljZW5z ZSB2MS4wCiAq
IHdoaWNoIGFjY29tcGFuaWVzIHRoaXMgZGlzdHJpYnV0aW9uLCBhbmQgaXMg YXZhaWxhYmxl
IGF0CiAqIGh0dHA6Ly93d3cuZWNsaXBzZS5vcmcvbGVnYWwvZXBsLXYxMC5o dG1sCiAqCiAq
IENvbnRyaWJ1dG9yczoKICogICAgIFRvbSBTY2hpbmRsIC0gaW5pdGlhbCBB UEkgYW5kIGlt
cGxlbWVudGF0aW9uCiAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwpwYWNr YWdlIG9yZy5l
Y2xpcHNlLnN3dC5uZWJ1bGEuc25pcHBldHMuZ3JpZC52aWV3ZXI7CgppbXBv cnQgamF2YS5i
ZWFucy5CZWFuSW5mbzsKaW1wb3J0IGphdmEuYmVhbnMuSW50cm9zcGVjdGlv bkV4Y2VwdGlv
bjsKaW1wb3J0IGphdmEuYmVhbnMuSW50cm9zcGVjdG9yOwppbXBvcnQgamF2 YS5iZWFucy5Q
cm9wZXJ0eURlc2NyaXB0b3I7CmltcG9ydCBqYXZhLnRleHQuTnVtYmVyRm9y bWF0OwppbXBv
cnQgamF2YS50ZXh0LlBhcnNlRXhjZ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y2goKSkgewoJCQkJCWRpc3BsYXkuc2xlZXAoKTsKCQkJCX0KCQkJfQoK CQkJZGlzcGxh
eS5kaXNwb3NlKCk7CgkJfSBjYXRjaCAoRXhjZXB0aW9uIGUpIHsKCQkJZS5w cmludFN0YWNr
VHJhY2UoKTsKCQl9Cgl9Cgp9
--------------070401020909050409020601--
Re: Row-wise table editing [message #595307 is a reply to message #64830] Fri, 19 June 2009 12:00 Go to previous message
Mustufa Kasidwala is currently offline Mustufa KasidwalaFriend
Messages: 60
Registered: July 2009
Member
Thanks Tom,

This seems to be helpful in understanding the Column-Row transformation.

Thanks,

Mustufa

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:h1fqg3$brs$1@build.eclipse.org...
> Hi,
>
> There no such support for this but IMHO transforming a Row-Model into
> Column-Model isn't a problem. Using reflection this is done quite easily
> in a generic manner.
>
> I just gave it a try and came up with the snippet attached to this mail
> and available from our snippets collection.
>
> Tom
>
> Mustufa Kasidwala schrieb:
>> Hi Tom,
>>
>> I think you got my question that I want a viewer where Columns are the
>> dynamic part. Sorry for the confusion. The previous question was related
>> to
>> this one as i want dynamic columns plus different editor on each row.
>>
>> Your suggestion about transforming Column model to Row model could be
>> explored (it will too complicated though). I was just looking if there is
>> some inbuilt facility already provided by Nebula Grid.
>>
>> Anyways, Thanks a lot for the answers.
>>
>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>> news:h1fjhu$hmj$1@build.eclipse.org...
>>> Hi,
>>>
>>> Sorry I don't get the problem. Whenever the viewer wants to show an
>>> editor he asks the EditingSupport for one.
>>>
>>> Based on the information provided to you (you know the column and you
>>> get the domain-object representing the row) you can switch your editor
>>> for every single cell.
>>>
>>> Are you asking for a viewer where the Columns are the dynamic part
>>> instead of the rows? Then this is not possible but you should be able to
>>> handle this at the model part by transforming your column domain model
>>> into a row model and feeding it into the viewer. But you original
>>> question was about something completely different so I'm not sure I
>>> understood your problem.
>>>
>>> Tom
>>>
>>> Mustufa Kasidwala schrieb:
>>>> Hi Tom,
>>>>
>>>> Thanks for the reply. Yes i did went through the idea you provided in
>>>> this
>>>> article. I can see that you are using Model which is represented in
>>>> Rows,
>>>> although this is the obvious approach of TableViewer/Nebul Grid, my
>>>> requirement extends further to the fact that I need Model represented
>>>> by
>>>> Columns rather than rows. Is that possible using the inbuild JFace
>>>> APIs?
>>>> or
>>>> i will have to do something manually to manage the Model input/output ?
>>>>
>>>> Consider a normal Nebula Grid editor but Rows will take place of
>>>> Columns
>>>> and
>>>> vice-versa.
>>>>
>>>> Thanks
>>>> Mustufa
>>>> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
>>>> news:h1fi0u$sh9$1@build.eclipse.org...
>>>>> Hi,
>>>>>
>>>>> Yes this is supported using JFace 3.3 API named EditingSupport where
>>>>> you
>>>>> are asked every time for an editor before displaying it.
>>>>>
>>>>> You can simply use the code from
>>>>> http://wiki.eclipse.org/JFaceSnippets#Snippet034CellEditorPe rRowNewAPI
>>>>> This is a general rule everything available from JFace upstream is
>>>>> available in the Nebula-Grid-Viewer (with small exception when it
>>>>> comes
>>>>> to Grid-TreeViewer) else it is a bug and needs fixing.
>>>>>
>>>>> Tom
>>>>>
>>>>> Mustufa Kasidwala schrieb:
>>>>>> Hi,
>>>>>>
>>>>>> Is there a support to have different editors on different rows of
>>>>>> Nebula
>>>>>> grid? Currently, we can have editors (text, combo etc.) on columns
>>>>>> and
>>>>>> this
>>>>>> would mean it will display the same editor for that column in all the
>>>>>> rows...My requirement is something kind of a Transposed table. Is it
>>>>>> possible with Nebula Grid?
>>>>>>
>>>>>> Thanks
>>>>>> Mustufa
>>>>>>
>>>>>>
>>>>
>>
>>
>
>


------------------------------------------------------------ --------------------


> /*********************************************************** ********************
> * Copyright (c) 2009 Tom Schindl and others.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * Tom Schindl - initial API and implementation
> ************************************************************ *******************/
> package org.eclipse.swt.nebula.snippets.grid.viewer;
>
> import java.beans.BeanInfo;
> import java.beans.IntrospectionException;
> import java.beans.Introspector;
> import java.beans.PropertyDescriptor;
> import java.text.NumberFormat;
> import java.text.ParseException;
> import java.text.SimpleDateFormat;
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.List;
> import org.eclipse.jface.resource.ImageDescriptor;
> import org.eclipse.jface.resource.ImageRegistry;
> import org.eclipse.jface.viewers.CellEditor;
> import org.eclipse.jface.viewers.ColumnLabelProvider;
> import org.eclipse.jface.viewers.ColumnViewer;
> import org.eclipse.jface.viewers.EditingSupport;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.TextCellEditor;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.VerifyEvent;
> import org.eclipse.swt.events.VerifyListener;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> /**
> * Creating a viewer where columns are dynamic
> *
> * @author Tom Schindl <tom.schindl@bestsolution.at>
> */
> public class GridViewerSnippet7 {
> private static class Committer {
> private String name;
> private Date birthday;
> private int commits;
> private int bugs;
>
> public Committer(String name, Date birthday, int commits, int bugs) {
> this.name = name;
> this.birthday = birthday;
> this.commits = commits;
> this.bugs = bugs;
> }
>
> public String getName() {
> return name;
> }
>
> @SuppressWarnings("unused")
> public void setName(String name) {
> this.name = name;
> }
>
> @SuppressWarnings("unused")
> public int getCommits() {
> return commits;
> }
>
> @SuppressWarnings("unused")
> public void setCommits(int commits) {
> this.commits = commits;
> }
>
> @SuppressWarnings("unused")
> public int getBugs() {
> return bugs;
> }
>
> @SuppressWarnings("unused")
> public void setBugs(int bugs) {
> this.bugs = bugs;
> }
>
> @SuppressWarnings("unused")
> public Date getBirthday() {
> return birthday;
> }
>
> @SuppressWarnings("unused")
> public void setBirthday(Date birthday) {
> this.birthday = birthday;
> }
> }
>
> private static interface IMediator {
> public Object getValue(int index);
>
> public void setValue(int index, Object value);
>
> public Class<?> getType(int index);
>
> public String getPropertyName();
> }
>
> private static class Mediator implements IMediator {
> private List<Object> domainObjects;
> private String propertyName;
> private PropertyDescriptor descriptor;
>
> public Mediator(List<?> domainObjects, String propertyName) {
> this.domainObjects = new ArrayList<Object>(domainObjects);
> this.propertyName = propertyName;
>
> BeanInfo beanInfo;
> try {
> beanInfo = Introspector.getBeanInfo(domainObjects.get(0)
> .getClass());
> PropertyDescriptor[] propertyDescriptors = beanInfo
> .getPropertyDescriptors();
>
> for (int i = 0; i < propertyDescriptors.length; i++) {
> PropertyDescriptor descriptor = propertyDescriptors[i];
> if (descriptor.getName().equals(propertyName)) {
> this.descriptor = descriptor;
> break;
> }
> }
> } catch (IntrospectionException e) {
> e.printStackTrace();
> }
> }
>
> public Object getValue(int index) {
> try {
> if (domainObjects.size() > index) {
> return descriptor.getReadMethod().invoke(
> domainObjects.get(index), new Object[0]);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> return null;
> }
>
> public void setValue(int index, Object value) {
> try {
> if (domainObjects.size() > index) {
> descriptor.getWriteMethod().invoke(
> domainObjects.get(index), value);
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public Class<?> getType(int index) {
> return descriptor.getPropertyType();
> }
>
> public String getPropertyName() {
> return propertyName;
> }
> }
>
> private static class LabelProviderImpl extends ColumnLabelProvider {
> private int colIndex;
>
> public LabelProviderImpl(int colIndex) {
> this.colIndex = colIndex;
> }
>
> @Override
> public String getText(Object element) {
> IMediator m = (IMediator) element;
> if (m.getType(colIndex) == int.class) {
> return NumberFormat.getIntegerInstance().format(
> m.getValue(colIndex));
> } else if (m.getType(colIndex) == Date.class) {
> return new SimpleDateFormat("yyyy-MM-dd").format(
> m.getValue(colIndex));
> }
> return super.getText(element);
> }
>
> }
>
> private static class ContentProvider implements IStructuredContentProvider
> {
> private String[] attributes;
> private List<IMediator> mediators = new ArrayList<IMediator>();
>
> public ContentProvider(String... attributes) {
> this.attributes = attributes;
> }
>
> public Object[] getElements(Object inputElement) {
> return mediators.toArray();
> }
>
> public void dispose() {
>
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
> {
> mediators = new ArrayList<IMediator>();
>
> if (newInput != null && newInput instanceof List<?>) {
> for (String attribute : attributes) {
> mediators.add(new Mediator((List<?>) newInput, attribute));
> }
> }
> }
> }
>
> private static class EditingSupportImpl extends EditingSupport {
>
> private int colIndex;
>
> private TextCellEditor integerEditor;
> private TextCellEditor dateEditor;
>
> public EditingSupportImpl(ColumnViewer viewer, int colIndex) {
> super(viewer);
> this.colIndex = colIndex;
> this.integerEditor = new TextCellEditor((Composite) viewer
> .getControl(), SWT.NONE);
> ((Text) this.integerEditor.getControl())
> .addVerifyListener(new VerifyListener() {
>
> public void verifyText(VerifyEvent e) {
> String string = e.text;
> char[] chars = new char[string.length()];
> string.getChars(0, chars.length, chars, 0);
> for (int i = 0; i < chars.length; i++) {
> if (!('0' <= chars[i] && chars[i] <= '9')) {
> e.doit = false;
> return;
> }
> }
> }
> });
> this.dateEditor = new TextCellEditor((Composite) viewer
> .getControl(), SWT.NONE);
> ((Text) this.dateEditor.getControl())
> .addVerifyListener(new VerifyListener() {
>
> public void verifyText(VerifyEvent e) {
> String string = e.text;
> char[] chars = new char[string.length()];
> string.getChars(0, chars.length, chars, 0);
> for (int i = 0; i < chars.length; i++) {
> if (!( ('0' <= chars[i] && chars[i] <= '9') || chars[i] == '-' ) ) {
> e.doit = false;
> return;
> }
> }
> }
> });
> }
>
> @Override
> protected boolean canEdit(Object element) {
> return true;
> }
>
> @Override
> protected CellEditor getCellEditor(Object element) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> return integerEditor;
> } else if (m.getType(colIndex) == Date.class) {
> return dateEditor;
> }
>
> return null;
> }
>
> @Override
> protected Object getValue(Object element) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> return m.getValue(colIndex) + "";
> } else if (m.getType(colIndex) == Date.class) {
> return new SimpleDateFormat("yyyy-MM-dd").format(m
> .getValue(colIndex));
> }
>
> return null;
> }
>
> @Override
> protected void setValue(Object element, Object value) {
> IMediator m = (IMediator) element;
>
> if (m.getType(colIndex) == int.class) {
> try {
> m.setValue(colIndex, Integer.parseInt(value.toString()));
> } catch (NumberFormatException e) {
> e.printStackTrace();
> }
>
> } else if (m.getType(colIndex) == Date.class) {
> try {
> m.setValue(colIndex, new SimpleDateFormat("yyyy-MM-dd")
> .parse(value.toString()));
> } catch (ParseException e) {
> e.printStackTrace();
> }
> }
>
> getViewer().update(element, null);
> }
> }
>
> public static void main(String[] args) {
> try {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
>
> final ImageRegistry reg = new ImageRegistry(display);
> reg.put("ICON", ImageDescriptor.createFromFile(
> GridViewerSnippet6.class, "th_vertical.gif"));
>
> GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION
> | SWT.H_SCROLL | SWT.V_SCROLL);
> v.getGrid().setLinesVisible(true);
> v.getGrid().setHeaderVisible(true);
> v.setContentProvider(new ContentProvider("birthday", "commits",
> "bugs"));
> v.getGrid().setRowHeaderVisible(true);
> v.setRowHeaderLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> String propertyName = ((Mediator) element)
> .getPropertyName();
> return propertyName;
> }
>
> });
>
> List<Committer> committers = new ArrayList<Committer>();
> committers.add(new Committer("Tom Schindl", new Date(), 10, 5));
> committers
> .add(new Committer("Boris Bokowski", new Date(), 1000, 35));
>
> int i = 0;
> for (Committer committer : committers) {
> GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
> column.setEditingSupport(new EditingSupportImpl(v, i));
> column.setLabelProvider(new LabelProviderImpl(i));
> column.getColumn().setText(committer.getName());
> column.getColumn().setWidth(200);
> i++;
> }
>
> v.setInput(committers);
>
> shell.setSize(500, 200);
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
>
> display.dispose();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
Previous Topic:Gantt: remove Connections
Next Topic:help about gallery
Goto Forum:
  


Current Time: Fri Mar 29 09:49:34 GMT 2024

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

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

Back to the top