Added indirection for Java 7 interoperability.
diff --git a/bundles/runtime/org.eclipse.fx.emf.edit.ui/META-INF/MANIFEST.MF b/bundles/runtime/org.eclipse.fx.emf.edit.ui/META-INF/MANIFEST.MF
index d834651..1b6f9e1 100755
--- a/bundles/runtime/org.eclipse.fx.emf.edit.ui/META-INF/MANIFEST.MF
+++ b/bundles/runtime/org.eclipse.fx.emf.edit.ui/META-INF/MANIFEST.MF
@@ -35,6 +35,7 @@
javafx.stage;version="2.2.0",
javafx.util;version="2.2.0",
javafx.util.converter;version="2.2.0"
-Require-Bundle: org.eclipse.emf.edit;bundle-version="2.7.0"
+Require-Bundle: org.eclipse.emf.edit;bundle-version="2.7.0",
+ org.eclipse.fx.core;bundle-version="0.8.1"
Export-Package: org.eclipse.fx.emf.edit.ui,
org.eclipse.fx.emf.edit.ui.dnd
diff --git a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/AdapterFactoryTreeItem.java b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/AdapterFactoryTreeItem.java
index abdc6e1..72c2fe4 100644
--- a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/AdapterFactoryTreeItem.java
+++ b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/AdapterFactoryTreeItem.java
@@ -19,8 +19,6 @@
import javafx.scene.control.Control;
import javafx.scene.control.MultipleSelectionModel;
import javafx.scene.control.TreeItem;
-import javafx.scene.control.TreeTableView;
-import javafx.scene.control.TreeView;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
@@ -79,8 +77,7 @@
void updateChildren() {
ObservableList<TreeItem<Object>> childTreeItems = super.getChildren();
- MultipleSelectionModel<?> selectionModel = view instanceof TreeView<?> ? ((TreeView<?>) view).getSelectionModel()
- : ((TreeTableView<?>) view).getSelectionModel();
+ MultipleSelectionModel<?> selectionModel = CellUtil.getSelectionModel(view);
List<?> selection = selectionModel.getSelectedItems();
ArrayList<Object> selectedItems = new ArrayList<>();
ArrayList<TreeItem<?>> selectedTreeItems = new ArrayList<>();
diff --git a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil.java b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil.java
index 51fd144..ca79a70 100644
--- a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil.java
+++ b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil.java
@@ -1,83 +1,67 @@
package org.eclipse.fx.emf.edit.ui;
-import java.util.ArrayList;
import java.util.List;
import javafx.scene.control.Cell;
-import javafx.scene.control.ListCell;
+import javafx.scene.control.Control;
import javafx.scene.control.ListView;
import javafx.scene.control.MultipleSelectionModel;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
-import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableCell;
import javafx.scene.control.TreeTableRow;
import javafx.scene.control.TreeTableView;
import javafx.scene.control.TreeView;
+import org.eclipse.fx.core.Util;
+
public class CellUtil {
/**
- * Finds the row for a {@link Cell} so the feedback can be applied to the whole row
+ * Finds the row for a {@link Cell} so the feedback can be applied to the
+ * whole row
*
- * @return the containing {@link TableRow} for {@link TableCell}s or the {@link TreeTableRow} for
- * {@link TreeTableCell}s and the {@link Cell} itself otherwise
+ * @return the containing {@link TableRow} for {@link TableCell}s or the
+ * {@link TreeTableRow} for {@link TreeTableCell}s and the
+ * {@link Cell} itself otherwise
*/
public static Cell<?> getRowNode(final Cell<?> cell) {
- if (cell instanceof TableCell)
- return ((TableCell<?, ?>) cell).getTableRow();
- else if (cell instanceof TreeTableCell)
- return ((TreeTableCell<?, ?>) cell).getTreeTableRow();
- else
- return cell;
+ return Util.isFX2() ? CellUtil2.getRowNode(cell) : CellUtil8.getRowNode(cell);
}
/**
- * Retrieves the {@link MultipleSelectionModel} from the {@link ListView}, {@link TreeView},
- * {@link TableView} or {@link TreeTableView} in which <code>cell</code> is displayed
+ * Retrieves the {@link MultipleSelectionModel} from the {@link ListView},
+ * {@link TreeView}, {@link TableView} or {@link TreeTableView} in which
+ * <code>cell</code> is displayed
*
- * @param cell the {@link Cell} for which the {@link MultipleSelectionModel} is to be retrieved
+ * @param cell
+ * the {@link Cell} for which the {@link MultipleSelectionModel}
+ * is to be retrieved
* @return the {@link MultipleSelectionModel} for this {@link Cell}
*/
public static MultipleSelectionModel<?> getSelectionModel(Cell<?> cell) {
- if (cell instanceof ListCell)
- return ((ListCell<?>) cell).getListView().getSelectionModel();
- else if (cell instanceof TreeCell)
- return ((TreeCell<?>) cell).getTreeView().getSelectionModel();
- else if (cell instanceof TableCell)
- return ((TableCell<?, ?>) cell).getTableView().getSelectionModel();
- else if (cell instanceof TableRow)
- return ((TableRow<?>) cell).getTableView().getSelectionModel();
- else if (cell instanceof TreeTableCell)
- return ((TreeTableCell<?, ?>) cell).getTreeTableView().getSelectionModel();
- else if (cell instanceof TreeTableRow)
- return ((TreeTableRow<?>) cell).getTreeTableView().getSelectionModel();
- else
- throw new IllegalArgumentException("Unsupported Cell type");
+ return Util.isFX2() ? CellUtil2.getSelectionModel(cell) : CellUtil8.getSelectionModel(cell);
+ }
+
+ public static MultipleSelectionModel<?> getSelectionModel(Control view) {
+ return Util.isFX2() ? CellUtil2.getSelectionModel(view) : CellUtil8.getSelectionModel(view);
}
/**
- * Retrieves the selected items from the {@link ListView}, {@link TreeView}, {@link TableView} or
- * {@link TreeTableView} in which <code>cell</code> is displayed. {@link TreeItem}s will be replaced with
+ * Retrieves the selected items from the {@link ListView}, {@link TreeView},
+ * {@link TableView} or {@link TreeTableView} in which <code>cell</code> is
+ * displayed. {@link TreeItem}s will be replaced with
* {@link TreeItem#getValue()}.
*
- * @param cell the {@link Cell} for which the selected items should be retrieved
+ * @param cell
+ * the {@link Cell} for which the selected items should be
+ * retrieved
* @return a {@link List} with the selected items
*/
public static List<?> getSelectedItems(Cell<?> cell) {
- MultipleSelectionModel<?> selectionModel = getSelectionModel(cell);
- List<?> items = selectionModel.getSelectedItems();
-
- if (cell instanceof TreeCell || cell instanceof TreeTableCell) {
- List<Object> unwrappedItems = new ArrayList<>(items.size());
- for (Object item : items)
- unwrappedItems.add(((TreeItem<?>) item).getValue());
- return unwrappedItems;
- }
-
- return items;
+ return Util.isFX2() ? CellUtil2.getSelectedItems(cell) : CellUtil8.getSelectedItems(cell);
}
}
diff --git a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil2.java b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil2.java
new file mode 100644
index 0000000..fc1409a
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil2.java
@@ -0,0 +1,59 @@
+package org.eclipse.fx.emf.edit.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javafx.scene.control.Cell;
+import javafx.scene.control.Control;
+import javafx.scene.control.ListCell;
+import javafx.scene.control.MultipleSelectionModel;
+import javafx.scene.control.TableCell;
+import javafx.scene.control.TableRow;
+import javafx.scene.control.TreeCell;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeView;
+
+public class CellUtil2 {
+
+ public static Cell<?> getRowNode(final Cell<?> cell) {
+ if (cell instanceof TableCell)
+ return ((TableCell<?, ?>) cell).getTableRow();
+ else
+ return cell;
+ }
+
+ public static MultipleSelectionModel<?> getSelectionModel(Cell<?> cell) {
+ if (cell instanceof ListCell)
+ return ((ListCell<?>) cell).getListView().getSelectionModel();
+ else if (cell instanceof TreeCell)
+ return ((TreeCell<?>) cell).getTreeView().getSelectionModel();
+ else if (cell instanceof TableCell)
+ return ((TableCell<?, ?>) cell).getTableView().getSelectionModel();
+ else if (cell instanceof TableRow)
+ return ((TableRow<?>) cell).getTableView().getSelectionModel();
+ else
+ throw new IllegalArgumentException("Unsupported Cell type");
+ }
+
+ public static MultipleSelectionModel<?> getSelectionModel(Control view) {
+ if (view instanceof TreeView<?>)
+ return ((TreeView<?>) view).getSelectionModel();
+ else
+ throw new IllegalArgumentException("Unsupported View type");
+ }
+
+ public static List<?> getSelectedItems(Cell<?> cell) {
+ MultipleSelectionModel<?> selectionModel = getSelectionModel(cell);
+ List<?> items = selectionModel.getSelectedItems();
+
+ if (cell instanceof TreeCell) {
+ List<Object> unwrappedItems = new ArrayList<>(items.size());
+ for (Object item : items)
+ unwrappedItems.add(((TreeItem<?>) item).getValue());
+ return unwrappedItems;
+ }
+
+ return items;
+ }
+
+}
diff --git a/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil8.java b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil8.java
new file mode 100644
index 0000000..0d1a5c0
--- /dev/null
+++ b/bundles/runtime/org.eclipse.fx.emf.edit.ui/src/org/eclipse/fx/emf/edit/ui/CellUtil8.java
@@ -0,0 +1,74 @@
+package org.eclipse.fx.emf.edit.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javafx.scene.control.Cell;
+import javafx.scene.control.Control;
+import javafx.scene.control.ListCell;
+import javafx.scene.control.MultipleSelectionModel;
+import javafx.scene.control.TableCell;
+import javafx.scene.control.TableRow;
+import javafx.scene.control.TreeCell;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeTableCell;
+import javafx.scene.control.TreeTableRow;
+import javafx.scene.control.TreeTableView;
+import javafx.scene.control.TreeView;
+
+import org.eclipse.fx.core.Util;
+
+public class CellUtil8 {
+
+ public static Cell<?> getRowNode(final Cell<?> cell) {
+ if (cell instanceof TableCell)
+ return ((TableCell<?, ?>) cell).getTableRow();
+ else if (cell instanceof TreeTableCell)
+ return ((TreeTableCell<?, ?>) cell).getTreeTableRow();
+ else
+ return cell;
+ }
+
+ public static MultipleSelectionModel<?> getSelectionModel(Cell<?> cell) {
+ if (cell instanceof ListCell)
+ return ((ListCell<?>) cell).getListView().getSelectionModel();
+ else if (cell instanceof TreeCell)
+ return ((TreeCell<?>) cell).getTreeView().getSelectionModel();
+ else if (cell instanceof TableCell)
+ return ((TableCell<?, ?>) cell).getTableView().getSelectionModel();
+ else if (cell instanceof TableRow)
+ return ((TableRow<?>) cell).getTableView().getSelectionModel();
+ else if (cell instanceof TreeTableCell)
+ return ((TreeTableCell<?, ?>) cell).getTreeTableView()
+ .getSelectionModel();
+ else if (cell instanceof TreeTableRow)
+ return ((TreeTableRow<?>) cell).getTreeTableView()
+ .getSelectionModel();
+ else
+ throw new IllegalArgumentException("Unsupported Cell type");
+ }
+
+ public static MultipleSelectionModel<?> getSelectionModel(Control view) {
+ if (view instanceof TreeView<?>)
+ return ((TreeView<?>) view).getSelectionModel();
+ else if (Util.isFX2() && view instanceof TreeTableView<?>)
+ return ((TreeTableView<?>) view).getSelectionModel();
+ else
+ throw new IllegalArgumentException("Unsupported View type");
+ }
+
+ public static List<?> getSelectedItems(Cell<?> cell) {
+ MultipleSelectionModel<?> selectionModel = getSelectionModel(cell);
+ List<?> items = selectionModel.getSelectedItems();
+
+ if (cell instanceof TreeCell || cell instanceof TreeTableCell) {
+ List<Object> unwrappedItems = new ArrayList<>(items.size());
+ for (Object item : items)
+ unwrappedItems.add(((TreeItem<?>) item).getValue());
+ return unwrappedItems;
+ }
+
+ return items;
+ }
+
+}