Converting DB Schema into UML ClassesWe provide a sample case-study about how to leverage the powerful modelingframeworks ...
The editpolicy service allows plug-ins to modify or enhance the behavior of an editpartvia an editpolicy without modifying...
public boolean provides(IOperation operation) {       if(operation instanceof CreateEditPoliciesOperation){           Edit...
Every      Diagram     Editor     provides  its     custom     implementation      ofCanonicalConnectionEditPolicy, say in...
public boolean evaluate(EditPart editpart) {                       Command command =editpart.getCommand(getTargetRequest()...
while (i.hasNext()) {              EditPolicy tempPolicy = i.next();               if (tempPolicy instanceof DragDropEditP...
Step 7 : Execute the DnD Command to create the Concepts throughcorresponding Generator classpublic class BOMADragDropComma...
case DropElementTypeResolver.DB_TYPE:modelGen = newDB2UMLModelGenerator((Model)modelObj);                  modelGen.genera...
Upcoming SlideShare
Loading in...5
×

Converting Db Schema Into Uml Classes

919

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
919
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Converting Db Schema Into Uml Classes

  1. 1. Converting DB Schema into UML ClassesWe provide a sample case-study about how to leverage the powerful modelingframeworks of eclipse (Semantic Notation management using EMF , Diagram Graphicsmanagement using MF and Draw2d, Standard Visual Representation using UML)Users can drag the Database schema/table/tablespce and drop onto a custom UMLeditor.After tables are are converted into uml classes, we apply stereotype and profile to retainthe original DB info.Step 1 : Contributing custom edit policy provider to GMF editor In our DnD handler plugin, we contributecom.pramati.tools.dnd.policies.CustomEditPolicyProvider to theorg.eclipse.gmf.runtime.diagram.ui.editpolicyProviders. The Object class should specify the object that has to be examined by this provider.Considering a UML class Diagram Editor the object class would be“org.eclipse.uml2.diagram.clazz.edit.parts.PackageEditPart” as it is the root edit partonto which objects should be dropped. <extension point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders"> <editpolicyProvider class="com.pramati.tools.dnd.policies.CustomEditPolicyProvider"> <Priority name="Lowest"> </Priority> <context editparts="TraceEditPart"> </context> <object class="org.eclipse.uml2.diagram.clazz.edit.parts.PackageEditPart" id="TraceEditPart"> </object> </editpolicyProvider> </extension>This Presentation Edit Policy Provider extension point is used to define editpolicyproviders for the editpolicy service.
  2. 2. The editpolicy service allows plug-ins to modify or enhance the behavior of an editpartvia an editpolicy without modifying the editpart code.Step 2 : Install Edit Policy for CANONICAL_ROLE and DRAG_DROP_ROLE on<Root>EditPart of the Diagram Editor that extends DiagramEditPart.The Canonical edit policy will ensure that the hosts model children are in sync with aspecific set of semantic children. It will register itself with the model server to receivesemantic events fired to its host editpart. It will create, if necessary, notation elementsfor all semantic elements inserted into the host element or delete the notation element forthe semantic element removed from the host element. CanonicalConnectionEditPolicy isa specialized implementation of CanonicalEditPolicy. It will manage connections ownedby the semantic host.public class CustomDragDropEditPolicy extends DragDropEditPolicy {public void createEditPolicies(EditPart editPart) { if (editPart instanceof PackageEditPart) {editPart.installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,new CustomCanonicalConnectionEditPolicy());editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDnDEditPolicy(); editPart.getViewer().addDropTargetListener( newCustomDragDropTargetListner(editPart().getViewer())); } }Note : Very important point to note while installing Canonical Edit policy is that thetarget editPart on which we install the edit policy should be specific to the DiagramEditor and should not be GraphicalEditPart as it would effect the creation of notationelements for all other GMF Editors.
  3. 3. public boolean provides(IOperation operation) { if(operation instanceof CreateEditPoliciesOperation){ EditPart editPart = ((CreateEditPoliciesOperation) operation).getEditPart(); return isEditPartValid(editPart); } return false;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; }@Overrideprotected Request createTargetRequest() {DropObjectsRequest req = new DropObjectsRequest(); req.setObjects(getObjectsBeingDropped()); return req; }Step-4 : Provide implementation for CustomCanonicalConnectionEditPolicyclass
  4. 4. Every Diagram Editor provides its custom implementation ofCanonicalConnectionEditPolicy, say in the Mindmap example it is provided byMapCanonicalEditPolicy class and in Taipan example it is provided by thePortCanonicalEditPolicy class. Use this custom implementation and overrideallowDropElement(Object dropElement) method to allow custom objects to be dropped .This method by default only allows dropping of objects which are an instance oforg.eclipse.gmf.runtime.notation.Diagram. Now, for example if we want to drop a tableor scheme from DataSourceExplorer the implementation would be as follows: @Override protected boolean allowDropElement(Object dropElement) { if(dropElement instanceof Diagram || dropElement instanceof BaseTable|| dropElement instanceof Schema) return true; else return false; }Step 5: Return an edit part that can produce an executable command for thetarget request private EditPart calculateTargetEditPart() { updateTargetRequest(); EditPart ep = getViewer() .findObjectAtExcluding( getDropLocation(), getExclusionSet(), new EditPartViewer.Conditional() {
  5. 5. 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 6: Return the required DnD command from the corresponding Edit Part @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();
  6. 6. while (i.hasNext()) { EditPolicy tempPolicy = i.next(); if (tempPolicy instanceof DragDropEditPolicy) { dndPolicy = tempPolicy; break; } } return dndPolicy; }// Custom Edit Policypublic class CustomDragDropEditPolicy extends DragDropEditPolicy {@Override protected Command getDropElementCommand(EObject element,DropObjectsRequest request) { EObject modelObj = getHostObject(); TransactionalEditingDomain editDomain = (TransactionalEditingDomain)WorkingCopyUtil.getWorkingCopyFor(modelObj).getEditingDomain(); return getGMFWrapper(new CustomDragDropCommand(editDomain,request,modelObj,element)); } private Command getGMFWrapper(ICommand gmfCommand){ return new ICommandProxy(gmfCommand); }//------}
  7. 7. Step 7 : Execute the DnD Command to create the Concepts throughcorresponding Generator classpublic class BOMADragDropCommand extends AbstractTransactionalCommand{ private EObject modelObj; private EObject element; private IDataModelGenerator modelGen; /** * * @param editDomain * @param request * @param modelObj * @param element */ public CustomDragDropCommand (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){
  8. 8. case DropElementTypeResolver.DB_TYPE:modelGen = newDB2UMLModelGenerator((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; }}

×