Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Table Developer Documentation"

Line 67: Line 67:
  
 
[[File:ColumnTableHeaderAxisConfiguration.png]]
 
[[File:ColumnTableHeaderAxisConfiguration.png]]
 +
 +
====Add one Feature Label Provider Configuration====
 +
Click with the right mouse button on your new created Table Header Axis Configuration item and create a New Child of type Feature Label Provider Configuration.  Once added, define its properties:
 +
 +
[[File:AxisManagerRepresentation01.png]]
 +
 +
And again, create a second New Child of type Axis Manager Representation.  Once added, define its properties:
 +
 +
[[File:AxisManagerRepresentation02.png]]
 +
 +
===Add one Column Axis Providers Slave Object Axis Provider===
 +
Click with the right mouse button on the Table Configuration item and create a New Child of type Column Axis Providers Slave Object Axis Provider (Fig. 7). Once added, define its properties:
 +
 +
[[File:SlaveObjectAxisProvider.png]]
 +
 +
====Add one EStructural Feature Axis====
 +
Click with the right mouse button on your new created Slave Object Axis Provider item and create a New Child of type EStructural Feature Axis.  Once added, define its properties:
 +
 +
[[File:EStructuralFeatureAxis.png]]
 +
 +
 
=Contribute to menu with a new Papyrus Table (must be completed)=
 
=Contribute to menu with a new Papyrus Table (must be completed)=
 
The contribution must be done using viewpoint with a file .configuration.
 
The contribution must be done using viewpoint with a file .configuration.

Revision as of 08:19, 16 December 2014

WORK IN PROGRESS

The Papyrus Table uses the NatTable widget. Its documentation is available here and here. These new table are available since the Papyrus Release 0.10 in June 2013.

The NatTable source code can be downloaded with git http://git.eclipse.org/gitroot/nattable/org.eclipse.nebula.widgets.nattable.git

Customizing Synchronized Papyrus Tables

The aim of this topic is to provide a tutorial for customizing a table within Papyrus. The Papyrus Table can be synchronized or not. In this tutorial, the customized table will be synchronized with an element type of a SysML model. Specifically, the table will be synchronized with the elements of Block type. It means, any creation, destruction and modification of a block within a model will be automatically updated within the table.

Table Configuration

For this step, first of all, you have to create a new Nattableconfiguration Model, for example, called block.nattableconfiguration. Once a block.nattableconfiguration has been created, you have to open it for setting your customizing table.

BlockNattableconfiguration.png

To set the Block Table you have to follow the following steps:

Add one Java Table Tester

Click with the right mouse button on the Table Configuration item and create a New Child of type Java Table Tester. Once added, define its properties:

JavaTableTester.png

Tester: define the Id that you will use to set the extension org.eclipse.papyrus.infra.nattable.tester.

Add one Row Header Axis Configuration Table Header Axis Configuration

Click with the right mouse button on the Table Configuration item and create a New Child of type Row Header Axis Configuration Table Header Axis Configuration. Once added, define its properties:

RowTableHeaderAxisConfiguration.png

Add one Object Label Provider Configuration

Click with the right mouse button on your new created Table Header Axis Configuration item and create a New Child of type Object Label Provider Configuration. Once added, define its properties:

ObjectLabelProviderConfiguration.png

Add one EStructural Feature Value Filling Configuration

Click with the right mouse button on your new created Table Header Axis Configuration item and create a New Child of type EStructural Feature Value Filling Configuration. But, before setting its properties, you have to load the UML.ecore model. Follow these steps:

1. Open the block.nattableconfiguration file with Sample Reflective Ecore Model Editor;

2. Click with the right mouse button on the editor and choose Load Resource… in the popup menu;

3. Click on the Browse Target Platform Packages…;

4. Select http://www.eclipse.org/uml2/4.0.0/UML.

Still in the Sample Reflective Ecore Model Editor, define the EStructural Feature Value Filling Configuration properties:

EStructuralFeatureValueFillingConfiguration.png

At the end, open block.nattableconfiguration file with Text Editor and replace

<listenFeature xsi:type="ecore:EReference" href="../../org.eclipse.uml2.uml/model/UML.ecore#//Namespace/ownedMember"/>

by

<listenFeature xsi:type="ecore:EReference" href="http://www.eclipse.org/uml2/5.0.0/UML#//Namespace/ownedMember"/>

Add one Axis Manager Representation

