KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > diagrams > PointcutLinkShowTool


1 /*
2   Copyright (C) 2002 Renaud Pawlak
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA. */

18
19 package org.objectweb.jac.ide.diagrams;
20
21
22 import CH.ifa.draw.framework.DrawingEditor;
23 import CH.ifa.draw.framework.Figure;
24 import CH.ifa.draw.standard.ActionTool;
25 import org.objectweb.jac.aspects.gui.DisplayContext;
26 import org.objectweb.jac.core.Wrapping;
27 import org.objectweb.jac.core.rtti.ClassRepository;
28 import java.util.List JavaDoc;
29
30 public class PointcutLinkShowTool extends ActionTool {
31    DisplayContext context;
32    public PointcutLinkShowTool(DrawingEditor newDrawingEditor,
33                                DisplayContext context) {
34       super(newDrawingEditor);
35       this.context = context;
36    }
37
38    // gui related infos and methods
39

40    static org.objectweb.jac.ide.Aspect curAspect=null;
41
42    public static List JavaDoc pointcuts(Object JavaDoc o) {
43       if(curAspect!=null) {
44          return curAspect.getPointcutLinks();
45       } else {
46          return null;
47       }
48    }
49
50    public void choosePointcut(org.objectweb.jac.ide.PointcutLink pointcut) {
51    }
52
53    public void action(Figure figure) {
54       if(! (figure instanceof AspectFigure) ) return;
55       
56       curAspect=(org.objectweb.jac.ide.Aspect)((AspectFigure)figure).getSubstance();
57       Object JavaDoc[] parameters = new Object JavaDoc[] {null};
58       boolean result = context.getDisplay().showInput(
59          this,ClassRepository.get().getClass(getClass()).getMethod("choosePointcut"),
60          parameters);
61       Figure cf = null;
62       if( result ) {
63          org.objectweb.jac.ide.PointcutLink rel = (org.objectweb.jac.ide.PointcutLink)parameters[0];
64          if( rel == null || rel.getEnd() == null ) return;
65          
66          if( rel.getEnd() instanceof org.objectweb.jac.ide.TypedElement ) {
67             cf = ((DiagramView)editor()).findElement((org.objectweb.jac.ide.TypedElement)rel.getEnd());
68          }
69          if( cf == null ) {
70             // end is not found in the diagram... import it!
71
context.getDisplay().showMessage(
72                "You must import '"+
73                rel.getEnd()+
74                "' before this action.",
75                "Error",false,false,true);
76          } else {
77
78             PointcutLinkFigure relf = new PointcutLinkFigure();
79             relf.startPoint(figure.center().x,figure.center().y);
80             relf.endPoint(cf.center().x,cf.center().y);
81             relf.connectStart(figure.connectorAt(figure.center().x,figure.center().y));
82             relf.connectEnd(cf.connectorAt(cf.center().x,cf.center().y));
83
84             // *** relf.setSubstance(rel);
85

86             view().add(relf);
87
88             view().add(relf.createAttachedFigure(
89                AttachedTextFigure.NAME));
90             view().add(relf.createAttachedFigure(
91                AttachedTextFigure.START_ROLE));
92             view().add(relf.createAttachedFigure(
93                AttachedTextFigure.END_ROLE));
94             view().add(relf.createAttachedFigure(
95                AttachedTextFigure.START_CARDINALITY));
96             view().add(relf.createAttachedFigure(
97                AttachedTextFigure.END_CARDINALITY));
98             
99             relf.updateConnection();
100             Wrapping.invokeRoleMethod((org.objectweb.jac.core.Wrappee)rel,"addView",new Object JavaDoc[]{relf});
101
102             editor().toolDone();
103          }
104       }
105    }
106
107 }
108
109
Popular Tags