Customizing GMF DnD FrameworkStep 1 : Contributing custom edit policy provider to GMF editorIn our DnD handler plugin, we ...
LocalSelectionTransfer.getInstance().getSelection();                            if (selection instanceof IStructuredSelect...
returngetDnDEditPolicy().getCommand(_request);                            }else {                                         ...
public class BOMADragDropCommand extends AbstractTransactionalCommand{              private EObject modelObj;             ...
break;                                                   }                                     }                       }  ...
Upcoming SlideShare
Loading in...5
×

Create a Customized GMF DnD Framework

1,314

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,314
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Create a Customized GMF DnD Framework

  1. 1. Customizing GMF DnD FrameworkStep 1 : Contributing custom edit policy provider to GMF editorIn our DnD handler plugin, we contributecom.tibco.xpd.cm.boma.dnd.core.BOMADnDEditPolicyProvider to theorg.eclipse.gmf.runtime.diagram.ui.editpolicyProviders.This Presentation Edit Policy Provider extension point is used to define editpolicy providersfor the editpolicy service.The editpolicy service allows plug-ins to modify or enhance the behavior of an editpart via aneditpolicy without modifying the editpart code.Step 2 : Attach a custom edit policy and a drop target listener to the edit partpublic void createEditPolicies(EditPart editPart) { if (isEditPartValid(editPart)) {/** if the edit part is valid, install the dnd edit policy editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,dndPolicy); editPart.getViewer().addDropTargetListener(dndListner);**/}}public boolean provides(IOperation operation) { if(operation instanceof CreateEditPoliciesOperation){ EditPart editPart =((CreateEditPoliciesOperation) operation).getEditPart(); return isEditPartValid(editPart); } return false;// Custom Edit Policypublic class BOMADragDropEditPolicy extends DragDropEditPolicy {//------}Step 3 : Prepare the list of objects to be dropped and set it on the Drop Request@Override protected List<Object> getObjectsBeingDropped() { ISelection selection =
  2. 2. LocalSelectionTransfer.getInstance().getSelection(); if (selection instanceof IStructuredSelection) { sourceObjectList =((IStructuredSelection) selection).toList(); } return sourceObjectList; }@Override protected Request createTargetRequest() { DropObjectsRequest req = new DropObjectsRequest(); req.setObjects(getObjectsBeingDropped()); return req; }Step 4: Return an edit part that can produce an executable command for thetarget request private EditPart calculateTargetEditPart() { updateTargetRequest(); EditPart ep = getViewer() .findObjectAtExcluding( getDropLocation(), getExclusionSet(), newEditPartViewer.Conditional() { publicboolean evaluate(EditPart editpart) {Command command = editpart.getCommand(getTargetRequest());return command != null; } }); /*if (ep != null) { Command command =ep.getCommand(getTargetRequest()); return (command != null &&command.canExecute())? ep : null; }*/ return ep; }Step 5: Return the required DnD command from the corresponding Edit Part/** * @generated NOT */ @Override public Command getCommand(Request _request) { if(_request instanceof DropObjectsRequest){
  3. 3. returngetDnDEditPolicy().getCommand(_request); }else { returnsuper.getCommand(_request); } } /** * @generated NOT * @return */ private EditPolicy getDnDEditPolicy() { EditPolicy dndPolicy = null; EditPolicyIterator i =getEditPolicyIterator(); while (i.hasNext()) { EditPolicy tempPolicy =i.next(); if (tempPolicy instanceofDragDropEditPolicy) { dndPolicy =tempPolicy; break; } } return dndPolicy; }// Custom Edit Policy public class BOMADragDropEditPolicy extends DragDropEditPolicy {@Override protected Command getDropElementCommand(EObject element,DropObjectsRequest request) { EObject modelObj = getHostObject(); TransactionalEditingDomain editDomain =(TransactionalEdit ingDomain)WorkingCopyUtil.getWorkingCopyFor(modelObj).getEditingDomain(); return getGMFWrapper(new BOMADragDropCommand(editDomain,request,modelObj,element)); } private Command getGMFWrapper(ICommand gmfCommand){ return new ICommandProxy(gmfCommand); }//------}Step 6 : Execute the DnD Command to create the Concepts through correspondingGenerator class
  4. 4. public class BOMADragDropCommand extends AbstractTransactionalCommand{ private EObject modelObj; private EObject element; private IDataModelGenerator modelGen; /** * * @param editDomain * @param request * @param modelObj * @param element */ public BOMADragDropCommand (TransactionalEditingDomaineditDomain,DropObjectsRequest request,EObject modelObj,EObject element){ super(editDomain,"DND",getAffectedFiles(request)); this.modelObj = modelObj; this.element = element; } @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor,IAdaptable info) throws ExecutionException { Model model = null; // if(modelObj != null){ if(modelObj instanceof Model){ model = (Model)modelObj; int elementType = DropElementTypeResolver.getElementType(element); switch(elementType){ caseDropElementTypeResolver.CONCEPT_TYPE: modelGen = new ConceptModelGenerator((Model)modelObj);modelGen.generateUMLModel(element);modelGen.setRelationships();break; caseDropElementTypeResolver.DB_TYPE: modelGen = new DB2UMLModelGenerator((Model)modelObj);modelGen.generateUMLModel(element);modelGen.setRelationships();break; caseDropElementTypeResolver.JAVA_TYPE:break; caseDropElementTypeResolver.XSD_TYPE:
  5. 5. break; } } } return CommandResult.newOKCommandResult(); } private static List getAffectedFiles(Request request){ return null; }}

×