Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2007-04-17 04:45:26 -0400
committerdstadnik2007-04-17 04:45:26 -0400
commit3e9d1be3c719caef18d6984823baf8c415ac9f04 (patch)
tree1848aa9ae2564dd8fc4058678f14d1597eda0c2b
parent59d4e2ac4661fbf8af57f0b68448529b5542a9d0 (diff)
downloadorg.eclipse.gmf-tooling-3e9d1be3c719caef18d6984823baf8c415ac9f04.tar.gz
org.eclipse.gmf-tooling-3e9d1be3c719caef18d6984823baf8c415ac9f04.tar.xz
org.eclipse.gmf-tooling-3e9d1be3c719caef18d6984823baf8c415ac9f04.zip
use enum for resolution
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DefinitionPage.java1
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelSource.java3
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelViewerFactory.java30
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/GraphDefBuilder.java1
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/Resolution.java45
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ResolvedItem.java6
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/StructureBuilder.java36
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ToolDefBuilder.java1
8 files changed, 58 insertions, 65 deletions
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DefinitionPage.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DefinitionPage.java
index c4a1fb5d3..daca8d017 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DefinitionPage.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DefinitionPage.java
@@ -14,6 +14,7 @@ package org.eclipse.gmf.internal.bridge.wizards.pages.simple;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.gmf.internal.bridge.ui.Plugin;
+import org.eclipse.gmf.internal.bridge.wizards.pages.simple.ResolvedItem.Resolution;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelSource.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelSource.java
index eefb6229f..3bd143b80 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelSource.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelSource.java
@@ -22,6 +22,9 @@ public interface DomainModelSource {
public EPackage getContents();
+ /**
+ * EClass mapped to diagram canvas.
+ */
public EClass getDiagramElement();
/**
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelViewerFactory.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelViewerFactory.java
index d7104ebea..82aaa0695 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelViewerFactory.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/DomainModelViewerFactory.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gmf.internal.bridge.ui.Plugin;
+import org.eclipse.gmf.internal.bridge.wizards.pages.simple.ResolvedItem.Resolution;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
@@ -35,16 +36,22 @@ import org.eclipse.swt.widgets.TreeItem;
*/
class DomainModelViewerFactory {
+ private static final String P_NODE = "Node"; //$NON-NLS-1$
+
+ private static final String P_LINK = "Link"; //$NON-NLS-1$
+
+ private static final String P_LABEL = "Label"; //$NON-NLS-1$
+
public static TreeViewer createViewer(Tree tree, boolean withLabes) {
TreeViewer viewer = new TreeViewer(tree);
viewer.setContentProvider(new ResolverContentProvider());
AdapterFactory adapterFactory = new EcoreItemProviderAdapterFactory();
viewer.setLabelProvider(new ResolverLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)));
if (withLabes) {
- viewer.setColumnProperties(new String[] { "no", Resolution.NODE.getName(), Resolution.LINK.getName(), Resolution.LABEL.getName() }); //$NON-NLS-1$
+ viewer.setColumnProperties(new String[] { "no", P_NODE, P_LINK, P_LABEL }); //$NON-NLS-1$
viewer.setCellEditors(new CellEditor[] { null, new CheckboxCellEditor(), new CheckboxCellEditor(), new CheckboxCellEditor() });
} else {
- viewer.setColumnProperties(new String[] { "no", Resolution.NODE.getName(), Resolution.LINK.getName() }); //$NON-NLS-1$
+ viewer.setColumnProperties(new String[] { "no", P_NODE, P_LINK }); //$NON-NLS-1$
viewer.setCellEditors(new CellEditor[] { null, new CheckboxCellEditor(), new CheckboxCellEditor() });
}
viewer.setCellModifier(new ResolverCellModifier(viewer, withLabes));
@@ -64,7 +71,7 @@ class DomainModelViewerFactory {
public Object getValue(Object element, String property) {
ResolvedItem item = (ResolvedItem) element;
- return Boolean.valueOf(item.getResolution() == Resolution.getByName(property));
+ return Boolean.valueOf(item.getResolution() == getResolution(property));
}
public boolean canModify(Object element, String property) {
@@ -74,17 +81,28 @@ class DomainModelViewerFactory {
public void modify(Object element, String property, Object value) {
ResolvedItem item = (ResolvedItem) ((TreeItem) element).getData();
- Resolution resolution = Resolution.getByName(property);
+ Resolution resolution = getResolution(property);
if (!item.isPossibleResolution(resolution)) {
return;
}
item.setResolution(((Boolean) value).booleanValue() ? resolution : null);
if (withLabels) {
- viewer.update(item, new String[] { Resolution.NODE.getName(), Resolution.LINK.getName(), Resolution.LABEL.getName() });
+ viewer.update(item, new String[] { P_NODE, P_LINK, P_LABEL });
} else {
- viewer.update(item, new String[] { Resolution.NODE.getName(), Resolution.LINK.getName() });
+ viewer.update(item, new String[] { P_NODE, P_LINK });
}
}
+
+ private Resolution getResolution(String property) {
+ if (P_NODE.equals(property)) {
+ return Resolution.NODE;
+ } else if (P_LINK.equals(property)) {
+ return Resolution.LINK;
+ } else if (P_LABEL.equals(property)) {
+ return Resolution.LABEL;
+ }
+ return null;
+ }
}
private static class ResolverContentProvider implements ITreeContentProvider {
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/GraphDefBuilder.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/GraphDefBuilder.java
index aec0fdcb7..100711b68 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/GraphDefBuilder.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/GraphDefBuilder.java
@@ -33,6 +33,7 @@ import org.eclipse.gmf.gmfgraph.Node;
import org.eclipse.gmf.gmfgraph.PolylineConnection;
import org.eclipse.gmf.gmfgraph.Rectangle;
import org.eclipse.gmf.internal.bridge.wizards.WizardUtil;
+import org.eclipse.gmf.internal.bridge.wizards.pages.simple.ResolvedItem.Resolution;
import org.eclipse.gmf.internal.common.IncrementalNamesDispenser;
import org.eclipse.gmf.internal.common.NamesDispenser;
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/Resolution.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/Resolution.java
deleted file mode 100644
index aeb5b1122..000000000
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/Resolution.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2006 Eclipse.org
- *
- * 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:
- * Dmitry Stadnik - initial API and implementation
- */
-package org.eclipse.gmf.internal.bridge.wizards.pages.simple;
-
-/**
- * @author dstadnik
- */
-public class Resolution {
-
- public static final Resolution NODE = new Resolution("Node"); //$NON-NLS-1$
-
- public static final Resolution LINK = new Resolution("Link"); //$NON-NLS-1$
-
- public static final Resolution LABEL = new Resolution("Label"); //$NON-NLS-1$
-
- private final String name;
-
- private Resolution(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public static Resolution getByName(String name) {
- if (NODE.name.equals(name)) {
- return NODE;
- } else if (LINK.name.equals(name)) {
- return LINK;
- } else if (LABEL.name.equals(name)) {
- return LABEL;
- }
- return null;
- }
-}
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ResolvedItem.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ResolvedItem.java
index ce56dcc11..db55c8761 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ResolvedItem.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ResolvedItem.java
@@ -21,6 +21,12 @@ import org.eclipse.gmf.internal.bridge.resolver.TypePattern;
*/
public class ResolvedItem {
+ public enum Resolution {
+ NODE,
+ LINK,
+ LABEL
+ }
+
public static final Resolution[] NO_RESOLUTIONS = { null };
public static final Resolution[] ALL_RESOLUTIONS = { null, Resolution.NODE, Resolution.LINK, Resolution.LABEL };
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/StructureBuilder.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/StructureBuilder.java
index 14b6c943a..ac05d809c 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/StructureBuilder.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/StructureBuilder.java
@@ -28,6 +28,7 @@ import org.eclipse.gmf.internal.bridge.resolver.StructureResolver;
import org.eclipse.gmf.internal.bridge.resolver.TypeLinkPattern;
import org.eclipse.gmf.internal.bridge.resolver.TypePattern;
import org.eclipse.gmf.internal.bridge.ui.Plugin;
+import org.eclipse.gmf.internal.bridge.wizards.pages.simple.ResolvedItem.Resolution;
/**
* @author dstadnik
@@ -50,8 +51,11 @@ public class StructureBuilder {
return withLabels;
}
+ /**
+ * Entry point to the structure builder. It walks over the domain model and builds resolutions tree.
+ */
public ResolvedItem process(DomainModelSource dms) {
- ResolvedItem item = new ResolvedItem(null, dms.getContents(), null, ResolvedItem.NO_RESOLUTIONS, false);
+ ResolvedItem item = new ResolvedItem(null, dms.getContents(), null, ResolvedItem.NO_RESOLUTIONS, false); // root of the resolutions tree
for (Iterator<EObject> it = dms.getContents().eAllContents(); it.hasNext();) {
EObject next = it.next();
if (next instanceof EClass) {
@@ -62,25 +66,27 @@ public class StructureBuilder {
}
protected ResolvedItem process(EClass domainClass, DomainModelSource dms) {
- final EClass diagramClass = dms.getDiagramElement();
+ final EClass diagramClass = dms.getDiagramElement(); // containment root of diagram elements
final EPackage domainPackage = dms.getContents();
Resolution resolution;
- Resolution[] resolutions = ResolvedItem.NODE_LINK_RESOLUTIONS;
+ Resolution[] resolutions = ResolvedItem.NODE_LINK_RESOLUTIONS; // class may be resolved only as node or link
TypePattern pattern = resolver.resolve(domainClass, domainPackage);
if (pattern instanceof NodePattern) {
resolution = Resolution.NODE;
if (diagramClass != null && !containmentClosure.contains(diagramClass, domainClass, domainPackage)) {
- resolution = null;
+ resolution = null; // class is not in diagram containment hierarchy
}
} else if (pattern instanceof TypeLinkPattern) {
resolution = Resolution.LINK;
if (diagramClass != null) {
TypeLinkPattern linkPattern = (TypeLinkPattern) pattern;
- if (linkPattern.getSource() != null && !containmentClosure.contains(diagramClass, linkPattern.getSource().getEReferenceType(), domainPackage)) {
- resolution = null;
+ if (linkPattern.getSource() != null &&
+ !containmentClosure.contains(diagramClass, linkPattern.getSource().getEReferenceType(), domainPackage)) {
+ resolution = null; // source is not in diagram containment hierarchy
}
- if (linkPattern.getTarget() != null && !containmentClosure.contains(diagramClass, linkPattern.getTarget().getEReferenceType(), domainPackage)) {
- resolution = null;
+ if (linkPattern.getTarget() != null &&
+ !containmentClosure.contains(diagramClass, linkPattern.getTarget().getEReferenceType(), domainPackage)) {
+ resolution = null; // target is not in diagram containment hierarchy
}
}
} else {
@@ -99,27 +105,29 @@ public class StructureBuilder {
if (!withLabels) {
return;
}
- Resolution baseResolution = typeItem.getResolution() == null ? null : Resolution.LABEL;
+ Resolution baseResolution = typeItem.getResolution() == null ? null : Resolution.LABEL; // exclude label if parent is excluded
Collection<EAttribute> resolvedAttrs = Collections.emptyList();
if (typeItem.getPattern() != null) {
resolvedAttrs = Arrays.asList(typeItem.getPattern().getLabels());
}
- Resolution[] possibleResolutions = Arrays.equals(typeItem.getPossibleResolutions(), ResolvedItem.NO_RESOLUTIONS) ? ResolvedItem.NO_RESOLUTIONS : ResolvedItem.LABEL_RESOLUTIONS;
+ Resolution[] possibleResolutions = Arrays.equals(typeItem.getPossibleResolutions(), ResolvedItem.NO_RESOLUTIONS) ?
+ ResolvedItem.NO_RESOLUTIONS : ResolvedItem.LABEL_RESOLUTIONS; // exclude label if parent is excluded
for (EAttribute attribute : (List<? extends EAttribute>) type.getEAllAttributes()) {
- Resolution resolution = resolvedAttrs.contains(attribute) ? baseResolution : null;
+ Resolution resolution = resolvedAttrs.contains(attribute) ? baseResolution : null; // include only attributes resolved as labels
typeItem.addChild(new ResolvedItem(resolution, attribute, null, possibleResolutions, dms.isDisabled(attribute)));
}
}
protected void addRefLinks(ResolvedItem typeItem, EClass type, DomainModelSource dms) {
- Resolution baseResolution = typeItem.getResolution() != Resolution.NODE ? null : Resolution.LINK;
+ Resolution baseResolution = typeItem.getResolution() != Resolution.NODE ? null : Resolution.LINK; // ref links are available only for nodes
Collection<EReference> resolvedRefs = Collections.emptyList();
if (typeItem.getPattern() instanceof NodePattern) {
resolvedRefs = Arrays.asList(((NodePattern) typeItem.getPattern()).getRefLinks());
}
- Resolution[] possibleResolutions = Arrays.equals(typeItem.getPossibleResolutions(), ResolvedItem.NO_RESOLUTIONS) ? ResolvedItem.NO_RESOLUTIONS : ResolvedItem.LINK_RESOLUTIONS;
+ Resolution[] possibleResolutions = Arrays.equals(typeItem.getPossibleResolutions(), ResolvedItem.NO_RESOLUTIONS) ?
+ ResolvedItem.NO_RESOLUTIONS : ResolvedItem.LINK_RESOLUTIONS; // exclude link if parent is excluded
for (EReference reference : (List<? extends EReference>) type.getEAllReferences()) {
- Resolution resolution = resolvedRefs.contains(reference) ? baseResolution : null;
+ Resolution resolution = resolvedRefs.contains(reference) ? baseResolution : null; // include only refs resolved as links
typeItem.addChild(new ResolvedItem(resolution, reference, null, possibleResolutions, dms.isDisabled(reference)));
}
}
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ToolDefBuilder.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ToolDefBuilder.java
index b1236f084..bec94a6c2 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ToolDefBuilder.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/wizards/pages/simple/ToolDefBuilder.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.internal.bridge.wizards.WizardUtil;
+import org.eclipse.gmf.internal.bridge.wizards.pages.simple.ResolvedItem.Resolution;
import org.eclipse.gmf.internal.common.IncrementalNamesDispenser;
import org.eclipse.gmf.internal.common.NamesDispenser;
import org.eclipse.gmf.tooldef.AbstractTool;

Back to the top