KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > swing > FieldNameEditor


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
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, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   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.swing;
20
21 import java.util.Collection JavaDoc;
22 import org.objectweb.jac.aspects.gui.swing.PrimitiveFieldEditor;
23 import org.objectweb.jac.core.rtti.FieldItem;
24 import org.objectweb.jac.ide.Gui;
25 import org.objectweb.jac.ide.Type;
26 import org.objectweb.jac.ide.TypedElement;
27 import org.objectweb.jac.util.Strings;
28
29 /**
30  * This editor tries to set the type of the field from its name if
31  * it's not already set.
32  */

33 public class FieldNameEditor extends PrimitiveFieldEditor {
34     TypedElement element;
35     public FieldNameEditor(TypedElement substance, FieldItem field) {
36         super(substance,field);
37         this.element = substance;
38     }
39
40     public void setValue(Object JavaDoc value) {
41         super.setValue(value);
42         if (element.getType()==null && !Strings.isEmpty((String JavaDoc)value)) {
43             Collection JavaDoc types = Gui.getMatchingTypes(element,element.getName());
44             if (!types.isEmpty()) {
45                 element.setType((Type)types.iterator().next());
46             }
47         }
48     }
49 }
50
Popular Tags