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 org.objectweb.jac.aspects.gui.DisplayContext; 022 import org.objectweb.jac.aspects.gui.EventHandler; 023 import org.objectweb.jac.aspects.gui.GuiAC; 024 import org.objectweb.jac.aspects.gui.ObjectUpdate; 025 import org.objectweb.jac.aspects.gui.Utils; 026 import org.objectweb.jac.core.rtti.ClassRepository; 027 import org.objectweb.jac.core.rtti.CollectionItem; 028 import org.objectweb.jac.ide.Class; 029 import org.objectweb.jac.ide.Field; 030 import org.objectweb.jac.ide.ModelElement; 031 032 public class FieldFigure extends MemberFigure 033 implements ModelElementFigure, ObjectUpdate, Selectable 034 { 035 Field field; 036 037 public FieldFigure(Field field, ClassFigure parentFigure) { 038 super(parentFigure); 039 this.field = field; 040 super.setText(GuiAC.toString(field)); 041 Utils.registerObject(field,this); 042 } 043 044 public void close() { 045 Utils.unregisterObject(field,this); 046 } 047 048 public ModelElement getSubstance() { 049 return field; 050 } 051 052 public void linkToField(Class cl) { 053 field = cl.findField(getName()); 054 } 055 056 boolean updating = false; 057 058 public void setText(String s) { 059 super.setText(s); 060 if (field != null && !DiagramView.init) { 061 updating=true; 062 field.setName(getName()); 063 field.setType(org.objectweb.jac.ide.Projects.types.resolveType(getType())); 064 updating=false; 065 } 066 } 067 068 // ObjectUpdate interface 069 public void objectUpdated(Object object, Object extra) { 070 if (!updating) { 071 super.setText(GuiAC.toString(field)); 072 } 073 } 074 075 // Selectable interface 076 public void onSelect(DisplayContext context) { 077 CollectionItem coll = ClassRepository.get().getClass(Class.class) 078 .getCollection("fields"); 079 EventHandler.get().onSelection( 080 context,coll,getSubstance(),null,null); 081 } 082 }