Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2014-01-16 15:05:39 +0000
committervlorenzo2014-01-16 15:05:39 +0000
commit00ac2a1ef99eba2dfe0199ba42a405f51467847d (patch)
tree50f0d981201ffdb1fbd6a5131ce563533edcb7dd /extraplugins
parent158fd10bc953c93cab15a138476ab2b8bee61a7a (diff)
downloadorg.eclipse.papyrus-00ac2a1ef99eba2dfe0199ba42a405f51467847d.tar.gz
org.eclipse.papyrus-00ac2a1ef99eba2dfe0199ba42a405f51467847d.tar.xz
org.eclipse.papyrus-00ac2a1ef99eba2dfe0199ba42a405f51467847d.zip
423451: [Table] Enhancement around table selection
https://bugs.eclipse.org/bugs/show_bug.cgi?id=423451
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java2
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java123
2 files changed, 104 insertions, 21 deletions
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
index 4b9e0d208bb..b4bf438bb2b 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java
@@ -205,7 +205,7 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan
final Menu menu = menuMgr.createContextMenu(this.natTable);
this.natTable.setMenu(menu);
- this.selectionProvider = new TableSelectionProvider(this.bodyLayerStack.getSelectionLayer());
+ this.selectionProvider = new TableSelectionProvider(this, this.bodyLayerStack.getSelectionLayer());
site.registerContextMenu(menuMgr, this.selectionProvider);
site.setSelectionProvider(this.selectionProvider);
}
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java
index 87f00f096ff..1b7aef2f42d 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java
@@ -30,22 +30,56 @@ import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
+import org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent;
import org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent;
+import org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
import org.eclipse.ui.services.IDisposable;
-
+/**
+ *
+ * The selection provider used by the table. The returned selection is used to display property views or to do the synchronization in the
+ * ModelExplorer
+ *
+ */
public class TableSelectionProvider implements ISelectionProvider, IDisposable {
+ /**
+ * the selection layer used in the table
+ */
private SelectionLayer selectionLayer;
+ /**
+ * the selection listener
+ */
private final ILayerListener selectionListener;
+ /**
+ * the current selection in the table
+ */
private ISelection currentSelection;
+ /**
+ * the list of listener on the selections
+ */
private final List<ISelectionChangedListener> listeners;
- public TableSelectionProvider(final SelectionLayer selectionLayer) {
+ /**
+ * the table model manager to use to find selected elements
+ */
+ private INattableModelManager manager;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param manager
+ * the table model manager to use to find selected elements
+ * @param selectionLayer
+ */
+ public TableSelectionProvider(final INattableModelManager manager, final SelectionLayer selectionLayer) {
this.selectionLayer = selectionLayer;
this.selectionListener = new ILayerListener() {
@@ -56,22 +90,45 @@ public class TableSelectionProvider implements ISelectionProvider, IDisposable {
this.selectionLayer.addLayerListener(this.selectionListener);
this.currentSelection = new StructuredSelection();
this.listeners = new ArrayList<ISelectionChangedListener>();
+ this.manager = manager;
}
-
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ *
+ * @param listener
+ */
public void addSelectionChangedListener(final ISelectionChangedListener listener) {
this.listeners.add(listener);
-
}
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
+ *
+ * @return
+ */
public synchronized ISelection getSelection() {
return this.currentSelection;
}
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ *
+ * @param listener
+ */
public void removeSelectionChangedListener(final ISelectionChangedListener listener) {
this.listeners.remove(listener);
}
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
+ *
+ * @param selection
+ */
public synchronized void setSelection(final ISelection selection) {
if(this.currentSelection.equals(selection)) {
return;
@@ -91,29 +148,48 @@ public class TableSelectionProvider implements ISelectionProvider, IDisposable {
//add the cell selection
final Collection<PositionCoordinate> selectedCells = Arrays.asList(this.selectionLayer.getSelectedCellPositions());
final TableSelectionWrapper wrapper = new TableSelectionWrapper(selectedCells);
- // selection.add(0, wrapper);
//we returns the contents of the last selected cell
//we could returns the contents of all selected cells if its required
if(event instanceof CellSelectionEvent) {
- final CellSelectionEvent e = (CellSelectionEvent)event;
- final int colPos = e.getColumnPosition();
- final int rowPos = e.getRowPosition();
- final ILayerCell cell = this.selectionLayer.getCellByPosition(colPos, rowPos);
- if(cell != null) {
- final Object value = cell.getDataValue();
-
- if(value != null) {
- if(value instanceof Collection<?>) {
- final Iterator<?> iter = ((Collection<?>)value).iterator();
- while(iter.hasNext()) {
- final Object current = iter.next();
- selection.add(current);
+ for(final PositionCoordinate current1 : this.selectionLayer.getSelectedCellPositions()) {
+ final int colPos = current1.getColumnPosition();
+ final int rowPos = current1.getRowPosition();
+ final ILayerCell cell = this.selectionLayer.getCellByPosition(colPos, rowPos);
+ if(cell != null) {
+ final Object value = cell.getDataValue();
+ if(value != null) {
+ if(value instanceof Collection<?>) {
+ final Iterator<?> iter = ((Collection<?>)value).iterator();
+ while(iter.hasNext()) {
+ final Object current = iter.next();
+ selection.add(current);
+ }
+ } else {
+ selection.add(value);
}
- } else {
- selection.add(value);
}
+ }
+ }
+ } else if(event instanceof RowSelectionEvent) {
+ this.selectionLayer.getFullySelectedRowPositions();
+ int[] rows = this.selectionLayer.getFullySelectedRowPositions();
+ for(int i : rows) {
+ Object el = this.manager.getRowElement(i);
+ if(el != null) {
+ el = AxisUtils.getRepresentedElement(el);
+ selection.add(el);
+ }
+ }
+
+ } else if(event instanceof ColumnSelectionEvent) {
+ int[] selectedColumn = this.selectionLayer.getFullySelectedColumnPositions();
+ for(int i : selectedColumn) {
+ Object el = this.manager.getColumnElement(i);
+ if(el != null) {
+ el = AxisUtils.getRepresentedElement(el);
+ selection.add(el);
}
}
}
@@ -124,6 +200,13 @@ public class TableSelectionProvider implements ISelectionProvider, IDisposable {
setSelection(newSelection);
}
+
+
+ /**
+ *
+ * @see org.eclipse.ui.services.IDisposable#dispose()
+ *
+ */
public void dispose() {
this.selectionLayer.removeLayerListener(this.selectionListener);
this.selectionLayer = null;

Back to the top