001 /* 002 Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com> 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 */ 018 019 package org.objectweb.jac.ide.diagrams; 020 021 import CH.ifa.draw.framework.DrawingEditor; 022 import CH.ifa.draw.framework.Figure; 023 import java.util.List; 024 import java.util.Vector; 025 import org.objectweb.jac.aspects.gui.DisplayContext; 026 import org.objectweb.jac.aspects.gui.EventHandler; 027 import org.objectweb.jac.aspects.gui.InvokeEvent; 028 import org.objectweb.jac.core.rtti.ClassRepository; 029 import org.objectweb.jac.ide.Class; 030 import org.objectweb.jac.ide.InheritanceLink; 031 import org.objectweb.jac.ide.Link; 032 import org.objectweb.jac.ide.RelationLink; 033 import org.objectweb.jac.util.Log; 034 035 /** 036 * Show an existing relation or inheritance link 037 */ 038 public class RelationLinkShowTool extends AbstractActionTool { 039 040 public RelationLinkShowTool(DrawingEditor newDrawingEditor, 041 DisplayContext context) throws ClassNotFoundException { 042 super(newDrawingEditor,context,java.lang.Class.forName("org.objectweb.jac.ide.diagrams.ClassFigure")); 043 } 044 045 // gui related infos and methods 046 047 Class curClass = null; 048 ClassFigure startFig = null; 049 050 /** 051 * Returns the list of relations of the current class not yet on 052 * the diagram 053 * @return a list of RelationLink 054 */ 055 public List relations() { 056 Log.trace("figures","getting relations for class "+curClass); 057 List relations = new Vector(); 058 if (curClass!=null) { 059 return ((DiagramView)editor()).getDiagram().getMissingRelations(curClass); 060 } else { 061 return null; 062 } 063 } 064 065 public void showRelation(Link link) throws Exception { 066 //System.out.println("chooseRelation("+relation+","+relation.getEnd()+")"); 067 if (link==null || link.getStart()==null || link.getEnd()==null) 068 return; 069 if (link instanceof RelationLink) 070 ((DiagramView)editor()).importRelation((RelationLink)link); 071 else if (link instanceof InheritanceLink) 072 ((DiagramView)editor()).importInheritance((InheritanceLink)link); 073 view().repairDamage(); 074 editor().toolDone(); 075 } 076 077 public void action(Figure figure) { 078 startFig = (ClassFigure)figure; 079 curClass = startFig.getClassElement(); 080 EventHandler.get().onInvoke( 081 context, 082 new InvokeEvent( 083 null, 084 this, 085 ClassRepository.get().getClass(getClass()) 086 .getMethod("showRelation"))); 087 088 } 089 090 } 091