Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ed71d4d438f135a4d9f9fcc21ec19a5566f43830 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * 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.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.core.runtime.IProgressMonitor;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.graphiti.ui.editor.IDiagramEditorInput;
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;

  private DefaultPersistencyBehavior persistencyBehavior;

  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;

      // TODO Check, if needed:
      // final TransactionalEditingDomain domain = DawnGraphitiUtil.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, null);
      }
    }

    super.init(site, input);
  }

  @Override
  public void setInput(IEditorInput input)
  {
    super.setInput(input);
    IDiagramEditorInput diagramEditorInput = (IDiagramEditorInput)input;

    Diagram diagram = persistencyBehavior.loadDiagram(diagramEditorInput.getUri());
    Resource eResource = diagram.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());
    }
  }

  /**
   * @since 2.1
   */
  @Override
  public 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();
    return dawnEditorSupport.isDirty();
  }

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

  @Override
  protected DiagramBehavior createDiagramBehavior()
  {
    DiagramBehavior diagramBehavior = new DiagramBehavior(this)
    {
      {
        setParentPart(DawnGraphitiDiagramEditor.this);
        initDefaultBehaviors();
      }

      @Override
      protected DefaultPersistencyBehavior createPersistencyBehavior()
      {
        persistencyBehavior = new DefaultPersistencyBehavior(getDiagramBehavior())
        {
          @Override
          public void saveDiagram(IProgressMonitor monitor)
          {
            dawnEditorSupport.setDirty(false);
            super.saveDiagram(monitor);
          }
        };

        return persistencyBehavior;
      }
    };

    return diagramBehavior;
  }

  @Deprecated
  protected DefaultPersistencyBehavior createPersistencyBehavior()
  {
    throw new UnsupportedOperationException();
  }

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

Back to the top