[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: Add sub menu in context menu

Hello.

Sorry for the delay, I had skipped the gmf mailing-list.
I don't know if you solved your problem. If not, here is my opinion.

If I correctly understand, the problem is about the creation of the copy in the new diagram.
I have not looked very carefully your xml files, I prefer to ask you: you must have two files, one for your model, and one for your graphical aspects. And does your copy appears in the model file (I have understood than it does not appear on the graphic) ?

How I would do:
- your copy seems correct.
- for the paste action, I would rather use a CreateElementAndView command.

Something like...
IElementType type = OrchestrationElementTypes.Service_1001;     
// replace "Service" by your node type and "Orchestration" by your root object
                        ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
                                new CreateElementRequestAdapter(
                                        new CreateElementRequest( type )),
                                Node.class,
                                ((IHintedType) type).getSemanticHint(),
                                orchestrationEditPart.getDiagramPreferencesHint() );                  
   
                        CreateViewAndElementRequest req = new CreateViewAndElementRequest( viewDescriptor );
                        req.setLocation( ((DropObjectsRequest) request).getLocation());         // adapt it to your mouse right-click location
                       
                        // execute the command
                        CompoundCommand cmd = new CompoundCommand("Copy action");
                        cmd.add( orchestrationEditPart.getCommand(req) );                     // replace "Orchestration"    
                        orchestrationEditPart.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
Note: this code was used in an *EditPart (the one of my root element).
But you can adapt it to your problem. This will create a new "empty" node. Then, you can initialize its attributes with those of your copy kept in ClipboardUtil. The initialization is another problem (at least, try to copy a new node where you copy-click is a first good step).

About initialization, you can search for this in the mailing-list and in the FAQ (search for "SetRequest" and "SetValueCommand").
This also answers to your last question.

Regards,

                 Vincent.



Zoya Pandeva wrote:
Hello,

Thank you for the response.Answer for my first question was useful for 
me.But I have no success with second one.I test but it does not work.I have 
a chance to find ClipboardUtil and try it with this class.This is my code 
for newly created diagram,code for copy/paste command, diagram from wherever 
the widgets must be copy , newly created diagram wherever the widgets must 
be paste.There are differences between diagram files and when open  diagram 
the pasted widgets does not appear.
 And also I want to know Is there a possibility to change the name of the 
widgets when widgets are pasted?

code for newly created diagram:

byte[] buf = new byte[1024];
IFile diagramFile = null;
try {
DiagramFileCreator dfc = ComponentsDiagramFileCreator.getInstance();
diagramFile = ComponentsDiagramEditorUtil
..createNewDiagramFile(dfc, project.getFullPath(),
"test.mmgp", new ByteArrayInputStream(buf),
"components", new Shell(),
new NullProgressMonitor());
} catch (Exception e) {
e.printStackTrace();
}
 code for copy/paste comand:

Object obj = sSelection.getFirstElement();
  if (!(obj instanceof ShapeNodeEditPart))
   return;
  ShapeNodeEditPart snep = (ShapeNodeEditPart) obj;
  Object modelObject = snep.getModel();
  if (!(modelObject instanceof Node))
   return;
  Node node = (Node) modelObject;
  List list = new ArrayList();

    String copyRes=null;
  try {
   copyRes = ClipboardUtil.copyElementsToString(list, null,
     new NullProgressMonitor());
  } catch (Exception e) {
   e.printStackTrace();
  }

  final ResourceSet resourceSet = new ResourceSetImpl();
  final URI fileURI =
