Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2013-09-17 08:25:55 +0000
committerVincent Lorenzo2013-09-17 08:25:55 +0000
commit1b32c2d01a6864f7a06bf4da41d48c177a038a5c (patch)
tree5781f2f47c306d9aaca3884e4726040f5972af9b /extraplugins
parente9ffc6134c96c3112560e6e5d2759c107b717eef (diff)
downloadorg.eclipse.papyrus-1b32c2d01a6864f7a06bf4da41d48c177a038a5c.tar.gz
org.eclipse.papyrus-1b32c2d01a6864f7a06bf4da41d48c177a038a5c.tar.xz
org.eclipse.papyrus-1b32c2d01a6864f7a06bf4da41d48c177a038a5c.zip
413077: [Table 2] The method getSelection in the table must be improved
https://bugs.eclipse.org/bugs/show_bug.cgi?id=413077
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/AbstractTableHandler.java22
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableSelectionProvider.java9
-rw-r--r--extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableStructuredSelection.java112
3 files changed, 130 insertions, 13 deletions
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/AbstractTableHandler.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/AbstractTableHandler.java
index 2a9db3d3784..e03aa979278 100644
--- a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/AbstractTableHandler.java
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/AbstractTableHandler.java
@@ -15,13 +15,12 @@ package org.eclipse.papyrus.infra.nattable.handler;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.ui.NatEventData;
@@ -227,14 +226,17 @@ public abstract class AbstractTableHandler extends AbstractHandler {
if(evaluationContext instanceof IEvaluationContext) {
Object selection = HandlerUtil.getVariable(evaluationContext, "selection"); //$NON-NLS-1$
- if(selection instanceof IStructuredSelection) {
- Iterator<?> iter = ((IStructuredSelection)selection).iterator();
- while(iter.hasNext() && wrapper == null) {
- Object current = iter.next();
- if(current instanceof TableSelectionWrapper) {
- wrapper = (TableSelectionWrapper)current;
- }
- }
+ // if(selection instanceof IStructuredSelection) {
+ // Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ // while(iter.hasNext() && wrapper == null) {
+ // Object current = iter.next();
+ // if(current instanceof TableSelectionWrapper) {
+ // wrapper = (TableSelectionWrapper)current;
+ // }
+ // }
+ // }
+ if(selection instanceof IAdaptable) {
+ wrapper = (TableSelectionWrapper)((IAdaptable)selection).getAdapter(TableSelectionWrapper.class);
}
}
}
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 ed28d362b40..87f00f096ff 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
@@ -86,12 +86,12 @@ public class TableSelectionProvider implements ISelectionProvider, IDisposable {
protected/* synchronized */void calculateAndStoreNewSelection(final ILayerEvent event) {
//the list of the selected elements
final List<Object> selection = new ArrayList<Object>();
-
+ final ISelection newSelection;
if(event instanceof ISelectionEvent) {
//add the cell selection
final Collection<PositionCoordinate> selectedCells = Arrays.asList(this.selectionLayer.getSelectedCellPositions());
final TableSelectionWrapper wrapper = new TableSelectionWrapper(selectedCells);
- selection.add(0, wrapper);
+ // 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
@@ -117,8 +117,11 @@ public class TableSelectionProvider implements ISelectionProvider, IDisposable {
}
}
}
+ newSelection = new TableStructuredSelection(selection, wrapper);
+ } else {
+ newSelection = new StructuredSelection();
}
- setSelection(new StructuredSelection(selection));
+ setSelection(newSelection);
}
public void dispose() {
diff --git a/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableStructuredSelection.java b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableStructuredSelection.java
new file mode 100644
index 00000000000..7645aae87bf
--- /dev/null
+++ b/extraplugins/table/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/TableStructuredSelection.java
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.provider;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
+
+/**
+ * The StructuredSelection filled by the tables. It able to embed more precision about the selected elements in the table.
+ *
+ * @author vl222926
+ *
+ */
+public class TableStructuredSelection extends StructuredSelection implements IAdaptable {
+
+ /**
+ * the wrapper for the table selection
+ */
+ private final TableSelectionWrapper wrapper;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param wrapper
+ */
+ public TableStructuredSelection(TableSelectionWrapper wrapper) {
+ super();
+ this.wrapper = wrapper;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param elements
+ * @param comparer
+ * @param wrapper
+ */
+ public TableStructuredSelection(List<?> elements, IElementComparer comparer, TableSelectionWrapper wrapper) {
+ super(elements, comparer);
+ this.wrapper = wrapper;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param elements
+ * @param wrapper
+ */
+ public TableStructuredSelection(List<?> elements, TableSelectionWrapper wrapper) {
+ super(elements);
+ this.wrapper = wrapper;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param element
+ * @param wrapper
+ */
+ public TableStructuredSelection(Object element, TableSelectionWrapper wrapper) {
+ super(element);
+ this.wrapper = wrapper;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param elements
+ * @param wrapper
+ */
+ public TableStructuredSelection(Object[] elements, TableSelectionWrapper wrapper) {
+ super(elements);
+ this.wrapper = wrapper;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ *
+ * @param adapter
+ * @return
+ */
+ @Override
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ if(adapter == TableSelectionWrapper.class) {
+ return this.wrapper;
+ }
+ return null;
+ }
+
+
+}

Back to the top