Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Spungin2014-04-02 14:14:54 -0400
committerLars Vogel2014-04-02 17:58:39 -0400
commit7937d36a333066d77b95ed30bcf737784c129f76 (patch)
tree5234891103e104bc72653d481359eb8c7af25f26
parentf2d53ff946213ad9776992fd0c3abd0a1ce0e3f9 (diff)
downloadorg.eclipse.e4.tools-7937d36a333066d77b95ed30bcf737784c129f76.tar.gz
org.eclipse.e4.tools-7937d36a333066d77b95ed30bcf737784c129f76.tar.xz
org.eclipse.e4.tools-7937d36a333066d77b95ed30bcf737784c129f76.zip
Bug 396902 - Reloading the model causes the model editor tree toI20140402-2200
collapse Change-Id: I0e22906ee88f8a6b6e9a812625badfdbe2d2627a Signed-off-by: Steven Spungin <steven@spungin.tv>
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java9
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/TreeViewerEx.java119
2 files changed, 124 insertions, 4 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index 0dfccb83..f3b4542e 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -10,7 +10,7 @@
* Wim Jongman <wim.jongman@remainsoftware.com> - Maintenance
* Marco Descher <marco@descher.at> - Bug395982, 426653, 422465
* Lars Vogel <Lars.Vogel@gmail.com> - Ongoing maintenance
- * Steven Spungin <steven@spungin.tv> - Bug 431755
+ * Steven Spungin <steven@spungin.tv> - Bug 396902, 431755
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common;
@@ -390,14 +390,15 @@ public class ModelEditor {
fragment = modelProvider.getRoot().get(0) instanceof MModelFragments;
+ // For Bug 396902, create this before creating the Form tab
+ emfDocumentProvider = new EMFDocumentResourceMediator(modelProvider);
+
editorTabFolder = new CTabFolder(composite, SWT.BOTTOM);
CTabItem item = new CTabItem(editorTabFolder, SWT.NONE);
item.setText(messages.ModelEditor_Form);
item.setControl(createFormTab(editorTabFolder));
item.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_Obj16_application_form));
- emfDocumentProvider = new EMFDocumentResourceMediator(modelProvider);
-
item = new CTabItem(editorTabFolder, SWT.NONE);
item.setText(messages.ModelEditor_XMI);
item.setControl(createXMITab(editorTabFolder));
@@ -996,7 +997,7 @@ public class ModelEditor {
FilteredTree viewParent = new FilteredTree(treeArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), true);
tempViewer = viewParent.getViewer();
} else {
- tempViewer = new TreeViewer(treeArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ tempViewer = new TreeViewerEx(treeArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL, emfDocumentProvider, modelProvider);
}
final TreeViewer viewer = tempViewer;
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/TreeViewerEx.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/TreeViewerEx.java
new file mode 100644
index 00000000..d3011212
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/TreeViewerEx.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2014 TwelveTone LLC and others.
+ * 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:
+ * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 396902
+ ******************************************************************************/
+
+package org.eclipse.e4.tools.emf.ui.internal.common;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.e4.tools.emf.ui.common.IModelResource;
+import org.eclipse.e4.tools.emf.ui.internal.common.xml.EMFDocumentResourceMediator;
+import org.eclipse.e4.ui.internal.workbench.E4XMIResource;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Adds additional functionality to TreeViewer
+ *
+ * @author Steven Spungin
+ *
+ */
+public class TreeViewerEx extends TreeViewer {
+
+ private ArrayList<String> elementsIds;
+ private ArrayList<String> selectedIds;
+
+ public TreeViewerEx(Composite parent, int style, EMFDocumentResourceMediator emfDocumentProvider, final IModelResource modelProvider) {
+ super(parent, style);
+
+ emfDocumentProvider.getDocument().addDocumentListener(new IDocumentListener() {
+
+ @Override
+ public void documentChanged(DocumentEvent event) {
+ try {
+ // restore Nodes from XmiIds
+ E4XMIResource xmiResource = (E4XMIResource) ((EObject) modelProvider.getRoot().get(0)).eResource();
+ ArrayList<Object> newElements = new ArrayList<Object>();
+ ObservableListTreeContentProvider provider = (ObservableListTreeContentProvider) getContentProvider();
+ for (String id : elementsIds) {
+ EObject eObject = xmiResource.getEObject(id);
+ if (eObject != null) {
+ newElements.add(eObject);
+ // force tree node creation
+ getFirstMatchingItem(eObject, provider, provider.getChildren(getInput()));
+ }
+ }
+ ArrayList<Object> newSelected = new ArrayList<Object>();
+ for (String id : selectedIds) {
+ EObject eObject = xmiResource.getEObject(id);
+ if (eObject != null) {
+ newSelected.add(eObject);
+ // force tree node creation
+ getFirstMatchingItem(eObject, provider, provider.getChildren(getInput()));
+ }
+ }
+ setExpandedElements(newElements.toArray(new Object[0]));
+ setSelection(new StructuredSelection(newSelected));
+
+ // update our stored id values
+ documentAboutToBeChanged(event);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ try {
+ // Stash XmiIds
+ Object[] elements = getExpandedElements();
+ List<?> selected = ((IStructuredSelection) getSelection()).toList();
+ E4XMIResource xmiResource = (E4XMIResource) ((EObject) modelProvider.getRoot().get(0)).eResource();
+ elementsIds = new ArrayList<String>();
+ selectedIds = new ArrayList<String>();
+ for (Object obj : elements) {
+ if (obj instanceof EObject) {
+ elementsIds.add(xmiResource.getID((EObject) obj));
+ }
+ }
+ for (Object obj : selected) {
+ if (obj instanceof EObject) {
+ selectedIds.add(xmiResource.getID((EObject) obj));
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ // This will ensure the provider has created the tree node (so we can reveal
+ // it).
+ static public Object getFirstMatchingItem(EObject target, ObservableListTreeContentProvider provider, Object[] items) {
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == target) {
+ return items[i];
+ }
+ Object found = getFirstMatchingItem(target, provider, provider.getChildren(items[i]));
+ if (found != null) {
+ return found;
+ }
+ }
+ return null;
+ }
+}

Back to the top