diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse')
23 files changed, 3826 insertions, 3826 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/Activator.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/Activator.java index 47bfe130b5..8e65c4d311 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/Activator.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/Activator.java @@ -1,48 +1,48 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf;
-
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Martin Fluegge
- */
-public class Activator extends AbstractUIPlugin
-{
- public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.gmf"; //$NON-NLS-1$
-
- private static Activator plugin;
-
- public Activator()
- {
- }
-
- @Override
- public void start(BundleContext context) throws Exception
- {
- super.start(context);
- plugin = this;
- }
-
- @Override
- public void stop(BundleContext context) throws Exception
- {
- plugin = null;
- super.stop(context);
- }
-
- public static Activator getDefault()
- {
- return plugin;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf; + +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import org.osgi.framework.BundleContext; + +/** + * @author Martin Fluegge + */ +public class Activator extends AbstractUIPlugin +{ + public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.gmf"; //$NON-NLS-1$ + + private static Activator plugin; + + public Activator() + { + } + + @Override + public void start(BundleContext context) throws Exception + { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception + { + plugin = null; + super.stop(context); + } + + public static Activator getDefault() + { + return plugin; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java index e0bb80736e..bbbea2c18d 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnAppearancer.java @@ -1,97 +1,97 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance;
-
-import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
-import org.eclipse.emf.cdo.dawn.helper.DawnEditorHelper;
-import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.util.EditPartUtilities;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- */
-public class DawnAppearancer
-{
- public static final int DEFAULT_BORDER_THICKNESS = 2;
-
- public static final int DEFAULT_LINE_THICKNESS = 3;
-
- public static final int TYPE_CONFLICT_NONE = -1;
-
- public static final int TYPE_CONFLICT_LOCALLY_DELETED = 0;
-
- public static final int TYPE_CONFLICT_REMOTELY_DELETED = 1;
-
- public static final int TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED = 2;
-
- public static final int TYPE_LOCKED_LOCALLY = 3;
-
- public static final int TYPE_LOCKED_GLOBALLY = 4;
-
- /**
- * @since 2.0
- */
- public static void setEditPartConflicted(EditPart editPart, int type)
- {
- DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
- if (stylizer != null)
- {
- stylizer.setConflicted(editPart, type);
- }
- }
-
- /**
- * @since 2.0
- */
- public static void setEditPartDefaultAllChildren(EditPart editPart)
- {
- setEditPartDefault(editPart);
-
- for (Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)editPart))
- {
- setEditPartDefaultAllChildren((EditPart)child);
- }
- }
-
- /**
- * @since 2.0
- */
- public static void setEditPartDefault(EditPart editPart)
- {
- DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
- if (stylizer != null)
- {
- stylizer.setDefault(editPart);
- }
- }
-
- /**
- * @since 2.0
- */
- public static void setEditPartLocked(final EditPart editPart, final int type)
- {
- final DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
- if (stylizer != null)
- {
- DawnEditorHelper.getDisplay().syncExec(new Runnable()
- {
- public void run()
- {
- stylizer.setLocked(editPart, type);
- }
- });
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance; + +import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer; +import org.eclipse.emf.cdo.dawn.helper.DawnEditorHelper; +import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.util.EditPartUtilities; + +/** + * @author Martin Fluegge + * @since 2.0 + */ +public class DawnAppearancer +{ + public static final int DEFAULT_BORDER_THICKNESS = 2; + + public static final int DEFAULT_LINE_THICKNESS = 3; + + public static final int TYPE_CONFLICT_NONE = -1; + + public static final int TYPE_CONFLICT_LOCALLY_DELETED = 0; + + public static final int TYPE_CONFLICT_REMOTELY_DELETED = 1; + + public static final int TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED = 2; + + public static final int TYPE_LOCKED_LOCALLY = 3; + + public static final int TYPE_LOCKED_GLOBALLY = 4; + + /** + * @since 2.0 + */ + public static void setEditPartConflicted(EditPart editPart, int type) + { + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setConflicted(editPart, type); + } + } + + /** + * @since 2.0 + */ + public static void setEditPartDefaultAllChildren(EditPart editPart) + { + setEditPartDefault(editPart); + + for (Object child : EditPartUtilities.getAllChildren((GraphicalEditPart)editPart)) + { + setEditPartDefaultAllChildren((EditPart)child); + } + } + + /** + * @since 2.0 + */ + public static void setEditPartDefault(EditPart editPart) + { + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setDefault(editPart); + } + } + + /** + * @since 2.0 + */ + public static void setEditPartLocked(final EditPart editPart, final int type) + { + final DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + DawnEditorHelper.getDisplay().syncExec(new Runnable() + { + public void run() + { + stylizer.setLocked(editPart, type); + } + }); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizer.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizer.java index fae55d139c..e614c3b0e4 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizer.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizer.java @@ -1,60 +1,60 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance;
-
-import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnDefaultElementStylizer;
-
-import org.eclipse.gef.EditPart;
-
-/**
- * An EditPartStylizer can influence the visual representation of the models state. Dawn knows three states - default,
- * conflicted and locked. By implementing an own DawnStylizer you can influence the appearance of the three states for
- * your EditPart and it's related models. New stylizer can be registered to Dawn using the
- * <b>org.eclipse.emf.cdo.dawn.editpartstylizers</b> extension point.
- *
- * @author Martin Fluegge
- * @since 2.0
- */
-public abstract class DawnEditPartStylizer extends DawnDefaultElementStylizer
-{
- /**
- * @since 2.0
- */
- public abstract void setDefault(EditPart editPart);
-
- /**
- * @since 2.0
- */
- public abstract void setConflicted(EditPart editPart, int type);
-
- /**
- * @since 2.0
- */
- public abstract void setLocked(EditPart editPart, int type);
-
- @Override
- public void setDefault(Object element)
- {
- setDefault((EditPart)element);
- }
-
- @Override
- public void setConflicted(Object element, int type)
- {
- setConflicted((EditPart)element, type);
- }
-
- @Override
- public void setLocked(Object element, int type)
- {
- setLocked((EditPart)element, type);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance; + +import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnDefaultElementStylizer; + +import org.eclipse.gef.EditPart; + +/** + * An EditPartStylizer can influence the visual representation of the models state. Dawn knows three states - default, + * conflicted and locked. By implementing an own DawnStylizer you can influence the appearance of the three states for + * your EditPart and it's related models. New stylizer can be registered to Dawn using the + * <b>org.eclipse.emf.cdo.dawn.editpartstylizers</b> extension point. + * + * @author Martin Fluegge + * @since 2.0 + */ +public abstract class DawnEditPartStylizer extends DawnDefaultElementStylizer +{ + /** + * @since 2.0 + */ + public abstract void setDefault(EditPart editPart); + + /** + * @since 2.0 + */ + public abstract void setConflicted(EditPart editPart, int type); + + /** + * @since 2.0 + */ + public abstract void setLocked(EditPart editPart, int type); + + @Override + public void setDefault(Object element) + { + setDefault((EditPart)element); + } + + @Override + public void setConflicted(Object element, int type) + { + setConflicted((EditPart)element, type); + } + + @Override + public void setLocked(Object element, int type) + { + setLocked((EditPart)element, type); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizerRegistry.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizerRegistry.java index 07aa4295d0..508fcbfcfa 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizerRegistry.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/DawnEditPartStylizerRegistry.java @@ -1,130 +1,130 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicConnectionEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicGraphicalEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicNodeEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicTextAwareEditPartStylizerImpl;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.InvalidRegistryObjectException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.NodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- * @deprecated
- */
-@Deprecated
-public class DawnEditPartStylizerRegistry
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnEditPartStylizerRegistry.class);
-
- private static final String DAWN_STYLIZER_EXTENSION_POINT_ID = "org.eclipse.emf.cdo.dawn.editpartstylizers";
-
- public static DawnEditPartStylizerRegistry instance = new DawnEditPartStylizerRegistry();
-
- private Map<String, DawnEditPartStylizer> registeredStylizers = new HashMap<String, DawnEditPartStylizer>();
-
- /**
- * @since 2.0
- */
- public DawnEditPartStylizer getStylizer(EditPart editPart)
- {
- DawnEditPartStylizer stylizer = registeredStylizers.get(editPart.getClass().getCanonicalName());
-
- if (stylizer == null)
- {
- stylizer = getStylizerFromExtensionPoint(editPart);
- }
-
- if (stylizer == null)
- {
- stylizer = getDefaultStylizer(editPart);
- }
-
- return stylizer;
- }
-
- private DawnEditPartStylizer getDefaultStylizer(EditPart editPart)
- {
- DawnEditPartStylizer stylizer = null;
- if (editPart instanceof ConnectionEditPart)
- {
- stylizer = new DawnBasicConnectionEditPartStylizerImpl();
- }
- else if (editPart instanceof NodeEditPart)
- {
- stylizer = new DawnBasicNodeEditPartStylizerImpl();
- }
- else if (editPart instanceof DiagramEditPart)
- {
- stylizer = new DawnBasicNodeEditPartStylizerImpl();
- }
- else if (editPart instanceof ITextAwareEditPart)
- {
- stylizer = new DawnBasicTextAwareEditPartStylizerImpl();
- }
- else
- {
- // In the case that there is no match we use a simple border styled stylizer.
- stylizer = new DawnBasicGraphicalEditPartStylizerImpl();
- }
-
- return stylizer;
- }
-
- private DawnEditPartStylizer getStylizerFromExtensionPoint(EditPart editPart)
- {
- try
- {
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
- DAWN_STYLIZER_EXTENSION_POINT_ID);
- for (IConfigurationElement e : config)
- {
- if (editPart.getClass().getCanonicalName().equals(e.getAttribute("editpart")))
- {
- DawnEditPartStylizer stylizer = (DawnEditPartStylizer)e.createExecutableExtension("stylizer");
- registeredStylizers.put(editPart.getClass().getCanonicalName(), stylizer);
- if (TRACER.isEnabled())
- {
- TRACER.format("Registered DawnEditPartStylizer {0} ", stylizer); //$NON-NLS-1$
- }
-
- return stylizer;
- }
- }
- }
- catch (InvalidRegistryObjectException e1)
- {
- e1.printStackTrace();
- }
- catch (CoreException e)
- {
- e.printStackTrace();
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicConnectionEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicGraphicalEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicNodeEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicTextAwareEditPartStylizerImpl; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.InvalidRegistryObjectException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.NodeEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Martin Fluegge + * @since 2.0 + * @deprecated + */ +@Deprecated +public class DawnEditPartStylizerRegistry +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnEditPartStylizerRegistry.class); + + private static final String DAWN_STYLIZER_EXTENSION_POINT_ID = "org.eclipse.emf.cdo.dawn.editpartstylizers"; + + public static DawnEditPartStylizerRegistry instance = new DawnEditPartStylizerRegistry(); + + private Map<String, DawnEditPartStylizer> registeredStylizers = new HashMap<String, DawnEditPartStylizer>(); + + /** + * @since 2.0 + */ + public DawnEditPartStylizer getStylizer(EditPart editPart) + { + DawnEditPartStylizer stylizer = registeredStylizers.get(editPart.getClass().getCanonicalName()); + + if (stylizer == null) + { + stylizer = getStylizerFromExtensionPoint(editPart); + } + + if (stylizer == null) + { + stylizer = getDefaultStylizer(editPart); + } + + return stylizer; + } + + private DawnEditPartStylizer getDefaultStylizer(EditPart editPart) + { + DawnEditPartStylizer stylizer = null; + if (editPart instanceof ConnectionEditPart) + { + stylizer = new DawnBasicConnectionEditPartStylizerImpl(); + } + else if (editPart instanceof NodeEditPart) + { + stylizer = new DawnBasicNodeEditPartStylizerImpl(); + } + else if (editPart instanceof DiagramEditPart) + { + stylizer = new DawnBasicNodeEditPartStylizerImpl(); + } + else if (editPart instanceof ITextAwareEditPart) + { + stylizer = new DawnBasicTextAwareEditPartStylizerImpl(); + } + else + { + // In the case that there is no match we use a simple border styled stylizer. + stylizer = new DawnBasicGraphicalEditPartStylizerImpl(); + } + + return stylizer; + } + + private DawnEditPartStylizer getStylizerFromExtensionPoint(EditPart editPart) + { + try + { + IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor( + DAWN_STYLIZER_EXTENSION_POINT_ID); + for (IConfigurationElement e : config) + { + if (editPart.getClass().getCanonicalName().equals(e.getAttribute("editpart"))) + { + DawnEditPartStylizer stylizer = (DawnEditPartStylizer)e.createExecutableExtension("stylizer"); + registeredStylizers.put(editPart.getClass().getCanonicalName(), stylizer); + if (TRACER.isEnabled()) + { + TRACER.format("Registered DawnEditPartStylizer {0} ", stylizer); //$NON-NLS-1$ + } + + return stylizer; + } + } + } + catch (InvalidRegistryObjectException e1) + { + e1.printStackTrace(); + } + catch (CoreException e) + { + e.printStackTrace(); + } + + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java index 9a230fd0be..d2c2bf71e4 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicConnectionEditPartStylizerImpl.java @@ -1,123 +1,123 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer;
-import org.eclipse.emf.cdo.dawn.spi.DawnState;
-import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
-
-import org.eclipse.emf.workspace.AbstractEMFOperation;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.util.StringStatics;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.ChangePropertyValueRequest;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
-import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.swt.graphics.Color;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- */
-public class DawnBasicConnectionEditPartStylizerImpl extends DawnEditPartStylizer
-{
-
- /**
- * @since 2.0
- */
- @Override
- public void setDefault(EditPart editPart)
- {
- setEdge(editPart, DawnColorConstants.COLOR_NO_CONFLICT);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setConflicted(EditPart editPart, int type)
- {
- // Color color = DawnColorConstants.COLOR_DELETE_CONFLICT;
- Color color = getForegroundColor(editPart, DawnState.CONFLICT);
- setEdge(editPart, color);
- }
-
- /**
- * @since 2.0
- */
- private void setEdge(EditPart editPart, Color color)
- {
- ChangePropertyValueRequest request = new ChangePropertyValueRequest(StringStatics.BLANK,
- PackageUtil.getID(NotationPackage.eINSTANCE.getLineStyle_LineColor()), FigureUtilities.colorToInteger(color));
- final Command command = editPart.getCommand(request);
-
- AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(),
- StringStatics.BLANK, null)
- {
- @Override
- protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
- {
- command.execute();
- return Status.OK_STATUS;
- }
- };
-
- try
- {
- operation.execute(new NullProgressMonitor(), null);
- }
- catch (ExecutionException e)
- {
- }
-
- editPart.refresh();
- editPart.getRoot().refresh();
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setLocked(EditPart editPart, int type)
- {
- Color color = null;
- switch (type)
- {
- case DawnAppearancer.TYPE_LOCKED_LOCALLY:
- {
- color = getBackgroundColor(editPart, DawnState.LOCKED_LOCALLY);
- break;
- }
- case DawnAppearancer.TYPE_LOCKED_GLOBALLY:
- {
- color = getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY);
- break;
- }
-
- default:
- break;
- }
- if (color != null)
- {
- setEdge(editPart, color);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer; +import org.eclipse.emf.cdo.dawn.spi.DawnState; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; + +import org.eclipse.emf.workspace.AbstractEMFOperation; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.util.StringStatics; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.requests.ChangePropertyValueRequest; +import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; +import org.eclipse.gmf.runtime.emf.core.util.PackageUtil; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.swt.graphics.Color; + +/** + * @author Martin Fluegge + * @since 2.0 + */ +public class DawnBasicConnectionEditPartStylizerImpl extends DawnEditPartStylizer +{ + + /** + * @since 2.0 + */ + @Override + public void setDefault(EditPart editPart) + { + setEdge(editPart, DawnColorConstants.COLOR_NO_CONFLICT); + } + + /** + * @since 2.0 + */ + @Override + public void setConflicted(EditPart editPart, int type) + { + // Color color = DawnColorConstants.COLOR_DELETE_CONFLICT; + Color color = getForegroundColor(editPart, DawnState.CONFLICT); + setEdge(editPart, color); + } + + /** + * @since 2.0 + */ + private void setEdge(EditPart editPart, Color color) + { + ChangePropertyValueRequest request = new ChangePropertyValueRequest(StringStatics.BLANK, + PackageUtil.getID(NotationPackage.eINSTANCE.getLineStyle_LineColor()), FigureUtilities.colorToInteger(color)); + final Command command = editPart.getCommand(request); + + AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart)editPart).getEditingDomain(), + StringStatics.BLANK, null) + { + @Override + protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException + { + command.execute(); + return Status.OK_STATUS; + } + }; + + try + { + operation.execute(new NullProgressMonitor(), null); + } + catch (ExecutionException e) + { + } + + editPart.refresh(); + editPart.getRoot().refresh(); + } + + /** + * @since 2.0 + */ + @Override + public void setLocked(EditPart editPart, int type) + { + Color color = null; + switch (type) + { + case DawnAppearancer.TYPE_LOCKED_LOCALLY: + { + color = getBackgroundColor(editPart, DawnState.LOCKED_LOCALLY); + break; + } + case DawnAppearancer.TYPE_LOCKED_GLOBALLY: + { + color = getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY); + break; + } + + default: + break; + } + if (color != null) + { + setEdge(editPart, color); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicDiagramStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicDiagramStylizerImpl.java index 0661e9fb80..c24bbc5b3e 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicDiagramStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicDiagramStylizerImpl.java @@ -1,46 +1,46 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer;
-
-import org.eclipse.gef.EditPart;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- */
-public class DawnBasicDiagramStylizerImpl extends DawnEditPartStylizer
-{
- /**
- * @since 2.0
- */
- @Override
- public void setDefault(EditPart editpart)
- {
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setConflicted(EditPart editpart, int type)
- {
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setLocked(EditPart editpart, int type)
- {
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer; + +import org.eclipse.gef.EditPart; + +/** + * @author Martin Fluegge + * @since 2.0 + */ +public class DawnBasicDiagramStylizerImpl extends DawnEditPartStylizer +{ + /** + * @since 2.0 + */ + @Override + public void setDefault(EditPart editpart) + { + } + + /** + * @since 2.0 + */ + @Override + public void setConflicted(EditPart editpart, int type) + { + } + + /** + * @since 2.0 + */ + @Override + public void setLocked(EditPart editpart, int type) + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java index c64f62c1d6..aee8c949f0 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicGraphicalEditPartStylizerImpl.java @@ -1,79 +1,79 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer;
-import org.eclipse.emf.cdo.dawn.spi.DawnState;
-
-import org.eclipse.draw2d.Border;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.swt.graphics.Color;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- */
-
-public class DawnBasicGraphicalEditPartStylizerImpl extends DawnEditPartStylizer
-{
- /**
- * @since 2.0
- */
- @Override
- public void setDefault(EditPart editPart)
- {
- setBorder(editPart, null);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setConflicted(EditPart editPart, int type)
- {
- setBorder(editPart, getForegroundColor(editPart, DawnState.CONFLICT), DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void setLocked(EditPart editPart, int type)
- {
- setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY),
- DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
-
- /**
- * @since 2.0
- */
- protected void setBorder(EditPart editPart, Color color, int thickness)
- {
- Border thickBorder = new LineBorder(color, thickness);
- setBorder(editPart, thickBorder);
- }
-
- /**
- * @since 2.0
- */
- protected void setBorder(EditPart editPart, Border border)
- {
- GraphicalEditPart e = (GraphicalEditPart)editPart;
-
- IFigure figure = e.getFigure();
- figure.setBorder(border);
- editPart.refresh();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnEditPartStylizer; +import org.eclipse.emf.cdo.dawn.spi.DawnState; + +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LineBorder; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.swt.graphics.Color; + +/** + * @author Martin Fluegge + * @since 2.0 + */ + +public class DawnBasicGraphicalEditPartStylizerImpl extends DawnEditPartStylizer +{ + /** + * @since 2.0 + */ + @Override + public void setDefault(EditPart editPart) + { + setBorder(editPart, null); + } + + /** + * @since 2.0 + */ + @Override + public void setConflicted(EditPart editPart, int type) + { + setBorder(editPart, getForegroundColor(editPart, DawnState.CONFLICT), DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } + + /** + * @since 2.0 + */ + @Override + public void setLocked(EditPart editPart, int type) + { + setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY), + DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } + + /** + * @since 2.0 + */ + protected void setBorder(EditPart editPart, Color color, int thickness) + { + Border thickBorder = new LineBorder(color, thickness); + setBorder(editPart, thickBorder); + } + + /** + * @since 2.0 + */ + protected void setBorder(EditPart editPart, Border border) + { + GraphicalEditPart e = (GraphicalEditPart)editPart; + + IFigure figure = e.getFigure(); + figure.setBorder(border); + editPart.refresh(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java index e317cd13fd..a6481d0177 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicNodeEditPartStylizerImpl.java @@ -1,56 +1,56 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.spi.DawnState;
-import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
-
-import org.eclipse.gef.EditPart;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnBasicNodeEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl
-{
-
- @Override
- public void setDefault(EditPart editPart)
- {
- setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0);
- }
-
- // @Override
- // public void setConflicted(EditPart editPart, int type)
- // {
- // setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- // }
-
- @Override
- public void setLocked(EditPart editPart, int type)
- {
- switch (type)
- {
- case DawnAppearancer.TYPE_LOCKED_GLOBALLY:
- {
- setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY),
- DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- break;
- }
- case DawnAppearancer.TYPE_LOCKED_LOCALLY:
- {
- setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_LOCALLY),
- DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- break;
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.spi.DawnState; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; + +import org.eclipse.gef.EditPart; + +/** + * @author Martin Fluegge + */ +public class DawnBasicNodeEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl +{ + + @Override + public void setDefault(EditPart editPart) + { + setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0); + } + + // @Override + // public void setConflicted(EditPart editPart, int type) + // { + // setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + // } + + @Override + public void setLocked(EditPart editPart, int type) + { + switch (type) + { + case DawnAppearancer.TYPE_LOCKED_GLOBALLY: + { + setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_REMOTELY), + DawnAppearancer.DEFAULT_BORDER_THICKNESS); + break; + } + case DawnAppearancer.TYPE_LOCKED_LOCALLY: + { + setBorder(editPart, getBackgroundColor(editPart, DawnState.LOCKED_LOCALLY), + DawnAppearancer.DEFAULT_BORDER_THICKNESS); + break; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java index 6a807a6ff8..0469273056 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBasicTextAwareEditPartStylizerImpl.java @@ -1,65 +1,65 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
-
-import org.eclipse.draw2d.Border;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnBasicTextAwareEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl
-{
-
- Map<EditPart, Border> oldValues = new HashMap<EditPart, Border>();
-
- @Override
- public void setDefault(EditPart editPart)
- {
- setBorder(editPart, oldValues.get(editPart));
- }
-
- @Override
- public void setConflicted(EditPart editPart, int type)
- {
- final IGraphicalEditPart e = (IGraphicalEditPart)editPart;
-
- // TODO Setting the foreground color just works until the EditPart is refreshed and the default color is used again.
- // Find a better way to handle this.
- // e.getFigure().setForegroundColor(DawnAppearancer.COLOR_DELETE_CONFLICT);
- oldValues.put(e, e.getFigure().getBorder());
-
- setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- // View view = (View)e.getModel();
- // FontStyle style = (FontStyle)view.getStyle(NotationPackage.eINSTANCE.getFontStyle());
- // if (style == null)
- // {
- // style = NotationFactory.eINSTANCE.createFontStyle();
- // style.setFontColor(FigureUtilities.colorToInteger(DiagramColorConstants.red));
- // style.setBold(true);
- //
- // view.getStyles().add(style);
- // }
- }
-
- @Override
- public void setLocked(EditPart editPart, int type)
- {
- setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; + +import org.eclipse.draw2d.Border; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Martin Fluegge + */ +public class DawnBasicTextAwareEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl +{ + + Map<EditPart, Border> oldValues = new HashMap<EditPart, Border>(); + + @Override + public void setDefault(EditPart editPart) + { + setBorder(editPart, oldValues.get(editPart)); + } + + @Override + public void setConflicted(EditPart editPart, int type) + { + final IGraphicalEditPart e = (IGraphicalEditPart)editPart; + + // TODO Setting the foreground color just works until the EditPart is refreshed and the default color is used again. + // Find a better way to handle this. + // e.getFigure().setForegroundColor(DawnAppearancer.COLOR_DELETE_CONFLICT); + oldValues.put(e, e.getFigure().getBorder()); + + setBorder(editPart, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + // View view = (View)e.getModel(); + // FontStyle style = (FontStyle)view.getStyle(NotationPackage.eINSTANCE.getFontStyle()); + // if (style == null) + // { + // style = NotationFactory.eINSTANCE.createFontStyle(); + // style.setFontColor(FigureUtilities.colorToInteger(DiagramColorConstants.red)); + // style.setBold(true); + // + // view.getStyles().add(style); + // } + } + + @Override + public void setLocked(EditPart editPart, int type) + { + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java index 40152b9548..d79bd57249 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/appearance/impl/DawnBlinkingNodeEditPartStylizerImpl.java @@ -1,105 +1,105 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.appearance.impl;
-
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
-
-import org.eclipse.gef.EditPart;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- * @since 2.0
- */
-public class DawnBlinkingNodeEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl
-{
- BlinkingThread blinkingThread;
-
- public DawnBlinkingNodeEditPartStylizerImpl()
- {
- blinkingThread = new BlinkingThread();
- blinkingThread.start();
- }
-
- @Override
- public void setDefault(EditPart editPart)
- {
- blinkingThread.stop(editPart);
- setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0);
- }
-
- @Override
- public void setConflicted(EditPart editPart, int type)
- {
- blinkingThread.start(editPart);
- }
-
- @Override
- public void setLocked(EditPart editPart, int type)
- {
- setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
-
- /**
- * @author Martin Fluegge
- * @since 2.0
- */
- protected class BlinkingThread extends Thread
- {
-
- Map<EditPart, Boolean> editParts = new HashMap<EditPart, Boolean>();
-
- @Override
- public void run()
- {
- while (true)
- {
- for (EditPart e : editParts.keySet())
- {
- if (editParts.get(e))
- {
- setBorder(e, DawnColorConstants.COLOR_NO_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
- else
- {
- setBorder(e, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS);
- }
-
- editParts.put(e, !editParts.get(e));
- }
- try
- {
- Thread.sleep(500);
- }
- catch (InterruptedException e1)
- {
- e1.printStackTrace();
- }
- }
- }
-
- /**
- * @since 2.0
- */
- public void start(EditPart editPart)
- {
- editParts.put(editPart, true);
- }
-
- public void stop(EditPart editPart)
- {
- editParts.remove(editPart);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.appearance.impl; + +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants; + +import org.eclipse.gef.EditPart; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Martin Fluegge + * @since 2.0 + */ +public class DawnBlinkingNodeEditPartStylizerImpl extends DawnBasicGraphicalEditPartStylizerImpl +{ + BlinkingThread blinkingThread; + + public DawnBlinkingNodeEditPartStylizerImpl() + { + blinkingThread = new BlinkingThread(); + blinkingThread.start(); + } + + @Override + public void setDefault(EditPart editPart) + { + blinkingThread.stop(editPart); + setBorder(editPart, DawnColorConstants.COLOR_NO_CONFLICT, 0); + } + + @Override + public void setConflicted(EditPart editPart, int type) + { + blinkingThread.start(editPart); + } + + @Override + public void setLocked(EditPart editPart, int type) + { + setBorder(editPart, DawnColorConstants.COLOR_LOCKED_REMOTELY, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } + + /** + * @author Martin Fluegge + * @since 2.0 + */ + protected class BlinkingThread extends Thread + { + + Map<EditPart, Boolean> editParts = new HashMap<EditPart, Boolean>(); + + @Override + public void run() + { + while (true) + { + for (EditPart e : editParts.keySet()) + { + if (editParts.get(e)) + { + setBorder(e, DawnColorConstants.COLOR_NO_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } + else + { + setBorder(e, DawnColorConstants.COLOR_DELETE_CONFLICT, DawnAppearancer.DEFAULT_BORDER_THICKNESS); + } + + editParts.put(e, !editParts.get(e)); + } + try + { + Thread.sleep(500); + } + catch (InterruptedException e1) + { + e1.printStackTrace(); + } + } + } + + /** + * @since 2.0 + */ + public void start(EditPart editPart) + { + editParts.put(editPart, true); + } + + public void stop(EditPart editPart) + { + editParts.remove(editPart); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java index 3e44d0bdbd..70dc9cee0a 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/editors/impl/DawnGMFEditorSupport.java @@ -1,198 +1,198 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.editors.impl;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
-import org.eclipse.emf.cdo.dawn.editors.impl.DawnAbstractEditorSupport;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFHandler;
-import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFLockingHandler;
-import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnChangeHelper;
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
-import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener;
-import org.eclipse.emf.cdo.dawn.spi.DawnState;
-import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry;
-import org.eclipse.emf.cdo.transaction.CDOTransactionHandlerBase;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.notation.View;
-
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnGMFEditorSupport extends DawnAbstractEditorSupport
-{
- private DawnGMFHandler dawnGMFHandler;
-
- public DawnGMFEditorSupport(IDawnEditor editor)
- {
- super(editor);
- dawnGMFHandler = new DawnGMFHandler(editor);
- }
-
- public void close()
- {
- CDOView view = getView();
- if (view != null && !view.isClosed())
- {
- view.close();
- }
- }
-
- @Override
- protected BasicDawnListener getBasicHandler()
- {
- return dawnGMFHandler;
- }
-
- @Override
- protected BasicDawnListener getLockingHandler()
- {
- return new DawnGMFLockingHandler(getEditor());
- }
-
- @Override
- protected CDOTransactionHandlerBase getTransactionHandler()
- {
- return dawnGMFHandler;
- }
-
- /**
- * @since 1.0
- */
- @Override
- public void rollback()
- {
- super.rollback();
- final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor)getEditor();
- TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain();
- editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain)
- {
- @Override
- public void doExecute()
- {
- DawnAppearancer.setEditPartDefaultAllChildren(diagramDocumentEditor.getDiagramEditPart());
- DawnDiagramUpdater.refreshEditPart(diagramDocumentEditor.getDiagramEditPart());
- }
- });
- }
-
- public void refresh()
- {
- final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor)getEditor();
- TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain();
- editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain)
- {
- @Override
- public void doExecute()
- {
- DawnDiagramUpdater.refreshEditPart(diagramDocumentEditor.getDiagramEditPart());
- }
- });
- }
-
- public void lockObject(Object objectToBeLocked)
- {
- if (objectToBeLocked instanceof EditPart)
- {
- EditPart editPart = (EditPart)objectToBeLocked;
- Object model = editPart.getModel();
-
- if (model instanceof EObject)
- {
- CDOUtil.getCDOObject((EObject)model).cdoWriteLock().lock();
- if (model instanceof View)
- {
- EObject element = ((View)model).getElement();
- CDOUtil.getCDOObject(element).cdoWriteLock().lock();
- }
- }
- DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
- if (stylizer != null)
- {
- stylizer.setLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY);
- }
- }
- refresh();
- }
-
- public void unlockObject(Object objectToBeUnlocked)
- {
- if (objectToBeUnlocked instanceof EditPart)
- {
- EditPart editPart = (EditPart)objectToBeUnlocked;
-
- Object model = editPart.getModel();
-
- if (model instanceof EObject)
- {
- CDOUtil.getCDOObject((EObject)model).cdoWriteLock().unlock();
- if (model instanceof View)
- {
- EObject element = ((View)model).getElement();
- CDOUtil.getCDOObject(element).cdoWriteLock().unlock();
- }
- }
- DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart);
- if (stylizer != null)
- {
- stylizer.setDefault(editPart);
- }
- }
- refresh();
- }
-
- public void handleRemoteLockChanges(Map<Object, DawnState> changedObjects)
- {
- for (Object o : changedObjects.keySet())
- {
- handleLock((CDOObject)o, getView());
- }
- refresh();
- }
-
- private void handleLock(CDOObject object, CDOView cdoView)
- {
- EObject element = CDOUtil.getEObject(object); // either semantic object or notational
- View view = DawnDiagramUpdater.findView(element);
- if (view != null)
- {
- // if there is no view, the semantic object is not displayed.
- EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, (DiagramDocumentEditor)getEditor());
-
- if (object.cdoWriteLock().isLocked())
- {
- DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY);
- }
- else if (object.cdoWriteLock().isLockedByOthers())
- {
- DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_GLOBALLY);
- DawnChangeHelper.deactivateEditPart(editPart);
- }
- else
- {
- DawnAppearancer.setEditPartDefault(editPart);
- DawnChangeHelper.activateEditPart(editPart);
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.editors.impl; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer; +import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.editors.impl.DawnAbstractEditorSupport; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFHandler; +import org.eclipse.emf.cdo.dawn.gmf.notifications.impl.DawnGMFLockingHandler; +import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnChangeHelper; +import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.notifications.BasicDawnListener; +import org.eclipse.emf.cdo.dawn.spi.DawnState; +import org.eclipse.emf.cdo.dawn.ui.stylizer.DawnElementStylizerRegistry; +import org.eclipse.emf.cdo.transaction.CDOTransactionHandlerBase; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.notation.View; + +import java.util.Map; + +/** + * @author Martin Fluegge + */ +public class DawnGMFEditorSupport extends DawnAbstractEditorSupport +{ + private DawnGMFHandler dawnGMFHandler; + + public DawnGMFEditorSupport(IDawnEditor editor) + { + super(editor); + dawnGMFHandler = new DawnGMFHandler(editor); + } + + public void close() + { + CDOView view = getView(); + if (view != null && !view.isClosed()) + { + view.close(); + } + } + + @Override + protected BasicDawnListener getBasicHandler() + { + return dawnGMFHandler; + } + + @Override + protected BasicDawnListener getLockingHandler() + { + return new DawnGMFLockingHandler(getEditor()); + } + + @Override + protected CDOTransactionHandlerBase getTransactionHandler() + { + return dawnGMFHandler; + } + + /** + * @since 1.0 + */ + @Override + public void rollback() + { + super.rollback(); + final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor)getEditor(); + TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + @Override + public void doExecute() + { + DawnAppearancer.setEditPartDefaultAllChildren(diagramDocumentEditor.getDiagramEditPart()); + DawnDiagramUpdater.refreshEditPart(diagramDocumentEditor.getDiagramEditPart()); + } + }); + } + + public void refresh() + { + final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor)getEditor(); + TransactionalEditingDomain editingDomain = diagramDocumentEditor.getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + @Override + public void doExecute() + { + DawnDiagramUpdater.refreshEditPart(diagramDocumentEditor.getDiagramEditPart()); + } + }); + } + + public void lockObject(Object objectToBeLocked) + { + if (objectToBeLocked instanceof EditPart) + { + EditPart editPart = (EditPart)objectToBeLocked; + Object model = editPart.getModel(); + + if (model instanceof EObject) + { + CDOUtil.getCDOObject((EObject)model).cdoWriteLock().lock(); + if (model instanceof View) + { + EObject element = ((View)model).getElement(); + CDOUtil.getCDOObject(element).cdoWriteLock().lock(); + } + } + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); + } + } + refresh(); + } + + public void unlockObject(Object objectToBeUnlocked) + { + if (objectToBeUnlocked instanceof EditPart) + { + EditPart editPart = (EditPart)objectToBeUnlocked; + + Object model = editPart.getModel(); + + if (model instanceof EObject) + { + CDOUtil.getCDOObject((EObject)model).cdoWriteLock().unlock(); + if (model instanceof View) + { + EObject element = ((View)model).getElement(); + CDOUtil.getCDOObject(element).cdoWriteLock().unlock(); + } + } + DawnElementStylizer stylizer = DawnElementStylizerRegistry.instance.getStylizer(editPart); + if (stylizer != null) + { + stylizer.setDefault(editPart); + } + } + refresh(); + } + + public void handleRemoteLockChanges(Map<Object, DawnState> changedObjects) + { + for (Object o : changedObjects.keySet()) + { + handleLock((CDOObject)o, getView()); + } + refresh(); + } + + private void handleLock(CDOObject object, CDOView cdoView) + { + EObject element = CDOUtil.getEObject(object); // either semantic object or notational + View view = DawnDiagramUpdater.findView(element); + if (view != null) + { + // if there is no view, the semantic object is not displayed. + EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, (DiagramDocumentEditor)getEditor()); + + if (object.cdoWriteLock().isLocked()) + { + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_LOCALLY); + } + else if (object.cdoWriteLock().isLockedByOthers()) + { + DawnAppearancer.setEditPartLocked(editPart, DawnAppearancer.TYPE_LOCKED_GLOBALLY); + DawnChangeHelper.deactivateEditPart(editPart); + } + else + { + DawnAppearancer.setEditPartDefault(editPart); + DawnChangeHelper.activateEditPart(editPart); + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelper.java index 42adec1815..e7d96fd71b 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelper.java @@ -1,30 +1,30 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.elementtypes;
-
-/**
- *
- * @author Martin Fluegge
- * @since 2.0
- */
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * @since 2.0
- */
-public interface DawnElementTypeHelper
-{
- /**
- * @since 2.0
- */
- IElementType getElementType(View view);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.elementtypes; + +/** + * + * @author Martin Fluegge + * @since 2.0 + */ +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.notation.View; + +/** + * @since 2.0 + */ +public interface DawnElementTypeHelper +{ + /** + * @since 2.0 + */ + IElementType getElementType(View view); +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelperFactory.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelperFactory.java index 27973ed403..d076f28bb8 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelperFactory.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/elementtypes/DawnElementTypeHelperFactory.java @@ -1,19 +1,19 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.elementtypes;
-
-/**
- * @author Martin Fluegge
- */
-public interface DawnElementTypeHelperFactory
-{
- DawnElementTypeHelper create();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.elementtypes; + +/** + * @author Martin Fluegge + */ +public interface DawnElementTypeHelperFactory +{ + DawnElementTypeHelper create(); +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java index f00242bfe4..adbdf63480 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java @@ -1,287 +1,287 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.notifications.impl;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
-import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper;
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
-import org.eclipse.emf.cdo.dawn.notifications.BasicDawnTransactionHandler;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.transaction.CDOTransactionConflictEvent;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.InvalidObjectException;
-import org.eclipse.emf.cdo.view.CDOViewInvalidationEvent;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnGMFHandler extends BasicDawnTransactionHandler
-{
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnGMFHandler.class);
-
- /**
- * @since 1.0
- */
- public DawnGMFHandler(IDawnEditor editor)
- {
- super(editor);
- }
-
- /**
- * @since 1.0
- */
- @Override
- public void handleViewInvalidationEvent(CDOViewInvalidationEvent event)
- {
- CDOViewInvalidationEvent e = event;
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Detached Objects {0} ", e.getDetachedObjects()); //$NON-NLS-1$
- TRACER.format("Dirty Objects {0} ", e.getDirtyObjects()); //$NON-NLS-1$
- }
- adjustDeletedEdges(e);
-
- for (CDOObject dirtyObject : e.getDirtyObjects())
- {
- handleObject(dirtyObject);
- }
-
- for (CDOObject detachedObject : e.getDetachedObjects())
- {
- handleObject(detachedObject);
- }
- }
-
- /**
- * @since 1.0
- */
- @Override
- public void handleTransactionConflictEvent(CDOTransactionConflictEvent event)
- {
- CDOTransactionConflictEvent cdoTransactionConflictEvent = event;
-
- CDOObject cdoObject = cdoTransactionConflictEvent.getConflictingObject();
-
- EObject element = CDOUtil.getEObject(cdoObject); // either semantic object or notational
- View view = DawnDiagramUpdater.findView(element);
-
- if (DawnConflictHelper.isConflicted(cdoObject))
- {
- DawnConflictHelper.handleConflictedView(cdoObject, view, (DiagramDocumentEditor)editor);
- return;
- }
- }
-
- @Override
- public void modifyingObject(CDOTransaction transaction, final CDOObject object, CDOFeatureDelta featureDelta)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("modifyingObject {0}", object); //$NON-NLS-1$
- }
-
- refresh(object);
- editor.setDirty();
- object.eAdapters().add(new Adapter()
- {
- public void setTarget(Notifier newTarget)
- {
- }
-
- public void notifyChanged(Notification notification)
- {
- DawnDiagramUpdater.refreshEditPart(((DiagramDocumentEditor)editor).getDiagramEditPart(),
- (DiagramDocumentEditor)editor);
- object.eAdapters().remove(this);
- }
-
- public boolean isAdapterForType(Object type)
- {
- return false;
- }
-
- public Notifier getTarget()
- {
- return null;
- }
- });
- }
-
- /**
- * @since 1.0
- */
- @Override
- public void attachingObject(CDOTransaction transaction, CDOObject object)
- {
- super.attachingObject(transaction, object);
- refresh(object);
- }
-
- /**
- * Edges must be adjusted because of the transience of the Node source/targetEdges CDO cannot see this because
- * removing an edges just removes the edge from the diagram. CDO just notices the change in the diagram but not in the
- * (detached) edge. The other site (node) is transient and will not be part of the notification. So I must adjust this
- * later. CDOLEgacy Wrapper breakes because it only adjusts the changes in the diagram and not the removed edge. So I
- * cannot adjust this in the Wrapper. Maybe there is another more generic way.
- */
- public void adjustDeletedEdges(final CDOViewInvalidationEvent e)
- {
- Display.getDefault().asyncExec(new Runnable()
- {
- public void run()
- {
- for (CDOObject obj : e.getDetachedObjects())
- {
- final EObject view = CDOUtil.getEObject(obj);
- if (view instanceof Edge)
- {
- EditingDomain editingDomain = ((IEditingDomainProvider)view.eResource().getResourceSet())
- .getEditingDomain();
- editingDomain.getCommandStack().execute(new RecordingCommand((TransactionalEditingDomain)editingDomain)
- {
- @Override
- protected void doExecute()
- {
- try
- {
- ((Edge)view).setTarget(null);
- }
- catch (InvalidObjectException ignore)
- {
- }
-
- try
- {
- ((Edge)view).setSource(null);
- }
- catch (InvalidObjectException ignore)
- {
- }
- }
- });
- }
- }
- }
- });
- }
-
- protected void handleConflicts(CDOViewInvalidationEvent e)
- {
- for (CDOObject obj : e.getDetachedObjects())
- {
- EObject element = CDOUtil.getEObject(obj);
- View view = DawnDiagramUpdater.findViewByContainer(element);
- DawnConflictHelper.handleConflictedView(CDOUtil.getCDOObject(element), view, (DiagramDocumentEditor)editor);
- }
- }
-
- private void handleObject(CDOObject dirtyObject)
- {
- if (dirtyObject.cdoInvalid())
- {
- return;
- }
- EObject element = CDOUtil.getEObject(dirtyObject); // either sementic object or notational
-
- View view = DawnDiagramUpdater.findView(element);
-
- if (DawnConflictHelper.isConflicted(dirtyObject))
- {
- // DawnConflictHelper.handleConflictedView(dirtyObject, view, editor);
- return;
- }
-
- EditPart relatedEditPart = DawnDiagramUpdater.findEditPart(view, ((DiagramEditor)editor).getDiagramEditPart()
- .getViewer());
- if (relatedEditPart != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Updating EditPart {0} ", relatedEditPart); //$NON-NLS-1$
- }
- DawnDiagramUpdater.refreshEditPart(relatedEditPart.getParent(), (DiagramDocumentEditor)editor);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Updating DiagramEditPart {0} ", ((DiagramEditor)editor).getDiagramEditPart()); //$NON-NLS-1$
- }
- DawnDiagramUpdater.refreshEditPart(((DiagramEditor)editor).getDiagramEditPart(), (DiagramDocumentEditor)editor);
- }
- }
-
- protected void refresh(CDOObject object)
- {
- View view = DawnDiagramUpdater.findViewByContainer(object);
- if (view == null)
- {
- view = DawnDiagramUpdater.findViewForModel(object, (DiagramDocumentEditor)editor);
- }
- if (view == null)
- {
- DawnDiagramUpdater.findViewFromCrossReferences(object);
- }
-
- EditPart relatedEditPart = DawnDiagramUpdater.findEditPart(view, ((DiagramDocumentEditor)editor)
- .getDiagramEditPart().getViewer());
-
- if (relatedEditPart != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Updating EditPart {0} ", relatedEditPart); //$NON-NLS-1$
- }
- EditPart parent = relatedEditPart.getParent();
- if (parent instanceof IGraphicalEditPart)
- {
- DawnDiagramUpdater.refresh((IGraphicalEditPart)parent);
- }
- else
- {
- DawnDiagramUpdater.refreshEditPart(parent, (DiagramDocumentEditor)editor);
- }
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Updating DiagramEditPart {0} ", ((DiagramDocumentEditor)editor).getDiagramEditPart()); //$NON-NLS-1$
- }
-
- DawnDiagramUpdater.refresh(((DiagramDocumentEditor)editor).getDiagramEditPart());
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.notifications.impl; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; +import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper; +import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.notifications.BasicDawnTransactionHandler; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.transaction.CDOTransactionConflictEvent; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.InvalidObjectException; +import org.eclipse.emf.cdo.view.CDOViewInvalidationEvent; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.swt.widgets.Display; + +/** + * @author Martin Fluegge + */ +public class DawnGMFHandler extends BasicDawnTransactionHandler +{ + + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnGMFHandler.class); + + /** + * @since 1.0 + */ + public DawnGMFHandler(IDawnEditor editor) + { + super(editor); + } + + /** + * @since 1.0 + */ + @Override + public void handleViewInvalidationEvent(CDOViewInvalidationEvent event) + { + CDOViewInvalidationEvent e = event; + + if (TRACER.isEnabled()) + { + TRACER.format("Detached Objects {0} ", e.getDetachedObjects()); //$NON-NLS-1$ + TRACER.format("Dirty Objects {0} ", e.getDirtyObjects()); //$NON-NLS-1$ + } + adjustDeletedEdges(e); + + for (CDOObject dirtyObject : e.getDirtyObjects()) + { + handleObject(dirtyObject); + } + + for (CDOObject detachedObject : e.getDetachedObjects()) + { + handleObject(detachedObject); + } + } + + /** + * @since 1.0 + */ + @Override + public void handleTransactionConflictEvent(CDOTransactionConflictEvent event) + { + CDOTransactionConflictEvent cdoTransactionConflictEvent = event; + + CDOObject cdoObject = cdoTransactionConflictEvent.getConflictingObject(); + + EObject element = CDOUtil.getEObject(cdoObject); // either semantic object or notational + View view = DawnDiagramUpdater.findView(element); + + if (DawnConflictHelper.isConflicted(cdoObject)) + { + DawnConflictHelper.handleConflictedView(cdoObject, view, (DiagramDocumentEditor)editor); + return; + } + } + + @Override + public void modifyingObject(CDOTransaction transaction, final CDOObject object, CDOFeatureDelta featureDelta) + { + if (TRACER.isEnabled()) + { + TRACER.format("modifyingObject {0}", object); //$NON-NLS-1$ + } + + refresh(object); + editor.setDirty(); + object.eAdapters().add(new Adapter() + { + public void setTarget(Notifier newTarget) + { + } + + public void notifyChanged(Notification notification) + { + DawnDiagramUpdater.refreshEditPart(((DiagramDocumentEditor)editor).getDiagramEditPart(), + (DiagramDocumentEditor)editor); + object.eAdapters().remove(this); + } + + public boolean isAdapterForType(Object type) + { + return false; + } + + public Notifier getTarget() + { + return null; + } + }); + } + + /** + * @since 1.0 + */ + @Override + public void attachingObject(CDOTransaction transaction, CDOObject object) + { + super.attachingObject(transaction, object); + refresh(object); + } + + /** + * Edges must be adjusted because of the transience of the Node source/targetEdges CDO cannot see this because + * removing an edges just removes the edge from the diagram. CDO just notices the change in the diagram but not in the + * (detached) edge. The other site (node) is transient and will not be part of the notification. So I must adjust this + * later. CDOLEgacy Wrapper breakes because it only adjusts the changes in the diagram and not the removed edge. So I + * cannot adjust this in the Wrapper. Maybe there is another more generic way. + */ + public void adjustDeletedEdges(final CDOViewInvalidationEvent e) + { + Display.getDefault().asyncExec(new Runnable() + { + public void run() + { + for (CDOObject obj : e.getDetachedObjects()) + { + final EObject view = CDOUtil.getEObject(obj); + if (view instanceof Edge) + { + EditingDomain editingDomain = ((IEditingDomainProvider)view.eResource().getResourceSet()) + .getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand((TransactionalEditingDomain)editingDomain) + { + @Override + protected void doExecute() + { + try + { + ((Edge)view).setTarget(null); + } + catch (InvalidObjectException ignore) + { + } + + try + { + ((Edge)view).setSource(null); + } + catch (InvalidObjectException ignore) + { + } + } + }); + } + } + } + }); + } + + protected void handleConflicts(CDOViewInvalidationEvent e) + { + for (CDOObject obj : e.getDetachedObjects()) + { + EObject element = CDOUtil.getEObject(obj); + View view = DawnDiagramUpdater.findViewByContainer(element); + DawnConflictHelper.handleConflictedView(CDOUtil.getCDOObject(element), view, (DiagramDocumentEditor)editor); + } + } + + private void handleObject(CDOObject dirtyObject) + { + if (dirtyObject.cdoInvalid()) + { + return; + } + EObject element = CDOUtil.getEObject(dirtyObject); // either sementic object or notational + + View view = DawnDiagramUpdater.findView(element); + + if (DawnConflictHelper.isConflicted(dirtyObject)) + { + // DawnConflictHelper.handleConflictedView(dirtyObject, view, editor); + return; + } + + EditPart relatedEditPart = DawnDiagramUpdater.findEditPart(view, ((DiagramEditor)editor).getDiagramEditPart() + .getViewer()); + if (relatedEditPart != null) + { + if (TRACER.isEnabled()) + { + TRACER.format("Updating EditPart {0} ", relatedEditPart); //$NON-NLS-1$ + } + DawnDiagramUpdater.refreshEditPart(relatedEditPart.getParent(), (DiagramDocumentEditor)editor); + } + else + { + if (TRACER.isEnabled()) + { + TRACER.format("Updating DiagramEditPart {0} ", ((DiagramEditor)editor).getDiagramEditPart()); //$NON-NLS-1$ + } + DawnDiagramUpdater.refreshEditPart(((DiagramEditor)editor).getDiagramEditPart(), (DiagramDocumentEditor)editor); + } + } + + protected void refresh(CDOObject object) + { + View view = DawnDiagramUpdater.findViewByContainer(object); + if (view == null) + { + view = DawnDiagramUpdater.findViewForModel(object, (DiagramDocumentEditor)editor); + } + if (view == null) + { + DawnDiagramUpdater.findViewFromCrossReferences(object); + } + + EditPart relatedEditPart = DawnDiagramUpdater.findEditPart(view, ((DiagramDocumentEditor)editor) + .getDiagramEditPart().getViewer()); + + if (relatedEditPart != null) + { + if (TRACER.isEnabled()) + { + TRACER.format("Updating EditPart {0} ", relatedEditPart); //$NON-NLS-1$ + } + EditPart parent = relatedEditPart.getParent(); + if (parent instanceof IGraphicalEditPart) + { + DawnDiagramUpdater.refresh((IGraphicalEditPart)parent); + } + else + { + DawnDiagramUpdater.refreshEditPart(parent, (DiagramDocumentEditor)editor); + } + } + else + { + if (TRACER.isEnabled()) + { + TRACER.format("Updating DiagramEditPart {0} ", ((DiagramDocumentEditor)editor).getDiagramEditPart()); //$NON-NLS-1$ + } + + DawnDiagramUpdater.refresh(((DiagramDocumentEditor)editor).getDiagramEditPart()); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java index 6a5706c569..746dca16a5 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFLockingHandler.java @@ -1,25 +1,25 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.notifications.impl;
-
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
-import org.eclipse.emf.cdo.dawn.notifications.BasicDawnLockingHandler;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnGMFLockingHandler extends BasicDawnLockingHandler
-{
- public DawnGMFLockingHandler(IDawnEditor editor)
- {
- super(editor);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.notifications.impl; + +import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.notifications.BasicDawnLockingHandler; + +/** + * @author Martin Fluegge + */ +public class DawnGMFLockingHandler extends BasicDawnLockingHandler +{ + public DawnGMFLockingHandler(IDawnEditor editor) + { + super(editor); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/resources/DawnPathmapManager.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/resources/DawnPathmapManager.java index 79edd01b3f..17a30070dc 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/resources/DawnPathmapManager.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/resources/DawnPathmapManager.java @@ -1,64 +1,64 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.resources;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Martin Fluegge
- */
-@SuppressWarnings("restriction")
-public class DawnPathmapManager extends PathmapManager
-{
- // TODO remove this as soon as the PathmapManager problem is solved!
- @Override
- public void notifyChanged(Notification msg)
- {
- if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES)
- {
- switch (msg.getEventType())
- {
- case Notification.REMOVE_MANY:
- {
- if (msg.getNewValue() instanceof int[])
- {
- return;
- }
- break;
- }
- }
- }
-
- super.notifyChanged(msg);
- }
-
- public static void removePathMapMananger(EList<Adapter> eAdapters)
- {
- List<Adapter> toBeRemoved = new ArrayList<Adapter>();
- for (Adapter a : eAdapters)
- {
- if (a instanceof PathmapManager)
- {
- toBeRemoved.add(a);
- }
- }
- eAdapters.removeAll(toBeRemoved);
- }
-
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.resources; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.resource.ResourceSet; + +import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Martin Fluegge + */ +@SuppressWarnings("restriction") +public class DawnPathmapManager extends PathmapManager +{ + // TODO remove this as soon as the PathmapManager problem is solved! + @Override + public void notifyChanged(Notification msg) + { + if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) + { + switch (msg.getEventType()) + { + case Notification.REMOVE_MANY: + { + if (msg.getNewValue() instanceof int[]) + { + return; + } + break; + } + } + } + + super.notifyChanged(msg); + } + + public static void removePathMapMananger(EList<Adapter> eAdapters) + { + List<Adapter> toBeRemoved = new ArrayList<Adapter>(); + for (Adapter a : eAdapters) + { + if (a instanceof PathmapManager) + { + toBeRemoved.add(a); + } + } + eAdapters.removeAll(toBeRemoved); + } + +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/stylizer/DawnGMFElementStylizerFactory.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/stylizer/DawnGMFElementStylizerFactory.java index 25f6b8e568..97834f06ac 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/stylizer/DawnGMFElementStylizerFactory.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/stylizer/DawnGMFElementStylizerFactory.java @@ -1,57 +1,57 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.stylizer;
-
-import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer;
-import org.eclipse.emf.cdo.dawn.appearance.IDawnElementStylizerFactory;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicConnectionEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicGraphicalEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicNodeEditPartStylizerImpl;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicTextAwareEditPartStylizerImpl;
-
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.NodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnGMFElementStylizerFactory implements IDawnElementStylizerFactory
-{
- public DawnElementStylizer getElementStylizer(Object object)
- {
- DawnElementStylizer stylizer = null;
- if (object instanceof ConnectionEditPart)
- {
- stylizer = new DawnBasicConnectionEditPartStylizerImpl();
- }
- else if (object instanceof NodeEditPart)
- {
- stylizer = new DawnBasicNodeEditPartStylizerImpl();
- }
- else if (object instanceof DiagramEditPart)
- {
- stylizer = new DawnBasicNodeEditPartStylizerImpl();
- }
- else if (object instanceof ITextAwareEditPart)
- {
- stylizer = new DawnBasicTextAwareEditPartStylizerImpl();
- }
- else
- {
- // In the case that there is no match we use a simple border styled stylizer.
- stylizer = new DawnBasicGraphicalEditPartStylizerImpl();
- }
-
- return stylizer;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.stylizer; + +import org.eclipse.emf.cdo.dawn.appearance.DawnElementStylizer; +import org.eclipse.emf.cdo.dawn.appearance.IDawnElementStylizerFactory; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicConnectionEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicGraphicalEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicNodeEditPartStylizerImpl; +import org.eclipse.emf.cdo.dawn.gmf.appearance.impl.DawnBasicTextAwareEditPartStylizerImpl; + +import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.NodeEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; + +/** + * @author Martin Fluegge + */ +public class DawnGMFElementStylizerFactory implements IDawnElementStylizerFactory +{ + public DawnElementStylizer getElementStylizer(Object object) + { + DawnElementStylizer stylizer = null; + if (object instanceof ConnectionEditPart) + { + stylizer = new DawnBasicConnectionEditPartStylizerImpl(); + } + else if (object instanceof NodeEditPart) + { + stylizer = new DawnBasicNodeEditPartStylizerImpl(); + } + else if (object instanceof DiagramEditPart) + { + stylizer = new DawnBasicNodeEditPartStylizerImpl(); + } + else if (object instanceof ITextAwareEditPart) + { + stylizer = new DawnBasicTextAwareEditPartStylizerImpl(); + } + else + { + // In the case that there is no match we use a simple border styled stylizer. + stylizer = new DawnBasicGraphicalEditPartStylizerImpl(); + } + + return stylizer; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java index 57f5ffdc94..fceeda2786 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnChangeHelper.java @@ -1,629 +1,629 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.synchronize;
-
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnResourceHelper;
-import org.eclipse.emf.cdo.dawn.util.exceptions.EClassIncompatibleException;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.draw2d.Border;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand;
-import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewAndElementCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest.ConnectionViewAndElementDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
-import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
-import org.eclipse.gmf.runtime.notation.Anchor;
-import org.eclipse.gmf.runtime.notation.Bendpoints;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Display;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnChangeHelper
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnChangeHelper.class);
-
- protected static final java.util.Map<String, Boolean> options = new HashMap<String, Boolean>();
-
- protected static final java.util.Map<Object, Object> setElementOptions = new HashMap<Object, Object>();
- static
- {
- options.put(Transaction.OPTION_UNPROTECTED, Boolean.FALSE);
- options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
- options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
- }
-
- /**
- * generic Method to create an EditPart by the given view
- *
- * @param node
- * @param elementType
- * @param diagramEP
- * @return the EditPart for the newly created Node
- */
- public static EditPart createNode(final Node node, IElementType elementType, DiagramEditPart diagramEP)
- {
- CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType,
- diagramEP.getDiagramPreferencesHint());
-
- Bounds bounds = (Bounds)node.getLayoutConstraint();
-
- Point p = new Point(bounds.getX(), bounds.getY());
- Dimension dimension = new Dimension(bounds.getWidth(), bounds.getHeight());
- createViewRequest.setLocation(p);
- createViewRequest.setSize(dimension);
-
- diagramEP.performRequest(createViewRequest);
-
- final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
- final EditPartViewer viewer = diagramEP.getViewer();
- final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
- return kep;
- }
-
- public static EditPart createAttribute(final Node node, IElementType elementType, IGraphicalEditPart parentEditpart)
- {
-
- if (TRACER.isEnabled())
- {
- TRACER.format("ElementType: {0} semanticHint {1}", elementType, ((IHintedType)elementType).getSemanticHint()); //$NON-NLS-1$
- }
-
- CreateElementRequest request = new CreateElementRequest(elementType);
- CreateElementRequestAdapter createElementRequestAdapter = new CreateElementRequestAdapter(request);
-
- ViewAndElementDescriptor viewAndElementDescriptor = new ViewAndElementDescriptor(createElementRequestAdapter,
- Node.class, ((IHintedType)elementType).getSemanticHint(),
-
- parentEditpart.getDiagramPreferencesHint());
-
- CreateViewAndElementRequest createViewRequest = new CreateViewAndElementRequest(viewAndElementDescriptor);
-
- // Command command = parentEditpart.getCommand(createViewRequest);
-
- parentEditpart.performRequest(createViewRequest);
-
- final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
- final EditPartViewer viewer = parentEditpart.getViewer();
- final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
- return kep;
- }
-
- /***************************************
- * This method creates an EditPart given by the specified ElemetType and PLaces it to the give coordinates
- * Element-Types could be: DawnElementTypes.Klasse_1001
- *
- * @param p
- * the point where the view shoudl be created
- * @param elementType
- * @param diagramEditor
- * @return the created EditPart
- ********************************************************************************************************************/
- public static EditPart createEditPart(Point p, IElementType elementType, DiagramDocumentEditor diagramEditor)
- {
- DiagramEditPart diagramEP = diagramEditor.getDiagramEditPart();
-
- CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType,
- diagramEP.getDiagramPreferencesHint());
-
- createViewRequest.setLocation(p);
- diagramEP.performRequest(createViewRequest);
-
- final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0);
- final EditPartViewer viewer = diagramEP.getViewer();
- return (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));
- }
-
- /***************************************
- * sets a property for an editpart
- *
- * @param editPart
- * @param name
- * @param object
- * @param dawnDiagramEditor
- ********************************************************************************************************************/
- public static void setProperty(EditPart editPart, String name, String packageUtilPropertyID, Object object,
- DiagramDocumentEditor dawnDiagramEditor)
- {
- SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart,
- packageUtilPropertyID, name, object);
-
- DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart();
-
- diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand));
-
- }
-
- /***************************************
- * resizes an Editpart to the given dimension
- *
- * @param editpart
- * @param d
- * dimension
- ********************************************************************************************************************/
- public static void resizeEditPart(EditPart editpart, Dimension d)
- {
- boolean editModeEnabled = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart)
- .isEditModeEnabled();
- if (!editModeEnabled)
- {
- ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode();
- }
-
- ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
- move_req.setResizeDirection(PositionConstants.SOUTH_EAST);
-
- Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint();
- Dimension dimensionDelta = new Dimension(d.width - b.getWidth(), d.height - b.getHeight());
-
- move_req.setSizeDelta(dimensionDelta);
-
- Command cmd = editpart.getCommand(move_req);
- if (cmd == null || !cmd.canExecute())
- {
- throw new IllegalArgumentException("Command is not executable.");
- }
- ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
-
- if (editModeEnabled)
- {
- ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode();
- }
- else
- {
- ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).disableEditMode();
- }
- }
-
- /***************************************
- * moves an EdidPart to the given postione
- *
- * @param editpart
- * @param p
- ********************************************************************************************************************/
- public static void moveEditPart(EditPart editpart, Point p)
- {
- ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
-
- Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint();
- Point newPoint = new Point(p.x - b.getX(), p.y - b.getY());
- move_req.setMoveDelta(newPoint);
-
- Command cmd = editpart.getCommand(move_req);
- if (cmd == null || !cmd.canExecute())
- {
- throw new IllegalArgumentException("Command is not executable.");
- }
- ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
- }
-
- /**
- * Moves the Editpart from the current position to the new Vector
- */
- public static void moveEditPartTo(EditPart editpart, Point p)
- {
- ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
- move_req.setMoveDelta(p);
- Command cmd = editpart.getCommand(move_req);
- if (cmd == null || !cmd.canExecute())
- {
- throw new IllegalArgumentException("Command is not executable.");
- }
- ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
- }
-
- /**
- * deletes the EditPart an the concerning model element
- *
- * @param editPart
- * @param editor
- */
- public static void deleteEditPart(final EditPart editPart, DiagramDocumentEditor editor)
- {
- final View view = (View)editPart.getModel();
-
- EObject eObject = view.getElement();
- if (eObject != null)
- {
- DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false);
-
- Request req = new EditCommandRequestWrapper(destroy);
-
- Command command = editPart.getCommand(req);
- editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
- }
- TransactionalEditingDomain domain = editor.getEditingDomain();
- if (view instanceof Edge) // also update the lists of the other client
- {
- domain.getCommandStack().execute(new RecordingCommand(domain)
- {
- @Override
- public void doExecute()
- {
- Edge e = (Edge)view;
- View source = e.getSource();
- View target = e.getTarget();
- if (source != null && target != null)
- {
- EObject targetElement = target.getElement();
- EObject sourceElement = source.getElement();
-
- EStructuralFeature containingFeature = sourceElement.eContainingFeature();
- Collection<?> sourceCrossreferenceCollection = (Collection<?>)sourceElement.eGet(containingFeature);
- sourceCrossreferenceCollection.remove(targetElement);
- }
- }
- });
- }
- ViewUtil.destroy(view);
- }
-
- /***************************************
- * Deletes a view and it's contained element
- *
- * @param view
- * @param editor
- ********************************************************************************************************************/
- public static void deleteView(final View view, DiagramDocumentEditor editor)
- {
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Deleting view {0} ", view); //$NON-NLS-1$
- }
-
- EObject eObject = view.getElement();
- if (eObject != null)
- {
- DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false);
-
- Request req = new EditCommandRequestWrapper(destroy);
-
- EditPart findEditPart = DawnDiagramUpdater.findEditPart(view, editor.getDiagramEditPart().getViewer());
- Command command = findEditPart.getCommand(req);
- editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
- }
- if (view instanceof Edge) // also update the lists of the other client
- {
- destroyEdge((Edge)view, editor);
- }
- ViewUtil.destroy(view);
- }
-
- public static void destroyEdge(Edge edge, DiagramDocumentEditor editor)
- {
- EObject referenceObject = ViewUtil.resolveSemanticElement(edge.getTarget());
- EObject container = ViewUtil.resolveSemanticElement(edge.getSource());
- EditPart parentEditpart = DawnDiagramUpdater.findEditPart(edge, editor.getDiagramEditPart().getViewer());
- DestroyReferenceRequest destroyReferenceRequest = new DestroyReferenceRequest(editor.getEditingDomain(), container,
- null, referenceObject, false);
- Request req = new EditCommandRequestWrapper(destroyReferenceRequest);
-
- Command command = parentEditpart.getCommand(req);
- editor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
- }
-
- /***************************************
- * creates an edge for a given elementType
- *
- * @param oldEdge
- * @param sourceEditPart
- * @param targetEditPart
- * @param elementType
- * @param root
- * @return the newly created EditPart
- ********************************************************************************************************************/
- public static EditPart createEdge(Edge oldEdge, EditPart sourceEditPart, EditPart targetEditPart,
- IElementType elementType, final DiagramEditPart root)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Creaeting Edge from old edge {0} ", oldEdge); //$NON-NLS-1$
- }
-
- CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(elementType,
- ((IHintedType)elementType).getSemanticHint(), root.getDiagramPreferencesHint());
-
- ICommand createConnectionCmd = new DeferredCreateConnectionViewAndElementCommand(req, new EObjectAdapter(
- (EObject)sourceEditPart.getModel()), new EObjectAdapter((EObject)targetEditPart.getModel()), root.getViewer());
-
- root.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(createConnectionCmd));
-
- final EditPartViewer viewer = root.getViewer();
-
- final EditPart ret = (EditPart)viewer.getEditPartRegistry().get(
- ((ConnectionViewAndElementDescriptor)req.getNewObject()).getAdapter(View.class));
-
- if (ret != null)
- {
- setAnchorsAndBendPoints(ret, oldEdge, root);
- }
- return ret;
- }
-
- /***************************************
- * This Method sets the Anchors and Bendpoint from an old Edge to the edge of the given EditPart
- *
- * @param edgeEditpart
- * @param oldEdge
- * @param root
- ********************************************************************************************************************/
- public static void setAnchorsAndBendPoints(final EditPart edgeEditpart, final Edge oldEdge, final DiagramEditPart root)
- {
- TransactionalEditingDomain domain = root.getEditingDomain();// getEditingDomain();
- domain.getCommandStack().execute(new RecordingCommand(domain)
- {
- @Override
- public void doExecute()
- {
- Edge edge = (Edge)edgeEditpart.getModel();
-
- edge.setBendpoints((Bendpoints)DawnResourceHelper.createCopy(oldEdge.getBendpoints()));
- if (oldEdge.getSourceAnchor() != null)
- {
- edge.setSourceAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getSourceAnchor()));
- }
- if (oldEdge.getTargetAnchor() != null)
- {
- edge.setTargetAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getTargetAnchor()));
- }
-
- edgeEditpart.refresh();
- root.refresh();
- }
- });
- }
-
- /**
- * returns the border color from a given EditPart
- *
- * @param editPart
- * @return the border color of the EditPart
- */
- public static Color getBorderColor(EditPart editPart)
- {
- GraphicalEditPart e = (GraphicalEditPart)editPart;
-
- Border border = e.getFigure().getBorder();
-
- if (border instanceof org.eclipse.draw2d.MarginBorder)
- {
- // MarginBorder b = ((MarginBorder) e.getFigure().getBorder());
- // if (border != null)
- // {
- // return b.getColor();
- // }
- return null;
- }
- else if (border instanceof LineBorder)
- {
- LineBorder b = (LineBorder)e.getFigure().getBorder();
-
- return b.getColor();
- }
-
- return null;
- }
-
- /**
- * activates a given EditPart
- *
- * @param editPart
- */
- public static void activateEditPart(final EditPart editPart)
- {
- Display.getDefault().asyncExec(new Runnable()
- {
- public void run()
- {
- editPart.activate();
- AbstractGraphicalEditPart graphicalEditPart = (AbstractGraphicalEditPart)editPart;
- graphicalEditPart.getFigure().setEnabled(true);
- }
- });
- }
-
- /**
- * activates the diagram EditPart
- *
- * @param diagramEditPart
- */
- public static void activateDiagramEditPart(DiagramEditPart diagramEditPart)
- {
- DawnChangeHelper.activateEditPart(diagramEditPart);
-
- for (Object e : diagramEditPart.getChildren())
- {
- DawnChangeHelper.activateEditPart((EditPart)e);
- }
- }
-
- /**
- * deactivates the given EditPart
- *
- * @param editPart
- */
- public static void deactivateEditPart(final EditPart editPart)
- {
- Display.getDefault().asyncExec(new Runnable()
- {
- public void run()
- {
- editPart.deactivate();
- editPart.getViewer().deselect(editPart);
-
- AbstractGraphicalEditPart graphicalEditPart = (AbstractGraphicalEditPart)editPart;
- graphicalEditPart.getFigure().setEnabled(false);
- }
- });
- }
-
- /**
- * deactivates the DiagramEditPart
- *
- * @param diagramEditPart
- */
- public static void deactivateDiagramEditPart(DiagramEditPart diagramEditPart)
- {
- DawnChangeHelper.deactivateEditPart(diagramEditPart);
-
- for (Object e : diagramEditPart.getChildren())
- {
- DawnChangeHelper.deactivateEditPart((EditPart)e);
- }
-
- }
-
- /**
- * Deselects the given EditPart EditPart
- */
- public static void deselect(final EditPart e)
- {
- Display.getDefault().asyncExec(new Runnable()
- {
-
- public void run()
- {
- e.getViewer().deselect(e);
- }
- });
- }
-
- /**
- * selects the given EditPart
- *
- * @param e
- */
- public static void select(final EditPart e)
- {
- Display.getDefault().asyncExec(new Runnable()
- {
-
- public void run()
- {
- e.getViewer().select(e);
- }
- });
- }
-
- /***************************************
- * sets a property for an editpart
- *
- * @param editPart
- * @param name
- * @param object
- * @param dawnDiagramEditor
- ********************************************************************************************************************/
- public static void setProperty(EditPart editPart, String name, EAttribute attribute, Object object,
- DiagramDocumentEditor dawnDiagramEditor)
- {
- SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart,
- PackageUtil.getID(attribute), name, object);
- DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart();
-
- diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand));
- }
-
- /***************************************
- * updates the model
- *
- * @param editPart
- * @param model
- * @param editor
- ********************************************************************************************************************/
- public static void updateModel(final EditPart editPart, final EObject model, DiagramDocumentEditor editor)
- {
- editPart.getViewer().getEditDomain();
- View view = (View)editPart.getModel();
- final EObject element = view.getElement();
-
- if (element.eClass().getName().equals("AnOperation")) // ugliest of all workarounds. Just for the prototype
- {
- editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain())
- {
- @Override
- public void doExecute()
- {
- try
- {
- DawnResourceHelper.updateEObject(element, model);
- }
- catch (EClassIncompatibleException e)
- {
- e.printStackTrace();
- }
- }
- });
- }
- else
- {
- for (EAttribute attribute : element.eClass().getEAllAttributes())
- {
- setProperty(editPart, attribute.getName(), attribute, model.eGet(attribute), editor);
- }
- }
- }
-
- public static void deleteAttribute(View view, DiagramDocumentEditor editor)
- {
- deleteView(view, editor);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.synchronize; + +import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.gmf.util.DawnResourceHelper; +import org.eclipse.emf.cdo.dawn.util.exceptions.EClassIncompatibleException; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.Transaction; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.draw2d.Border; +import org.eclipse.draw2d.LineBorder; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand; +import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredCreateConnectionViewAndElementCommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest.ConnectionViewAndElementDescriptor; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory; +import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.core.util.PackageUtil; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.IHintedType; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; +import org.eclipse.gmf.runtime.notation.Anchor; +import org.eclipse.gmf.runtime.notation.Bendpoints; +import org.eclipse.gmf.runtime.notation.Bounds; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +/** + * @author Martin Fluegge + */ +public class DawnChangeHelper +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnChangeHelper.class); + + protected static final java.util.Map<String, Boolean> options = new HashMap<String, Boolean>(); + + protected static final java.util.Map<Object, Object> setElementOptions = new HashMap<Object, Object>(); + static + { + options.put(Transaction.OPTION_UNPROTECTED, Boolean.FALSE); + options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE); + options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE); + } + + /** + * generic Method to create an EditPart by the given view + * + * @param node + * @param elementType + * @param diagramEP + * @return the EditPart for the newly created Node + */ + public static EditPart createNode(final Node node, IElementType elementType, DiagramEditPart diagramEP) + { + CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType, + diagramEP.getDiagramPreferencesHint()); + + Bounds bounds = (Bounds)node.getLayoutConstraint(); + + Point p = new Point(bounds.getX(), bounds.getY()); + Dimension dimension = new Dimension(bounds.getWidth(), bounds.getHeight()); + createViewRequest.setLocation(p); + createViewRequest.setSize(dimension); + + diagramEP.performRequest(createViewRequest); + + final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); + final EditPartViewer viewer = diagramEP.getViewer(); + final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); + return kep; + } + + public static EditPart createAttribute(final Node node, IElementType elementType, IGraphicalEditPart parentEditpart) + { + + if (TRACER.isEnabled()) + { + TRACER.format("ElementType: {0} semanticHint {1}", elementType, ((IHintedType)elementType).getSemanticHint()); //$NON-NLS-1$ + } + + CreateElementRequest request = new CreateElementRequest(elementType); + CreateElementRequestAdapter createElementRequestAdapter = new CreateElementRequestAdapter(request); + + ViewAndElementDescriptor viewAndElementDescriptor = new ViewAndElementDescriptor(createElementRequestAdapter, + Node.class, ((IHintedType)elementType).getSemanticHint(), + + parentEditpart.getDiagramPreferencesHint()); + + CreateViewAndElementRequest createViewRequest = new CreateViewAndElementRequest(viewAndElementDescriptor); + + // Command command = parentEditpart.getCommand(createViewRequest); + + parentEditpart.performRequest(createViewRequest); + + final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); + final EditPartViewer viewer = parentEditpart.getViewer(); + final EditPart kep = (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); + return kep; + } + + /*************************************** + * This method creates an EditPart given by the specified ElemetType and PLaces it to the give coordinates + * Element-Types could be: DawnElementTypes.Klasse_1001 + * + * @param p + * the point where the view shoudl be created + * @param elementType + * @param diagramEditor + * @return the created EditPart + ********************************************************************************************************************/ + public static EditPart createEditPart(Point p, IElementType elementType, DiagramDocumentEditor diagramEditor) + { + DiagramEditPart diagramEP = diagramEditor.getDiagramEditPart(); + + CreateViewRequest createViewRequest = CreateViewRequestFactory.getCreateShapeRequest(elementType, + diagramEP.getDiagramPreferencesHint()); + + createViewRequest.setLocation(p); + diagramEP.performRequest(createViewRequest); + + final IAdaptable viewAdapter = (IAdaptable)((List<?>)createViewRequest.getNewObject()).get(0); + final EditPartViewer viewer = diagramEP.getViewer(); + return (EditPart)viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class)); + } + + /*************************************** + * sets a property for an editpart + * + * @param editPart + * @param name + * @param object + * @param dawnDiagramEditor + ********************************************************************************************************************/ + public static void setProperty(EditPart editPart, String name, String packageUtilPropertyID, Object object, + DiagramDocumentEditor dawnDiagramEditor) + { + SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart, + packageUtilPropertyID, name, object); + + DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart(); + + diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand)); + + } + + /*************************************** + * resizes an Editpart to the given dimension + * + * @param editpart + * @param d + * dimension + ********************************************************************************************************************/ + public static void resizeEditPart(EditPart editpart, Dimension d) + { + boolean editModeEnabled = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart) + .isEditModeEnabled(); + if (!editModeEnabled) + { + ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode(); + } + + ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); + move_req.setResizeDirection(PositionConstants.SOUTH_EAST); + + Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint(); + Dimension dimensionDelta = new Dimension(d.width - b.getWidth(), d.height - b.getHeight()); + + move_req.setSizeDelta(dimensionDelta); + + Command cmd = editpart.getCommand(move_req); + if (cmd == null || !cmd.canExecute()) + { + throw new IllegalArgumentException("Command is not executable."); + } + ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); + + if (editModeEnabled) + { + ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).enableEditMode(); + } + else + { + ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart)editpart).disableEditMode(); + } + } + + /*************************************** + * moves an EdidPart to the given postione + * + * @param editpart + * @param p + ********************************************************************************************************************/ + public static void moveEditPart(EditPart editpart, Point p) + { + ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + + Bounds b = (Bounds)((Node)editpart.getModel()).getLayoutConstraint(); + Point newPoint = new Point(p.x - b.getX(), p.y - b.getY()); + move_req.setMoveDelta(newPoint); + + Command cmd = editpart.getCommand(move_req); + if (cmd == null || !cmd.canExecute()) + { + throw new IllegalArgumentException("Command is not executable."); + } + ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); + } + + /** + * Moves the Editpart from the current position to the new Vector + */ + public static void moveEditPartTo(EditPart editpart, Point p) + { + ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + move_req.setMoveDelta(p); + Command cmd = editpart.getCommand(move_req); + if (cmd == null || !cmd.canExecute()) + { + throw new IllegalArgumentException("Command is not executable."); + } + ((DiagramEditPart)editpart.getParent()).getDiagramEditDomain().getDiagramCommandStack().execute(cmd); + } + + /** + * deletes the EditPart an the concerning model element + * + * @param editPart + * @param editor + */ + public static void deleteEditPart(final EditPart editPart, DiagramDocumentEditor editor) + { + final View view = (View)editPart.getModel(); + + EObject eObject = view.getElement(); + if (eObject != null) + { + DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false); + + Request req = new EditCommandRequestWrapper(destroy); + + Command command = editPart.getCommand(req); + editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); + } + TransactionalEditingDomain domain = editor.getEditingDomain(); + if (view instanceof Edge) // also update the lists of the other client + { + domain.getCommandStack().execute(new RecordingCommand(domain) + { + @Override + public void doExecute() + { + Edge e = (Edge)view; + View source = e.getSource(); + View target = e.getTarget(); + if (source != null && target != null) + { + EObject targetElement = target.getElement(); + EObject sourceElement = source.getElement(); + + EStructuralFeature containingFeature = sourceElement.eContainingFeature(); + Collection<?> sourceCrossreferenceCollection = (Collection<?>)sourceElement.eGet(containingFeature); + sourceCrossreferenceCollection.remove(targetElement); + } + } + }); + } + ViewUtil.destroy(view); + } + + /*************************************** + * Deletes a view and it's contained element + * + * @param view + * @param editor + ********************************************************************************************************************/ + public static void deleteView(final View view, DiagramDocumentEditor editor) + { + + if (TRACER.isEnabled()) + { + TRACER.format("Deleting view {0} ", view); //$NON-NLS-1$ + } + + EObject eObject = view.getElement(); + if (eObject != null) + { + DestroyElementRequest destroy = new DestroyElementRequest(editor.getEditingDomain(), eObject, false); + + Request req = new EditCommandRequestWrapper(destroy); + + EditPart findEditPart = DawnDiagramUpdater.findEditPart(view, editor.getDiagramEditPart().getViewer()); + Command command = findEditPart.getCommand(req); + editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); + } + if (view instanceof Edge) // also update the lists of the other client + { + destroyEdge((Edge)view, editor); + } + ViewUtil.destroy(view); + } + + public static void destroyEdge(Edge edge, DiagramDocumentEditor editor) + { + EObject referenceObject = ViewUtil.resolveSemanticElement(edge.getTarget()); + EObject container = ViewUtil.resolveSemanticElement(edge.getSource()); + EditPart parentEditpart = DawnDiagramUpdater.findEditPart(edge, editor.getDiagramEditPart().getViewer()); + DestroyReferenceRequest destroyReferenceRequest = new DestroyReferenceRequest(editor.getEditingDomain(), container, + null, referenceObject, false); + Request req = new EditCommandRequestWrapper(destroyReferenceRequest); + + Command command = parentEditpart.getCommand(req); + editor.getDiagramEditDomain().getDiagramCommandStack().execute(command); + } + + /*************************************** + * creates an edge for a given elementType + * + * @param oldEdge + * @param sourceEditPart + * @param targetEditPart + * @param elementType + * @param root + * @return the newly created EditPart + ********************************************************************************************************************/ + public static EditPart createEdge(Edge oldEdge, EditPart sourceEditPart, EditPart targetEditPart, + IElementType elementType, final DiagramEditPart root) + { + if (TRACER.isEnabled()) + { + TRACER.format("Creaeting Edge from old edge {0} ", oldEdge); //$NON-NLS-1$ + } + + CreateConnectionViewAndElementRequest req = new CreateConnectionViewAndElementRequest(elementType, + ((IHintedType)elementType).getSemanticHint(), root.getDiagramPreferencesHint()); + + ICommand createConnectionCmd = new DeferredCreateConnectionViewAndElementCommand(req, new EObjectAdapter( + (EObject)sourceEditPart.getModel()), new EObjectAdapter((EObject)targetEditPart.getModel()), root.getViewer()); + + root.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(createConnectionCmd)); + + final EditPartViewer viewer = root.getViewer(); + + final EditPart ret = (EditPart)viewer.getEditPartRegistry().get( + ((ConnectionViewAndElementDescriptor)req.getNewObject()).getAdapter(View.class)); + + if (ret != null) + { + setAnchorsAndBendPoints(ret, oldEdge, root); + } + return ret; + } + + /*************************************** + * This Method sets the Anchors and Bendpoint from an old Edge to the edge of the given EditPart + * + * @param edgeEditpart + * @param oldEdge + * @param root + ********************************************************************************************************************/ + public static void setAnchorsAndBendPoints(final EditPart edgeEditpart, final Edge oldEdge, final DiagramEditPart root) + { + TransactionalEditingDomain domain = root.getEditingDomain();// getEditingDomain(); + domain.getCommandStack().execute(new RecordingCommand(domain) + { + @Override + public void doExecute() + { + Edge edge = (Edge)edgeEditpart.getModel(); + + edge.setBendpoints((Bendpoints)DawnResourceHelper.createCopy(oldEdge.getBendpoints())); + if (oldEdge.getSourceAnchor() != null) + { + edge.setSourceAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getSourceAnchor())); + } + if (oldEdge.getTargetAnchor() != null) + { + edge.setTargetAnchor((Anchor)DawnResourceHelper.createCopy(oldEdge.getTargetAnchor())); + } + + edgeEditpart.refresh(); + root.refresh(); + } + }); + } + + /** + * returns the border color from a given EditPart + * + * @param editPart + * @return the border color of the EditPart + */ + public static Color getBorderColor(EditPart editPart) + { + GraphicalEditPart e = (GraphicalEditPart)editPart; + + Border border = e.getFigure().getBorder(); + + if (border instanceof org.eclipse.draw2d.MarginBorder) + { + // MarginBorder b = ((MarginBorder) e.getFigure().getBorder()); + // if (border != null) + // { + // return b.getColor(); + // } + return null; + } + else if (border instanceof LineBorder) + { + LineBorder b = (LineBorder)e.getFigure().getBorder(); + + return b.getColor(); + } + + return null; + } + + /** + * activates a given EditPart + * + * @param editPart + */ + public static void activateEditPart(final EditPart editPart) + { + Display.getDefault().asyncExec(new Runnable() + { + public void run() + { + editPart.activate(); + AbstractGraphicalEditPart graphicalEditPart = (AbstractGraphicalEditPart)editPart; + graphicalEditPart.getFigure().setEnabled(true); + } + }); + } + + /** + * activates the diagram EditPart + * + * @param diagramEditPart + */ + public static void activateDiagramEditPart(DiagramEditPart diagramEditPart) + { + DawnChangeHelper.activateEditPart(diagramEditPart); + + for (Object e : diagramEditPart.getChildren()) + { + DawnChangeHelper.activateEditPart((EditPart)e); + } + } + + /** + * deactivates the given EditPart + * + * @param editPart + */ + public static void deactivateEditPart(final EditPart editPart) + { + Display.getDefault().asyncExec(new Runnable() + { + public void run() + { + editPart.deactivate(); + editPart.getViewer().deselect(editPart); + + AbstractGraphicalEditPart graphicalEditPart = (AbstractGraphicalEditPart)editPart; + graphicalEditPart.getFigure().setEnabled(false); + } + }); + } + + /** + * deactivates the DiagramEditPart + * + * @param diagramEditPart + */ + public static void deactivateDiagramEditPart(DiagramEditPart diagramEditPart) + { + DawnChangeHelper.deactivateEditPart(diagramEditPart); + + for (Object e : diagramEditPart.getChildren()) + { + DawnChangeHelper.deactivateEditPart((EditPart)e); + } + + } + + /** + * Deselects the given EditPart EditPart + */ + public static void deselect(final EditPart e) + { + Display.getDefault().asyncExec(new Runnable() + { + + public void run() + { + e.getViewer().deselect(e); + } + }); + } + + /** + * selects the given EditPart + * + * @param e + */ + public static void select(final EditPart e) + { + Display.getDefault().asyncExec(new Runnable() + { + + public void run() + { + e.getViewer().select(e); + } + }); + } + + /*************************************** + * sets a property for an editpart + * + * @param editPart + * @param name + * @param object + * @param dawnDiagramEditor + ********************************************************************************************************************/ + public static void setProperty(EditPart editPart, String name, EAttribute attribute, Object object, + DiagramDocumentEditor dawnDiagramEditor) + { + SetPropertyCommand setPropertyCommand = new SetPropertyCommand(dawnDiagramEditor.getEditingDomain(), editPart, + PackageUtil.getID(attribute), name, object); + DiagramEditPart diagramEP = dawnDiagramEditor.getDiagramEditPart(); + + diagramEP.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setPropertyCommand)); + } + + /*************************************** + * updates the model + * + * @param editPart + * @param model + * @param editor + ********************************************************************************************************************/ + public static void updateModel(final EditPart editPart, final EObject model, DiagramDocumentEditor editor) + { + editPart.getViewer().getEditDomain(); + View view = (View)editPart.getModel(); + final EObject element = view.getElement(); + + if (element.eClass().getName().equals("AnOperation")) // ugliest of all workarounds. Just for the prototype + { + editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain()) + { + @Override + public void doExecute() + { + try + { + DawnResourceHelper.updateEObject(element, model); + } + catch (EClassIncompatibleException e) + { + e.printStackTrace(); + } + } + }); + } + else + { + for (EAttribute attribute : element.eClass().getEAllAttributes()) + { + setProperty(editPart, attribute.getName(), attribute, model.eGet(attribute), editor); + } + } + } + + public static void deleteAttribute(View view, DiagramDocumentEditor editor) + { + deleteView(view, editor); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java index de9c97920c..abc45a71b4 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/synchronize/DawnConflictHelper.java @@ -1,107 +1,107 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.synchronize;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.CDOState;
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
-import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer;
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnConflictHelper
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnConflictHelper.class);
-
- public static boolean handleConflictedView(CDOObject cdoObject, View view, DiagramDocumentEditor editor)
- {
- boolean cdoConflict = cdoObject.cdoConflict();
- if (cdoConflict && view != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Object ({0}) is in state conflict!", cdoObject); //$NON-NLS-1$
- }
- EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, editor);
- int typeConflictLocallyDeleted = evaluateConflictType(cdoObject);
- DawnAppearancer.setEditPartConflicted(editPart, typeConflictLocallyDeleted);
- }
- return cdoConflict;
- }
-
- private static int evaluateConflictType(CDOObject cdoObject)
- {
- if (cdoObject.cdoState() == CDOState.DIRTY)
- {
- return DawnAppearancer.TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED;
- }
- return DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED;
- }
-
- public static void rollback(final DiagramDocumentEditor editor)
- {
- CDOView view = ((IDawnEditor)editor).getView();
-
- if (view != null && view instanceof CDOTransaction)
- {
- ((CDOTransaction)view).rollback();
- }
-
- editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain())
- {
- @Override
- public void doExecute()
- {
- DawnAppearancer.setEditPartDefaultAllChildren(editor.getDiagramEditPart());
- DawnDiagramUpdater.refreshEditPart(editor.getDiagramEditPart());
- }
- });
- }
-
- /**
- * TODO this method should decide whether the object is conflicted or not using special Policies
- *
- * @param object
- * @return whether the object is conflicted
- */
- public static boolean isConflicted(EObject object)
- {
- CDOObject cdoObject = CDOUtil.getCDOObject(object);
- if (cdoObject.cdoConflict())
- {
- return true;
- }
- if (object instanceof View)
- {
- CDOObject element = CDOUtil.getCDOObject(((View)object).getElement());
- if (element.cdoConflict())
- {
- return true;
- }
- }
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.synchronize; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.gmf.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.notation.View; + +/** + * @author Martin Fluegge + */ +public class DawnConflictHelper +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnConflictHelper.class); + + public static boolean handleConflictedView(CDOObject cdoObject, View view, DiagramDocumentEditor editor) + { + boolean cdoConflict = cdoObject.cdoConflict(); + if (cdoConflict && view != null) + { + if (TRACER.isEnabled()) + { + TRACER.format("Object ({0}) is in state conflict!", cdoObject); //$NON-NLS-1$ + } + EditPart editPart = DawnDiagramUpdater.createOrFindEditPartIfViewExists(view, editor); + int typeConflictLocallyDeleted = evaluateConflictType(cdoObject); + DawnAppearancer.setEditPartConflicted(editPart, typeConflictLocallyDeleted); + } + return cdoConflict; + } + + private static int evaluateConflictType(CDOObject cdoObject) + { + if (cdoObject.cdoState() == CDOState.DIRTY) + { + return DawnAppearancer.TYPE_CONFLICT_REMOTELY_AND_LOCALLY_CHANGED; + } + return DawnAppearancer.TYPE_CONFLICT_REMOTELY_DELETED; + } + + public static void rollback(final DiagramDocumentEditor editor) + { + CDOView view = ((IDawnEditor)editor).getView(); + + if (view != null && view instanceof CDOTransaction) + { + ((CDOTransaction)view).rollback(); + } + + editor.getEditingDomain().getCommandStack().execute(new RecordingCommand(editor.getEditingDomain()) + { + @Override + public void doExecute() + { + DawnAppearancer.setEditPartDefaultAllChildren(editor.getDiagramEditPart()); + DawnDiagramUpdater.refreshEditPart(editor.getDiagramEditPart()); + } + }); + } + + /** + * TODO this method should decide whether the object is conflicted or not using special Policies + * + * @param object + * @return whether the object is conflicted + */ + public static boolean isConflicted(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject.cdoConflict()) + { + return true; + } + if (object instanceof View) + { + CDOObject element = CDOUtil.getCDOObject(((View)object).getElement()); + if (element.cdoConflict()) + { + return true; + } + } + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java index cf41dedab1..bbe1638cb8 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java @@ -1,397 +1,397 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.util;
-
-import org.eclipse.emf.cdo.dawn.internal.util.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService;
-import org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.PlatformUI;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnDiagramUpdater
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnDiagramUpdater.class);
-
- public static void refresh(final IGraphicalEditPart editPart)
- {
- TransactionalEditingDomain editingDomain = editPart.getEditingDomain();
- editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain)
- {
- @Override
- public void doExecute()
- {
- editPart.refresh();
-
- if (editPart instanceof ConnectionEditPart)
- {
- DawnDiagramUpdater.refresh((IGraphicalEditPart)((ConnectionEditPart)editPart).getTarget());
- DawnDiagramUpdater.refresh((IGraphicalEditPart)((ConnectionEditPart)editPart).getSource());
- }
- }
- });
- }
-
- public static void refreshEditPart(EditPart editPart)
- {
- refeshEditpartInternal(editPart);
- }
-
- public static void refreshEditPart(final EditPart editPart, DiagramDocumentEditor editor)
- {
- try
- {
- editor.getEditingDomain().runExclusive(new Runnable()
- {
- public void run()
- {
- DawnDiagramUpdater.refreshEditPart(editPart);
- }
- });
- }
- catch (InterruptedException ex)
- {
- throw new RuntimeException(ex);
- }
- }
-
- public static void refreshEditCurrentSelected(TransactionalEditingDomain editingDomain)
- {
- editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain)
- {
-
- @Override
- protected void doExecute()
- {
- // ((ExamplediagramDocumentProvider)getDocumentProvider()).changed(getEditorInput());
- ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
- .getSelection();
- if (selection instanceof IStructuredSelection)
- {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- if (structuredSelection.size() != 1)
- {
- return;
- }
- if (structuredSelection.getFirstElement() instanceof EditPart
- && ((EditPart)structuredSelection.getFirstElement()).getModel() instanceof View)
- {
- EObject modelElement = ((View)((EditPart)structuredSelection.getFirstElement()).getModel()).getElement();
- List<?> editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
- for (Iterator<?> it = editPolicies.iterator(); it.hasNext();)
- {
- CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next();
- nextEditPolicy.refresh();
- }
- }
- }
- }
- });
- }
-
- private static void refeshEditpartInternal(EditPart editPart)
- {
- if (editPart != null)
- {
- try
- {
-
- // EObject modelElement = ((View)(editPart).getModel()).getElement();
- // List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
- // for (Iterator it = editPolicies.iterator(); it.hasNext();)
- // {
- // CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next();
- // nextEditPolicy.refresh();
- // }
-
- editPart.refresh();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- if (editPart instanceof DiagramEditPart)
- {
- for (Object connectionEditPart : ((DiagramEditPart)editPart).getConnections())
- {
- if (connectionEditPart instanceof EditPart)
- {
- if (((Edge)((EditPart)connectionEditPart).getModel()).getBendpoints() != null)
- {
- refeshEditpartInternal((EditPart)connectionEditPart);
- }
- }
- }
- }
-
- for (Object childEditPart : editPart.getChildren())
- {
- if (childEditPart instanceof EditPart)
- {
- refeshEditpartInternal((EditPart)childEditPart);
- }
- }
- }
- }
-
- public static View findViewByContainer(EObject element)
- {
- if (element instanceof View)
- {
- return (View)element;
- }
-
- if (element.eContainer() == null)
- {
- return null;
- }
-
- if (element.eContainer() instanceof View)
- {
- return (View)element.eContainer();
- }
-
- return findViewByContainer(element.eContainer());
- }
-
- public static View findViewForModel(EObject object, DiagramDocumentEditor editor)
- {
- if (object == null)
- {
- return null;
- }
- for (EObject e : editor.getDiagram().eContents())
- {
- if (e instanceof View)
- {
- View view = (View)e;
- if (object.equals(view.getElement()))
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("FOUND View: {0} for view obj: {1} ", e, object); //$NON-NLS-1$
- }
- }
- return (View)e;
- }
- }
- return null;
- }
-
- public static View getViewFromObject(EObject element, DiagramDocumentEditor editor)
- {
- View view;
-
- if (element instanceof Diagram)
- {
- view = ViewUtil.getViewContainer(element);
- return view;
- }
-
- if (element instanceof View)
- {
- view = (View)element;
- }
- else
- {
- view = DawnDiagramUpdater.findViewByContainer(element); // something which is not view (Edge or Node)
- if (view == null)
- {
- view = DawnDiagramUpdater.findViewForModel(element, editor);
- }
- }
- return view;
- }
-
- public static EditPart createOrFindEditPartIfViewExists(View view, DiagramDocumentEditor editor)
- {
- EditPart editPart = findEditPart(view, editor.getDiagramEditPart());
-
- if (view != null)
- {
- if (editPart == null) // does not exist?
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("EditPart does not exist for view {0} ", view); //$NON-NLS-1$
- }
- editPart = EditPartService.getInstance().createGraphicEditPart(view);
- setParentEditPart(editor, view, editPart);
- }
- }
- if (TRACER.isEnabled())
- {
- TRACER.format("Found EditPart: {0} ", editPart); //$NON-NLS-1$
- }
- return editPart;
- }
-
- public static void setParentEditPart(final DiagramDocumentEditor editor, View view, EditPart editPart)
- {
- View viewParent = (View)view.eContainer();
- EditPart parentEditPart = findEditPart(viewParent, editor);
- if (parentEditPart == null)
- {
- parentEditPart = editor.getDiagramEditPart();
- }
- editPart.setParent(parentEditPart);
- }
-
- public static EditPart findEditPart(View view, DiagramDocumentEditor dawnDiagramEditor)
- {
- DiagramEditPart diagramEditPart = dawnDiagramEditor.getDiagramEditPart();
-
- for (Object e : diagramEditPart.getChildren())
- {
- EditPart ep = (EditPart)e;
- if (ep.getModel().equals(view))
- {
- return ep;
- }
- }
-
- for (Object e : diagramEditPart.getConnections())
- {
- EditPart ep = (EditPart)e;
- if (ep.getModel().equals(view))
- {
- return ep;
- }
- }
- return null;
- }
-
- public static EditPart findEditPart(View view, EditPart editPart)
- {
- EditPart ret;
-
- if (editPart.getModel().equals(view))
- {
- return editPart;
- }
-
- for (Object o : editPart.getChildren())
- {
- EditPart child = (EditPart)o;
- ret = findEditPart(view, child);
- if (ret != null)
- {
- return ret;
- }
- }
-
- if (editPart instanceof DiagramEditPart)
- {
- for (Object o : ((DiagramEditPart)editPart).getConnections())
- {
- EditPart child = (EditPart)o;
- ret = findEditPart(view, child);
- if (ret != null)
- {
- return ret;
- }
- }
- }
- return null;
- }
-
- public static EditPart findEditPart(View view, EditPartViewer viewer)
- {
- return (EditPart)viewer.getEditPartRegistry().get(view);
- }
-
- /**
- * In a normal GMF environment the diagram is loaded from a xml resource. In this scenario the XMLHelper sets "null"
- * to the element of edge. Thus the value is 'set' with a null value. We do not have this in our case because the
- * element is carefully loaded from the CDO repository. But if the value is not set a getElement() call fills the
- * element with the eContainer. See <b>org.eclipse.gmf.runtime.notation.impl.ViewImpl.isSetElement()</b>. This happens
- * when the ConnectionEditPart is activated and the model registered. See
- * <b>org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.registerModel()</b>
- * <p>
- * In our scenario the Edges will be wrongly connected to the diagram itself, which makes the CanonicalEditingPolicy
- * to remove and restore the edge. Long, short story, we must 'touch' the elements here to have the element set.
- *
- * @param diagram
- */
- public static void initializeElement(Diagram diagram)
- {
- for (Object obj : diagram.getEdges())
- {
- Edge edge = (Edge)obj;
- if (!edge.isSetElement())
- {
- boolean eDeliver = edge.eDeliver();
- edge.eSetDeliver(false);
- edge.setElement(null);
- edge.eSetDeliver(eDeliver);
- }
- }
- }
-
- public static View findViewFromCrossReferences(EObject element)
- {
- CrossReferenceAdapter crossreferenceAdapter = (CrossReferenceAdapter)ECrossReferenceAdapter
- .getCrossReferenceAdapter(element);// getCrossReferenceAdapter(element);
- if (crossreferenceAdapter != null)
- {
- Collection<?> iinverseReferences = crossreferenceAdapter.getInverseReferencers(element,
- NotationPackage.eINSTANCE.getView_Element(), null);
-
- for (Object f : iinverseReferences)
- {
- if (f instanceof View)
- {
- return (View)f;
- }
- }
- }
- return null;
- }
-
- public static View findView(EObject element)
- {
- View view = DawnDiagramUpdater.findViewByContainer(element);
-
- if (view == null)
- {
- view = DawnDiagramUpdater.findViewFromCrossReferences(element);
- }
- return view;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.util; + +import org.eclipse.emf.cdo.dawn.internal.util.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService; +import org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PlatformUI; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/** + * @author Martin Fluegge + */ +public class DawnDiagramUpdater +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnDiagramUpdater.class); + + public static void refresh(final IGraphicalEditPart editPart) + { + TransactionalEditingDomain editingDomain = editPart.getEditingDomain(); + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + @Override + public void doExecute() + { + editPart.refresh(); + + if (editPart instanceof ConnectionEditPart) + { + DawnDiagramUpdater.refresh((IGraphicalEditPart)((ConnectionEditPart)editPart).getTarget()); + DawnDiagramUpdater.refresh((IGraphicalEditPart)((ConnectionEditPart)editPart).getSource()); + } + } + }); + } + + public static void refreshEditPart(EditPart editPart) + { + refeshEditpartInternal(editPart); + } + + public static void refreshEditPart(final EditPart editPart, DiagramDocumentEditor editor) + { + try + { + editor.getEditingDomain().runExclusive(new Runnable() + { + public void run() + { + DawnDiagramUpdater.refreshEditPart(editPart); + } + }); + } + catch (InterruptedException ex) + { + throw new RuntimeException(ex); + } + } + + public static void refreshEditCurrentSelected(TransactionalEditingDomain editingDomain) + { + editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) + { + + @Override + protected void doExecute() + { + // ((ExamplediagramDocumentProvider)getDocumentProvider()).changed(getEditorInput()); + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() + .getSelection(); + if (selection instanceof IStructuredSelection) + { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + if (structuredSelection.size() != 1) + { + return; + } + if (structuredSelection.getFirstElement() instanceof EditPart + && ((EditPart)structuredSelection.getFirstElement()).getModel() instanceof View) + { + EObject modelElement = ((View)((EditPart)structuredSelection.getFirstElement()).getModel()).getElement(); + List<?> editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement); + for (Iterator<?> it = editPolicies.iterator(); it.hasNext();) + { + CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next(); + nextEditPolicy.refresh(); + } + } + } + } + }); + } + + private static void refeshEditpartInternal(EditPart editPart) + { + if (editPart != null) + { + try + { + + // EObject modelElement = ((View)(editPart).getModel()).getElement(); + // List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement); + // for (Iterator it = editPolicies.iterator(); it.hasNext();) + // { + // CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next(); + // nextEditPolicy.refresh(); + // } + + editPart.refresh(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + if (editPart instanceof DiagramEditPart) + { + for (Object connectionEditPart : ((DiagramEditPart)editPart).getConnections()) + { + if (connectionEditPart instanceof EditPart) + { + if (((Edge)((EditPart)connectionEditPart).getModel()).getBendpoints() != null) + { + refeshEditpartInternal((EditPart)connectionEditPart); + } + } + } + } + + for (Object childEditPart : editPart.getChildren()) + { + if (childEditPart instanceof EditPart) + { + refeshEditpartInternal((EditPart)childEditPart); + } + } + } + } + + public static View findViewByContainer(EObject element) + { + if (element instanceof View) + { + return (View)element; + } + + if (element.eContainer() == null) + { + return null; + } + + if (element.eContainer() instanceof View) + { + return (View)element.eContainer(); + } + + return findViewByContainer(element.eContainer()); + } + + public static View findViewForModel(EObject object, DiagramDocumentEditor editor) + { + if (object == null) + { + return null; + } + for (EObject e : editor.getDiagram().eContents()) + { + if (e instanceof View) + { + View view = (View)e; + if (object.equals(view.getElement())) + { + if (TRACER.isEnabled()) + { + TRACER.format("FOUND View: {0} for view obj: {1} ", e, object); //$NON-NLS-1$ + } + } + return (View)e; + } + } + return null; + } + + public static View getViewFromObject(EObject element, DiagramDocumentEditor editor) + { + View view; + + if (element instanceof Diagram) + { + view = ViewUtil.getViewContainer(element); + return view; + } + + if (element instanceof View) + { + view = (View)element; + } + else + { + view = DawnDiagramUpdater.findViewByContainer(element); // something which is not view (Edge or Node) + if (view == null) + { + view = DawnDiagramUpdater.findViewForModel(element, editor); + } + } + return view; + } + + public static EditPart createOrFindEditPartIfViewExists(View view, DiagramDocumentEditor editor) + { + EditPart editPart = findEditPart(view, editor.getDiagramEditPart()); + + if (view != null) + { + if (editPart == null) // does not exist? + { + if (TRACER.isEnabled()) + { + TRACER.format("EditPart does not exist for view {0} ", view); //$NON-NLS-1$ + } + editPart = EditPartService.getInstance().createGraphicEditPart(view); + setParentEditPart(editor, view, editPart); + } + } + if (TRACER.isEnabled()) + { + TRACER.format("Found EditPart: {0} ", editPart); //$NON-NLS-1$ + } + return editPart; + } + + public static void setParentEditPart(final DiagramDocumentEditor editor, View view, EditPart editPart) + { + View viewParent = (View)view.eContainer(); + EditPart parentEditPart = findEditPart(viewParent, editor); + if (parentEditPart == null) + { + parentEditPart = editor.getDiagramEditPart(); + } + editPart.setParent(parentEditPart); + } + + public static EditPart findEditPart(View view, DiagramDocumentEditor dawnDiagramEditor) + { + DiagramEditPart diagramEditPart = dawnDiagramEditor.getDiagramEditPart(); + + for (Object e : diagramEditPart.getChildren()) + { + EditPart ep = (EditPart)e; + if (ep.getModel().equals(view)) + { + return ep; + } + } + + for (Object e : diagramEditPart.getConnections()) + { + EditPart ep = (EditPart)e; + if (ep.getModel().equals(view)) + { + return ep; + } + } + return null; + } + + public static EditPart findEditPart(View view, EditPart editPart) + { + EditPart ret; + + if (editPart.getModel().equals(view)) + { + return editPart; + } + + for (Object o : editPart.getChildren()) + { + EditPart child = (EditPart)o; + ret = findEditPart(view, child); + if (ret != null) + { + return ret; + } + } + + if (editPart instanceof DiagramEditPart) + { + for (Object o : ((DiagramEditPart)editPart).getConnections()) + { + EditPart child = (EditPart)o; + ret = findEditPart(view, child); + if (ret != null) + { + return ret; + } + } + } + return null; + } + + public static EditPart findEditPart(View view, EditPartViewer viewer) + { + return (EditPart)viewer.getEditPartRegistry().get(view); + } + + /** + * In a normal GMF environment the diagram is loaded from a xml resource. In this scenario the XMLHelper sets "null" + * to the element of edge. Thus the value is 'set' with a null value. We do not have this in our case because the + * element is carefully loaded from the CDO repository. But if the value is not set a getElement() call fills the + * element with the eContainer. See <b>org.eclipse.gmf.runtime.notation.impl.ViewImpl.isSetElement()</b>. This happens + * when the ConnectionEditPart is activated and the model registered. See + * <b>org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.registerModel()</b> + * <p> + * In our scenario the Edges will be wrongly connected to the diagram itself, which makes the CanonicalEditingPolicy + * to remove and restore the edge. Long, short story, we must 'touch' the elements here to have the element set. + * + * @param diagram + */ + public static void initializeElement(Diagram diagram) + { + for (Object obj : diagram.getEdges()) + { + Edge edge = (Edge)obj; + if (!edge.isSetElement()) + { + boolean eDeliver = edge.eDeliver(); + edge.eSetDeliver(false); + edge.setElement(null); + edge.eSetDeliver(eDeliver); + } + } + } + + public static View findViewFromCrossReferences(EObject element) + { + CrossReferenceAdapter crossreferenceAdapter = (CrossReferenceAdapter)ECrossReferenceAdapter + .getCrossReferenceAdapter(element);// getCrossReferenceAdapter(element); + if (crossreferenceAdapter != null) + { + Collection<?> iinverseReferences = crossreferenceAdapter.getInverseReferencers(element, + NotationPackage.eINSTANCE.getView_Element(), null); + + for (Object f : iinverseReferences) + { + if (f instanceof View) + { + return (View)f; + } + } + } + return null; + } + + public static View findView(EObject element) + { + View view = DawnDiagramUpdater.findViewByContainer(element); + + if (view == null) + { + view = DawnDiagramUpdater.findViewFromCrossReferences(element); + } + return view; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnResourceHelper.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnResourceHelper.java index 329c85b144..327e28f7be 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnResourceHelper.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnResourceHelper.java @@ -1,984 +1,984 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Martin Fluegge - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.gmf.util;
-
-/**
- *
- * @author Martin Fluegge
- */
-
-//import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-
-import org.eclipse.emf.cdo.dawn.internal.util.bundle.OM;
-import org.eclipse.emf.cdo.dawn.util.exceptions.EClassIncompatibleException;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EGenericType;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.emf.ecore.xmi.XMLHelper;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @since 1.0
- */
-public class DawnResourceHelper
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnResourceHelper.class);
-
- public static String getXmiId(EObject eObject)
- {
- Resource xmiResource = eObject.eResource();
- if (xmiResource == null)
- {
- return null;
- }
-
- return ((XMLResource)xmiResource).getID(eObject);
- }
-
- public static String getXmiId(EObject eObject, Resource xmiResource)
- {
- if (xmiResource == null)
- {
- return null;
- }
-
- return ((XMLResource)xmiResource).getID(eObject);
- }
-
- public static void setXmiId(EObject eObject, String id)
- {
- Resource xmiResource = eObject.eResource();
- if (xmiResource != null)
- {
- ((XMLResource)xmiResource).setID(eObject, id);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Could set xmi id, because object is not attached to a resource!"); //$NON-NLS-1$
- }
- }
- }
-
- // public static String resourceToString(Resource res)
- // {
- //
- // StringBuffer s = new StringBuffer();
- // Diagram dia = null;
- // for (Object o : res.getContents())
- // {
- // LOG.info(o);
- // if (o instanceof Diagram)
- // {
- // dia = (Diagram)o;
- // break;
- // }
- // }
- //
- // LOG.info("-----------------------------------------------------");
- //
- // LOG.info("Diagram" + dia + "");
- // if (dia != null)
- // {
- // try
- // {
- // for (Object o : dia.getChildren())
- // {
- // Node n = (Node)o;
- // EObject element = n.getElement();
- //
- // LOG.info(o + " (" + ResourceHelper.getXmiId((EObject)o) + ")");
- //
- // for (EAttribute attribute : element.eClass().getEAllAttributes())
- // {
- // LOG.info("\t" + attribute.getName() + ": " + element.eGet(attribute));
- // }
- //
- // LOG.info("- LayoutContraint: " + n.getLayoutConstraint() + "");
- // }
- //
- // EObject semanticConainer = dia.getElement();
- // LOG.info("SemanticConatiner" + semanticConainer + "");
- //
- // for (EObject k : semanticConainer.eContents())
- // {
- // LOG.info("Semantic Container Element: " + k + " (" + ResourceHelper.getXmiId(k) + ")" + "");
- // }
- // }
- // catch (Exception e)
- // {
- // e.printStackTrace();
- // }
- //
- // }
- // LOG.info("-----------------------------------------------------");
- // return s.toString();
- // }
-
- public static Resource loadFromFile(String file, ResourceSet rsSet)
- {
- URI uri = URI.createURI("file:/" + file);
-
- Resource res = rsSet.getResource(uri, true);
- return res;
- }
-
- public static void writeToFile(String path, String xml) throws IOException
- {
- File file = new File(path);
- FileWriter writer = new FileWriter(file);
- writer.write(xml);
- writer.close();
- }
-
- public static String saveToXML(XMLResource resource) throws IOException
- {
-
- resource.setXMLVersion("1.0");
-
- Map<Object, Object> saveOptions = new HashMap<Object, Object>();
- // options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
- // options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
- // options.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
- saveOptions.putAll(resource.getDefaultSaveOptions());
- saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE);
- saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD);
- saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
- saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
- saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
- saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE);
- saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8");
-
- final XMLHelper xmlHelper = new XMIHelperImpl(resource);
-
- XMISaveImpl x = new XMISaveImpl(xmlHelper);
-
- StringWriter sw = new StringWriter();
- x.save(resource, sw, saveOptions);
- return sw.toString();
- }
-
- public static Resource loadFromXML(String xml, ResourceSet rsSet) throws IOException
- {
- final Resource res;
-
- res = new XMIResourceImpl();
- final XMLHelper xmlHelper = new XMLHelperImpl();
- ByteArrayInputStream stringreader = new ByteArrayInputStream(xml.getBytes());
- XMILoadImpl xmiload = new XMILoadImpl(xmlHelper);
- xmiload.load((XMLResource)res, stringreader, Collections.EMPTY_MAP);
-
- /* setdummy URI */
- if (res.getURI() == null)
- {
- res.setURI(URI.createURI(""));
- }
- return res;
- }
-
- /**
- * returns the diagram from the resource if no diagram can be found it returns null.
- *
- * @param res
- * @return if it exists the diagram otherwise null
- */
- public static Diagram getDiagramFromResource(Resource res)
- {
- for (Object o : res.getContents())
- {
- if (o instanceof Diagram)
- {
- return (Diagram)o;
- }
- }
- return null;
- }
-
- /**
- * compares two eObjects by there xmi-id whether the are equal or not
- *
- * @param oldNode
- * @param newNode
- * @return true if xmi-id equal, else otherwise
- */
- public static boolean areSameObjects(EObject oldNode, EObject newNode)
- {
- String newXMI = getXmiId(newNode);
- String oldXMI = getXmiId(oldNode);
-
- if (newXMI.equals(oldXMI))
- {
- return true;
- }
- return false;
- }
-
- /**
- * returns the same Object in the other resource. The Object is identified by the xmi ID
- *
- * @param e
- * @param resource
- * @return an object in the given resource with the same xmi Id
- */
- public static EObject getSameEObjectFromOtherResource(EObject e, XMLResource resource)
- {
- String xmiId = DawnResourceHelper.getXmiId(e);
- // EObject ret = resource.getIDToEObjectMap().get(xmiId);
- EObject ret = resource.getEObject(xmiId);
- return ret;
- }
-
- /**
- * finds changed objects
- *
- * @param serverO
- * @param clientO
- * @return true if the obejcts are different
- */
- public static boolean objectsHaveChanged(Object serverO, Object clientO)
- {
- if (serverO instanceof Node && clientO instanceof Node)
- {
- Node s = (Node)serverO;
- Node c = (Node)clientO;
-
- if (objectsHaveChanged(s.getLayoutConstraint(), c.getLayoutConstraint()))
- {
- return true;
- }
- if (objectsHaveChanged(s.getElement(), c.getElement()))
- {
- return true;
- }
-
- }
- else if (serverO instanceof Edge && clientO instanceof Edge) // compare edges
- {
- Edge s = (Edge)serverO;
- Edge c = (Edge)clientO;
- RelativeBendpoints sr = (RelativeBendpoints)s.getBendpoints();
- RelativeBendpoints cr = (RelativeBendpoints)c.getBendpoints();
- if (sr.getPoints().size() != cr.getPoints().size())
- {
- return true;
- }
- int i = 0;
- for (Object o : sr.getPoints())
- {
- RelativeBendpoint sb = (RelativeBendpoint)o;
- RelativeBendpoint cb = (RelativeBendpoint)cr.getPoints().get(i);
- if (objectsHaveChanged(sb, cb))
- {
- return true;
- }
- i++;
- }
- }
- else if (serverO instanceof RelativeBendpoint && clientO instanceof RelativeBendpoint)
- {
- RelativeBendpoint sb = (RelativeBendpoint)serverO;
- RelativeBendpoint cb = (RelativeBendpoint)clientO;
- if (sb.getSourceX() != cb.getSourceX())
- {
- return true;
- }
- if (sb.getSourceY() != cb.getSourceY())
- {
- return true;
- }
- if (sb.getTargetX() != cb.getTargetX())
- {
- return true;
- }
- if (sb.getTargetY() != cb.getTargetY())
- {
- return true;
- }
- }
- else if (serverO instanceof Bounds && clientO instanceof Bounds)
- {
- if (((Bounds)serverO).getX() != ((Bounds)clientO).getX())
- {
- return true;
- }
- if (((Bounds)serverO).getY() != ((Bounds)clientO).getY())
- {
- return true;
- }
- if (((Bounds)serverO).getWidth() != ((Bounds)clientO).getWidth())
- {
- return true;
- }
- if (((Bounds)serverO).getHeight() != ((Bounds)clientO).getHeight())
- {
- return true;
- }
- }
- else if (serverO instanceof EObject && clientO instanceof EObject)
- {
- EObject s = (EObject)serverO;
- EObject c = (EObject)clientO;
-
- for (EAttribute attribute : s.eClass().getEAllAttributes())
- {
- Object co = c.eGet(attribute);
- Object so = s.eGet(attribute);
- if (co == null || so == null)
- {
- return false;
- }
- if (!co.equals(so))
- {
- return true;
- }
- }
-
- // checking size of chidlren
- if (s.eContents().size() != c.eContents().size())
- {
- return true;
- }
- int i = 0;
- // chekcing every child
- for (EObject sChild : s.eContents())
- {
- EObject cChild = c.eContents().get(i);
- if (objectsHaveChanged(sChild, cChild))
- {
- return true;
- }
- i++;
- }
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("classes are not identical...no match {0} / {1}", serverO, clientO); //$NON-NLS-1$
- }
- }
- return false;
- }
-
- public static Resource loadResourceFromFileString(String filePath, ResourceSet rsSet) throws IOException
- {
- try
- {
- File file = new File(filePath);
- FileReader reader = new FileReader(file);
- BufferedReader Ein = new BufferedReader(reader);
- String s;
- StringBuffer buff = new StringBuffer();
- while ((s = Ein.readLine()) != null) // Null-Referenz
- {
- buff.append(s + System.getProperty("line.separator"));
- }
- Ein.close();
- Resource resource = DawnResourceHelper.loadFromXML(buff.toString(), rsSet);
- return resource;
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- return null;
- }
-
- public static String readFromFile(String filePath) throws IOException
- {
- try
- {
- File file = new File(filePath);
- FileReader reader = new FileReader(file);
- BufferedReader Ein = new BufferedReader(reader);
- String s;
- StringBuffer buff = new StringBuffer();
- while ((s = Ein.readLine()) != null) // Null-Referenz
- {
- buff.append(s + System.getProperty("line.separator"));
- }
- Ein.close();
- return buff.toString();
-
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * copies the XMI-id from oldElement to new Element
- *
- * @param newElement
- * @param oldElement
- */
- public static void copyXmiId(EObject oldElement, EObject newElement)
- {
- DawnResourceHelper.setXmiId(newElement, DawnResourceHelper.getXmiId(oldElement));
- }
-
- /**
- * sets the objects id in the old resource to the new resource
- *
- * @param v
- * @param oldResource
- */
- public static void setXmiId(EObject v, XMLResource oldResource)
- {
- DawnResourceHelper.setXmiId(v, getXmiId(v, oldResource));
- }
-
- /**
- * creates a deep Copy and also copies xmi ids This method can be used if the copy should be insertet into newParent
- *
- * @param oldObject
- * @param newParent
- * @return the copy of the oldObject
- */
- @SuppressWarnings("unchecked")
- public static EObject createCopyAndInsert(EObject oldObject, EObject newParent)
- {
- EObject ret = EcoreUtil.copy(oldObject);
-
- EStructuralFeature containingFeature = oldObject.eContainingFeature();
-
- Object get = newParent.eGet(containingFeature);
- if (get instanceof Collection<?>)
- {
- Collection<EObject> list = (Collection<EObject>)get;
- list.add(ret);
- }
- else
- {
- newParent.eSet(containingFeature, ret);
- }
-
- setXmiIdForChildren(oldObject, ret);
-
- return ret;
- }
-
- public static EObject createCopy(EObject v)
- {
- EObject ret = EcoreUtil.copy(v);
- return ret;
- }
-
- private static int setXmiIdForChildren(EObject oldChild, EObject newChild)
- {
- DawnResourceHelper.setXmiId(newChild, DawnResourceHelper.getXmiId(oldChild));
- int i = 0;
- for (EObject oldC : oldChild.eContents())
- {
- EObject newC = newChild.eContents().get(i);
- setXmiIdForChildren(oldC, newC);
- i++;
- }
- return i;
- }
-
- /**
- * This method provides deep copying of all childrens xmi ids from oldObject to newObject
- *
- * @param oldObject
- * @param newObject
- */
- public static void copyXmiIds(EObject oldObject, EObject newObject)
- {
- setXmiIdForChildren(oldObject, newObject);
- }
-
- /**
- * this Method copies the values from one Element to the other curretnly only for attributes and not for references
- */
- @Deprecated
- public static void updateElement(EObject oldElement, EObject newElement)
- {
- if (oldElement == null)
- {
- newElement = oldElement;
- return;
- }
-
- for (EAttribute attribute : oldElement.eClass().getEAllAttributes())
- {
- newElement.eSet(attribute, oldElement.eGet(attribute));
- }
- }
-
- /**
- * @param leftObject
- * @param rightObject
- * @throws EClassIncompatibleException
- */
- // TODO delte removed references
- public static void updateEObject(EObject leftObject, EObject rightObject) throws EClassIncompatibleException
- {
- if (rightObject == null) // remove left Object
- {
- removeEObjectFromParent(leftObject);
- return;
- }
-
- if (!leftObject.eClass().equals(rightObject.eClass()))
- {
- throw new EClassIncompatibleException(leftObject.eClass().getName() + "("
- + DawnResourceHelper.getXmiId(leftObject) + ")" + "/" + rightObject.eClass().getName() + "("
- + DawnResourceHelper.getXmiId(leftObject) + ")");
- }
-
- updateEAttributes(leftObject, rightObject);
- updateEReferences(leftObject, rightObject);
-
- for (Object o : rightObject.eContents())
- {
- EObject rightChild = (EObject)o;
- EObject leftChild = getSameEObjectFromOtherResource(rightChild, (XMLResource)leftObject.eResource());
- if (leftChild != null)// child exists
- {
- updateEObject(leftChild, rightChild); // removes it
- }
- else
- // child must be created
- {
- if (o instanceof View)
- {
- View childView = (View)o;
- EObject childViewElement = childView.getElement();
- View childViewCopy = (View)createCopyAndInsert(rightChild, leftObject);
- if (childViewElement != null)
- {
- EObject childElementCopy = getSameEObjectFromOtherResource(childViewElement,
- (XMLResource)leftObject.eResource());
-
- updateEObject(childElementCopy, childViewElement);// not shure whether this is needed here
- childViewCopy.setElement(childElementCopy);
- }
-
- updateEObject(childViewCopy, childView);// not shure whether this is needed here
- }
- else
- {
- EObject childCopy = createCopyAndInsert(rightChild, leftObject);
- updateEObject(childCopy, rightChild); // not shure whether this is needed here
- }
- }
- }
-
- ArrayList<EObject> tempDeletionList = new ArrayList<EObject>();
-
- for (Object leftChild : leftObject.eContents())
- {
- tempDeletionList.add((EObject)leftChild);
- }
-
- // here delete all which are not in the right object
- for (EObject leftChild : tempDeletionList)
- {
- EObject rightChild = getSameEObjectFromOtherResource(leftChild, (XMLResource)rightObject.eResource());
- updateEObject(leftChild, rightChild);
- }
- }
-
- private static void removeEObjectFromParent(EObject leftObject)
- {
- if (leftObject instanceof View)
- {
- View view = (View)leftObject;
- if (view.getElement() != null)
- {
- removeEObjectFromParent(view.getElement());
- }
- }
-
- EObject parent = leftObject.eContainer();
- EStructuralFeature containingFeature = leftObject.eContainingFeature();
- if (parent != null)
- {
- Object container = parent.eGet(containingFeature);
-
- if (container instanceof Collection<?>)
- {
- Collection<?> collection = (Collection<?>)container;
- collection.remove(leftObject);
- }
- else
- {
- parent.eSet(containingFeature, null);
- }
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("arent is null, object ist still removed from parent : {0} ", leftObject); //$NON-NLS-1$
- }
- }
- }
-
- private static void updateEReferences(EObject leftObject, EObject rightObject) throws EClassIncompatibleException
- {
- for (EReference reference : rightObject.eClass().getEReferences())
- {
- updateReference(leftObject, rightObject, reference);
- }
- }
-
- @SuppressWarnings("unchecked")
- public static void updateReference(EObject leftParent, EObject rightParent, EReference reference)
- throws EClassIncompatibleException
- {
-
- if (reference.getName().equals("element"))
- {
- return;
- }
- Object leftReferenceObject = leftParent.eGet(reference);
- Object rightReferenceObject = rightParent.eGet(reference);
-
- if (leftReferenceObject != null)
- {
-
- if (leftReferenceObject instanceof Collection<?>)
- {
- Collection<EObject> leftCollection = (Collection<EObject>)leftReferenceObject;
- Collection<?> rightCollection = (Collection<?>)rightReferenceObject;
- for (Object o : rightCollection)
- {
- EObject rightCollectionChild = (EObject)o;
- EObject leftCollectionChild = getSameEObjectFromOtherResource(rightCollectionChild,
- (XMLResource)leftParent.eResource());
-
- if (leftCollectionChild == null)// create
- {
- leftCollectionChild = DawnResourceHelper.createCopy(rightCollectionChild);
- leftCollection.add(leftCollectionChild);
- }
- else
- {
- if (!rightCollectionChild.eResource().equals(leftParent.eResource())) // reference to another resource
- {
- leftCollection.remove(rightCollectionChild);
- leftCollection.add(leftCollectionChild);
- }
-
- updateEObject(leftCollectionChild, rightCollectionChild);
- }
- }
- }
- else
- {
- updateEObject((EObject)leftParent.eGet(reference), (EObject)rightParent.eGet(reference));
- }
- }
- else
- // create
- {
- if (rightReferenceObject != null)
- {
- leftParent.eSet(reference, EcoreUtil.copy((EObject)rightReferenceObject));
- }
- }
- }
-
- private static void updateEAttributes(EObject leftObject, EObject rightObject)
- {
- for (EAttribute attribute : rightObject.eClass().getEAllAttributes())
- {
- leftObject.eSet(attribute, rightObject.eGet(attribute));
- }
- }
-
- /**
- * @since 1.0
- */
- public static void deleteViewInResource(Resource resource, EObject e)
- {
- Diagram diagram = DawnResourceHelper.getDiagramFromResource(resource);
- EObject element = ((View)e).getElement();
-
- if (element != null)
- {
- removeElementFromContainer(element);
- }
-
- if (e instanceof Node)
- {
- View node = (View)e;
- diagram.removeChild(node);// ..getChildren().add(v);
- @SuppressWarnings("unchecked")
- List<Edge> toBeDeleted = new ArrayList<Edge>(node.getSourceEdges());
- for (Object obj : toBeDeleted)
- {
- Edge edge = (Edge)obj;
- deleteViewInResource(resource, edge);
- }
- }
- else if (e instanceof Edge)
- {
- Edge edge = (Edge)e;
- diagram.removeEdge(edge);// ..getChildren().add(v);
- edge.setSource(null);
- edge.setTarget(null);
- }
- }
-
- private static void removeElementFromContainer(EObject element)
- {
- EStructuralFeature containingFeature = element.eContainingFeature();
- EObject container = element.eContainer();
- if (container != null)
- {
- Object get = container.eGet(containingFeature);
- if (get instanceof Collection<?>)
- {
- Collection<?> list = (Collection<?>)get;
- list.remove(element);
- }
- else
- {
- container.eSet(containingFeature, null);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- public static void addElementToContainer(EObject element, EObject container, EStructuralFeature containingFeature)
- {
- // EStructuralFeature containingFeature = element.eContainingFeature();
- Object get = container.eGet(containingFeature);
- if (get instanceof Collection<?>)
- {
- Collection<EObject> list = (Collection<EObject>)get;
- list.add(element);
- }
- else
- {
- container.eSet(containingFeature, element);
- }
- }
-
- /**
- * checks if an element with element's id exists in the give resource
- *
- * @param res
- * @param element
- * @return true is the object with the same xmi id as element is contained in the given resource
- */
- public static boolean isObjectInResource(Resource res, EObject element)
- {
- EObject object = res.getEObject(DawnResourceHelper.getXmiId(element));
- if (object == null)
- {
- return false;
- }
-
- return true;
- }
-
- public static void printResource(Resource r)
- {
- for (EObject o : r.getContents())
- {
- printEObjectFull(o, 0);
- }
- }
-
- public static void printEObject(EObject o, int level)
- {
- for (Object child : o.eContents())
- {
- printEObject((EObject)child, level + 1);
- }
- }
-
- public static void printEObjectFull(EObject o, int level)
- {
- print(tabs(level) + "--------------------------------------------");
- print(tabs(level) + "Object: " + o);
- print(tabs(level) + "o.eContainer: " + o.eContainer());
- print(tabs(level) + "o.eContainingFeature: " + o.eContainingFeature());
- print(tabs(level) + "o.eContainmentFeature: " + o.eContainmentFeature());
- print(tabs(level) + "o.eIsProxy: " + o.eIsProxy());
- print(tabs(level) + "o.eResource: " + o.eResource());
- print(tabs(level) + "o.getClass: " + o.getClass());
- print(tabs(level) + "o.eClass: " + o.eClass());
- print(tabs(level) + "o.eCrossReferences: " + o.eCrossReferences());
-
- print(tabs(level) + "o.eClass.getClassifierID: " + o.eClass().getClassifierID());
- print(tabs(level) + "o.eClass.getFeatureCount: " + o.eClass().getFeatureCount());
- print(tabs(level) + "o.eClass.getInstanceClassName: " + o.eClass().getInstanceClassName());
- print(tabs(level) + "o.eClass.getInstanceTypeName: " + o.eClass().getInstanceTypeName());
- print(tabs(level) + "o.eClass.getName: " + o.eClass().getName());
- print(tabs(level) + "o.eClass.getDefaultValue: " + o.eClass().getDefaultValue());
- print(tabs(level) + "o.eClass.getEPackage: " + o.eClass().getEPackage());
- print(tabs(level) + "o.eClass.getEIDAttribute: " + o.eClass().getEIDAttribute());
- print(tabs(level) + "o.eClass.getInstanceClass: " + o.eClass().getInstanceClass());
-
- for (EAttribute attribute : o.eClass().getEAllAttributes())
- {
- print(tabs(level + 1) + "o.eClass.getEAllAttributes.attribute: '" + attribute.getName() + "': "
- + o.eGet(attribute));
- }
- for (EAnnotation annotation : o.eClass().getEAnnotations())
- {
- print(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation);
- }
- for (EReference containment : o.eClass().getEAllContainments())
- {
- print(tabs(level + 1) + "o.eClass().getEAllContainments().containment: '" + containment);
- }
- for (EGenericType genericSupertype : o.eClass().getEAllGenericSuperTypes())
- {
- print(tabs(level + 1) + "o.eClass().getEAllGenericSuperTypes().genericSupertype: '" + genericSupertype);
- }
- for (EOperation operation : o.eClass().getEAllOperations())
- {
- print(tabs(level + 1) + "o.eClass().getEAllOperations().operation: '" + operation);
- }
-
- for (EReference reference : o.eClass().getEAllReferences())
- {
- print(tabs(level + 1) + "o.eClass().getEAllReferences().reference: '" + reference);
- }
- for (EClass supertype : o.eClass().getEAllSuperTypes())
- {
- print(tabs(level + 1) + "o.eClass().getEAllSuperTypes().supertype: '" + supertype);
- }
- for (EStructuralFeature structuralFeature : o.eClass().getEAllStructuralFeatures())
- {
- print(tabs(level + 1) + "o.eClass().getEAllStructuralFeatures().structuralFeature: '" + structuralFeature);
- }
- for (EAnnotation annotation : o.eClass().getEAnnotations())
- {
- print(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation);
- }
- for (EAttribute attribute : o.eClass().getEAttributes())
- {
- print(tabs(level + 1) + "o.eClass().getEAttributes().annotation: '" + attribute);
- }
- for (Adapter adapter : o.eClass().eAdapters())
- {
- print(tabs(level + 1) + "o.eClass().eAdapters().adapter: '" + adapter);
- }
-
- for (Object child : o.eContents())
- {
- printEObjectFull((EObject)child, level + 2);
- }
- }
-
- private static String tabs(int level)
- {
- String s = "";
- for (int i = 0; i < level; i++)
- {
- s += "\t";
- }
- return s;
- }
-
- public static String getLocationFromResource(Resource r) throws MalformedURLException, IOException
- {
- return FileLocator.resolve(new URL(r.getURI().toString())).toString().replace("file:", "");
- }
-
- /**********************
- * finds EditPart from a View
- *
- * @param view
- * @param dawnDiagramEditor
- * @return find an Editpart for a view with the same xmi id
- ***************************************************************************************************/
- @Deprecated
- public static EditPart findEditPartByXMIId(View view, DiagramDocumentEditor dawnDiagramEditor)
- {
- DiagramEditPart diagramEditPart = dawnDiagramEditor.getDiagramEditPart();
-
- for (Object e : diagramEditPart.getChildren())
- {
- EditPart ep = (EditPart)e;
- if (DawnResourceHelper.getXmiId((EObject)ep.getModel()).equals(DawnResourceHelper.getXmiId(view)))
- {
- return ep;
- }
- }
-
- for (Object e : diagramEditPart.getConnections())
- {
- EditPart ep = (EditPart)e;
- if (DawnResourceHelper.getXmiId((EObject)ep.getModel()).equals(DawnResourceHelper.getXmiId(view)))
- {
- return ep;
- }
- }
- return null;
- }
-
- protected static void print(String s)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace(s);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.gmf.util; + +/** + * + * @author Martin Fluegge + */ + +//import org.eclipse.emf.cdo.internal.dawn.bundle.OM; + +import org.eclipse.emf.cdo.dawn.internal.util.bundle.OM; +import org.eclipse.emf.cdo.dawn.util.exceptions.EClassIncompatibleException; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EGenericType; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.xmi.XMIResource; +import org.eclipse.emf.ecore.xmi.XMLHelper; +import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl; +import org.eclipse.emf.ecore.xmi.impl.XMILoadImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.emf.ecore.xmi.impl.XMISaveImpl; +import org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.notation.Bounds; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.RelativeBendpoints; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @since 1.0 + */ +public class DawnResourceHelper +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnResourceHelper.class); + + public static String getXmiId(EObject eObject) + { + Resource xmiResource = eObject.eResource(); + if (xmiResource == null) + { + return null; + } + + return ((XMLResource)xmiResource).getID(eObject); + } + + public static String getXmiId(EObject eObject, Resource xmiResource) + { + if (xmiResource == null) + { + return null; + } + + return ((XMLResource)xmiResource).getID(eObject); + } + + public static void setXmiId(EObject eObject, String id) + { + Resource xmiResource = eObject.eResource(); + if (xmiResource != null) + { + ((XMLResource)xmiResource).setID(eObject, id); + } + else + { + if (TRACER.isEnabled()) + { + TRACER.trace("Could set xmi id, because object is not attached to a resource!"); //$NON-NLS-1$ + } + } + } + + // public static String resourceToString(Resource res) + // { + // + // StringBuffer s = new StringBuffer(); + // Diagram dia = null; + // for (Object o : res.getContents()) + // { + // LOG.info(o); + // if (o instanceof Diagram) + // { + // dia = (Diagram)o; + // break; + // } + // } + // + // LOG.info("-----------------------------------------------------"); + // + // LOG.info("Diagram" + dia + ""); + // if (dia != null) + // { + // try + // { + // for (Object o : dia.getChildren()) + // { + // Node n = (Node)o; + // EObject element = n.getElement(); + // + // LOG.info(o + " (" + ResourceHelper.getXmiId((EObject)o) + ")"); + // + // for (EAttribute attribute : element.eClass().getEAllAttributes()) + // { + // LOG.info("\t" + attribute.getName() + ": " + element.eGet(attribute)); + // } + // + // LOG.info("- LayoutContraint: " + n.getLayoutConstraint() + ""); + // } + // + // EObject semanticConainer = dia.getElement(); + // LOG.info("SemanticConatiner" + semanticConainer + ""); + // + // for (EObject k : semanticConainer.eContents()) + // { + // LOG.info("Semantic Container Element: " + k + " (" + ResourceHelper.getXmiId(k) + ")" + ""); + // } + // } + // catch (Exception e) + // { + // e.printStackTrace(); + // } + // + // } + // LOG.info("-----------------------------------------------------"); + // return s.toString(); + // } + + public static Resource loadFromFile(String file, ResourceSet rsSet) + { + URI uri = URI.createURI("file:/" + file); + + Resource res = rsSet.getResource(uri, true); + return res; + } + + public static void writeToFile(String path, String xml) throws IOException + { + File file = new File(path); + FileWriter writer = new FileWriter(file); + writer.write(xml); + writer.close(); + } + + public static String saveToXML(XMLResource resource) throws IOException + { + + resource.setXMLVersion("1.0"); + + Map<Object, Object> saveOptions = new HashMap<Object, Object>(); + // options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); + // options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + // options.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + saveOptions.putAll(resource.getDefaultSaveOptions()); + saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE); + saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD); + saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE); + saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE); + saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE); + saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8"); + + final XMLHelper xmlHelper = new XMIHelperImpl(resource); + + XMISaveImpl x = new XMISaveImpl(xmlHelper); + + StringWriter sw = new StringWriter(); + x.save(resource, sw, saveOptions); + return sw.toString(); + } + + public static Resource loadFromXML(String xml, ResourceSet rsSet) throws IOException + { + final Resource res; + + res = new XMIResourceImpl(); + final XMLHelper xmlHelper = new XMLHelperImpl(); + ByteArrayInputStream stringreader = new ByteArrayInputStream(xml.getBytes()); + XMILoadImpl xmiload = new XMILoadImpl(xmlHelper); + xmiload.load((XMLResource)res, stringreader, Collections.EMPTY_MAP); + + /* setdummy URI */ + if (res.getURI() == null) + { + res.setURI(URI.createURI("")); + } + return res; + } + + /** + * returns the diagram from the resource if no diagram can be found it returns null. + * + * @param res + * @return if it exists the diagram otherwise null + */ + public static Diagram getDiagramFromResource(Resource res) + { + for (Object o : res.getContents()) + { + if (o instanceof Diagram) + { + return (Diagram)o; + } + } + return null; + } + + /** + * compares two eObjects by there xmi-id whether the are equal or not + * + * @param oldNode + * @param newNode + * @return true if xmi-id equal, else otherwise + */ + public static boolean areSameObjects(EObject oldNode, EObject newNode) + { + String newXMI = getXmiId(newNode); + String oldXMI = getXmiId(oldNode); + + if (newXMI.equals(oldXMI)) + { + return true; + } + return false; + } + + /** + * returns the same Object in the other resource. The Object is identified by the xmi ID + * + * @param e + * @param resource + * @return an object in the given resource with the same xmi Id + */ + public static EObject getSameEObjectFromOtherResource(EObject e, XMLResource resource) + { + String xmiId = DawnResourceHelper.getXmiId(e); + // EObject ret = resource.getIDToEObjectMap().get(xmiId); + EObject ret = resource.getEObject(xmiId); + return ret; + } + + /** + * finds changed objects + * + * @param serverO + * @param clientO + * @return true if the obejcts are different + */ + public static boolean objectsHaveChanged(Object serverO, Object clientO) + { + if (serverO instanceof Node && clientO instanceof Node) + { + Node s = (Node)serverO; + Node c = (Node)clientO; + + if (objectsHaveChanged(s.getLayoutConstraint(), c.getLayoutConstraint())) + { + return true; + } + if (objectsHaveChanged(s.getElement(), c.getElement())) + { + return true; + } + + } + else if (serverO instanceof Edge && clientO instanceof Edge) // compare edges + { + Edge s = (Edge)serverO; + Edge c = (Edge)clientO; + RelativeBendpoints sr = (RelativeBendpoints)s.getBendpoints(); + RelativeBendpoints cr = (RelativeBendpoints)c.getBendpoints(); + if (sr.getPoints().size() != cr.getPoints().size()) + { + return true; + } + int i = 0; + for (Object o : sr.getPoints()) + { + RelativeBendpoint sb = (RelativeBendpoint)o; + RelativeBendpoint cb = (RelativeBendpoint)cr.getPoints().get(i); + if (objectsHaveChanged(sb, cb)) + { + return true; + } + i++; + } + } + else if (serverO instanceof RelativeBendpoint && clientO instanceof RelativeBendpoint) + { + RelativeBendpoint sb = (RelativeBendpoint)serverO; + RelativeBendpoint cb = (RelativeBendpoint)clientO; + if (sb.getSourceX() != cb.getSourceX()) + { + return true; + } + if (sb.getSourceY() != cb.getSourceY()) + { + return true; + } + if (sb.getTargetX() != cb.getTargetX()) + { + return true; + } + if (sb.getTargetY() != cb.getTargetY()) + { + return true; + } + } + else if (serverO instanceof Bounds && clientO instanceof Bounds) + { + if (((Bounds)serverO).getX() != ((Bounds)clientO).getX()) + { + return true; + } + if (((Bounds)serverO).getY() != ((Bounds)clientO).getY()) + { + return true; + } + if (((Bounds)serverO).getWidth() != ((Bounds)clientO).getWidth()) + { + return true; + } + if (((Bounds)serverO).getHeight() != ((Bounds)clientO).getHeight()) + { + return true; + } + } + else if (serverO instanceof EObject && clientO instanceof EObject) + { + EObject s = (EObject)serverO; + EObject c = (EObject)clientO; + + for (EAttribute attribute : s.eClass().getEAllAttributes()) + { + Object co = c.eGet(attribute); + Object so = s.eGet(attribute); + if (co == null || so == null) + { + return false; + } + if (!co.equals(so)) + { + return true; + } + } + + // checking size of chidlren + if (s.eContents().size() != c.eContents().size()) + { + return true; + } + int i = 0; + // chekcing every child + for (EObject sChild : s.eContents()) + { + EObject cChild = c.eContents().get(i); + if (objectsHaveChanged(sChild, cChild)) + { + return true; + } + i++; + } + } + else + { + if (TRACER.isEnabled()) + { + TRACER.format("classes are not identical...no match {0} / {1}", serverO, clientO); //$NON-NLS-1$ + } + } + return false; + } + + public static Resource loadResourceFromFileString(String filePath, ResourceSet rsSet) throws IOException + { + try + { + File file = new File(filePath); + FileReader reader = new FileReader(file); + BufferedReader Ein = new BufferedReader(reader); + String s; + StringBuffer buff = new StringBuffer(); + while ((s = Ein.readLine()) != null) // Null-Referenz + { + buff.append(s + System.getProperty("line.separator")); + } + Ein.close(); + Resource resource = DawnResourceHelper.loadFromXML(buff.toString(), rsSet); + return resource; + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + return null; + } + + public static String readFromFile(String filePath) throws IOException + { + try + { + File file = new File(filePath); + FileReader reader = new FileReader(file); + BufferedReader Ein = new BufferedReader(reader); + String s; + StringBuffer buff = new StringBuffer(); + while ((s = Ein.readLine()) != null) // Null-Referenz + { + buff.append(s + System.getProperty("line.separator")); + } + Ein.close(); + return buff.toString(); + + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + return null; + } + + /** + * copies the XMI-id from oldElement to new Element + * + * @param newElement + * @param oldElement + */ + public static void copyXmiId(EObject oldElement, EObject newElement) + { + DawnResourceHelper.setXmiId(newElement, DawnResourceHelper.getXmiId(oldElement)); + } + + /** + * sets the objects id in the old resource to the new resource + * + * @param v + * @param oldResource + */ + public static void setXmiId(EObject v, XMLResource oldResource) + { + DawnResourceHelper.setXmiId(v, getXmiId(v, oldResource)); + } + + /** + * creates a deep Copy and also copies xmi ids This method can be used if the copy should be insertet into newParent + * + * @param oldObject + * @param newParent + * @return the copy of the oldObject + */ + @SuppressWarnings("unchecked") + public static EObject createCopyAndInsert(EObject oldObject, EObject newParent) + { + EObject ret = EcoreUtil.copy(oldObject); + + EStructuralFeature containingFeature = oldObject.eContainingFeature(); + + Object get = newParent.eGet(containingFeature); + if (get instanceof Collection<?>) + { + Collection<EObject> list = (Collection<EObject>)get; + list.add(ret); + } + else + { + newParent.eSet(containingFeature, ret); + } + + setXmiIdForChildren(oldObject, ret); + + return ret; + } + + public static EObject createCopy(EObject v) + { + EObject ret = EcoreUtil.copy(v); + return ret; + } + + private static int setXmiIdForChildren(EObject oldChild, EObject newChild) + { + DawnResourceHelper.setXmiId(newChild, DawnResourceHelper.getXmiId(oldChild)); + int i = 0; + for (EObject oldC : oldChild.eContents()) + { + EObject newC = newChild.eContents().get(i); + setXmiIdForChildren(oldC, newC); + i++; + } + return i; + } + + /** + * This method provides deep copying of all childrens xmi ids from oldObject to newObject + * + * @param oldObject + * @param newObject + */ + public static void copyXmiIds(EObject oldObject, EObject newObject) + { + setXmiIdForChildren(oldObject, newObject); + } + + /** + * this Method copies the values from one Element to the other curretnly only for attributes and not for references + */ + @Deprecated + public static void updateElement(EObject oldElement, EObject newElement) + { + if (oldElement == null) + { + newElement = oldElement; + return; + } + + for (EAttribute attribute : oldElement.eClass().getEAllAttributes()) + { + newElement.eSet(attribute, oldElement.eGet(attribute)); + } + } + + /** + * @param leftObject + * @param rightObject + * @throws EClassIncompatibleException + */ + // TODO delte removed references + public static void updateEObject(EObject leftObject, EObject rightObject) throws EClassIncompatibleException + { + if (rightObject == null) // remove left Object + { + removeEObjectFromParent(leftObject); + return; + } + + if (!leftObject.eClass().equals(rightObject.eClass())) + { + throw new EClassIncompatibleException(leftObject.eClass().getName() + "(" + + DawnResourceHelper.getXmiId(leftObject) + ")" + "/" + rightObject.eClass().getName() + "(" + + DawnResourceHelper.getXmiId(leftObject) + ")"); + } + + updateEAttributes(leftObject, rightObject); + updateEReferences(leftObject, rightObject); + + for (Object o : rightObject.eContents()) + { + EObject rightChild = (EObject)o; + EObject leftChild = getSameEObjectFromOtherResource(rightChild, (XMLResource)leftObject.eResource()); + if (leftChild != null)// child exists + { + updateEObject(leftChild, rightChild); // removes it + } + else + // child must be created + { + if (o instanceof View) + { + View childView = (View)o; + EObject childViewElement = childView.getElement(); + View childViewCopy = (View)createCopyAndInsert(rightChild, leftObject); + if (childViewElement != null) + { + EObject childElementCopy = getSameEObjectFromOtherResource(childViewElement, + (XMLResource)leftObject.eResource()); + + updateEObject(childElementCopy, childViewElement);// not shure whether this is needed here + childViewCopy.setElement(childElementCopy); + } + + updateEObject(childViewCopy, childView);// not shure whether this is needed here + } + else + { + EObject childCopy = createCopyAndInsert(rightChild, leftObject); + updateEObject(childCopy, rightChild); // not shure whether this is needed here + } + } + } + + ArrayList<EObject> tempDeletionList = new ArrayList<EObject>(); + + for (Object leftChild : leftObject.eContents()) + { + tempDeletionList.add((EObject)leftChild); + } + + // here delete all which are not in the right object + for (EObject leftChild : tempDeletionList) + { + EObject rightChild = getSameEObjectFromOtherResource(leftChild, (XMLResource)rightObject.eResource()); + updateEObject(leftChild, rightChild); + } + } + + private static void removeEObjectFromParent(EObject leftObject) + { + if (leftObject instanceof View) + { + View view = (View)leftObject; + if (view.getElement() != null) + { + removeEObjectFromParent(view.getElement()); + } + } + + EObject parent = leftObject.eContainer(); + EStructuralFeature containingFeature = leftObject.eContainingFeature(); + if (parent != null) + { + Object container = parent.eGet(containingFeature); + + if (container instanceof Collection<?>) + { + Collection<?> collection = (Collection<?>)container; + collection.remove(leftObject); + } + else + { + parent.eSet(containingFeature, null); + } + } + else + { + if (TRACER.isEnabled()) + { + TRACER.format("arent is null, object ist still removed from parent : {0} ", leftObject); //$NON-NLS-1$ + } + } + } + + private static void updateEReferences(EObject leftObject, EObject rightObject) throws EClassIncompatibleException + { + for (EReference reference : rightObject.eClass().getEReferences()) + { + updateReference(leftObject, rightObject, reference); + } + } + + @SuppressWarnings("unchecked") + public static void updateReference(EObject leftParent, EObject rightParent, EReference reference) + throws EClassIncompatibleException + { + + if (reference.getName().equals("element")) + { + return; + } + Object leftReferenceObject = leftParent.eGet(reference); + Object rightReferenceObject = rightParent.eGet(reference); + + if (leftReferenceObject != null) + { + + if (leftReferenceObject instanceof Collection<?>) + { + Collection<EObject> leftCollection = (Collection<EObject>)leftReferenceObject; + Collection<?> rightCollection = (Collection<?>)rightReferenceObject; + for (Object o : rightCollection) + { + EObject rightCollectionChild = (EObject)o; + EObject leftCollectionChild = getSameEObjectFromOtherResource(rightCollectionChild, + (XMLResource)leftParent.eResource()); + + if (leftCollectionChild == null)// create + { + leftCollectionChild = DawnResourceHelper.createCopy(rightCollectionChild); + leftCollection.add(leftCollectionChild); + } + else + { + if (!rightCollectionChild.eResource().equals(leftParent.eResource())) // reference to another resource + { + leftCollection.remove(rightCollectionChild); + leftCollection.add(leftCollectionChild); + } + + updateEObject(leftCollectionChild, rightCollectionChild); + } + } + } + else + { + updateEObject((EObject)leftParent.eGet(reference), (EObject)rightParent.eGet(reference)); + } + } + else + // create + { + if (rightReferenceObject != null) + { + leftParent.eSet(reference, EcoreUtil.copy((EObject)rightReferenceObject)); + } + } + } + + private static void updateEAttributes(EObject leftObject, EObject rightObject) + { + for (EAttribute attribute : rightObject.eClass().getEAllAttributes()) + { + leftObject.eSet(attribute, rightObject.eGet(attribute)); + } + } + + /** + * @since 1.0 + */ + public static void deleteViewInResource(Resource resource, EObject e) + { + Diagram diagram = DawnResourceHelper.getDiagramFromResource(resource); + EObject element = ((View)e).getElement(); + + if (element != null) + { + removeElementFromContainer(element); + } + + if (e instanceof Node) + { + View node = (View)e; + diagram.removeChild(node);// ..getChildren().add(v); + @SuppressWarnings("unchecked") + List<Edge> toBeDeleted = new ArrayList<Edge>(node.getSourceEdges()); + for (Object obj : toBeDeleted) + { + Edge edge = (Edge)obj; + deleteViewInResource(resource, edge); + } + } + else if (e instanceof Edge) + { + Edge edge = (Edge)e; + diagram.removeEdge(edge);// ..getChildren().add(v); + edge.setSource(null); + edge.setTarget(null); + } + } + + private static void removeElementFromContainer(EObject element) + { + EStructuralFeature containingFeature = element.eContainingFeature(); + EObject container = element.eContainer(); + if (container != null) + { + Object get = container.eGet(containingFeature); + if (get instanceof Collection<?>) + { + Collection<?> list = (Collection<?>)get; + list.remove(element); + } + else + { + container.eSet(containingFeature, null); + } + } + } + + @SuppressWarnings("unchecked") + public static void addElementToContainer(EObject element, EObject container, EStructuralFeature containingFeature) + { + // EStructuralFeature containingFeature = element.eContainingFeature(); + Object get = container.eGet(containingFeature); + if (get instanceof Collection<?>) + { + Collection<EObject> list = (Collection<EObject>)get; + list.add(element); + } + else + { + container.eSet(containingFeature, element); + } + } + + /** + * checks if an element with element's id exists in the give resource + * + * @param res + * @param element + * @return true is the object with the same xmi id as element is contained in the given resource + */ + public static boolean isObjectInResource(Resource res, EObject element) + { + EObject object = res.getEObject(DawnResourceHelper.getXmiId(element)); + if (object == null) + { + return false; + } + + return true; + } + + public static void printResource(Resource r) + { + for (EObject o : r.getContents()) + { + printEObjectFull(o, 0); + } + } + + public static void printEObject(EObject o, int level) + { + for (Object child : o.eContents()) + { + printEObject((EObject)child, level + 1); + } + } + + public static void printEObjectFull(EObject o, int level) + { + print(tabs(level) + "--------------------------------------------"); + print(tabs(level) + "Object: " + o); + print(tabs(level) + "o.eContainer: " + o.eContainer()); + print(tabs(level) + "o.eContainingFeature: " + o.eContainingFeature()); + print(tabs(level) + "o.eContainmentFeature: " + o.eContainmentFeature()); + print(tabs(level) + "o.eIsProxy: " + o.eIsProxy()); + print(tabs(level) + "o.eResource: " + o.eResource()); + print(tabs(level) + "o.getClass: " + o.getClass()); + print(tabs(level) + "o.eClass: " + o.eClass()); + print(tabs(level) + "o.eCrossReferences: " + o.eCrossReferences()); + + print(tabs(level) + "o.eClass.getClassifierID: " + o.eClass().getClassifierID()); + print(tabs(level) + "o.eClass.getFeatureCount: " + o.eClass().getFeatureCount()); + print(tabs(level) + "o.eClass.getInstanceClassName: " + o.eClass().getInstanceClassName()); + print(tabs(level) + "o.eClass.getInstanceTypeName: " + o.eClass().getInstanceTypeName()); + print(tabs(level) + "o.eClass.getName: " + o.eClass().getName()); + print(tabs(level) + "o.eClass.getDefaultValue: " + o.eClass().getDefaultValue()); + print(tabs(level) + "o.eClass.getEPackage: " + o.eClass().getEPackage()); + print(tabs(level) + "o.eClass.getEIDAttribute: " + o.eClass().getEIDAttribute()); + print(tabs(level) + "o.eClass.getInstanceClass: " + o.eClass().getInstanceClass()); + + for (EAttribute attribute : o.eClass().getEAllAttributes()) + { + print(tabs(level + 1) + "o.eClass.getEAllAttributes.attribute: '" + attribute.getName() + "': " + + o.eGet(attribute)); + } + for (EAnnotation annotation : o.eClass().getEAnnotations()) + { + print(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); + } + for (EReference containment : o.eClass().getEAllContainments()) + { + print(tabs(level + 1) + "o.eClass().getEAllContainments().containment: '" + containment); + } + for (EGenericType genericSupertype : o.eClass().getEAllGenericSuperTypes()) + { + print(tabs(level + 1) + "o.eClass().getEAllGenericSuperTypes().genericSupertype: '" + genericSupertype); + } + for (EOperation operation : o.eClass().getEAllOperations()) + { + print(tabs(level + 1) + "o.eClass().getEAllOperations().operation: '" + operation); + } + + for (EReference reference : o.eClass().getEAllReferences()) + { + print(tabs(level + 1) + "o.eClass().getEAllReferences().reference: '" + reference); + } + for (EClass supertype : o.eClass().getEAllSuperTypes()) + { + print(tabs(level + 1) + "o.eClass().getEAllSuperTypes().supertype: '" + supertype); + } + for (EStructuralFeature structuralFeature : o.eClass().getEAllStructuralFeatures()) + { + print(tabs(level + 1) + "o.eClass().getEAllStructuralFeatures().structuralFeature: '" + structuralFeature); + } + for (EAnnotation annotation : o.eClass().getEAnnotations()) + { + print(tabs(level + 1) + "o.eClass().getEAnnotations().annotation: '" + annotation); + } + for (EAttribute attribute : o.eClass().getEAttributes()) + { + print(tabs(level + 1) + "o.eClass().getEAttributes().annotation: '" + attribute); + } + for (Adapter adapter : o.eClass().eAdapters()) + { + print(tabs(level + 1) + "o.eClass().eAdapters().adapter: '" + adapter); + } + + for (Object child : o.eContents()) + { + printEObjectFull((EObject)child, level + 2); + } + } + + private static String tabs(int level) + { + String s = ""; + for (int i = 0; i < level; i++) + { + s += "\t"; + } + return s; + } + + public static String getLocationFromResource(Resource r) throws MalformedURLException, IOException + { + return FileLocator.resolve(new URL(r.getURI().toString())).toString().replace("file:", ""); + } + + /********************** + * finds EditPart from a View + * + * @param view + * @param dawnDiagramEditor + * @return find an Editpart for a view with the same xmi id + ***************************************************************************************************/ + @Deprecated + public static EditPart findEditPartByXMIId(View view, DiagramDocumentEditor dawnDiagramEditor) + { + DiagramEditPart diagramEditPart = dawnDiagramEditor.getDiagramEditPart(); + + for (Object e : diagramEditPart.getChildren()) + { + EditPart ep = (EditPart)e; + if (DawnResourceHelper.getXmiId((EObject)ep.getModel()).equals(DawnResourceHelper.getXmiId(view))) + { + return ep; + } + } + + for (Object e : diagramEditPart.getConnections()) + { + EditPart ep = (EditPart)e; + if (DawnResourceHelper.getXmiId((EObject)ep.getModel()).equals(DawnResourceHelper.getXmiId(view))) + { + return ep; + } + } + return null; + } + + protected static void print(String s) + { + if (TRACER.isEnabled()) + { + TRACER.trace(s); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnDiagramEditingDomainFactory.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnDiagramEditingDomainFactory.java index 227fbb0313..ded12589fb 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnDiagramEditingDomainFactory.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnDiagramEditingDomainFactory.java @@ -1,114 +1,114 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.transaction;
-
-import org.eclipse.emf.cdo.dawn.gmf.resources.DawnPathmapManager;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.transaction.TransactionalCommandStack;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.impl.TransactionChangeRecorder;
-import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
-import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl;
-
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory;
-
-public class DawnDiagramEditingDomainFactory extends DiagramEditingDomainFactory
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnDiagramEditingDomainFactory.class);
-
- private static DawnDiagramEditingDomainFactory instance = new DawnDiagramEditingDomainFactory();
-
- protected static class DawnDiagramEditingDomain extends DiagramEditingDomain
- {
- public DawnDiagramEditingDomain(AdapterFactory adapterFactory, ResourceSet resourceSet)
- {
- super(adapterFactory, resourceSet);
- }
-
- public DawnDiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack,
- ResourceSet resourceSet)
- {
- super(adapterFactory, stack, resourceSet);
- }
-
- public DawnDiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack)
- {
- super(adapterFactory, stack);
- }
-
- public DawnDiagramEditingDomain(AdapterFactory adapterFactory)
- {
- super(adapterFactory);
- }
-
- /**
- * override the TransactionChangeRecorder to suppress the write asserts which are not need with CDO
- */
- @Override
- protected TransactionChangeRecorder createChangeRecorder(ResourceSet rset)
- {
- return new DawnTransactionChangeRecorder(this, rset);
- }
- }
-
- @Override
- public TransactionalEditingDomain createEditingDomain(IOperationHistory history)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Creating DawnTransactionalEditingDomain using DawnDiagramEditingDomainFactory"); //$NON-NLS-1$
- }
- WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history);
-
- TransactionalEditingDomain result = new DawnDiagramEditingDomain(new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack);
-
- mapResourceSet(result);
-
- configure(result);
- return result;
- }
-
- @Override
- public TransactionalEditingDomain createEditingDomain(ResourceSet rset, IOperationHistory history)
- {
- WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history);
-
- TransactionalEditingDomain result = new DawnDiagramEditingDomain(new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack, rset);
-
- mapResourceSet(result);
- configure(result);
- return result;
- }
-
- @Override
- protected void configure(final TransactionalEditingDomain domain)
- {
- super.configure(domain);
-
- final ResourceSet rset = domain.getResourceSet();
- DawnPathmapManager.removePathMapMananger(rset.eAdapters());
- rset.eAdapters().add(new DawnPathmapManager());
- }
-
- public static WorkspaceEditingDomainFactory getInstance()
- {
- return instance;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.transaction; + +import org.eclipse.emf.cdo.dawn.gmf.resources.DawnPathmapManager; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.transaction.TransactionalCommandStack; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.impl.TransactionChangeRecorder; +import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; +import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl; + +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory; + +public class DawnDiagramEditingDomainFactory extends DiagramEditingDomainFactory +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnDiagramEditingDomainFactory.class); + + private static DawnDiagramEditingDomainFactory instance = new DawnDiagramEditingDomainFactory(); + + protected static class DawnDiagramEditingDomain extends DiagramEditingDomain + { + public DawnDiagramEditingDomain(AdapterFactory adapterFactory, ResourceSet resourceSet) + { + super(adapterFactory, resourceSet); + } + + public DawnDiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack, + ResourceSet resourceSet) + { + super(adapterFactory, stack, resourceSet); + } + + public DawnDiagramEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack) + { + super(adapterFactory, stack); + } + + public DawnDiagramEditingDomain(AdapterFactory adapterFactory) + { + super(adapterFactory); + } + + /** + * override the TransactionChangeRecorder to suppress the write asserts which are not need with CDO + */ + @Override + protected TransactionChangeRecorder createChangeRecorder(ResourceSet rset) + { + return new DawnTransactionChangeRecorder(this, rset); + } + } + + @Override + public TransactionalEditingDomain createEditingDomain(IOperationHistory history) + { + if (TRACER.isEnabled()) + { + TRACER.trace("Creating DawnTransactionalEditingDomain using DawnDiagramEditingDomainFactory"); //$NON-NLS-1$ + } + WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); + + TransactionalEditingDomain result = new DawnDiagramEditingDomain(new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack); + + mapResourceSet(result); + + configure(result); + return result; + } + + @Override + public TransactionalEditingDomain createEditingDomain(ResourceSet rset, IOperationHistory history) + { + WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); + + TransactionalEditingDomain result = new DawnDiagramEditingDomain(new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack, rset); + + mapResourceSet(result); + configure(result); + return result; + } + + @Override + protected void configure(final TransactionalEditingDomain domain) + { + super.configure(domain); + + final ResourceSet rset = domain.getResourceSet(); + DawnPathmapManager.removePathMapMananger(rset.eAdapters()); + rset.eAdapters().add(new DawnPathmapManager()); + } + + public static WorkspaceEditingDomainFactory getInstance() + { + return instance; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnGMFEditingDomainFactory.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnGMFEditingDomainFactory.java index 4823e63839..d7ae9c49ec 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnGMFEditingDomainFactory.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/transaction/DawnGMFEditingDomainFactory.java @@ -1,106 +1,106 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.dawn.transaction;
-
-import org.eclipse.emf.cdo.dawn.gmf.resources.DawnPathmapManager;
-import org.eclipse.emf.cdo.internal.dawn.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
-import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl;
-
-import org.eclipse.core.commands.operations.IOperationHistory;
-import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
-
-public class DawnGMFEditingDomainFactory extends GMFEditingDomainFactory
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnGMFEditingDomainFactory.class);
-
- private static DawnGMFEditingDomainFactory instance = new DawnGMFEditingDomainFactory();
-
- @Override
- public TransactionalEditingDomain createEditingDomain()
- {
- TransactionalEditingDomain result = super.createEditingDomain();
- configure(result);
- return result;
- }
-
- @Override
- public TransactionalEditingDomain createEditingDomain(ResourceSet rset)
- {
- TransactionalEditingDomain result = super.createEditingDomain(rset);
- configure(result);
- return result;
- }
-
- /**
- * overrides WorkspaceEditingDomainFactory method
- */
- @Override
- public synchronized TransactionalEditingDomain createEditingDomain(IOperationHistory history)
- {
- WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history);
- stack.setResourceUndoContextPolicy(getResourceUndoContextPolicy());
-
- TransactionalEditingDomain result = new DawnTransactionalEditingDomainImpl(new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack);
-
- mapResourceSet(result);
- // configures as the GMFEditingDomainFactory would do
- configure(result);
-
- return result;
- }
-
- /**
- * overrides WorkspaceEditingDomainFactory method
- */
- @Override
- public synchronized TransactionalEditingDomain createEditingDomain(ResourceSet rset, IOperationHistory history)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Creating DawnTransactionalEditingDomain using DawnDiagramEditingDomainFactory"); //$NON-NLS-1$
- }
- WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history);
- stack.setResourceUndoContextPolicy(getResourceUndoContextPolicy());
-
- TransactionalEditingDomain result = new DawnTransactionalEditingDomainImpl(new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack, rset);
-
- mapResourceSet(result);
-
- // configures as the GMFEditingDomainFactory would do
- configure(result);
-
- return result;
- }
-
- public static WorkspaceEditingDomainFactory getInstance()
- {
- return instance;
- }
-
- @Override
- protected void configure(final TransactionalEditingDomain domain)
- {
- super.configure(domain);
-
- final ResourceSet rset = domain.getResourceSet();
- DawnPathmapManager.removePathMapMananger(rset.eAdapters());
- rset.eAdapters().add(new DawnPathmapManager());
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.transaction; + +import org.eclipse.emf.cdo.dawn.gmf.resources.DawnPathmapManager; +import org.eclipse.emf.cdo.internal.dawn.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory; +import org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl; + +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory; + +public class DawnGMFEditingDomainFactory extends GMFEditingDomainFactory +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DawnGMFEditingDomainFactory.class); + + private static DawnGMFEditingDomainFactory instance = new DawnGMFEditingDomainFactory(); + + @Override + public TransactionalEditingDomain createEditingDomain() + { + TransactionalEditingDomain result = super.createEditingDomain(); + configure(result); + return result; + } + + @Override + public TransactionalEditingDomain createEditingDomain(ResourceSet rset) + { + TransactionalEditingDomain result = super.createEditingDomain(rset); + configure(result); + return result; + } + + /** + * overrides WorkspaceEditingDomainFactory method + */ + @Override + public synchronized TransactionalEditingDomain createEditingDomain(IOperationHistory history) + { + WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); + stack.setResourceUndoContextPolicy(getResourceUndoContextPolicy()); + + TransactionalEditingDomain result = new DawnTransactionalEditingDomainImpl(new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack); + + mapResourceSet(result); + // configures as the GMFEditingDomainFactory would do + configure(result); + + return result; + } + + /** + * overrides WorkspaceEditingDomainFactory method + */ + @Override + public synchronized TransactionalEditingDomain createEditingDomain(ResourceSet rset, IOperationHistory history) + { + if (TRACER.isEnabled()) + { + TRACER.trace("Creating DawnTransactionalEditingDomain using DawnDiagramEditingDomainFactory"); //$NON-NLS-1$ + } + WorkspaceCommandStackImpl stack = new WorkspaceCommandStackImpl(history); + stack.setResourceUndoContextPolicy(getResourceUndoContextPolicy()); + + TransactionalEditingDomain result = new DawnTransactionalEditingDomainImpl(new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack, rset); + + mapResourceSet(result); + + // configures as the GMFEditingDomainFactory would do + configure(result); + + return result; + } + + public static WorkspaceEditingDomainFactory getInstance() + { + return instance; + } + + @Override + protected void configure(final TransactionalEditingDomain domain) + { + super.configure(domain); + + final ResourceSet rset = domain.getResourceSet(); + DawnPathmapManager.removePathMapMananger(rset.eAdapters()); + rset.eAdapters().add(new DawnPathmapManager()); + } +} |