URI.createPlatformResourceURI(diagramFile.getFullPath().toPortableString());
    final Resource resource = resourceSet.getResource(fileURI, true);

  Collection pasted=null;
  try {
  pasted = ClipboardUtil.pasteElementsFromString(copyRes,
    resource, null, new NullProgressMonitor());
  } catch (Exception e){
   e.printStackTrace();
  }
  try {
   resource.save(null);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

diagram from wherever the widgets must be copy :
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:components="http:///components.ecore"
xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.0/notation">
 <components:Editor xmi:id="_HswkIGdyEdyGQ_aU24dEkA">
   <label xmi:type="components:Label" xmi:id="_WJHgAGdyEdyGQ_aU24dEkA"
name="Label_1190290172416" value="dsa"/>
 </components:Editor>
 <notation:Diagram xmi:id="_Hv6l0GdyEdyGQ_aU24dEkA" type="components"
element="_HswkIGdyEdyGQ_aU24dEkA" name="default.mmgp"
measurementUnit="Pixel">
   <children xmi:type="notation:Node" xmi:id="_WJf6gGdyEdyGQ_aU24dEkA"
type="1001" element="_WJHgAGdyEdyGQ_aU24dEkA">
     <children xmi:type="notation:Node" xmi:id="_WJmBIGdyEdyGQ_aU24dEkA"
type="4001"/>
     <styles xmi:type="notation:FontStyle"
xmi:id="_WJf6gWdyEdyGQ_aU24dEkA"/>
     <styles xmi:type="notation:DescriptionStyle"
xmi:id="_WJf6gmdyEdyGQ_aU24dEkA"/>
     <styles xmi:type="notation:FillStyle"
xmi:id="_WJf6g2dyEdyGQ_aU24dEkA"/>
     <styles xmi:type="notation:LineStyle"
xmi:id="_WJf6hGdyEdyGQ_aU24dEkA"/>
     <layoutConstraint xmi:type="notation:Bounds"
xmi:id="_WJf6hWdyEdyGQ_aU24dEkA" x="108" y="72" width="313" height="145"/>
   </children>
   <styles xmi:type="notation:PageStyle" xmi:id="_Hv6l0WdyEdyGQ_aU24dEkA"/>
   <styles xmi:type="notation:GuideStyle" xmi:id="_Hv6l0mdyEdyGQ_aU24dEkA"/>
   <styles xmi:type="notation:DescriptionStyle"
xmi:id="_Hv6l02dyEdyGQ_aU24dEkA"/>
 </notation:Diagram>
</xmi:XMI>

newly created diagram wherever the widgets must be paste:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:components="http:///components.ecore"
xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.0/notation">
 <components:Editor xmi:id="_K0DSsGgWEdyYsvrIY-dLzA"/>
 <notation:Diagram xmi:id="_K0Pf8GgWEdyYsvrIY-dLzA" type="components"
element="_K0DSsGgWEdyYsvrIY-dLzA" name="test.mmgp" measurementUnit="Pixel">
   <styles xmi:type="notation:PageStyle" xmi:id="_K0Pf8WgWEdyYsvrIY-dLzA"/>
   <styles xmi:type="notation:GuideStyle" xmi:id="_K0Pf8mgWEdyYsvrIY-dLzA"/>
   <styles xmi:type="notation:DescriptionStyle"
xmi:id="_K0Pf82gWEdyYsvrIY-dLzA"/>
 </notation:Diagram>
 <notation:Node xmi:id="_K1k8sGgWEdyYsvrIY-dLzA" type="1001"
element="_K1k8t2gWEdyYsvrIY-dLzA">
   <children xmi:type="notation:Node" xmi:id="_K1k8sWgWEdyYsvrIY-dLzA"
type="4001"/>
   <styles xmi:type="notation:FontStyle" xmi:id="_K1k8smgWEdyYsvrIY-dLzA"/>
   <styles xmi:type="notation:DescriptionStyle"
xmi:id="_K1k8s2gWEdyYsvrIY-dLzA"/>
   <styles xmi:type="notation:FillStyle" xmi:id="_K1k8tGgWEdyYsvrIY-dLzA"/>
   <styles xmi:type="notation:LineStyle" xmi:id="_K1k8tWgWEdyYsvrIY-dLzA"/>
   <layoutConstraint xmi:type="notation:Bounds"
xmi:id="_K1k8tmgWEdyYsvrIY-dLzA" x="108" y="72" width="313" height="145"/>
 </notation:Node>
 <components:Label xmi:id="_K1k8t2gWEdyYsvrIY-dLzA"
name="Label_1190290172416" value="dsa"/>
</xmi:XMI>

Many thanks
Zoya Pandeva