EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcm.gmf.repository.edit.policies]

COVERAGE SUMMARY FOR SOURCE FILE [RepositoryCreationEditPolicy.java]

nameclass, %method, %block, %line, %
RepositoryCreationEditPolicy.java0%   (0/1)0%   (0/1)0%   (0/3)0%   (0/1)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RepositoryCreationEditPolicy0%   (0/1)0%   (0/1)0%   (0/3)0%   (0/1)
RepositoryCreationEditPolicy (): void 0%   (0/1)0%   (0/3)0%   (0/1)

1package de.uka.ipd.sdq.pcm.gmf.repository.edit.policies;
2 
3import org.eclipse.gef.EditPolicy;
4import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
5 
6/*
7 * A creation policy which supports adding roles when dragging components or
8 * interfaces on the diagramm
9 */
10public class RepositoryCreationEditPolicy extends CreationEditPolicy implements
11                EditPolicy {
12 
13//        @Override
14//        protected Command getCreateCommand(CreateViewRequest request) {
15//                Command cmd = super.getCreateCommand(request);
16//                final CompoundCommand cc = new CompoundCommand();
17//                final List<IAdaptable> descriptors = (List<IAdaptable>)request.getNewObject();
18//
19//                cc.add(cmd);
20//                cc.add(new Command(){
21//                        private CompoundCommand doCommand = new CompoundCommand();
22//                        
23//                        @Override
24//                        public void execute() {
25//                                for (IAdaptable d : descriptors) {
26//                                        View o = (View) d.getAdapter(View.class);
27//                                        if (o.getElement() instanceof Interface) {
28//                                                doCommand.add(getAddMissingInterfaceComponentRoleRelations(o));
29//                                        } else if (o.getElement() instanceof ProvidesComponentType) {
30//                                                doCommand.add(getAddMissingComponentInterfaceRoleRelations(o));;
31//                                        }
32//                                }
33//                                doCommand.execute();
34//                        }
35//
36//                        @Override
37//                        public boolean canExecute() {
38//                                return true;
39//                        }
40//
41//                        @Override
42//                        public boolean canUndo() {
43//                                return true;
44//                        }
45//
46//                        @Override
47//                        public void redo() {
48//                                doCommand.redo();
49//                        }
50//
51//                        @Override
52//                        public void undo() {
53//                                doCommand.undo();
54//                        }
55//                        
56//                        
57//                });
58//                return cc;
59//        }
60//
61//        private Command getAddMissingComponentInterfaceRoleRelations(
62//                        View componentView) {
63//                CompoundCommand cc = new CompoundCommand();
64//                RepositoryComponent pc = (RepositoryComponent)componentView.getElement();
65//                Repository r = pc.getRepository_RepositoryComponent();
66//                for (EditPart editPart : (List<EditPart>) getHost().getChildren()) {
67//                        if (editPart instanceof IGraphicalEditPart) {
68//                                IGraphicalEditPart iEditPart = (IGraphicalEditPart) editPart;
69//                                if (((View) editPart.getModel()).getElement() instanceof Interface) {
70//                                        Interface interf = (Interface) ((View) editPart.getModel()).getElement();
71//                                        ArrayList<EObject> missingRoles = new ArrayList<EObject>();
72//                                        if (getProvidedRole(pc, interf) != null) {
73//                                                missingRoles.add(getProvidedRole(pc, interf));
74//                                        }
75//                                        if (getRequiredRole(pc, interf) != null) {
76//                                                missingRoles.add(getRequiredRole(pc, interf));
77//                                        }
78//                                        addCreateRelationshipViewsCommands(cc, iEditPart, findEditPart(componentView), missingRoles);
79//                                }
80//                        }
81//                }
82//                return cc;
83//        }
84//        
85//        private Command getAddMissingInterfaceComponentRoleRelations(
86//                        View interfaceView) {
87//                CompoundCommand cc = new CompoundCommand();
88//                Interface interf = (Interface)interfaceView.getElement();
89//                Repository r = interf.getRepository_Interface();
90//                for (EditPart editPart : (List<EditPart>) getHost().getChildren()) {
91//                        if (editPart instanceof IGraphicalEditPart) {
92//                                IGraphicalEditPart iEditPart = (IGraphicalEditPart) editPart;
93//                                if (((View) editPart.getModel()).getElement() instanceof ProvidesComponentType) {
94//                                        ProvidesComponentType pc = (ProvidesComponentType) ((View) editPart.getModel()).getElement();
95//                                        ArrayList<EObject> missingRoles = new ArrayList<EObject>();
96//                                        if (getProvidedRole(pc, interf) != null) {
97//                                                missingRoles.add(getProvidedRole(pc, interf));
98//                                        }
99//                                        if (getRequiredRole(pc, interf) != null) {
100//                                                missingRoles.add(getRequiredRole(pc, interf));
101//                                        }
102//                                        addCreateRelationshipViewsCommands(cc, findEditPart(interfaceView), iEditPart, missingRoles);
103//                                }
104//                        }
105//                }
106//                return cc;
107//        }
108//
109//        private void addCreateRelationshipViewsCommands(CompoundCommand cc,
110//                        IGraphicalEditPart targetEditPart, IGraphicalEditPart sourceEditPart, ArrayList<EObject> missingRoles) {
111//
112//                
113//                if (targetEditPart == null) return;
114//                
115//                for (EObject role : missingRoles) {
116//                        ConnectionViewDescriptor descriptor = new ConnectionViewDescriptor(
117//                                        new EObjectAdapter(role),
118//                                        null,
119//                                        ((IGraphicalEditPart) getHost())
120//                                                        .getDiagramPreferencesHint());
121//                        CreateConnectionViewRequest request = new CreateConnectionViewRequest(
122//                                        descriptor);
123//                        request.setSourceEditPart(sourceEditPart);
124//                        request.setTargetEditPart(targetEditPart);
125//                        request.setType(RequestConstants.REQ_CONNECTION_START);
126//                        sourceEditPart.getCommand(request);
127//                        request.setType(RequestConstants.REQ_CONNECTION_END);
128//                        Command addViewCommand = targetEditPart.getCommand(request);
129//                        cc.add(addViewCommand);
130//                }
131//        }
132//
133//        private ProvidedRole getProvidedRole(ProvidesComponentType pc,
134//                        Interface interf) {
135//                for (ProvidedRole pr : pc.getProvidedRoles_InterfaceProvidingEntity())
136//                        if (pr.getProvidedInterface__ProvidedRole() == interf)
137//                                return pr;
138//                return null;
139//        }
140//
141//        private RequiredRole getRequiredRole(ProvidesComponentType pc,
142//                        Interface interf) {
143//                for (RequiredRole rr : pc.getRequiredRoles_InterfaceRequiringEntity())
144//                        if (rr.getRequiredInterface__RequiredRole() == interf)
145//                                return rr;
146//                return null;
147//        }
148//
149//        private IGraphicalEditPart findEditPart(View targetView){
150//                List<EditPart>children = ((IGraphicalEditPart) getHost()).getChildren();
151//                IGraphicalEditPart targetEditPart = null;
152//                for (EditPart ep : children) {
153//                        if (ep instanceof IGraphicalEditPart){
154//                                IGraphicalEditPart iep = (IGraphicalEditPart)ep;
155//                                if (iep.getNotationView() == targetView)
156//                                        targetEditPart = iep;
157//                        }
158//                }                
159//                return targetEditPart;
160//        }
161}

[all classes][de.uka.ipd.sdq.pcm.gmf.repository.edit.policies]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov