Home » Eclipse Projects » NatTable » Simple Cell Editing
Simple Cell Editing [message #1053708] |
Tue, 07 May 2013 10:43  |
Aljoscha Steffens Messages: 302 Registered: November 2012 |
Senior Member |
|
|
Hi,
I'm tinker with this problem since a couple of hours and even if it's so basic, I can't get it working.
So all I need is a simple Text(Cell)Editor for selected cells and maybe a check an input check (so that only numbers can be put in).
This is the code:
dataProvider = new DataProvider();
final ViewportLayer layer = new ViewportLayer( new DataLayer(dataProvider) );
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
configLabels.addLabel("myCellLabel");
}
};
layer.setConfigLabelAccumulator(cellLabelAccumulator);
natTable = new NatTable(container, layer, false);
natTable.addConfiguration(new AbstractRegistryConfiguration() {
public void configureRegistry(IConfigRegistry configRegistry) {
TextCellEditor textCellEditor = new TextCellEditor();
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, textCellEditor, DisplayMode.EDIT, "myCellLabel");
//configRegistry.registerConfigAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "myCellLabel");
}
});
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.configure();
Neither of the "configRegistry.registerConfigAttribute(..)" functions work. What did I do wrong?
|
|
|
Re: Simple Cell Editing [message #1053717 is a reply to message #1053708] |
Tue, 07 May 2013 11:28   |
Eclipse User |
|
|
|
The label mechanism is the way to configure things for special cases. What you want to do is to configure that all cells are always editable.
a) you need to enable editing by editing rule. you commented it so there is nothing editable
b) as you are not using the GridLayer, the configuration of the handlers and bindings are missing. You need the configurations as expressed in DefaultEditConfiguration and DefaultEditBindings.
c) you don't need the labels in your case so you can get rid of the IConfigLabelAccumulator
|
|
|
Re: Simple Cell Editing [message #1053718 is a reply to message #1053717] |
Tue, 07 May 2013 11:29   |
Eclipse User |
|
|
|
Oh, you could of course simply add the DefaultEditBindings as configuration to your NatTable, but then you will need to set the region label of the viewport to GridRegion.BODY
|
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Re: Simple Cell Editing [message #1057760 is a reply to message #1054091] |
Wed, 08 May 2013 15:25   |
Eclipse User |
|
|
|
Hm, have you tried to add the configurations to the ViewportLayer instead of adding it to the NatTable instance?
I think there is also a post regarding the same topic in this forum. Maybe that helps too?
|
|
|
Re: Simple Cell Editing [message #1057801 is a reply to message #1057760] |
Wed, 08 May 2013 20:46   |
Aljoscha Steffens Messages: 302 Registered: November 2012 |
Senior Member |
|
|
Okay. Another two and a half hours without any glimpse of success.
I tried to understand EditableGridExample and failed when I tried to implement a DefaultGridLayer. (But at least I learned sth about Reflection ).
So.. before I do any more research: Is the GridLayer necessary for editing cells? I can remember that I chose the ViewPortLayer for a certain reason, so I would like to keep it.
I tried to add the configuration to the ViewPortLayer but nothing happens.
Also I tried to find the topic you mentioned, but I couldn't find any other than I found previously.
This is my code now..
final ViewportLayer layer = new ViewportLayer( new DataLayer(dataProvider) );
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
configLabels.addLabel("myCellLabel");
}
};
layer.setConfigLabelAccumulator(cellLabelAccumulator);
layer.setRegionName(GridRegion.BODY);
layer.addConfiguration(new AbstractRegistryConfiguration() {
public void configureRegistry(IConfigRegistry configRegistry) {
TextCellEditor textCellEditor = new TextCellEditor();
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, textCellEditor, DisplayMode.EDIT, "myCellLabel");
configRegistry.registerConfigAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "myCellLabel");
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
}
});
natTable = new NatTable(container, layer, false);
natTable.addConfiguration(new AbstractRegistryConfiguration() {
public void configureRegistry(IConfigRegistry configRegistry) {
TextCellEditor textCellEditor = new TextCellEditor();
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, textCellEditor, DisplayMode.EDIT, "myCellLabel");
configRegistry.registerConfigAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "myCellLabel");
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
}
});
natTable.addConfiguration(new DefaultEditConfiguration());
natTable.addConfiguration(new DefaultEditBindings());
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.configure();
By the way: I think that its really good how many example classes you provide as an "how to do". But for example the "EditableGridExample ": why does it need to be so big? I would much more appreciate a 4by4 table with as few configurations as possible. But on the other hand you do a great job in the forum Thanks
|
|
|
Re: Simple Cell Editing [message #1057803 is a reply to message #1057801] |
Wed, 08 May 2013 21:24   |
Eclipse User |
|
|
|
natTable.addConfiguration(new DefaultEditConfiguration());
as explained before, this should be
layer.addConfiguration(new DefaultEditConfiguration());
That is because DefaultEditConfiguration is an AbstractLayerConfiguration.
Quote:But for example the "EditableGridExample ": why does it need to be so big?
Several answers to that:
a) it is an example from quite early stages
b) it shows that editing is possible for large grids
c) it shows several functionality in one because we don't want to create thousands of examples for every single functionality 
We will rework the examples in some way, but some of them will be also quite large (see point c). But maybe we should think about adding a small example on how to add editing to a non grid NatTable. That might be helpful.
|
|
| | | | |
Goto Forum:
Current Time: Sat Feb 08 01:38:08 GMT 2025
Powered by FUDForum. Page generated in 0.21335 seconds
|