Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9600ad0331ec7fbfc65931628a80ffd88039f5fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * 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.editors;

import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditorSupport;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.emf.common.ui.URIEditorInput;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;

import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;

/**
 * @author Martin Fluegge
 */
/*
 * TODO remove this suppress warning as soon as I have found a way to workaround the problem that the Graphiti editor
 * which is extended is internal
 */
@SuppressWarnings("restriction")
public class DawnGraphitiDiagramEditor extends DiagramEditor implements IDawnEditor
{
  public static final String ID = "org.eclipse.emf.cdo.dawn.graphiti.editor";

  private IDawnEditorSupport dawnEditorSupport;

  public DawnGraphitiDiagramEditor()
  {
    dawnEditorSupport = new DawnGraphitiEditorSupport(this);
  }

  @Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException
  {
    if (input instanceof URIEditorInput)
    {
      CDOConnectionUtil.instance.getCurrentSession();
      final URIEditorInput uriInput = (URIEditorInput)input;
      final TransactionalEditingDomain domain = DawnGraphitiDiagramEditorFactory.createResourceSetAndEditingDomain();
      URI diagramFileUri = uriInput.getURI();
      if (diagramFileUri != null)
      {
        // the file's first base node has to be a diagram

        URI diagramUri = GraphitiUiInternal.getEmfService().mapDiagramFileUriToDiagramUri(diagramFileUri);
        input = new DawnGraphitiEditorInput(diagramUri, domain, null, true);
      }
    }

    super.init(site, input);
  }

  @Override
  public void setInput(IEditorInput input)
  {
    super.setInput(input);
    DiagramEditorInput iDawnEditorInput = (DiagramEditorInput)input;

    Resource eResource = iDawnEditorInput.getDiagram().eResource();

    /**
     * TODO check if this can be always done this way and if the view can be canceled from the DawnEditorInput or if
     * there is a better way to put in the view to the editor input.
     */
    if (eResource instanceof CDOResource)
    {
      dawnEditorSupport.setView(((CDOResource)eResource).cdoView());
    }
  }

  @Override
  protected void initializeGraphicalViewer()
  {
    super.initializeGraphicalViewer();
    dawnEditorSupport.registerListeners();
  }

  public CDOView getView()
  {
    return dawnEditorSupport.getView();
  }

  public IDawnEditorSupport getDawnEditorSupport()
  {
    return dawnEditorSupport;
  }

  public String getContributorID()
  {
    return ID;
  }

  @Override
  public boolean isDirty()
  {
    return super.isDirty() || dawnEditorSupport.isDirty();
  }

  public void setDirty()
  {
    dawnEditorSupport.setDirty(true);
  }

  @Override
  public void dispose()
  {
    try
    {
      super.dispose();
    }
    finally
    {
      dawnEditorSupport.close();
    }
  }
}

Back to the top