Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2013-08-27 21:02:34 +0000
committerChristian W. Damus2013-09-16 20:02:45 +0000
commitd428560b06d22dd088928f7549562072b8eb4613 (patch)
tree50a26a66f7156cea9c23476aab6040064a970a19 /extraplugins
parentee7752c06ac58a4cf1bba5053b2e6212c05a92c1 (diff)
downloadorg.eclipse.papyrus-d428560b06d22dd088928f7549562072b8eb4613.tar.gz
org.eclipse.papyrus-d428560b06d22dd088928f7549562072b8eb4613.tar.xz
org.eclipse.papyrus-d428560b06d22dd088928f7549562072b8eb4613.zip
415369: [CDO] Support controlled resources and lazy loading
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415369 Require import/export of all super- and sub-units of model units being imported/exported. That is, import/export requires the entire logical model.
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/importer/IModelTransferNode.java22
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferConfiguration.java52
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferNode.java50
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/wizards/ModelReferencesPage.java64
4 files changed, 165 insertions, 23 deletions
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/importer/IModelTransferNode.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/importer/IModelTransferNode.java
index 1415292d4fd..5a497f3b4df 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/importer/IModelTransferNode.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/core/importer/IModelTransferNode.java
@@ -21,7 +21,7 @@ import org.eclipse.emf.common.util.URI;
public interface IModelTransferNode {
String getName();
-
+
URI getPrimaryResourceURI();
Collection<URI> getResourceURIs();
@@ -29,4 +29,24 @@ public interface IModelTransferNode {
Collection<IModelTransferNode> getDependencies();
Collection<IModelTransferNode> getDependents();
+
+ /**
+ * Queries whether an{@code other} node represents a model sub-unit of me.
+ *
+ * @param other
+ * another model unit
+ *
+ * @return whether the {@code other} it is a logical model sub-unit of me
+ */
+ boolean isModelSubUnit(IModelTransferNode other);
+
+ /**
+ * Queries whether an{@code other} node represents my model super-unit.
+ *
+ * @param other
+ * another model unit
+ *
+ * @return whether the {@code other} it is the logical model super-unit of me
+ */
+ boolean isModelParentUnit(IModelTransferNode other);
}
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferConfiguration.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferConfiguration.java
index 8b362991b55..1f3fb30c582 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferConfiguration.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferConfiguration.java
@@ -157,6 +157,8 @@ public class ModelTransferConfiguration implements IModelTransferConfiguration {
// first, if it's a DI resource, ensure that it gets its components
if(DependencyAdapter.isDIResource(resource)) {
DependencyAdapter adapter = DependencyAdapter.getInstance(resource);
+ final int oldCount = adapter.getDependencies().size();
+
for(URI uri : next.getComponents(resource, monitor)) {
// this is an implicit dependency, even if there are no references
// to it (which occurs, e.g., in model sub-units that have no diagrams)
@@ -166,8 +168,11 @@ public class ModelTransferConfiguration implements IModelTransferConfiguration {
}
}
- // scan for components again
- newNode.scanForComponents();
+ if(adapter.getDependencies().size() > oldCount) {
+ // scan for components and dependencies again
+ newNode.scanForComponents();
+ newNode.scanForDependencies();
+ }
}
for(URI uri : next.getDependents(newNode.getPrimaryResource(), monitor)) {
@@ -222,8 +227,13 @@ public class ModelTransferConfiguration implements IModelTransferConfiguration {
Set<IModelTransferNode> dependents = ImmutableSet.copyOf(node.getDependents());
Set<IModelTransferNode> leftOut = Sets.difference(dependents, toImport);
if(!leftOut.isEmpty()) {
- int severity = direction.isImport() ? Diagnostic.WARNING : Diagnostic.INFO;
- diagnostics.add(new BasicDiagnostic(severity, Activator.PLUGIN_ID, 0, NLS.bind(Messages.ModelTransferConfiguration_1, node.getName(), direction), new Object[]{ node, leftOut }));
+ IModelTransferNode parentUnit = findParentUnit(node, leftOut);
+ if(parentUnit != null) {
+ diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, Activator.PLUGIN_ID, 0, NLS.bind("Parent unit {2} of controlled unit {0} must be selected for {1}.", new Object[]{ node.getName(), direction, parentUnit.getName() }), new Object[]{ node, parentUnit }));
+ } else {
+ int severity = direction.isImport() ? Diagnostic.WARNING : Diagnostic.INFO;
+ diagnostics.add(new BasicDiagnostic(severity, Activator.PLUGIN_ID, 0, NLS.bind(Messages.ModelTransferConfiguration_1, node.getName(), direction), new Object[]{ node, leftOut }));
+ }
}
}
@@ -231,9 +241,39 @@ public class ModelTransferConfiguration implements IModelTransferConfiguration {
Set<IModelTransferNode> dependencies = ImmutableSet.copyOf(node.getDependencies());
Set<IModelTransferNode> leftOut = Sets.difference(dependencies, toImport);
if(!leftOut.isEmpty()) {
- int severity = direction.isImport() ? Diagnostic.INFO : Diagnostic.WARNING;
- diagnostics.add(new BasicDiagnostic(severity, Activator.PLUGIN_ID, 0, NLS.bind(Messages.ModelTransferConfiguration_2, node.getName(), direction), new Object[]{ node, leftOut }));
+ Set<IModelTransferNode> subUnits = findSubUnits(node, leftOut);
+ if(!subUnits.isEmpty()) {
+ diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, Activator.PLUGIN_ID, 0, NLS.bind("All controlled sub-units of {0} must be selected for {1}.", new Object[]{ node.getName(), direction }), new Object[]{ node, subUnits }));
+ } else {
+ int severity = direction.isImport() ? Diagnostic.INFO : Diagnostic.WARNING;
+ diagnostics.add(new BasicDiagnostic(severity, Activator.PLUGIN_ID, 0, NLS.bind(Messages.ModelTransferConfiguration_2, node.getName(), direction), new Object[]{ node, leftOut }));
+ }
+ }
+ }
+
+ private IModelTransferNode findParentUnit(IModelTransferNode node, Collection<? extends IModelTransferNode> possibleParents) {
+ IModelTransferNode result = null;
+
+ for(IModelTransferNode next : possibleParents) {
+ if(node.isModelParentUnit(next)) {
+ result = next;
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ private Set<IModelTransferNode> findSubUnits(IModelTransferNode node, Collection<? extends IModelTransferNode> possibleChildren) {
+ ImmutableSet.Builder<IModelTransferNode> result = ImmutableSet.builder();
+
+ for(IModelTransferNode next : possibleChildren) {
+ if(node.isModelSubUnit(next)) {
+ result.add(next);
+ }
}
+
+ return result.build();
}
public void addModelTransferListener(IModelTransferListener listener) {
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferNode.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferNode.java
index ee88f6fbd50..cb6e5692a36 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferNode.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.core/src/org/eclipse/papyrus/cdo/internal/core/importer/ModelTransferNode.java
@@ -19,8 +19,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.cdo.core.importer.IModelTransferNode;
import org.eclipse.papyrus.cdo.core.importer.IModelTransferOperation;
import org.eclipse.papyrus.cdo.internal.core.l10n.Messages;
@@ -144,7 +146,7 @@ public class ModelTransferNode implements IModelTransferNode {
}
}
- private void scanForDependencies() {
+ void scanForDependencies() {
// for each component resource, find the external resources that it
// references and, for any that seems to have a primary resource, get
// its node
@@ -174,4 +176,50 @@ public class ModelTransferNode implements IModelTransferNode {
return result;
}
+
+ public boolean isModelParentUnit(IModelTransferNode other) {
+ boolean result = false;
+
+ out: for(URI childURI : getResourceURIs()) {
+ Resource child = config.getResourceSet().getResource(childURI, false);
+ if(child != null) {
+ for(EObject root : child.getContents()) {
+ EObject container = root.eContainer();
+ if(container != null) {
+ URI uri = EcoreUtil.getURI(container).trimFragment();
+ if(other.getResourceURIs().contains(uri)) {
+ // found the parent unit
+ result = true;
+ break out;
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public boolean isModelSubUnit(IModelTransferNode other) {
+ boolean result = false;
+
+ out: for(URI uri : other.getResourceURIs()) {
+ Resource possibleChild = config.getResourceSet().getResource(uri, false);
+ if(possibleChild != null) {
+ for(EObject root : possibleChild.getContents()) {
+ EObject container = root.eContainer();
+ if(container != null) {
+ URI parentURI = EcoreUtil.getURI(container).trimFragment();
+ if(getResourceURIs().contains(parentURI)) {
+ // found a child unit
+ result = true;
+ break out;
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
}
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/wizards/ModelReferencesPage.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/wizards/ModelReferencesPage.java
index 1a2937c0019..125b628957f 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/wizards/ModelReferencesPage.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.ui/src/org/eclipse/papyrus/cdo/internal/ui/wizards/ModelReferencesPage.java
@@ -11,8 +11,11 @@
*****************************************************************************/
package org.eclipse.papyrus.cdo.internal.ui.wizards;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.Queue;
+import java.util.Set;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.jface.layout.GridDataFactory;
@@ -47,6 +50,7 @@ import org.eclipse.swt.widgets.Text;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
@@ -142,20 +146,7 @@ public class ModelReferencesPage extends ModelImportWizardPage {
if(configuration != null) {
// initialize the checkboxes
- Collection<IModelTransferNode> initialSet = configuration.getModelsToTransfer();
- ITreeContentProvider contents = (ITreeContentProvider)modelsTree.getContentProvider();
- ICheckable checkable = (ICheckable)modelsTree;
- for(Object next : contents.getElements(configuration)) {
- checkable.setChecked(next, true);
-
- for(Object child : contents.getChildren(next)) {
- ITreeNode treeNode = (ITreeNode)child;
- if((isImport ? treeNode.isDependent() : treeNode.isDependency()) || initialSet.contains(treeNode.getElement())) {
- checkable.setChecked(child, true);
- configuration.addModelToTransfer(treeNode.getElement().getPrimaryResourceURI());
- }
- }
- }
+ initializeCheckedNodes();
}
validatePage();
@@ -169,6 +160,50 @@ public class ModelReferencesPage extends ModelImportWizardPage {
super.dispose();
}
+ private void initializeCheckedNodes() {
+ final Collection<IModelTransferNode> initialSet = importConfig.getModelsToTransfer();
+ final ITreeContentProvider contents = (ITreeContentProvider)modelsTree.getContentProvider();
+ final ICheckable checkable = (ICheckable)modelsTree;
+
+ final Set<IModelTransferNode> visited = Sets.newHashSet();
+ final Queue<Object> queue = new java.util.ArrayDeque<Object>(Arrays.asList(contents.getElements(importConfig)));
+
+ for(Object next = queue.poll(); next != null; next = queue.poll()) {
+ ITreeNode parent = (ITreeNode)next;
+
+ // we must check a parent if the user initially selected it on opening the wizard
+ // or we are importing and it is a dependent of a checked node,
+ // or we are exporting and it is a dependency of a checked node,
+ // or it is a model sub-unit (required dependency) of a checked node
+ boolean mustCheck = initialSet.contains(parent.getElement());
+ if(mustCheck) {
+ checkable.setChecked(next, true);
+ }
+
+ if(visited.add(parent.getElement())) {
+ // recurse into the children
+ for(Object child : contents.getChildren(next)) {
+ ITreeNode treeNode = (ITreeNode)child;
+ queue.add(treeNode);
+
+ // we must check a node if either the user initially selected it on opening the wizard,
+ // or we are importing and it is a dependent of a checked node,
+ // or we are exporting and it is a dependency of a checked node,
+ // or it is a model sub-unit (required dependency) of a checked node
+ mustCheck = initialSet.contains(treeNode.getElement()) //
+ || (isImport ? treeNode.isDependent() : treeNode.isDependency()) //
+ || (checkable.getChecked(parent) && parent.getElement().isModelSubUnit(treeNode.getElement()));
+
+ if(mustCheck) {
+ checkable.setChecked(child, true);
+ importConfig.addModelToTransfer(treeNode.getElement().getPrimaryResourceURI());
+ }
+ }
+ }
+ }
+
+ }
+
void selected(Object treeNode) {
if(treeNode == null) {
pathText.setText(""); //$NON-NLS-1$
@@ -303,7 +338,6 @@ public class ModelReferencesPage extends ModelImportWizardPage {
}
TreeNode(TreeNode parent, IModelTransferNode element, boolean dependent) {
-
this.parent = parent;
this.element = element;
this.dependent = dependent;

Back to the top