Come back to use the Nattableconfiguration Model Editor, click with the right mouse button on your new created Table Header Axis Configuration item and create a New Child of type Axis Manager Representation. Once added, define its properties:

AxisManagerRepresentation.png

Axis Manager Id: define the Id that you will use to set the extension org.eclipse.papyrus.infra.nattable.axismanager.

Add one Column Header Axis Configuration Table Header Axis Configuration

Click with the right mouse button on the Table Configuration item and create a New Child of type Column Header Axis Configuration Table Header Axis Configuration (Fig. 7). Once added, define its properties:

ColumnTableHeaderAxisConfiguration.png

Add one Feature Label Provider Configuration

Click with the right mouse button on your new created Table Header Axis Configuration item and create a New Child of type Feature Label Provider Configuration. Once added, define its properties:

AxisManagerRepresentation01.png

And again, create a second New Child of type Axis Manager Representation. Once added, define its properties:

AxisManagerRepresentation02.png

Add one Column Axis Providers Slave Object Axis Provider

Click with the right mouse button on the Table Configuration item and create a New Child of type Column Axis Providers Slave Object Axis Provider (Fig. 7). Once added, define its properties:

SlaveObjectAxisProvider.png

Add one EStructural Feature Axis

Click with the right mouse button on your new created Slave Object Axis Provider item and create a New Child of type EStructural Feature Axis. Once added, define its properties:

EStructuralFeatureAxis.png


Contribute to menu with a new Papyrus Table (must be completed)

The contribution must be done using viewpoint with a file .configuration. The viewpoint metamodel provides 2 ways to register new tables. the first one used the Element Papyrus Sync Table. You must fill the field :

  • categories
  • Icon
  • ImplementationID : the type of the table, with the same value than in the field type declared in the file .nattableConfiguration of your table
  • Name : the name of the table

Then you can declare Rules to allow/forbid the creation of the table according to the selected element

The second way with viewpoint using Papyrus Table element In this case you must fill the field configuration with the path of your table configuration file.

Label Providers

For the label provider, we divided the tables into 2 areas :

  1. Headers
  2. Body


for each areas we declared a label provider context (using the Papyrus Label Provider extension point):

  1. org.eclipse.papyrus.infra.nattable.full.labelprovider : the context to use to find the label provider used in the table. This one calls the others label providers according to the region for which we are looking for the text/image to display.
  2. org.eclipse.papyrus.infra.nattable.body.labelprovider : the context to use to find the label provider used to get the text in the body of the table
  3. org.eclipse.papyrus.infra.nattable.header.labelprovider : the context to use to find the label provider used to get the text in the header of the table (display icon, display label)
  4. org.eclipse.papyrus.infra.nattable.header.feature.labelprovider : the context to use to find the label provider used to display feature in a header. This label provider allows to define the text to display according to the configuration of the axis ( display icon, display label, display multiciplicity, display type, display a "/" for the derived feature)

These contexts are declared into the plugin org.eclipse.papyrus.infra.nattable.

All label provider declared on these context must accept elements implementing ILabelProviderCellContextElement. This object encapsulate the cell for which we want display a text AND useful elements which can be used to define the text/image/color/... to display in the cell.


Papyrus Extension Point For Table :

  1. Axis Manager
  2. Cell Manager
  3. Cell Editor Configuration




Selection synchronization

Some changes have been applied to the code in order to allow a selection synchronization between the tables and the model explorer. The affected classes are the following :
In these changes, IRevealSemanticElement and its associated method revealSemanticElement is at the core of the modifications.

  1. org/eclipse/papyrus/infra/nattable/common/editor/AbstractEMFNattableEditor.java
    • where we implement the interface and add the call for the newly created revealSemanticElement method in AbstractNattableWidgetManager and giving it the list of selected objects.
  2. org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
    • the method goes through the lines and columns of the tables to find all the elements contained in the list and then proceed to select them graphically in the table.
    • the method used for this is org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.doCommand(ILayerCommand command)
  3. org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
    • in the original method the selection only allowed the first selected element found to show. we now collect all found IGraphicalEditParts and proceed to set the selection in the graphicalViewer.
  4. org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
    • in the handleSelectionChangedFromDiagramEditor method the principal problem was that, if revealSemanticElement was called, it shunned the model explorer as it was not an IEditPart and the redundacy of the IAdaptable verification crashed the process.
    • when we are in an IIeditorPart, as we were interested in the Eobject for the contruction of the list of selected elements and that org.eclipse.papyrus.infra.emf.utils.EMFHelper.getEObject(Object source) already checked for the IAdaptability, the direct replacement of the verification was done.
    • as for the selection in the model explorer, we went through org.eclipse.ui.navigator.LinkHelperService.getLinkHelpersFor(Object anObject) to get the list of LinkHelpers and used the LinkHelper in org.eclipse.papyrus.views.modelexplorer.LinkHelper.activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) to handle the selection with revealSemantiElement.


