Create a Customized GMF DnD Framework
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Create a Customized GMF DnD Framework

  • 1,683 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,683
On Slideshare
1,682
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
14
Comments
0
Likes
0

Embeds 1

http://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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. 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. 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. 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. break; } } } return CommandResult.newOKCommandResult(); } private static List getAffectedFiles(Request request){ return null; }}