diff options
author | Martin Fluegge | 2010-04-11 18:09:51 +0000 |
---|---|---|
committer | Martin Fluegge | 2010-04-11 18:09:51 +0000 |
commit | 3ee27b5b37e25e247f4e4d0e86f735931aa14280 (patch) | |
tree | a1803a55ce8576a3c6e2b605fdd85070e6db397b /plugins/org.eclipse.emf.cdo.dawn.util/src | |
parent | 33f1502eef76b2f70bca95c2d9932700e1bc360a (diff) | |
download | cdo-3ee27b5b37e25e247f4e4d0e86f735931aa14280.tar.gz cdo-3ee27b5b37e25e247f4e4d0e86f735931aa14280.tar.xz cdo-3ee27b5b37e25e247f4e4d0e86f735931aa14280.zip |
[308232] [Dawn] Develop collaborative support for GMF on CDO
https://bugs.eclipse.org/bugs/show_bug.cgi?id=308232
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.util/src')
4 files changed, 210 insertions, 60 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/Activator.java b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/Activator.java index 44b967f6da..1428198c01 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/Activator.java +++ b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/Activator.java @@ -14,48 +14,52 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** - * * @author Martin Fluegge */ -public class Activator extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.util"; - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } +public class Activator extends AbstractUIPlugin +{ + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.util"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() + { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception + { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception + { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() + { + return plugin; + } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/DawnDiagramUpdater.java b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/DawnDiagramUpdater.java index 69bbb3bab2..d32cddd309 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/DawnDiagramUpdater.java +++ b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/DawnDiagramUpdater.java @@ -13,19 +13,22 @@ package org.eclipse.emf.cdo.dawn.util; import java.util.Iterator; import java.util.List; +import org.eclipse.emf.cdo.dawn.logging.logger.LOG; 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.gef.EditPartViewer; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; 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.notation.View; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.PlatformUI; + /** - * * @author Martin Fluegge */ public class DawnDiagramUpdater @@ -97,7 +100,7 @@ public class DawnDiagramUpdater // { // CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next(); // nextEditPolicy.refresh(); - // + // // } } catch (Exception e) @@ -132,4 +135,143 @@ public class DawnDiagramUpdater } + public static View findView(EObject element) + { + if (element instanceof View) + return (View)element; + else + { + if (element.eContainer() == null) + return null; + if (element.eContainer() instanceof View) + { + return (View)element.eContainer(); + } + else + { + findView(element.eContainer()); + } + } + return null; + } + + /** + * TODO: Martin: shouldmove this to a helper class or change with an existing GMF helper + */ + public static View findViewForModel(EObject object, DiagramDocumentEditor editor) + { + + try + { + for (EObject e : editor.getDiagram().eContents()) + { + if (e instanceof View && ((View)e).getElement().equals(object)) + { + LOG.info("FOUND View: " + e + " for view obj: " + object); + return (View)e; + } + } + } + catch (Exception e) + { + // quickhack + } + + return null; + } + + // copied from DawnGMFTransactionListener + public static EditPart createOrFindEditPartIfViewExists(View view, DiagramDocumentEditor editor) + { + // EditPart editPart = ResourceHelper.findEditPart(view, editor); + EditPart editPart = findEditPart(view, editor.getDiagramEditPart()); + + if (view != null) + { + if (editPart == null) // does not exist? + { + LOG.info("Editpart does not exist for view " + view); + editPart = EditPartService.getInstance().createGraphicEditPart(view); + setParentEditPart(editor, view, editPart); + } + } + LOG.info("found EditPart: " + editPart); + return editPart; + } + + // copied from DawnGMFTransactionListener + 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); + } + } diff --git a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/connection/CDOConnectionUtil.java b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/connection/CDOConnectionUtil.java index b97a04dfc1..99c85e3bee 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/connection/CDOConnectionUtil.java +++ b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/connection/CDOConnectionUtil.java @@ -24,8 +24,6 @@ import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.emf.cdo.view.CDOViewSet; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.internal.cdo.session.CDOSessionImpl; -import org.eclipse.emf.spi.cdo.InternalCDOSession; import org.eclipse.emf.spi.cdo.InternalCDOView; import org.eclipse.net4j.Net4jUtil; import org.eclipse.net4j.connector.IConnector; @@ -92,13 +90,13 @@ public class CDOConnectionUtil */ public CDOSession openSession() { + if (!CDOUtil.isLegacyModeDefault()) + { + CDOUtil.setLegacyModeDefault(true); + } currentSession = (CDOSession)IPluginContainer.INSTANCE.getElement("org.eclipse.emf.cdo.sessions", "cdo", protocol + "://" + host + "?repositoryName=" + repositoryName); - if(!((InternalCDOSession)currentSession).isLegacyEnabled()) - { - ((InternalCDOSession)currentSession).setLegacyEnabled(true); - } return currentSession; } @@ -117,7 +115,7 @@ public class CDOConnectionUtil { throw new DawnInvalidIdException("The identifier '" + id + "' is invalid for openeing a transaction"); } - System.out.println("Openeing transcation for "+id+ " on "+resourceSet); + System.out.println("Opening transaction for " + id + " on " + resourceSet); id = convert(id); CDOTransaction transaction = getCurrentSession().openTransaction(resourceSet); getTransactions().put(id, transaction); @@ -161,7 +159,8 @@ public class CDOConnectionUtil // // public CDOSession openSession(String repositoryName) // { - // CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration(); + // CDOSessionConfiguration configuration = + // CDONet4jUtil.createSessionConfiguration(); // // configuration.setConnector(connector); // configuration.setRepositoryName(repositoryName); @@ -173,9 +172,12 @@ public class CDOConnectionUtil // public CDOSession openCurrentSession(String repositoryName) // { // //TODO id for every editor instance - // currentSession = (CDOSession)IPluginContainer.INSTANCE.getElement("org.eclipse.emf.cdo.sessions", "cdo", + // currentSession = + // (CDOSession)IPluginContainer.INSTANCE.getElement("org.eclipse.emf.cdo.sessions", + // "cdo", // "tcp://localhost?repositoryName=repo1&id=1"); - // // CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration(); + // // CDOSessionConfiguration configuration = + // CDONet4jUtil.createSessionConfiguration(); // // // // configuration.setConnector(connector); // // configuration.setRepositoryName(repositoryName); @@ -185,10 +187,11 @@ public class CDOConnectionUtil // // } // - // // // - // public CDOTransaction openTransaction(CDOSession session, ResourceSet resourceSet) + // + // public CDOTransaction openTransaction(CDOSession session, ResourceSet + // resourceSet) // { // return session.openTransaction(resourceSet); // } @@ -205,7 +208,8 @@ public class CDOConnectionUtil // } // // - // private void setCurrentSession(org.eclipse.emf.cdo.net4j.CDOSession currentSession) + // private void setCurrentSession(org.eclipse.emf.cdo.net4j.CDOSession + // currentSession) // { // this.currentSession = currentSession; // } @@ -235,10 +239,10 @@ public class CDOConnectionUtil public CDOTransaction getOrOpenCurrentTransaction(String id, ResourceSet resourceSet) { CDOTransaction transaction = getCurrentTransaction(id); - + CDOViewSet viewSet = CDOUtil.getViewSet(resourceSet); - - if(viewSet !=null) + + if (viewSet != null) { return ((InternalCDOView)viewSet.resolveView("repo1")).toTransaction(); } diff --git a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/exceptions/DawnInvalidIdException.java b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/exceptions/DawnInvalidIdException.java index 77481187a5..d0276abbb4 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/exceptions/DawnInvalidIdException.java +++ b/plugins/org.eclipse.emf.cdo.dawn.util/src/org/eclipse/emf/cdo/dawn/util/exceptions/DawnInvalidIdException.java @@ -9,8 +9,8 @@ * Martin Fluegge - initial API and implementation ******************************************************************************/ package org.eclipse.emf.cdo.dawn.util.exceptions; + /** - * * @author Martin Fluegge */ public class DawnInvalidIdException extends RuntimeException |