Skip to main content
summaryrefslogtreecommitdiffstats
blob: d5ca110e3a800778db6278052c7424d49b4eb03d (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
/*
 * 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.ecoretools.diagram.edit.policies;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecoretools.diagram.edit.policies.EPackageCanonicalEditPolicy;
import org.eclipse.emf.ecoretools.diagram.part.EcoreDiagramEditorPlugin;

import org.eclipse.core.runtime.IAdaptable;
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.LinkedList;
import java.util.List;

/**
 * @author Martin Fluegge
 */
public class DawnECoreRootCanonicalEditPolicy extends EPackageCanonicalEditPolicy
{

  public DawnECoreRootCanonicalEditPolicy()
  {
    super();
    EcoreDiagramEditorPlugin.getInstance().logInfo("Running DawnEcoreCanonicalEditPolicy 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 void refreshSemantic()
  {
    deleteOrphanedViews();
    List<IAdaptable> createdConnectionViews = new LinkedList<IAdaptable>();
    createdConnectionViews.addAll(refreshSemanticConnections());
    // createdConnectionViews.addAll(refreshConnections());

    makeViewsImmutable(createdConnectionViews);
  }
}

Back to the top