Modifying the graphical representation of the tables

Resizing Axis and Headers

Three listeners have been added to the AbstractNattableWidgetManager class in order to capture the graphical changes and edit the model.

  1. addAxisResizeListener(final BodyLayerStack bodyLayerStack) that listens to the BodyLayerStack
  2. addColumnHeaderResizeListener(final ColumnHeaderLayerStack columnHeaderLayerStack) that listens to the ColumnHeaderLayerStack
  3. addRowHeaderResizeListener(final RowHeaderLayerStack rowHeaderLayerStack) that listens to the RowHeaderLayerStack

Those methods verify the model in order to know if the graphical values are already present and if not create them and write them using a CompositeCommand and executing it.

The major change introduced in order to accomplish this is the modification of the table's model by adding new Styles, more particularly intValueStyles that are used to carry this specific information. These styles are introduced in the Axis elements, if the changes of size modify axis, or to a newly, or existing, LocalHeaderAxisConfiguration if the changes modify headers. Of course, both of them are now StyledElements and therefore can call on the method getNamedStyle().

  • NamedStyle org.eclipse.papyrus.infra.nattable.model.nattable.nattablestyle.StyledElement.getNamedStyle(EClass eClass, String name)

Two init methods will also be called when refreshing or opening the table in order to show the modified table.

  1. initTableAxis() that gets the list of the displayed axis and check their styles
  2. initTableHeaders() that gets the AbstractHeaderAxisConfigurationUsedInTable, allowing the method to get around the invertAxis configuration, and check their styles

Both have a default behavior, in case no styles were attached to an element, to apply its default size to its graphical representation.


Merging cells inside their Axis

The merge is based on nebula's AutomaticSpanningDataProvider (org.eclipse.nebula.widgets.nattable.data.AutomaticSpanningDataProvider) allowing us to apply a spanProvider to the table's BodyLayerStack and, with minor modification of the method valuesNotEqual(), triggering the desired span (i.e. merge) throughout the layer. It is to be noted that the cells are merged using their values and not their types.
To accomplish this four new merge handlers were created, piloted by a menu constituted of exclusive choices.

  1. org.eclipse.papyrus.infra.nattable.handler.MergeColumnsHandler
  2. org.eclipse.papyrus.infra.nattable.handler.MergeRowsHandler
  3. org.eclipse.papyrus.infra.nattable.handler.MergeSelectedRowsHandler
  4. org.eclipse.papyrus.infra.nattable.handler.MergeSelectedColumnsHandler

The handlers' model modification behavior are similar to the resize listeners' one, where the style's value is researched in the model and created, or modified, depending on the case, set inside a CompositeCommand and executed inside the core AbstractMergeHandler. The merge boolean will then be carried by the LocalHeaderAxisConfiguration if the user chose to merge all the columns/rows inside the table or by the Axis if the user chose to merge only selected Axis.

To access these handlers, new extensions have been added in the form of a new menu to call on the handlers and a property tester to check the availability of the menu's options or not depending on the merge state of the table; and to update the toggles of each menu, new updateToggleCommandState() have also been added to NattableModelManager, calling on the getToggleState[...]() methods in AbstractNattableManager.
One init method and two Listeners, one for the resourceSet and another for the Layer, are used to update the graphical view throughout the changes.

  1. initTableMerge() in wich the list of the displayed axis is obtained and their styles checked
  2. resourceSetListener inside the updateCellMap() method in which the notifications due to the modification of the resourceSet are filtered to keep the styles we want to apply or unapply, depending on the user's choices, and enable the use of the undo/redo behavior


Editing merged cells

A PapyrusSpanningDataLayer has been added and @Overrides the setDataValue of nebula's org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer#setDataValue(int, int, java.lang.Object) to allow the edition of multiple cells inside a merged selection.
The edition will then verify if the value to be inputted can indeed be, see org.eclipse.papyrus.infra.nattable.manager.cell.AbstractCellManager.setValue(), and edit the cell accordingly. Of course, the merge selection is updated after this so that, inside a previuosly merged selection, only the cells of equal values are still merged.

Back to the top