001 /* 002 Copyright (C) 2002 Renaud Pawlak 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA. */ 018 019 package org.objectweb.jac.ide.diagrams; 020 021 022 import CH.ifa.draw.framework.DrawingEditor; 023 import CH.ifa.draw.framework.Figure; 024 import CH.ifa.draw.standard.ActionTool; 025 import org.objectweb.jac.aspects.gui.DisplayContext; 026 import org.objectweb.jac.core.Wrapping; 027 import org.objectweb.jac.core.rtti.ClassRepository; 028 import java.util.List; 029 030 public class PointcutLinkShowTool extends ActionTool { 031 DisplayContext context; 032 public PointcutLinkShowTool(DrawingEditor newDrawingEditor, 033 DisplayContext context) { 034 super(newDrawingEditor); 035 this.context = context; 036 } 037 038 // gui related infos and methods 039 040 static org.objectweb.jac.ide.Aspect curAspect=null; 041 042 public static List pointcuts(Object o) { 043 if(curAspect!=null) { 044 return curAspect.getPointcutLinks(); 045 } else { 046 return null; 047 } 048 } 049 050 public void choosePointcut(org.objectweb.jac.ide.PointcutLink pointcut) { 051 } 052 053 public void action(Figure figure) { 054 if(! (figure instanceof AspectFigure) ) return; 055 056 curAspect=(org.objectweb.jac.ide.Aspect)((AspectFigure)figure).getSubstance(); 057 Object[] parameters = new Object[] {null}; 058 boolean result = context.getDisplay().showInput( 059 this,ClassRepository.get().getClass(getClass()).getMethod("choosePointcut"), 060 parameters); 061 Figure cf = null; 062 if( result ) { 063 org.objectweb.jac.ide.PointcutLink rel = (org.objectweb.jac.ide.PointcutLink)parameters[0]; 064 if( rel == null || rel.getEnd() == null ) return; 065 066 if( rel.getEnd() instanceof org.objectweb.jac.ide.TypedElement ) { 067 cf = ((DiagramView)editor()).findElement((org.objectweb.jac.ide.TypedElement)rel.getEnd()); 068 } 069 if( cf == null ) { 070 // end is not found in the diagram... import it! 071 context.getDisplay().showMessage( 072 "You must import '"+ 073 rel.getEnd()+ 074 "' before this action.", 075 "Error",false,false,true); 076 } else { 077 078 PointcutLinkFigure relf = new PointcutLinkFigure(); 079 relf.startPoint(figure.center().x,figure.center().y); 080 relf.endPoint(cf.center().x,cf.center().y); 081 relf.connectStart(figure.connectorAt(figure.center().x,figure.center().y)); 082 relf.connectEnd(cf.connectorAt(cf.center().x,cf.center().y)); 083 084 // *** relf.setSubstance(rel); 085 086 view().add(relf); 087 088 view().add(relf.createAttachedFigure( 089 AttachedTextFigure.NAME)); 090 view().add(relf.createAttachedFigure( 091 AttachedTextFigure.START_ROLE)); 092 view().add(relf.createAttachedFigure( 093 AttachedTextFigure.END_ROLE)); 094 view().add(relf.createAttachedFigure( 095 AttachedTextFigure.START_CARDINALITY)); 096 view().add(relf.createAttachedFigure( 097 AttachedTextFigure.END_CARDINALITY)); 098 099 relf.updateConnection(); 100 Wrapping.invokeRoleMethod((org.objectweb.jac.core.Wrappee)rel,"addView",new Object[]{relf}); 101 102 editor().toolDone(); 103 } 104 } 105 } 106 107 } 108