[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,

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

"Vincent Zurczak" <vincent.zurczak@xxxxxxxxxxxxxxxxxx> wrote in message 
news:fcdtco$r50$1@xxxxxxxxxxxxxxxxxxxx
Hello.

- For the context menu, in the plugin.xml file, add an extension by using 
the wizard PopMenu.
If your widgets are all of the same class, or inherit from the same class, 
just provide this class as the target object. If they are of different 
kinds, I let you adjust the previous hint. Since you are working with 
several objects, select "multiple selection".

What happens when the user clicks on your sub-menu is defined in the run 
method of the Action class (let it be generated by the wizard and then, 
modify it ;) ).

- About your second question, I have an idea, but it may/should be possible 
to use another way, more GMF-like.
For a "move" action, you should implement a drag-and-drop (see mailing-list 
for hints).
For a "copy / paste", you could  see it as two actions :
- first diagram: copy => get selected objects (quite easy with an ISelection 
object).

See your "Action class" or use "ISelection t = 
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();"
Also, get a way to transfer these objects to another diagram (singleton 
class ?).

- second diagram: paste => get previously selected objects, and for each 
one, extract its attributes to create the same new element and initialize 
it. To create new elements programmatically, you will have to use command 
mechanisms (see mailing-list).

Note : this may be done in a separate plugin (more convenient if you foresee 
to re-generate your diagram code).
I hope this helps you a little.

Bye,

                 Vincent.



Zoya Pandeva wrote:
I have several selected widgets in GMF diagram and I want add my own sub 
menu in right click context menu.
Can I add such an action and if I can from where? And how can I 
programmatically move (or copy/paste) selected widget to other GMF diagram?