diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples')
9 files changed, 1208 insertions, 1208 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnACoreRootEditPart.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnACoreRootEditPart.java index a94ab7c488..fff3fbb8a0 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnACoreRootEditPart.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnACoreRootEditPart.java @@ -1,55 +1,55 @@ -/*
- * 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.examples.acore.diagram.edit.parts;
-
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin;
-import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper;
-
-import org.eclipse.emf.ecore.EObject;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnACoreRootEditPart extends ACoreRootEditPart
-{
-
- // /**
- // * @generated
- // */
- // public final static String MODEL_ID = "Acore"; //$NON-NLS-1$
- //
- // /**
- // * @generated
- // */
- // public static final int VISUAL_ID = 1000;
-
- /**
- * @generated
- */
- public DawnACoreRootEditPart(View view)
- {
- super(view);
- AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnACoreRootEditPart instead of the original one");
- }
-
- @Override
- protected void removeChild(EditPart child)
- {
- if (DawnConflictHelper.isConflicted((EObject)child.getModel()))
- {
- return;
- }
- super.removeChild(child);
- }
-}
+/* + * 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.examples.acore.diagram.edit.parts; + +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin; +import org.eclipse.emf.cdo.dawn.gmf.synchronize.DawnConflictHelper; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.View; + +/** + * @author Martin Fluegge + */ +public class DawnACoreRootEditPart extends ACoreRootEditPart +{ + + // /** + // * @generated + // */ + // public final static String MODEL_ID = "Acore"; //$NON-NLS-1$ + // + // /** + // * @generated + // */ + // public static final int VISUAL_ID = 1000; + + /** + * @generated + */ + public DawnACoreRootEditPart(View view) + { + super(view); + AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnACoreRootEditPart instead of the original one"); + } + + @Override + protected void removeChild(EditPart child) + { + if (DawnConflictHelper.isConflicted((EObject)child.getModel())) + { + return; + } + super.removeChild(child); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnAcoreEditPartFactory.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnAcoreEditPartFactory.java index 192ab75268..9e1bf8ba25 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnAcoreEditPartFactory.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/parts/DawnAcoreEditPartFactory.java @@ -1,42 +1,42 @@ -/*
- * 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.examples.acore.diagram.edit.parts;
-
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin;
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreVisualIDRegistry;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class DawnAcoreEditPartFactory extends AcoreEditPartFactory
-{
- public DawnAcoreEditPartFactory()
- {
- super();
- AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreEditPartFactory instead of the original one");
- }
-
- @Override
- public EditPart createEditPart(EditPart context, Object model)
- {
- if (model instanceof View)
- {
- View view = (View)model;
- switch (AcoreVisualIDRegistry.getVisualID(view))
- {
- case DawnACoreRootEditPart.VISUAL_ID:
- return new DawnACoreRootEditPart(view);
- }
- }
-
- return super.createEditPart(context, model);
- }
-}
+/* + * 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.examples.acore.diagram.edit.parts; + +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreVisualIDRegistry; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.View; + +public class DawnAcoreEditPartFactory extends AcoreEditPartFactory +{ + public DawnAcoreEditPartFactory() + { + super(); + AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreEditPartFactory instead of the original one"); + } + + @Override + public EditPart createEditPart(EditPart context, Object model) + { + if (model instanceof View) + { + View view = (View)model; + switch (AcoreVisualIDRegistry.getVisualID(view)) + { + case DawnACoreRootEditPart.VISUAL_ID: + return new DawnACoreRootEditPart(view); + } + } + + return super.createEditPart(context, model); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/policies/DawnACoreRootCanonicalEditPolicy.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/policies/DawnACoreRootCanonicalEditPolicy.java index 73ffb75d25..3df34de94d 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/policies/DawnACoreRootCanonicalEditPolicy.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/edit/policies/DawnACoreRootCanonicalEditPolicy.java @@ -1,101 +1,101 @@ -/*
- * 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.examples.acore.diagram.edit.policies;
-
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin;
-
-import org.eclipse.emf.ecore.EObject;
-
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.notation.View;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnACoreRootCanonicalEditPolicy extends ACoreRootCanonicalEditPolicy
-{
-
- public DawnACoreRootCanonicalEditPolicy()
- {
- super();
- AcoreDiagramEditorPlugin.getInstance().logInfo("Running DawnAcoreCanonicalEditPolicy instead of original one");
- }
-
- @Override
- protected CreateViewRequest getCreateViewRequest(List<ViewDescriptor> descriptors)
- {
- List<View> viewChildren = getViewChildren();
-
- List<ViewDescriptor> tbr = new ArrayList<CreateViewRequest.ViewDescriptor>();
-
- for (ViewDescriptor desc : descriptors)
- {
- EObject obj = (EObject)((CanonicalElementAdapter)desc.getElementAdapter()).getRealObject();
-
- boolean found = false;
-
- for (View view : viewChildren)
- {
- if (view.getElement().equals(obj))
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- tbr.add(desc);
- }
- }
-
- descriptors.removeAll(tbr);
-
- return new CreateViewRequest(descriptors);
- }
- // @Override
- // protected List getSemanticChildrenList()
- // {
- // List semanticChildren = super.getSemanticChildrenList();
- // List<View> viewChildren = getViewChildren();
- //
- // //remove all semantic children that do not have a view because the have one in another resource,
- // //or the child should not have one
- // semanticChildren.removeAll(cleanCanonicalSemanticChildren(viewChildren, semanticChildren));
- // return semanticChildren;
- // }
-
- // /**
- // * @generated
- // */
- // @Override
- // public void refreshSemantic()
- // {
- // List createdViews = new LinkedList();
- // // createdViews.addAll(refreshSemanticChildren());
- // List createdConnectionViews = new LinkedList();
- // createdConnectionViews.addAll(refreshSemanticConnections());
- // createdConnectionViews.addAll(refreshConnections());
- //
- // if (createdViews.size() > 1)
- // {
- // // perform a layout of the container
- // DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
- // executeCommand(new ICommandProxy(layoutCmd));
- // }
- //
- // createdViews.addAll(createdConnectionViews);
- // makeViewsImmutable(createdViews);
- // }
-}
+/* + * 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.examples.acore.diagram.edit.policies; + +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor; +import org.eclipse.gmf.runtime.notation.View; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Martin Fluegge + */ +public class DawnACoreRootCanonicalEditPolicy extends ACoreRootCanonicalEditPolicy +{ + + public DawnACoreRootCanonicalEditPolicy() + { + super(); + AcoreDiagramEditorPlugin.getInstance().logInfo("Running DawnAcoreCanonicalEditPolicy instead of original one"); + } + + @Override + protected CreateViewRequest getCreateViewRequest(List<ViewDescriptor> descriptors) + { + List<View> viewChildren = getViewChildren(); + + List<ViewDescriptor> tbr = new ArrayList<CreateViewRequest.ViewDescriptor>(); + + for (ViewDescriptor desc : descriptors) + { + EObject obj = (EObject)((CanonicalElementAdapter)desc.getElementAdapter()).getRealObject(); + + boolean found = false; + + for (View view : viewChildren) + { + if (view.getElement().equals(obj)) + { + found = true; + break; + } + } + if (!found) + { + tbr.add(desc); + } + } + + descriptors.removeAll(tbr); + + return new CreateViewRequest(descriptors); + } + // @Override + // protected List getSemanticChildrenList() + // { + // List semanticChildren = super.getSemanticChildrenList(); + // List<View> viewChildren = getViewChildren(); + // + // //remove all semantic children that do not have a view because the have one in another resource, + // //or the child should not have one + // semanticChildren.removeAll(cleanCanonicalSemanticChildren(viewChildren, semanticChildren)); + // return semanticChildren; + // } + + // /** + // * @generated + // */ + // @Override + // public void refreshSemantic() + // { + // List createdViews = new LinkedList(); + // // createdViews.addAll(refreshSemanticChildren()); + // List createdConnectionViews = new LinkedList(); + // createdConnectionViews.addAll(refreshSemanticConnections()); + // createdConnectionViews.addAll(refreshConnections()); + // + // if (createdViews.size() > 1) + // { + // // perform a layout of the container + // DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host()); + // executeCommand(new ICommandProxy(layoutCmd)); + // } + // + // createdViews.addAll(createdConnectionViews); + // makeViewsImmutable(createdViews); + // } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreCreationWizard.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreCreationWizard.java index 4c6031d2d4..9ac4c4db13 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreCreationWizard.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreCreationWizard.java @@ -1,143 +1,143 @@ -/*
- * 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.examples.acore.diagram.part;
-
-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.util.URI;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnAcoreCreationWizard extends AcoreCreationWizard
-{
- private CDOView view;
-
- private DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
-
- private DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
-
- public DawnAcoreCreationWizard()
- {
- super();
- // CDOConnectionUtil.instance.init("repo1", "tcp", "localhost");
- CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
- PreferenceConstants.getServerName());
- CDOSession session = CDOConnectionUtil.instance.openSession();
- view = CDOConnectionUtil.instance.openView(session);
- }
-
- @Override
- public boolean performFinish()
- {
- IRunnableWithProgress op = new WorkspaceModifyOperation(null)
- {
- @Override
- protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException
- {
- URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
- URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
-
- diagram = DawnAcoreDiagramEditorUtil.createDiagram(diagramResourceURI, domainModelResourceURI, monitor);
-
- if (isOpenNewlyCreatedDiagramEditor() && diagram != null)
- {
- try
- {
- DawnAcoreDiagramEditorUtil.openDiagram(diagram);
- }
- catch (PartInitException e)
- {
- ErrorDialog.openError(getContainer().getShell(), Messages.AcoreCreationWizardOpenEditorError, null,
- e.getStatus());
- }
- }
- }
- };
- try
- {
- getContainer().run(false, true, op);
- }
- catch (InterruptedException e)
- {
- return false;
- }
- catch (InvocationTargetException e)
- {
- if (e.getTargetException() instanceof CoreException)
- {
- ErrorDialog.openError(getContainer().getShell(), Messages.AcoreCreationWizardCreationError, null,
- ((CoreException)e.getTargetException()).getStatus());
- }
- else
- {
- AcoreDiagramEditorPlugin.getInstance().logError("Error creating diagram", e.getTargetException()); //$NON-NLS-1$
- }
- return false;
- }
- return diagram != null;
- }
-
- @Override
- public void addPages()
- {
- dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage("acore_diagram", false, view);
- dawnDiagramModelFilePage.setTitle(Messages.AcoreCreationWizard_DiagramModelFilePageTitle);
- dawnDiagramModelFilePage.setDescription(Messages.AcoreCreationWizard_DiagramModelFilePageDescription);
- dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
- addPage(dawnDiagramModelFilePage);
-
- dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("acore", true, view)
- {
- @Override
- public void setVisible(boolean visible)
- {
- if (visible)
- {
- URI uri = dawnDiagramModelFilePage.getURI();
- String fileName = uri.lastSegment();
- fileName = fileName.substring(0, fileName.length() - ".acore_diagram".length()); //$NON-NLS-1$
- fileName += ".acore";
- dawnDomainModelFilePage.setResourceNamePrefix(fileName);
- dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
- }
- super.setVisible(visible);
- }
- };
- dawnDomainModelFilePage.setTitle(Messages.AcoreCreationWizard_DomainModelFilePageTitle);
- dawnDomainModelFilePage.setDescription(Messages.AcoreCreationWizard_DomainModelFilePageDescription);
-
- // allows to connect to an existing resource
- dawnDomainModelFilePage.setResourceValidationType(ResourceChooserValidator.VALIDATION_WARN);
- addPage(dawnDomainModelFilePage);
- }
-
- @Override
- public void dispose()
- {
- view.close();
- }
-}
+/* + * 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.examples.acore.diagram.part; + +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.util.URI; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.actions.WorkspaceModifyOperation; + +import java.lang.reflect.InvocationTargetException; + +/** + * @author Martin Fluegge + */ +public class DawnAcoreCreationWizard extends AcoreCreationWizard +{ + private CDOView view; + + private DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage; + + private DawnCreateNewResourceWizardPage dawnDomainModelFilePage; + + public DawnAcoreCreationWizard() + { + super(); + // CDOConnectionUtil.instance.init("repo1", "tcp", "localhost"); + CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(), + PreferenceConstants.getServerName()); + CDOSession session = CDOConnectionUtil.instance.openSession(); + view = CDOConnectionUtil.instance.openView(session); + } + + @Override + public boolean performFinish() + { + IRunnableWithProgress op = new WorkspaceModifyOperation(null) + { + @Override + protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException + { + URI diagramResourceURI = dawnDiagramModelFilePage.getURI(); + URI domainModelResourceURI = dawnDomainModelFilePage.getURI(); + + diagram = DawnAcoreDiagramEditorUtil.createDiagram(diagramResourceURI, domainModelResourceURI, monitor); + + if (isOpenNewlyCreatedDiagramEditor() && diagram != null) + { + try + { + DawnAcoreDiagramEditorUtil.openDiagram(diagram); + } + catch (PartInitException e) + { + ErrorDialog.openError(getContainer().getShell(), Messages.AcoreCreationWizardOpenEditorError, null, + e.getStatus()); + } + } + } + }; + try + { + getContainer().run(false, true, op); + } + catch (InterruptedException e) + { + return false; + } + catch (InvocationTargetException e) + { + if (e.getTargetException() instanceof CoreException) + { + ErrorDialog.openError(getContainer().getShell(), Messages.AcoreCreationWizardCreationError, null, + ((CoreException)e.getTargetException()).getStatus()); + } + else + { + AcoreDiagramEditorPlugin.getInstance().logError("Error creating diagram", e.getTargetException()); //$NON-NLS-1$ + } + return false; + } + return diagram != null; + } + + @Override + public void addPages() + { + dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage("acore_diagram", false, view); + dawnDiagramModelFilePage.setTitle(Messages.AcoreCreationWizard_DiagramModelFilePageTitle); + dawnDiagramModelFilePage.setDescription(Messages.AcoreCreationWizard_DiagramModelFilePageDescription); + dawnDiagramModelFilePage.setCreateAutomaticResourceName(true); + addPage(dawnDiagramModelFilePage); + + dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("acore", true, view) + { + @Override + public void setVisible(boolean visible) + { + if (visible) + { + URI uri = dawnDiagramModelFilePage.getURI(); + String fileName = uri.lastSegment(); + fileName = fileName.substring(0, fileName.length() - ".acore_diagram".length()); //$NON-NLS-1$ + fileName += ".acore"; + dawnDomainModelFilePage.setResourceNamePrefix(fileName); + dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath()); + } + super.setVisible(visible); + } + }; + dawnDomainModelFilePage.setTitle(Messages.AcoreCreationWizard_DomainModelFilePageTitle); + dawnDomainModelFilePage.setDescription(Messages.AcoreCreationWizard_DomainModelFilePageDescription); + + // allows to connect to an existing resource + dawnDomainModelFilePage.setResourceValidationType(ResourceChooserValidator.VALIDATION_WARN); + addPage(dawnDomainModelFilePage); + } + + @Override + public void dispose() + { + view.close(); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditor.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditor.java index a3cf56dff7..c2826174db 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditor.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditor.java @@ -1,166 +1,166 @@ -/*
- * 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.examples.acore.diagram.part;
-
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
-import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport;
-import org.eclipse.emf.cdo.dawn.gmf.editors.impl.DawnGMFEditorSupport;
-import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
-import org.eclipse.emf.cdo.ui.CDOEditorInput;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.transaction.TransactionException;
-
-import org.eclipse.emf.common.ui.URIEditorInput;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnAcoreDiagramEditor extends AcoreDiagramEditor implements IDawnEditor
-{
- public static String ID = "org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.DawnAcoreDiagramEditor";
-
- private IDawnEditorSupport dawnEditorSupport;
-
- public DawnAcoreDiagramEditor()
- {
- super();
- AcoreDiagramEditorPlugin.getInstance().logInfo("CDO Editor ist starting");
- setDocumentProvider(new DawnAcoreDocumentProvider());
- setDawnEditorSupport(new DawnGMFEditorSupport(this));
- }
-
- @Override
- public void setInput(IEditorInput input)
- {
- AcoreDiagramEditorPlugin.getInstance().logInfo("Setting input for DawnAcoreDiagramEditor (" + input + ")");
-
- try
- {
- doSetInput(input, true);
- }
- catch (CoreException x)
- {
- x.printStackTrace(System.err);
- String title = x.getMessage();
- String msg = x.getMessage();
- Shell shell = getSite().getShell();
- ErrorDialog.openError(shell, title, msg, x.getStatus());
- }
-
- dawnEditorSupport.setView(((DawnEditorInput)input).getView());
- }
-
- @Override
- protected void initializeGraphicalViewer()
- {
- super.initializeGraphicalViewer();
- dawnEditorSupport.registerListeners();
- }
-
- @Override
- public void doSave(IProgressMonitor monitor)
- {
- try
- {
- dawnEditorSupport.setDirty(false);
- updateState(getEditorInput());
- validateState(getEditorInput());
- performSave(false, monitor);
- }
- catch (TransactionException e)
- {
- if (e.getMessage().contains("conflict"))
- {
- MessageDialog.openError(Display.getDefault().getActiveShell(), "conflict",
- "Your Resource is in conflict and cannot be committed");
- }
- else
- {
- throw e;
- }
- }
- }
-
- @Override
- public boolean isDirty()
- {
- return dawnEditorSupport.isDirty();
- }
-
- public String getContributorID()
- {
- return ID;
- }
-
- /**
- * Have to override this method to change the the DocuemtnProvider behavior.
- */
- @Override
- protected void setDocumentProvider(IEditorInput input)
- {
- if (input instanceof IFileEditorInput || input instanceof URIEditorInput || input instanceof CDOEditorInput)
- {
- setDocumentProvider(getDocumentProvider());
- }
- else
- {
- super.setDocumentProvider(input);
- }
- }
-
- @Override
- public void dispose()
- {
- try
- {
- super.dispose();
- }
- finally
- {
- dawnEditorSupport.close();
- }
- }
-
- /**
- * @since 1.0
- */
- public CDOView getView()
- {
- return dawnEditorSupport.getView();
- }
-
- public void setDirty()
- {
- dawnEditorSupport.setDirty(true);
- ((AbstractDocumentProvider)getDocumentProvider()).changed(getEditorInput());
- }
-
- public void setDawnEditorSupport(IDawnEditorSupport dawnEditorSupport)
- {
- this.dawnEditorSupport = dawnEditorSupport;
- }
-
- public IDawnEditorSupport getDawnEditorSupport()
- {
- return dawnEditorSupport;
- }
-}
+/* + * 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.examples.acore.diagram.part; + +import org.eclipse.emf.cdo.dawn.editors.IDawnEditor; +import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport; +import org.eclipse.emf.cdo.dawn.gmf.editors.impl.DawnGMFEditorSupport; +import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput; +import org.eclipse.emf.cdo.ui.CDOEditorInput; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.transaction.TransactionException; + +import org.eclipse.emf.common.ui.URIEditorInput; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; + +/** + * @author Martin Fluegge + */ +public class DawnAcoreDiagramEditor extends AcoreDiagramEditor implements IDawnEditor +{ + public static String ID = "org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.DawnAcoreDiagramEditor"; + + private IDawnEditorSupport dawnEditorSupport; + + public DawnAcoreDiagramEditor() + { + super(); + AcoreDiagramEditorPlugin.getInstance().logInfo("CDO Editor ist starting"); + setDocumentProvider(new DawnAcoreDocumentProvider()); + setDawnEditorSupport(new DawnGMFEditorSupport(this)); + } + + @Override + public void setInput(IEditorInput input) + { + AcoreDiagramEditorPlugin.getInstance().logInfo("Setting input for DawnAcoreDiagramEditor (" + input + ")"); + + try + { + doSetInput(input, true); + } + catch (CoreException x) + { + x.printStackTrace(System.err); + String title = x.getMessage(); + String msg = x.getMessage(); + Shell shell = getSite().getShell(); + ErrorDialog.openError(shell, title, msg, x.getStatus()); + } + + dawnEditorSupport.setView(((DawnEditorInput)input).getView()); + } + + @Override + protected void initializeGraphicalViewer() + { + super.initializeGraphicalViewer(); + dawnEditorSupport.registerListeners(); + } + + @Override + public void doSave(IProgressMonitor monitor) + { + try + { + dawnEditorSupport.setDirty(false); + updateState(getEditorInput()); + validateState(getEditorInput()); + performSave(false, monitor); + } + catch (TransactionException e) + { + if (e.getMessage().contains("conflict")) + { + MessageDialog.openError(Display.getDefault().getActiveShell(), "conflict", + "Your Resource is in conflict and cannot be committed"); + } + else + { + throw e; + } + } + } + + @Override + public boolean isDirty() + { + return dawnEditorSupport.isDirty(); + } + + public String getContributorID() + { + return ID; + } + + /** + * Have to override this method to change the the DocuemtnProvider behavior. + */ + @Override + protected void setDocumentProvider(IEditorInput input) + { + if (input instanceof IFileEditorInput || input instanceof URIEditorInput || input instanceof CDOEditorInput) + { + setDocumentProvider(getDocumentProvider()); + } + else + { + super.setDocumentProvider(input); + } + } + + @Override + public void dispose() + { + try + { + super.dispose(); + } + finally + { + dawnEditorSupport.close(); + } + } + + /** + * @since 1.0 + */ + public CDOView getView() + { + return dawnEditorSupport.getView(); + } + + public void setDirty() + { + dawnEditorSupport.setDirty(true); + ((AbstractDocumentProvider)getDocumentProvider()).changed(getEditorInput()); + } + + public void setDawnEditorSupport(IDawnEditorSupport dawnEditorSupport) + { + this.dawnEditorSupport = dawnEditorSupport; + } + + public IDawnEditorSupport getDawnEditorSupport() + { + return dawnEditorSupport; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditorUtil.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditorUtil.java index 95666753e3..0b6e1ea008 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditorUtil.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDiagramEditorUtil.java @@ -1,390 +1,390 @@ -/*
- * 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.examples.acore.diagram.part;
-
-import org.eclipse.emf.cdo.dawn.commands.CreateSemanticResourceRecordingCommand;
-import org.eclipse.emf.cdo.dawn.examples.acore.AcoreFactory;
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.DawnACoreRootEditPart;
-import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
-import org.eclipse.emf.cdo.dawn.transaction.DawnGMFEditingDomainFactory;
-import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
-import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.OperationHistoryFactory;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-
-import java.io.IOException;
-import java.util.Collections;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnAcoreDiagramEditorUtil extends AcoreDiagramEditorUtil
-{
-
- // static CDOSession session;
-
- /**
- * @generated
- */
- public static boolean openDiagram(Resource diagram) throws PartInitException
- {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- return null != page.openEditor(new DawnEditorInput(diagram.getURI()), DawnAcoreDiagramEditor.ID);
- }
-
- /**
- * Runs the wizard in a dialog.
- *
- * @generated
- */
- public static void runWizard(Shell shell, Wizard wizard, String settingsKey)
- {
- IDialogSettings pluginDialogSettings = AcoreDiagramEditorPlugin.getInstance().getDialogSettings();
- IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
- if (wizardDialogSettings == null)
- {
- wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
- }
- wizard.setDialogSettings(wizardDialogSettings);
- WizardDialog dialog = new WizardDialog(shell, wizard);
- dialog.create();
- dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
- dialog.open();
- }
-
- public static Resource createDiagram(URI diagramURI, URI modelURI, IProgressMonitor progressMonitor)
- {
- TransactionalEditingDomain editingDomain = DawnGMFEditingDomainFactory.getInstance().createEditingDomain();
-
- progressMonitor.beginTask(Messages.AcoreDiagramEditorUtil_CreateDiagramProgressTask, 3);
-
- CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
- PreferenceConstants.getServerName());
- CDOConnectionUtil.instance.openSession();
- ResourceSet resourceSet = editingDomain.getResourceSet();
-
- AcoreDiagramEditorPlugin.getInstance().logInfo("URI toString: " + diagramURI.toString());
- AcoreDiagramEditorPlugin.getInstance().logInfo("URI authority: " + diagramURI.authority());
-
- CDOTransaction transaction = CDOConnectionUtil.instance.openCurrentTransaction(resourceSet, diagramURI.toString());
-
- final Resource diagramResource = resourceSet.createResource(diagramURI);
-
- AcoreDiagramEditorPlugin.getInstance().logInfo("Diagram URI: " + diagramURI);
- AcoreDiagramEditorPlugin.getInstance().logInfo("Diagram Resource: " + diagramResource);
-
- CreateSemanticResourceRecordingCommand createSemanticResourceCommand = new CreateSemanticResourceRecordingCommand(
- editingDomain, transaction, modelURI.path());
-
- editingDomain.getCommandStack().execute(createSemanticResourceCommand);
- final Resource modelResource = createSemanticResourceCommand.getResource();
- AcoreDiagramEditorPlugin.getInstance().logInfo("Model URI: " + modelURI);
- AcoreDiagramEditorPlugin.getInstance().logInfo("Model Resource: " + modelResource);
-
- final String diagramName = diagramURI.lastSegment();
- AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain,
- Messages.AcoreDiagramEditorUtil_CreateDiagramCommandLabel, Collections.EMPTY_LIST)
- {
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
- {
- EObject model = null;
- if (modelResource.getContents().size() > 0)
- {
- model = modelResource.getContents().get(0);
- }
- else
- {
- model = createInitialModel();
- attachModelToResource(model, modelResource);
- }
-
- Diagram diagram = ViewService.createDiagram(model, DawnACoreRootEditPart.MODEL_ID,
- AcoreDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
- if (diagram != null)
- {
- diagramResource.getContents().add(diagram);
- diagram.setName(diagramName);
- diagram.setElement(model);
- }
-
- try
- {
- modelResource.save(Collections.EMPTY_MAP);
- diagramResource.save(Collections.EMPTY_MAP);
- }
- catch (IOException e)
- {
- AcoreDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", e); //$NON-NLS-1$
- }
-
- return CommandResult.newOKCommandResult();
- }
- };
- try
- {
- OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
- }
- catch (ExecutionException e)
- {
- AcoreDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$
- }
- setCharset(WorkspaceSynchronizer.getFile(modelResource));
- setCharset(WorkspaceSynchronizer.getFile(diagramResource));
- return diagramResource;
- }
-
- /**
- * Create a new instance of domain element associated with canvas. <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- private static EObject createInitialModel()
- {
- return AcoreFactory.eINSTANCE.createACoreRoot();
- }
-
- /**
- * Store model element in the resource. <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- private static void attachModelToResource(EObject model, Resource resource)
- {
- resource.getContents().add(model);
- }
-
- // /**
- // * @generated
- // */
- // public static void selectElementsInDiagram(IDiagramWorkbenchPart diagramPart, List/* EditPart */editParts)
- // {
- // diagramPart.getDiagramGraphicalViewer().deselectAll();
- //
- // EditPart firstPrimary = null;
- // for (Iterator it = editParts.iterator(); it.hasNext();)
- // {
- // EditPart nextPart = (EditPart)it.next();
- // diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
- // if (firstPrimary == null && nextPart instanceof IPrimaryEditPart)
- // {
- // firstPrimary = nextPart;
- // }
- // }
- //
- // if (!editParts.isEmpty())
- // {
- // diagramPart.getDiagramGraphicalViewer().reveal(firstPrimary != null ? firstPrimary : (EditPart)editParts.get(0));
- // }
- // }
-
- // /**
- // * @generated
- // */
- // private static int findElementsInDiagramByID(DiagramEditPart diagramPart, EObject element, List editPartCollector)
- // {
- // IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer)diagramPart.getViewer();
- // final int intialNumOfEditParts = editPartCollector.size();
- //
- // if (element instanceof View)
- // { // support notation element lookup
- // EditPart editPart = (EditPart)viewer.getEditPartRegistry().get(element);
- // if (editPart != null)
- // {
- // editPartCollector.add(editPart);
- // return 1;
- // }
- // }
- //
- // String elementID = EMFCoreUtil.getProxyID(element);
- // List associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class);
- // // perform the possible hierarchy disjoint -> take the top-most parts only
- // for (Iterator editPartIt = associatedParts.iterator(); editPartIt.hasNext();)
- // {
- // EditPart nextPart = (EditPart)editPartIt.next();
- // EditPart parentPart = nextPart.getParent();
- // while (parentPart != null && !associatedParts.contains(parentPart))
- // {
- // parentPart = parentPart.getParent();
- // }
- // if (parentPart == null)
- // {
- // editPartCollector.add(nextPart);
- // }
- // }
- //
- // if (intialNumOfEditParts == editPartCollector.size())
- // {
- // if (!associatedParts.isEmpty())
- // {
- // editPartCollector.add(associatedParts.iterator().next());
- // }
- // else
- // {
- // if (element.eContainer() != null)
- // {
- // return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
- // }
- // }
- // }
- // return editPartCollector.size() - intialNumOfEditParts;
- // }
-
- // /**
- // * @generated
- // */
- // public static View findView(DiagramEditPart diagramEditPart, EObject targetElement,
- // LazyElement2ViewMap lazyElement2ViewMap)
- // {
- // boolean hasStructuralURI = false;
- // if (targetElement.eResource() instanceof XMLResource)
- // {
- // hasStructuralURI = ((XMLResource)targetElement.eResource()).getID(targetElement) == null;
- // }
- //
- // View view = null;
- // if (hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty())
- // {
- // view = (View)lazyElement2ViewMap.getElement2ViewMap().get(targetElement);
- // }
- // else if (findElementsInDiagramByID(diagramEditPart, targetElement, lazyElement2ViewMap.editPartTmpHolder) > 0)
- // {
- // EditPart editPart = (EditPart)lazyElement2ViewMap.editPartTmpHolder.get(0);
- // lazyElement2ViewMap.editPartTmpHolder.clear();
- // view = editPart.getModel() instanceof View ? (View)editPart.getModel() : null;
- // }
- //
- // return (view == null) ? diagramEditPart.getDiagramView() : view;
- // }
-
- // /**
- // * @generated
- // */
- // public static class LazyElement2ViewMap
- // {
- // /**
- // * @generated
- // */
- // private Map element2ViewMap;
- //
- // /**
- // * @generated
- // */
- // private View scope;
- //
- // /**
- // * @generated
- // */
- // private Set elementSet;
- //
- // /**
- // * @generated
- // */
- // public final List editPartTmpHolder = new ArrayList();
- //
- // /**
- // * @generated
- // */
- // public LazyElement2ViewMap(View scope, Set elements)
- // {
- // this.scope = scope;
- // this.elementSet = elements;
- // }
- //
- // /**
- // * @generated
- // */
- // public final Map getElement2ViewMap()
- // {
- // if (element2ViewMap == null)
- // {
- // element2ViewMap = new HashMap();
- // // map possible notation elements to itself as these can't be found by view.getElement()
- // for (Iterator it = elementSet.iterator(); it.hasNext();)
- // {
- // EObject element = (EObject)it.next();
- // if (element instanceof View)
- // {
- // View view = (View)element;
- // if (view.getDiagram() == scope.getDiagram())
- // {
- // element2ViewMap.put(element, element); // take only those that part of our diagram
- // }
- // }
- // }
- //
- // buildElement2ViewMap(scope, element2ViewMap, elementSet);
- // }
- // return element2ViewMap;
- // }
- //
- // /**
- // * @generated
- // */
- // static Map buildElement2ViewMap(View parentView, Map element2ViewMap, Set elements)
- // {
- // if (elements.size() == element2ViewMap.size())
- // return element2ViewMap;
- //
- // if (parentView.isSetElement() && !element2ViewMap.containsKey(parentView.getElement())
- // && elements.contains(parentView.getElement()))
- // {
- // element2ViewMap.put(parentView.getElement(), parentView);
- // if (elements.size() == element2ViewMap.size())
- // return element2ViewMap;
- // }
- //
- // for (Iterator it = parentView.getChildren().iterator(); it.hasNext();)
- // {
- // buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
- // if (elements.size() == element2ViewMap.size())
- // return element2ViewMap;
- // }
- // for (Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();)
- // {
- // buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
- // if (elements.size() == element2ViewMap.size())
- // return element2ViewMap;
- // }
- // for (Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();)
- // {
- // buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
- // if (elements.size() == element2ViewMap.size())
- // return element2ViewMap;
- // }
- // return element2ViewMap;
- // }
- // } // LazyElement2ViewMap
-
-}
+/* + * 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.examples.acore.diagram.part; + +import org.eclipse.emf.cdo.dawn.commands.CreateSemanticResourceRecordingCommand; +import org.eclipse.emf.cdo.dawn.examples.acore.AcoreFactory; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.DawnACoreRootEditPart; +import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants; +import org.eclipse.emf.cdo.dawn.transaction.DawnGMFEditingDomainFactory; +import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput; +import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil; +import org.eclipse.emf.cdo.transaction.CDOTransaction; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.OperationHistoryFactory; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.diagram.core.services.ViewService; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +import java.io.IOException; +import java.util.Collections; + +/** + * @author Martin Fluegge + */ +public class DawnAcoreDiagramEditorUtil extends AcoreDiagramEditorUtil +{ + + // static CDOSession session; + + /** + * @generated + */ + public static boolean openDiagram(Resource diagram) throws PartInitException + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + return null != page.openEditor(new DawnEditorInput(diagram.getURI()), DawnAcoreDiagramEditor.ID); + } + + /** + * Runs the wizard in a dialog. + * + * @generated + */ + public static void runWizard(Shell shell, Wizard wizard, String settingsKey) + { + IDialogSettings pluginDialogSettings = AcoreDiagramEditorPlugin.getInstance().getDialogSettings(); + IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey); + if (wizardDialogSettings == null) + { + wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey); + } + wizard.setDialogSettings(wizardDialogSettings); + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.create(); + dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500); + dialog.open(); + } + + public static Resource createDiagram(URI diagramURI, URI modelURI, IProgressMonitor progressMonitor) + { + TransactionalEditingDomain editingDomain = DawnGMFEditingDomainFactory.getInstance().createEditingDomain(); + + progressMonitor.beginTask(Messages.AcoreDiagramEditorUtil_CreateDiagramProgressTask, 3); + + CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(), + PreferenceConstants.getServerName()); + CDOConnectionUtil.instance.openSession(); + ResourceSet resourceSet = editingDomain.getResourceSet(); + + AcoreDiagramEditorPlugin.getInstance().logInfo("URI toString: " + diagramURI.toString()); + AcoreDiagramEditorPlugin.getInstance().logInfo("URI authority: " + diagramURI.authority()); + + CDOTransaction transaction = CDOConnectionUtil.instance.openCurrentTransaction(resourceSet, diagramURI.toString()); + + final Resource diagramResource = resourceSet.createResource(diagramURI); + + AcoreDiagramEditorPlugin.getInstance().logInfo("Diagram URI: " + diagramURI); + AcoreDiagramEditorPlugin.getInstance().logInfo("Diagram Resource: " + diagramResource); + + CreateSemanticResourceRecordingCommand createSemanticResourceCommand = new CreateSemanticResourceRecordingCommand( + editingDomain, transaction, modelURI.path()); + + editingDomain.getCommandStack().execute(createSemanticResourceCommand); + final Resource modelResource = createSemanticResourceCommand.getResource(); + AcoreDiagramEditorPlugin.getInstance().logInfo("Model URI: " + modelURI); + AcoreDiagramEditorPlugin.getInstance().logInfo("Model Resource: " + modelResource); + + final String diagramName = diagramURI.lastSegment(); + AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, + Messages.AcoreDiagramEditorUtil_CreateDiagramCommandLabel, Collections.EMPTY_LIST) + { + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException + { + EObject model = null; + if (modelResource.getContents().size() > 0) + { + model = modelResource.getContents().get(0); + } + else + { + model = createInitialModel(); + attachModelToResource(model, modelResource); + } + + Diagram diagram = ViewService.createDiagram(model, DawnACoreRootEditPart.MODEL_ID, + AcoreDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); + if (diagram != null) + { + diagramResource.getContents().add(diagram); + diagram.setName(diagramName); + diagram.setElement(model); + } + + try + { + modelResource.save(Collections.EMPTY_MAP); + diagramResource.save(Collections.EMPTY_MAP); + } + catch (IOException e) + { + AcoreDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", e); //$NON-NLS-1$ + } + + return CommandResult.newOKCommandResult(); + } + }; + try + { + OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null); + } + catch (ExecutionException e) + { + AcoreDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$ + } + setCharset(WorkspaceSynchronizer.getFile(modelResource)); + setCharset(WorkspaceSynchronizer.getFile(diagramResource)); + return diagramResource; + } + + /** + * Create a new instance of domain element associated with canvas. <!-- begin-user-doc --> <!-- end-user-doc --> + * + * @generated + */ + private static EObject createInitialModel() + { + return AcoreFactory.eINSTANCE.createACoreRoot(); + } + + /** + * Store model element in the resource. <!-- begin-user-doc --> <!-- end-user-doc --> + * + * @generated + */ + private static void attachModelToResource(EObject model, Resource resource) + { + resource.getContents().add(model); + } + + // /** + // * @generated + // */ + // public static void selectElementsInDiagram(IDiagramWorkbenchPart diagramPart, List/* EditPart */editParts) + // { + // diagramPart.getDiagramGraphicalViewer().deselectAll(); + // + // EditPart firstPrimary = null; + // for (Iterator it = editParts.iterator(); it.hasNext();) + // { + // EditPart nextPart = (EditPart)it.next(); + // diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart); + // if (firstPrimary == null && nextPart instanceof IPrimaryEditPart) + // { + // firstPrimary = nextPart; + // } + // } + // + // if (!editParts.isEmpty()) + // { + // diagramPart.getDiagramGraphicalViewer().reveal(firstPrimary != null ? firstPrimary : (EditPart)editParts.get(0)); + // } + // } + + // /** + // * @generated + // */ + // private static int findElementsInDiagramByID(DiagramEditPart diagramPart, EObject element, List editPartCollector) + // { + // IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer)diagramPart.getViewer(); + // final int intialNumOfEditParts = editPartCollector.size(); + // + // if (element instanceof View) + // { // support notation element lookup + // EditPart editPart = (EditPart)viewer.getEditPartRegistry().get(element); + // if (editPart != null) + // { + // editPartCollector.add(editPart); + // return 1; + // } + // } + // + // String elementID = EMFCoreUtil.getProxyID(element); + // List associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class); + // // perform the possible hierarchy disjoint -> take the top-most parts only + // for (Iterator editPartIt = associatedParts.iterator(); editPartIt.hasNext();) + // { + // EditPart nextPart = (EditPart)editPartIt.next(); + // EditPart parentPart = nextPart.getParent(); + // while (parentPart != null && !associatedParts.contains(parentPart)) + // { + // parentPart = parentPart.getParent(); + // } + // if (parentPart == null) + // { + // editPartCollector.add(nextPart); + // } + // } + // + // if (intialNumOfEditParts == editPartCollector.size()) + // { + // if (!associatedParts.isEmpty()) + // { + // editPartCollector.add(associatedParts.iterator().next()); + // } + // else + // { + // if (element.eContainer() != null) + // { + // return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector); + // } + // } + // } + // return editPartCollector.size() - intialNumOfEditParts; + // } + + // /** + // * @generated + // */ + // public static View findView(DiagramEditPart diagramEditPart, EObject targetElement, + // LazyElement2ViewMap lazyElement2ViewMap) + // { + // boolean hasStructuralURI = false; + // if (targetElement.eResource() instanceof XMLResource) + // { + // hasStructuralURI = ((XMLResource)targetElement.eResource()).getID(targetElement) == null; + // } + // + // View view = null; + // if (hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) + // { + // view = (View)lazyElement2ViewMap.getElement2ViewMap().get(targetElement); + // } + // else if (findElementsInDiagramByID(diagramEditPart, targetElement, lazyElement2ViewMap.editPartTmpHolder) > 0) + // { + // EditPart editPart = (EditPart)lazyElement2ViewMap.editPartTmpHolder.get(0); + // lazyElement2ViewMap.editPartTmpHolder.clear(); + // view = editPart.getModel() instanceof View ? (View)editPart.getModel() : null; + // } + // + // return (view == null) ? diagramEditPart.getDiagramView() : view; + // } + + // /** + // * @generated + // */ + // public static class LazyElement2ViewMap + // { + // /** + // * @generated + // */ + // private Map element2ViewMap; + // + // /** + // * @generated + // */ + // private View scope; + // + // /** + // * @generated + // */ + // private Set elementSet; + // + // /** + // * @generated + // */ + // public final List editPartTmpHolder = new ArrayList(); + // + // /** + // * @generated + // */ + // public LazyElement2ViewMap(View scope, Set elements) + // { + // this.scope = scope; + // this.elementSet = elements; + // } + // + // /** + // * @generated + // */ + // public final Map getElement2ViewMap() + // { + // if (element2ViewMap == null) + // { + // element2ViewMap = new HashMap(); + // // map possible notation elements to itself as these can't be found by view.getElement() + // for (Iterator it = elementSet.iterator(); it.hasNext();) + // { + // EObject element = (EObject)it.next(); + // if (element instanceof View) + // { + // View view = (View)element; + // if (view.getDiagram() == scope.getDiagram()) + // { + // element2ViewMap.put(element, element); // take only those that part of our diagram + // } + // } + // } + // + // buildElement2ViewMap(scope, element2ViewMap, elementSet); + // } + // return element2ViewMap; + // } + // + // /** + // * @generated + // */ + // static Map buildElement2ViewMap(View parentView, Map element2ViewMap, Set elements) + // { + // if (elements.size() == element2ViewMap.size()) + // return element2ViewMap; + // + // if (parentView.isSetElement() && !element2ViewMap.containsKey(parentView.getElement()) + // && elements.contains(parentView.getElement())) + // { + // element2ViewMap.put(parentView.getElement(), parentView); + // if (elements.size() == element2ViewMap.size()) + // return element2ViewMap; + // } + // + // for (Iterator it = parentView.getChildren().iterator(); it.hasNext();) + // { + // buildElement2ViewMap((View)it.next(), element2ViewMap, elements); + // if (elements.size() == element2ViewMap.size()) + // return element2ViewMap; + // } + // for (Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) + // { + // buildElement2ViewMap((View)it.next(), element2ViewMap, elements); + // if (elements.size() == element2ViewMap.size()) + // return element2ViewMap; + // } + // for (Iterator it = parentView.getSourceEdges().iterator(); it.hasNext();) + // { + // buildElement2ViewMap((View)it.next(), element2ViewMap, elements); + // if (elements.size() == element2ViewMap.size()) + // return element2ViewMap; + // } + // return element2ViewMap; + // } + // } // LazyElement2ViewMap + +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDocumentProvider.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDocumentProvider.java index eba3814d34..63d9795c4c 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDocumentProvider.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/part/DawnAcoreDocumentProvider.java @@ -1,227 +1,227 @@ -/*
- * 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.examples.acore.diagram.part;
-
-import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater;
-import org.eclipse.emf.cdo.dawn.transaction.DawnDiagramEditingDomainFactory;
-import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
-import org.eclipse.emf.cdo.eresource.CDOResource;
-
-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.common.ui.URIEditorInput;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.transaction.NotificationFilter;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil;
-import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.part.FileEditorInput;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author Martin Fluegge
- */
-@SuppressWarnings("restriction")
-public class DawnAcoreDocumentProvider extends AcoreDocumentProvider
-{
- public DawnAcoreDocumentProvider()
- {
- super();
- AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreDocumentProvider instead of the original one");
- }
-
- /**
- * override to change creation of editingdomain
- */
- @Override
- protected IDocument createEmptyDocument()
- {
- DiagramDocument document = new DiagramDocument();
- document.setEditingDomain(createEditingDomain());
- return document;
- }
-
- /**
- * override to change the EditingDomain
- */
- private TransactionalEditingDomain createEditingDomain()
- {
- TransactionalEditingDomain editingDomain = DawnDiagramEditingDomainFactory.getInstance().createEditingDomain();
- editingDomain.setID("org.eclipse.emf.cdo.dawn.examples.acore.diagram.EditingDomain"); //$NON-NLS-1$
- final NotificationFilter diagramResourceModifiedFilter = NotificationFilter
- .createNotifierFilter(editingDomain.getResourceSet())
- .and(NotificationFilter.createEventTypeFilter(Notification.ADD))
- .and(NotificationFilter.createFeatureFilter(ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
- editingDomain.getResourceSet().eAdapters().add(new Adapter()
- {
- private Notifier myTarger;
-
- public Notifier getTarget()
- {
- return myTarger;
- }
-
- public boolean isAdapterForType(Object type)
- {
- return false;
- }
-
- public void notifyChanged(Notification notification)
- {
- if (diagramResourceModifiedFilter.matches(notification))
- {
- Object value = notification.getNewValue();
- if (value instanceof Resource)
- {
- ((Resource)value).setTrackingModification(true);
- }
- }
- }
-
- public void setTarget(Notifier newTarget)
- {
- myTarger = newTarget;
- }
- });
-
- return editingDomain;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException
- {
- AcoreDiagramEditorPlugin.getInstance().logInfo("Editor Input: " + element.getName());
-
- IDiagramDocument diagramDocument = (IDiagramDocument)document;
- TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
- if (element instanceof FileEditorInput)
- {
- IStorage storage = ((FileEditorInput)element).getStorage();
- Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor());
- document.setContent(diagram);
- }
- else if (element instanceof URIEditorInput)
- {
- URIEditorInput editorInput = (URIEditorInput)element;
-
- URI uri = editorInput.getURI();
- Resource resource = null;
- try
- {
- // TODO change this fake!!
- URI dawnURI = URI.createURI(uri.toString().replace("cdo", "dawn"));
- resource = domain.getResourceSet().getResource(dawnURI, false);
- if (resource == null)
- {
- // TODO clarify with Eike why here a transaction will be opended??
- resource = domain.getResourceSet().getResource(dawnURI, true);
- }
-
- if (editorInput instanceof DawnEditorInput)
- {
- ((DawnEditorInput)editorInput).setResource((CDOResource)resource);
- }
- if (!resource.isLoaded())
- {
- try
- {
- Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions());
- resource.load(options);
- }
- catch (IOException e)
- {
- resource.unload();
- throw e;
- }
- }
- if (uri.fragment() != null)
- {
- EObject rootElement = resource.getEObject(uri.fragment());
- if (rootElement instanceof Diagram)
- {
- Diagram diagram = (Diagram)rootElement;
- DawnDiagramUpdater.initializeElement(diagram);
- document.setContent(diagram);
-
- return;
- }
- }
- else
- {
- for (Iterator<?> it = resource.getContents().iterator(); it.hasNext();)
- {
- Object rootElement = it.next();
- if (rootElement instanceof Diagram)
- {
- Diagram diagram = (Diagram)rootElement;
- DawnDiagramUpdater.initializeElement(diagram);
- document.setContent(diagram);
-
- return;
- }
- }
- }
- throw new RuntimeException(Messages.AcoreDocumentProvider_NoDiagramInResourceError);
- }
- catch (Exception e)
- {
- CoreException thrownExcp = null;
- if (e instanceof CoreException)
- {
- thrownExcp = (CoreException)e;
- }
- else
- {
- String msg = e.getLocalizedMessage();
- thrownExcp = new CoreException(new Status(IStatus.ERROR, AcoreDiagramEditorPlugin.ID, 0, msg != null ? msg
- : Messages.AcoreDocumentProvider_DiagramLoadingError, e));
- }
- throw thrownExcp;
- }
- }
- else
- {
- throw new CoreException(new Status(IStatus.ERROR, AcoreDiagramEditorPlugin.ID, 0, NLS.bind(
- Messages.AcoreDocumentProvider_IncorrectInputError, new Object[] { element,
- "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
- null));
- }
- }
-
- @Override
- public void changed(Object element)
- {
- if (element instanceof IEditorInput)
- {
- fireElementDirtyStateChanged(element, true);
- }
- }
-}
+/* + * 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.examples.acore.diagram.part; + +import org.eclipse.emf.cdo.dawn.gmf.util.DawnDiagramUpdater; +import org.eclipse.emf.cdo.dawn.transaction.DawnDiagramEditingDomainFactory; +import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput; +import org.eclipse.emf.cdo.eresource.CDOResource; + +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.common.ui.URIEditorInput; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.transaction.NotificationFilter; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil; +import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.part.FileEditorInput; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @author Martin Fluegge + */ +@SuppressWarnings("restriction") +public class DawnAcoreDocumentProvider extends AcoreDocumentProvider +{ + public DawnAcoreDocumentProvider() + { + super(); + AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreDocumentProvider instead of the original one"); + } + + /** + * override to change creation of editingdomain + */ + @Override + protected IDocument createEmptyDocument() + { + DiagramDocument document = new DiagramDocument(); + document.setEditingDomain(createEditingDomain()); + return document; + } + + /** + * override to change the EditingDomain + */ + private TransactionalEditingDomain createEditingDomain() + { + TransactionalEditingDomain editingDomain = DawnDiagramEditingDomainFactory.getInstance().createEditingDomain(); + editingDomain.setID("org.eclipse.emf.cdo.dawn.examples.acore.diagram.EditingDomain"); //$NON-NLS-1$ + final NotificationFilter diagramResourceModifiedFilter = NotificationFilter + .createNotifierFilter(editingDomain.getResourceSet()) + .and(NotificationFilter.createEventTypeFilter(Notification.ADD)) + .and(NotificationFilter.createFeatureFilter(ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES)); + editingDomain.getResourceSet().eAdapters().add(new Adapter() + { + private Notifier myTarger; + + public Notifier getTarget() + { + return myTarger; + } + + public boolean isAdapterForType(Object type) + { + return false; + } + + public void notifyChanged(Notification notification) + { + if (diagramResourceModifiedFilter.matches(notification)) + { + Object value = notification.getNewValue(); + if (value instanceof Resource) + { + ((Resource)value).setTrackingModification(true); + } + } + } + + public void setTarget(Notifier newTarget) + { + myTarger = newTarget; + } + }); + + return editingDomain; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException + { + AcoreDiagramEditorPlugin.getInstance().logInfo("Editor Input: " + element.getName()); + + IDiagramDocument diagramDocument = (IDiagramDocument)document; + TransactionalEditingDomain domain = diagramDocument.getEditingDomain(); + if (element instanceof FileEditorInput) + { + IStorage storage = ((FileEditorInput)element).getStorage(); + Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor()); + document.setContent(diagram); + } + else if (element instanceof URIEditorInput) + { + URIEditorInput editorInput = (URIEditorInput)element; + + URI uri = editorInput.getURI(); + Resource resource = null; + try + { + // TODO change this fake!! + URI dawnURI = URI.createURI(uri.toString().replace("cdo", "dawn")); + resource = domain.getResourceSet().getResource(dawnURI, false); + if (resource == null) + { + // TODO clarify with Eike why here a transaction will be opended?? + resource = domain.getResourceSet().getResource(dawnURI, true); + } + + if (editorInput instanceof DawnEditorInput) + { + ((DawnEditorInput)editorInput).setResource((CDOResource)resource); + } + if (!resource.isLoaded()) + { + try + { + Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions()); + resource.load(options); + } + catch (IOException e) + { + resource.unload(); + throw e; + } + } + if (uri.fragment() != null) + { + EObject rootElement = resource.getEObject(uri.fragment()); + if (rootElement instanceof Diagram) + { + Diagram diagram = (Diagram)rootElement; + DawnDiagramUpdater.initializeElement(diagram); + document.setContent(diagram); + + return; + } + } + else + { + for (Iterator<?> it = resource.getContents().iterator(); it.hasNext();) + { + Object rootElement = it.next(); + if (rootElement instanceof Diagram) + { + Diagram diagram = (Diagram)rootElement; + DawnDiagramUpdater.initializeElement(diagram); + document.setContent(diagram); + + return; + } + } + } + throw new RuntimeException(Messages.AcoreDocumentProvider_NoDiagramInResourceError); + } + catch (Exception e) + { + CoreException thrownExcp = null; + if (e instanceof CoreException) + { + thrownExcp = (CoreException)e; + } + else + { + String msg = e.getLocalizedMessage(); + thrownExcp = new CoreException(new Status(IStatus.ERROR, AcoreDiagramEditorPlugin.ID, 0, msg != null ? msg + : Messages.AcoreDocumentProvider_DiagramLoadingError, e)); + } + throw thrownExcp; + } + } + else + { + throw new CoreException(new Status(IStatus.ERROR, AcoreDiagramEditorPlugin.ID, 0, NLS.bind( + Messages.AcoreDocumentProvider_IncorrectInputError, new Object[] { element, + "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ + null)); + } + } + + @Override + public void changed(Object element) + { + if (element instanceof IEditorInput) + { + fireElementDirtyStateChanged(element, true); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPartProvider.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPartProvider.java index 9a80ea4580..998ca754a3 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPartProvider.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPartProvider.java @@ -1,32 +1,32 @@ -/*
- * 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.examples.acore.diagram.providers;
-
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.DawnAcoreEditPartFactory;
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnAcoreEditPartProvider extends AcoreEditPartProvider
-{
- /**
- * This class is currently not needed because the change of the EditPolicy is done by changing the EditPart but by
- * using an own EditPartPolicyProvider. The class is left to have the chance to influence the behavior of the
- * EditParts from the generated fragment.
- */
- public DawnAcoreEditPartProvider()
- {
- super();
- AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreEditPartProvider instead of the original one.");
- setFactory(new DawnAcoreEditPartFactory());
- }
-}
+/* + * 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.examples.acore.diagram.providers; + +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.DawnAcoreEditPartFactory; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin; + +/** + * @author Martin Fluegge + */ +public class DawnAcoreEditPartProvider extends AcoreEditPartProvider +{ + /** + * This class is currently not needed because the change of the EditPolicy is done by changing the EditPart but by + * using an own EditPartPolicyProvider. The class is left to have the chance to influence the behavior of the + * EditParts from the generated fragment. + */ + public DawnAcoreEditPartProvider() + { + super(); + AcoreDiagramEditorPlugin.getInstance().logInfo("Using DawnAcoreEditPartProvider instead of the original one."); + setFactory(new DawnAcoreEditPartFactory()); + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPolicyProvider.java b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPolicyProvider.java index 56501e9f00..fce161fec2 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPolicyProvider.java +++ b/plugins/org.eclipse.emf.cdo.dawn.examples.acore.diagram.dawn/src/org/eclipse/emf/cdo/dawn/examples/acore/diagram/providers/DawnAcoreEditPolicyProvider.java @@ -1,52 +1,52 @@ -/*
- * 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.examples.acore.diagram.providers;
-
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.ACoreRootEditPart;
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.policies.DawnACoreRootCanonicalEditPolicy;
-import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
-
-/**
- * @author Martin Fluegge
- */
-public class DawnAcoreEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider
-{
- public static String ID = "org.eclipse.emf.cdo.dawn.examples.acore.diagram.providers.DawnAcoreEditPolicyProvider";
-
- public boolean provides(IOperation operation)
- {
- if (operation instanceof CreateEditPoliciesOperation)
- {
- CreateEditPoliciesOperation editPoliciesOperation = (CreateEditPoliciesOperation)operation;
- if (editPoliciesOperation.getEditPart() instanceof ACoreRootEditPart)
- {
- return true;
- }
- }
- return false;
- }
-
- public void createEditPolicies(EditPart editPart)
- {
- if (editPart instanceof ACoreRootEditPart)
- {
- AcoreDiagramEditorPlugin.getInstance().logInfo("Overwriting CANONICAL EDITING POLICY in " + editPart);
- editPart.installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new DawnACoreRootCanonicalEditPolicy());
- }
- }
-}
+/* + * 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.examples.acore.diagram.providers; + +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.ACoreRootEditPart; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.policies.DawnACoreRootCanonicalEditPolicy; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreDiagramEditorPlugin; + +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; +import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider; + +/** + * @author Martin Fluegge + */ +public class DawnAcoreEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider +{ + public static String ID = "org.eclipse.emf.cdo.dawn.examples.acore.diagram.providers.DawnAcoreEditPolicyProvider"; + + public boolean provides(IOperation operation) + { + if (operation instanceof CreateEditPoliciesOperation) + { + CreateEditPoliciesOperation editPoliciesOperation = (CreateEditPoliciesOperation)operation; + if (editPoliciesOperation.getEditPart() instanceof ACoreRootEditPart) + { + return true; + } + } + return false; + } + + public void createEditPolicies(EditPart editPart) + { + if (editPart instanceof ACoreRootEditPart) + { + AcoreDiagramEditorPlugin.getInstance().logInfo("Overwriting CANONICAL EDITING POLICY in " + editPart); + editPart.installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new DawnACoreRootCanonicalEditPolicy()); + } + } +} |