Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fluegge2011-10-25 09:44:18 +0000
committerMartin Fluegge2011-10-25 09:44:18 +0000
commit69117c8416fda55d147060e7a38ee53f6d5745e8 (patch)
tree18b55a5dd5b7f341eab7121425420549f42b77b7 /plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo
parent53b22bda9348fac657b37f4b232b0f0db218482c (diff)
downloadcdo-69117c8416fda55d147060e7a38ee53f6d5745e8.tar.gz
cdo-69117c8416fda55d147060e7a38ee53f6d5745e8.tar.xz
cdo-69117c8416fda55d147060e7a38ee53f6d5745e8.zip
[359656] [Dawn] Provide collaborative extension for Graphiti editors
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java222
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java140
3 files changed, 232 insertions, 131 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
index 2c64b85e45..a16d5de457 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/notifications/DawnGraphitiHandler.java
@@ -52,6 +52,7 @@ public class DawnGraphitiHandler extends BasicDawnTransactionHandler
editor.getDawnEditorSupport().refresh();
// CDOViewInvalidationEvent e = event;
+
//
// adjustDeletedEdges(e);
//
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java
new file mode 100644
index 0000000000..81ba76b128
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnBasicGraphitiWizard.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2004 - 2011 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.graphiti.wizards;
+
+import org.eclipse.emf.cdo.dawn.graphiti.DawnGraphitiUIPlugin;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditor;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditorFactory;
+import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiEditorInput;
+import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
+import org.eclipse.emf.cdo.dawn.ui.composites.CDOResourceNodeChooserComposite.ResourceChooserValidator;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewDiagramResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.util.URI;
+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.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
+import org.eclipse.graphiti.ui.services.GraphitiUi;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+import java.io.IOException;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnBasicGraphitiWizard extends Wizard implements INewWizard
+{
+ protected CDOView view;
+
+ protected DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
+
+ protected DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
+
+ protected String diagramExtension = "model_graphiti";
+
+ protected String modelExtension = "model";
+
+ public DawnBasicGraphitiWizard()
+ {
+ super();
+ CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
+ PreferenceConstants.getServerName());
+ CDOSession session = CDOConnectionUtil.instance.openSession();
+ view = CDOConnectionUtil.instance.openView(session);
+ }
+
+ public DawnBasicGraphitiWizard(String modelExtension, String diagramExtension)
+ {
+ this();
+ this.diagramExtension = diagramExtension;
+ this.modelExtension = modelExtension;
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection)
+ {
+ }
+
+ @Override
+ public void addPages()
+ {
+ dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage(diagramExtension, false, view);
+ dawnDiagramModelFilePage.setTitle("");
+ dawnDiagramModelFilePage.setDescription("");
+ dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
+ addPage(dawnDiagramModelFilePage);
+
+ dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage(modelExtension, true, view)
+ {
+ @Override
+ public void setVisible(boolean visible)
+ {
+ if (visible)
+ {
+ URI uri = dawnDiagramModelFilePage.getURI();
+ String fileName = uri.lastSegment();
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
+ fileName += ".acore";
+ dawnDomainModelFilePage.setResourceNamePrefix(fileName);
+ dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
+ }
+ super.setVisible(visible);
+ }
+ };
+ dawnDomainModelFilePage.setTitle("");
+ dawnDomainModelFilePage.setDescription("");
+
+ // allows to connect to an existing resource
+ dawnDomainModelFilePage.setResourceValidationType(ResourceChooserValidator.VALIDATION_WARN);
+ addPage(dawnDomainModelFilePage);
+ }
+
+ @Override
+ public boolean performFinish()
+ {
+ String diagramTypeId = geTypeId();
+
+ URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
+ URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
+
+ Diagram diagram = Graphiti.getPeCreateService()
+ .createDiagram(diagramTypeId, diagramResourceURI.lastSegment(), true);
+
+ String editorID = DawnGraphitiDiagramEditor.ID;
+
+ TransactionalEditingDomain editingDomain = createEditingDomain(diagramResourceURI, diagram);
+
+ createModelResource(domainModelResourceURI, editingDomain.getResourceSet());
+
+ Resource diagramResource = createDiagramResource(diagramResourceURI, diagram, editingDomain);
+
+ String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
+ DiagramEditorInput editorInput = new DawnGraphitiEditorInput(EcoreUtil.getURI(diagram), editingDomain, providerId,
+ true, diagramResource);
+
+ try
+ {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
+ }
+ catch (PartInitException e)
+ {
+ String error = "Error opening diagram";
+ IStatus status = new Status(IStatus.ERROR, DawnGraphitiUIPlugin.ID, error, e);
+ ErrorDialog.openError(getShell(), "Error", null, status);
+ return false;
+ }
+
+ return true;
+ }
+
+ protected String geTypeId()
+ {
+ return modelExtension;
+ }
+
+ private Resource createModelResource(URI uri, ResourceSet resourceSet)
+ {
+ Resource resource = null;
+
+ // try
+ // {
+ // resource = resourceSet.getResource(uri, true);
+ // }
+ // catch (Exception ex)
+ // {
+ // // ignore
+ // }
+ //
+ // if (resource == null)
+ // {
+ resource = resourceSet.createResource(uri);
+ // }
+
+ return resource;
+ }
+
+ private TransactionalEditingDomain createEditingDomain(URI diagramResourceURI, final Diagram diagram)
+ {
+ final TransactionalEditingDomain editingDomain = DawnGraphitiDiagramEditorFactory
+ .createResourceSetAndEditingDomain();
+
+ return editingDomain;
+ }
+
+ private Resource createDiagramResource(URI diagramResourceURI, final Diagram diagram,
+ final TransactionalEditingDomain editingDomain)
+ {
+ final ResourceSet resourceSet = editingDomain.getResourceSet();
+ final Resource resource = createModelResource(diagramResourceURI, resourceSet);
+
+ final CommandStack commandStack = editingDomain.getCommandStack();
+ commandStack.execute(new RecordingCommand(editingDomain)
+ {
+ @Override
+ protected void doExecute()
+ {
+ resource.getContents().add(diagram);
+ }
+ });
+
+ try
+ {
+ resource.save(null);
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ return resource;
+ }
+
+ @Override
+ public void dispose()
+ {
+ view.close();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
index 2fed0614d4..3aa0afc63e 100644
--- a/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
+++ b/plugins/org.eclipse.emf.cdo.dawn.graphiti/src/org/eclipse/emf/cdo/dawn/graphiti/wizards/DawnGenericGraphitiWizard.java
@@ -10,66 +10,22 @@
*/
package org.eclipse.emf.cdo.dawn.graphiti.wizards;
-import org.eclipse.emf.cdo.dawn.graphiti.DawnGraphitiUIPlugin;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditor;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiDiagramEditorFactory;
-import org.eclipse.emf.cdo.dawn.graphiti.editors.DawnGraphitiEditorInput;
-import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.ui.composites.CDOResourceNodeChooserComposite.ResourceChooserValidator;
import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewDiagramResourceWizardPage;
import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
-import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.util.URI;
-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.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.services.Graphiti;
-import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-
-import java.io.IOException;
/**
* @author Martin Fluegge
*/
-public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
+public class DawnGenericGraphitiWizard extends DawnBasicGraphitiWizard
{
- private CDOView view;
-
private DawnGraphitiyDiagramTypeSelectionWizardPage dawnSelectModelPage;
- private DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
-
- private DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
-
public DawnGenericGraphitiWizard()
{
- super();
- CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
- PreferenceConstants.getServerName());
- CDOSession session = CDOConnectionUtil.instance.openSession();
- view = CDOConnectionUtil.instance.openView(session);
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection)
- {
+ super("", "graphiti");
}
@Override
@@ -78,19 +34,17 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
dawnSelectModelPage = new DawnGraphitiyDiagramTypeSelectionWizardPage("title");
addPage(dawnSelectModelPage);
- dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage("acore_graphiti", false, view)
+ dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage(diagramExtension, false, view)
{
@Override
public void setVisible(boolean visible)
{
if (visible)
{
- String extension = dawnSelectModelPage.getText();
-
URI uri = dawnDiagramModelFilePage.getURI();
String fileName = uri.lastSegment();
- fileName = fileName.substring(0, fileName.length() - ("." + extension + "_graphiti").length()); //$NON-NLS-1$
- fileName += "." + extension + "_graphiti";
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
+ fileName += "." + diagramExtension;
dawnDomainModelFilePage.setResourceNamePrefix(fileName);
dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
}
@@ -103,7 +57,7 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
addPage(dawnDiagramModelFilePage);
- dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("acore", true, view)
+ dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("", true, view)
{
@Override
public void setVisible(boolean visible)
@@ -113,7 +67,7 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
String extension = dawnSelectModelPage.getText();
URI uri = dawnDiagramModelFilePage.getURI();
String fileName = uri.lastSegment();
- fileName = fileName.substring(0, fileName.length() - ("." + extension + "_graphiti").length()); //$NON-NLS-1$
+ fileName = fileName.substring(0, fileName.length() - ("." + diagramExtension).length()); //$NON-NLS-1$
fileName += "." + extension;
dawnDomainModelFilePage.setResourceNamePrefix(fileName);
dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
@@ -130,84 +84,8 @@ public class DawnGenericGraphitiWizard extends Wizard implements INewWizard
}
@Override
- public boolean performFinish()
- {
- String diagramTypeId = dawnSelectModelPage.getText();
-
- URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
- @SuppressWarnings("unused")
- URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
-
- Diagram diagram = Graphiti.getPeCreateService()
- .createDiagram(diagramTypeId, diagramResourceURI.lastSegment(), true);
-
- String editorID = DawnGraphitiDiagramEditor.ID;
- // String diagramTypeProviderId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagramTypeId);
-
- TransactionalEditingDomain domain = createEditingDomain(diagramResourceURI, diagram);
-
- Resource resource = createResource(diagramResourceURI, diagram, domain);
-
- String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
- DiagramEditorInput editorInput = new DawnGraphitiEditorInput(EcoreUtil.getURI(diagram), domain, providerId, true,
- resource);
-
- try
- {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
- }
- catch (PartInitException e)
- {
- String error = "Error opening diagram";
- IStatus status = new Status(IStatus.ERROR, DawnGraphitiUIPlugin.ID, error, e);
- ErrorDialog.openError(getShell(), "Error", null, status);
- return false;
- }
-
- return true;
- }
-
- private TransactionalEditingDomain createEditingDomain(URI diagramResourceURI, final Diagram diagram)
- {
- // Create a resource set and EditingDomain
- final TransactionalEditingDomain editingDomain = DawnGraphitiDiagramEditorFactory
- .createResourceSetAndEditingDomain();
-
- // save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
- return editingDomain;
- }
-
- private Resource createResource(URI diagramResourceURI, final Diagram diagram,
- final TransactionalEditingDomain editingDomain)
- {
- final ResourceSet resourceSet = editingDomain.getResourceSet();
- // Create a resource for this file.
- final Resource resource = resourceSet.createResource(diagramResourceURI);
- final CommandStack commandStack = editingDomain.getCommandStack();
- commandStack.execute(new RecordingCommand(editingDomain)
- {
- @Override
- protected void doExecute()
- {
- // resource.setTrackingModification(true);
- resource.getContents().add(diagram);
- }
- });
-
- try
- {
- resource.save(null);
- }
- catch (IOException ex)
- {
- throw new RuntimeException(ex);
- }
- return resource;
- }
-
- @Override
- public void dispose()
+ protected String geTypeId()
{
- view.close();
+ return dawnSelectModelPage.getText();
}
}

Back to the top