Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 48f2daaf1969981c53d920cc6b955f157a1f7979 (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
/*
 * Copyright (c) 2011, 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.graphiti.features;

import org.eclipse.emf.cdo.dawn.examples.acore.AClass;

import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IPasteContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.features.AbstractPasteFeature;

/**
 * @author Martin Fluegge
 */
public class AcorePasteAClassFeature extends AbstractPasteFeature
{

  public AcorePasteAClassFeature(IFeatureProvider fp)
  {
    super(fp);
  }

  public boolean canPaste(IPasteContext context)
  {
    // only support pasting directly in the diagram (nothing else selected)
    PictogramElement[] pes = context.getPictogramElements();
    if (pes.length != 1 || !(pes[0] instanceof Diagram))
    {
      return false;
    }

    // can paste, if all objects on the clipboard are AClasses
    Object[] fromClipboard = getFromClipboard();
    if (fromClipboard == null || fromClipboard.length == 0)
    {
      return false;
    }
    for (Object object : fromClipboard)
    {
      if (!(object instanceof AClass))
      {
        return false;
      }
    }
    return true;
  }

  public void paste(IPasteContext context)
  {
    // we already verified, that we paste directly in the diagram
    PictogramElement[] pes = context.getPictogramElements();
    Diagram diagram = (Diagram)pes[0];
    // get the AClasses from the clipboard without copying them
    // (only copy the pictogram element, not the business object)
    // then create new pictogram elements using the add feature
    Object[] objects = getFromClipboard();
    for (Object object : objects)
    {
      AddContext ac = new AddContext();
      ac.setLocation(0, 0); // for simplicity paste at (0, 0)
      ac.setTargetContainer(diagram);
      addGraphicalRepresentation(ac, object);
    }
  }
}

Back to the top