SlideShare une entreprise Scribd logo
1  sur  5
Customizing GMF DnD Framework

Step 1 : Contributing custom edit policy provider to GMF editor

In our DnD handler plugin, we contribute
com.tibco.xpd.cm.boma.dnd.core.BOMADnDEditPolicyProvider to the
org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders.

This Presentation Edit Policy Provider extension point is used to define editpolicy providers
for the editpolicy service.
The editpolicy service allows plug-ins to modify or enhance the behavior of an editpart via an
editpolicy without modifying the editpart code.



Step 2 : Attach a custom edit policy and a drop target listener to the edit part

public 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 Policy
public 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 =
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 the
target        request

              private EditPart calculateTargetEditPart() {
                            updateTargetRequest();
                            EditPart ep = getViewer()
                                          .findObjectAtExcluding(
                                                        getDropLocation(),
                                                        getExclusionSet(),
                                                        new
EditPartViewer.Conditional() {
                                                                      public
boolean 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)
{
return
getDnDEditPolicy().getCommand(_request);
                            }else {
                                            return
super.getCommand(_request);
                              }
              }

              /**
              * @generated NOT
              * @return
              */
              private EditPolicy getDnDEditPolicy() {
                             EditPolicy dndPolicy = null;
                             EditPolicyIterator i =
getEditPolicyIterator();
                             while (i.hasNext()) {
                                           EditPolicy tempPolicy =
i.next();
                                           if (tempPolicy instanceof
DragDropEditPolicy) {
                                                          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 corresponding
Generator class
public class BOMADragDropCommand extends AbstractTransactionalCommand{

              private EObject modelObj;
              private EObject element;
              private IDataModelGenerator modelGen;

              /**
              *
              * @param editDomain
              * @param request
              * @param modelObj
              * @param element
              */
              public BOMADragDropCommand (TransactionalEditingDomain
editDomain,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){
                                                                       case
DropElementTypeResolver.CONCEPT_TYPE:
      modelGen = new
      ConceptModelGenerator((Model)modelObj);

modelGen.generateUMLModel(element);

modelGen.setRelationships();

break;
                                                                         case
DropElementTypeResolver.DB_TYPE:
      modelGen = new
      DB2UMLModelGenerator((Model)modelObj);

modelGen.generateUMLModel(element);

modelGen.setRelationships();

break;
                                                                         case
DropElementTypeResolver.JAVA_TYPE:

break;
                                                                         case
DropElementTypeResolver.XSD_TYPE:
break;
                                                   }

                                     }
                       }
                       return CommandResult.newOKCommandResult();
         }

         private static List getAffectedFiles(Request request){

                       return null;
         }
}

Contenu connexe

Tendances

Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
louieuser
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
Chris Weldon
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
cymbron
 
Refactoring group 1 - chapter 3,4,6
Refactoring   group 1 - chapter 3,4,6Refactoring   group 1 - chapter 3,4,6
Refactoring group 1 - chapter 3,4,6
Duy Lâm
 

Tendances (20)

Vaadin 7
Vaadin 7Vaadin 7
Vaadin 7
 
Student management system
Student management systemStudent management system
Student management system
 
Java
JavaJava
Java
 
Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014ESNext for humans - LvivJS 16 August 2014
ESNext for humans - LvivJS 16 August 2014
 
MaintainStaffTable
MaintainStaffTableMaintainStaffTable
MaintainStaffTable
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
 
Removing structural duplication
Removing structural duplicationRemoving structural duplication
Removing structural duplication
 
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
Andriy Slobodyanyk "How to Use Hibernate: Key Problems and Solutions"
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Magic methods
Magic methodsMagic methods
Magic methods
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
 
Refactoring group 1 - chapter 3,4,6
Refactoring   group 1 - chapter 3,4,6Refactoring   group 1 - chapter 3,4,6
Refactoring group 1 - chapter 3,4,6
 
PHP 5 Magic Methods
PHP 5 Magic MethodsPHP 5 Magic Methods
PHP 5 Magic Methods
 
Con5623 pdf 5623_001
Con5623 pdf 5623_001Con5623 pdf 5623_001
Con5623 pdf 5623_001
 

En vedette (8)

Rosemary Carter (2)
Rosemary Carter (2)Rosemary Carter (2)
Rosemary Carter (2)
 
Rosemary Carter
Rosemary CarterRosemary Carter
Rosemary Carter
 
Rosemary Carter
Rosemary CarterRosemary Carter
Rosemary Carter
 
Joe Little - What's Lean got to do with it - The Lean within Scrum
Joe Little - What's Lean got to do with it - The Lean within ScrumJoe Little - What's Lean got to do with it - The Lean within Scrum
Joe Little - What's Lean got to do with it - The Lean within Scrum
 
Rosemary Carter (2)
Rosemary Carter (2)Rosemary Carter (2)
Rosemary Carter (2)
 
Mike Cottmeyer - How to Own a Really big complex Product
Mike Cottmeyer - How to Own a Really big complex ProductMike Cottmeyer - How to Own a Really big complex Product
Mike Cottmeyer - How to Own a Really big complex Product
 
Machine Learning Comparative Analysis - Part 1
Machine Learning Comparative Analysis - Part 1Machine Learning Comparative Analysis - Part 1
Machine Learning Comparative Analysis - Part 1
 
Core concepts and Key technologies - Big Data Analytics
Core concepts and Key technologies - Big Data AnalyticsCore concepts and Key technologies - Big Data Analytics
Core concepts and Key technologies - Big Data Analytics
 

Similaire à Create a Customized GMF DnD Framework

DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
AntoJoseph36
 
First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)
Wildan Maulana
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
DATAVERSITY
 

Similaire à Create a Customized GMF DnD Framework (20)

DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)First Steps. (db4o - Object Oriented Database)
First Steps. (db4o - Object Oriented Database)
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 

Plus de Kaniska Mandal

Debugging over tcp and http
Debugging over tcp and httpDebugging over tcp and http
Debugging over tcp and http
Kaniska Mandal
 
Concurrency Learning From Jdk Source
Concurrency Learning From Jdk SourceConcurrency Learning From Jdk Source
Concurrency Learning From Jdk Source
Kaniska Mandal
 
Wondeland Of Modelling
Wondeland Of ModellingWondeland Of Modelling
Wondeland Of Modelling
Kaniska Mandal
 
The Road To Openness.Odt
The Road To Openness.OdtThe Road To Openness.Odt
The Road To Openness.Odt
Kaniska Mandal
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class Loader
Kaniska Mandal
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In Eclipse
Kaniska Mandal
 
E4 Eclipse Super Force
E4 Eclipse Super ForceE4 Eclipse Super Force
E4 Eclipse Super Force
Kaniska Mandal
 
Creating A Language Editor Using Dltk
Creating A Language Editor Using DltkCreating A Language Editor Using Dltk
Creating A Language Editor Using Dltk
Kaniska Mandal
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
Kaniska Mandal
 
Protocol For Streaming Media
Protocol For Streaming MediaProtocol For Streaming Media
Protocol For Streaming Media
Kaniska Mandal
 
Rest With Json Vs Soap With Xml
Rest With Json Vs Soap With XmlRest With Json Vs Soap With Xml
Rest With Json Vs Soap With Xml
Kaniska Mandal
 
Riding The Semantic Wave
Riding The Semantic WaveRiding The Semantic Wave
Riding The Semantic Wave
Kaniska Mandal
 

Plus de Kaniska Mandal (20)

Machine learning advanced applications
Machine learning advanced applicationsMachine learning advanced applications
Machine learning advanced applications
 
MS CS - Selecting Machine Learning Algorithm
MS CS - Selecting Machine Learning AlgorithmMS CS - Selecting Machine Learning Algorithm
MS CS - Selecting Machine Learning Algorithm
 
Debugging over tcp and http
Debugging over tcp and httpDebugging over tcp and http
Debugging over tcp and http
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Concurrency Learning From Jdk Source
Concurrency Learning From Jdk SourceConcurrency Learning From Jdk Source
Concurrency Learning From Jdk Source
 
Wondeland Of Modelling
Wondeland Of ModellingWondeland Of Modelling
Wondeland Of Modelling
 
The Road To Openness.Odt
The Road To Openness.OdtThe Road To Openness.Odt
The Road To Openness.Odt
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class Loader
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In Eclipse
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
E4 Eclipse Super Force
E4 Eclipse Super ForceE4 Eclipse Super Force
E4 Eclipse Super Force
 
Creating A Language Editor Using Dltk
Creating A Language Editor Using DltkCreating A Language Editor Using Dltk
Creating A Language Editor Using Dltk
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
 
Best Of Jdk 7
Best Of Jdk 7Best Of Jdk 7
Best Of Jdk 7
 
EMF Tips n Tricks
EMF Tips n TricksEMF Tips n Tricks
EMF Tips n Tricks
 
Graphical Model Transformation Framework
Graphical Model Transformation FrameworkGraphical Model Transformation Framework
Graphical Model Transformation Framework
 
Mashup Magic
Mashup MagicMashup Magic
Mashup Magic
 
Protocol For Streaming Media
Protocol For Streaming MediaProtocol For Streaming Media
Protocol For Streaming Media
 
Rest With Json Vs Soap With Xml
Rest With Json Vs Soap With XmlRest With Json Vs Soap With Xml
Rest With Json Vs Soap With Xml
 
Riding The Semantic Wave
Riding The Semantic WaveRiding The Semantic Wave
Riding The Semantic Wave
 

Dernier

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Create a Customized GMF DnD Framework

  • 1. Customizing GMF DnD Framework Step 1 : Contributing custom edit policy provider to GMF editor In our DnD handler plugin, we contribute com.tibco.xpd.cm.boma.dnd.core.BOMADnDEditPolicyProvider to the org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders. This Presentation Edit Policy Provider extension point is used to define editpolicy providers for the editpolicy service. The editpolicy service allows plug-ins to modify or enhance the behavior of an editpart via an editpolicy without modifying the editpart code. Step 2 : Attach a custom edit policy and a drop target listener to the edit part public 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 Policy public 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 the target request private EditPart calculateTargetEditPart() { updateTargetRequest(); EditPart ep = getViewer() .findObjectAtExcluding( getDropLocation(), getExclusionSet(), new EditPartViewer.Conditional() { public boolean 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. return getDnDEditPolicy().getCommand(_request); }else { return super.getCommand(_request); } } /** * @generated NOT * @return */ private EditPolicy getDnDEditPolicy() { EditPolicy dndPolicy = null; EditPolicyIterator i = getEditPolicyIterator(); while (i.hasNext()) { EditPolicy tempPolicy = i.next(); if (tempPolicy instanceof DragDropEditPolicy) { 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 corresponding Generator 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 (TransactionalEditingDomain editDomain,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){ case DropElementTypeResolver.CONCEPT_TYPE: modelGen = new ConceptModelGenerator((Model)modelObj); modelGen.generateUMLModel(element); modelGen.setRelationships(); break; case DropElementTypeResolver.DB_TYPE: modelGen = new DB2UMLModelGenerator((Model)modelObj); modelGen.generateUMLModel(element); modelGen.setRelationships(); break; case DropElementTypeResolver.JAVA_TYPE: break; case DropElementTypeResolver.XSD_TYPE:
  • 5. break; } } } return CommandResult.newOKCommandResult(); } private static List getAffectedFiles(Request request){ return null; } }